akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#define DEBUG 0
int* array;
int N;
int L;
int minicount;
void Print_Array(void);
void shift(void);
int Find_min(int start);
int main(){
    scanf("%d %d",&N,&L);
    if(DEBUG)printf("N = %6d\nL = %6d\n",N,L);
    array = malloc(sizeof(int)*N);
    if(array == NULL){
        if(DEBUG)printf("Out of memory\n");
return 1; }
    for(int i = 0; i< N; i++){
        scanf("%d",&array[i]);
    }
    if(DEBUG)Print_Array();
    shift();
}
void shift(void){
    int index = 0;
    int min = Find_min(index);
    printf("%d",min);
while(index+L < N){
if(array[index+L]<min){
    min = array[index+L];
    minicount = 1;
    printf(" %d",min);
}else{
    if(array[index+L] == min){
        if(array[index] != min){
           minicount ++;
}
printf(" %d",min);
}else{
if(array[index]!=min){
    printf(" %d",min);
}else{
    if(minicount>1){
       minicount --;
        printf(" %d",min);
}else{
    min = Find_min(index+1);
    printf(" %d",min);
                    }
} }
}
index++; }
printf("\n");
}

int
Find_min(int start){
int i;
int min = INT_MAX;
minicount = 0;
for(i = 0; i< L; i++){
    if(array[start+i] < min){
        min = array[start+i];
       minicount = 1;
    }else if(array[start+i] == min){
       minicount ++;
} }
return min; }
void Print_Array(void){
    int i;
    printf("array  : ");
    for (i = 0; i< N ; i++){
        printf("%3d",array[i]);
    }
    printf("\n");
}


Measured memory_bytes: 5756
#include <iostream>
using namespace std;
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <math.h>
#include <string>
#include <cstdlib>
#include <fstream>

int main(){
	int h, w, d;
	int px[90001], py[90001];
	int dp[90001]={};

	cin >> h >> w >> d;

	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			int a;
			cin >> a;
			px[a]=i;
			py[a]=j;
		}
	}

	for(int i = d+1; i < h*w+1; i++){
		dp[i]=dp[i-d]+abs(px[i]-px[i-d])+abs(py[i]-py[i-d]);
	}

	int q;
	cin >> q;
	for(int i = 0; i < q; i++){
		int l, r;
		cin >> l >> r;
		cout << dp[r]-dp[l] <<endl;
	}
	
	return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <climits>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string.h>
#include <iomanip>
#include <ctype.h>

#define ll          long long int
#define ull         unsigned long long int
#define pb          push_back
#define pii         pair<int,int>
#define F         first
#define S          second
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define M_PI        3.14159265358979323846
#define mp          make_pair
#define sz(x)       (int)x.size()
#define hell        1000000007
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define eps 1e9
#define all(a)      (a).begin(),(a).end()
const long long INF = (long long) 10000;


using namespace std;
void solve();

void fastIO() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

int main(){
   fastIO();
    solve();
}
//void sieve();
ll pw(ll k,ll x);
ll gcd(ll x,ll y);

bool comp(pair<ll,ll> a,pair<ll,ll> b);
bool comp(pair<ll,ll> a,pair<ll,ll> b){
  if(a.F!=b.F)
  return a.F<b.F;
  else
  return a.S<b.S;
}


void solve(){

  int n,k,q;
  cin>>n>>k>>q;
  int a[n];
  for(int i=0;i<n;i++)
  a[i]=k-q;
  
  while(q--){
    int x;
    cin>>x;
    x--;
    a[x]++;
  }
  
  forn(i,0,n){
    if(a[i]<=0)
    cout<<"No\n";
    else
    cout<<"Yes\n";
  }

}



///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1

ll gcd(ll x,ll y){
  if(x==0)
  return y;
  else
  return gcd(y%x,x);
}


ll pw(ll k,ll x){
  if(x==0)
  return 1;
  if(x&1)
  return ((pw(k,x-1)%hell)*k%hell)%hell;
  else
  return ((pw(k,x/2)%hell)*(pw(k,x/2)%hell))%hell;
}

/*void sieve(){

  for(int i=2;i<=1000000;i++){
    if(prime[i]==true){
      for(int j=i*i;j<=1000000;j+=i)
      prime[j]=false;
    }
  }

}*/


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int a, b;

	scanf("%d%d", &a, &b);
	if (a < b) printf("a < b\n");
	else if (a > b) printf("a > b\n");
	else printf("a == b\n");
	return 0;
}



Measured memory_bytes: 2040
N=int(input())

def listdict(s1):
    ret={}
    rets=""
    for i in s1:
        tmp=ret.get(i,0)
        if tmp==0:
            ret[i]=1
        else:
            ret[i]+=1
    ret_sorted = sorted(ret.items(), key=lambda x:x[0])
    
    for k in range(len(ret_sorted)):
        rets+=str(ret_sorted[k][0])
        rets+=str(ret_sorted[k][1])
    return rets

sN=[listdict(input()) for _ in range(N)]

d1={}
for i in sN:
    tmp=d1.get(i,0)
    if tmp==0:
        d1[i]=1
    else:
        d1[i]+=1
ret=0
for i in d1.values():
    if i ==1:
        continue
    for j in range(1,i):
        ret+=j
print(ret)

