akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef pair<long,long> PL;
typedef map<long,long> ML;
typedef vector<long> VL;
#define INF (int)(1e9)
#define MAXX 999999
#define EPS (1e-7)
#define MOD ((ll)1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/
/*--------------------------------------------*/

int main(){
    int n;cin>>n;
    V x(n),y(n),h(n);rep(i,n)cin>>x[i]>>y[i]>>h[i];
    rep(i,101){
        rep(j,101){
            int cx=i;int cy=j;
            int flag=1;
            int height;
            //printf("cx,cy=%d,%d\n",cx,cy);
            int now=0;
            while(h[now]==0&&now<n){now++;}
            int dx=abs(x[now]-cx);
            int dy=abs(y[now]-cy);
            height=h[now]+dx+dy;
            //printf("now=%d\n",now);
            int tmp=-INF;
            rep(k,n){
                //if(k==now)continue;
                //printf("h=%d\n",h[k]);
                int dx=abs(x[k]-cx);
                int dy=abs(y[k]-cy);
                if(h[k]==0||k==now){continue;}
                tmp=h[k]+dx+dy;
                //printf("tmp=%d\n",tmp);
                if(height!=tmp)flag=0;
            }
            if(tmp==-INF){cout<<x[now]<<" "<<y[now]<<" "<<h[now]<<endl;return 0;}//一回も更新されなければ入力をそのまま出力して逃げる。。
            if(flag){
                //printf("height=%d\n",height);
                cout<<cx<<" "<<cy<<" "<<height<<endl;return 0;
                //return 0;
            }
        }
    }
}






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

using namespace std;

using ll = long long;

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

    int n;
    ll x;

    cin >> n >> x;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    sort(a.begin(), a.end());

    int num = 0;
    for (int i = 0; i < n; ++i) {
        if (a[i] <= x) {
            x -= a[i];
            ++num;
        }
    }
    if (0 < x && 0 < num && n == num) --num;

    cout << num << endl;

    return 0;
}


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

int main(){
    ll H, W;
    int N;
    cin >> H >> W >> N;
    map<P,int> m;
    for(int i=0; i<N; i++){
        int a, b;  cin >> a >> b;
        for(int dh=0; dh<=2; dh++) for(int dw=0; dw<=2; dw++){
            int na = a-dh;
            int nb = b-dw;
            if(na >= 1 && nb >= 1){
                if(m.find({na,nb}) == m.end()) m[{na,nb}] = 0;
                m[{na,nb}]++;
            }
        }
    }

    vector<ll> ans(10,0);
    for(auto itr = m.begin(); itr != m.end(); itr++){
        P p = itr -> first;
        int cnt = itr -> second;

        int a = p.first, b = p.second;
        if(a <= H-2 && b <= W-2) ans[cnt]++;
    }
    ans[0] = (H-2)*(W-2);
    for(int i=1; i<=9; i++){
        ans[0] -= ans[i];
    }

    for(int i=0; i<=9; i++) cout << ans[i] << endl;
}


Measured memory_bytes: 56448
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

int main(){
    long N,M;
    cin >> N >> M;

    priority_queue<long> A;
    for(long i=0; i<N; i++){
        long t;
        cin >> t;
        A.push(t);
    }

    while(M!=0){
        long t = A.top()/2;
        A.pop();
        A.push(t);

        /*2分探索だと遅い
        long start = 0;
        long end = N-2;
        while(start < end){
            long mid =(start + end) / 2;
            if(A[mid] < A[N-1]) start = mid + 1;
            else end = mid - 1;
        }
        
        long t = A[N-1];
        A.pop_back();
        A.insert(A.begin() + start, t);
        */

        M--;
    }

    long sum = 0;
    for(long i=0; i<N; i++){
        sum += A.top();
        A.pop();
    }

    cout << sum;

    return 0;

}

Measured memory_bytes: 1400
#include<cmath>
#include<cstdio>
#include<vector>
using namespace std;
struct node{
	int u, v, w;
	node(int _u, int _v, int _w):u(_u), v(_v), w(_w){}
};
vector<node>ans;
inline int lowbit(int x) {
	return x & -x;
}
int main() {
	int L;
	scanf("%d", &L);
	for(int i=19;i>1;i--) {
		ans.push_back(node(i, i+1, 0));
		ans.push_back(node(i, i+1, (1<<(20-i-1))));
	}
	if( L >= (1<<19) ) {
		ans.push_back(node(1, 2, 0));
		ans.push_back(node(1, 2, 1<<18));
	}
	while( L ) {
		int p = int(log2(lowbit(L)));
		if( p != 19 )
			ans.push_back(node(1, 20-p, L^lowbit(L)));
		L ^= lowbit(L);
	}
	printf("%d %d\n", 20, ans.size());
	for(int i=0;i<ans.size();i++)
		printf("%d %d %d\n", ans[i].u, ans[i].v, ans[i].w);
} 

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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

const int N = 200000;
int h, w, n, r, c;
string s, t;
map<char, int> dir;
int d[4];

int32_t main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> h >> w >> n >> r >> c >> s >> t;
    dir['L'] = 0, dir['R'] = 1, dir['U'] = 2, dir['D'] = 3;
    
    for(int i = 0; i < n; ++i) {
        d[dir[s[i]]]++;
        if(c+d[1] > w || c-d[0] < 1 || r+d[3] > h || r-d[2] < 1) {
            cout << "NO\n";
            return 0;
        }
        
        if(t[i] == 'L') {
            if(c+d[1] > 1) d[1]--;
        } else if(t[i] == 'R') {
            if(c-d[0] < w) d[0]--;
        } else if(t[i] == 'U') {
            if(r+d[3] > 1) d[3]--;
        } else if(t[i] == 'D') {
            if(r-d[2] < h) d[2]--;
        }
    }
    
    cout << "YES\n";
    
    return 0;
}


