akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
using namespace std;
#define ll long long

void swap(pair<int,int> *a,pair<int,int> *b){
	pair<int,int> temp=*a;
	*a=*b;
	*b=temp;
}
void quicksort(pair<int,int> a[],int lower,int upper){
	pair<int,int> bound=a[lower];
	int l=lower,u=upper;
	//printf("lower = %d, upper = %d\n",l,u);
	do{
		while(a[l]<bound)l++;
		while(a[u]>bound)u--;
		if(l<=u){
			swap(&a[l],&a[u]);
			l++;
			u--;
		}
	}while(l<u);
	if(lower<u)quicksort(a,lower,u);
	if(l<upper)quicksort(a,l,upper);
}
int main(){
	int n,q;
	pair<int,int> ab[200010]={};
	pair<int,int> px[200010]={};
	int v[200010]={};
	cin>>n>>q;
	for(int i=0;i<n-1;i++){
		cin>>ab[i].first>>ab[i].second;
	}
	for(int i=0;i<q;i++){
		cin>>px[i].first>>px[i].second;
	}
	quicksort(ab,0,n-2);
	quicksort(px,0,q-1);
	int p_ab=0,p_px=0;
	for(int i=1;i<=n;i++){
		//cout<<"set"<<i<<endl;
		while(1){
			if(px[p_px].first==i){
				v[i]+=px[p_px].second;
				p_px++;
			}else if(px[p_px].first>i || px[p_px].first==0){
				break;
			}
		}
		//cout<<"send"<<i<<endl;
		while(1){
			//cout<<"  send"<<p_ab<<" "<<ab[p_ab].first<<endl;
			if(ab[p_ab].first==i){
				//cout<<"1"<<endl;
				v[ab[p_ab].second]+=v[i];
				p_ab++;
			}else if(ab[p_ab].first>i || ab[p_ab].first==0){
				//cout<<"3"<<endl;
				break;
			}
		}
		//cout<<"end"<<i<<endl;
	}
	for(int i=1;i<=n;i++){
		cout<<v[i]<<" ";
	}
	return 0;
}


Measured memory_bytes: 6272
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int s = sc.nextInt();
        final long mod = 1000000007;
        //s個の〇に仕切りを入れて数列を作る
        long dp[] = new long [s + 1];
        dp[0] = 1;
        
        for(int i = 1; i < s + 1; i++){
            for(int j = 0; j < i - 3 + 1; j++){
                dp[i] += dp[j];
                dp[i] %= mod;
            }
        }
        //正解を出力
        System.out.println(dp[s]);
    }
}


Measured memory_bytes: 35904
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define M 1000000007
#define all(a) (a).begin(),(a).end()
#define rep(i,n) reps(i,0,n)
#define reps(i,m,n) for(int i=(m);i<(n);i++)
int main(){
  int a,b,c;cin>>a>>b>>c;
  cout<<c<<" "<<a<<" "<<b;
}

Measured memory_bytes: 256
def dgsm(n):
    x=0
    while n>0:
        x+=n%10
        n//=10
    return(x)
ans=0
n,a,b=map(int, input().split())
for i in range(1,n+1):
    if a<=dgsm(i)<=b:
        ans+=i
print(ans)

Measured memory_bytes: 84224
import java.util.*;
import java.io.*;
import java.math.*;
class Main
{
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
    public static void main(String args[])
    {
        FastReader sc=new FastReader();
        int k=sc.nextInt();
        int a=sc.nextInt();
        int b=sc.nextInt();
        int sum=0;
        for(int i=a;i<=b;i++)
        {
            if(i%k==0)
            {
                sum=1;
            }
        }
        if(sum==1)
        {
            System.out.println("OK");
        }
        else
        {
            System.out.println("NG");
        }


    }
}   

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout.precision(10);
    cout<<fixed;
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
#endif
    int n,m;
    cin>>n>>m;
    bool ans=true;
    vector<int> v(n);
    vector<bool> b(n);
    while(m--) {
        int x,y;
        cin>>x>>y;
        if (!b[x-1]) {
            v[x-1]=y;
            b[x-1]=true;
        }
        else if(v[x-1]!=y) ans=false;
    }
    if(n>1) {
        if(v[0]==0 && b[0]) ans=false;
        else if(v[0]==0) v[0]=1;
    }
    if(ans)
        for(auto i:v) cout<<i;
    else cout<<-1;
    return 0;
}

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

int main(){
    int N,T,A;
    cin>>N>>T>>A;

    vector<pair<double,int>> data;
    for(int i=0;i<N;i++){
        pair<double,int> x;
        int y;
        cin>>y;
        x=make_pair(abs(T-0.006*y-A),i+1);
        data.push_back(x);
    }
    
    sort(data.begin(),data.end());
    cout<<data.at(0).second<<endl;
}

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

int main(){
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  int D = max({A, B, C});
  int E = D;
  for(int i=0; i<K; i++){
    E = E*2;
  }
  int ans = A + B + C - D + E;
  cout << ans << endl;
}

