akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n, k;
    char out[10][8] = {"0111111","0000110","1011011","1001111","1100110","1101101","1111101","0100111","1111111","1101111"};
    char bit[8];
    while (cin >> n, n != -1) {
          for (int i = 0; i < 7; ++i) bit[i] = '0';
          bit[7] = '\0';
          for (int i = 0; i < n; ++i) {
              cin >> k;
              for (int j = 0; j < 7; ++j) {
                  if (out[k][j] != bit[j]) {
                     cout << 1;
                     bit[j] = (bit[j] == '0' ? '1' : '0');
                  }
                  else cout << 0;
              }
              cout << endl;
          }
    }
    return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int ans = 0;
		for (int i = 0; i < n; i++)
			ans += -Integer.parseInt(sc.next()) + Integer.parseInt(sc.next()) + 1;
		System.out.println(ans);
	}
}

Measured memory_bytes: 23892
#include <stdio.h>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;

struct point{
	int x, y, i;
};

map<int, vector<pair<int, int> > > u,t;

int N, A, B;
int X[100010], Y[100010], P[100010], C[100010];
int W[100010][4];

int find(int x)
{
	if (P[x] != x) P[x] = find(P[x]);
	return P[x];
}

int main()
{
	scanf("%d %d %d", &N, &A, &B); A--; B--;
	for (int i = 0; i < N; i++){
		scanf("%d %d", &X[i], &Y[i]);
		P[i] = i;
	}
	int D = abs(X[A] - X[B]) + abs(Y[A] - Y[B]);

	for (int k = 0; k < 4; k++){
		u.clear(); t.clear();
		for (int i = 0; i < N; i++){
			u[X[i] + Y[i]].push_back({ X[i], i });
		}
		for (auto &p : u)
		{
			sort(p.second.begin(), p.second.end());
		}
		for (int i = 0; i < N; i++){
			W[i][k] = -1;
			int s = X[i] + Y[i] + D;
			if (u.count(s)){
				auto &v = u[s];
				auto I = lower_bound(v.begin(), v.end(), make_pair(X[i], -1)) - v.begin();
				auto J = upper_bound(v.begin(), v.end(), make_pair(X[i] + D, -1)) - v.begin();
				if (I < J){
					W[i][k] = v[I].second;
				}
				C[i] += J - I;
				t[s].push_back({ I, J });
			}
		}
		for (auto &p : t)
		{
			auto &v = u[p.first];
			sort(p.second.begin(), p.second.end());

			vector<int> cnt(v.size());
			for (auto &q : p.second) if (q.first < q.second){
				cnt[q.first]++;
				cnt[q.second-1]--;
			}

			for (int i = 0; i < cnt.size(); i++){
				if (i) cnt[i] += cnt[i - 1];
				if (i + 1 < cnt.size())
				{
					int x = v[i].second;
					int y = v[i + 1].second;
					if (cnt[i]){
						P[find(x)] = find(y);
					}
				}
			}
		}

		for (int i = 0; i < N; i++){
			int x = X[i], y = Y[i];
			Y[i] = x; X[i] = -y;
		}
	}

	for (int i = 0; i < N; i++){
		for (int j = 0; j < 4; j++) if (W[i][j] != -1){
			int x = W[i][j];
			for (int k = j - 1; k >= 0; k--) if (W[i][k] != -1){
				int y = W[i][k];
				P[(find(x))] = find(y);
				break;
			}
		}
	}

	long long r = 0;
	P[find(A)] = find(B);
	for (int i = 0; i < N; i++){
		if (find(i) == find(A)) r += C[i];
	}
	r /= 2;
	printf("%lld\n", r);

	return 0;
}

Measured memory_bytes: 17152
import java.util.*;

public class Main{
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);

      int L=sc.nextInt();
      int R=sc.nextInt();

      //0 < L <= i < j <= R

      int mod,ii,jj;
      int ans = 2019;
      int cnt =0;

      for(int i=L;i<R;i++){
        ii = i % 2019;
        for(int j=i+1;j<=R;j++){
          jj = j % 2019;
          mod = (ii*jj) % 2019;
          if(mod<ans) ans=mod;
          if(ans==0){break;}
        }
        if(ans==0){break;}
      }
      System.out.println(ans);

//kan nin gu

    }
}


Measured memory_bytes: 23124
#include <stdio.h>