Measured memory_bytes: 20080
n = list(range(1,int(input())+1))
p = list(map(int,input().split()))
count = 0
ans = 'NO'

for i in range(len(n)):
  if n[i] == p[i]:
    continue
  else:
    count+=1
if count == 0 or count == 2:
  ans = 'YES'
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vd=vector<double>;
using vvd=vector<vd>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using vs=vector<string>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.141592653589793

template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	vd x(3),y(3),e(3);
	cin>>x[0]>>y[0]>>x[1]>>y[1]>>x[2]>>y[2];
	e[0]=hypot(x[0]-x[1],y[0]-y[1]);
	e[1]=hypot(x[2]-x[1],y[2]-y[1]);
	e[2]=hypot(x[0]-x[2],y[0]-y[2]);
	double m=*max_element(all(e));
	double s=(e[0]+e[1]+e[2])/2;
	double S=sqrt(s*(s-e[0]))*sqrt((s-e[1])*(s-e[2]));
	double R=S/s;
	double l=0,r=1000;
	while(abs(r-l)>EPS){
	    double d=(r+l)/2;
	    double x=(R-d)*m/R;
	    if(x>=d*2){
	        l=d;
	    }else{
	        r=d;
	    }
	}
	fcout(12)<<l<<endl;
	return 0;
}


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

int main() {
    int n, m, x;
    cin >> n >> m >> x;
    bool tg[101];
    for(int i = 0;  i < 101; i++)
        tg[i] = 0;
    for(int i = 0; i < m; i++) {
        int x;
        cin >> x;
        tg[x] = 1;
    }
    int cnt = 0, ans = (int)1e9;
    for(int i = x; i > 0; i--) {
        if (tg[i])
            cnt++;
    }
    ans = min(ans, cnt);
    //cerr << cnt << " is" << endl;
    cnt = 0;
    for(int i = x; i <= n; i++) {
        if (tg[i])
            cnt++;
            //cerr << "sq on " << i << ' ' << tg[i] << endl;
    }
    ans = min(ans, cnt);
    //cerr << cnt << " is" << endl;
    cout << ans << endl;
    return 0;
    
}


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

struct Job{
  char name[20];
  int time;
};

Job process[100010];
int head = 0;
int tail;

void enqueue( Job x );
Job dequeue();

int main(){
  int N, Q; cin >> N >> Q;
  tail = N;
  for( int i = 0; i < N; i++ ){
    cin >> process[i].name >> process[i].time;
  }

  int sum = 0;
  while( head != tail ){
    Job tmp = dequeue();
    if( tmp.time > Q ){
      sum += Q;
      tmp.time -= Q;
      enqueue( tmp );
    }else{
      sum += tmp.time;
      cout << tmp.name << " " << sum << endl;
    }
  }
}

void enqueue( Job x ){
  process[tail] = x;
  tail++;
  if( tail >= 100005 ) tail = 0; 
}

Job dequeue(){
  Job tmp = process[head];
  head++;
  if( head >= 100005 ) head = 0;
  return tmp;
}



Measured memory_bytes: 5436
import sys
S=raw_input()

cnt=0
while len(S)>1:
	#print S,cnt
	if S[0]==S[-1]:
		S=S[1:-1]
	elif S[0]!=S[-1] and S[0]=="x":
		cnt+=1
		S=S+"x"
	elif S[0]!=S[-1] and S[-1]=="x":
		S="x"+S
		cnt+=1
	else:
		print "-1"
		sys.exit()
print cnt

Measured memory_bytes: 2948
//I am so vegetable
//#define err
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define pb push_back
#define in insert
#define er erase
#define ct count
#define ep empty
#define _for(i,a,b) for(int i = (a);i<(b);++i)
#define _rfor(i,a,b) for(int i = (a);i>(b);--i)
#define _sfor(p,st) for(auto &p:st)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const double eps = 1e-6;
const double pi = acos(-1.0);
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll qpow(ll x, ll y) { ll ans = 1; for (; y > 0; y >>= 1) { if (y & 1)ans *= x; x *= x; }return ans; }
ll qpow(ll x, ll y, int MOD) { ll ans = 1; for (; y > 0; y >>= 1) { if (y & 1)ans = ans*x%MOD; x = x*x%MOD; }return ans; }
void exgcd(ll a,ll b,ll &x,ll &y){
    if(!b){x=1;y=0;return;}
    exgcd(b,a%b,x,y);
    ll X=x;
    x=y; y=X-a/b*y;
}
ll inv(ll x, int mod = MOD) { return qpow(x, mod - 2,mod); }
ll m_m(ll a){ return (a%MOD+MOD)%MOD; }


    
signed main() {
    //ifstream cin("E:\\acm dream\\in.in");
	//ofstream cout("E:\\acm dream\\out.out");
	FIO;
    #ifdef err
	double be = clock();
    #endif

    string s;cin>>s;
    _for(i,0,s.size()){
        if(i+1<s.size()&&s[i]==s[i+1]){
            cout<<i+1<<' '<<i+2;
            return 0;
        }
        if(i+2<s.size()&&s[i]==s[i+2]){
            cout<<i+1<<' '<<i+3;
            return 0;
        }
    }
    cout<<-1<<' '<<-1;
    
    #ifdef err
	double en = clock();
    cout<<"time: "<<fixed<<setprecision(8)<<en-be;
    #endif
	return 0;
}