Measured memory_bytes: 920
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
int main(){
  int N,M;
  cin >> N >> M;
  vector<int> h(N),m(N);
  rep(i,N){
    int x;
    cin >> x;
    h.at(i)=x;
  }
  rep(i,M){
    int a,b;
    cin >> a >> b;
    m.at(a-1)=max(h.at(b-1),m.at(a-1));
    m.at(b-1)=max(h.at(a-1),m.at(b-1));
  }
  int count;
  rep(i,N){
    if(h.at(i)>m.at(i))
      count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 4044
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,1,-1,1,-1,-1,0};
int dy[]={0,1,1,-1,-1,1,0,-1};
 


int main(){
    LL n,a,b;cin >> n >> a >> b;
    LL t = abs(a-b);
    LL ans = LINF;
    if(t%2 == 0){
        ans = min(ans,t / 2);
    }
    LL p = min(a,b);
    LL bb = max(a,b) - p;
    ans = min(ans, p + (bb - 1) / 2);
    LL q = n - max(a,b) + 1;
    LL aa = min(a,b) + q;
    ans = min(ans, q + (n - aa) / 2);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int n, k; cin>>n>>k;
    string s; cin>>s;
    vector<int> v;
    if(s[0]=='0') v.push_back(0);
    int ct=0;
    for(int i=0; i<n-1; i++){
        if(s[i]!=s[i+1]){
            v.push_back(ct+1);
            ct=0;
        }else{
            ct++;
        }
    }
    v.push_back(ct+1);
    if(s[n-1]=='0') v.push_back(0);
    if(v.size()<=2*k+1){
        cout<<n<<endl;
        return 0;
    }else{
        int m=v.size();
        int s[200002]; s[0]=0;
        for(int i=0; i<m; i++){
            s[i+1]=s[i]+v[i];
        }
        int ans=0;
        for(int i=0; i+2*k+1<=m; i+=2){
            ans=max(ans, s[i+2*k+1]-s[i]);
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 1272
#include <bits/stdc++.h>
#define  rep(i,n) for(li i=0;i<(n);i++)
#define  red(i,n) for(li i=(n)-1;i>=0;i--)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a) 
#define  fi first
#define  se second 
using namespace std;
using li = long long;
using ul = unsigned long long;
using vi = vector<li>;
using vs = vector<string>;
inline ul gcd(ul a,ul b) { return b?gcd(b,a%b):a; }
const int INF=1000000009;


int main()
{
    int a,b;
    cin>>a>>b;
    string s;
    rep(i,a)rep(j,b){
        cin>>s;
        if(s=="snuke")cout<<(char)(j+'A')<<i+1<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main() {
  int sum;
  while (cin >> sum) {
    int ans = 0;
    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        for (int k = 0; k < 10; k++) {
          for (int l = 0; l < 10; l++) {
            if (i+j+k+l == sum) ans++;
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

using namespace std;

int main(){
    int a , b , d;
    double c;
    cin >> a >> b;
    c = ( (double)a + (double)b ) / 2;
    d = (int)c;
    if ((c - d)==0 ){
        cout << d << endl;
    } else {
        cout << d + 1 << endl;
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdint>
#include <cmath>
#include <vector>
#include <utility>
#include <limits>

using namespace std;

int main() {
  int H, N;
  cin >> H >> N;
  
  vector<pair<int, int>> magics;
  magics.reserve(N + 1);
  magics.push_back(make_pair(0, 0));
  for (size_t n = 0; n < N; ++n) {
    int A, B;
    cin >> A >> B;
    magics.push_back(make_pair(A, B));
  }
  sort(magics.begin(), magics.end(), [] (const pair<int, int>& lhs, const pair<int, int>& rhs) {
    return lhs.first < rhs.first;
  });
  vector<vector<int>> dp(H + 1, vector<int>(N + 1, numeric_limits<int>::max()));
  for (int h = 1; h <= H; ++h) {
    for (int n = 1; n <= N; ++n) {
      int m = magics[n].second;
      int a = magics[n].first;
      if (h - a >= 0) {
        int cnt = static_cast<int>(ceil(h / static_cast<float>(a)));
        m = magics[n].second * cnt;
        if (dp[h - a][n] != numeric_limits<int>::max()) {
          m = min(m, dp[h - a][n] + magics[n].second);
        }
      }
      if (n != 1) {
        m = min(m, dp[h][n - 1]);
      }
      dp[h][n] = m;
    }
  }
  cout << dp[H][N] << endl;
  
  return 0;
}


Measured memory_bytes: 39680
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
#define Endl endl
const ll INF=100000000000000000;
int main(){
	ll n,ans=INF,dim,count=1;
	string s;
	cin>>n;
	for(ll i=1;i*i<=n;i++){
		if(n%i==0){
			dim=max(i,n/i);
			ans=min(ans,dim);
		}
	}
	while(!(ans<10)){
		ans/=10;
		count++;
	}
	DEB(ans)DEB(count)END
	cout<<count<<endl;
	return 0;
}
//0.25 0.5 1 2

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

int main(){
 int K,S,ans = 0;
 cin >> K >> S;
 for(int X = 0; X <=K; X++){
   for(int Y = 0; Y <= K; Y++){
     int Z = S - X - Y;
      if(Z < 0 || Z > K)
         continue;
         ans++;
   }
 }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,k;
int main(){
    cin>>n>>k;
    if(n==1){
        cout<<(k==0?"0 0 1 1\n":"-1\n");
        return 0;
    }
    if(1<<n<=k){
        cout<<-1<<endl;
        return 0;
    }
    for(int i=0;i<1<<n;i++)if(i!=k)cout<<i<<" ";
    cout<<k<<" ";
    for(int i=(1<<n)-1;i>=0;i--)if(i!=k)cout<<i<<" ";
    cout<<k<<endl;
}

Measured memory_bytes: 1792
//  AOJ1 microwave
#include <iostream>
using namespace std;
int main(int argc,const char * argv[]){
    int A,B,C,D,E,F,c,e;
    cin>>A>>B>>C>>D>>E;
    if(A<0){
        c=-A*C;
        e=B*E;
        F=c+D+e;
    }else if(A>0){
        c=0;
        e=(B-A)*E;
        F=e;
    }else{
        c=0;
        e=B*E;
        F=D+E;
    }
    cout<<F<<endl;
    return 0;
}



Measured memory_bytes: 3112
from collections import deque

N,Q=map(int,input().split())
L=[[] for _ in range(N+1)]
for i in range(N-1):
    a,b=map(int,input().split())
    L[a].append(b)
    L[b].append(a)
count=[0]*(N+1)
for j in range(Q):
    p,x=map(int,input().split())
    count[p]+=x

#print(count)

q=deque() #queueとして(popleftとappend)
q.append(1)
parent=[-1]*(N+1)
#parent[1]=1

while q:
    now=q.popleft()
    for k in L[now]:
        if parent[now]==k:
            continue
        count[k]+=count[now]
        parent[k]=now
        q.append(k)
        #print(parent)

print(*count[1:])



Measured memory_bytes: 105676
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    k, n = map(int, input().split())
    a = list(map(int, input().split()))
    max = 0
    tmp = a[-1] - k
    for i in range(n):
        if a[i] - tmp > max:
            max = a[i] - tmp
        tmp = a[i]
    print(k - max)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


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

using namespace std;

int N, A, B, C, D;

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d %d %d %d", &N, &A, &B, &C, &D);
int target = B - A;
if (target < 0)
    target = -target;
for (int x=0; x<=N - 2; x++)
{
    int y = N - 1 - x;
    long long lft = 1LL * C * x - 1LL * D * y, rgt = 1LL * D * x - 1LL * C * y;
    if (lft <= target && target <= rgt)
    {
        printf ("YES\n");
        return 0;
    }
}
printf ("NO\n");
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
using namespace std;
typedef pair<int, int> P;

vector<int> G[100010];
int dp[100010];
int INF = 1e9;
int n;

int dfs(int now){
    if(dp[now] != -1) return dp[now];
    if(G[now].size() == 0) return dp[now] = 0;
    vector<int> d;
    rep(i, 0, G[now].size()){
        int tmp = dfs(G[now][i]);
        d.push_back(tmp);
    }
    sort(all(d));
    reverse(all(d));
    int MAX = -1;
    rep(i, 0, d.size()){
        MAX = max(MAX, d[i] + i + 1);
    }
    return dp[now] = MAX;
}

signed main(){
    cin >> n;
    vector<int> a(n);
    memset(dp, -1, sizeof(dp));
    rep(i, 1, n){
        cin >> a[i];
        a[i]--;
        G[a[i]]. push_back(i);
    }
    cout << dfs(0) << endl;
}

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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()
#define PB push_back
#define LL long long

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {
    _for(i,0,v.size()) os << v[i] << " ";
    return os;
}

template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){
    for(typename set<T>::iterator it = v.begin();it != v.end();it++)
    os << *it <<" ";
    return os;
}

int main()
{
    string s;
    int N,M;
    cin >> N >> M >> s;
    s[M-1] = tolower(s[M-1]);
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include <stdlib.h>

struct NODE{
  int k;
  struct  NODE *p;
  struct NODE *l;
  struct NODE *ri;
};
typedef struct NODE * node;
#define N NULL
node r;
void ins(int o){
  node a=N;
  node b=r;
  node c;
  c=malloc(sizeof(struct NODE));
  
  c->k = o;
  c->l = N;
  c->ri = N;
  while(b!=N){
    a = b;
    if(c->k < b->k){
      b=b->l;
    }
    else{
      b=b->ri;
    } 
  }
  c->p=a;
  if(a==N){
    r=c;
  }
  else{
    if(c->k < a->k){
      a->l=c;
    }
    else{
      a->ri=c;
    }
  }
}

void T(node R){
  if(R==N)return;
  T(R->l);
  printf(" %d",R->k);
  T(R->ri);
}

void S(node R){
  if(R==N)return;
  printf(" %d",R->k);
  S(R->l);
  S(R->ri);
}
node s(node l,int c){

  while(l !=N && c != l->k){
    if(c < l->k) {
      l = l->l;
    }
    else {
      l = l->ri;
    }
  }
  return l;
}

int main(){
  int i,j,o,h;
  char O[10];
  scanf("%d",&o);
  for(i=0;i<o;i++){
    scanf("%s",O);
    if(strlen(O)==6){
      scanf("%d",&h);
      ins(h);
    }
    else if(strlen(O)==4){
      scanf("%d",&h);
      node f = s(r,h);
      if(f != N)printf("yes\n");
      else printf("no\n");
    }
    else{
      T(r);
      printf("\n");
      S(r);
      printf("\n");
    }
  }
  return 0;
}



Measured memory_bytes: 20496
#include <iostream>

using namespace std;

int am(int n) {

    int cnt = 0;

    while(n%2 == 0) {
        n /= 2;
        cnt++;
    }

    return cnt;

}

int main() {

    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    pair<int, int> mx = {0, 1};
    int t = 0;

    for(int i = 1; i <= n; i++) {

        t = am(i);

        if(t >= mx.first) {
            mx.first = t;
            mx.second = i;
        }

    }

    cout << mx.second;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main () {
  int n = 0, A[100], i, j, key = 0;

  for(i = 0 ; i < 100 ; i++) A[i] = 0;

  scanf("%d",&n);

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

  for(i = 0 ; i < n ; i++) {
    if(i == n - 1) printf("%d",A[i]);
    else printf("%d ",A[i]);
  }
  printf("\n");

  for(i = 1 ; i <= n - 1 ; i++) {
    key = A[i];
    j = i - 1;

    while(j >= 0 && A[j] > key) {
      A[j + 1] = A[j];
      j--;
    }
    A[j + 1] = key;

    for(j = 0 ; j < n ; j++) {
      if(j == n - 1) printf("%d",A[j]);
      else printf("%d ",A[j]);
    }
    printf("\n");
  }
  

  return 0;
}



Measured memory_bytes: 2068
from collections import Counter

N=int(input())
A=list(map(int,input().split()))
c = Counter(A)
keys=c.keys()
ans = 0
for key in keys:
    ans+=c[key]*(c[key]-1)/2
for a in A:
    amin = (c[a]*(c[a]-1)/2) - ((c[a]-1)*(c[a]-2)/2)
    
    
    
    
    print(int(ans-amin))

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

ll dp[410][410];

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    ll MA, MB;
    cin >> N >> MA >> MB;

    vector<ll> A(N);
    vector<ll> B(N);
    vector<ll> C(N);

    REP(i, N){
        cin >> A[i] >> B[i] >> C[i];
    }

    Fill(dp, LINF);

    dp[0][0] = 0;

    REP(n, N){
        for(ll i=400; i>=0; i--){
            for(ll j=400; j>=0; j--){
                if(i < A[n]) continue;
                if(j < B[n]) continue;
                dp[i][j] = min(dp[i-A[n]][j-B[n]]+C[n], dp[i][j]);
            }
        }
    }
    
    // REP(i, 10){
    //         REP(j, 10){
    //             cout << "i:" << i << " j:" << j << " dp:" << dp[i][j] << endl;
    //         }
    // }
    ll ans = LINF;
    for(ll i=1; i<=400; i++){
        if(MA*i>400) break;
        if(MB*i>400) break;

        if(dp[MA*i][MB*i] != LINF){
            ans = min(ans, dp[MA*i][MB*i]);
            // cout << ans << endl;
        }
    }
    
    if(ans == LINF){
        cout << -1 << endl;
    }
    else{
        cout << ans << endl;
    }
    return 0;
}

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

int main(void) {
  int cc = 0;
  string s;
  bool ans = true;
  cin >> s;
  
  for (int i = 0; i < s.size(); i++) {
    if (i == 0 && s[i] != 'A') {
      ans = false;
      break;
    }
    if (2 <= i && i <= s.size() - 2 && s[i] == 'C')
      cc++;
    if (i != 0 && s[i] != 'C' && 'A' <= s[i] && s[i] <= 'Z') {
      ans = false;
      break;
    }
  }
  
  if (cc != 1)
    ans = false;
    
  cout << (ans ? "AC" : "WA") << endl;
}


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

string solve() {
    ll N;
    cin >> N;
    ll t = 26, k = 1;
    N--;
    while ( N >= t ) {
        k++;
        N -= t;
        t *= 26;
    }
    string s;
    for ( int i = 0; i < k; i++ ) {
        s.push_back('a' + (N % 26));
        N /= 26;
    }
    reverse(s.begin(), s.end());
    return s;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
const int N=3e5+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("E.in","r",stdin);
	freopen("E.out","w",stdout);
#endif
}
int n,k;
int a[N];
void input()
{
	k=read<int>(),n=read<int>();
}
void work()
{
	if(k&1)
	{
		int last=n;
		For(i,1,n)a[i]=(k+1)/2;
		For(i,1,n/2)
		{
			if(a[last]==1)last--;
			else
			{
				a[last]--;
				For(j,last+1,n)a[j]=k;
				last=n;
			}
		}
		For(i,1,last)write(a[i],' ');
	}
	else
	{
		a[1]=k/2;
		For(i,2,n)a[i]=k;
		For(i,1,n)write(a[i],' ');
	}
}
int main()
{
//	file();
	input();
	work();
	return 0;
}


Measured memory_bytes: 3456
// AOJ 2456: Usoperanto
// 2018.4.17 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// マイナス値の入力に対応
//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	if (c == '-') { c = getchar_unlocked();
		do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

#define MAX 1000002
int  N;
int  m[MAX];
int  *base, bsz;
int  hi[MAX], *to[MAX];
int  que[MAX], top;
int  a[MAX], b[MAX], s[MAX];
long long dp[MAX];

int cmp(int *a, int *b) { return *b - *a; }

void calc(int u)
{
	int i, v, sz;

	sz = 0, s[u] = m[u], dp[u] = 0;
	for (i = 0; i < hi[u]; i++) {
		v = to[u][i];
		b[sz++] = s[v], s[u] += s[v], dp[u] += dp[v];
	}
	qsort(b, sz, sizeof(int), cmp);
	for (i = 0; i < sz; i++) dp[u] += b[i]*i;
}

int main()
{
	int i, l, t;
	long long ans;
	int *memo;

	N = in();
	memo = malloc(N<<2);
	for (i = 0; i < N; i++) {
		m[i] = in(), memo[i] = l = in();
		if (l == -1) bsz++;
		else hi[l]++;
	}
	base = malloc(bsz<<2);
	for (i = 0; i < N; i++) if (hi[i]) to[i] = malloc(hi[i]<<2);
	bsz = 0, memset(hi, 0, N<<2);

	for (i = 0; i < N; i++) {
		l = memo[i];
		if (l == -1) base[bsz++] = i;
		else to[l][hi[l]++] = i;
	}

	ans = 0;
	for (i = 0; i < bsz; i++) {
		if (hi[base[i]] < 1) continue;
		que[1] = base[i], top = 1;
		while (top) {
			t = que[top];
			if (a[t] < hi[t]) que[++top] = to[t][a[t]++];
			else calc(t), top--;
		}
		ans += dp[base[i]];
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 72084
def main():

    N = int(input())
    one=9
    hun=900
    man=90000

    if N <= 9:
        print(N)
        exit()
    elif N <= 99:
        print(9)
        exit()
    elif N <= 999:
        print(N-99+9)
        exit()
    elif N <= 9999:
        print(909)
        exit()
    elif N <= 99999:
        print(N-9999+909)
        exit()
    else:
        print(90909)




    
if __name__== "__main__":
    main() 




Measured memory_bytes: 3060
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
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; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion


void Main();
void solve(long long A, long long B, long long H, long long M);

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long H;
    scanf("%lld",&H);
    long long M;
    scanf("%lld",&M);
    solve(A, B, H, M);
}

void solve(long long A, long long B, long long H, long long M){
    long double theta = (H*30.0 + M*0.5) - M*6.0;
    theta = abs(theta)*2*M_PI/360.0;
    long double c = A*A + B*B - 2.0*A*B*cos(theta);
    cout << sqrt(c) << el;
}



Measured memory_bytes: 4228
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  ll N, M;
  cin >> N >> M;

  unordered_set<ll> AC;
  unordered_map<ll, ll> WA;

  ll ans_ac = 0;
  ll ans_pn = 0;

  rep (i, M) {
    ll p;
    string s;
    cin >> p >> s;
    if (s == "WA") WA[p]++;
    if (s == "AC" and AC.count(p) == 0) {
      ans_ac++;
      ans_pn += WA[p];
      AC.insert(p);
    }
  }

  cout << ans_ac << " " << ans_pn << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}


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

#define ll long long
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define fo(i,a,b) for(ll i=a; i<b; i++)

int main(){
    ll N, sv;
    cin >> N;
    vl num(N);
    
    fo(i,1,N){
        cin >> sv;
        num[sv-1]++;
    }

    fo(i,0,N) cout << num[i] << endl;
    
}

/*
　 ◇　　　　 ミ ◇
　◇◇　 /￣|　 ◇◇
◇◇＼　 L＿| ◇◇
　　彡Ｏ(・＿・)/
　 　　ヽ Ｐ`Ｏ
　　 ／彡#_|ミ＼
　　　 </LL凵>
　　　　∪ ∪
pass system test !!
*/

Measured memory_bytes: 4752
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define all(v) v.begin(),v.end()
#define fio() ios::sync_with_stdio(0);cin.tie(0);
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define fornn(i,a,n) for(ll i=a;i<=n;i++)
#define pb push_back
#define MAXN 100005LL
#define INF 1000000005LL
inline void solve(){
	ll X,A,B;
	cin>>X>>A>>B;
	cout<<(X-A)-((X-A)/B)*B;
}
int main(){
	// #ifndef ONLINE_JUDGE
	// freopen("output.txt","w",stdout);
	// freopen("input.txt","r",stdin);
	// #endif
	fio();
	ll t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
} 

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

int main() {
  int N, K;
  cin >> N >> K;
  bool dp[200010] = {false};
 
  int a[N];
  for (int i = 0; i < N; i++) cin >> a[i];
  
  for (int i = 0; i < K; i++) {
    if (dp[i]) {
      continue; 
    } else {
      for (int j = 0; j < N; j++) dp[i + a[j]] = true;
    }
    
  }
  
  if (dp[K]) {
    cout << "First" << endl;
  } else {
    cout << "Second" << endl;
  }
  
}

Measured memory_bytes: 384
N,M,K = list(map(int,input().split(' ')))

friend_list = [0]*(N+1)
bad_list = [0]*(N+1)
group = {}

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

def find(i):
    rireki = []
    while parent[i] != i:
        rireki.append(i)
        i = parent[i]
    for r in rireki:
        parent[r]=i
    return i

def union(i, j):
    i = find(i)
    j = find(j)
    parent[j] = i



for i in range(M):
    A,B = list(map(int,input().split(' ')))
    friend_list[A]+=1
    friend_list[B]+=1
    
    union(A,B)

for i in range(1,N+1):
    oya = find(i)
    parent[i] = oya
    #print(oya)
    if oya in group:
        group[oya] = group[oya]+1
    else:
        group[oya]=1

for i in range(K):
    A,B = list(map(int,input().split(' ')))
    if find(A)==find(B):
        bad_list[A]+=1
        bad_list[B]+=1
    
    #union(A,B)



#print(parent)
#print('parent')

#print('friend')
#print(friend_list)
#print('bad')
#print(bad_list) 
#print(group)

kouho = [0]*N

for i in range(1,N+1):
    oya = find(i)
    abc = group[oya]-friend_list[i]-bad_list[i]-1
    kouho[i-1] = abc

for k in kouho:
    print(k,end=" ")
print()

#print(parent)


Measured memory_bytes: 78112
#include <bits/stdc++.h>
using namespace std;
 
int main(void)
{
    int n,m,mx=0;
    cin >> n;
    vector<string> ss(n);
    for(int i=0;i<n;i++){
        cin >> ss.at(i);
    }
    cin >> m;
    vector<string> tt(m);
    for(int i=0;i<m;i++){
        cin >> tt.at(i);
    }
    for(int i=0;i<n;i++){
        int count = 0;
        for(int j=0;j<n;j++){
            if(ss.at(i)==ss.at(j)) count++;
        }
        for(int k=0;k<m;k++){
            if(ss.at(i)==tt.at(k)) count--;
        }
        mx=max(count,mx);
    }
    cout << mx;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
#define MAX 100000
void inarray(int a[], int n){
    for(int i = 0; i < n; i++) cin >> a[i];
}

int main(){
    ll h,w; cin >> h >> w;
    if(h == 1 || w == 1) {cout << 1 << endl; return 0;}
    ll ans  = h*w/2;
    if(h%2 == 1 && w%2 == 1) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/**
 *	 Code by b21
 *	 Time: 19:03 Sat 14/03/2020
**/

#include <bits/stdc++.h>

using namespace std;

const int mn = 1 * (int)(1e5) + 10;
const int mod = 1 * (int)(1e9) + 7;
const int mm = 1 * (int)(1e3) + 10;
const int base = 1 * (int)(1e9);
const bool aNs = 0;

int tt, ntest = 1;
void docfile()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    if (ifstream("test.inp"))
    {
       freopen("test.inp", "r", stdin);
       if (!aNs) freopen("test.out", "w", stdout);
       else freopen ("test.ans", "w", stdout);
    }
   else if (ifstream("panasonic2020a.inp"))
    {
        freopen("panasonic2020a.inp", "r", stdin);
        freopen("panasonic2020a.out", "w", stdout);
    }
}

template <typename T>
void read(T& x)
{
    x = 0; T f = 1;
    char ch = getchar();
    while (!isdigit(ch)) f = ch == '-' ? - f : f, ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
    x *= f;
}

template <typename T>
void write (T a)
{
    if (a < 0)
    {
        putchar ('-');
        write (-a);
        return;
    }
    if (a < 10)
    {
        putchar ('0' + a);
        return;
    }
    write (a / 10);
    putchar ((char)('0' + (a % 10)));
}

void enter()
{
    long long h, w;
    cin >> h >> w;
    if (h == 1 || w == 1) {
        cout << 1;
        return;
    }
    cout << h * w / 2 + (h % 2 && w % 2);
}

void solve()
{

}

void print_result()
{

}

main()
{
    docfile();
    //cin>>ntest;
    for (tt = 1; tt <= ntest; ++ tt)
    {
        enter();
        solve();
        print_result();
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define mod 998244353
#define N 300010
ll n,a[N];
ll fac[N];
ll solve(){
	{//全て1のケース
		bool ok=1;
		rep(i,n)ok&=(a[i]==1);
		if(ok)return fac[n];
	}
	ll k=0;
	{//kを求める、kがゼロなら0を返す
		rep(i,n)k+=(a[i]==1);
		if(k==0)return 0;
	}
	cerr<<__LINE__<<endl;
	{//1,1,..,1が左端に来るようにする
		ll p=0;
		rep(i,n-1)if(a[i]!=1&&a[i+1]==1)p=i+1;
		ll cop[N];
		rep(i,n)cop[i]=a[i];
		rep(i,n)a[i]=cop[(i+p)%n];
	}
	cerr<<__LINE__<<endl;
	ll l[N],r[N],len[N];
	{//l,r,cntを設定、同じ値が連続していなければ0を返す
		for(int i=1;i<=n;i++){
			l[i]=1e17,r[i]=-1e17;
			len[i]=0;
		}
		rep(i,n){
			chmin(l[a[i]],(ll)i);
			chmax(r[a[i]],(ll)i);
			len[a[i]]++;
		}
		for(int i=1;i<=n;i++){
			if(l[i]!=1e17){
				if(r[i]-l[i]+1!=len[i]){
					return 0;
				}
				if(len[i]>k){
					return 0;
				}
			}
		}
	}
	cerr<<__LINE__<<endl;
	ll ans=1;
	{//最後の列にあるものの場合の数
		for(int i=1;i<=n;i++){
			if(l[i]==1e17)continue;
			ll vl=a[(l[i]-1+n)%n];
			ll vr=a[(r[i]+1)%n];
			if(i<vl&&i<vr){
				if(len[i]<k)return 0;
			}
			if(i>vl&&i>vr){
				ans=ans*(k-len[i]+1)%mod;
			}
		}	
	}
	cerr<<__LINE__<<" "<<ans<<endl;
	ll cnt[N];
	//cnt[x]:=x+1以上のものがいて良い場所の個数(xはダメ)
	{//cntを求める
		rep(i,N)cnt[i]=0;
		for(int i=1;i<=n;i++){
			if(l[i]<1e17)cnt[i]--;
		}
		ll aa[2*N];
		rep(i,n)aa[i]=a[i],aa[i+n]=a[i];
		deque<ll> Q;
		rep(i,2*n){
			while(!Q.empty()){
				if(aa[Q.back()]<=aa[i])Q.pop_back();
				else break;
			}
			Q.push_back(i);
			while(!Q.empty()){
				if(Q.front()<=i-k)Q.pop_front();
				else break;
			}
			if(k-1<=i&&i<n+k-1){
				cnt[aa[Q.front()]]++;
			}
		}
	}
	{//最後の列にないものの場合の数
		ll rui=0;
		for(int i=1;i<=n;i++){
			if(l[i]==1e17){
				if(rui<=0)return 0;
				ans=ans*rui%mod;
				rui--;
			}
			rui+=cnt[i];
		}
	}
	return ans;
}
int main(){
	fac[0]=1;
	for(ll i=1;i<N;i++)fac[i]=fac[i-1]*i%mod;
	cin>>n;
	rep(i,n)cin>>a[i];
	cout<<solve()<<endl;
}


Measured memory_bytes: 19712
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int N,M;
ll dp[2005];
ll dp2[105][205],work[105][205];
ll next_ch[26];
ll K;
ll len[105];
double tmp_K;
char word[105][205];

void add(ll &A,ll B){
	A = min(K,A+B);
}

ll mult(ll A,ll B){

	double tmp_A = A,tmp_B = B;

	if(tmp_A*tmp_B > tmp_K){

		return K;

	}else{

		return A*B;
	}
}

int main(){

	scanf("%d %d %lld",&N,&M,&K);

	tmp_K = (double)K;

	int length;

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

		scanf("%s",word[i]);

		for(length = 0; word[i][length] != '\0'; length++);

		len[i] = length;
	}

	dp[0] = 1;
	for(int i = 1; i <= M; i++){
		dp[i] = 0;
	}

	for(int left = 0; left <= M-1; left++){
		for(int i = 0; i < N; i++){

			if(left+len[i] > M)continue;

			add(dp[left+len[i]],dp[left]);
		}
	}

	for(int i = 0; i < N; i++){
		for(int k = 0; k < len[i]; k++){
			dp2[i][k+1] = 0;
		}
	}

	bool FLG = false;

	for(int i = 0; i < N; i++){
		if(len[i] <= M){
			dp2[i][len[i]-1] = 1;
			FLG = true;
			break;
		}
	}

	if(!FLG){
		printf("-\n");
		return 0;
	}

	queue<char> ANS;
	ll tmp,sum;
	char tmp_ch;

	for(int i = 0; i < M; i++){

		for(int ch = 0; ch < 26; ch++){

			next_ch[ch] = 0;
		}

		for(int a = 0; a < N; a++){
			for(int k = 0; k < len[a]; k++){

				if(k == len[a]-1){

					for(int b = 0; b < N; b++){

						add(next_ch[word[b][0]-'a'],mult(dp2[a][k],dp[M-i-len[b]]));
					}

				}else{

					add(next_ch[word[a][k+1]-'a'],mult(dp2[a][k],dp[M-i-len[a]+k+1]));
				}
			}
		}

		sum = 0;
		tmp_ch = '@';

		for(int k = 0; k < 26; k++){

			tmp = sum;

			sum += next_ch[k];

			if(sum >= K){
				tmp_ch = 'a'+k;
				ANS.push(tmp_ch);
				K -= tmp;
				break;
			}
		}

		if(tmp_ch == '@'){

			printf("-\n");
			return 0;
		}

		for(int a = 0; a < N; a++){
			for(int b = 0; b < len[a]; b++){
				work[a][b] = 0;
			}
		}

		for(int a = 0; a < N; a++){
			for(int k = 0; k < len[a]; k++){

				if(k == len[a]-1){

					for(int b = 0; b < N; b++){
						if(word[b][0] != tmp_ch)continue;
						add(work[b][0],dp2[a][k]);
					}

				}else{

					if(word[a][k+1] != tmp_ch)continue;
					add(work[a][k+1],dp2[a][k]);
				}
			}
		}

		for(int a = 0; a < N; a++){
			for(int k = 0; k < len[a]; k++){
				dp2[a][k] = work[a][k];
			}
		}
	}

	while(!ANS.empty()){
		printf("%c",ANS.front());
		ANS.pop();
	}

	printf("\n");

	return 0;
}



Measured memory_bytes: 3524
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
using namespace std::chrono;

#define ll long long
#define ld long double
#define pq priority_queue
#define ff first
#define ss second
#define pb push_back
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(c) ((ll)c.size())
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mod1 998244353
#define mod2 1000000007

#ifdef LL
const ll INF = 1e18;
#else 
const ll INF = 1e9;
#endif

typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

high_resolution_clock::time_point curTime() { return high_resolution_clock::now(); }
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);} //Just add this as a third argument to sort() while sorting an array of pairs; NO NEED FOR ANY ARGUMENTS;
template <typename T>
T fact(T a, T mod){ int res = 1, i; for (i = 2; i <= a; i++){ res *= i; res%=mod;} return res; }
template <typename T>
ll powmod(T a,T b,ll m){ ll ans=1; while(b>0){if(b&1){ans*=a;ans%=m;}a*=a;a%=m;b>>=1;} return ans; }
template <typename T>
ll power(T a, T b){ ll ans=1; while(b>0){if(b&1){ans*=a;}a*=a;b>>=1;}return ans;}
template <typename T>
T max3(T a, T b, T c) { return max((max(a,b), max(b,c))); }
template <typename T>
T min3(T a, T b, T c) { return min((min(a,b), min(b,c))); }
template <typename T>
T mid3(T a, T b, T c) { return a+b+c-max3(a,b,c)-min3(a,b,c); }
template <typename T>
T mid(T a, T b) { return min(a,b)+((max(a,b)-min(a,b))/2); }
template <typename T>
T gcd(T a,T b){ return (b?__gcd(a,b):a); }
template <typename T>
T lcm(T a, T b){ return (a*(b/gcd(a,b))); }
template <typename T>
T cl(T a, T b){ return (a+b-1)/b; }
template <typename T>
T set_bits(T a)
{ return __builtin_popcount(a); }
template <typename T>
T add_self(T& a, T b, T mod){ a+=b; if(a>=mod){ a-=mod; } }
template <typename T>
T to_upper(T s){ return transform(s.begin(), s.end(), s.begin(), ::toupper); }
template <typename T>
T to_lower(T s){ return transform(s.begin(), s.end(), s.begin(), ::tolower); }

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    auto startTime = curTime();

    int n,k;
    cin>>n>>k;

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

    vi dp(k+1, 0);
    for(int i=1;i<=k;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(i>=a[j])
            {
                if(dp[i-a[j]]==0) dp[i]=1;
            }
        }
    }

    cout<<(dp[k] ? "First" : "Second")<<endl;

    auto stopTime = curTime();
    auto duration = duration_cast<microseconds>(stopTime - startTime);
    //cout<<"Program ran for "<<(ld)duration.count()/1e6<<" "<<"seconds"<<endl;
}


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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define SORTG(v) sort(v.begin(),v.end(),greater<>())
#define SORT(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/3

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<string> Vs;

template<class T> void chmax(T& a, T b) {if(a<b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a>b){a=b;}}
void YesNo(int a) {if(a){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}}
void YESNO(int a) {if(a){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}}
void AorB(int a,string b,string c) {if(a){cout<<b<<endl;}else{cout<<c<<endl;}}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void start(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);}

bool check(int n){
    if(1<=n && n<=12) return true;
    else return false;
}

signed main(){start();
    int n;
    cin>>n;
    int kami=n/100,simo=n%100;
    if(check(kami) && check(simo)) cout<<"AMBIGUOUS"<<endl;
    if(check(kami) && !check(simo)) cout<<"MMYY"<<endl;
    if(!check(kami) && check(simo)) cout<<"YYMM"<<endl;
    if(!check(kami) && !check(simo)) cout<<"NA"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(x, y) for(int x = 0; x < (y); x++)
#define REP(x, z, y) for(int x = (z); x < (y); x++)
#define all(x) x.begin(), x.end()
#define len(x) (sizeof(x) / sizeof(x[0]))
#define split_str(str, sp_word) istringstream stream(str); string res; for(int cnt = 0; getline(stream,res,sp_word); cnt++)
#define scanln(x) fgets(x, sizeof x, stdin)
#define down_queue(x) priority_queue<x>
#define up_queue(x) priority_queue<x, vector<x>, greater<x>>
#define i_str(x) atoi(x.c_str())
#define digit(x) ((int)log10((double)(x)) + 1)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
using namespace std;
const int MOD = 1000000007; 
typedef long long ll;
typedef string str;
 
int main(){
  char c;
  cin >> c;
  str vowels = "aiueo";
  for(int i : vowels){
    if(c == i) {
      printf("vowel");
      return 0;
    }
  }
  printf("consonant");
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define re register
#define inc(i,j,k) for(re int i=j;i<=k;i++)
#define ll long long 
using namespace std;
const int mod=998244353;
const int inv2=499122177;
inline int read(){
	int x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while('0'<=ch&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x;	
}
int n,u;
ll g[1<<18],f[1<<18],all;
ll qp(ll x,ll k){
	ll res=1;
	while(k){
		if(k&1) res=res*x%mod;
		k>>=1,x=x*x%mod;
	}
	return res;
}
void fwt(ll *tmp,int tp){
	for(re int mid=1;mid<=u;mid<<=1){
		for(re int i=0;i<=u;i+=(mid<<1)){
			inc(j,0,mid-1){
				ll x=tmp[i+j],y=tmp[i+j+mid];
				tmp[i+j]=(x+y)%mod;
				tmp[i+j+mid]=(x-y+mod)%mod;
				if(tp==-1) tmp[i+j]=tmp[i+j]*inv2%mod,tmp[i+j+mid]=tmp[i+j+mid]*inv2%mod;
			}
		}
	}
}
int main(){
	n=read();u=(1<<n)-1;
	inc(i,0,u) f[i]=read(),all+=f[i];
	all=qp(all,mod-2);
	inc(i,0,u) f[i]=f[i]*all%mod;
	g[0]=u;inc(i,1,u) g[i]=mod-1;
	f[0]=(f[0]+mod-1)%mod;
	fwt(f,1),fwt(g,1);
	inc(i,0,u) f[i]=g[i]*qp(f[i],mod-2)%mod;
	fwt(f,-1);
	inc(i,1,u) f[i]=(f[i]-f[0]+mod)%mod;
	puts("0");
	inc(i,1,u) printf("%lld\n",f[i]);
}
/*
2 
1 1 1 1
*/

Measured memory_bytes: 7852
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
  string S; cin >> S;
  if (S == "ABC") cout << "ARC" << endl;
  else cout << "ABC" << endl;


  return 0;
}


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

int a[200];

int main() {
	int n, x; cin >> n >> x;
	for (int i = 0; i < n; i++) {
		cin >> a[i]; x -= a[i];
	}
	sort(a, a + n);
	int ans = n;
	ans += x / a[0];
	cout << ans << endl;
	return 0;
}

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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int p = 0;
  p = c - b ;
  if ( p > 0 && p > a) cout << "dangerous" << endl;
  else if ( p > 0 && p <= a)cout << "safe" << endl;
  else if ( p <= 0 ) cout << "delicious" << endl;
}


Measured memory_bytes: 256
while True:
    cnt = 0
    ipt = [int(i) for i in input().split()]
    n = ipt[0]
    x = ipt[1]
    if n == 0 and x == 0:
        break
    for i in range(1, n-1):
        for j in range(i+1, n):
            k = x - (i+j)
            if k > j and k <= n:
                cnt += 1
    print(cnt)
    



Measured memory_bytes: 5600
#include<iostream>
#include<string>

using namespace std;

int main(){

	string a, b, c;

	while(cin >> a, !cin.eof())
	{
		cin >> b;

		int res = 0;
		c = string(b.size(),'1');
		a = c + a;
		
		for(int i = 0; i < (int)a.size(); i++)
		{
//			cout << a << endl;
//			cout << b << endl;
			
			int ct = 0;
			
			for(int j = 0; j < min(a.size(), b.size()); j++)
			{
				if( a[j] == b[j] )
					res = max( ++ct, res );
				else
					ct = 0;
			}
			
			b = "2" + b;
//			cout << ct << endl;
		}
		
		cout << res << endl;
	}
	return 0;	
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N;

ll i, j, k,ans;
int main(){
    scanf("%lld",&N);
    printf("%lld", (N - 1) * N / 2);
    return 0;
}

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

typedef long long ll;
typedef pair<long long, int> P;


int main(void){
    ll n,a[100000],b[100000],x=0,y=0;
    P p[100000];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
        p[i].first=a[i]+b[i];
        p[i].second=i;
    }
    sort(p,p+n,greater<P>());
    for(int i=0;i<n;i++){
        if(i%2==0){
            x+=a[p[i].second];
        }else{
            y+=b[p[i].second];
        }
    }
    cout<<x-y<<endl;
}


Measured memory_bytes: 3328