akhauriyash/Code-Regression huggingface dataset:
from sys import stdin
input = stdin.readline

x,y=map(int,input().split())

ans=0

if x==1:
    ans+=300000
elif x==2:
    ans+=200000
elif x==3:
    ans+=100000
if y==1:
    ans+=300000
elif y==2:
    ans+=200000
elif y==3:
    ans+=100000
if x==1 and y==1:
    ans+=400000
print(ans)

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
a = [0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1]
x, y = map(int, input().split())

if(a[x] == a[y]):
  print('Yes')
else:
  print('No')


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];
    vector<int> b(n);
    b = a;
    sort(b.begin(), b.end());
    REP(i, n) {
        if (a[i] == b[n - 1]) cout << b[n - 2] << '\n';
        else cout << b[n - 1] << '\n';
    }
    return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int k;
  string s;
  cin >> s >> k;
  vector<string> v;
  unordered_set<string> st;
  int ss = s.size();
  for (int i = 0; i < ss; ++i) {
    for (int j = 1; i + j <= ss; ++j) {
      if (j > k) continue;
      string ss = s.substr(i, j);
      if (st.find(ss) == st.end()) {
        st.insert(ss);
        v.push_back(ss);
      }
    }
  }

  sort(v.begin(), v.end());
  cout << v[k - 1] << endl;
  return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
  
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * (B / gcd(A, B));
}
  