Measured memory_bytes: 3776
#include <bits/stdc++.h>
using namespace std;
#define int long long

const int MAX_N = 100000;
const int MOD = 1000000007;

int N, A[MAX_N];
int cnt[MAX_N];

int Solve()
{
	for (int i = N - 1; i > 0; i -= 2)
	{
		if (cnt[i] != 2) return 0;
	}
	for (int i = N - 2; i >= 0; i -= 2)
	{
		if (cnt[i] != 0) return 0;
	}
	if ((N&1) && cnt[0] != 1) return 0;
	int ans = 1;
	for (int i = 0; i < N/2; i++) (ans *= 2) %= MOD;
	return ans;
}

signed main()
{
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
		cnt[A[i]]++;
	}
	printf("%lld\n", Solve());
	return 0;
}

Measured memory_bytes: 1792
n, a, b = map(int, input().split())
def divi(n):
    n1 = n%10
    n2 = n//10 %10
    n3 = n//100 %10
    n4 = n//1000 %10
    n5 = n//10000 %10
    return n1, n2, n3, n4, n5
ans = 0
for j in range(1,n+1):
    count = 0
    for s in divi(j):
        count += s
    if a<=count<=b:
        ans += j
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {


  
string S;
  cin >>S;
  int x=S.size();
  bool answer=true;
  if(S.at(0) !='A') {
    answer=false;
  }
  
  
  int y=0;
  repl(i,2,x-1) {
  if(S.at(i) =='C') {
y++;
  }
  }
  if(y!=1) {
    answer=false;
  }
  
  
  int count=0;
  rep(i,x) {
    if(S.at(i)>'Z') {
      count++;
    }
  }
  //cout<<count<< endl;
if(count!=x-2) {
answer=false;
}
  
  if(answer) {
cout <<"AC"<< endl;
  }
else {
cout<< "WA" << endl;
}
}



Measured memory_bytes: 256
import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline
def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')
#import numpy as np

from collections import deque

def main():
	n,q=MI()
	E=[[] for _ in range(n+1)]
	X=[0]*(n+1)

	for _ in range(n-1):
		a,b=MI()
		E[a].append(b)
		E[b].append(a)
	for _ in range(q):
		p,x=MI()
		X[p]+=x
	#print(E)

	Q=deque([1])

	while Q:
		#print(Q)
		now=Q.popleft()
		#print(now)
		if E[now]!=[]:
			for i in E[now]:
				if E[i]!=[]:
					Q.append(i)
					X[i]+=X[now]
			E[now]=[]
	print(*X[1:])


if __name__ == "__main__":
	main()

Measured memory_bytes: 93516
N=int(input())
W=list(map(int,input().split()))
X=0
for i in range(N-1): #0~N-2
    X=X+W[i]
Y=W[N-1]
A=abs(X-Y)

a=N-2 #最初にYに移す番号
for i in range(N-2): 
    X=X-W[a]
    Y=Y+W[a]
    B=abs(X-Y)
    if B<A:
        A=B
        a=a-1
    else:
        break
print(A)

Measured memory_bytes: 3064
import Data.Functor( (<$>))

main = do
    n <- read <$> getLine
    let
	almostAnswer = filter predicate [1..n]
	  where
	    predicate i
	      = let
		    str = show i
		    p1 = '3' `elem` str
		    p2 = i `mod` 3 == 0
		in
		    p1 || p2

    (\i -> putStr $ " "++(show i)) `mapM_` almostAnswer
    putStrLn ""



Measured memory_bytes: 4144
def main():
    N, M = map(int, input().split())
    A = [int(x) for x in input().split()]
    changes = []
    for i in range(M):
    	changes.append([int(e) for e in input().split(" ")])
    changes.sort(key=lambda x:(x[1],x[0]),reverse = True)
	
    cnt = N
    for i in changes:
    	A.extend([i[1]] * min(i[0],cnt))
    	cnt -= min(i[0],cnt)
    A.sort()
    A.reverse()
    A = A[:N]
    print(sum(A))
if __name__ == "__main__":
    main()

Measured memory_bytes: 34496
#define INF 10000000000
#define MOD 1000000007

#if 1   // use_templates

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define rep(i, up) for (ll i = 0; i < (up); ++i)
#define repp(i, up) for (ll i = 0; i <= (up); ++i)
#define rrep(i, lo, up) for (ll i = (lo); i < (up); ++i)
#define rrepp(i, lo, up) for (ll i = (lo); i <= (up); ++i)
#define eep(i, lo, up) for ((i) = (lo); (i) < (up); ++(i))
#define eepp(i, lo, up) for ((i) = (lo); (i) <= (up); ++(i))
#define feach(it, vec) for (auto it = (vec).begin(); it != (vec).end(); ++it)


ll gcd(ll a, ll b);

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;
}

#endif  // end of use_templates


