akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
using namespace std;

const auto gcu = getchar_unlocked;
const auto pcu = putchar_unlocked;
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _sc _il bool scan
_T T in(int c){T n=0;int m=1;while(isspace(c)){c=gcu();}if(c=='-')m=-1,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
_il int in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _ot _il void out
#define _ol _il void outl
_ot(bool b) {pcu('0'+b);}
_ot(const char *s){while(*s)pcu(*s++);}
_ot(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_ot(string s){for(char c:s)pcu(c);}
#endif
_T _ot(T n){static char b[20];char *p=b,m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=n%10*m+'0',n/=10;while(p!=b)pcu(*--p);}
_ol(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _ot(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _ot(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _ol(T&&... t){out(move(t)...);outl();}

struct item {int v, w;};

int main() {
	int N = in(), W = in();
	vector<item> items(N);
	for (item &i : items)
		i = {in(), in()};
	vector<int> dp(W + 1);
	for (int i = 0; i < N; i++)
		for (int w = items[i].w; w <= W; w++)
			dp[w] = max(dp[w - items[i].w] + items[i].v, dp[w]);
	outl(dp[W]);
}


Measured memory_bytes: 2620
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 
#define ll long long 
#define int long long 
#define vll vector<long long>
#define pii pair<long long ,long long > 
#define vvi vector< vector<long long > > 
#define vpii vector<pair<int,int>> 
#define pll  pair<long long ,long long > 
#define pb  push_back
#define ff  first 
#define sec second  
#define SORT(a) sort(a.begin(),a.end())
#define SORTR(a) sort(a.rbegin(),a.rend()) 
#define m_p make_pair
#define all(x)   (x.begin(),x.end()) 
#define sz(v)     ((int)(v.size()))
#define INF 1e9+7
typedef vector< long long > vi ;
const int MOD=1e9 +7 ;
int size=10000000; 

int32_t main(){
  fast; 
  
  int n , m ; cin>>n>>m ; 

  cout<<n*(n-1)/2 + (m*(m-1)/2); 
   
  return 0; 
}

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

const int MOD=1e9+7;

int main(){
    int N; cin >> N;
    long long dp[N+1][5][5][5]={};
    dp[0][0][0][0]=1; 
    for(int n=0;n<N;n++){
        for(int i=0;i<5;i++){ //1文字目
            for(int j=0;j<5;j++){ //2文字目
                for(int k=0;k<5;k++){ //3文字目
                    for(int l=1;l<5;l++){ //4文字目
                        if(j==1&&k==3&&l==2) continue; //a:1 g:2 c:3 t:4
                        if(i==1&&j==2&&l==3) continue;
                        if(j==2&&k==1&&l==3) continue;
                        if(i==1&&k==2&&l==3) continue;
                        if(j==1&&k==2&&l==3) continue;
                        dp[n+1][j][k][l]+=dp[n][i][j][k]%MOD;
                        dp[n+1][j][k][l]%=MOD;
                    }
                }
            }
        }
    }
    long long ans=0;
    for(int i=1;i<5;i++){
        for(int j=1;j<5;j++){
            for(int k=1;k<5;k++){
                ans+=dp[N][i][j][k]%MOD;
                ans%=MOD;
            }
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,k;cin>>a>>b>>k;
  int cnt=0,ans=0;
  for(int i=min(a,b);i>=1;i--){
    if((a%i==0)&&(b%i==0)){
      cnt++;
      if(cnt==k){
        cout<<i<<endl;
        return 0;
      }
    }
  }
}

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = getInt(sc);
		int n = getInt(sc);
		List<Integer> p = new ArrayList<Integer>();
		for (int i = 0; i < n; i++) {
			p.add(getInt(sc));
		}

		for (int i = 0; i < 100; i++) {
			if (!p.contains(x - i)) {
				System.out.println(x - i);
				break;
			} else if (!p.contains(x + i)) {
				System.out.println(x + i);
				break;
			}
		}

	}

	/**
	 * *汎用メソッド<br>
	 * 入力した配列に対する順列を取得
	 *
	 * @param numArray
	 * @return
	 */
	private static List<Integer[]> getPermutation(int[] numArray) {
		List<Integer[]> permutation = new ArrayList<>();
		Integer[] ans = new Integer[numArray.length];
		boolean[] used = new boolean[numArray.length];

		return buildPermutaion(permutation, numArray, ans, used, 0);
	}

	/**
	 * *汎用メソッド(内部)<br>
	 * 入力した配列に対する順列を作成
	 *
	 * @param list
	 * @param numArray
	 * @param ans
	 * @param used
	 * @param depth
	 * @return
	 */
	private static List<Integer[]> buildPermutaion(List<Integer[]> list, int[] numArray, Integer[] ans, boolean[] used,
			int depth) {

		// 全部使い切った時=>できた順列を返す
		if (depth == numArray.length) {
			list.add(ans.clone());
			return list;
		}
		// 使い切っていない場合

		for (int i = 0; i < numArray.length; i++) {
			if (used[i]) {
				continue;
			}
			ans[depth] = numArray[i];
			used[i] = true;
			list = buildPermutaion(list, numArray, ans, used, depth + 1);

			used[i] = false;
		}

		return list;
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

}


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

int main() {
  int n;
  cin >> n;
  map<long long, int> a;

  for (int i = 0; i < n; i++) {
    int b;
    cin >> b;
    a[b]++;
    // if (a.at(b) == 1) a.at(b)--;
  }
  int count = 0;
  for (auto p : a) {
    if (p.second % 2 == 1) count++;
  }
  cout << count;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7, MAX_N = 2010;
int C[MAX_N][MAX_N];

int main(){
  for(int i = 0; i < MAX_N; i++){
    C[i][0] = 1;
    for(int j = 1; j <= i; j++) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % M;
  }
  int N, K; cin >>N >>K;
  for(int i = 1; i <= K; i++) cout <<1ll * C[N - K + 1][i] * C[K - 1][i - 1] % M <<endl;
  return 0;
}


Measured memory_bytes: 15104
import java.io.BufferedReader;
//import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
 
public class Main {
 
    public static void main(String[] args) throws NumberFormatException, IOException {
 
        Node[] node = input();
        print(node);
    }
     
    public static Node[] input() throws NumberFormatException, IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        Node[] node = new Node[n];
        for(int i = 0; i < n; ++i) {
            node[i] = new Node(i);
        }
        for(int i = 0; i < n; ++i) {
            String[] t = br.readLine().split(" ");
            int id = Integer.parseInt(t[0]);
            int k = Integer.parseInt(t[1]);
            for(int j = 0; j < k; ++j) {
                int c = Integer.parseInt(t[j+2]);
                node[id].child.add(node[c]);
                node[c].parent = node[id];
            }
        }
        return node;
    }
     
    public static void print(Node[] node){
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < node.length; ++i) {
            // example
            // node 0: parent = -1, depth = 0, root, [1, 4, 10]
            sb.append("node " + node[i].id);
            sb.append(": parent = " + node[i].parent.id);
            sb.append(", depth = " + node[i].getDepth());
            sb.append(", " + node[i].getType());
            sb.append(", [");
            int c = node[i].child.size();
            for(int j = 0; j < c; ++j) {
                if(j != 0){
                    sb.append(", ");
                }
                sb.append(node[i].child.get(j).id);
            }
            sb.append("]\n");
 
        }
        System.out.print(sb);
    }
}
 
class Node {
    public int id;
    public Node parent;
    public ArrayList<Node> child = new ArrayList<Node>();
    public Node(int id){
        this.id = id;
        if(id != -1){
            parent = new Node(-1);
        }
    }
 
    public int getDepth(){
        if(parent.id == -1){
            return 0;
        }else{
            return parent.getDepth() + 1;
        }
    }
     
    public String getType(){
        if(parent.id == -1){
            return "root";
        }else if(child.size() == 0){
            return "leaf";
        }else{
            return "internal node";
        }
         
    }
}

Measured memory_bytes: 113796
n = int(input())
p = [i for i,j in sorted([[i,pp] for i,pp in enumerate(map(int, input().split()))], key=lambda t:t[1])]

a = []
acc = 0
for i in range(n):
    acc += p[i]
    a.append(i + 1 + acc)
b = []
acc = 0
for i in range(n):
    acc += p[-i-1]
    b.append(i + 1 + acc)
print(*a)
print(*b[::-1])


Measured memory_bytes: 8008
#include <iostream>
#include <queue>
#include <limits>
using namespace std;

struct vec {
    int t, c;
    vec(int to, int cost):t(to),c(cost){}
    bool operator>(const vec &r)const{return t>r.t;}
};
vector<vec> adj[100];
int d[100];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=0; i<n; i++) d[i]=numeric_limits<int>::max();
    for(int i=0; i<n; i++) {
        int u,k;
        cin>>u>>k;
        adj[u].reserve(k);
        for(int j=0; j<k; j++) {
            int v,c;
            cin>>v>>c;
            adj[u].push_back(vec(v,c));
        }
    }
    priority_queue<vec, vector<vec>, greater<vec> >q;
    q.push(vec(0,0));
    while(!q.empty()) {
        vec e=q.top();
        q.pop();
        if(d[e.t]<=e.c) continue;
        d[e.t]=e.c;
        for(vector<vec>::iterator it=adj[e.t].begin(); it!=adj[e.t].end(); ++it) q.push(vec(it->t, e.c+it->c));
    }
    for(int i=0; i<n; i++) cout<<i<<' '<<d[i]<<'\n';
    return 0;
}

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

int main(){
  int N;
  vector<int> A;
  int m; //負の数の個数を求める
  int n; //絶対値が最も小さいもの
  
  long long answer;
  
  cin>>N;
  for(int i=0;i<N;i++){
    int x;
    cin>>x;
    A.push_back(x);
    if (x<0) m++;
  }
  
  if (m%2==0) {
    for(int i=0;i<N;i++) answer+=abs(A.at(i));
  }
  
  else {
    n=abs(A.at(0));
    for(int i=0;i<N;i++){
      if (n>abs(A.at(i))) n=abs(A.at(i));
      answer+=abs(A.at(i));
    }
    
    answer-=2*n;
  }
  
  cout<<answer<<endl;
}
  

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

int main() {
	int a, b;
	cin >> a >> b;
	cout << (b - a) * (b - a + 1) / 2 - b;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

b-aについて、右側の塔の高さは必ず1+2+…+b-aになります
後は等差数列の和の公式から塔の本来の高さを出せば、埋もれている高さが分かります
*/

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer n = Integer.parseInt(scanner.next());
        String str = scanner.next();

        char[] alphabet = new char[26];
        char c = 'A';

        for(int i = 0; i < 26; i++) {
            alphabet[i] = c++;
        }

        String answer = new String();
        for(int i =0 ; i < str.length(); i++) {
            for(int k =0; k < alphabet.length; k++) {
                if(str.charAt(i) == alphabet[k]) {
                    int kekka = (k+n) - (26 * ((k+n) / 26));
                    answer += alphabet[kekka];
                }
            }
        }
        System.out.println(answer);
    }
}

Measured memory_bytes: 90296
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

int main() {
	ll h, w; cin >> h >> w;
	ll n; cin >> n;
	ll a[10000] = {};
	ll m[100][100] = {};
	rep(i, 0, n)cin >> a[i];

	bool r = true;
	ll H = 0;
	ll W = 0;
	rep(i, 0, n) {
		rep(j, 0, a[i]) {
			m[H][W] = i + 1;

			if (r) {
				W++;
			}
			else {
				W--;
			}
			if (W == w) {
				H++;
				W--;
				r = !r;
				continue;
			}
			else if (W < 0) {
				H++;
				W++;
				r = !r;
				continue;
			}
		}
	}

	rep(i, 0, h) {
		rep(j, 0, w) {
			cout << m[i][j];
			if (j != w - 1) {
				cout << " ";
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 384
n = int(input())
arr = [list(map(int, input().split())) for _ in range(n-1)]
for i in range(n):
    t = 0  # 初期条件
    for j in range(i, n-1):
        ci, si, fi = arr[j]  # 各駅の条件を代入
        if t <= si:  # まだ始発が出発していないとき
            t = si
        elif t % fi == 0:
            pass
        else:  # すでに出発している時
            t = t + fi - (t % fi)
        t += ci  # 電車に乗っている時間
    print(t)

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

#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;

int main(){
	int a,b,sum=0;
	cin>>a>>b;

	if(a<b){
		sum+=b;
		b--;
	}else{
		sum+=a;
		a--;
	}

	if(a<b){
		sum+=b;
		b--;
	}else{
		sum+=a;
		a--;
	}

	cout<<sum<<endl;


}

Measured memory_bytes: 256
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
long long a,b,c,ans;
int main()
{
	cin>>a>>b>>c;
	ans=b/c-a/c+1;
	if (a%c) ans--;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <vector>
#include <string.h>
using namespace std;

int main() {
	int N;
	bool c=false;
	char S;
	
	cin>>N;
	for(int i=0;i<N;i++)
	{
		cin>>S;
		if(S=='Y'){
			c=true;
			break;
			}
	}
	cout<<((!c)?"Three":"Four");
	}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
ll A,B,C;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>A>>B>>C;
    if(A==B&&B==C) cout <<(A%2?0:-1)<<"\n";
    else{
        ll a=0;
        while(A%2==0&&B%2==0&&C%2==0){
            a++;
            ll X=(B+C)/2,Y=(C+A)/2,Z=(A+B)/2;
            A=X;
            B=Y;
            C=Z;
        }
        cout <<a<<"\n";
    }
}

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

struct disjoint_set {
    std::vector<int> par, size;
    disjoint_set(){}
    disjoint_set(int N)
    {
        par=std::vector<int>(N);
        size=std::vector<int>(N, 1);
        for(int i=0; i<N; ++i) par[i]=i;
    }
    int root(int x)
    {
        if (x==par[x]) return x;
        return par[x]=root(par[x]);
    }
    void unite(int x, int y)
    {
        x=root(x);
        y=root(y);
        if (x==y) return;
        if (size[x]<size[y]) swap(x, y);
        par[y]=x;
        size[x]+=size[y];
    }
    bool same(int x, int y) { return root(x)==root(y); }
    int getsize(int x) { return size[root(x)]; }
};

int main()
{
    int n, m; cin>>n>>m;
    vector<int> a(m), b(m);
    for(int i=0; i<m; ++i) cin>>a[i]>>b[i];

    disjoint_set s(n);
    vector<long> res(m);
    res.back()=n*(n-1L)/2;
    for(int i=m-1; i>0; --i) {
        --a[i], --b[i];
        if (s.same(a[i], b[i]))
            res[i-1]=res[i];
        else {
            res[i-1]=res[i]-1L*s.getsize(a[i])*s.getsize(b[i]);
            s.unite(a[i], b[i]);
        }
    }
    for(auto& e: res) cout<<e<<endl;
}


Measured memory_bytes: 3712
#(i)N%K!=0の時、N-Kを繰り返すことになるためN-K%K=N%Kより
#N%K=1にならないといけない
#よってこのようなKはN-1が最大であり、他は全てN-1の約数であり、(そのほかにない)
#(証)
#N%K<=>N-1%K=0より直ちに従う(ただし、K=1の時N%1=0なので注意)
#よって、N-1を素因数分解して、チャチャチャっとやって…終わり！

#(ii)N%K==0の時、約数をO(sqrt(N))で全探査し、
#高々2*(sqrt(N))の約数KについてO(log(N))オーダーで(N/K^i)%K=1かを調べる

import math
N=int(input())
l=[]
ser=[]
#(i)の部分
#素因数分解
pf={}
ans1=1
m=N-1
buf=0
for i in range(2,int(m**0.5)+1):
    while m%i==0:
        pf[i]=pf.get(i,0)+1
        m//=i
if m>1:pf[m]=1
#print(pf)
keys=list(pf.keys())
values=list(pf.values())
for i in range(len(keys)):
    l.append([keys[i],values[i]])
#print(l)	#これでlistになったろう
ans1=1
for i in range(len(keys)):
    ans1=ans1*(l[i][1]+1)
ans1=ans1-1
#print(ans1)

#(ii)の部分
ans2=0
for i in range(int(math.sqrt(N))):
    a=i+1
    b=N/a
    #print(a)
    if b.is_integer()==True:
        if a!=b:
            ser.append(a)
            ser.append(int(b))
        else:
            ser.append(a)
#print(ser)
for i in range(len(ser)):
    buf=N
    if ser[i]!=1:
        while (buf/ser[i]).is_integer()==True:
            #print(buf / ser[i])
            buf=buf//ser[i]
        if buf%ser[i]==1:
            ans2=ans2+1
#print(ser,ans2)
print(ans1+ans2)




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

#define ALL(s) begin(s), end(s)
#define RALL(s) rbegin(s), rend(s)
#define DEBUG(x) cout << #x << ": " << x << endl
#define INFILE() freopen("input.txt", "r", stdin)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define RREP(i, a, b) for (int i = (a); i >= (b); i--)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_i = pair<double, int>;
using i_d = pair<int, double>;
using d_d = pair<double, double>;

static constexpr ll LL_MOD = 1000000009;
static constexpr ll LL2_MOD = 1000000007;
static constexpr ll INF = 1LL << 60;
static constexpr double EPS = numeric_limits<double>::epsilon();
static constexpr double PI = 3.14159265358979323846264338327950288;

static map<type_index, const char *const> scanType = {
  { typeid(int), "%d" }, { typeid(ll), "%lld" }, { typeid(double), "%lf" }, { typeid(char), "%c" }};

template <class T> static void scan(vector<T>& v);
static void scan(vector<string>& v, bool isWord = true);
template <class A, size_t N, class T> void Fill(A (&arr)[N], const T &val);
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class A, size_t N, class T> void Fill(A (&arr)[N], const T &val){ std::fill((T*)arr, (T*)(arr + N), val); }

ll dp[101][100001];

int main(int argc, char *argv[]) {
  //INFILE();

  ll n, w;
  ll max_value = 100000;
  cin >> n >> w;

  vector<ll> weights(static_cast<int>(n));
  vector<ll> values(static_cast<int>(n));
  REP(i, 0, n) {
    cin >> weights[i] >> values[i];
  }

  Fill(dp, INF);
  dp[0][0] = 0;

  REP(i, 0, n) {
    REP(j, 0, max_value) {
      if (j != 0 && dp[i][j] == INF) continue;
      chmin(dp[i + 1][j], dp[i][j]);
      chmin(dp[i + 1][j + values[i]], dp[i][j] + weights[i]);
    }
  }

  RREP(i, max_value, 0) {
    if (dp[n][i] <= w) {
      cout << i << endl;
      return 0;
    }
  }
  
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}



Measured memory_bytes: 79104
import java.util.Scanner;

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

        int n = sc.nextInt();
        int a = 0;
        long sum = 0;

        for (int i=n; i>0; --i) {
            if (n == 0) {
                break;
            }
            a = sc.nextInt();
            max = (max < a) ? a : max;
            min = (min > a) ? a : min;
            sum += a;
        }

        System.out.printf("%d %d %d\n", min, max, sum);
    }
}



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

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    rep(i,N) cin >> h[i];
    int ans = 0;
    rep(i,N) if (h[i] >= K) ans++;
    cout << ans << endl;

    return 0;
}

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

#define COUT(x) cout << #x << " = " << (x) << ", "
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
typedef long long ll;
const int MOD = 1000000007;

int main(){
  string s1,s2,s3;
  cin >> s1 >> s2 >> s3;
  char t = s1[0];
  t -= 32;
  cout << t;
  char t2 = s2[0];
  t2 -= 32;
  cout << t2;
  char t3 = s3[0];
  t3 -= 32;
  cout << t3;
  cout << endl;
}


Measured memory_bytes: 256
<?php
list($a,$b,$C)=explode(' ',trim(fgets(STDIN)));

$C=pi()*$C/180;

$h=$b*sin($C);
$c=sqrt(pow($a-$b*cos($C),2)+pow($h,2));

echo $a*$h/2
,PHP_EOL
,$a+$b+$c
,PHP_EOL
,$h;

Measured memory_bytes: 15640
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>
using namespace std;
using ll = long long;
constexpr ll INF = 1010000000000000017LL;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

class BTaxRate {
public:
	void solve(std::istream& in, std::ostream& out) {
	    double n;
	    in>>n;
	    for(ll i = (ll)(n*(100.0/108.0))-3; i < (ll)(n*(100.0/108.0))+3; i++){
	        if((ll)(i*1.08)==n){
	            out<<i<<endl;
                return;
	        }
	    }
	    out<<":("<<endl;



	};
};


int main() {
	BTaxRate solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
from itertools import accumulate
import bisect
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ac = [0] + list(accumulate(a))
bc = [0] + list(accumulate(b))

ans = 0
for i in range(bisect.bisect(ac, k)):
    bi = bisect.bisect(bc, k - ac[i])
    ans = max(ans, i+bi-1)
print(ans)

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

using namespace std;
using ll = long long;
using ii = pair<int, int>;

const int MAX { 200010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

ll solve(int N, const vector<ll>& xs)
{
    return 0;
}

int main()
{
    ios::sync_with_stdio(false);

    int A, B;
    cin >> A >> B;

    cout << (A < 10 and B < 10 ? A * B : -1) << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
   string weather[3] = {"Sunny", "Cloudy", "Rainy"};
   string S,tomorrow;
   cin >> S;
   for(int i = 0; i < 3; i++) {
        if(S == weather[2])
            tomorrow = weather[0];
        else if(S == weather[i])
            tomorrow = weather[i+1];
   }
   cout << tomorrow;
        return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
using i64=long long;
const int N=100007;
int a[N],b[N],p[N],fa[N],vis[N];i64 f[N],sum[N];
std::vector<int>e[N];
int read(){int x;scanf("%d",&x);return x;}
int find(int x){return x==fa[x]? x:fa[x]=find(fa[x]);}
int main ()
{
    int n=read(),m=read();
    for(int i=1;i<=n;++i) a[i]=read(),b[i]=read(),a[i]=std::max(a[i]-b[i],0),p[i]=fa[i]=i;
    std::sort(p+1,p+n+1,[](int i,int j){return a[i]<a[j];});
    for(int i=1,u,v;i<=m;++i) u=read(),v=read(),e[u].push_back(v),e[v].push_back(u);
    for(int i=1;i<=n;++i)
    {
	std::vector<int>son;int u=p[i];
        vis[u]=1,sum[u]=b[u]; 
        for(int v:e[u]) if(vis[v]&&find(u)^find(v)) son.push_back(fa[v]),sum[u]+=sum[fa[v]],fa[fa[v]]=u;
        f[u]=sum[u]+a[u];
        for(int v:son) f[u]=std::min(f[u],sum[u]-sum[v]+std::max((i64)a[u],f[v])); 
    }
    printf("%lld\n",f[p[n]]);
} 


Measured memory_bytes: 9852
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    bool p = true;
    cin>>s;
    long long int n=s.size();
    for(long long int i = 0; i < n; i++)
    {
        if(i % 2 == 0)
            {
                p &= (s[i] == 'R' || s[i] == 'U' || s[i] == 'D');
            }
        else
            {
                p &= (s[i] == 'L' || s[i] == 'U' || s[i] == 'D');
            }
    }

    if(p)
        {
            cout<<"Yes";
        }
    else
        {
            cout<<"No";
        }
    return 0;
}


Measured memory_bytes: 256
import numpy as np
import bisect
n, m = map(int, input().split())

#data = [[0] * 4] * m
data = [0] * m
for i in range(m):
    #data[i][2] = i
    p, y = map(int, input().split())
    temp = [p, y, i, 0]
    data[i] = temp

# 県でSort（普通にソート
# setから、Prefの数をカウント
# prefごとに範囲を絞って、４データ目に書き込み
# ３データでソートして、入力データ並びに戻す
# print(data)
data1 = sorted(data)
dArray = np.array(data1)
pref = dArray[:, 0]

setPref = set(pref)
numPref = len(setPref)
#lis = list(setPref)

for i in setPref:
    left = bisect.bisect_left(pref, i)
    right = bisect.bisect_right(pref, i) - 1
    tar = left - right + 1
    id = 1
    for j in range(left, right + 1):
        #t = '%06d' % (i)
        pre = '%06d' % (i)
        post = '%06d' % (id)
        dArray[j, 3] = pre + post
        id += 1

ansList = dArray[dArray[:, 2, ].argsort(), :]
for i in range(m):
    ans = ansList[i, 3]
    ansS = '{:0>12}'.format(ans)
    print(ansS)


Measured memory_bytes: 51160
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if(a + b >= 10) {
			System.out.println("error");
		} else {
			System.out.println(a + b);
		}
	}

}


Measured memory_bytes: 21076
package main

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

var (
	s = bufio.NewScanner(os.Stdin)
	w = bufio.NewWriter(os.Stdout)
	n = 0
	a = []int{}
)

func main() {
	n = nextInt(s)
	a = atoi(s)
	_ = nextInt(s)
	m := atoi(s)

	for _, v := range m {
		i := 0
		if solve(i, v) {
			fmt.Fprintln(w, "yes")
			continue
		}
		fmt.Fprintln(w, "no")
	}
	w.Flush()
}

func nextInt(s *bufio.Scanner) int {
	s.Scan()
	r, err := strconv.Atoi(s.Text())
	if err != nil {
		panic(err)
	}
	return r
}

func atoi(s *bufio.Scanner) []int {
	s.Scan()
	a := strings.Fields(s.Text())
	i := []int{}

	for _, v := range a {
		j, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		i = append(i, j)
	}
	return i
}

func solve(i, m int) bool {
	if m == 0 {
		return true
	} else if i >= n {
		return false
	}
	return solve(i+1, m) || solve(i+1, m-a[i])
}



Measured memory_bytes: 1140
#include<bits/stdc++.h>
using namespace std;
long long n,m,s,ans=0,l,r,x[100010],p[100010];
int main()
{
	scanf("%lld%lld",&n,&s);
	for (int i=1;i<=n;i++) scanf("%lld%lld",&x[i],&p[i]);
	l=1;
	r=n;
	while (x[l]<=s&&s<=x[r])
	{
		ans+=x[r]-x[l];
		if (p[l]<p[r]) while (p[l]<p[r]&&x[l]<=s&&s<=x[r]) p[r]+=p[l],l++;
		else while (p[l]>=p[r]&&x[l]<=s&&s<=x[r]) p[l]+=p[r],r--;
	}
	if (x[l]>=s) ans+=x[r]-s;
	else if (x[r]<=s) ans+=s-x[l];
	printf("%lld",ans); 
	return 0;
} 

Measured memory_bytes: 1792
#include <math.h>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;

int main()
{
string W,T;
cin >> W >> T;
for(int i=0;i<W.size();i++){if(isupper(W.at(i)))W.at(i)=tolower(W.at(i));}
int ans=0;
while(T!="END_OF_TEXT")
{
for(int i=0;i<T.size();i++){if(isupper(T.at(i)))T.at(i)=tolower(T.at(i));}
if(T==W)ans++;
cin >> T;
}
cout << ans << endl;
}


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

int main() {
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  int ans = 0;
  for (int i = 0; r * i <= n; i++) {
    for (int j = 0; r * i + j * b <= n; j++) {
      int x = n - r * i - b * j;
      if (x >= 0 && (x % g) == 0) ans++;
    }
  }
  cout << ans << endl;
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,n) for(int i=1; i<=(n); i++)
#define pii pair<int,int>
#define gsort(x,n) sort((x),(x)+(n),greater<int>())
#define all(x) (x).begin(), (x).end()
#define int long long
#define abs(a) llabs(a)
#define re(s) reverse((s).begin(),(s).end())
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
const long long mod = 1000000007;

using namespace std;
long long h[1000010],x[1010][1010],z[1000010];
int a,b,c,n,cnt=0,ans=0;
signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a,b;
    cin>>a>>b;
    int cnt = 1 ,ans =0;

    while(cnt < b){
        cnt--;
        cnt += a;
        ans++;
    }
    cout<<ans<<'\n';
}

Measured memory_bytes: 256
x1, y1, x2, y2 = gets.split.map(&:to_i)

x3 = x2 - (y2 - y1)
y3 = y2 + x2 - x1
x4 = x3 - (x2 - x1)
y4 = y3 - (y2 - y1)
puts "#{x3} #{y3} #{x4} #{y4}"


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

struct node{
    struct node *right;
    struct node *left;
    struct node *parent;
    int key;
};

typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){


}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
    Node y; // node to be deleted
    Node x; // child of y



}