Measured memory_bytes: 256
class AtCoder {
  // 入力系
  input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);
  input_i=-1;

  N=this.input[0];
  M=this.input[1];
  SN=String(this.input[0]);
  SM=String(this.input[1]);

  n(){
    this.input_i++;
    return Number(this.input[this.input_i]);
  }
  nn(n:number):number[]{
    const a=[];
    for(let i=0;i<n;i++){
      a.push(this.n());
    }
    return a;
  }
  s(){
    this.input_i++;
    return String(this.input[this.input_i]);
  }
  ss(n:number):string[]{
    const a=[];
    for(let i=0;i<n;i++){
      a.push(this.s());
    }
    return a;
  }

  // コンソール
  o(...a:any){
    console.log(...a);
  }

  // Math
  abs(a:number){
    return Math.abs(a);
  }
  min(...a:number[]){
    return Math.min(...a);
  }
  max(...a:number[]){
    return Math.max(...a);
  }
  floor(a:number){
    return Math.floor(a);
  }
  ceil(a:number){
    return Math.ceil(a);
  }
  round(a:number){
    return Math.round(a);
  }

  // ソート
  asc(ar:number[]){
    const t=[...ar];
    ar.sort((a,b)=>{return a-b});
  }
  desc(ar:number[]){
    const t=[...ar];
    ar.sort((a,b)=>{return b-a});
  }

  // 自作
  gcd(...arr:number[]):number{
    for(let i=0;i<arr.length-1;i++){
      let [x,y]=[arr[i],arr[i+1]];
      while(y){
        [x,y]=[y,x%y];
      }
      arr[i+1]=x;
    }
    return arr[arr.length-1];
  };
  lcm(...arr:number[]):number{
    for(let i=0;i<arr.length-1;i++){
      let [x,y]=[arr[i],arr[i+1]];
      while(y){
        [x,y]=[y,x%y];
      }
      arr[i+1]=arr[i]*arr[i+1]/x;
    }
    return arr[arr.length-1];
  };
  isPrime(n:number):boolean{
    if(n < 2) return false;
    const suq=Math.sqrt(n);
    for(let i=2;i<=suq;i++){
      if(n%i==0){
        return false;
      }
    }return true;
  };
  deduplicate(a:any[]):any[]{
    return Array.from(new Set(a));
  };
  f(roop:number, callback:any){
    for(let i=0;i<roop;i++){
      callback(i);
    }
  };
  Yes(){
    console.log('Yes');
  }
  No(){
    console.log('No');
  }
  YES(){
    console.log('YES');
  }
  NO(){
    console.log('NO');
  }
}
const m = () => {
  const o = new AtCoder()
  o.o(o.n() <= o.n() ? 'unsafe' : 'safe')
}
m();

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

int main()
{
    int N;
    ll L, T;
    cin >> N >> L >> T;
    vector<ll> X(N);
    vector<int> W(N);
    for (int n = 0; n < N; ++n) {
        cin >> X[n] >> W[n];
    }

    ll Col = 0LL;
    int Num; ll Pos;
    switch (W[0]) {
    case 1:
        for (int n = 1; n < N; ++n) {
            if (W[n] == 2) {
                Col += (2*T-X[n]+X[0]+L) / L;
            }
        }
        Num = Col % N;
        Pos = (X[0]+T) % L;
        break;
    case 2:
        for (int n = 1; n < N; ++n) {
            if (W[n] == 1) {
                Col += (2*T-L+X[n]-X[0]+L) / L;
            }
        }
        Num = (N*T-Col) % N;
        Pos = (X[0]-T+T*L) % L;
        break;
    }

    vector<ll> P;
    P.reserve(N);
    for (int n = 0; n < N; ++n) {
        switch (W[n]) {
        case 1:
            P.push_back((X[n]+T)%L);
            break;
        case 2:
            P.push_back((X[n]-T+L*T)%L);
            break;
        }
    }
    sort(P.begin(), P.end());

    int K = lower_bound(P.begin(), P.end(), Pos) - P.begin();
    if (P[K+1] == Pos && W[0] == 1) {
        ++K;
    }
    
    for (int n = 0; n < N; ++n) {
        cout << P[(K+n-Num+N) % N] << endl;
    }

    return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(i=1;i<=n;i++)
#define reps(i,a,n) for(i=a;i<=n;i++)
#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))
#define all(x) (x).begin(),(x).end()
#define fast ios_base:: sync_with_stdio( false ); cin.tie(0); cout.tie(0);
#define eb              emplace_back
#define em              emplace
#define pb              push_back
#define Mp              make_pair
#define ff              first
#define ss              second
#define mod 1000000007
typedef long long ll;
using namespace std;

const int M = (int)(2e6 + 239);

void decitobinbitodeci()
{
    string binary = bitset<8>(128).to_string(); //to binary
    cout<<binary<<"\n";

    unsigned long decimal = bitset<8>(binary).to_ulong();
    cout<<decimal<<"\n";
}

int getnum(string a)
{
    int i,p=0;
    rep0(i,a.size())
    {
        p*=10;
        p+=a[i]-'0';
    }
    return p;
}

/*
1.always remember for ncr(n,2), you can calculate by
n*(n-1)/2
2.Power of 2 ->  (1ll<<i)
*/

int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast

    double a,b,c,d,y,z;
    cin>>a>>b>>c;
    double x=b-1;
    if(c>x)
    {
        c=x;
    }
    y=floor((c*a)/b);
    z=a*floor(c/b);
    cout<<y-z<<endl;
}


Measured memory_bytes: 3844
#include<stdio.h>
int main()
{
  int a, b,c;
  scanf("%d" ,&a);
  scanf("%d" ,&b);
  
  c= a*b;
  
  if(c%2 == 1)
    printf("Yes");
  
  else
    printf("No");
  
  return 0;
}