int main()
{
    ll h, w, m;
    cin >> h >> w >> m;
    map<ll, ll> hs, ws;
    vector<pair<ll, ll>> mp(m);
    rep(i, m) {
        ll hh, ww;
        cin >> hh >> ww;
        ++hs[hh];
        ++ws[ww];
        mp[i].first = hh;
        mp[i].second = ww;
    }
    ll hc = -1, wc = -1;
    set<ll> hms, wms;
    feach(ith, hs) {
        if (hc < ith->second) {
            hms.clear();
        }
        if (hc <= ith->second) {
            hc = ith->second;
            hms.insert(ith->first);
        }
    }
    feach(itw, ws) {
        if (wc < itw->second) {
            wms.clear();
        }
        if (wc <= itw->second) {
            wc = itw->second;
            wms.insert(itw->first);
        }
    }
    ll cnt = 0;
    feach(itm, mp) {
        if (hms.find(itm->first) != hms.end() && wms.find(itm->second) != wms.end()) {
            ++cnt;
        }
    }
    if (cnt == hms.size() * (ll)wms.size()) {
        cout << hc + wc - 1 << endl;
    } else {
        cout << hc + wc << endl;
    }
    return 0;
}


Measured memory_bytes: 73092
from itertools import permutations
from math import sqrt

n=int(input())
permlist = list(permutations(range(n)))
#print('permlist: {}'.format(permlist))

x = []
y = []
for i in range(n):
    xi,yi = list(map(int,input().split()))
    x.append(xi)
    y.append(yi)

lengths = 0.0
for p in permlist:
    length = 0.0
    for _ in range(len(p)-1):
        i = p[_]
        j = p[_+1]
        #print('i: {} j:{}'.format(i,j))
        length += sqrt( (x[i]-x[j])**2 + (y[i]-y[j])**2 )
    #print('length: {}'.format(length))
    lengths += length

print(lengths/len(permlist))


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

int main()
{
    long long l, r;
    long long min = 100000;
    long long count = 0;
    cin >> l >> r;
    if(l%2019+(r-l)>2019){
        cout << 0 << endl;
        return 0;
    }else{
        for(int i = 0;i<r-l;i++){
            for(int j=1;j<r-l+1;j++){
                if(((l+i)%2019*(l+j)%2019)%2019<min){
                    min = ((l+i)%2019*(l+j)%2019)%2019;
                }
            }
        }
        cout << min << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = (1e+9) + 7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-4;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int cc[1 << 20];
int cm[1 << 20];
int main() {
	int n; string s; cin >> n >> s;
	rep(i, n) {
		if (s[i] == 'C') {
			cc[i + 1] = cc[i] + 1;
		}
		else {
			cc[i + 1] = cc[i];
		}
		if (s[i] == 'M') {
			cm[i + 1] = cm[i] + 1;
		}
		else {
			cm[i + 1] = cm[i];
		}
	}
	int q; cin >> q;
	rep(aa, q) {
		int k; cin >> k;
		ll now = 0, out = 0;
		rep(i, k) {
			if (s[i] == 'M') {
				now += cc[k] - cc[i];
			}
		}
		rep(i, n){
			//cout << now << endl;
			if(s[i]=='D') {
				out += now;
			}
			else if (s[i] == 'M') {
				now -= cc[min(n,i + k)] - cc[i];
			}
			if (i + k < n) {
				if (s[i + k] == 'C') {
					now += cm[min(n,i + k)] - cm[i + 1];
				}
			}
		}
		cout << out << endl;
	}
	return 0;
}


Measured memory_bytes: 9604
import collections

ans=0
dic={}
n=int(input())
for i in range(n):
  s=input()
  sl=[i for i in s]
  sl.sort()
  ss=tuple(sl)

  if ss not in dic:
    dic[ss]=1
  else:
    ans+=dic[ss]
    dic[ss]+=1

print(ans)

Measured memory_bytes: 28048
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>

using namespace std;
typedef long long ll;
const ll INF   = 1000000000000000000;
const ll MAX_N = 100 + 1;
const ll MAX_V = 1000 + 1;
ll w[MAX_N];
ll v[MAX_N];
ll dp[MAX_N][MAX_V * MAX_N];

int main() {

  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  ll N, W;
  cin >> N >> W;

  ll max_v = 0;
  for(ll i = 1; i <= N; i++) {
    cin >> w[i] >> v[i];
    max_v += v[i];
  }

  for(ll i = 0; i < MAX_N; i++) {
    for(ll j = 0; j < MAX_V * MAX_N; j++) {
      dp[i][j] = INF;
    }
  }

  dp[0][0] = 0;
  
  for(ll i = 1; i <= N; i++) {
    for(ll j = 0; j <= max_v; j++) {
      if(j - v[i] < 0) dp[i][j] = dp[i-1][j];
      else dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i]] + w[i]);
    }
  }

  ll ans = 0;
  for(ll j = 0; j <= max_v; j++) {
    if(dp[N][j] > W) continue;
    ans = max(ans, j);
  }
  
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 82928
#include<stdio.h>
#define MAX 500000
#define INFTY 2000000000
int L[MAX/2+2],R[MAX/2+2];
int count;
void merge(int *,int ,int ,int ,int);
void mergesort(int * ,int ,int,int);
int main(){
  int A[MAX],n,i;
  count=0;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&A[i]);
  mergesort(A,n,0,n);
  for(i=0;i<n;i++){
    if(i==n-1)
      printf("%d\n",A[i]);
    else
      printf("%d ",A[i]);
  }
  printf("%d\n",count);
  return 0;
}
void merge(int *A,int n,int left,int mid,int right){
  int i,j,k,num1,num2;
  num1=mid-left;
  num2=right-mid;
  for(i=0;i<num1;i++)
    L[i]=A[left+i];
  for(j=0;j<num2;j++)
    R[j]=A[mid+j];
  L[num1]=INFTY;
  R[num2]=INFTY;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    count++;
    if(L[i]<=R[j]){
      A[k]=L[i];
      i++;
    }
    else{
      A[k]=R[j];
      j++;
    }
  }
}
void mergesort(int *A,int n,int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergesort(A,n,left,mid);
    mergesort(A,n,mid,right);
    merge(A,n,left,mid,right);
  }
}