int main(void) {
	int N,i,j,k,tmp;
	int A[100];
	
	scanf("%d", &N);
	for (i = 0;i < N;i++) {
		scanf("%d", &A[i]);
	}
	
	for (i = 0;i < N;i++) {
		tmp = A[i];
		k = i-1;
		while (k >= 0 && A[k] > tmp) {
			A[k+1] = A[k];
			k--;
		}
		A[k+1] = tmp;
		for (j = 0;j < N;j++) {
			printf("%d%c", A[j], j == N-1 ? '\n' : ' ');
		}
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long ;
int main(){
    ll n,a,b;
    ll ans;
    cin >> n >> a >> b;
    if(a>b) ans=0;
    else if(n==1){
        if(a!=b) ans=0;
        else ans=1;
    }
    else{
        n = n-2;
        ans = b*n -a*n +1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3600
#include<stdio.h>

int solve(int,int);
int n,A[20];

int main(){
  int i,q,m[200];

  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&A[i]);

  scanf("%d",&q);
  for(i=0;i<q;i++)
    scanf("%d",&m[i]);

  for(i=0;i<q;i++){
    if(solve(0,m[i]))printf("yes\n");
    else printf("no\n");
  }
  return 0;
}

int solve(int i,int m){
  int a,b;
  if(m<0)return 0;
  if(m==0)return 1;
  if(i==n)return 0;
  a = solve(i+1,m);
  b = solve(i+1,m-A[i]);
  if(a == 1 || b == 1) return 1;
  else return 0;
}

Measured memory_bytes: 580
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int w=sc.nextInt(),h=sc.nextInt(),x=sc.nextInt(),
            y=sc.nextInt(),r=sc.nextInt();
        int s=Math.min(x,w-x),t=Math.min(y,h-y);
        String a = (s>=r && t>=r) ? "Yes" : "No";
        System.out.println(a);
    }
}


Measured memory_bytes: 26360
H,W,K=map(int,input().split())
S=[list(map(int,list(input()))) for i in range(H)]
ans=H+W-2
for bit in range(2**(H-1)):
    divH=[0]
    for j in range(H-1):
        if(bit>>j&1):
            divH.append(j+1)
    divH.append(H)
    glen=len(divH)-1
    group=[0]*(glen)
    res=glen-1
    go=True
    for w in range(W):
        ok=True
        c=[0]*(glen)
        for g in range(glen):
            cum=0
            for h in range(divH[g],divH[g+1]):
                cum+=S[h][w]
            c[g]+=cum
            if cum>K:
                go=False
            if cum+group[g]>K:
                ok=False
        if not go:
            break
        if not ok:
            res+=1
            group=[c[i] for i in range(glen)]
        else:
            for i in range(glen):
                group[i]+=c[i]
    if not go:
        continue
    ans=min(ans,res)
print(ans)


Measured memory_bytes: 46428
// A - Connection and Disconnection
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll opeCounter(string &S, int K){
	string T=S; while(--K) T += S;
	ll c = 0; for(int i=1; i<T.size(); ++i) if(T[i-1] == T[i]) c++, i++;
	return c;
}

int main(){
  string S; int K; cin>>S>>K;
	ll s1 = opeCounter(S, 1);
	ll s2 = opeCounter(S, 2);
	int i=1; for(; i<S.size() && S[0]==S[i]; ++i);
  cout<< (i==S.size()? S.size() * K / 2: (s2 - s1) * (K - 1) + s1) <<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
    #include<stdlib.h>
    int main(){
      long long int n,i,j,r=0,g=0,b=0;
      long long int count;
      scanf("%d ",&n);
      char s[n+2];
      for(i=1;i<=n;i++){
        scanf("%c",&s[i]);
        if(s[i]=='R')
          r++;
        else if(s[i]=='G')
          g++;
        else
          b++;
      }
      count=r*g*b;
      for(j=1;j<n-1;j++){
        i=1;
        while(j+i*2<=n){
          if(s[j]!=s[j+i] && s[j+i]!=s[j+2*i] && s[j]!=s[j+2*i])
            count-=1;
          i+=1;
        }
      }
      printf("%lld\n",count);
      return 0;
    }


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

using namespace std;
typedef long long ll;
#define cc(x) cout << (x) << endl
#define FOR(az,c)   for ( int (az)=0; (az)<(c); (az)++)
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
typedef vector<int> vi;
#define endl '\n';
#define pb push_back
#define mp make_pair
#define X first
#define Y second
typedef pair<int, int> pii;
#define all(v) (v).begin(),(v).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

string trim(const string& str)
{
    size_t first=str.find_first_not_of(' ');
    if(string::npos == first)
    {
        return str;
    }
    size_t last=str.find_last_not_of(' ');
    return str.substr(first,(last-first+1));
}
//----------------------------------------------------------//


void solve()
{
   int n;
   cin>>n;
   n=n%1000;
   if(n==0)
   {
       cout<<0<<endl;
   }
   else
   {
       cout<<1000-(n%1000)<<endl;
   }
   
   

}
   



int main()
{
    IOS
    int t;
    cin>>t;
    int ac=0,tle=0,re=0,wa=0;
    while(t--)
    {
        string st;
        cin>>st;
        if(st=="AC")
        {
            ac++;
        }
        else if(st=="TLE")
        {
            tle++;
        }
        else if(st=="RE")
        {
            re++;
        }
        else if(st=="WA")
        {
            wa++;
        }
    }

    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl;
    return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>

int main()
{
    int n, m, n1, m1, cnt = 0, i, j;
    scanf("%d", &n);
    scanf("%d", &m);
    scanf("%d", &n1);
    scanf("%d", &m1);
    for(i = 0; i < n - n1; ++i)
        for(j = 0; j < m - m1; ++j)
            ++cnt;
    printf("%d", cnt);
    return 0;
}


Measured memory_bytes: 128
import sys
input = sys.stdin.readline


N,Q=map(int,input().split())
EDGE=[list(map(int,input().split())) for i in range(N-1)]
PLUS=[list(map(int,input().split())) for i in range(Q)]

SCORE=[0]*(N+1)
for p,x in PLUS:
    SCORE[p]+=x

ELIST=[[] for i in range(N+1)]

for x,y in EDGE:
    ELIST[x].append(y)
    ELIST[y].append(x)

from collections import deque
Q=deque([1])

USED=[0]*(N+1)
USED[1]=1

while Q:
    x=Q.pop()

    for to in ELIST[x]:
        if USED[to]==0:
            USED[to]=1
            SCORE[to]+=SCORE[x]
            Q.append(to)

print(*SCORE[1:])
    


Measured memory_bytes: 125532
#include <stdio.h>

int main() {
	long long int n;
	scanf("%lld", &n);
	long long int total = 0;
	
	for(int i = 0; i <=n; i++){
		if(i % 3 == 0 && i % 5 == 0) {
			continue;
	} else if (i % 3 == 0) {
		continue;
	} else if (i % 5 == 0) {
		continue;
	} else { 
		total += i;
	}
}
	printf("%lld", total);
	return 0;
}

Measured memory_bytes: 1720
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b,shabi;
	cin>>a>>b;shabi=b-a+1;
	if(a>0)
	{
		cout<<"Positive";
		return 0;
	}
	if((a<0&&b>=0))
	{
		cout<<"Zero";
		return 0;
	}
	if(a<0&&b<0&&shabi%2==1)
	{
		cout<<"Negative";return 0;
	}
	cout<<"Positive";
 } 

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

typedef long long LL;

int main()
{
    LL n;
    cin >> n;
    vector<LL> a;
    LL num;
    for(LL i=0; i<n; i++)
    {
        cin >> num;
        a.push_back(num);
    }    
    vector<LL> temp;
    for(LL i=0; i<n; i++)
    {
        if(i==0)
        {
            temp.push_back(a[0]);
        }
        else{
            if(a[i]<temp[i-1])
            {
                temp.push_back(temp[i-1]);
            }
            else{
                temp.push_back(a[i]);
            }
        }
    }
    LL ht = 0;
    for(LL i=0; i<n; i++)
    {
        ht += temp[i]-a[i];
    }
    cout << ht;
    return 0;
}

Measured memory_bytes: 7908
if __name__=="__main__":
    n = int(input())
    A = [int(i) for i in input().split(' ')]
    B = [int(i) for i in input().split(' ')]
    allA = 0
    allB = 0
    for a, b in zip(A, B):
        allA += a
        allB += b
    if (allA < allB):
        print(-1)
        exit(0)
    C = []
    sum = 0
    ans = 0
    for i in range(n):
      if (A[i] < B[i]):
          sum += A[i] - B[i]
          ans += 1
      else:
          C.append(A[i] - B[i])
    if (sum >= 0):
        print(ans)
        exit(0)
    C = sorted(C)
    C.reverse()
    for i in (C):
        sum += i
        ans += 1
        if (sum >= 0):
            print(ans)
            exit(0)

Measured memory_bytes: 18356
# coding: utf-8

x, N = map(int,input().split())
if N != 0:
    P = list(map(int,input().split()))
    L = [i for i in range(-1000, 1010)]

    l = list(set(P)^set(L))
    dis = 10**9
    
    for i in range(len(l)):
        dis_ = abs(x-l[i])
        if dis_ < dis:
            ans = l[i]
            dis = dis_
else:
    ans = x


print(ans)

Measured memory_bytes: 9236
#include <bits/stdc++.h>
#define N 50001
#define M 100011
#define f first
#define s second
#define INF (1e9)
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
int n,m,T;
set<PP> G[M]; // to,cost,y,x
vector<int> g[M],c[M];
vector<P> D[M];
priority_queue<PP,vector<PP>,greater<PP> >Q;  

void ifPush(int cost,int cnt,int y,int x){
  if(D[y][x]<=P(cost,cnt))return;
  D[y][x]=P(cost,cnt);
  Q.push(PP(D[y][x],P(y,x)));
}

P dijkstra(int a,int b){
  vector<int>used(n,0);

  while(!Q.empty()){
    PP t=Q.top();Q.pop();
    int cost=t.f.f,cnt=t.f.s;
    int y=t.s.f, x=t.s.s;
    int pos=g[y][x];
    if(D[y][x]<t.f)continue;
    if(pos==b) return t.f;

    if(used[pos]++){
      if(x+1<g[y].size())ifPush(cost+c[y][x],cnt,y,x+1);
      if(x-1>=0)ifPush(cost+c[y][x-1],cnt,y,x-1);
      continue;
    }
    
    for(set<PP>::iterator i=G[pos].begin();i!=G[pos].end();i++){
      int ncost=cost+i->f.s,ncnt=cnt;
      int ny=i->s.f,nx=i->s.s;
      if(pos!=a&&(ny!=y||abs(x-nx)!=1))ncost+=T,ncnt++;
      ifPush(ncost,ncnt,ny,nx);
    }
  }
  return P(-1,-1);
}

int main(){
  string s,t;
  cin>>m>>T>>s>>t;
  map<string,int> mp;
  mp[s]=n++;
  mp[t]=n++;

  for(int i=0,a;i<m;i++){
    cin>>a;
    D[i].resize(a,P(INF,INF));
    c[i].resize(a-1);
    for(int j=0;j<a;j++){
      string str;
      cin>>str;
      if(!mp.count(str))mp[str]=n++;
      if(str==s)D[i][j]=P(0,0);
      if(str==s&&Q.empty())Q.push(PP(P(0,0),P(i,j)));
      g[i].push_back(mp[str]);
    }

    for(int j=0,pre=g[i][0];j<a-1;j++){
      cin>>c[i][j];
      int pos=g[i][j+1];
      G[pre].insert(PP(P(pos,c[i][j]),P(i,j+1)));
      G[pos].insert(PP(P(pre,c[i][j]),P(i,j)));
      pre=pos;
    }
  }

  P ans=dijkstra(0,1);
  if(ans==P(-1,-1)) cout<<-1<<endl;
  else cout<<ans.f<<" "<<ans.s<<endl;
  return 0;
}

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

lli n;

int main(void){
	cin >> n;
	vector<vector<lli>> a(n, vector<lli>(26));
	rep(i, n){
		string s;
		cin >> s;
		rep(j, s.size()){
			a[i][s[j]-'a']++;
		}
	}
	string ans = "";
	rep(i, 26){
		lli minv = 1e9;
		rep(j, n){
			minv = min(minv, a[j][i]);
		}
		rep(j, minv) ans+=('a'+i);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3588
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstdio>
#include<queue> 
 
using namespace std;
  
int main(void){
  
  priority_queue<int> que;
  char ch[10];
  int k;
  
  while(true){
    scanf(" %s",ch);
    if(ch[2]=='d')break;
    if(ch[0]=='i'){
      scanf("%d",&k);
      que.push(k);
    } else {
      printf("%d\n",que.top());
      que.pop();
    }
  }
  
  return 0;
}

Measured memory_bytes: 6192
toInt :: (String -> Int)
toInt x = read x :: Int

getInts = do
  x <- getLine
  let y = (map$toInt)$words x
  return y
  
main = do
  inNum <- getInts
  let square = (inNum !! 0) * (inNum !! 1)
  let perimeter = (inNum !! 0) * 2 + (inNum !! 1) * 2
  putStrLn ((show square) ++ [' '] ++ (show perimeter))


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#include<string>
#include<cmath>

using namespace std;

#define ll long long int
#define ld long double
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout<< #x << '=' << x <<endl
#define MOD 1000000007

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n , x , t;
    cin>>n>>x>>t;
    cout<<((n + x - 1)/x) * t;
}

Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
using namespace std;
#define N 100010
int main() {
  int n, m, h[N], ma[N];
  cin>>n>>m;
  for(int i=1; i<=n; i++) {
    cin >> h[i];
    ma[i] = 0;
  }
  for(int i=0; i<m; i++) {
    int a,b;
    cin>>a>>b;
    ma[a]=max(ma[a],h[b]);
    ma[b]=max(ma[b],h[a]);
  }
  int ans=0;
  for(int i =1;i<=n; i++) {
    ans+=h[i]>ma[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4368
def main():
    n = int(input())
    p = [int(x) for x in input().split()]
    ans = 0
    for idx in range(n-2):
        if (p[idx] < p[idx+1] and p[idx+1] < p[idx+2]) \
            or (p[idx] > p[idx+1] and p[idx+1] > p[idx+2]):
            ans+=1
    print(ans)

main()


Measured memory_bytes: 3060
#include <stdio.h>

int main(void){
	int a, b, c;
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	int larger = 0;
	if(a < b){
		larger = b;
	}else if(a >= b){
		larger = a;
	}
	if(larger < c){
		printf("%d \n",a + b);
	}else if(larger >= c){
		printf("%d \n",a + b + c - larger);
	}
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long b = sc.nextLong();
        long r = sc.nextLong();
        long br = b + r;

        long ans = n / br * b;
        long rem = n % br;
        ans += Math.min(rem, b);

        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
const int INF = 1e6;
using namespace std;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    int n,m;
    cin >> n >> m;
    int A[n][m];
    rep(i,n){
        rep(j,m){
            cin >> A[i][j];
        }
    }
    int b[m];
    rep(i,m){
        cin >> b[i];
    }
    rep(i,n){
        int ans = 0;
        rep(j,m){
            ans += A[i][j] * b[j];
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3128
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define ll long long
#define ull unsigned long long
#define INF (1 << 29)
#define LLINF (1LL << 61)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10
#define P pair<int, int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define TO_STRING(VariableName) # VariableName

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }

int main() {
	int x, a, b;
	cin >> x >> a >> b;
	if (abs(x - a) < abs(x - b)) {
		cout << "A" << endl;
	}
	else {
		cout << "B" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
n = int(raw_input())
t = 0
h = 0
for i in range(n):
    line = raw_input().split()
    if line[0] == line[1]:
        t += 1
        h += 1
    elif line[0] > line[1]:
        t += 3
    else:
        h += 3
print '{0} {1}'.format(t,h)

Measured memory_bytes: 6364
#include<iostream>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
using namespace std;

bool is_even(int n) {
  return n % 2 == 0;
}

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  bool inf = false;
  int ans = 0;
  while (1) {
    if (A == B && B == C) {
      if (!is_even(A)) break;
      inf = true;
      break;
    }
    if (!is_even(A) || !is_even(B) || !is_even(C)) break;
    int tmp_a = 0, tmp_b = 0, tmp_c = 0;
    tmp_a += B / 2;
    tmp_a += C / 2;
    tmp_b += A / 2;
    tmp_b += C / 2;
    tmp_c += A / 2;
    tmp_c += B / 2;
    A = tmp_a, B = tmp_b, C = tmp_c;
    ++ans;
  }

  if (inf) cout << "-1" << endl;
  else cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
 
using namespace std;
 
signed main()
{
    fast;
    string s;
    cin>>s;

    if ( s == "SUN" )
    {
        cout<<"7"<<endl;
    }
    else if ( s == "SAT" )
    {
        cout<<"1"<<endl;
    }
    else if ( s == "MON" )
    {
        cout<<"6"<<endl;
    }
    else if ( s == "TUE" )
    {
        cout<<"5"<<endl;
    }
    else if ( s == "WED" )
    {
        cout<<"4"<<endl;
    }
    else if ( s == "THU" )
    {
        cout<<"3"<<endl;
    }
    else if ( s == "FRI" )
    {
        cout<<"2"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
using namespace std;
typedef long long ll;
int N,M;
int H[1510] = {},W[1510] = {};

int main(){
    while(true){
        cin >> N >> M;
        if(N==0) break;
        for(int i=1;i<=N;i++){
            cin >> H[i];
            H[i] += H[i-1];
        }
        for(int i=1;i<=M;i++){
            cin >> W[i];
            W[i] += W[i-1];
        }
        map<int,ll> m;
        for(int i=0;i<=N;i++) for(int j=0;j<=M;j++) m[H[i]+W[j]]++;
        ll ans = 0;
        for(auto x:m){
            ans += x.second*(x.second-1)/2;
        }
        cout << ans << endl;
    }
}


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

string s;
int ans;


int cal(int num,int pos){
	if(s.size()==num){
		if(pos!=3)ans=0;
	}
	else{
		if(pos==0){
			if(s[num]=='0')cal(num+1,1);
			if(s[num]=='1')cal(num+1,5);
		}
		if(pos==1){
			if(s[num]=='0')ans=0;
			if(s[num]=='1')cal(num+1,2);
		}
		if(pos==2){
			if(s[num]=='0')cal(num+1,4);
			if(s[num]=='1')cal(num+1,3);
		}
		if(pos==3){
			if(s[num]=='0')cal(num+1,5);
			if(s[num]=='1')cal(num+1,1);
		}
		if(pos==4){
			if(s[num]=='0')cal(num+1,3);
			if(s[num]=='1')cal(num+1,5);
		}
		if(pos==5){
			if(s[num]=='0')cal(num+1,1);
			if(s[num]=='1')ans=0;
		}
		
	}
	
}


int main(){
	
	while(cin>>s){
		if(s=="#")break;
		ans=1;
		cal(0,0);
		if(ans)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 1184
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const long double PI = (acos(-1));
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
#define scll(x) scanf("%lld",&x)
int main(){
    int now = 0, next = 0;
    string a, b, c; cin >> a >> b >> c;
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    reverse(c.begin(), c.end());
    while (1){
        now = next;
        if (now==0){
            if (a.size()==0) break;
            next = *(a.end()-1) - 'a';
            a.pop_back();
        }else if (now==1){
            if (b.size()==0) break;
            next = *(b.end()-1) - 'a';
            b.pop_back();
        }else if (now==2){
            if (c.size()==0) break;
            next = *(c.end()-1) - 'a';
            c.pop_back();
        }
    }
    if (now==0) cout << 'A' << endl;
    else if (now==1) cout << 'B' << endl;
    else cout << 'C' << endl;
    return 0;
}

Measured memory_bytes: 256
#n = int(input())
s = input()
#a,b= map(int,input().split())
#da = list(map(int,input().split()))
#a = [int(input()) for i in range(n)]

n = len(s)
ju = True
for i in range(n):
    if i%2 ==0 and s[i] != 'h':
        ju = False
    if i%2==1 and s[i] !='i':
        ju  = False

if ju and n%2==0:
    print("Yes")
else:
    print("No")
        

Measured memory_bytes: 2940
n, a, b = map(int, input().split())
S = str(input())

dom = 0
glo = 0

for s in S:
    if (s == 'a') and (dom + glo < a + b):
        print('Yes')
        dom += 1
    elif (s == 'b') and (dom + glo < a + b) and (glo < b):
        print('Yes')
        glo += 1
    else:
        print('No')


Measured memory_bytes: 9264
N=int(input())
a=0
b=0
c=0
d=0

#print(N)
for i in range(N):
    #print(i)
    j=str(input())
    if j=="AC":
      a+=1
    elif j=="WA":
      b+=1
    elif j=="TLE":
      c+=1
    elif j=="RE":
      d+=1

print("AC x "+str(a))
print("WA x "+str(b))
print("TLE x " + str(c))
print("RE x " + str(d))

Measured memory_bytes: 9212
import queue
N,M=map(int,input().split())
p=[int(i)-1 for i in input().split()]
x=[0 for i in range(M)]
y=[0 for i in range(M)]
edge=[set() for i in range(N)]
for i in range(M):
    x[i],y[i]=map(int,input().split())
    x[i]-=1;y[i]-=1
    edge[x[i]].add(y[i])
    edge[y[i]].add(x[i])
k=0
L=[0 for i in range(N)]
q=queue.Queue()
reached=[0 for i in range(N)]
for i in  range(N):
    if reached[i]==1:
        continue
    k+=1
    q.put(i)
    reached[i]=1
    L[i]=k
    while(not(q.empty())):
        r=q.get()
        for v in edge[r]:
            if not(reached[v]):
                q.put(v)
                reached[v]=1
                L[v]=k
ans=0
for i in range(N):
    if L[i]==L[p[i]]:
        ans+=1
print(ans)


Measured memory_bytes: 58592
extern crate core;

use std::io::{self, Read};

#[macro_use]
mod parser {
    macro_rules! input {
    ($s:expr=>$($t:tt)*) => {
        let mut lines=$s.split("\n");
        $(
            line_parse!(lines,$t);
        )*
    };
    }

    macro_rules! line_parse {
    ($lines:expr,($($name:ident:$t:tt)*)) => {
        let mut line=$lines.next().unwrap().split_whitespace();
        $(value_def!(line,$name,$t);)*
    };

    //複数行
    ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
        values_def!($lines,$n,$name,$t);
    };
    }

    macro_rules! value_def {
        ($line:expr, $name:ident, $t:tt) => {
            let $name = value!($line, $t);
        };
    }

    macro_rules! values_def {
        ($lines:expr, $n:expr, $name:ident, $t:tt) => {
            let $name = {
                let mut vec = Vec::new();
                for i in 0..$n {
                    let mut next = $lines.next().unwrap().split_whitespace();
                    vec.push(value!(next, $t));
                }
                vec
            };
        };
    }

    macro_rules! value {
    //配列
    ($line:expr,[$t:tt]) => {
        $line.map(|x|{
        let mut iter=::std::iter::once(x);
        value!(iter,$t)
        }).collect::<Vec<_>>()
    };
    //タプル
    ($line:expr,($($t:tt),*)) => {
        ($(value!($line,$t),)*)
    };
    //文字列
    ($line:expr,#) => {
        $line.next().unwrap()
    };
    //単一値
    ($line:expr,$t:ty) => {
        $line.next().unwrap().parse::<$t>().unwrap()
    };
    }
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(input: String) -> String {
    input!(input=>(n:i64));
    let mut now = 1;
    for i in 1.. {
        if i * i > n {
            return now.to_string();
        }
        now = i * i;
    }
    panic!();
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}

tests! {
    test1: "10" => "9",
    test2: "81" => "81",
    test3: "271828182" => "271821169",
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>

using namespace std;
int main() {

	int Input[3] = {};
	
	for (int i = 0; i < 3; i++)
		cin >> Input[i];

	sort(Input, Input + 3);

	cout << Input[0] << " " << Input[2] << "\n";

	return 0;
}


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

Q1 = len([x for x in P if x <= A])
Q2 = len([x for x in P if A+1 <= x <= B])
Q3 = len([x for x in P if x >= B+1])

print(min(Q1, Q2, Q3))


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

using namespace std;

typedef pair<int, int> ii;
typedef long long ll;
const int oo = 1e9 + 7;
const int modulo = 1e9 + 7;
template<typename T>
inline T sum(const T& a, const T& b) { return T((a % modulo + b % modulo) % modulo); }
template<typename T>
inline T mul(const T& a, const T& b) { return T((1LL * (a % (1LL * modulo)) * (b % (1LL * modulo))) % (1LL * modulo)); }
string to_string(string a) { return "\"" + a + "\""; }
#ifdef __LOCAL_DEBUG
#define debug(args...) { string __out = #args; replace(__out.begin(), __out.end(), ',', ' '); stringstream __out_ss(__out);\
istream_iterator<string> __it(__out_ss); _debug(__it, args); }
void _debug(istream_iterator<string> it) { }
template<typename T, typename... Args>
void _debug(istream_iterator<string> it, T a, Args... args){ cerr << *it << " = " << to_string(a) << '\n'; _debug(++it, args...); }
#else
#define debug(...)
#endif

int fpow(int a, int p) {
  if (p == 0) return 1;
  if (p == 1) return a;
  int tmp = fpow(a, p / 2);
  tmp = mul(tmp, tmp);
  if (p & 1) tmp = mul(tmp, a);
  return tmp;
}

int n, dp[101][64], m;
bool ok[64][64], mk[64] = {0};
const char* p = "ACGT";

bool check(string s) {
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 2; ++j)
      if (s[j] == 'A' && s[j + 1] == 'G' && s[j + 2] == 'C')
        return false;
    swap(s[i], s[i + 1]);
    for (int j = 0; j < 2; ++j)
      if (s[j] == 'A' && s[j + 1] == 'G' && s[j + 2] == 'C')
        return false;
    swap(s[i], s[i + 1]);
  }
  return true;
}

void init() {
  memset(ok, 0, sizeof ok);
  vector<string> w;
  for (int i = 0; i < 4; ++i) {
    for (int j = 0; j < 4; ++j) {
      for (int k = 0; k < 4; ++k) {
        string tmp;
        tmp.push_back(p[i]);
        tmp.push_back(p[j]);
        tmp.push_back(p[k]);
        w.push_back(tmp);
        if (!check(tmp))
          mk[int(w.size()) - 1] = true;
      }
    }
  }
  debug(w.size());
  int m = int(w.size());
  for (int i = 0; i < m; ++i) {
    for (int j = 0; j < m; ++j) {
      if (w[i][1] == w[j][0] && w[i][2] == w[j][1]) {
        string tmp;
        tmp.push_back(w[i][0]);
        tmp.push_back(w[i][1]);
        tmp.push_back(w[i][2]);
        tmp.push_back(w[j][2]);
        ok[i][j] = check(tmp);
      }
    }
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  init();
  memset(dp, 0, sizeof dp);
  for (int j = 0; j < 64; ++j)
    if (!mk[j])
      dp[3][j] = 1;
  for (int i = 4; i <= n; ++i)
    for (int pre = 0; pre < 64; ++pre)
      for (int nxt = 0; nxt < 64; ++nxt)
        if (ok[pre][nxt])
          dp[i][nxt] = sum(dp[i][nxt], dp[i - 1][pre]);
  int ans = 0;
  for (int j = 0; j < 64; ++j)
    ans = sum(ans, dp[n][j]);
  cout << ans;
  return 0;
}


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

bool comp(int a, int b){
    return a > b;
}

int main(void){
    int n, k; cin >> n >> k;
    int array[200010] = {};
    for(int i = 0; i < n; i++){
        int input; cin >> input;
        array[input]++;
    }

    vector<int> v;
    for(int i = 0; i < 200010; i++){
        if(array[i] != 0){
            v.push_back(array[i]);
        }
    }

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

    int ans = 0;

    while(v.size() > k){
        ans += v.back();
        v.pop_back();
    }

    cout << ans << endl;
    return 0;
}

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
//const int mod = 998244353;
const double eps = 1e-9;

/*{
  }*/

signed main(){
  int n, t;
  cin >> n >> t;

  vi a(n), b(n);
  rep(i, 0, n) cin >> a[i] >> b[i];

  vector<pii> v(n);
  rep(i, 0, n) v[i] = {a[i], b[i]};
  sort(all(v));
  rep(i, 0, n){
    a[i] = v[i].first;
    b[i] = v[i].second;
  }

  vvi dp(n+1, vi(6001));
  rep(i, 0, n){
    rep(j, 0, 6000){
      chmax(dp[i+1][j], dp[i][j]);
      if(j < t){
        chmax(dp[i+1][j+a[i]], dp[i][j]+b[i]);
      }
    }
  }

  int ans = 0;
  rep(j, t, 6001){
    chmax(ans, dp[n][j]);
  }

  cout << ans << endl;

  return 0;
}




Measured memory_bytes: 141184
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	vector<bool> s(n + 1), t(n + 1);
	for (int i = 0; i < m; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		if (a > b) swap(a, b);
		if (a == 1) s[b] = true;
		if (b == n) t[a] = true;
	}
	for (int i = 1; i <= n; ++i)
		if (s[i] && t[i]) {
			printf("POSSIBLE\n");
			return 0;
		}
	printf("IMPOSSIBLE\n");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp(a,b) make_pair(a,b)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
int main(){
    int64_t x,k,d;
    cin>>x>>k>>d;
    x = abs(x);
    if(k==1){
        cout<<abs(x-d)<<endl;
        return 0;
    }
    if(x/d>=k){//0にたどり着けない
        cout<<x-d*k<<endl;
    }
    else{
        int cnt = x/d;//これで
        x -= cnt*d;
        k -= cnt;
        if(k%2==0){//ここか-2*d
            cout<<min(x,abs(x-2*d))<<endl;
        }
        else{
            cout<<min(x+d,abs(x-d))<<endl;
        }
        
    }
}

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mt make_tuple
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<ll,ll> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
//typedef tuple<ll,ll,ll,ll> tp;
//typedef vector<tp> vt;
typedef vector<vd> vvd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n;
	while(cin>>n,n){
		vp in(n);
		rep(i,n)cin>>in[i].first>>in[i].second;
		int m;
		cin>>m;
		vvi fi(21,vi(21));
		int x=10,y=10;
		fi[x][y]=true;
		string s="NESW";
		while(m--){
			char c;
			int d;
			cin>>c>>d;
			rep(i,4)if(s[i]==c)while(d--){
				x+=dx[i];
				y+=dy[i];
				fi[x][y]=true;
			}
		}
		bool h=true;
		rep(i,n)if(fi[in[i].first][in[i].second]==0)h=false;
		if(h)cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
}

Measured memory_bytes: 3124
#include <stdio.h>

int main(){
    int x, y;
    
    while(scanf("%d %d", &x, &y), x > 0 || y > 0){
        if(x > y){
            printf("%d %d\n", y, x);
        }
        
        else {
            printf("%d %d\n", x, y);
        }
    }
    
    return 0;
}

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

int main() {
	int	N;
	cin >> N;
	bitset<13> S;
	bitset<13> H;
	bitset<13> C;
	bitset<13> D;
	for (int i = 0; i < N; i++)
	{
		char	suit;
		int		n;	
		cin >> suit >> n;;
		if (suit == 'S')
			S.set(n - 1);
		else if (suit == 'H')
			H.set(n - 1);
		else if (suit == 'C')
			C.set(n - 1);
		else 
			D.set(n - 1);
	}
	for (int i = 0; i < 13; i++)
	{
		if (!S.test(i))
			cout << "S " << i + 1 << endl;
	}
	for (int i = 0; i < 13; i++)
	{
		if (!H.test(i))
			cout << "H " << i + 1 << endl;
	}
	for (int i = 0; i < 13; i++)
	{
		if (!C.test(i))
			cout << "C " << i + 1 << endl;
	}
	for (int i = 0; i < 13; i++)
	{
		if (!D.test(i))
			cout << "D " << i + 1 << endl;
	}
}



Measured memory_bytes: 3092
#include <iostream>

int main(){
   char c[3][3];
   for(int i=0; i<3; ++i){
      for(int j=0; j<3; ++j)
	 std::cin >> c[i][j];
   }

   std::cout << c[0][0] << c[1][1] << c[2][2] << std::endl;

   return 0;
}


Measured memory_bytes: 256
dp = []
30.times do |i|
	i += 1
	if i == 1
		dp[i] = 1
	elsif i == 2
		dp[i] = 2
	elsif i == 3
		dp[i] = 4
	else
		dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3]
	end
end
until (n = gets.to_i) == 0
	p (dp[n] / 10.0 / 365.0).ceil.to_i
end

Measured memory_bytes: 8576
#include <stdio.h>
#define MAX 10000
int n;
int S[MAX];
int linearsearch(int);
int main(){
  int q;
  int T[500];
  int i,j;
  int count=0;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }
  for(i=0;i<q;i++){
    if(linearSearch(T[i])==1)
      count++;
  }
  printf("%d\n",count);

  return 0;
}

int linearSearch(int key){
  int i=0;
  S[n]=key;
  while(S[i]!=key){
    i++;
    if(i==n){
      return 0;
    }
  }
    return 1;
}

Measured memory_bytes: 636
a = [int(s) for s in input().split()]
b = a[0]
c = a[1]
d = a[2]
e = a[3]
f = int(0)
g = int(0)

if b >= 0 and d >= 0:
    print(c*e)
elif b < 0 and c >= 0 and d < 0 and e >= 0:
    f = b * d
    g = c * e
    print(max([f,g]))
elif b >= 0 and d < 0 and e >= 0:
    print(c*e)
elif d >= 0 and b < 0 and c >= 0:
    print(c*e)
elif b >= 0 and e < 0:
    print(b*e)
elif d >= 0 and c < 0:
    print(c*d)
else:
    print(b*d)

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

using namespace std;

int main()
{
	string O, E;
	cin >> O >> E;

	for (size_t i = 0; i < E.size(); i++) {
		cout << O[i] << E[i];
	}

	if (E.size() < O.size()) {
		cout << O[O.size() - 1];
	}

	cout << "\n";
	return 0;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
typedef long long ll;
string s;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>s;
    for(auto isi:s){
        if(isi=='?') cout<<"D";
        else cout<<isi;
    }
    cout<<endl;
}

Measured memory_bytes: 3752
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<functional>
#include<algorithm>
#include<bitset>
#include<utility>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
using namespace std;
typedef long long ll;
ll n,k,dp[2005][2005];
const ll mod=1e9+7;
int main()
{
	for(int i=0;i<2005;i++)
	{
		dp[i][0]=1;
		for(int j=1;j<=i;j++)
			dp[i][j]=(dp[i-1][j]+dp[i-1][j-1])%mod;
	}
	cin>>n>>k;
	for(int i=1;i<=k;i++)
		cout<<(dp[k-1][i-1]*dp[n-k+1][i])%mod<<endl;
    return 0;
}

Measured memory_bytes: 30208
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n,sn=0,temp;
  cin >> n;
  temp = n;
  while (temp > 0){
    sn += temp%10;
    temp /= 10;
  }
  if (n%sn == 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<int>v;
int main(){
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	int k,n,tmp;

	cin>>k>>n;
	for(int i=0;i<n;i++){
		cin>>tmp;
		v.push_back(tmp);
	}
	int ma = 0;
	for(int i=1;i<v.size();i++){
		ma = max(abs(v[i] - v[i-1]), ma);
	}
	ma = max(k - v[v.size()-1] + v[0], ma);
	cout<<k-ma<<endl;
	return 0;
}


Measured memory_bytes: 1400
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <sstream>

using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-11;
typedef long long ll;
const ll MOD = 1000000007;
const int N = 100000 + 7;
typedef unsigned long long ull;

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
void fast() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
}

/*                What if i lose? only losers think like that. But the answer is you will lose rate.                */


int x;

int main() {
#ifndef ONLINE_JUDGE
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
#endif
    fast();

    cin>>x;
    int ini= 1000;
    while(ini<x)
        ini+=1000;
    cout<<ini-x<<endl;

    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <map>
#include <vector>
#include <queue>
#include <functional>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#define mp make_pair
#define pb push_back

using namespace std;

const int MAX = 2e5 + 5;

int main() 
{
	int n;
	scanf("%d", &n);
	vector<pair<long long, int>> v(n);
	for (int i = 0; i<n; ++i) {
		long long a;
		scanf("%lld", &a);
		v[i] = mp(a,i);
	}
	sort(v.begin(), v.end());
	long long low = v[n/2-1].first, high = v[n/2].first;
	bool res[MAX];
	for (int i = 0; i<n/2; ++i) {
		res[v[i].second] = 1;
	}
	for (int i = n/2; i<n; ++i) {
		res[v[i].second] = 0;
	}
	for (int i = 0; i<n; ++i) {
		if (res[i]) {
			printf("%lld\n", high);
		}
		else {
			printf("%lld\n", low);
		}
	}
	return 0;
}

Measured memory_bytes: 5504
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define fir first
#define sec second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=1e5+5;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}int n,A,B,a[MAXN];ll F[MAXN];
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read(),A=read(),B=read();Rep(i,1,n)a[i]=read()+1;a[0]=1,a[n+1]=n+2,memset(F,0x3f,sizeof(F)),F[0]=0;
	Rep(i,1,n+1){ll tmp=0;Red(j,i-1,0)(a[j]<a[i]?F[i]=min(F[i],F[j]+tmp):0),(a[j]<a[i]?tmp+=B:0),(a[j]>a[i]?tmp+=A:0);}
	cout<<F[n+1]<<'\n';
	return 0;
}




Measured memory_bytes: 4388
#include<iostream>

using namespace std;

int main(){
  int ureshi=0;
  int total;
  cin >> total;
  while(total>=500){
    ureshi+=1000;
    total-=500;
  }
  while(total>=5){
    ureshi+=5;
    total-=5;
  }
  cout << ureshi <<endl;
  return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	char a;
	cin>>a;
	a++;
	cout<<a<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
void func(int ,int ,int);
int m,n;
int mx;
int data[90][90];
int main(void)
{
	int i,j;
	while(1)	{
		scanf("%d %d",&m,&n);
		if(m==0 && n==0)	break;
		for(i=0;i<n;i++)	{
			for(j=0;j<m;j++)	{
				scanf("%d",&data[i][j]);
			}
		}
		mx=0;
		for(i=0;i<n;i++)	{
			for(j=0;j<m;j++)	{
				if(data[i][j]==1)	{
					data[i][j]=0;
					if(mx==0)	mx=1;
					func(i,j,1);
					data[i][j]=1;
				}
			}
		}
		printf("%d\n",mx);
	}
	return 0;
}
void func(int y,int x,int cnt)
{
	int i,j;
	int xx,yy;
	int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
	for(i=0;i<4;i++)	{
		xx=x+dx[i];	yy=y+dy[i];
		if(xx>=0 && xx<m && yy>=0 && yy<n && data[yy][xx]==1)	{
			data[yy][xx]=0;
			if(mx<cnt+1)	mx=cnt+1;
			func(yy,xx,cnt+1);
			data[yy][xx]=1;
		}
	}
}


Measured memory_bytes: 1060
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N, M = map(int, input().split())

    g = [[False] * N for _ in range(N)]
    for _ in range(M):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        g[a][b] = True
        g[b][a] = True

    ans = 0
    for p in permutations(range(1, N)):
        now = 0
        ok = True
        for n in p:
            ok &= g[now][n]
            now = n
        ans += ok

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4196
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> ii;

#define M 1000000 
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define fill(a,x) memset(a,x,sizeof(a))
#define F first
#define S second
#define FOR(i,a,b) for(ll i = a; i<=b; ++i)
#define NFOR(i,a,b) for(ll i = a; i>=b; --i)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
const ll INF = 1e18;
const ll mod = 1e9+7;
const ll N = 1e5 + 10;
inline ll add(ll x,ll y){
  x += y;
  if(x >= mod) x -= mod;
  return x;
}
inline ll mul(ll x,ll y){
  x = (1LL * x * y) % mod;
  return x;
}

// vector<int>g[N];
// int dp[N];
// int rec(int u){
// 	if(dp[u]!=-1)return dp[u];
// 	if(g[u].size()==0)return 1;
// 	int ans = 0;
// 	for(auto x:g[u]){
// 		ans = max(ans,rec(x));
// 	}
// 	dp[u]=ans+1;
// 	return dp[u];
// }

int main()
{	

	int n; cin >> n;
	double p[n+1];
	FOR(i,1,n)cin >> p[i];
	double dp[n+1][n+1];
	dp[1][0] = p[1];
	dp[0][1] = 1-p[1];

	FOR(i,2,n){
		FOR(j,0,i){
			dp[i-j][j] = p[i]*dp[i-j-1][j] + (1-p[i])*dp[i-j][j-1];
		}
	}
	double ans = 0;
	FOR(j,0,n)if(n-j>j)ans+=dp[n-j][j];
	// cout << ans;
	printf("%0.15f",ans);

	return 0;
}

Measured memory_bytes: 69888
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		double[] x = new double[N];
		String[] u = new String[N];
		double a = 0;
		for(int i=0; i<N; i++) {
			x[i] = sc.nextDouble();
			u[i] = sc.next();
			if(u[i].contains("JPY")) {
				a += x[i];
			}else {
				a += x[i]*380000;
			}
		}
		sc.close();
		System.out.println(a);
	}

}

Measured memory_bytes: 37296