Measured memory_bytes: 128
/*
██████╗  ███████╗  
██╔══██╗ ██╔════╝ 
██████╔╝ ███████╗ 
██╔══██╗ ╚════██║  
██║  ██║ ███████║      
╚═╝  ╚═╝ ╚══════╝                                                                                                             
*/

#include<bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define haha(j,a,n) for(int j=a;j<n;j++)
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define endl "\n"
#define bc(v) v.begin(),v.end()
#define vl vector<ll>
#define vi vector<int>
#define mod 1000000007
#define NUM 100005
#define F first
#define S second
#define bhar(a) rep(i,a.size()) cin>>a[i];
#define show(a) rep(i,a.size()) cout<<a[i]<<" ";
#define sott(a) sort(bc(a))
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define mapp map<ll,ll>
#define dkac cout<<fixed<<setprecision(15);
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define yeah(n) while(n--)
ll gcd(int a, int b){if(b==0) return a; else return gcd(b,a%b);}
ll bitfun(ll x){
  return (x&(-x));
}
void solve(){
  ll x; cin>>x;
  for(ll i=1;i*i<=x;i++){
    if(x%i==0){
      ll cnt=0;
      while(cnt<=1000){
        if(pow(cnt,5)-pow(cnt-i,5)==x){
          cout<<cnt<<" "<<cnt-i;
          return;
        }
        cnt++;
      }
    }
  }
}
int main(){
    ios
    int t=1; 
    //cin>>t;
    yeah(t){
      solve();
    }
}

Measured memory_bytes: 4028
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
using namespace std;

int N;
vector<pair<long,long>> job;

string ans = "";

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}
 
void solve(){
	sort(job.begin(),job.end(), compare_by_b);//締め切り日(B[i])に関して昇順に並べ替え

	long spent_time = 0;//i個目の仕事をした時点で何日経っているか
	for(int i=0;i<N;i++){
		spent_time+=job[i].first;//使った時間を加算
		if(spent_time>job[i].second){//締め切りを過ぎたなら
			ans = "No";
			return;
		}
	}
	ans = "Yes";
}
 