/*------------------------------------------------------------------*/
int main(){
    int n, p; cin >> n >> p;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    ll dp[60][2]; // １：奇数　０：偶数
    
    rep(i, n){
        if(i == 0){
            if(a[i] % 2 == 0){
                dp[i][0] = 2;
                dp[i][1] = 0;
            }else{
                dp[i][0] = 1;
                dp[i][1] = 1;
            }
            continue;
        }
        if(a[i] % 2 == 0){
            dp[i][0] = dp[i - 1][0] * 2;
            dp[i][1] = dp[i - 1][1] * 2;
        }else{
            dp[i][0] = dp[i - 1][0] + dp[i - 1][1];
            dp[i][1] = dp[i - 1][0] + dp[i - 1][1];
        }
    }
    if(p % 2 == 0)cout << dp[n - 1][0] << endl;
    else cout << dp[n - 1][1] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int>> w(100001, vector<int>());
    int a,b;
    for(int i=0;i<n;i++){
        cin >> a >> b;
        w[a].push_back(b);
    }
    priority_queue<int> q;
    ll ans = 0;
    for(int i=m-1;i>=0;i--){
        for(auto e: w[m-i]){
            q.push(e);
        }
        if(!q.empty()){
            ans += q.top();
            q.pop();
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5632
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int main(){ _;
  int n;
  while(cin>>n,n!=0){
    int sum=0;
    int rest=1;
    for(int i=2;;i++){
      rest+=i;
      if(rest>n){break;}
      if((n-rest)%i==0){sum++;}
    }
    cout<<sum<<endl;
  }
}

Measured memory_bytes: 1188
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	var l, min, sum float64
	fmt.Scan(&n, &l)
	min = math.Abs(l)
	for i := 0; i < n; i++ {
		if math.Abs(l) < math.Abs(min) {
			min = l
		}
		sum += l
		l++
	}
	fmt.Println(sum - min)
}


Measured memory_bytes: 512
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
pre = -1
for i in A:
  ans += B[i-1]
  if i == pre+1:
  	ans += C[pre-1]
  pre = i
print(ans)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;
vin dx={-1,0,1},dy={-1,0,1};
ll w,h;
void dfs(vvll g,vvll &c,ll x,ll y){
  c[x][y]=1;
  rep(k,0,3){
    ll nx=x+dx[k];
    if(nx>=h||nx<0){continue;}
    rep(l,0,3){
      ll ny=y+dy[l];
      if(ny>=w||ny<0){continue;}
      if(!c[nx][ny]&&g[nx][ny]){
        dfs(g,c,nx,ny);
      }
    }
  }
}
int main(){
  do{
    ll cnt=0;
    cin>>w>>h;
    if(w==0&&h==0){break;}
    vvll g(h,vll(w)),c(h,vll(w,0));
    rep(i,0,h){
      rep(j,0,w){
        cin>>g[i][j];
      }
    }
    rep(i,0,h){
      rep(j,0,w){
        if(!c[i][j]&&g[i][j]){
          dfs(g,c,i,j);
          cnt++;
        }
      }
    }
   out(cnt);
  }while(w!=0&&h!=0);
}



Measured memory_bytes: 50128
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

long long factorial(long long i){ // 階乗
  if(i > 0)
    return i * factorial(i-1);
  else
    return 1;
}
//// a^n mod
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n>0) {
    if(n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

//// a^(-1) mod
long long modinv(long long a, long long mod) {
  return modpow(a, mod-2, mod);
}

int main() {
  const ll mod = 1000000000+7;
  ll N, K;
  cin >> N >> K;
  
  vector<ll> fact(max(K+2, N-K)+4);
  fact[0] = 1;
  rep(i, max(K+2, N-K)+3) {
    fact[i+1] = fact[i] * (i+1) %mod;
  }
  
  vector<ll> cnt(K);
  ll tmp = 0;
  
  for(int i=1; i<=K; i++) {
    // r の位置 * rの個数
    tmp = fact[K-1]* modinv(fact[i-1], mod)%mod *modinv(fact[K-i], mod)%mod;
    //cout << "1:" << tmp << endl;
    if(N-K-i+1<0) {
      tmp = 0;
    }
    else tmp *= fact[N-K+1]* modinv(fact[i],mod)%mod *modinv(fact[N-K-i+1],mod)%mod;
    //cout << "2:" << fact[N-K+1] << ' ' << modinv(fact[i],mod) << ' ' << modinv(fact[N-K-i+1],mod) << endl;
    tmp = tmp%mod;
    
    cnt[i-1] = tmp;
  }
  
  rep(i, K) {
    cout << cnt[i] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int c=0,i,j;
  string s,s1;
  cin>>s>>s1;
for(i=0;i<s.size();i++)
{
	if(s[i]==s1[i]){
		c++;
	}
}
(c==s.size())?cout<<"Yes":cout<<"No";

 return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;

int main(int argc, char const *argv[]) {

  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (abs(a-c) <= d)
  cout << "Yes";
  else if (abs(a-b) <=d and abs(b-c) <= d)
  cout << "Yes";
  else
  cout << "No";

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
    int N, M, R;
    cin >> N >> M >> R;
    vector<int> r(R);
    for(auto& e : r) cin >> e, e--;
    vector<int> a(M), b(M), c(M);
    for(int i = 0; i < M; i++) cin >> a[i] >> b[i] >> c[i], a[i]--, b[i]--;

    vector<vector<int> > dist(N, vector<int>(N, 1e9+1));
    for(int i = 0; i < N; i++) dist[i][i] = 0;
    for(int i = 0; i < M; i++) dist[a[i]][b[i]] = c[i], dist[b[i]][a[i]] = c[i];

    for(int k = 0; k < N; k++) {
        for(int i = 0; i < N; i++) {
            for(int j = 0; j < N; j++) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    sort(r.begin(), r.end());

    int ans = 1e9+1;
    do {
        int sum = 0;
        for(int i = 1; i < r.size(); i++) {
            sum += dist[r[i-1]][r[i]];
        }
        ans = min(ans, sum);
    }while(next_permutation(r.begin(), r.end()));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,a,b;
int main()
{
    scanf("%d",&n);
    if(n==1)printf("Hello World");
    else{
    	scanf("%d%d",&a,&b);
    	printf("%d",a+b);
	}
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <cstring>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;

int main()
{
    int n, m, Q, l[212345], r[212345];

    int t[510][510];
    memset(t, 0, sizeof(t));

    cin >> n >> m >> Q;

    REP(i, m)
    {
        cin >> l[i] >> r[i];
        t[l[i]][r[i]]++;
    }

    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
            t[i][j] += t[i][j - 1];
    }

    vector<int> resv;

    REP(i, Q)
    {
        int p, q;
        cin >> p >> q;

        int res = 0;
        for (int j = p; j <= q; j++)
            res += t[j][q];

        resv.push_back(res);
    }

    for (int i : resv)
        cout << i << endl;

    return 0;
}

Measured memory_bytes: 4088
import java.util.*;
public class Main {
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        Random rand = new Random();
        int a,b,c;
		// 整数の入力
        a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();

        if(a==b && a!=c && b!=c){
            System.out.println("Yes");
        }else if(a==c && a!=b && c!=b){
            System.out.println("Yes");
        }else if(b==c && b!=a && c!=a){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
        
       


    
	}
}

Measured memory_bytes: 22740
runrun = []


def dfs(x):
    if x > 3234566667:
        return
    runrun.append(x)
    for i in range(10):
        if abs(x % 10 - i) <= 1:
            dfs(x * 10 + i)


for i in range(1, 10):
    dfs(i)

runrun = sorted(runrun)
K = int(input())

print(runrun[K-1])

Measured memory_bytes: 8512
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;




//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)




int main() {
	int r, g;
	cin >> r >> g;
	cout << g + (g - r) << endl;

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
#include <set>

using namespace std;
using ll = long long;
#define rep(i,a,b) for(ll i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
void printVec(std::vector<char> &vec) {
  std::cout << "";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    std::cout << *it << " ";
  }
  std::cout << std::endl;
}
 
int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector <char> a(n);
    int ma =0;
    rep(i,0,n-1) {
        // a = unique(s.begin()+i+1, s.end()) ;
        rep(j,i+1,n) {
            a.push_back(s[j]);
        }
        sort(a.begin(), a.end());
        a.erase(unique(a.begin(), a.end()), a.end());
        int count = 0;
        for(int j =0;j <a.size();j++) {
            rep(k,0,i+1) {
                if (a[j] == s[k]) {
                    count++;
                    break;
                }
            }
        }
        ma = max(ma, count);
        a.clear();
    }
    cout << ma << endl;
}

Measured memory_bytes: 3100
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) {
    if(a < b){
        return gcd(b, a);
    }
    ll r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

int main(){
    ll n;
    cin >> n;
    vector<ll> as(n, 0);
    for(int i = 0; i < n; ++i){
        cin >> as.at(i);
    }
    ll ans = as.at(0);
    for(int i = 1; i < n; ++i){
        ans = gcd(ans, as.at(i));
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long h = scanner.nextLong();
        
        long w = scanner.nextLong();
        if (h == 1 || w == 1) {
            System.out.println(1);
            return;
        }
        long a = h / 2;
        long b = a * w;
        long ret = b;

        if (h % 2 == 1) {
            if (w % 2 == 1) {
                ret += (w / 2) + 1;
            } else {
                ret += w / 2;
            }
        }
        System.out.println(ret);
    }
}

Measured memory_bytes: 23764
N,K = map(int,input().split())
p = list(map(int,input().split()))

for i in range(0,N,1):
    p[i] = (p[i]+1)/2

tmp = sum(p[0:K])
ans = tmp
for i in range(0,N-K,1):
    tmp -= p[i]
    tmp += p[K+i]
    ans = max(ans,tmp)

print(ans)


Measured memory_bytes: 71920
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
int ABS(int a) {if(a<0) a = -a; return a;}
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数の個数*/int divisor_number(int n){auto p = prime_factor(n); int res = 1; for(auto x:p)res*=(x.second+1); return res;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    string s,t; cin >> s >> t;
    string a = s;
    bool ok = 0;
    REP(i,s.size()){
        REP(j,s.size()){
            a[j] = s[(j+i)%s.size()];
        }
        if(a==t) ok = 1;
    }
    Yn(ok);

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<int> H(N);
    rep(i,0,N){
        cin >> H[i];
    }
    int cnt = 0;
    rep(j,0,10101){
        int flag = H[0] != 0;
        cnt += flag;
        H[0] -= flag;
        rep(i,1,N){
            if(flag){
                if(H[i] != 0){
                    H[i]--;
                }else{
                    break;
                }
            }else{
                if(H[i] != 0){
                    flag = 1;
                    H[i]--;
                    cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,z,w,a[2000];
  cin>>n>>z>>w;
  for(int i=0;i<n;i++)cin>>a[i];
  int ans=abs(w-a[n-1]);
  if(n>1)ans=max(ans,abs(a[n-1]-a[n-2]));
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 
//using namespace boost::multiprecision; 

using namespace std;

//#Rohitpratap311
//#Keep Calm And Stay Happy

typedef long long ll;
typedef long double ld;




int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--)
    {
      	ll a,b,c,d;
      	cin>>a>>b>>c>>d;
      	cout<<max(a*d,(max(a*c,max(b*d,b*c))));
    
    }
    return 0;
}


Measured memory_bytes: 3580
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <stdio.h>
#include <ctype.h>
#include <string.h>

using namespace std;

void deleteX(list<int> &list, int x) {
    for(auto itr=list.begin(); itr!=list.end(); itr++ ) {
        if(*itr==x) {
            list.erase(itr);
            break;
        }
    }
}

bool tiny_match(const char* str, const char* ptn, int n, int* p_val) {
	*p_val = 0;
	if (strncmp(str, ptn, (size_t)n) != 0) {
		return false;
	}
	if (isalpha(str[n])) {
		return false;
	}
	*p_val = atoi(&(str[n]));
	return true;
};

#define MATCH(str, ptn, p)		(tiny_match((str), (ptn), sizeof(ptn) - (size_t)1, (p)))

int main(void) {
    list<int> list;
    int n;
    int x;
    
    string str;
    getline(cin,str);
    stringstream ss(str);

	ss >> n;

	while( n > 0 && getline(cin, str) ) {
		size_t head = str.find_first_not_of(" \t\v\r\n");
		if (head == std::string::npos) {
			printf("ERROR: Syntax error.\n");
			return -1;
		}
		n--;
        
        if( MATCH(&(str[head]), "insert", &x) ) {
			//printf("insert %d\n", x);
            list.push_front(x);
        }
        else if( MATCH(&(str[head]), "delete", &x) ) {
			//printf("delete %d\n", x);
            deleteX(list, x);
        }
        else if( MATCH(&(str[head]), "deleteFirst", &x) ) {
			//printf("deleteFirst %d\n", x);
            list.pop_front();
        }
        else if( MATCH(&(str[head]), "deleteLast", &x) ) {
			//printf("deleteLast %d\n", x);
            list.pop_back();
        }
		else {
			printf("ERROR: Unknown token.\n");
		}
    }

	//display list
    for(auto itr=list.begin(); itr!=list.end(); itr++ ) {
        if(itr==list.begin()) {
            cout << *itr;
        } else {
            cout << " " << *itr;
        }
    }
    cout << endl;

	return 0;
}

Measured memory_bytes: 34316
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int INTMAX = 2147483647;
const int INTMIN = -2147483648;
const unsigned int UINTMAX = 4294967295;
const long LONGMAX = 9223372036854775807;
const long LONGMIN = -9223372036854775808;
const unsigned long ULONGMAX = 18446744073709551615;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define UNIQ(c) (c).erase(unique((c).begin(), (c).end()), (c).end());
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

bool isprime(int p) {
  if (p==1) return false;
  FOR(i,2,p) {
    if (p%i==0) return false;
  }
  return true;
}

long a[200010];

bool chk(int l, int r){
  int rp=0;
  FOR (i,l,r){
    if (rp&a[i]) return false;
    rp+=a[i];
  }
  return true;
}

int main(){
  string s;
  cin >> s;
  int r=0;
  REP(i,4){
    if(s[i]=='+'){
      r++;
    } else {
      r--;
    }
  }
  cout << r;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
typedef long long ll;
using namespace std;

int main()
{
    ll x;
    ll a = 0, b = 0; //500,5
    cin >> x;

    while (x >= 500)
    {
        x = x - 500;
        a++;
    }

    while (x >= 5)
    {
        x = x - 5;
        b++;
    }

    cout << a * 1000 + b * 5 << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++){
		    a[i] = sc.nextInt();
		}
		
		// 計算
		//String result = "No";
		for(int i = k; i < n; i++){
		    if(a[i-k] < a[i]){
		        System.out.println("Yes");
		    }else{
		        System.out.println("No");
		    }
		}
		
		// 出力
		//System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}


Measured memory_bytes: 63624
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := newIo()
	defer io.Flush()
	N, Q := io.NextInt(), io.NextInt()
	points := map[int]int{}
	edges := map[int][]int{}
	for i := 0; i < N-1; i++ {
		a, b := io.NextInt(), io.NextInt()
		edges[a] = append(edges[a], b)
		edges[b] = append(edges[b], a)
	}
	for i := 0; i < Q; i++ {
		a, point := io.NextInt(), io.NextInt()
		points[a] = points[a] + point
	}
	totalPoints := map[int]int{}
	totalPoints[1] = points[1]
	q := []int{1}
	for len(q) > 0 {
		qq := q[0]
		q = q[1:]
		currentPoint := totalPoints[qq]
		for _, edge := range edges[qq] {
			_, exists := totalPoints[edge]
			if exists {
				continue
			}
			totalPoints[edge] = currentPoint + points[edge]
			q = append(q, edge)
		}
	}
	for i := 1; i < N+1; i++ {
		fmt.Print(totalPoints[i])
		if i < N {
			fmt.Print(" ")
		}
	}
	fmt.Println("")
}

type io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func newIo() *io {
	return &io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *io) PrintIntLn(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func (io *io) PrintStringLn(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}


Measured memory_bytes: 49920
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        String s;
        String t;

        Scanner sc = new Scanner(System.in);
        s = sc.nextLine();
        t = sc.nextLine();

        int count = 0;
        for (int i = 0; i < 3; i++) {
            if (s.charAt(i) == t.charAt(i)) {
                count++;
            }
        }

        System.out.println(count);
    }
}


Measured memory_bytes: 21844
import java.io.*;

class Main
{
	public static void main(String[] args) throws IOException
	{
		BufferedReader br =
			new BufferedReader(new InputStreamReader(System.in));

		String str;

	while((str=br.readLine()) != null){

		int integral = 0;
		int  j=1;

		int d = Integer.parseInt(str);

		int num = 600 / d;

		for(int i=0; i<num-1; i++){

			integral = integral + (j*d)*(j*d)*d;
			j++;

		}


		System.out.println(integral);

	}


	}


}

Measured memory_bytes: 23956
#include<stdio.h>

#define INFTY 1 << 30;



int Merge(int A[],int left,int mid,int right){

  int k;
  int n1 = mid-left;
  int n2 = right-mid;

  int L[n1+1];
  int R[n2+1];

  for(int i=0;i<n1;i++){
    L[i] = A[left+i];
  }

  for(int i=0;i<n2;i++){
    R[i] = A[mid+i];
  }

  L[n1] = INFTY;
  R[n2] = INFTY;

  int i=0;
  int j=0;

  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      A[k] = L[i];
      i++;
    }else{
      A[k] = R[j];
      j++;
    }
  }
  return k - left;
}

int MergeSort(int A[],int left,int right){
  int count = 0;
  if(left+1 < right){
    int mid = (left+right)/2;
    count += MergeSort(A,left,mid);
    count += MergeSort(A,mid,right);
    count += Merge(A,left,mid,right);
  }
  return count;
}

int main(){
  int n,m;
  scanf("%d",&n);

  int S[500000];
  for(int i=0;i<n;i++){
    scanf("%d",&S[i]);
  }

  m = MergeSort(S,0,n);

  for(int i=0;i<n-1;i++){
    printf("%d ",S[i]);
  }
  printf("%d\n%d\n",S[n-1],m);

  return 0;
}



Measured memory_bytes: 6488
#include<iostream>
#include<vector>
int main()
{
	int n;
	std::cin >> n;
	std::vector<int>num(n);
	for(int i = 0; i < n; i++)
	{
		std::cin >> num[i];
	}
	long long ans = 0, sum = 0;
	for(int l = 0, r = 0; l < n && r < n;)
	{
		if((sum ^ num[r]) == sum + num[r])
		{
			if(r == n - 1)
			{
				ans += r - l + 1;
				l++;
			}
			else
			{
				sum += num[r];
				r++;
			}
		}
		else
		{
			ans += r - l;
			sum ^= num[l];
			l++;
		}
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;


int main() {

	int n; cin >> n;
	int a[100]; for (int i = 0; i < n; i++) cin >> a[i];
	int ans = 0;

	bool flag = true;
	while (flag) {
		flag = false;
		for (int i = n - 1; i > 0; i--) {
			if (a[i - 1] > a[i]) {
				swap(a[i - 1], a[i]);
				ans++;
				flag = true;
			}
		}
	}

	for (int i = 0; i < n; i++) {
		if (i != 0) cout << " ";
		cout << a[i];
	}
	cout << endl;

	cout << ans << endl;

	return 0;
}





Measured memory_bytes: 3092
N,K= map(int,input().split())

h = [int(input()) for i in range(N)]

h.sort()

# h_sa = [0]*N

# for i in range(1,N):
#     h_sa[i] = h[i] - h[i-1]

# print(h)

# h_sa.sort()
answer = 10**9
for i in range(N):
    if i + K -1 >= N:
        break
    # if answer > sum(h_sa[i:i+K]):
    #     answer = sum(h_sa[i:i+K])
    # print(h[i+K-1]-h[i])

    if answer > h[i+K-1]-h[i]:
        answer = h[i+K-1]-h[i]





print(answer)





Measured memory_bytes: 7384
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
template<class T> using vv=vector<vector< T > >;

int V, E;
struct Edge {
  int s;
  int t;
  int cost;
};
vector<Edge> edge;
vector<int> d;
#define INF 1e9

bool bellman_ford(int s) {
  d.assign(V, INF);
  d[s] = 0;

  rep (i, V-1) {
    rep (j, E) {
      auto e = edge[j];
      auto u = e.s;
      auto v = e.t;
      if (d[u] == INF) {
        continue;
      }
      if (d[v] > d[u] + e.cost) {
        d[v] = d[u] + e.cost;
      }
    }
  }
  rep (j, E) {
    auto e = edge[j];
    auto u = e.s;
    auto v = e.t;
    if (d[u] == INF) {
      continue;
    }
    if (d[v] > d[u] + e.cost) {
      return false;
    }
  }
  return true;
}

int main() {
  int src;
  scanf("%d %d %d", &V, &E, &src);
  edge.resize(E);
  rep (i, E) {
    int s, t, d;
    scanf("%d %d %d", &s, &t, &d);
    edge[i].s = s;
    edge[i].t = t;
    edge[i].cost = d;
  }

  bool valid = bellman_ford(src);
  if (valid) {
    rep (i, V) {
      if (d[i] == INF) {
        printf("INF\n");
      } else {
        printf("%d\n", d[i]);
      }
    } 
    return 0;
  }
  printf("NEGATIVE CYCLE\n");

  return 0;
}

Measured memory_bytes: 3208
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a<b) {
			System.out.println("a < b");
		} else if(a==b) {
			System.out.println("a == b");
		}else {
			System.out.println("a > b");
		}
		

	}

}



Measured memory_bytes: 26052
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define show(n) cerr<<#n<<" = "<<n<<endl
#define showp(n) cerr<<n.fs<<", "<<n.sc<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showsp(n) for(auto z:n){cerr<<z.fs<<" "<<z.sc<<", "}cerr<<endl

#define yes puts("Yes")
#define no puts("No")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

inline void io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}
template<typename T> inline void in(T &e){cin>>e;}
template<typename T> inline void out(T e){cout<<e<<endl;}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

int n,k;

signed main(){
    io();
    cin>>n>>k;
    if(n%k==0){
        out(0);
    }else{
        out(1);
    }

    return 0;
}


Measured memory_bytes: 888
let n = Int(readLine()!)!
 
let a = readLine()!.split(separator: " ").map { Int($0)! }
 
var stocks = 0
var money = 1000
 
for i in 1..<n {
  if a[i-1] < a[i] {
    // buy
    stocks += money / a[i-1]
    money = money % a[i-1]
  } else if a[i-1] > a[i] {
    //sell
    money += stocks * a[i - 1]
    stocks = 0
  }
}

money += stocks * a[n - 1]
 
print(money)

Measured memory_bytes: 8268
H, W = gets.chomp.split().map(&:to_i)
MAZE = Array.new(H)
H.times do |i|
  MAZE[i] = gets.chomp.chars
end

def bfs(start)
  queue = []
  costMemo = H.times.map { Array.new(W, -1) }
  #最初のキューを入れる (h, w, goal, cost)
  queue.push([start[0], start[1], 0])
  
  while !queue.empty? do
    farCost = 0
    #キューを取りだす
    loc = queue.shift
    h = loc[0]; w = loc[1]; cost = loc[2]
    #コストの記録を行い、既に短い経路が見つかっている場合はnext
    if costMemo[h][w] == -1 || costMemo[h][w] > cost 
      costMemo[h][w] = cost
    else
      next
    end
    
    #進行方向のキューを追加（上下、左右
    queue.push([h + 1, w, cost + 1]) if h < H - 1 && MAZE[h + 1][w] == '.'
    queue.push([h - 1, w, cost + 1]) if h > 0 && MAZE[h - 1][w] == '.'
    queue.push([h, w + 1, cost + 1]) if w < W - 1 && MAZE[h][w + 1] == '.'
    queue.push([h, w - 1, cost + 1]) if w > 0 && MAZE[h][w - 1] == '.'
  end
  
  #もっとも高かったコストを返す
  return costMemo.flatten.max
end

ans = -1

H.times do |i|
  W.times do |j|
    next if MAZE[i][j] == '#'
    mazeCost = bfs([i, j])
    ans = mazeCost if ans == -1 || ans < mazeCost
  end
end

puts ans

Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll x;
    cin >> x;
    ll a = 100;
    int d = 0;
    while(a < x) {
        a += a * 0.01;
        d++;
    }

    cout << d;
    return 0;
}


Measured memory_bytes: 3656
package main

import "fmt"

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	fmt.Println(min(n%k, abs(n%k, k)))
}

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func abs(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}


Measured memory_bytes: 512
#include <stdio.h>

#define N 8
#define TRUE 1
#define FALSE 0
#define CHECKED 1
#define NOT_CHECKED -1

int tate[N];
int yoko[N];
int naname_l[2*N-1];
int naname_r[2*N-1];
int hi[N][N];

void reset();
void print();
void recursive (int st);

int main(){
  int i,j,k,tate,yoko;
  reset();

  for(i=0;i<N;i++)
    for(j=0;j<N;j++)
      hi[i][j]=FALSE;
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d%d",&tate,&yoko);
    hi[tate][yoko]=TRUE;
  }

  recursive(0);

  return 0;
}

	
  
void reset(){
  int i;
  for(i=0;i<N;i++){
    tate[i]=NOT_CHECKED,
      yoko[i]=NOT_CHECKED;
  }

  for(i=0;i<2*N-1;i++){
    naname_l[i]=NOT_CHECKED;
    naname_r[i]=NOT_CHECKED;
  }
}

void print(){
  int i,j;
  
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(hi[i][j]){
	if(tate[i]!=j)
	  return;
      }
    }
  }

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(tate[i]==j){
	printf("Q");
      }else{
	printf(".");
      }
    }
    printf("\n");
  }
}
      