void insert(int k){
    Node y = NIL;
    Node x = root;
    Node z;

    z = malloc(sizeof(struct node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while(x!=NULL){
        y=x;
        if(z->key<x->key)
            x=x->left;
        else
            x=x->right;
    }

    z->parent=y;

    if(y==NULL)
        root=z;
    else if(z->key<y->key)
        y->left=z;
    else
        y->right=z;

}

void inorder(Node u){
    if(u!=NULL){
        inorder(u->left);
        printf(" %d",u->key);
        inorder(u->right);
    }

}
void preorder(Node u){
    if(u!=NULL){
        printf(" %d",u->key);
        preorder(u->left);
        preorder(u->right);
    }
}


int main(){
    int n, i, x;
    char com[20];
    scanf("%d", &n);

    for ( i = 0; i < n; i++ ){
        scanf("%s", com);
        if ( com[0] == 'f' ){
            scanf("%d", &x);
            Node t = treeSearch(root, x);
            if ( t != NIL ) printf("yes\n");
            else printf("no\n");
        }
        else if ( com[0] == 'i' ){
            scanf("%d", &x);
            insert(x);
        }
        else if ( com[0] == 'p' ){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
        else if ( com[0] == 'd' ){
            scanf("%d", &x);
            treeDelete(treeSearch(root, x));
        }
    }

    return 0;
}



Measured memory_bytes: 25272
fun main(args: Array<String>) {
    fun read() = readLine()!!
    fun readInts() = read().split(" ").map { it.toInt() }

    data class Key(val ai: Int, val ci: List<Int>)

    val (n, m) = readInts()
    val arr = Array(m) {
        val (a, b) = readInts()
        val c = readInts()
        Key(a, c)
    }

    val dp = Array(m + 1) {
        IntArray(1 shl n) { -1 }
    }

    fun makePattern(ci: List<Int>): Int {
        var retV = 0
        ci.map { it - 1 }.forEach {
            retV = retV or (1 shl it)
        }
        return retV
    }

    dp[0][0] = 0
    for (i in 1..m) {
        val (ai, ci) = arr[i - 1]
        val myPattern = makePattern(ci)
        dp[i] = dp[i - 1].clone()
        for (pattern in 0 until (1 shl n)) {
            if (dp[i - 1][pattern] == -1) continue
            if (dp[i][pattern or myPattern] == -1) {
                dp[i][pattern or myPattern] = dp[i - 1][pattern] + ai
            } else {
                dp[i][pattern or myPattern] = Math.min(dp[i - 1][pattern] + ai, dp[i][pattern or myPattern])
            }
        }
    }

    println(dp[m][(1 shl n) - 1])
}

Measured memory_bytes: 76044
#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
#define inf 1e18+9
using namespace std;
int32_t main(){
	if(fopen("input.txt", "r"))
	freopen("input.txt", "r", stdin),
	freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0),cin.tie(0);
	int a,b;
	cin >> a >> b;
	for(int i=1;i<=100000;i++){
		if((i*8/100)==a and (i/10)==b){
			cout << i ;
			return 0;
		}
	}
	cout << -1;
}

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

#define ll long long 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ar array
#define vi vector<int>
#define vll vector<ll>
#define vpl vector<pair<ll, ll>> 
#define MOD 1000000007
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()

void init() {
	
}

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	init();
	int t = 1; 
	// cin >> t;
	while(t--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 5116
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
ll power(int n, int m){
  int res = 1;
  int i = 0;
  while(i < m){
    res *= n;
    i++;
  }
  return res;
}
ll count(int b, int a){
  int cnt = 0;
  for(int i=0;i<=a;i++){
    cnt += power(10,i)*power(2,a-i-1);
  }
  cnt *= power(2,b);
  return cnt;
}
int main(){
   string S;
   cin >> S;
   int l = S.size();

   ll ans = 0;
   for(int i=0;i<l;i++){
     ans += (S[i]-'0')*count(i, l-1-i);
   }
   cout << ans <<endl;

  return 0;
}

Measured memory_bytes: 256
H,N = input().split()
H = int(H)
N = int(N)
A = list(map(int, input().split()))
A.sort()
while H > 0 :
    H = H - A[-1]
    del A[-1]
    if len(A) == 0:
        break
if H > 0 :
    print("No")
else :
    print("Yes")


Measured memory_bytes: 13964
// In the Name of Allah. Ya Ali!
#include<bits/stdc++.h>
typedef long long ll;
const ll MAX_N = 3000+5;
const ll MOD = 1e9+7;
using namespace std;

ll dp[MAX_N][MAX_N][2];
ll a[MAX_N];
int n;

int main()
{
    cin >> n;
    for(int i = 1;i<=n;++i)
        cin >> a[i];
    for(int i = 1;i<=n;++i)
        dp[1][i][0] = a[i],dp[1][i][1] = -a[i];
    for(int i = 2;i<=n;++i)
    {
        for(int j = 1;j<=n-i+1;++j)
        {
            dp[i][j][0] = max(a[j]+dp[i-1][j+1][1],a[i+j-1]+dp[i-1][j][1]);
            dp[i][j][1] = min(dp[i-1][j+1][0]-a[j],dp[i-1][j][0]-a[i+j-1]);
        }
    }
    cout << dp[n][1][0];
    return 0;
}


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

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	string r; cin >> r;
	int n; cin >> n;
	vector<string> s;
	for(int i=0;i<n;i++){
		string t; cin >> t;
		t+=t;
		s.push_back(t);
	}
	int ans=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<20-r.size()+1;j++){
			if(s[i].substr(j,r.size())==r){
				ans++;
				break;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define LL long long
using namespace std;

int main(){
  LL N, A, B;
  cin >> N >> A >> B;
  LL X[N+5];
  FOR(i, 1, N+1){
    cin >> X[i];
  }

  LL dis, ans=0;
  FOR(i, 2, N+1){
    dis = X[i] - X[i-1];
    ans += min(dis*A, B);
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        a: usize,
        b: usize,
        h: usize
    }
    println!("{}", (a + b) * h / 2);
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;
typedef long long ll;
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i,n) REP(i,0,n)

class Dice{
public:
  int t, s, e, n, w, b;

  Dice(){}
  Dice(int _t, int _s, int _e, int _n, int _w, int _b){
    t = _t;
    s = _s;
    e = _e;
    n = _n;
    w = _w;
    b = _b;
  }

  Dice moveEast(){
    return Dice(w, s, t, n, b, e);
  }

  Dice moveNorth(){
    return Dice(s, b, e, t, w, n);
  }

  Dice moveRight(){
    return Dice(t, e, n, w, s, b);
  }

  bool operator==(const Dice &d)const{
    return
      t == d.t &&
      s == d.s &&
      e == d.e &&
      n == d.n &&
      w == d.w &&
      b == d.b;
  }

  void show(){
    printf("t:%d, s:%d, e:%d, n:%d, w:%d, b:%d\n", t, s, e, n, w, b);
  }
};

vector<Dice> all;

Dice getDice(int top, int south){
  for(int i = 0; i < 24; i++){
    if(all[i].t == top && all[i].s == south){
      return all[i];
    }
  }
}

void allState(){
  all.clear();

  Dice d(1, 3, 5, 4, 2, 6);

  for(int i = 0; i < 6; i++){
    for(int j = 0; j < 4; j++){
      all.push_back(d);
      d = d.moveRight();
    }
    if(i < 4)  d = d.moveNorth();
    if(i == 3) d = d.moveEast();
    if(i == 4) d = d.moveEast().moveEast();
  }
}

int ht[300][300];
int id[300][300];

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};

bool ok[] = {false, false, false, false, true, true, true};

bool fall(int &x, int &y, Dice &d){
  Dice maxDice = d;
  int maxX = x;
  int maxY = y;

  int maxID = 0;

  for(int i = 0; i < 4; i++){
    int nx = x + dx[i];
    int ny = y + dy[i];

    if(ht[y][x] <= ht[ny][nx]) continue;
    if(i == 0 && !ok[d.n]) continue;
    if(i == 1 && !ok[d.e]) continue;
    if(i == 2 && !ok[d.s]) continue;
    if(i == 3 && !ok[d.w]) continue;

    Dice tmp;

    if(i == 0) tmp = d.moveNorth();

    if(i == 1) tmp = d.moveEast();
    if(i == 2) tmp = d.moveNorth().moveNorth().moveNorth();
    if(i == 3) tmp = d.moveEast().moveEast().moveEast();

    if(maxID < tmp.b){
      maxID = tmp.b;
      maxX = nx;
      maxY = ny;
      maxDice = tmp;
    }
  }

  if(x != maxX || y != maxY){
    x = maxX;
    y = maxY;
    d = maxDice;
    return true;
  }

  return false;
}

void solve(Dice d){
  int x = 150;
  int y = 150;

  while(true){
    bool flg = fall(x, y, d);
    if(!flg){
      break;
    }
  }

  ht[y][x]++;
  id[y][x] = d.t;
}

int main(){
  allState();

  int n;

  while(cin >> n, n){
    memset(ht, 0, sizeof(ht));
    memset(id, -1, sizeof(id));

    for(int i = 0; i < n; i++){
      int t, f;
      cin >> t >> f;
      Dice d = getDice(t, f);
      solve(d);
    }

    int cnt[7];
    memset(cnt, 0, sizeof(cnt));

    for(int i = 0; i < 300; i++){
      for(int j = 0; j < 300; j++){
        if(id[i][j] != -1){
          cnt[id[i][j] - 1]++;
        }
      }
    }

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

  return 0;
}

Measured memory_bytes: 0
#include <iostream>
    #include <string.h>
    #include <vector>
    #include <deque>
    #include <bitset>
    #include <string>
    #include <limits.h>
    #include <stdint.h>
    #include <algorithm>
    #include <tuple>
    #include <iomanip>
    #include <set>
    #include <assert.h>
    using namespace std;
     
    struct SS
    {
    	vector<int> link;
    	int score;
    };
    SS S[100001];
     
    void find_score(int i)
    {
    	for (int j : S[i].link) {
    		if (S[j].score == -1) {
    			S[j].score = S[i].score + 1;
    			find_score(j);
    		}
    	}
    }
     
    int64_t find_links(int i, int parent)
    {
    	int64_t sum = 1;
    	for (int j : S[i].link) {
    		if (j != parent) {
    			sum += find_links(j, i);
    		}
    	}
    	return sum;
    }
    int main(int argc, char* argv[])
    {
    	if (argc >= 2) {
    		FILE* fp = freopen(argv[1], "r", stdin);
    	}
     
    	int N;
    	cin >> N;
    	for (int i = 1; i <= N; i++) {
    		S[i].score = -1;
    	}
    	for (int i = 0; i < N - 1; i++) {
    		int a, b;
    		cin >> a >> b;
    		S[a].link.push_back(b);
    		S[b].link.push_back(a);
    	}
    	S[1].score = 0;
    	find_score(1);
    	vector<int> root;
    	root.push_back(N);
    	for (int i = N; i != 1;) {
    		for (int j : S[i].link) {
    			if (S[j].score == S[i].score - 1) {
    				root.push_back(j);
    				i = j;
    				break;
    			}
    		}
    	}
    	int64_t f = 0, s = 0;
    	int i = 0;
    	for (i; i < root.size() / 2; i++) {
    		int j = root[i];
    		s++;
    		for (int k : S[j].link) {
    			if (i != 0 && k == root[i - 1]) continue;
    			if (i != root.size() - 1 && k == root[i + 1]) continue;
    			s += find_links(k, j);
    		}
    	}
    	for (; i < root.size(); i++) {
    		int j = root[i];
    		f++;
    		for (int k : S[j].link) {
    			if (i != 0 && k == root[i - 1]) continue;
    			if (i != root.size() - 1 && k == root[i + 1]) continue;
    			f += find_links(k, j);
    		}
    	}
    	if (f > s) {
    		cout << "Fennec";
    	} else {
    		cout << "Snuke";
    	}
    	
    	return 0;
    }

Measured memory_bytes: 10236
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
    

    ll n,m;
    cin >> n >> m;
    vector <ll> lis;
    for (ll i=0;i<m;i++){
        ll p;
        cin >> p;
        lis.push_back(p);
    }
    sort(lis.begin(), lis.end());
    ll ans = lis[m-1] - lis[0];
    vector <ll> sub;
    for (ll i=1;i<m;i++){
        sub.push_back(lis[i] - lis[i-1]);
    }
    sort(sub.begin(), sub.end());
    reverse(sub.begin(), sub.end());
    if(n < m) {
        for (ll i = 0; i < n - 1; i++) {
            ans -= sub[i];
        }
    }else{
        ans = 0;
    }
    cout << ans << endl;


}


Measured memory_bytes: 2548
#include<stdio.h>
 
 int main(){
  int n, a; 
  int y=0;
  int l, m, k;
  scanf("%d", &n);
  int data[n];
  char c[12];
  int i;
 for(i=0;i<n;i++){
    scanf("%s %d",c,&a);
    if(c[0]=='i'){
    data[i]=a;
    }
 else if(c[6]=='F'){
    i-=2;
    n-=2;
    }
 else if(c[6]=='L'){
    i--;
    n--;
    y++;
  }
 else{
    i--;
    n--;
    l=0;
    int j;
    for(j=i;j>=0;j--){
    if(l>0) break;
    if(a==data[j]){
      k=0;
      m=i-j;
      l++;
      while(m!=k++)
    data[j+k-1]=data[j+1+k-1];
      i--;
      n--;
        }  
      }
    }
  }
  for(i=0;i<n-y;i++){
    if(i==n-y-1)
      printf("%d\n",data[n-1-i]);
    else
      printf("%d ",data[n-1-i]);
  }
  return 0;
}

Measured memory_bytes: 6496
#include<iostream>
#include<map>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	cin >> n;
	map<string, int> p;
	string color;
	int value;

	while (n--)
	{
		int type;
		cin >> type;
		
		switch (type)
		{
		case 0:
			cin >> color >> value;
			p[color] = value;
			break;
		case 1:
			cin >> color;
			if (p.count(color) != 0)cout << p[color] << endl;
			else cout << 0 << endl;
			break;
		case 2:
			cin >> color;
			map<string, int>::iterator temp = p.find(color);
			if(temp!=p.end())p.erase(temp);
			break;
		}
	}
}


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

int max_(int a, int b){
	if(a > b) return a;
	return b;
}

int main(){
	string s, t; cin>>s>>t;
	int n = s.size(), m = t.size(), i, j;
	int dp[n+1][m+1];
	for(int i = 0; i <= n; i++) dp[i][0] = 0;
	for(int j = 0; j <= m; j++) dp[0][j] = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(s[i-1] == t[j-1]) dp[i][j] = dp[i-1][j-1] + 1;
			else dp[i][j] = max_(dp[i-1][j-1], max_(dp[i-1][j], dp[i][j-1]));
		}
	}
	string r = "";
	i = n; j = m;
	while(i > 0 && j > 0){
		if(s[i-1] == t[j-1]){
			r = s[i-1] + r;
			i--; j--;
		}
		else{
			if(dp[i][j] == dp[i-1][j]) i--;
			else if(dp[i][j] == dp[i][j-1]) j--;
			else{
				i--; j--;
			}
		}
	}
	cout<<r<<endl;
}

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

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int maxA = 0;
  int pointB = 0;
  rep(i, N) {
    int a, b;
    cin >> a >> b;
    if (maxA < a) {
      maxA = a;
      pointB = b;
    }
  }
  cout << maxA + pointB << endl;
  return 0;
}

Measured memory_bytes: 3664