akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstring>
#include<cstdio>
using namespace std;
void File(){
	freopen("D.in","r",stdin);
	freopen("D.out","w",stdout);
}
#define REP(i,a,b) for(register int i=a;i<=b;++i)
#define DREP(i,a,b) for(register int i=a;i>=b;--i)
const int maxn=200+10;
int n,m,a[maxn][maxn],cnt0,cnt1;
int main(){
	//File();
	scanf("%d%d",&n,&m);
	REP(i,1,50)REP(j,1,100)a[i][j]=1;
	REP(i,51,100)REP(j,1,100)a[i][j]=0;
	cout<<100<<" "<<100<<endl;
	n--,m--;
	int x,y;
	x=1,y=1;
	while(n){
		a[x][y]=0;
		if(y+2<=100) y+=2;
		else x+=2,y=1;
		n--;
	}
	x=52,y=1;
	while(m){
		a[x][y]=1;
		if(y+2<=100) y+=2;
		else x+=2,y=1;
		m--;
	}
	REP(i,1,100){
		REP(j,1,100)
		if(a[i][j]==1)cout<<"#";
		else cout<<".";
		cout<<endl;
	}
	return 0;
}



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

int main() {
    int n;
    cin >> n;
    vector<pair<long double, long double>> c(n);
    long double sum = 0.0;
    long double p = 1.0;
    for (int i = 0; i < n; i++) {
        cin >> c.at(i).first >> c.at(i).second;
        p *= (i+1);
    }
    sort(c.begin(), c.end());
    do {
        for (int i = 1; i < n; i++) {
            sum += sqrt(pow((c.at(i-1).first-c.at(i).first), 2.0) + pow((c.at(i-1).second-c.at(i).second), 2.0));
        }
    } while (next_permutation(c.begin(), c.end()));

    cout << fixed << setprecision(15) << sum / p << endl;
    return 0;
}

Measured memory_bytes: 3844
#include <iostream>
#include<cstdio>
#include<string>
using namespace std;
int main(void){
    while(true){
        string s;
        int m;
        cin>>s;
        if(s=="-")break;
        cin>>m;
        for(int i=0; i<m; i++){
            int a;
            cin>>a;
            string add=s.substr(0,a);
            s=s+add;
            s=s.substr(a,s.size());
        }
        cout<<s<<endl;
    }
    return 0;
}
        
 


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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

#ifdef DEBUG
#define DBG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)
#else
#define DBG(fmt, ...)
#endif

struct point{
    point(){};
    point(int _x,int _y):x(_x),y(_y){};
    int x;
    int y;
};


int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll S;
    cin >> S;

    ll table[2000] = {0};
    table[0]=1;

    for(int i = 3; i <= S; i++ ){
        ll sum = 0;
        for(int j = 0; j <= i-3; j++){
            sum += (table[j]);
            sum %= MOD;
        }
        table[i] = sum;
    }
    cout << table[S] << endl;
}


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

using Graph = std::vector<std::vector<int>>;

void dfs(std::vector<bool> &seen, Graph &g, int v, int &time, std::vector<int> &preOrder, std::vector<int> &postOrder){
    preOrder.at(v) = time;
    ++time;

    seen.at(v) = true;
    for(auto nextV : g.at(v)){
        if(seen.at(nextV)){
            continue;
        }
        dfs(seen, g, nextV, time, preOrder, postOrder);
    }

    postOrder.at(v) = time;
    ++time;
}