void recursive (int st){
  int i;
  if(st==N){
    print();
    return;
  }

  for(i=0;i<N;i++){

    if(CHECKED==yoko[i] ||CHECKED==naname_l[st+i] ||CHECKED==naname_r[st-i+N-1])
      continue;

    tate[st]=i;
    yoko[i]=naname_l[st+i]=naname_r[st-i+N-1]=CHECKED;

    recursive(st+1);

    tate[st]=yoko[i]=naname_l[st+i]=naname_r[st-i+N-1]=NOT_CHECKED;
  }
}

    




Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)x.size()
#define int ll

const int N = 1e5 + 10;
int ans[N], cnt[N];

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, m;
	cin >> n >> m;
	vector<int> q = {n};
	for (int i = 0; i < m; i++) {
		int x;
		cin >> x;
		while (!q.empty() && q.back() >= x) {
			q.pop_back();
		}
		q.pb(x);
	}
	cnt[SZ(q) - 1] = 1;
	for (int i = SZ(q) - 1; i >= 0; i--) {
		int cur = q[i];
		for (;;) {
			int pos = lower_bound(all(q), cur) - q.begin() - 1;
			if (pos < 0) {
				break;
			}
			cnt[pos] += cnt[i] * (cur / q[pos]);
			cur %= q[pos];
		}
		ans[1] += cnt[i];
		ans[cur + 1] -= cnt[i];
	}
	int cur = 0;
	for (int i = 1; i <= n; i++) {
		cur += ans[i];
		cout << cur << '\n';
	}
}