Measured memory_bytes: 5672
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef deque<int> DI;
typedef deque<LL> DLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const LL MOD = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

const LL MAXN = 1e4+10;
VLL adj[MAXN];
LL Cs[MAXN], Ds[MAXN];

int main() {
	sll(n);
	rep(i, 0, n-1) {
		sll(a); sll(b);
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	rep(i, 0, n)	Cs[i] = scanLong();
	sort(Cs, Cs+n);
	LL pos = n-1;
	queue<LL> Q; Q.push(1);
	LL ans = 0;
	while(!Q.empty()) {
		LL curr = Q.front(); Q.pop();
		Ds[curr] = Cs[pos];
		if(curr != 1)	ans +=	Cs[pos];
		pos--;
		rep(it, adj[curr].begin(), adj[curr].end()) {
			if(Ds[*it] == 0)	Q.push(*it);
		}
	}
	pll(ans); nl;
	rep(i, 1, n+1)	pll(Ds[i]); nl;
}

Measured memory_bytes: 1152
import sys


def input():
    return sys.stdin.readline()[:-1]

# N = int(input())
# A = [int(x) for x in input().split()]
# a, b, c = map(int, input().split())
# name1 = str(input())
# alph = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}
# b = list(map(lambda x: math.ceil(x/10)*10, a))


n = int(input())
l = list(map(int, input().split()))
if max(l) < sum(l)-max(l):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
sa = input()
sb = input()
sc = input()
if sa[0] == "a":
    k = "a"
    sa = sa[1:]
elif sa[0] == "b":
    k = "b"
    sa = sa[1:]
elif sa[0] == "c":
    k = "c"
    sa = sa[1:]
while True:
    if k == "a":
        if sa != "":
            k = sa[0]
            sa = sa[1:]
        else:
            print("A")
            exit()
    elif k == "b":
        if sb != "":
            k = sb[0]
            sb = sb[1:]
        else:
            print("B")
            exit()
    elif k == "c":
        if sc != "":
            k = sc[0]
            sc = sc[1:]
        else:
            print("C")
            exit()

Measured memory_bytes: 3064
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class Main {

    public static void main(String[] args) {
       
        Scanner sc = new Scanner(System.in);
        
       List<Integer> list = new ArrayList<>();
       
       
       int count = 0;
       
      while(true){
         
          list.add(sc.nextInt());
          
          
          if(count == list.get(0)){
             break;
          }
          
          count++;
          
      }
        int min;
        
        if(list.get(0) != 0){
            min = list.get(1); 
        }else{
            min = 0;
        }
        
        
        int max;
        
        if(list.get(0) != 0){
            max = list.get(1); 
        }else{
            max = 0;
        }
        
        long add = 0;
        
       for(int i=1; i<list.size(); i++){
           if(min > list.get(i)) min = list.get(i);
           if(max < list.get(i)) max = list.get(i);
           add = add + list.get(i);
       }
        
        System.out.println(min +" "+ max +" "+ add);
           
       
    }
}
       

   




Measured memory_bytes: 42368
N = int(input())


candidates = []
for base in [6, 9]:
    n = base
    while n <= N:
        candidates.append(n)
        n *= base



# DP
counts = [i for i in range(N + 1)]
for c in candidates:
    for i in range(c, N+1):
        counts[i] = min(counts[i], counts[i-c] + 1)

print(counts[N])

Measured memory_bytes: 44784
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
string s;
int main(){
	cin >> s;
	for(int i=0;i<3;i++){
		if(s[i]==s[i+1]){
			cout << "Bad" << endl;
			return 0;
		}
	}
	cout << "Good" << endl;
	return 0;
}

Measured memory_bytes: 764
#include <cstdio>
#include <iostream>
#include <stdlib.h>

using namespace std;

namespace {

struct Node {
  char suit; // S, H, C, D
  int value;
};

// SelectionSort sorts the array |a| in ascending order, and then returns
// the number of swap operations.
int SelectionSort(Node* a, int n) {
  int nswap = 0;

  for (int i = 0; i < n; ++i) {
    int minj = i;
    for (int j = i + 1; j < n; ++j) {
      if (a[j].value < a[minj].value) {
        minj = j;
      }
    }
    if (i != minj) {
      ++nswap;
      const Node t = a[i];
      a[i] = a[minj];
      a[minj] = t;
    }
  }

  return nswap;
}

// BubbleSort sorts the array |a| in ascending order, and then returns
// the number of swap operations.
int BubbleSort(Node* a, int n) {
  int nswap = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = n - 1; j >= 1; --j) {
      if (a[j].value < a[j - 1].value) {
        const Node t = a[j - 1];
        a[j - 1] = a[j];
        a[j] = t;
        ++nswap;
      }
    }
  }
  return nswap;
}