int main(){
	cin >> N;
	for(int i=0;i<N;i++){
		long a,b;
		cin>>a>>b;
		job.push_back(make_pair(a,b));
	}
 
	solve();
 
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 6384
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n, m = map(int, input().split())
H = list(map(int, input().split()))
edges = [[] for _ in range(n)]
for _ in range(m):
    a, b = list(map(lambda x: int(x)-1, input().split()))
    edges[a].append(b)
    edges[b].append(a)


ans = [0]*n


def dfs(v, parent):
    if visited[v]:
        return 0
    visited[v] = 1
    if not edges[v]:
        ans[v] = 1
    elif all(H[v2] < H[v] for v2 in edges[v]):
        ans[v] = 1
    for v2 in edges[v]:
        if v2 == parent:
            continue
        dfs(v2, v)


visited = [0]*n

for v in range(n):
    if visited[v]:
        continue
    dfs(v, -1)

print(sum(ans))


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

int *InsertionSort(int *,int);
int kansuu(int);
int num, cnt=0;
  
int main(){
  int *data, *g, m=0, i;

  //input data
  scanf("%d",&num);
  data=(int *)malloc(sizeof(int)*num);
  for(i=0;i<num;i++) scanf("%d",&data[i]);


  //shell sort
  for(i=1;kansuu(i)<=num;i++) m++;
  g=(int *)malloc(sizeof(int)*m);
  for(i=1;i<=m;i++) g[m-i]=kansuu(i);
  
  //insertionsort
  for(i=0;i<m;i++) data=InsertionSort(data,g[i]);
  

  //output result
  printf("%d\n",m);
  for(i=0;i<m-1;i++) printf("%d ",g[i]);
  printf("%d\n%d\n",g[i],cnt);
  for(i=0;i<num;i++) printf("%d\n",data[i]);
  

  free(data);
  free(g);
  return 0;
}

int *InsertionSort(int *data,int g){
  int i, j, v;

  for(i=g;i<num;i++){
    v=data[i];
    j=i-g;
    while(j>=0 && data[j]>v){
      data[j+g]=data[j];
      j-=g;
      cnt++;
    }
    data[j+g]=v;
  }
  
  return data;
}

int kansuu(int i){
  int a, b=1;
  if(i==1) return 1;
  else{
    for(a=0;a<i-1;a++) b*=3;
    return kansuu(i-1)+b;
  } 
}




Measured memory_bytes: 5452
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

//#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}

int a[85][85];
struct node{
    int x,y,sum;
};
int h,w;
bool in(int x,int y){
    if(x < 0 || x >= h)return false;
    if(y < 0 || y >= w)return false;
    return true;
}
int dx[] = {0,1};
int dy[] = {1,0};
signed main(void) {
    cin >> h >> w;
    rep(i,h)rep(j,w)cin >> a[i][j];
    rep(i,h)rep(j,w){
        int t;
        cin >> t;
        a[i][j] -= t;
        a[i][j] = abs(a[i][j]);
    }
    vector<vvi> v(h,vvi(w,vi(80*80,0)));
    v[0][0][a[0][0]] = 1;
    rep(i,h)rep(j,w)rep(sum,80*80)if(v[i][j][sum]){
        rep(k,2){
            int x = i + dx[k];
            int y = j + dy[k];
            if(in(x,y)){
                if(abs(sum+a[x][y]) < 80*80)v[x][y][abs(sum+a[x][y])]++;
                if(abs(sum-a[x][y]) < 80*80)v[x][y][abs(sum-a[x][y])]++;
            }
        }
    }
    rep(i,80*80){
        if(v[h-1][w-1][i]){
            cout << i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 162688
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

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

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

void	solve()
{
	string s;
	cin >> s;
	int n = s.size();
	int head, tail;
	rep(i, n) {
		if (s[i] == 'A') {
			head = i;
			break;
		}
	}
	for (int i = n - 1; ~i; i--) {
		if (s[i] == 'Z') {
			tail = i;
			break;
		}
	}
	cout << tail - head + 1 << endl;
}

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

	solve();
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

template <class T>
inline void read(T &x) {
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar()) f ^= c == '-';
    for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    T y = 1;
	int len = 1;
    for (; y <= x / 10; y *= 10) ++len;
    for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}

int n;
double ans;

int main() {
	read(n);
	for (int x, i = 1; i <= n; ++i) {
		read(x);
		ans += 1.0 / x;
	}
	ans = 1.0 / ans;
	printf("%.10lf\n", ans);
	return 0;
}

Measured memory_bytes: 256
#pragma warning(disable: 4996)

#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <functional>
#include <cstdio>
#include <cctype>
#include <climits>
#include <cmath>
#include <bitset>
#include <numeric>
#include <string>
#include <set>
#include <tuple>
#include <utility>
#include <regex>
#include <deque>
#include <map>
#include <queue>
#include <stack>
#include <sstream>
using namespace std;

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

	long long x, res = 0;
	cin >> x;
	res += x / 500 * 1000;
	x -= x / 500 * 500;
	res += x / 5 * 5;
	cout << res;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define test() ll t;cin>>t;while(t--)
#define MOD 1000000007
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)

int main() {
    SPEED;
    //CODE
	ll n,W;
	cin>>n>>W;
	ll w[n],v[n];
	ll ans=0;
	for(ll i=0;i<n;i++) cin>>w[i]>>v[i];
	ll dp[2][100001];
	for(ll i=0;i<2;i++){
		for(ll j=0;j<100001;j++){
			dp[i][j]=10e9;
		}
	}
	dp[0][0]=0;
	for(ll i=1;i<=n;i++){
		for(ll j=0;j<100001;j++){
			if(dp[0][j]!=10e9){
				dp[1][j]=min(dp[1][j],dp[0][j]);
				dp[1][j+v[i-1]]=min(dp[1][j+v[i-1]],dp[0][j]+w[i-1]);
			}
		}
		for(ll j=0;j<100001;j++){
				dp[0][j]=dp[1][j];
		}
	}
	for(ll i=0;i<100001;i++){
			if(dp[1][i]<=W){
				ans=i;
			}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
#define dump(x) cout << (x) << endl;
typedef int64_t Int;
Int mod = 1e9+7;

int main() {
  Int x, y, z;
  cin >> x >> y >> z;
  Int res = (x - z) / (y + z);
  x %= (y + z);
  if (x >= y + z) res++;
  dump(res);
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
const int maxn=1e5+10;
using namespace std;
struct node
{
	long long a,b;
}e[maxn];
bool cmp(node x,node y)
{
	return x.a<y.a;
}
int main()
{
	long long n,k,i;
	long long sum=0;
	cin>>n>>k;
	for(i=1;i<=n;i++)
	{
		cin>>e[i].a>>e[i].b;
	}
	sort(e+1,e+n+1,cmp);
	for(i=1;i<=n;i++)
	{
		sum+=e[i].b;
		if(sum>=k)
		{
			cout<<e[i].a<<endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <vector>
#include <functional>
using namespace std;

//---------------------------------------------------------------
// ------ graph ------ //
using Weight = int;
using Flow = int;
struct Edge {
    int src, dst;
    Weight weight;
    Flow cap;
    Edge() : src(0), dst(0), weight(0) { }
    Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) { }
};
bool operator < (const Edge &e, const Edge &f) {
    return e.weight != f.weight ? e.weight > f.weight : // pqが降順のため
        e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
using Edges = vector<Edge>;
struct Graph {
    vector<Edges> adj;
    Graph(int n) : adj(n) { }
    int size() { return adj.size(); }
    Edges operator [] (int v) { return adj[v]; }
    void add_edge(int a, int b, Weight w = 1) { // graph
        adj[a].emplace_back(a, b, w);
        adj[b].emplace_back(b, a, w);
    }
    void add_arc(int a, int b, Weight w = 1) {  // digraph
        adj[a].emplace_back(a, b, w);
    }
};
using Array = vector<Weight>;
using Matrix = vector<Array>;

// ------ Topological Sort (dfs) ------ //
vector<int> tsort(Graph &g) {
    int n = g.size();
    enum { YET, VISITED, DONE };
    vector<int> res, color(n, YET);
    static const function<bool(int)> dfs = [&](int v) {
        color[v] = VISITED;
        for (Edge &e : g[v]) {
            if (color[e.dst] != DONE && (color[e.dst] == VISITED || !dfs(e.dst))) return false;
        }
        color[v] = DONE; res.push_back(v);
        return true;
    };
    for (int i = 0; i < n; ++i) if (color[i] == YET && !dfs(i)) return {};
    reverse(res.begin(), res.end());
    return res;
}
//---------------------------------------------------------------

int main() {
    int V, E; cin >> V >> E;
    Graph g(V);
    for (int i = 0; i < E; i++) {
        int s, t; cin >> s >> t;
        g.add_arc(s, t);
    }
    vector<int> ord = tsort(g);
    for (int i = 0; i < V; i++) cout << ord[i] << endl;
    return 0;
}


Measured memory_bytes: 4320
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const ll mod = 1e9+7;

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

  ll q, h, s, d; cin >> q >> h >> s >> d;
  h = min(2*q, h);
  s = min(2*h, s);
  d = min(2*s, d);

  ll n; cin >> n;
  ll ans = (n/2)*d + (n%2)*s;
  cout << ans << endl;
}

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

#define INF 0x3f3f3f3f
#define EPS 1e-6
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 10;

int T;

int main()
{
    int a, b, c;
    while(cin >> a >> b >> c){
        cout << c << " " << a << " " << b << endl;
    }
    return 0;
}


Measured memory_bytes: 3620
import java.io.*;
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.StringTokenizer; 
import java.util.*;


public  class Main
{

	   
	   static class FastReader 
	    { 
	        BufferedReader br; 
	        StringTokenizer st; 
	       
	  
	        public FastReader() 
	        { 
	            br = new BufferedReader(new
	                     InputStreamReader(System.in)); 
	        } 
	  
	        String next() 
	        { 
	            while (st == null || !st.hasMoreTokens()) 
	            { 
	                try
	                { 
	                    st = new StringTokenizer(br.readLine()); 
	                } 
	                catch (IOException  e) 
	                { 
	                    e.printStackTrace(); 
	                } 
	            } 
	            return st.nextToken();
	            
	        } 
	  
	        int nextInt() 
	        { 
	            return Integer.parseInt(next()); 
	        } 
	  
	        long nextLong() 
	        { 
	            return Long.parseLong(next()); 
	        } 
	  
	        double nextDouble() 
	        { 
	            return Double.parseDouble(next()); 
	        } 
	  
	        String nextLine() 
	        { 
	            String str = ""; 
	            try
	            { 
	                str = br.readLine(); 
	            } 
	            catch (IOException e) 
	            { 
	                e.printStackTrace(); 
	            } 
	            return str; 
	        }

			public Character charAt(int i) {
				// TODO Auto-generated method stub
				return null;
			} 
	    } 

  

	  // Complete the hurdleRace function below.
//    public static void solve() {
//    	FastReader s=new FastReader();

    public static void main(String[] args) throws IOException {
    	FastReader s=new FastReader();
   			int n = s.nextInt();
			int[] ar = new int[n];
			for(int i=0;i<n;i++) {
				ar[i]=s.nextInt();
			}
			int s1=0;
			for(int i=0;i<n-1;i++) {
				for(int j=i+1;j<n;j++) {
					s1=s1 + (ar[i]*ar[j]);
				}
			}
			System.out.println(s1);
    }	
}





        
    

      
 

Measured memory_bytes: 32856
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
	
		Scanner scanner = new Scanner(System.in);
		if(scanner.hasNext()) {
			int x = scanner.nextInt();
			if(x==3||x==5||x==7) {
				System.out.println("YES");
			}else {
				System.out.println("NO");
			}
			scanner.close();
		}
	}
	
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <stdio.h>

#define rep(i, n) for(int i = 0;i < (n);++i)

int main(int argc, char** argv) {
  int N;
  std::cin >> N;
  std::vector<double> p(N);
  rep(i, N) std::cin >> p[i];
  std::vector<std::vector<double>> dp(N+1, std::vector<double>(N+1, 0));
  dp[0][0] = 1;
  for (auto i = 1;i <= N;++i) {
    for (auto j = 0;j <= i;++j) { // 表の数
      dp[i][j+1] += dp[i-1][j]*p[i-1];
      dp[i][j]   += dp[i-1][j]*(1.00 - p[i-1]);
    }
  }

  double answer {};
  for (auto i = (N+1)/2;i <= N;++i) {
    answer += dp[N][i];
  }

//  std::cout << std::fixed << answer << '\n';
  printf("%.10f\n", answer);
}


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

int main(){
  int H,m;
  cin >> H >> m;
  int a;
  int b=0;
  for(int i=0; i<m; i++){
    cin >> a;
    H = H - a;
    if(H <= 0){
      b=1;
      break;
	}
  }
  if(b == 1)cout << "Yes" << endl;
  if(b == 0)cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    string s; cin >> s;
    int n = s.size(), p = 2019;
    ll res = 0;
    if (p==2 || p==5) {
        rep(i, n) {
            if ((s[i] - '0') % p == 0) res += i+1;
        }
    } else {
        int m = 1;
        vector<int> mods(n);
        vector<ll> cnt(p, 0);
        cnt[0] = 1ll;
        ll val = 0;
        for (int i=n-1; i>=0; --i) {
            val += m * (s[i]-'0');
            val %= p;
            cnt[val]++;
            m = 10 * m % p;
        }
        rep(i, p) res += cnt[i] * (cnt[i]-1) / 2;
    }
    cout << res << endl;
}


Measured memory_bytes: 4344
from bisect import bisect_left

s = input()
t = input()

l = len(s)

ss = s * 2
let = [[] for _ in range(26)]
for i, e in enumerate(ss, 1):
    idx = ord(e) - ord("a")
    let[idx].append(i)

for e in t:
    idx = ord(e) - ord("a")
    if not let[idx]:
        print(-1)
        exit()

i = 1
times = 0
for e in t:
    j = ord(e) - ord("a")
    choose = bisect_left(let[j], i)
    q, r = divmod(let[j][choose], l)
    times += q
    i = r + 1

ans = times * l + i - 1
print(ans)


Measured memory_bytes: 55024
def solve(H, W, grid):
    from collections import deque
    groups = [[0] * W for h in range(H)]
    v = 0 
    def search(M, h0, w0):
        nonlocal v
        count = [0, 0]
        Q = [(h0, w0)]
        groups[h0][w0] = M
        v+=1
        while Q:
            (h, w) = Q.pop()
            c = 1 - grid[h][w]
            count[1-c] += 1
            if h < H-1:
                if groups[h+1][w] == 0:
                    if grid[h+1][w] == c:
                        groups[h+1][w] = M
                        v += 1
                        Q.append((h+1, w))
                    else:
                        q.append((h+1, w))
            if h > 0:
                if groups[h-1][w] == 0:
                    if grid[h-1][w] == c:
                        groups[h-1][w] = M
                        v += 1
                        Q.append((h-1, w))
                    else:
                        q.append((h-1, w))
            if w > 0:
                if groups[h][w-1] == 0:
                    if grid[h][w-1] == c:
                        groups[h][w-1] = M
                        v += 1
                        Q.append((h, w-1))
                    else:
                        q.append((h, w-1))
            if w < W-1:
                if groups[h][w+1] == 0:
                    if grid[h][w+1] == c:
                        groups[h][w+1] = M
                        v += 1
                        Q.append((h, w+1))
                    else:
                        q.append((h, w+1))
        #print("search(%d,%d): %s"%(h0, w0, count))
        return count

    answer = 0
    m = 0
    q = deque()
    q.append((0,0))
    while q:
        h, w = q.pop()
        if groups[h][w] == 0:
            m+=1
            b, w = search(m, h, w)
            answer += b * w
    #for h in range(H): print(*groups[h])
    return answer

def main():
    import sys
    input = sys.stdin.readline
    H, W = map(int, input().split())

    grid = [[0]]*H
    for i in range(H):
        grid[i] = [1 if c == '#' else 0 for c in input().rstrip()]
    print(solve(H, W, grid))

main()




Measured memory_bytes: 22788
import java.util.*;


public class Main{
  public static void main(String[] arg){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    String S = sc.next();
    int B = sc.nextInt();

    if (S.equals("+")){
      int ans = (A + B);
      System.out.println(ans);
    }else {
      int ans = (A - B);
      System.out.println(ans);
    }
  }
}


Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111

	vi morty(310000,0);

	void solve(){

		
		ini(n);
		ini(k);
		int rick = 0;
		map<int,int> map1;
		map1[0] = 1;
		vi pre;
		pre.push_back(0);
		FOR(i,1,n+1){
			ini(morty[i]);
			pre.push_back(pre[i-1]+morty[i]);
			if(i>=k)map1[(pre[i-k]-(i-k))%k]--;
			//out((pre[i]-i)%k,map1[(pre[i]-i)%k]);
			rick+=map1[(pre[i]-i)%k];
			map1[(pre[i]-i)%k]++;
		}
		out(rick);
















	}









































int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}

Measured memory_bytes: 18288
#include "iostream"
using namespace std;
int main() {
	for (int i = 1; i <= 10000; i++) {
		int num;
		cin >> num;
		if (num == 0) {
			break;
		}
		else {
			cout << "Case" << " " << i << ":" << " " << num << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3076
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
namespace IO{
    const int L=30000000;
    char inBuf[L];
    int inPos;
    void load(){
        fread(inBuf,1,L,stdin);
        inPos=0;
    }
    char getChar(){
        return inBuf[inPos++];
    }
    ll getInt(){
        ll x=0,f=1;
        char c=getChar();
        while(c<'0'||c>'9'){if(c=='-')f=-1;c=getChar();}
        while('0'<=c&&c<='9'){x=x*10+c-'0';c=getChar();}
        return x*f;
    }
}
using IO::getInt;
const int N=100010;
int n,m;
ll a[N];
ll f[N],ans[N];
void readData(){
	n=getInt(); m=getInt();
	for(int i=1;i<=m;i++) a[i]=getInt();
	a[0]=n;
}
void arrangeArray(){
	static ll sta[N],top;
	sta[top=1]=a[m];
	for(int i=m-1;i>=0;i--)
		if(a[i]<sta[top])
			sta[++top]=a[i];
	for(int i=1;i<=top;i++) 
		a[top-i+1]=sta[i];
	m=top;
	a[0]=0;
}
void downTag(int s,ll x,ll y){
	if(!y)
		return;
	if(s==1){
		ans[x]+=y;
		return;
	}
	f[s-1]+=y*(x/a[s-1]);
	ll rest=x%a[s-1];
	if(rest){
		int nextPos=lower_bound(a,a+(s-1),rest)-a;
		downTag(nextPos,rest,y);
	}
}
void count(){
	f[m]=1;
	for(int i=m;i>=1;i--)
		downTag(i,a[i],f[i]);
}
void print(){
	for(int i=n;i>=1;i--) ans[i]+=ans[i+1];
	for(int i=1;i<=n;i++)
		printf("%lld\n",ans[i]);
}
int main(){
	IO::load();
	readData();
	arrangeArray();
	count();
	print();
	return 0;
}


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

ll ppow[18], m[18][18];
unordered_map<ll, ll>q, r;
int l;

void dfs(int a, int b, ll s, ll t, vector<P>*v) {
	if (a == b || l - a - 1 <= a) {
		if (a != b&&l - a - 1 == a)t *= 10;
		v->push_back(P(s, t));
		return;
	}
	for (int i = -9; i <= 9; i++) {
		dfs(a + 1, b, s + m[l - a - 1][a] * i, t*(a == 0 ? r[i] : q[i]), v);
	}
}
int main() {
	ppow[0] = 1;
	for (int i = 1; i < 18; i++)ppow[i] = ppow[i - 1] * 10;
	rep(i, 18)rep(j, 18)m[i][j] = ppow[i] - ppow[j];
	rep(i, 10)rep(j, 10) {
		q[i - j]++;
		if (j)r[i - j]++;
	}
	ll D; scanf("%lld", &D);
	ll ans = 0;
	for (l = 2; l <= 18; l++) {
		vector<P>u, v;
		int a = ((l / 2) % 2 == 0 ? l / 2 : l / 2 + 1);
		dfs(0, a / 2, 0, 1, &u);
		dfs(a / 2, 100, 0, 1, &v);
		u.push_back(P(LLONG_MIN, 0));
		sort(u.begin(), u.end());
		for (int i = 1; i < u.size(); i++)u[i].second += u[i - 1].second;
		for (auto p : v)ans += p.second*((upper_bound(u.begin(), u.end(), P(D - p.first, LLONG_MAX)) - 1)->second - (lower_bound(u.begin(), u.end(), P(D - p.first, 0)) - 1)->second);
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 67964
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    static Scanner sc = new Scanner(System.in);
    static int n, x;
    static Card[] A, B;

    public static void main(String[] args) {
        read();
        quickSort(A, 0, n - 1);
        mergeSort(B, 0, n);

        boolean stable = same(A, B);
        String strStable = stable ? "Stable" : "Not stable";
        System.out.println(strStable);

        for (int i = 0; i < n; i++) {
            System.out.println(A[i]);
        }
    }

    static boolean same(Card[] A, Card[] B) {
        for (int i = 0; i < n; i++) {
            if (A[i].p != B[i].p) {
                return false;
            }
        }
        return true;
    }

    static void merge(Card[] A, int l, int m, int r) {
        int n1 = m - l, n2 = r - m;
        Card[] L = new Card[n1 + 1];
        Card[] R = new Card[n2 + 1];

        for (int i = 0; i < n1; i++) {
            L[i] = A[l + i];
        }

        for (int i = 0; i < n2; i++) {
            R[i] = A[m + i];
        }

        L[n1] = new Card(' ', 1 << 31 - 1);
        R[n2] = new Card(' ', 1 << 31 - 1);

        int i = 0, j = 0;
        for (int k = l; k < r; k++) {
            if (L[i].n <= R[j].n) {
                A[k] = L[i];
                i++;
            } else {
                A[k] = R[j];
                j++;
            }
        }
    }

    static void mergeSort(Card[] A, int l, int r) {
        if (l + 1 < r) {
            int m = (r + l) / 2;
            mergeSort(A, l, m);
            mergeSort(A, m, r);
            merge(A, l, m, r);
        }
    }

    static void quickSort(Card[] A, int p, int r) {
        if(p < r) {
            int q = partition(A, p, r);
            quickSort(A, p, q - 1);
            quickSort(A, q + 1, r);
        }
    }

    static int partition(Card[] A, int p, int r) {
        x = A[r].n;
        int i = p - 1;
        for (int j = p; j < r; j++) {
            if (A[j].n <= x) {
                i++;
                Card tmp = A[j]; A[j] = A[i]; A[i] = tmp;
            }
        }
        Card tmp = A[i + 1]; A[i + 1] = A[r]; A[r] = tmp;

        return i + 1;
    }

    static void read() {
        n = sc.nextInt();
        A = new Card[n];
        B = new Card[n];
        for (int i = 0; i < n; i++) {
            char p = sc.next().toCharArray()[0];
            int n = sc.nextInt();
            A[i] = new Card(p, n);
            B[i] = new Card(p, n);
        }
    }
}

class Card {
    char p;
    int n;

    public Card(char p, int n) {
        this.p = p;
        this.n = n;
    }

    @Override
    public String toString() {
        return String.format("%c %d", this.p, this.n);
    }
}

Measured memory_bytes: 125048
N = int(input())
A = list(map(int, input().split()))

cnt = [0] * (100000+1)
ans = 0
for i in range(N):
  cnt[A[i]] += 1
  ans += A[i]
#
Q = int(input())
for i in range(Q):
  B, C = map(int, input().split())
  ans += (C-B) * cnt[B]
  cnt[C] += cnt[B]
  cnt[B] = 0
  print(ans)
#

  


Measured memory_bytes: 21044
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,ans1=0,ans2=0,temp;
    cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>temp;
		if(temp%2==0)
		{
			if(temp%4==0)
				ans1++;
			else
				ans2++;
		}
	} 
	n=n-ans2-ans1;
	if(ans2==0)
	{
		if(n<=ans1+1)
		cout<<"Yes\n";
		else
			cout<<"No\n";
	}
	else
	{
		if(n<=ans1)
		 	cout<<"Yes\n";
		else
			cout<<"No\n";
	}
    return 0;
    
}

Measured memory_bytes: 256
N=int(input())
S=input()

def add1(S):
  cum=[0]
  for i in range(len(S)):
    if S[i]=='(':cum.append(cum[-1]+1)
    else:cum.append(cum[-1]-1)
  if min(cum)>=0:return S
  out = '('*(-min(cum))
  out += S
  return out

def add2(S):
  cum=[0]
  for i in range(len(S)):
    if S[i]=='(':cum.append(cum[-1]+1)
    else:cum.append(cum[-1]-1)
      
  if cum[-1]==0:return S
  n = cum[-1]
  out = S + ')'*n
  return out

S = add1(S)
S = add2(S)
print(S)

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

int gcd(int a, int b) {
    if(b == 0) return a;
    return gcd(b, a % b);
}

void solve(long long K){
    ll ans = 0;
    for(int i = 1;i <= K;i++){
        for(int j = 1;j <= K;j++){
            for(int k = 1;k <= K;k++){
                ans += gcd(i, gcd(j, k));
            }
        }

    }
    cout<<ans<<endl;
}


int main(){
    long long K;
    scanf("%lld",&K);
    solve(K);
    return 0;
}


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

int main(){
    int d;
    int cnt = 0;
    while(cin>>d,d){
        cnt++;
        double C0[d+3];
        double f[d+3];
        for(int i=0;i<d+3;i++) cin>>f[i];
        int ans = 0;

        for(int l=1;l<d+3;l++){
            double mat[d+1][d+2];//?????§??????
            for(int i=0,ite=1;i<d+1;i++){
                if(ite==l) ite++;
                for(int j=0;j<d+1;j++){
                    mat[i][j]=pow(ite,j);
                }
                mat[i][d+1]=f[ite];
                ite++;
            }
            // for(int i=0;i<d+1;i++){
            //     for(int j=0;j<d+2;j++){
            //         cout<<mat[i][j]<<' ';
            //     }
            //     cout<<endl;
            // }
            // cout<<endl;

            //??¬???????¶????
            for(int j=0;j<d+1;j++){
                for(int k=d+1;k>=j;k--) mat[j][k]/=mat[j][j];
                for(int i=0;i<d+1;i++){
                    if(i==j) continue;
                    for(int k=d+1;k>=j;k--) mat[i][k]-=mat[j][k]*mat[i][j];
                }
            }
            if(abs(mat[0][d+1]-f[0])<1e-2) ans = l;
            // cout<<"l:"<<l<<endl;
            // for(int i=0;i<d+1;i++){
            //     for(int j=0;j<d+2;j++){
            //         cout<<mat[i][j]<<' ';
            //     }
            //     cout<<endl;
            // }
            // cout<<endl;
        }
        cout<<ans<<endl;
    }

    return 0;
}

Measured memory_bytes: 3316
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
using namespace std;

int main(){
    string s;cin>>s;
    
    char ch;
    for(ch='a';ch<='z';ch++){
        bool ok=true;
        for(int i=0;i<s.size();i++)if(s[i]==ch){
            ok=false;break;
        }
        if(ok){
            cout<<ch<<endl;
            return 0;
        }
    }

    cout<<"None"<<endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  map<char, int> amap;
  string S;
  for(int i=0;i<N;++i) {
    cin>>S;
    map<char, int> bmap;
    for(int j=0;j<S.size();++j) {
      bmap[S[j]]++;
    }
    if(i==0) {
      for(char a='a';a<='z';++a) amap[a] = bmap[a];
    }
    else {
      for(char a='a';a<='z';++a) amap[a] = min(amap[a], bmap[a]);
    }
  }
  string ans;
  for(char a='a';a<='z';++a) {
    for(int i=0;i<amap[a];++i) ans.push_back(a);
  }
  cout<<ans<<endl;
}



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

int main(){
    ll k, n;
    cin >> k >> n;
    ll a[n + 1];
    rep(i,n) cin >> a[i];
    a[n] = a[0] + k;
    ll ans = 0;
    rep(i, n){
        ll diff = a[i+1] - a[i];
        ans = max(ans, diff);
    }
    cout << k - ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

vector<vector<int>> ass;

void dfs(vector<int> &acc, set<int> &vs) {
    if (vs.empty()) {
        ass.push_back(acc);
        return;
    }

    for (auto &v : vs) {
        acc.push_back(v);
        set<int> new_vs = vs;
        new_vs.erase(v);
        dfs(acc, new_vs);
        acc.pop_back();
    }
}

int find(const vector<int> &xs) {
    for (int i = 0; i < (int) ass.size(); i++) {
        if (ass[i] == xs) {
            return i;
        }
    }

    return -1;
}

int main(void) {
    int N;
    cin >> N;

    vector<int> p, q;
    for (int i = 0; i < N; i++) {
        int x;
        cin >> x;
        p.push_back(x);
    }
    for (int i = 0; i < N; i++) {
        int x;
        cin >> x;
        q.push_back(x);
    }

    {
        set<int> vs;
        for (int i = 1; i <= N; i++) {
            vs.insert(i);
        }
        vector<int> a;
        dfs(a, vs);
    }

    // for (auto &as : ass) {
    //     for (auto a : as) {
    //         printf("%d", a);
    //     }
    //     cout << endl;
    // }

    int x = find(p);
    int y = find(q);
    assert(x >= 0 && y >= 0);
    cout << abs(x - y) << endl;

    return 0;
}


Measured memory_bytes: 3384
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<string> S(N);
    map<char, ll> m;

    REP(i, N) {
        cin >> S.at(i);
        m[S[i][0]]++;
    }

    string march = "MARCH";
    ll ans = 0;
    REP(i, 5) {
        FOR(j, i + 1, 5) {
            FOR(k, j + 1, 5) { ans += m[march[i]] * m[march[j]] * m[march[k]]; }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6144