Measured memory_bytes: 4212
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;


int main(void)
{
	int r, g, b, n;

	while(scanf("%d%d%d%d", &r, &g, &b, &n)==4)
	{
		vll dp(n+1);

		dp[0]=1;
		for(int i=0;i+r<=n;i++)
		{
			dp[i+r]+=dp[i];
		}
		for(int i=0;i+g<=n;i++)
		{
			dp[i+g]+=dp[i];
		}
		for(int i=0;i+b<=n;i++)
		{
			dp[i+b]+=dp[i];
		}
		printf("%lld\n", dp[n]);
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

/**
 * B - Distance
 */
public class Main {

    public static void main( String[] args ) {

        Scanner sc = new Scanner( System.in );
        // 入力値
        int n = sc.nextInt(); // 2次元平面上にある点の数
        int d = sc.nextInt(); // 原点からD以下の点を求める

        int result = 0;
        for( int i = 0; i < n; i++ ) {
            double calc = Math.sqrt( Math.pow( sc.nextInt(), 2 ) + Math.pow( sc.nextInt(), 2 ) );
            if( calc <= d ) result++;
        }

        System.out.println( result );

        sc.close();
    }
}

Measured memory_bytes: 59700
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
//#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define INF (int)1e15
#define MOD 1000000007
//#define N 12
#define sz 1000*1000

 int  main(){

  string s;   cin>>s;
  int k; cin>>k;
  vector<string>v;

  int n = s.length();
 for(int i=0;i<n;i++){
      for(int j=1;j<=n-i;j++){
             if(j > k) break;
             string ans = s.substr(i,j);
                  v.push_back(ans); }

 }


 sort(v.begin(),v.end());
 unique(v.begin(),v.end());

 cout<<v[k-1]<<endl;

 return 0;
 }

Measured memory_bytes: 4332
from sys import stdin
S = input()
x = S
y =str()   
N = int(input())
Q =  [list(map(str, stdin.readline().split())) for _ in range(N)]
flag = True
for i in range(N):
    if Q[i][0]=="1":
        flag = not(flag)                
    else: 
        if (Q[i][1] == "2") == (flag == True):
            x += Q[i][2]#先頭
        else :
            y += Q[i][2]
M = "".join([y[::-1],x])
if flag == True:
    print(M)
else:
    print(M[::-1])  

Measured memory_bytes: 41460
// This template code suggested by KT BYTE Computer Science Academy
//   for use in reading and writing files for USACO problems.

// https://content.ktbyte.com/problem.java

import java.util.*;
import java.io.*;

public class Main {

    static StreamTokenizer in;

    static int nextInt() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }

    public static void main(String[] args) throws Exception {
        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

        int n = nextInt();
        int w = nextInt();

        Item[] items = new Item[n+1];

        int totalValues = 0;

        for (int i = 1; i <= n; i++) {
            items[i] = new Item(nextInt(), nextInt());
            totalValues += items[i].value;
        }

        long[][] dp = new long[n+1][totalValues + 1];

        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= totalValues; j++) {
                dp[i][j] = Integer.MAX_VALUE;
            }
        }

        dp[0][0] = 0;

        for (int i = 1; i <= n; i++) {
            Item item = items[i];
            for (int j = 0; j <= totalValues; j++) {
                dp[i][j] = dp[i-1][j];
                if (j - item.value >= 0 && dp[i-1][j-item.value] != Integer.MAX_VALUE) {
                    dp[i][j] = Math.min(dp[i][j], dp[i-1][j-item.value] + item.weight);
                }
            }
        }

        int result = 0;

        for (int i = 1; i <= n; i++) {
            for (int j = 0; j <= totalValues; j++) {
                if (dp[i][j] <= w) result = Math.max(result, j);
            }
        }

        out.println(result);

        out.close();
    }

    static class Item {
        int weight, value;

        Item(int weight, int value) {
            this.weight = weight;
            this.value = value;
        }
    }
}