int main(){
    int n;
    std::cin >> n;

    Graph g(n);
    std::vector<int> preOrder(n), postOrder(n);
    for(int i = 0; i < n; ++i){
        int m, l;
        std::cin >> m >> l;
        for(int j = 0; j < l; ++j){
            int k;
            std::cin >> k;

            g.at(i).push_back(k - 1); 
//            g.at(k - 1).push_back(i); // for undirected graphs
        }
    }

    std::vector<bool> seen(n, false);
    int time = 1;
    for(int i = 0; i < n; ++i){
        if(seen.at(i)){
            continue;
        }

        dfs(seen, g, i, time, preOrder, postOrder);
    }

    for(int i= 0; i < n; ++i){
        std::cout << i + 1 << " " << preOrder.at(i) << " " << postOrder.at(i) << std::endl;
    }

    return 0;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
int main(){
    int n;
    cin>>n;
    for(int i=0;i<=25;i++){
        for(int j=0;j<=14;j++){
            if(4*i+7*j==n){
                cout<<"Yes"<<endl;
                //cout<<"cake:"<<i<<"dounut:"<<j<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
}

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

typedef long long ll;

using namespace std;


ll GCD(ll a, ll b) {
	if (a < b) {
		ll tmp = a;
		a = b;
		b = tmp;
	}
	ll r = a % b;
	while (r != 0ll) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

vector<ll> divisor(ll n) {
	vector<ll> ret;
	for (ll i = 1ll; i * i <= n; i++) {
		if (n % i == 0ll) {
			ret.push_back(i);
			if (i * i != n) { ret.push_back(n / i); }
		}
	}
	sort(begin(ret), end(ret));
	return (ret);
}
bool is_prime(const ll n) {
	switch (n) {
	case 0ll: // fall-through
	case 1ll: return false;
	case 2ll: // fall-through
	case 3ll: return true;
	}

	if (n % 2ll == 0ll) { return false; }
	if (n % 3ll == 0ll) { return false; }

	if (n % 6ll != 1ll && n % 6ll != 5ll){return false;}
	for (ll i = 5ll; i * i <= n; i += 6) {
		if (n % i == 0) { return false; }
		if (n % (i + 2ll) == 0ll) {return false;}
	}

	return true;
}

//1000000000000 1000000000000

int main() {

	ll A, B;

	scanf("%lld %lld",&A,&B);

	ll gcd = GCD(A, B);

	vector<ll>num = divisor(gcd);

	ll ans = 1ll;
	for (int i = 0; i < num.size(); i++) {
		if (is_prime(num[i])) { ans++; }
	}

	printf("%lld\n",ans);

	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

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

        int n= in.nextInt();
        int k=in.nextInt();
        double res=0;
        for(int i=1;i<=n;i++){
            double temp = 1.0/n;
            int now =i;
            while(now<k){
                now=now*2;
                temp=temp/2;
            }
            res+=temp;
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 22228
# using this function takes too long time!
def step():

    for i in range(4,-1,-1):
        if state[i] <= capacities[i]:
            state[i+1] += state[i]
            state[i] = 0
        
        else:
            state[i+1] += capacities[i]
            state[i] -= capacities[i]


N = int(input())
capacities = [int(input()) for _ in range(5)]
# state = [N,0,0,0,0,0]

# t = 0
# while True:
#     t += 1
#     step()

#     if state[-1] == N:
#         break


t = (N-1) // min(capacities) + 1 + 4

print(t)



Measured memory_bytes: 3060
#include <bits/stdc++.h>
const int MAX = 2e3 + 10;
typedef long long i64;
using namespace std;
const double EPS = 1e-6;
const int MOD = 1e9 + 7;
#define mul(a, b) ((i64)(a) * b % MOD)


int minm(int low, int high, int target0, int target1){
	int a1 = -low + high - low + abs(target0 - high);
	int a2 = high + high - low + abs(target0 - low);
	int a3 = -low + high - low + abs(target1 - high);
	int a4 = high + high - low + abs(target1 - low);
	return min(min(a1, a2), min(a3, a4));
}
int main() {

    #ifdef LOCAL_DEBUG
    freopen ("data.in", "r", stdin );
    //freopen ("data.out", "w", stdout );
    #endif
    ios_base::sync_with_stdio(0); cin.tie(0);
    #define endl '\n'
    string a, b;
    cin >> a >>b ;
    bool poss = false;
    int n =(int) a.size();
    int beg = -1;
    for(int i = 0 ;i < n; i++)
    	if(b[i]!= '0'){
    		beg = i;
    		poss = true; break;

    	}
    if(!poss){
    	for(int i = 0 ;i < n; i++)
			if(a[i]!= '0'){
				poss = true; break;

			}
    	if(!poss){
    		cout << 0 << endl;
    		return 0;
    	}
    	cout << -1 << endl;
    	return 0;
    }

    vector<int> le(n);
    vector<int>re(n);
    for(int i = beg; i <beg + n; i++){
    	if(b[i % n] == '0'){
    		int j = i;
    		while(b[ j % n] == '0')j++;
    		for(int t = i; t < j; t++){
    			if(a[t % n] == '1'){
    				le[t % n] = t - i + 1;
    				re[t % n] = j - t;
    			}
    		}
    		i = j;
    	}
    }
    int ans = 2 * n;
    for(int i = 0; i < n; i++){
    	string c = a.substr(i) + a.substr(0, i);
    	vector<pair<int, int>> ss;
    	int cur = 0;
    	for(int j = 0; j < n; j++)
    		if(c[j] != b[j]){
    			cur += 1;
    			if(c[j] == '1'){
    				int o = (j + i) % n;
    				if(le[o] != 0)
    					ss.push_back({-le[o], re[o]});
    			}
    		}
    	if(ss.size() == 0){
    		ans = min(ans, cur + min(i, n - i));
    		continue;
    	}
    	ss.push_back({0, 0});
    	vector<int> mx(ss.size());
    	sort(ss.begin(), ss.end());

    	mx[0] = ss[0].second;
    	int mn = minm(ss[0].first, 0, n - i, -i);
    	for(int j = 1; j < (int)ss.size(); j++){
    		mx[j] = max(mx[j - 1], ss[j].second);
    		mn = min(mn, minm(ss[j].first, mx[j - 1], n - i, -i));
    	}
    	ans = min(ans, cur + mn);

    }
    cout << ans << endl;



}



Measured memory_bytes: 384
n = gets.to_i
as = gets.split.map(&:to_i)
max = as.max
as.delete(max)
if max%2 == 0 
  min = as.map{|a| (a-max/2).abs}.min 
  res = as.select{|a| (a-max/2).abs <= min}[0]
else
  min = as.map{|a| (a-max/2).abs < (a-(max+1)/2).abs ? (a-max/2).abs : (a-(max+1)/2).abs}.min 
  res = as.select{|a| (a-max/2).abs <= min || (a-(max+1)/2).abs <= min}[0]
end
puts max.to_s+" "+res.to_s


Measured memory_bytes: 9228
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef pair<int, int> p;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n; cin >> n;
    int ans = 0;
    REP(i, n)
    {
        int l, r;
        cin >> l >> r;
        ans += r - l + 1;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
//最大の下げ幅を見つける、それがいくつかを調べる。
//それだけコスト
//7 10 4 5 9 3 6 8 2 1
// 4-9
// 3-8
//おしりから見てくのがいいかな
//売値だけ
//10 10 9 9 9 8 8 8 2 1
//買値は？
//7  7  4 4 4 3 3 3 2 1
//あいことなる。

int main(){
  ll N,T; cin>>N>>T;
  vector<ll> A(N,0), sale(N,0), buy(N,0);
  for(int i=0; i<N; i++){
    ll a; cin>>a; A[i]=a;
  }
  ll tmp=0;
  for(int i=N-1; i>=0; i--) sale[i]=(tmp=max(tmp,A[i]));
  tmp=1e10;
  for(int i=0; i<N; i++) buy[i]=(tmp=min(tmp,A[i]));
  tmp=0;
  for(int i=0; i<N; i++) tmp=max(tmp,sale[i]-buy[i]);
  ll ans=0,s=0,b=0;
  for(int i=0; i<N; i++){
    if(sale[i]-buy[i]==tmp){
      if(s!=sale[i] || b!=buy[i]){
        ans++;
        s=sale[i];
        b=buy[i];
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int Judge(vector<pp> & d) {
	int i, n = 0;
	rep(i, d.size()) {
		if (n + d[i].first < 0)
			return -1;
		n += d[i].second;
	}
	return n;
}

int main(void) {
	int num, i, j;
	string s;
	cin >> num;
	vector<pp> a, b;
	rep(i, num) {
		pp n = { 0,0 };
		cin >> s;
		rep(j, s.size()) {
			if (s[j] == '(')
				n.second++;
			else
				n.second--;
			chmin(n.first, n.second);
		}
		if (n.second >= 0)
			a.push_back(n);
		else
			b.push_back({ n.first - n.second, -n.second });
	}
	sort(a.begin(), a.end(), greater<pp>());
	sort(b.begin(), b.end(), greater<pp>());
	i = Judge(a);
	j = Judge(b);
	if (i == j && i >= 0)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 11272
import java.util.Scanner;

public class Main {

/* (a)
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner (System .in);
        Integer a = scan.nextInt();
        Integer b = scan.nextInt();

        if(a <= 9 && b <= 9){
            System.out.println(a*b);
        }
        else {
            System.out.println(-1);
        }
        scan.close();
    }
*/
/* (b)
public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner (System .in);
        Integer num = scan.nextInt();
        String msg= "No";
    
        if(num > 81){
            System.out.println("No");
        }
        else if (1<=num && num<=9){
            System.out.println("Yes");            
        }
        else{
            for(int i=2;i<=9;i++){
                int d = num % i;
                int e = num / i;
                if(d==0 && 1<=e && e<=9){
                    msg ="Yes";
                    break;                    
                }
            }
            System.out.println(msg);
        }
        scan.close();
    }
*/
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner (System .in);
        long num = scan.nextLong();
        long steps = 0; 
        long preStep = (long)Math.pow(10,12);
        long j,d;

        boolean isPrime = isPrime(num);
        if (isPrime){
            steps = num - 1;
            System.out.println(steps);
        }
        else {
            for(long i=(long)Math.sqrt(num);i>=2;i--){
                d = num % i;
                if (d == 0){
                    j = num /i;
                    steps = Math.min(i+j-2,preStep);
                    preStep = steps;
                }
            }
            System.out.println(steps);            
        }

        scan.close();
    }

    public static boolean isPrime(long num) {
        if ( 1 >= num ) return false;
            
        // 2の場合は素数
        if ( 2 == num ) return true;
            // 素数判定
        int n = (int)Math.sqrt( num );
        for ( int i = 2; i <= n; ++ i ) {
        	// 余り0で割り切れるかを判定
        	if ( 0 == ( num % i ) ) return false;
        }
            // numが2～nで割り切れなかったので素数
        return true;
    }

}

Measured memory_bytes: 25172
import sys

sys.setrecursionlimit(int(1e7))

n = int(input())

tree = {}

for i in range(n - 1):
    s, t, w = map(int, input().split())
    if s not in tree:
        tree[s] = {}
    if t not in tree:
        tree[t] = {}
    tree[s][t] = tree[t][s] = w

max_cost = 0
max_id = 0


def visit(v: int, p: int, costs: list):
    global max_cost, max_id
    if v not in tree:
        return
    for t, w in tree[v].items():
        if t == p:
            continue
        costs[t] = costs[v] + w
        if costs[t] >= max_cost:
            max_cost = costs[t]
            max_id = t
        visit(t, v, costs)


costs0 = [0] * n
costs1 = [0] * n
costs2 = [0] * n

visit(0, -1, costs0)
visit(max_id, -1, costs1)
visit(max_id, -1, costs2)

for i in range(n):
    print(max(costs1[i], costs2[i]))



Measured memory_bytes: 21632
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
int main(){
  queue<int> q;
  int n,a,k,u,c[101];
  vector<int>  d[101];
  cin>>n;for(int i=0;i<n;i++){
    cin>>u>>k;c[i+1]=-1;
    d[u].resize(k);
    for(int j=0;j<k;j++) cin>>d[u][j];
  }q.push(1),c[1]=0;
  while(!q.empty()){
   a=q.front(),q.pop();
    for(int i=0;i<d[a].size();i++)
      if( d[a][i]>1 && c[d[a][i]]==-1) q.push(d[a][i]),c[d[a][i]]=c[a]+1;
  } for(int i=1;i<=n;i++) cout<<i<<" "<<c[i]<<endl;
  return 0;
}

Measured memory_bytes: 1200
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int[] h=new int[100000];
        int[] w=new int[100000];
        int l=0;
        while(true){
            h[l]=scan.nextInt();
            w[l]=scan.nextInt();
            if(h[l]==0&&w[l]==0) break;
            l++;
        }
        l=0;
        while(true){
            if(h[l]==0&&w[l]==0) break;
            for(int i=0;i<h[l];i++){
                for(int j=0;j<w[l];j++){
                    if(i==0||i==h[l]-1){
                        System.out.printf("#");
                    }
                    else{
                        if(j==0||j==w[l]-1){
                            System.out.printf("#");
                        }
                        else System.out.printf(".");
                    }
                }
                System.out.println();
            }
            System.out.println();
            l++;
        }
    }
}


Measured memory_bytes: 57600
a = [int(input()) for _ in range(5)]
b = [i%10 for i in a]

min_value = b[0]
for i in range(len(a)):
    if min_value == 0 and b[i] != 0:
        min_value == b[i]

    if b[i] != 0 and b[i] < min_value:
        min_value = b[i]

cnt = 0
flag = 0
for i in range(len(a)):
    if b[i] == min_value and flag == 0:
        flag = 1
        cnt += a[i]
    else:
        if b[i] != 0:
            cnt += (a[i] + 10 - b[i])
        else:
            cnt += a[i]

print(cnt)


Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Scanner;
import static java.lang.Math.*;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int start = N <= K ? N*X : K*X;
		int over = max(0, Y*(N-K));
		System.out.println(start+over);
		
		sc.close();
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 21844
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

int main() {
	string S; cin >> S;

	for (int s = S.length() - 2; s >= 0; s -= 2) {
		int mid = s / 2;
		int cnt = 0;
		for (int i = 0; i <= mid - 1; i++) {
			if (S[i] == S[i + mid])cnt++;
		}

		if (cnt == mid) {
			cout << s << endl;
			return 0;
		}
	}
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int num[252521];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	int n, k, a[252521];
	cin>>n>>k;
	REP(i, n){
		cin>>a[i];
		++num[a[i]];
	}
	sort(num, num+n+1);
	int ans=0, cnt=0;
	FORR(i, 0, n+1){
		++cnt;
		if(cnt>k){
			ans+=num[i];
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 1792
use std::io::*;
use std::str::*;

fn read<T: FromStr>(s: &mut StdinLock) -> Option<T> {
    let s = s
        .by_ref()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok()
}

fn main() {
    let stdin = stdin();
    let n = read::<i32>(&mut stdin.lock()).unwrap();
    let x = read::<i32>(&mut stdin.lock()).unwrap();
    let mut di = 0;

    for i in 1..n + 1 {
        let l = read::<i32>(&mut stdin.lock()).unwrap();
        di += l;

        if x < di {
            println!("{}", i);
            break;
        } else if i == n {
            println!("{}", i + 1);
        }
    }

    /*
     *  di = di-1 + li-1
     */
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int N,M;
    cin >> N >> M;
    vector<pair<pair<int,int> ,int> > vec(M);
    rep(i,M){
        cin >> vec[i].first.first;
        cin >> vec[i].first.second;
    }
    rep(i,M){
        vec[i].second = i + 1;
    }
    sort(all(vec));
    vector<pair<int,int> > copy(M);
    rep(i,M){
        copy[i].first = vec[i].second;
        copy[i].second = vec[i].first.first;
    }
    vector<pair<int,int> > count(M);
    rep(i,M){
        count[i].first = vec[i].second;
    }
    int left = 0;
    int right = 0;
    while (right < M) {
        if (right == M - 1){
            if (vec[right].first.first != vec[left].first.first){
                count[right].second = 1;
                right++;
            }
            else{
                count[right].second = right - left + 1;
                right++;
            }
        }
        else{
            if (vec[right].first.first == vec[left].first.first){
                count[right].second = right - left + 1;
                right++;
            }
            else{
                count[right].second = 1;
                left = right;
                right++;
            }
        }
    }
    sort(all(copy));
    sort(all(count));
    rep(i,M){
        int len_c = to_string(copy[i].second).size();
        rep(j,6 - len_c){
            cout << 0;
        }
        cout << copy[i].second;
        int len_count = to_string(count[i].second).size();
        rep(j,6 - len_count){
            cout << 0;
        }
        cout << count[i].second;
        cout << endl;
    }
}


Measured memory_bytes: 4224
n=int(input())
A=list(map(int,input().split()))	

fumidai=0

for i in range(1,n):
  if A[i-1]>A[i]:
    fumidai+=A[i-1]-A[i]
    A[i]=A[i-1]
  else:
    fumidai+=0

print(fumidai)

Measured memory_bytes: 105168
#include <iostream> 
#include <cstdio> 
#include <cstdlib> 
#include <cstring> 
#include <cmath> 
#include <algorithm> 
using namespace std; 
inline int gi() {
    register int data = 0, w = 1;
    register char ch = 0;
    while (!isdigit(ch) && ch != '-') ch = getchar(); 
    if (ch == '-') w = -1, ch = getchar(); 
    while (isdigit(ch)) data = 10 * data + ch - '0', ch = getchar(); 
    return w * data; 
} 
const int Mod = 924844033, G = 5; 
int fpow(int x, int y) { 
	int res = 1; 
	while (y) { 
		if (y & 1) res = 1ll * res * x % Mod; 
		x = 1ll * x * x % Mod; 
		y >>= 1; 
	} 
	return res; 
} 
const int iG = fpow(G, Mod - 2); 
const int MAX_N = 2e5 + 5; 
int Limit, rev[MAX_N << 2]; 
void FFT_prepare(int len) { 
	int p = 0; 
	for (Limit = 1; Limit <= len; Limit <<= 1) ++p; 
	for (int i = 1; i < Limit; i++) rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (p - 1)); 
} 
void NTT(int *p, int op) { 
	for (int i = 1; i < Limit; i++) if (i < rev[i]) swap(p[i], p[rev[i]]); 
	for (int i = 1; i < Limit; i <<= 1) { 
		int rot = fpow(op == 1 ? G : iG, (Mod - 1) / (i << 1)); 
		for (int j = 0; j < Limit; j += i << 1) 
			for (int k = 0, w = 1; k < i; k++, w = 1ll * w * rot % Mod) { 
				int x = p[j + k], y = 1ll * w * p[i + j + k] % Mod; 
				p[j + k] = (x + y) % Mod, p[i + j + k] = (x - y + Mod) % Mod; 
			} 
	} 
	if (!op) { 
		int inv = fpow(Limit, Mod - 2); 
		for (int i = 0; i < Limit; i++) p[i] = 1ll * p[i] * inv % Mod; 
	} 
} 
struct Graph { int to, next; } e[MAX_N << 1]; 
int fir[MAX_N], e_cnt; 
void clearGraph() { memset(fir, -1, sizeof(fir)); e_cnt = 0; } 
void Add_Edge(int u, int v) { e[e_cnt] = (Graph){v, fir[u]}, fir[u] = e_cnt++; } 
int N, f[MAX_N << 2], g[MAX_N << 2], h[MAX_N << 2];
int siz[MAX_N], cnt[MAX_N]; 
void dfs(int x, int fa) { 
	siz[x] = 1; 
	for (int i = fir[x]; ~i; i = e[i].next) {
		int v = e[i].to; if (v == fa) continue; 
		dfs(v, x), siz[x] += siz[v]; 
		cnt[siz[v]]++; 
	} 
	cnt[N - siz[x]]++; 
} 
int fac[MAX_N], ifc[MAX_N]; 
int C(int n, int m) { 
	if (n < 0 || m < 0 || n < m) return 0; 
	else return 1ll * fac[n] * ifc[n - m] % Mod * ifc[m] % Mod; 
} 
int main () { 
	clearGraph(); 
	N = gi(); 
	for (int i = 1; i < N; i++) { 
		int u = gi(), v = gi(); 
		Add_Edge(u, v), Add_Edge(v, u); 
	} 
	fac[0] = 1; for (int i = 1; i <= N; i++) fac[i] = 1ll * fac[i - 1] * i % Mod; 
	ifc[N] = fpow(fac[N], Mod - 2); 
	for (int i = N - 1; ~i; i--) ifc[i] = 1ll * ifc[i + 1] * (i + 1) % Mod;
	dfs(1, 0); 
	for (int i = 1; i <= N; i++) g[i] = 1ll * cnt[i] * fac[i] % Mod; 
	for (int i = 0; i <= N; i++) h[i] = ifc[i]; 
	reverse(&g[0], &g[N + 1]); 
	FFT_prepare(N << 1); 
	NTT(g, 1), NTT(h, 1); 
	for (int i = 0; i < Limit; i++) f[i] = 1ll * g[i] * h[i] % Mod; 
	NTT(f, 0); 
	for (int i = 1; i <= N; i++) { 
		int ans = 1ll * N * C(N, i) % Mod; 
		ans = (ans - 1ll * ifc[i] * f[N - i] % Mod + Mod) % Mod; 
		printf("%d\n", ans); 
	} 
    return 0; 
} 

Measured memory_bytes: 28672
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner _____ = new Scanner(System.in);
        int _________ = _____.nextInt();
        int ___________ = _____.nextInt();
        ArrayList<Integer> __________ = new ArrayList<Integer>();
        for (int ________ = 0; ________ < _________; ________++) {
            __________.add(________);
        }
        for (int ________ = 0; ________ < ___________; ________++) {
            String[] ______ = _____.next().split(",");
            int __ = Integer.parseInt(______[0]) - 1;
            int ___ = Integer.parseInt(______[1]) - 1;
            int ___________________________ = __________.get(__);
            __________.set(__, __________.get(___));
            __________.set(___, ___________________________);
        }
        for (int ________ = 0; ________ < __________.size(); ________++) {
            System.out.println(__________.get(________) + 1);
        }
        _____.close();
    }
}



Measured memory_bytes: 26188
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <set>
#include <unordered_set>
#include <vector>
#include<valarray>
#include<map>
#include <utility>
#include <deque>
#include <queue>
using namespace std;

int main()
{
    long long N;
    cin>>N;
    string s;
    char arr[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
    int count=0;
    while(true){

        if(N<26){


            break;
        }
        else{
            if(N%26!=0){
                N--;
                count++;
            }
            else if(N%26==0&&count==0)
            {
                s+='z';
                N-=1;
               N/=26;

            }
            else{
                s+=arr[count-1];
                N=N/26;
                count=0;
            }
        }
    }
    if(N==26)
        s+='a';
    else if(N>=1&&N<26) {



        s += arr[N-1];
    }
reverse(s.begin(),s.end());
cout<<s;

    return 0;
}

Measured memory_bytes: 3056
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <cctype>
#include <vector>
#include <tuple>
#include <random>
#include <utility>
#include <map>
#include <iterator>
#include <numeric>
#include <complex>
using namespace std;
 
// マクロ・マクロ関数リスト
#define loop while(1)
#define Init = 0
#define T true
#define F false;
#define rep(a, b) for(lli a = 0; a < b; a++)
#define debug cout << "Debug Massage :: "
#define ari(n) n * (n + 1) / 2
#define MOD 100000007
 
// typedefリスト
typedef pair<int, int> Type;
typedef long long ll;
typedef long long int lli;
 
// データリスト


int main() {
	string s;
	cin >> s;
	long cntb = 0, cntw = 0;
	long ansb = 0, answ = 0;
	for(int n = s.size() - 1; n >= 0; n--){
		if(s[n] == 'W'){
			cntw++;
		}
		if(s[n] == 'B'){
			ansb += cntw;
		}
	}
	for(int n = 0; n < s.size(); n++){
		if(s[n] == 'B'){
			cntb++;
		}
		if(s[n] == 'W'){
			answ += cntb;
		}
	}
	cout << max(ansb, answ) << endl;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(){
	int A,B;
	cin >> A >> B;
	if(A%3==0 || B%3==0 || (A+B)%3==0){
		cout <<"Possible";
	}else{
		cout << "Impossible";
	}
	cout << endl;
	return 0;
}


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

int main (int argc, char const* argv[])
{
	deque <int> Q;
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		int c;
		scanf("%d", &c);
		if((i & 1) != (n & 1)) Q.push_back(c);
		else Q.push_front(c);
	}
	while(!Q.empty()) {
		printf("%d ", Q.front());
		Q.pop_front();
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
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 (a>b) { a = b; return 1; } return 0; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;


int main(){
    ll N, K;
    cin >> N >> K;
    map<ll, ll> M;
    REP(i, K) {
        ll d;
        cin >> d;
        REP(D, d) {
            ll a;
            cin >> a;
            M[a] = 1;
        }
    }
    ll c = 0;
    REP(i, N) {
        if (M.count(i+1)==0) c++;
    }
    cout << c << "\n";
}


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

using namespace std;

int main(){

  int n=0, x=0, cnt=0;
  int y=0;
  cin >> n >> x;
  vector<int> d(n);

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

  for(int j=0; j<=n; ++j){
    if( x >= d[j] ){
      ++cnt;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll  long long int
#define ff first
#define pb push_back
#define ss second
#define debug 0
#define ff first
#define mp make_pair
 
using namespace std;
 
const ll MOD = 1000000007LL;
 
ll fact[1000006];
ll ifact[1000006];
ll power2[1000006];
 
ll ar[100056];
ll br[100056];
ll cr[100056];
vector<int> adj[100005];
set<ll> st;
 
int vis[100005];
 
 
bool prime[10000006];
 
vector<int> primes;
 
 
 
ll powr (ll a, ll  b)
{
    if (b == 0)
        return 1;
    long long int x = powr(a, b/2);
    if (b % 2 == 0)
        return (x*x)%MOD;
    else
        return ((x*x)%MOD*a%MOD)%MOD;
}
 
inline ll inv(ll x) {
  return powr(x, MOD - 2);
}
 
inline ll mulMod(ll a, ll b) {
  return (a%MOD * b%MOD) % MOD;
 
}
 
inline void process() {
  fact[0] = 1;
  power2[0] = 1;
  for(int i = 1; i < 1003; i++) {
    fact[i] = mulMod(fact[i - 1], i);
    power2[i] = mulMod(power2[i - 1], 2);
  }
  ifact[1002] = inv(fact[1002]);
  for(int i = 1002 - 1; i >= 0; i--) {
    ifact[i] = mulMod(ifact[i + 1], i + 1);
  }
}
 
inline ll ncr(ll n, ll r) {
  if(n < r) return 0;
  return mulMod(fact[n], mulMod(ifact[r], ifact[(n - r)]));
}
 
ll solve(ll n, ll k)
{
    ll C[k+1];
    memset(C, 0, sizeof(C));
 
    C[0] = 1; 
 
    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, k); j > 0; j--)
            C[j] = C[j] + C[j-1];
    }
    return C[k];
}
 
void solve1(vector<ll> price, ll n, ll S[])
{
   
   stack<ll> st;
   st.push(0);
 
   S[0] = 1;
 
   for (ll i = 1; i < n; i++)
   {
 
      while (!st.empty() && price[st.top()] <= price[i])
         st.pop();
 
 
      S[i] = (st.empty())? (i + 1) : (i - st.top());
 
      st.push(i);
   }
}
 
void sieve()
{
    memset(prime,true,sizeof(prime));
    prime[0]=prime[1]=false;
    
    for(ll i=2;i*i<=100006;i++)
    {
        if(prime[i])
        {
            for(ll j=i*2;j<=100006;j+=i)
            {
                prime[j]=false;
            }
        }
    }
    
    for(int i=2;i<=100005;i++)
    {
    	if(prime[i])
    	primes.pb(i);
	}
}
 
map<int,int> has[100008],occur[1000005];
bool flag;
 
map<ll,ll> hav;
 
 
void dfs(int s, int sum)
{
	
	vis[s]=1;
	vector<int>::iterator it;
	
	for(it=adj[s].begin();it!=adj[s].end();++it)
	{
		if(!vis[*it])
		{
			ar[*it]=sum+has[s][*it];
			dfs(*it,ar[*it]);
		}
		else if(vis[*it])
		{
			int p=sum+has[s][*it];
			
			//cout<<"vis p="<<p<<"\n";
			
			if(p!=ar[*it])
			{
			flag=1;
			}
		}
	}
}
 
 
 
 
int main() 
{
    ll n,m,t,p,q,s,a,b,c,d,e,f,g,h,sum=0,res,u,v,i,j,l,k,len,ans=0,tot,rad,ds,rs,x,y,r,z,maxm,minm;
    
    string str,ptr="";
    
    
    cin>>n;
    
    for(i=0;i<n;i++)
    {
    cin>>ar[i];
    hav[ar[i]]++;
    hav[ar[i]-1]++;
    hav[ar[i]+1]++;
    }
    
    maxm=0;
    
    for(map<ll,ll>::iterator it=hav.begin();it!=hav.end();++it)
    {
    	maxm=max(maxm,it->ss);
	}
    
    cout<<maxm;
    
    
    return 0;
    
}

Measured memory_bytes: 65536
import java.util.*;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        String str = sc.next();
        int K = sc.nextInt();
        TreeSet<String> set = new TreeSet<>();

        for (int i = 1; i <= K; i++) {
            for (int j = 0; j < str.length() - (i  - 1); j++) {
                set.add(str.substring(j, j + i));
            }
        }

        int count = 0;
        for (String subStr : set) {
            count++;
            if (count == K) {
                System.out.println(subStr);
            }
        }
    }
}

Measured memory_bytes: 25420
#include <iostream>
#include <string.h>
using namespace std;

#define MOD 1000000007

main(){
	int n;
	int a[200010];
	bool b;
	long long ans,k,l;
	string s;
	
	cin>>n>>s;
	k = 0;
	b = false;
	for(int i=0;i<n*2;i++){
		if(s[i] == 'B'){
			b = true;
			if(k%2 == 0){
				a[i] = 1;
				k++;
			}
			else{
				a[i] = 2;
				k--;
			}
		}
		else{
			if(k%2 == 0){
				if(k == 0){
					cout<<0;
					return 0;
				}
				else{
					a[i] = 2;
					k--;	
				}
			}
			else{
				a[i] = 1;
				k++;
			}
		}
	}
	if(k != 0 || b == false){
		cout<<0;
		return 0;
	}
	k = l = 0;
	ans = 1;
	for(int i=0;i<n*2;i++){
		if(a[i] == 1)
			k++;
		else if(a[i] == 2){
			ans *= k;
			ans %= MOD;
			k--;
			l++;
		}
	}
	for(int i=2;i<=l;i++){
		ans *= i;
		ans %= MOD;
	}
	cout<<ans;
	
} 


Measured memory_bytes: 1284
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int H = sc.nextInt();
        int[] a = new int[N];
        int[] b = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
        } 
        int max = 0;
        for (int i = 0; i < a.length; i++) {
            max = Math.max(max, a[i]);
        }
        List<Integer> bovermax = new ArrayList<>();
        for (int i = 0; i < b.length; i++) {
            if (b[i] > max) {
                bovermax.add(b[i]);
            }
        }
        Collections.sort(bovermax, Collections.reverseOrder());
        int damage = 0;
        int counter = 0;
        for (int i = 0; i < bovermax.size(); i++) {
            damage += bovermax.get(i);
            counter++;
            if (damage >= H) {
                break;
            }
        }
        counter += ((H - Math.min(damage, H)) + max - 1) / max;
        System.out.println(counter);
        sc.close();
    }
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);

/* -----  2019/04/27  Problem: ABC 125 C / Link: http://abc125.contest.atcoder.jp/tasks/abc125_c  ----- */

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

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

	VL R(N), L(N);
	FOR(i, 0, N) {
		L[i] = (i ? __gcd(L[i - 1], a[i]) : a[i]);
	}
	reverse(ALL(a));

	FOR(i, 0, N) {
		R[i] = (i ? __gcd(R[i - 1], a[i]) : a[i]);
	}
	LL ans = 0;
	FOR(i, 0, N) {
		if (i == 0) {
			ans = max(ans, (R[N - i - 2]));
		}
		else if (i == N - 1) {
			ans = max(ans, (L[i - 1]));
		}
		else {
			ans = max(ans, __gcd(L[i-1], R[N - i - 2]));
		}
	}


	cout << (ans) << "\n";

	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    int x, A, B;
    cin >> x >> A >> B;
    if (B-A <= 0){
        cout << "delicious" << endl;
    }
    else if (B-A <= x)cout << "safe" << endl;
    else cout << "dangerous" << endl;
}

Measured memory_bytes: 256
import numpy as np
import random
import sys
from functools import lru_cache

def main(n,k,a):

    mod = 10**9 + 7
    c1,c2 = 0,0
    for i in range(len(a)):
        for j in range(len(a)):
            # print('--- ---', i,j)
            if a[i] > a[j]:
                
                if i < j:
                    c1 += 1

                elif i > j:
                    c2 += 1
        
        count = (c1*k*(k+1)//2 + c2*k*(k-1)//2)%mod

    print(count)


if __name__ == '__main__':
    n,k = map(int,input().split(' '))
    a = list(map(int, input().split(' ')))
    main(n,k,a)


Measured memory_bytes: 14148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
#define PB push_back

#define N 100'005
int n;
int h[N];
int a[N];

int main(){
	scanf("%d", &n);
	REP(i, n) scanf("%d", h+i);
	a[0] = 0, a[1] = abs(h[0]-h[1]);
	FOR(i, 2, n){
		a[i] = min(a[i-2]+abs(h[i-2]-h[i]), a[i-1]+abs(h[i-1]-h[i]));
	}
	printf("%d\n", a[n-1]);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for (int i=(int)(n)-1;i>=0;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1);
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};
typedef long long ll;
typedef pair<int,int> pii;
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<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>&os,
const C& c){os<<'[';for(auto i=begin(c);i!=end(c);++i)os<<(i==begin(c)?"":" ")<<*i;return os<<']';}
template<class S,class T>ostream&operator<<(ostream &o,const pair<S,T>&t){return o<<'('<<t.first<<','<<t.second<<')';}
template<int N,class Tp>void output(ostream&,const Tp&){}
template<int N,class Tp,class,class ...Ts>void output(ostream &o,const Tp&t){if(N)o<<',';o<<get<N>(t);output<N+1,Tp,Ts...>(o,t);}
template<class ...Ts>ostream&operator<<(ostream&o,const tuple<Ts...>&t){o<<'(';output<0,tuple<Ts...>,Ts...>(o,t);return o<<')';}
template<class T>void output(T t,char z=10){if(t<0)t=-t,putchar(45);int c[20];
int k=0;while(t)c[k++]=t%10,t/=10;for(k||(c[k++]=0);k;)putchar(c[--k]^48);putchar(z);}
template<class T>void outputs(T t){output(t);}
template<class S,class ...T>void outputs(S a,T...t){output(a,32);outputs(t...);}
template<class T>void output(T *a,int n){REP(i,n)cout<<a[i]<<(i!=n-1?',':'\n');}
template<class T>void output(T *a,int n,int m){REP(i,n)output(a[i],m);}
template<class T>bool input(T &t){int n=1,c;for(t=0;!isdigit(c=getchar())&&~c&&c-45;);
if(!~c)return 0;for(c-45&&(n=0,t=c^48);isdigit(c=getchar());)t=10*t+c-48;t=n?-t:t;return 1;}
template<class S,class ...T>bool input(S&a,T&...t){input(a);return input(t...);}
template<class T>bool inputs(T *a, int n) { REP(i,n) if(!input(a[i])) return 0; return 1;}

int main() {
  int a,b,c;
  while(input(a,b,c)) {
    cout << min({a+b,b+c,c+a}) << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5000;
ll dp[N][26], n;
string s, p = "FESTIVA";

ll calc(int i, int j) {
	if (j == 'A')
		return 1;
	if (i == n)
		return 0;
	ll &ret = dp[i][j];
	if (ret != -1)
		return ret;
	ret = calc(i + 1, j);
	if (p[p.find(j) + 1] == s[i])
		ret += calc(i + 1, s[i]);
	return ret;
}
int main(int argc, char **argv) {
	for (int i = 0; i < 600; ++i)
		s += p;
	memset(dp, -1, sizeof dp);
	n = s.size();
	for (int i = N - 100; i >= 0; i -= 100)
		calc(i, 'Q');
	reverse(p.begin(), p.end());
	s.clear();
	ll x, t;
	cin >> x;
	for (int i = 0; i < 600; ++i) {
		if (dp[i * 7]['Q'] == -1)
			continue;
		t = x / dp[i * 7]['Q'];
		s += string(t, 'L') + p;
		x -= t * dp[i * 7]['Q'];
	}
	reverse(s.begin(), s.end());
	puts(s.c_str());
	return 0;
}


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

int main() {
    int n;
    cin >> n;

    if (n == 1) {
        cout << 1 << endl;
        return 0;
    }

    long long L0 = 2;
    long long L1 = 1;
    long long L2;
    for (int i = 2; i <= n; i++) {
        L2 = L1 + L0;
        L0 = L1;
        L1 = L2;
    }

    cout << L2 << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
import queue
readline = sys.stdin.readline
write = sys.stdout.write

n = int(input())
G = [None for i in range(n+1)]
dist = [-1,]*(n+1)
for i in range(n):
    node_id, k, *adj = map(int, readline().split())
    # adj.sort()
    G[node_id] = adj

def bfs(G):
    #q1が空でなければcntをインクリメントして下のブロックの処理を行う
        #q1から要素取り出し
        #→既に見た節点ならばそれに対しては処理を行わずq1から要素を取り出す(節点1⇔節点2の時の無限ループ回避)
        #→最短距離を格納した後,その要素の子をq2に入れる
        #→q1から要素が無くなったらq2の要素を全てq1に入れる
    cnt = -1

    q1 = queue.Queue()
    q2 = queue.Queue()
    q1.put(1)
    while not q1.empty():
        cnt += 1
        while not q1.empty():
            val = q1.get()
            if dist[val] != -1:
                continue
            dist[val] = cnt
            listlen = len(G[val])
            for i in range(listlen):
                q2.put(G[val][i])
        while not q2.empty():
            q1.put(q2.get())
bfs(G)
for i in range(1, n+1):
    write(str(i) + " " + str(dist[i]) + "\n")


Measured memory_bytes: 6852
s = str(input())
 
s_length = len(s)
 
answer = 0
cnt = 0
t = 0
_t = 0
for i in range(s_length):
  if s[i] == '<':
    t += 1
    cnt = 0
    answer += t
  else:
    if t == 0:
      if _t <= cnt:
        t = 0
        cnt += 1
        answer += cnt 
      else:
        t = 0
        cnt += 1
        answer += cnt - 1
    else:
      _t = t
      t = 0
      answer += cnt * 1
      cnt += 1
      
print(answer)

Measured memory_bytes: 4212
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <numeric>
#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
using namespace std;

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

	int N, Y;
	cin >> N >> Y;
	int sum = 0;
	int x = 0, y = 0, z = 0;
	bool flag = false;

	REP(i, N + 1) {
		x = i;
		REP(j, N - i + 1) {
			y = j;
			z = N - (x + y);
			if (z <= -1)break;
			sum = 10000 * x + 5000 * y + 1000 * z;
			if (sum == Y) {
				flag = true;
				break;
			}
		}
		if (flag == true)break;
	}

	if (flag == true) {
		cout << x << " " << y << " " << z << endl;
	}
	else if (flag == false)
	{
		cout << -1 << " " << -1 << " " << -1 << endl;
	}

	return 0;
}

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

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

int main() {
    int x, y;
    cin >> x >> y;

    int result = gcd(x, y);
    printf("%d\n", result);

    return 0;
}

Measured memory_bytes: 3220
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n,m;
    cin >> n >> m;
    ll a[m];
    ll d[n+1];
    F0R(i,m) cin >> a[i];
    ll curInd = 0;
    bool restEnd = false;
    F0R(i,n+1){
      if(!restEnd)
        if(i == a[curInd]){
          d[i] = 0;
          curInd++;
          if(curInd == m) restEnd = true;
          continue;
        }
      if(i == 0) d[i] = 1;
      else if(i == 1) {
        d[i] = d[i-1];
      }
      else {
        d[i] = (d[i-1]+d[i-2])%MOD;
      }
    }

    cout << d[n]<<endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 1792