void Print(const Node* a, int n) {
  for (int i = 0; i < n; ++i) {
    if (i > 0) printf(" ");
    printf("%c%d", a[i].suit, a[i].value);
  }
  printf("\n");
}

bool IsStable(const Node* a, const Node* b, int n) {
  for (int i = 0; i < n; ++i) {
    if (a[i].value == b[i].value && a[i].suit != b[i].suit) {
      return false;
    }
  }
  return true;
}

} // namespace

int main() {
  int n;
  cin >> n;
  Node a[36];
  Node b[36];

  char buf[4];
  for (int i = 0; i < n; ++i) {
    cin >> buf;
    a[i].suit = buf[0];
    a[i].value = atoi(&buf[1]);
    b[i] = a[i];
  }

  BubbleSort(a, n);
  Print(a, n);
  printf("Stable\n");

  SelectionSort(b, n);
  Print(b, n);
  if (IsStable(a, b, n)) {
    printf("Stable\n");
  } else {
    printf("Not stable\n");
  }
  return 0;
}

Measured memory_bytes: 1168
#include <cstdio>

int main()
{
    int no_of_operations, k;
    scanf("%d %d", &no_of_operations, &k);

    int value = 1;
    while(no_of_operations--)
    {
        value += (k < value ? k : value);
    }

    printf("%d\n", value);
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  bool p = true;
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
    if (a.at(i) % 2 == 0) {
      if (a.at(i) % 3 != 0 && a.at(i) % 5 != 0) {
        p = false;
        break;
      }
    }
  }
  if (p) {
    cout << "APPROVED" <<endl;
  }
  else {
    cout << "DENIED" <<endl;
  }
}

Measured memory_bytes: 256
def f(n):
    if n%2==0:
        return n/2
    else:
        return 3*n + 1

a = int(input())

if a==4 or a==2 or a==1:
    print(4)
else:
    count = 0
    i=0
    while(count!=2):
        i+=1
        # print("{}".format(a),end=",")
        if a==4:
            count+=1
        a = int(f(a))
    print(i)

Measured memory_bytes: 3060
if __name__ == '__main__':
    n, m = map(int, input().split())
    c = list(map(int, input().split()))
    dp = [float('inf') for _ in range(n+1)]
    dp[0] = 0
    for i in range(n+1):
        for j in range(m):
            if i - c[j] >= 0:
                dp[i] = min(dp[i-c[j]]+1, dp[i])

print(dp[n])



Measured memory_bytes: 7388
import java.util.ArrayList;
import java.util.Scanner;


public class Main {
    
    public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		class qube{
			Scanner sc = new Scanner(System.in);
			Integer [] face = new Integer[6];
			ArrayList<Integer []> box = new ArrayList<Integer []>();
			Integer i,j,k,n=0,dump=0,check,st=101,nd=101,p;

			qube(){
				n = sc.nextInt();
			}
			void load(){
				this.box.add(this.face.clone());
			}

			void areg(){
				for(i=0;i<6;i++){
					face[i] = sc.nextInt();
				}

				this.judge();
				for(k=0;;k++){
					if(this.face[1]==this.nd){
						break;
					}
					this.move("N");
					if(this.k.equals(3)){
						this.move("E");
					}
				}
				while(true){
					if(this.face[0]==this.st){
						break;
					}
					this.move("E");
				}
			}

			void swap(int a,int b){
				dump = this.face[a];
				this.face[a] = this.face[b];
				this.face[b] = dump;

			}
			void judge(){
				st = 101;
				nd = 101;
				for(i=0;i<6;i++){
					if(st>face[i]){
						st = face[i];
						p=i;
					}
				}
				for(i=0;i<6;i++){
					if(face[i] != st && nd>face[i] && (5-p) != i) nd = face[i];
				}
			}

			void move(String es){
				if(es.equals("E")){
					swap(0,2);
					swap(0,5);
					swap(0,3);
				}
				else if(es.equals("N")){
					swap(4,5);
					swap(4,1);
					swap(4,0);
				}

			}
			boolean comp(){
				check = 0;
				for(i=0;i<3;i++){
					for(j=0;j<3;j++){
						if(this.box.get(0)[i]==face[j] && this.box.get(0)[5-i]==face[5-j]){
							check++;
							break;
						}
					}
				}
				if(check == 3){
					return true;
				}
				else{
					return false;
				}
			}
		}
		Integer i;

		qube q = new qube();
		q.areg();
		q.load();
		for(i=0;i<(q.n-1);i++){
			q.areg();
			if(q.comp() == true){
				System.out.println("No");
				break;
			}
			else{
				q.load();
			}

		}
		if(i.equals((q.n-1))){
			System.out.println("Yes");
		}
	}

}