Measured memory_bytes: 138292
import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if ( n < 1000 ){
			System.out.println("ABC");
		} 
		else {
			System.out.println("ABD");
		}
	}
}

Measured memory_bytes: 23252
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

int M, D;

signed main()
{
	cin >> M >> D;

	int ans = 0;
	for (int m = 1; m <= M; m++)
	{
		for (int d = 1; d <= D; d++)
		{
			int d10 = d / 10;
			int d1 = d % 10;

			if (d1 >= 2 && d10 >= 2 && d1 * d10 == m)
			{
				ans++;
			}
		}
	}
	cout << ans << endl;
}




Measured memory_bytes: 256
while True :
  m,f,r = map(int,input().split())
  x = m + f
  
  if m == f == r == -1 :
    break
  elif m == -1 or f == -1 :
    print('F')

  elif x >= 80 :
    print('A')
  elif x >= 65 :
    print('B')
  elif x >= 50 or (x >= 30 and r >= 50) :
    print('C')
  elif x >= 30 :
    print('D')

  else :
    print('F')


Measured memory_bytes: 5596
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

typedef vector<int> vi;

const int INF = (int)1e7;
int N;
vector<vi> G;
vi d1, d2;

void bfs(int s, vi &d) {
	d[s] = 0;
	queue<int> q;
	q.push(s);
	while (q.size()) {
		int u = q.front();
		q.pop();
		for (int i = 0; i < (int)G[u].size(); ++i) {
			int v = G[u][i];
			if (d[v] > d[u] + 1) {
				d[v] = d[u] + 1;
				q.push(v);
			}
		}
	}
}

int main(void) {
	cin >> N;

	G.resize(N);
	for (int i = 1; i <= N - 1; ++i) {
		int a, b;
		cin >> a >> b;
		G[a - 1].push_back(b - 1);
		G[b - 1].push_back(a - 1);
	}

	d1.resize(N, INF);
	bfs(0, d1);

	d2.resize(N, INF);
	bfs(N - 1, d2);

	int black = 0;
	for (int i = 1; i < N - 1; ++i) {
		if (d1[i] <= d2[i])
			++black;
	}
	int white = N - 2 - black;

	if (black > white)
		cout << "Fennec\n";
	else
		cout << "Snuke\n";
	return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i > 0; i++)
const int MOD =1e9+7;

int main(){
    int n;
    cin >> n;
    int ans = 0;
    for(int i=1; i<=n; i++){
        if(i%2==0) continue;
        int cnt = 0;
        for(int j=1; j<=i; j++){
            if(i%j==0) cnt++;
        }
        if(cnt == 8) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <cmath>

typedef long long ll;

using namespace std;

int main(int argc , char *argv[]) {
    int R,G,B,N;
    int count=0;

    cin >> R >> G >> B >> N;

    for(int r=0 ; r<=N/R ; r++) {
        for(int g=0 ; g<=N/G ; g++) {
            int b=0;
            int inc = (N-r*R-g*G)/B;
            //cout << r << " " << g << " inc : " << inc << endl;
            if(r*R+g*G == N) count++;
            while(inc>0 && b<=N/B) {        
                if(r*R+g*G+b*B == N) count++;
                b+= inc;
            }
        }
    }

    cout << count;

    return 0;
}

Measured memory_bytes: 256
#include  <iostream>
#include  <vector>
#include  <algorithm>

using namespace std;

int main()
{
	int h, w;
	cin >> h >> w;

	vector <vector<int>> s(h, vector<int>(w, 0));
	vector <vector<int>> cnt(h, vector<int>(w, 0));
	
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			char c;
			cin >> c;

			if (c == '.');
			else if (c == '#')  s[i][j] = -1;
		}
	}

	
	for (int i = 0; i < h; i++) {
		vector <int> done(w, 0);
		for (int j = 0; j < w; j++) {
			if (s[i][j] == -1)  continue;
			if (done[j])  continue;

			int l = 0;
			while (j + l < w) {
				if (s[i][j + l] == -1)  break;
				l++;
			}
			for (int k = 0; k < l; k++) {
				cnt[i][j + k] += l;
				done[j + k] = 1;
			}
		}
	}

	for (int j = 0; j < w; j++) {
		vector <int> done(h, 0);
		for (int i = 0; i < h; i++) {
			if (s[i][j] == -1)  continue;
			if (done[i])  continue;

			int l = 0;
			while (i + l < h) {
				if (s[i + l][j] == -1)  break;
				l++;
			}
			for (int k = 0; k < l; k++) {
				cnt[i + k][j] += l;
				done[i + k] = 1;
			}
		}
	}

	int ans = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			ans = max(ans, cnt[i][j] - 1);
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 31616
package main

import (
  "fmt"
)

func maxInt(a ...int) int {m := a[0]; for _, x := range a {if x > m {m = x}}; return m}
func minInt(a ...int) int {m := a[0]; for _, x := range a {if x < m {m = x}}; return m}

func main() {
  var n, a, b int; fmt.Scan(&n, &a, &b)
  fmt.Println(minInt(n*a, b))

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (int i = 0; i < (int)n; i++)

int main()
{
    int N;
    cin >> N;
    int P[N];
    rep(i, N) {
        int a;
        cin >> a;
        P[i] = a - 1;
    }
    int count = 0;
    rep(i, N) {
        if (P[i] == i) {
            if (i == 0 || i < N - 1 && P[i + 1] == i + 1) {
                int t = P[i + 1];
                P[i + 1] = P[i];
                P[i] = t;
                count += 1;
            } else {
                int t = P[i - 1];
                P[i - 1] = P[i];
                P[i] = t;
                count += 1;
            }
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 3E5 + 10;

int n;
int a[MAXN];

int main(){
	scanf("%d", &n);
	int n0 = n * 3;
	for (int i = 0; i < n0; ++i)
		scanf("%d", a + i);
	sort(a, a + n0);
	long long ans = 0;
	for (int i = 0; i < n; ++i)
		ans += a[n + (i << 1)];
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 1408