Measured memory_bytes: 28020
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;
int main(void){
    int A,B,C;
    cin >>A>>B>>C;
    int ans;
    ans=A+B;

    if(ans>=C){
        cout<< "Yes" << endl;
    }else{
        cout<< "No" <<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*
    s.find_by_order(k) ---> returns iterator to the element at index(from 0) k
    s.order_of_key(val) ---> number of elements that are strictly smaller than the given value
*/
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int tc; cin >> tc; cin.ignore(); while(tc--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
ll xpow(ll n, ll m){if(m==0){return 1;}else{ll x = xpow(n, m/2);if(m&1){return x*x*n;}else{return x*x;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}

int main() {
	fast();

    /*NA – JEONG – MO – SA – JI – MI – DA – CHAE – TZU*/
    
    ll n, k, s;
    cin >> n >> k >> s;
    vl ans(n);
    for(int i=0; i<k; i++){
        ans[i] = s;
    }
    ll val = 1;
    if(s>100000){
        val = 1;
    }
    else{
        val = 1e9;
    }
    for(ll i=k; i<n; i++){
        ans[i] = val;
    }
    outv(ans);
}

Measured memory_bytes: 2176
#include <iostream>
using namespace std;

int main(){
  int N,index=1;
  cin >> N;
  int a[N];
  for(int i=0;i<N;i++)
    cin >> a[i];

  for(int i=0;i<100000;i++){
    if(index==2){
      cout << i << endl;
      return 0;
    }
    index=a[index-1];
  }
  cout << -1 << endl;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;

int main(void) {
    int n;cin>>n;
    int R[n];
    for (int i = 0; i < n; i++) {
        cin>>R[i];
    }
    int mi = R[0];
    int ma = R[1] - R[0];
    for (int i = 2; i < n; i++) {
        if (mi > R[i - 1]) mi = R[i - 1];
        if (ma < R[i] - mi) ma = R[i] - mi;
    }
    cout << ma << endl;
    return 0;
}


Measured memory_bytes: 3860
n = int(input())
ans = [0 for i in range(4)]
sList = []
for i in range(n):
    sList.append(input())

for s in sList:
    if "AC" == s:ans[0]+=1
    elif "WA" == s:ans[1]+=1
    elif "TLE" == s:ans[2]+=1
    elif "RE" == s:ans[3]+=1

print("AC x {}" .format(ans[0]))
print("WA x {}" .format(ans[1]))
print("TLE x {}" .format(ans[2]))
print("RE x {}" .format(ans[3]))

Measured memory_bytes: 16216
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;
using llong = long long;
using ullong = unsigned long long;

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection)  (collection).begin(), (collection).end()
#define loop(i, times) for (llong i = 0; i < times; i++)
#define rloop(i, times) for (llong i = times -1; 0 <= i; i--)

std::chrono::system_clock::time_point  start;

void TimeStart(void)
{
	start = std::chrono::system_clock::now();
}

void TimeEnd(void)
{
	auto time = std::chrono::system_clock::now() - start;
	auto msec = std::chrono::duration_cast<std::chrono::milliseconds>(time).count();
	cerr << endl << msec << " msec " << endl;
}

#endif


int main(void)
{
	llong n;  cin >> n;
	vector<llong> v(n);
	vector<llong> c(n);

	loop(i, n)
		cin >> v[i];

	loop(i, n)
		cin >> c[i];

	llong sum_v = 0;
	llong sum_c = 0;
	loop(i, n)
	{
		if (v[i] > c[i])
		{
			sum_v += v[i];
			sum_c += c[i];
		}
	}

	cout << sum_v - sum_c;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin>>s;
  int a,b;
  a=(s[0]-'0')*10+(s[1]-'0');
  b=(s[2]-'0')*10+(s[3]-'0');
  int flag=0;
  if(0<a&&a<13)
  {
    flag|=1;
  }

  if(0<b&&b<13)
  {
    flag|=2;
  }
  if(flag==0)cout<<"NA"<<endl;
  if(flag==1)cout<<"MMYY"<<endl;
  if(flag==2)cout<<"YYMM"<<endl;
  if(flag==3)cout<<"AMBIGUOUS"<<endl;




  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        rep(i, n) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) return x;
        int r = root(par[x]);
        diff_weight[x] += diff_weight[par[x]];
        return par[x] = r;
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

int main() {
    int N, M; cin >> N >> M;
    UnionFind<int> uf(N);
    rep(i, M) {
        ll a, b; cin >> a >> b; a--; b--;
        uf.merge(a, b, 0);
    }
    map<ll, ll> m;
    rep(i, N) m[uf.root(i)]++;
    ll ans = 0;
    for(auto x : m) chmax<ll>(ans, x.second);
    cout << ans << endl;
}


Measured memory_bytes: 17856
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

#define Len 10001 
int main()
{
    char day[3];
    int ans;
    scanf("%s", day);

    if (day[0] == 'S'){
        ans = (day[1] == 'U') ? 7 : 1;     
    }else if (day[0] == 'F') ans = 2;
    else if (day[0] == 'T') ans = (day[1] == 'H') ? 3 : 5;
    else if (day[0] == 'W') ans = 4;
    else if (day[0] == 'M') ans = 6;

    printf("%d\n", ans);
    
    return 0;
}   

Measured memory_bytes: 128
using System;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            char [] input = ReadCharArray();

            int ans = 0;

            foreach(char c in input){
                int i = int.Parse(c.ToString());
                if(i == 1){
                    ans += 1;
                }
            }

            Console.WriteLine(ans);

        }
        static string[] ReadArray(){return Console.ReadLine().Split((' '));}
        static char[] ReadCharArray(){return Console.ReadLine().ToCharArray();}
    }
}

Measured memory_bytes: 11092
#include <stdio.h>

int main(int argc, const char * argv[])
{
    int i,j,H,W;
    while(1){
        scanf("%d %d",&H,&W);
        if(H==0 && W==0){
            break;
        }else{
            for(i=0;i<H;i++){
                for(j=0;j<W;j++){
                    if((i+j)%2==1){
                        printf(".");
                    }else{
                        printf("#");
                    }
                }
                printf("\n");
            }
            printf("\n");
        }
        
    }

    return 0;
}

Measured memory_bytes: 572
#include<bits/stdc++.h>
#define ll long long
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#define MAX 1000000007
using namespace std;
int main()
{
 	speed_up
    string s,t;
    cin>>s>>t;ll ct=0;
    for(ll i=0;i<3;i++)
    {
    	if(s[i]==t[i]) ct++;
    	
	}
	cout<<ct;
	
	
 return 0;
}

Measured memory_bytes: 256
//#include"bits/stdc++.h"
#include<iostream>
#include<ostream>
#include<vector>
#include<string>
#include<algorithm>

#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)


using namespace std;
using ll = long long;

void solve();

int main() {

   solve();
   return 0;

}

void solve() {

	ll n;
	cin >> n;
	REP(i, n) {

		ll score=0;
		ll runner=0;
		ll out=0;
		string in;

		while (out < 3) {
			cin >> in;
			if (in == "OUT") {
				out++;
			}
			else if (in == "HIT") {
				runner++;
				if (runner == 4) {
					score++;
					runner = 3;
				}
			}
			else if (in == "HOMERUN") {
				score += (runner + 1);
				runner = 0;
			}
		}
		cout << score << endl;
	}

}

Measured memory_bytes: 3132
import java.util.Scanner;
 public class Main{

	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a=new int[n]; 
        for( int i = 1; i<=n; i++ ){
            int x=i;
          if(x%3==0){
              System.out.print(" "+i);
          }
          else{
              while(true){
                  if(x%10==3){
                     System.out.print(" "+i);
                      break;
                  }
                  x=x/10;
                  if(x==0)
                      break;
                
               }
          }
        }
        System.out.println();
        sc.close();
	}
 }


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

enum DICE{TOP, BOTTOM, FRONT, RIGHT, BACK, LEFT, END};
enum ROLL{NORTH_R, SOUTH_R, EAST_R, WEST_R, LEFT_R, RIGHT_R, END_R};

const int right_by_tf[6][6] = {
  {-1,  3,  5,  2,  4, -1},
  { 4, -1,  1,  6, -1,  3},
  { 2,  6, -1, -1,  1,  5},
  { 5,  1, -1, -1,  6,  2},
  { 3, -1,  6,  1, -1,  4},
  {-1,  4,  2,  5,  3, -1},
};
const enum DICE rolls[6][4] = {
  {BOTTOM, FRONT,    TOP,  BACK},//south
  {   TOP,  LEFT, BOTTOM, RIGHT},//east
  {   TOP, FRONT, BOTTOM,  BACK},//north
  {   TOP, RIGHT, BOTTOM,  LEFT},//west
  { RIGHT,  BACK,   LEFT, FRONT},//left
  {  LEFT,  BACK,  RIGHT, FRONT} //right
};
class Dice{
private:
  int dice[6];

public:
  Dice(int top, int front){
    dice[TOP] = top, dice[BOTTOM] = 7 - top;
    dice[FRONT] = front, dice[BACK] = 7 - front;
    dice[RIGHT] = right_by_tf[top - 1][front - 1]; dice[LEFT] = 7 - dice[RIGHT];
  }

  void roll_to(int  ro){
    int tmp = dice[rolls[ro][0]];
    for(int i = 0; i < 3; i++)dice[rolls[ro][i]] = dice[rolls[ro][i + 1]];
    dice[rolls[ro][3]] = tmp;
  }
  int at(int i){
    return dice[i];
  }
};
int grid[400][400], hight[400][400];
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

void drop(int top, int front, int x, int y){
  Dice dice(top, front);
  int h = hight[y][x];
  int dir = -1, maxi = 3;
  for(int i = 0; i < 4; i++){
    if(hight[y + dy[i]][x + dx[i]] >= h)continue;
    if(maxi < dice.at(i + 2)){
      maxi = dice.at(i + 2);
      dir = i;
    }
  }
  if(dir == -1){
    grid[y][x] = dice.at(TOP);
    hight[y][x]++;
  }else{
    dice.roll_to(dir);
    drop(dice.at(TOP), dice.at(FRONT), x + dx[dir], y + dy[dir]);
  }
}


int main(){
  int n, top, front;
  while(cin >> n, n){
    memset(grid, 0, sizeof(grid));
    memset(hight, 0, sizeof(hight));
    for(int i = 0; i < n; i++){
      cin >> top >> front;
      drop(top, front, 200, 200);
    }
    vector<int> ans(7);
    for(int i = 0; i < 400; i++){
      for(int j = 0; j < 400; j++){
	ans[grid[i][j]]++;
      }
    }


    
    for(int i = 1; i < 6; i++){
      cout << ans[i] << " ";
    }
    cout << ans[6] << endl;
  }
  return 0;
}

Measured memory_bytes: 2452