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

typedef long long ll;
#define mod 1000000007

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

void solve() {
    int n;
    cin>>n;
    vector<int> h(n);
    for(auto& e:h){
        cin>>e;
    }
    vector<int> dp(n+1);
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for(int i = 2; i < n; i++){
        dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
    }
    cout<<dp[n-1];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    // cin >> t;
    // pre();
    while (t--)
        solve();

    return 0;
}

Measured memory_bytes: 3972
#pragma comment (linker, "/STACK:256000000")
#define  _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()
void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(100);
}

#define int ll

void solve() {
	int a, b;
	cin >> a >> b;
	if (a > b) swap(a, b);
	REP(i, b) {
		cout << a;
	}
	cout << endl;
}

#undef int
int main() {
	init();
	solve();
}

Measured memory_bytes: 256
#include <stdio.h>
void bubbleSort(int A[] ,int N );
int main(){
  int i, j, A[100];

  scanf("%d",&i);
  for(j = 0; j < i; j++) scanf("%d",&A[j]);
  bubbleSort(A , i);
 
  return 0;
}

void bubbleSort(int A[] ,int N){
  int j, change, flag = 1, count = 0;
  while(flag == 1){
    flag = 0;
    for(j = N-1; j > 0; j--){
      if(A[j] < A[j-1]){
	change = A[j];
	A[j] = A[j-1];
	A[j-1] = change;
	flag = 1;
	count++;
      }
    }
  }
  for(j = 0; j < N; j++){
    printf("%d",A[j]);
    if(j != N-1) printf(" ");
  }
  printf("\n");
  printf("%d",count);
  printf("\n");
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define pb push_back
#define boostup ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long int ll;
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}
using namespace std;
double polyapothem(double n) 
{ 
  
    // Side and side length cannot be negative 
    // Degree converted to radians 
    return 1 / (2 * tan((180 / n) * 3.14159 / 180)); 
}
int main()
{
    boostup;
    ll n;
    cin>>n;
    ll d=n%10;
    if(d==2||d==4||d==5||d==7||d==9)
    {
        cout<<"hon"<<endl;
    }
    else if(d==0||d==1||d==6||d==8)
    {
        cout<<"pon"<<endl;
    }
    else if(d==3)
    {
        cout<<"bon"<<endl;
    }
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
//using namespace __gnu_pbds;
using namespace std;
typedef long long  L;

#define max_(x, y) (((x) > (y)) ? (x) : (y))
#define min_(x, y) (((x) < (y)) ? (x) : (y))
#define ___ ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Mx 10000001
#define inf 1e15
const L MOD = 1e9+7;
const double pi = 2 * acos (0.0);

/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/


//typedef tree<L,null_type,less<L>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

L a1,a2,a3,b1,b2,b3,c,c1,c2,c3,d,d1,d2,d3,d4,d5,e1,e2,e3,f,h,k,l,m,n,m1,m2,n1,n2,o,p,p1,p2,p3,p4,
q,q1,q2,q3,q4,r,s,t,u,v,x,y,z,sum,mx=-inf,mn=inf,flg,flg1,flg2,id,id1,id2,id3,id4,lim,from,to;
L A[Mx],B[Mx];
L ar[Mx];

void NOD(){
    ar[1]=1;
    for(L i=2;i<=Mx;i++){
        if(!ar[i]){
            ar[i]=2;
            for(L j=i+i;j<=Mx;j+=i){
                L n=j,c=0;
                if(!ar[j])ar[j]=1;
                while(!(n%i)){
                    c++;n/=i;
                }
                ar[j]*=(c+1);
            }
        }
    }
}
void preporcess(){
	NOD();
	ar[0]=0;
	for(L i=1;i<=1e7;i++){
		ar[i]=(i*ar[i])+ar[i-1];
		// if(i<10)cout<<ar[i]<<endl;
	}
}
int main()
{
	preporcess();
    scanf("%lld",&n);
    
    printf("%lld\n",ar[n]);
    return 0;
}

/// empty() lld I64d push_back() top() pop() insert() upper_bound() lower_bound() memset() max() min() scanf continue


Measured memory_bytes: 81896
#include<stdio.h>
#include<stdlib.h>
int inc(const void *a, const void *b)
{
	return *(int *)a-*(int *)b;
}
int main()
{
	int n,a[10000],l=0,r=1,m,cnt=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	qsort(a,n,sizeof(int),inc);
	m=2;
	for(int i=0;i<n-2;i++)
	{
		for(int j=i+1;j<n-1;j++)
		{
			for(int k=j+1;k<n;k++)
			{
				if(a[i]+a[j]>a[k])cnt++;
			}
		}
	}
	/*while(l<n-2)
	{
		if(m<=n-1&&a[l]+a[r]>a[m])
		{
			cnt++;
			m++;
		}
		else
		{
			r++;
			m=r+1;
		}
		if(r==n-1)
		{
			l++;
			r=l+1;
			m=r+1;
		}
	}*/
	printf("%d\n",cnt);
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC080A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n,a,b,x;
            var word = Console.ReadLine().Split(' ');
            n = int.Parse(word[0]);
            a = int.Parse(word[1]);
            b = int.Parse(word[2]);
            if (n * a > b) 
            {
                Console.WriteLine(b);
            }
            else
            {
                Console.WriteLine(n * a);
            }
            Console.ReadKey();


        }
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef long long LL;
typedef pair<int,int> pa;
typedef vector<int> vec;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
bool v[500010];
int nedge,too[500010],hed[500010],x[500010],y[500010],nxt[500010],n,m,d[500010],d4,A,B;
void ae(int x,int y){
	nxt[++nedge]=hed[x];
	hed[x]=nedge;
	too[nedge]=y;
}
void dfs(int x){
	v[x]=1;
	for (int i=hed[x];i;i=nxt[i]){
		int y=too[i];
		if (y==B || v[y]) continue;
		dfs(y);
	}
}
int main(){
	cin>>n>>m;
	if (n==1) return puts("No"),0;
	FOR(i,1,m){
		getint(x[i]),getint(y[i]);
		++d[x[i]],++d[y[i]];
		ae(x[i],y[i]),ae(y[i],x[i]);
	}
	FOR(i,1,n) if (d[i]&1) return puts("No"),0;
	FOR(i,1,n) if (d[i]>=6) return puts("Yes"),0;
	FOR(i,1,n) if (d[i]>=4) ++d4;
	if (d4>=3) return puts("Yes"),0;
	if (d4<=1) return puts("No"),0;
	FOR(i,1,n) if (d[i]==4) A=i;
	FOR(i,1,n) if (d[i]==4 && i!=A) B=i;
	dfs(A);
	for (int i=hed[B];i;i=nxt[i]){
		int y=too[i];
		if (!v[y]) return puts("Yes"),0;
	}
	puts("No");
	return 0;
}
//神仙猜结论题打不过告辞

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

int N;
vector<int> A;
vector<vector<int> > adj;

bool dfs(int u, int p, int first) {
    bool ret = false;
    for(int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i];
        if(v == p) continue;
        if(A[v] <= A[u] - 1) ret |= dfs(v, u, first ^ 1) ^ 1;
    }
    return ret;
}
int main() {
    scanf("%d", &N);
    A.resize(N);
    for(int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }
    adj.resize(N);
    for(int i = 0; i < N - 1; i++) {
        int u, v; scanf("%d %d", &u, &v);
        u--; v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(int i = 0; i < N; i++) {
        if(dfs(i, -1, 1)) printf("%d ", i + 1);
    }
}


Measured memory_bytes: 384
n = int(input())
d, x = map(int, input().split())
an = []
for i in range(n):
  an.append(int(input()))

choco = []
for i in range(n):
  j = 0
  count = 0
  while(True):
    if 1+an[i]*j <= d:
      count += 1
      j += 1
    else :
      choco.append(count)
      break
      
choco.append(x)
      
print(sum(choco))

Measured memory_bytes: 9080
import java.io.IOException;

public class Main {

	public static void main(String[] args) {
		int n = nextInt();
		for (int i = 0; i < n; i++) {
			int y = nextInt();// 年
			int m = nextInt();// 月
			int d = nextInt();// 日

			int all = 195 * 999 + 333 * 5;// 1年1月1日生まれの人の日数
			int days = (y - 1) * 195 + (m - 1) * 19 + (d - 1);// 1年1月1日から何日経った時に生まれたか
			days += Math.round(m / 2);// 大の月の20日目を足す
			days += Math.round((y - 1) / 3) * 5;
			if (y % 3 == 0) {
				// 3の倍数年だった時、小の月の分も足す
				days += Math.round((m - 1) / 2);// 大の月の20日目を足す
			}

			System.out.println(all - days);
		}

	}

	static int nextInt() {
		int c;
		try {
			c = System.in.read();
			while (c != '-' && (c < '0' || c > '9'))
				c = System.in.read();
			if (c == '-')
				return -nextInt();
			int res = 0;
			while (c >= '0' && c <= '9') {
				res = res * 10 + c - '0';
				c = System.in.read();
			}
			return res;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return -1;
	}

}

Measured memory_bytes: 17012
def solve(A):
    n = A[-1]
    is_nodiv = [True] * (n+1)

    pre = 0
    for a in A:
        if pre == a or not is_nodiv[a]:
            is_nodiv[a] = False
            continue

        for j in range(2*a, n+1, a):
            is_nodiv[j] = False
        
        pre = a

    return sum([is_nodiv[a] for a in A])



def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    ans = solve(A)
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 32208
#include<stdio.h>
int main(void)
{
	char print;
	int num;
	int tramp[52] = { 0 };//トランプがあるか
	int sheet = 0;
	scanf("%d",&sheet);
	for (int i = 0; i < sheet; i++)
	{
		scanf("%s",&print);
		if (print == 'S')
		{
			scanf("%d",&num);
			tramp[num - 1] = 1;
		}
		else if (print == 'H')
		{
				scanf("%d", &num);
				tramp[num - 1 + 13] = 1;
		}else if (print == 'C')
		{
			scanf("%d", &num);
			tramp[num - 1 + 26] = 1;
		}else if (print == 'D')
		{
			scanf("%d", &num);
			tramp[num - 1 + 39] = 1;
		}
		else
		{
			break;
		}
	}
	for (int i = 0; i < 52; i++)
	{
		if (tramp[i] == 0)
		{
			if (i < 13)
			{
				printf("S %d\n", i + 1);
			}
			else if (i < 26)
			{
				printf("H %d\n", i - 12);
			}
			else if (i < 39)
			{
				printf("C %d\n", i - 25);
			}
			else
			{
				printf("D %d\n", i - 38);
			}
		}
	}
	return 0;
}


Measured memory_bytes: 2680
s = input()
q =int(input())
ten = 0
r = []
l = []
for _ in range(q):
    ls = tuple(map(str, input().split()))
    if len(ls)==1:
       ten +=1
    else:
        if ls[1] =='1':
            if ten%2 ==0:
                l.append(ls[2])
            else:
                r.append(ls[2])
        else:
            if ten%2 ==1:
                l.append(ls[2])
            else:
                r.append(ls[2])
s = ''.join(reversed(l))+s+''.join(r)
if ten%2 ==1:
    s = s[::-1]
print(s)

Measured memory_bytes: 100728
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {Main instance = new Main();sc = instance.new Scanner();instance.solve();}
    private class Scanner {String[] s = new String[0];String regex = " ";int i = 0;BufferedReader br = new BufferedReader(new InputStreamReader(System.in));public String next() {try {if (i < s.length) { return s[i++];}String st = br.readLine();while ("".equals(st)) { st = br.readLine(); }s = st.split(regex, 0);i = 0;return s[i++];} catch (IOException e) { return null; }}public int nextInt(){return Integer.parseInt(next());}}        
    private static Scanner sc;

    private void solve() {
        System.out.println(sc.nextInt()/3);
    }
}

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

int main() {
	int n;
	cin >> n;
	vector<ll>prime(n+1,2);
	prime.at(0) = 0;
	prime.at(1) = 1;
	for (int i = 2; i <= n; i++) {
		ll x = i * 2;
		while (x <= n) {
			prime.at(x)++;
			x += i;
		}
	}
	ll ans = 0;
	for (int i = 1; i < n + 1; i++)ans += i * prime.at(i);
	cout << ans << endl;
}

Measured memory_bytes: 81396
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

int main(){
    int n,c;
    cin >> n >> c;
    int d[c][c];
    for(int i = 0; i < c; i++){
        for(int j = 0; j < c; j++){
            cin >> d[i][j];
        }
    }
    int bd[n][n];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin >> bd[i][j];
        }
    }
    map<int,int> mp[3];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            mp[(i+j+2)%3][bd[i][j]]++;
        }
    }
    ll ans = mod*mod;
    for(int i = 0; i < c; i++){
        for(int j = 0; j < c; j++){
            if(i == j) continue;
            for(int k = 0; k < c; k++){
                if(i == k || j == k) continue;
                ll can = 0;
                for(auto p : mp[0]){
                    can += p.second*d[p.first-1][i];
                }
                for(auto p : mp[1]){
                    can += p.second*d[p.first-1][j];
                }
                for(auto p : mp[2]){
                    can += p.second*d[p.first-1][k];
                }
                if(ans > can){
                    ans = can;
                    //cout << ans << endl;
                    //cout << i << " " << j << " " << k << endl;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4580
#include <bits/stdc++.h>
#define LL long long

using namespace std;

template<typename tp> inline void read(tp &x) {
	x = 0; register char c = getchar(); register bool f = 0;
	for (; c < '0' || c > '9'; f |= (c == '-'), c = getchar());
	for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
	if (f) x = -x;
}

int main() {
    long long n;
    scanf("%lld",&n);
    int q = sqrt(n);
    int max = 0;
    for(int i = 1; i <= q; ++i) {
        if (n % i == 0) {
        max = i;
        }
    }
    printf("%lld",max + n / max - 2);
    return 0;
}

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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;

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

constexpr long long mod = 1000000007;

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

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

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

    bool b = false;

    for (int i = 0; i <= n; i++) {
        int cnt1 = 0;
        cnt1 += m * i;
        for (int j = 0; j <= m; j++) {
            int cnt2 = cnt1;
            cnt2 += (n - i) * j;
            cnt2 -= i * j;

            if (cnt2 == k) {
                b = true;
            }
        }
    }

    if(b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        sc.close();
        boolean ans = false;
        String k = "keyence";
        int diff = s.length() -7;
        for(int i = 0; i <= s.length() -diff; i++){
            if(i == 0){
                if(k.equals(s.substring(diff))) ans = true;
            }else if(i == s.length() -diff){
                if(k.equals(s.substring(0, s.length() -diff))) ans = true;
            }else{
                if(k.equals(s.substring(0, i) + s.substring(i+diff, s.length()))) ans = true;
            }
        }
        if(ans) System.out.println("YES");
        else System.out.println("NO");

    }

}


Measured memory_bytes: 22992
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
//E-Knapsack2
/*
    I ♥ CLARICE STARLING

    EXPLAINATION BELOW->
    Dp + small trick
      
    Observation:->
    Clue Knapsack1- 1≤W≤10^5 and 1≤vi≤10^9
    Clue Knapsack2- 1≤W≤10^9 and 1≤vi≤10^3
    
    In Knapsack1 
    Our dp state was dp[i][j] where i means starting from i we take into consideration all elements,j indicates that max capacity is j
    and dp[i][j] == max(⅀ v) possible
    but this would fail due to MLE as well TLE as max(W)=1e9
    
    In knapsack2
    kmax=1e3 and Nmax=100 so max possible value that can be obtained is 1e5;
    So we can phrase our dp[i][j] such that
    where i means starting from i we take into consideration all elements,j indicates that  ⅀value limit is j
    and dp[i][j] == min(⅀ w) possible
     * 
    So now our ans is max (possible) j for which ⅀weight is <=W;
    We here implement using Errichto's technique;
*/
//
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(x) x.begin(),x.end()
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
const ll INF=(ll)1e18+5;
void solve()
{
    int n,W,i,sum_value=0,value_already;cin>>n>>W;
    vector<int>w(n),v(n);
    fo(i,0,n)cin>>w[i]>>v[i],sum_value+=v[i];
    
    vector<ll>dp(sum_value+1,INF);
    dp[0]=0;
    fo(i,0,n)
    {
        for(value_already=sum_value-v[i];value_already>=0;value_already--)
        dp[value_already+v[i]]=min(dp[value_already+v[i]],w[i]+dp[value_already]);
    }
    ll ans=0;
    foe(i,0,sum_value)if(dp[i]<=W)ans=(ll)i;
    
    cout<<ans<<"\n";
}
int main()
{
   fastio
   solve();
  return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second

using namespace std;

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


int main(){
    int h, a;
    cin >> h >> a;
    cout << (h + a - 1) / a << endl;

    return 0;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    H = [int(x) for x in input().split()]
    max_move_num = 0
    move_num = 0
    for idx in range(N-1):
        if H[idx] >= H[idx+1]:
            move_num += 1
        else:
            max_move_num = max(max_move_num, move_num)
            move_num = 0
    max_move_num = max(max_move_num, move_num)
    print(max_move_num)


if __name__ == "__main__":
    main()


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


int main()
{
	ll n,w;
	cin>>n>>w;
	ll val[n];
	ll wt[n];
	ll i,j;

	for(i=0;i<n;i++)
	{
		cin>>wt[i]>>val[i];
	}
	vector < vector <ll> > dp(n+1, vector <ll> (100001,1000000000000000));  //n+1 dp's, each denoting choice at ith option

	dp[0][0]=0;
	for(i=1;i<=n;i++)
	{
		// if j=0 se chalu nhi karna toh 0th column pura 0 se initialize karo
		for(j=0;j<=100000;j++)
		{
			dp[i][j]=dp[i-1][j];
			if(j-val[i-1]>=0)
			{
				dp[i][j]=min(dp[i][j],wt[i-1]+dp[i-1][j-val[i-1]]);
			}
		}
	}
	ll ans=0;
	for(i=1;i<=100000;i++)	
	{
		if(dp[n][i]<=w)
			ans=i;
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 80256
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;

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

const ll INF = 1000000000000000;

struct edge{int to; ll cost;};

// Union_Find ????£???????????????§???????????£????????????

int par[100000],rnk[100000];

void init(int n){
	for(int i=0;i<n;i++){
		par[i] = i;
		rnk[i] = 0;
	}
}
int find(int x){
	if(par[x]==x) return x;
	else return par[x] = find(par[x]);
}
bool same(int x,int y){
	return find(x) == find(y);
}
void unite(int x,int y){
	x = find(x); y = find(y);
	if(x==y) return;
	if(rnk[x]>rnk[y]){
		par[y] = x;
	}else if(rnk[x]<rnk[y]){
		par[x] = y;
	}else{
		par[x] = y;
		rnk[y]++;
	}
}


int main(){
	int n,m,c;
	ll all = 0;
	pli dist[100000];
	vector<edge> G[100000];
	scanf("%d %d %d",&n,&m,&c);
	for(int i=0;i<m;i++){
		int a,b,d;
		scanf("%d %d %d",&a,&b,&d);
		a--; b--;
		edge e;
		e.cost = d;
		e.to = b;
		G[a].push_back(e);
		e.to = a;
		G[b].push_back(e);
		all += d;
	}
	for(int i=0;i<n;i++) dist[i] = pli(INF,i);
	dist[0].first = 0;
	priority_queue<pli,vector<pli>,greater<pli> > q;
	q.push(pli(0,0));
	while(!q.empty()){
		int v = q.top().second;
		ll cost = q.top().first;
		q.pop();
		if(dist[v].first<cost) continue;
		for(int i=0;i<G[v].size();i++){
			int nv = G[v][i].to;
			if(dist[nv].first>dist[v].first+G[v][i].cost){
				dist[nv].first = dist[v].first + G[v][i].cost;
				q.push(pli(dist[nv].first,nv));
			}
		}
	}
	sort(dist,dist+n);
	ll ans = 0, deleted = 0;
	init(n);
	for(int i=0;i<n;i++){
		if(dist[i].first==INF) break;
		int v = dist[i].second;
		unite(0,v);
		for(int j=0;j<G[v].size();j++){
			if(same(v,G[v][j].to)){
				deleted += G[v][j].cost;
			}
		}
		if(i==n-1||dist[i+1].first!=dist[i].first){
			ll x = dist[i].first;
			ans = min(ans,c*x-deleted);
		}
	}
	ans += all;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 18412
#include<iostream>
#include<algorithm>
using namespace std;
#define F(i,s,e) for(int i=s;i<e;++i)

int main(){
    int h,n;
    cin >> h >> n;
    int a;
    F(i,0,n){
        cin >> a;
        h-=a;
        if(h<=0){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    char a, b;
    scanf("%c %c", &a, &b);

    char c;
    if (a == 'H') {
        if (b == 'H') {
            c = 'H';
        } else {
            c = 'D';
        }
    } else { // D
        if (b == 'H') {
            c = 'D';
        } else {
            c = 'H';
        }
    }

    printf("%c\n", c);
    return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int  long long int
#define pb push_back
#define fe first
#define lb lower_bound 
#define ub upper_bound
#define pii pair<pair<int,int>,pair<int,int> >
#define se second
#define endl "\n"
#define pi pair<int, int>
#define mi          map<int,int>
#define mii         map<pi,int>
#define vi vector<int> 
#define vvi vector<vi>
#define bs   binary_search
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)	
#define all(c) (c).begin(),(c).end()
#define sz(x)       (int)x.size() 
#define PI 3.14159265358979323846

 const int N=2e5+5;

 int mod= 1e9+7;
 int dx[4]={0,0,+1,-1};
 int dy[4]={+1,-1,0,0};  
 
 
int po(int a, int b) {
	a %= mod;
	int res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a) % mod;
		a =(a*a) % mod;
		b >>= 1;
	}
	 return res;	
   }


void solve() {
     int k;
     cin>>k;
     if(k%2==0) {
		    cout<<-1<<endl;
		    return;
		 }	 
	 int ml=0;
	 rep(i,0,1e6+1) {
		   ml=ml*10+7;
		   ml%=k;
		   if(ml==0) {
			     cout<<i+1<<endl;
			     return;
			   }
		 }		 
	cout<<-1<<endl;	         
}

    
int32_t main() {
	cool;
	int t=1;	

	//cin>>t;
	while(t--)
	  solve();

  return 0;	   
}


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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf=1010001000;
const ll  INF=1001000100010001000;
const int mod=(int)1e9+7;

ll gcd(ll p, ll q){ 
    while(q != 0){
        ll r=p%q;
        p=q;
        q=r;
    }
    return p;
}

int main(){
    ll n,a,b,c,d,e;
    cin>>n>>a>>b>>c>>d>>e;
    ll bn=min(e,min(d,min(c,min(a,b))));
    if(bn>=n){
        cout<<5<<endl;
        return 0;
    }
    cout<<(n+(bn-1))/bn+4<<endl;
return 0;
}


Measured memory_bytes: 256
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
ns = [[] for _ in range(n)]
for i in range(n-1):
    u,v = map(int, input().split())
    u -= 1
    v -= 1
    ns[u].append(v)
    ns[v].append(u)

d1 = [None]*n
d2 = [None]*n
M = 10**9+7
def sub(u, p):
    if d1[u] is not None:
        return d1[u], d2[u]
    v1 = 1 # 白
    v2 = 1 # 黒
    for v in ns[u]:
        if v==p:
            continue
        w1, w2 = sub(v, u)
        v1 *= (w1+w2)
        v2 *= w1
        v1 %= M
        v2 %= M
    d1[u] = v1
    d2[u] = v2
    return v1, v2
sub(0, -1)
print((d1[0]+d2[0])%M)

Measured memory_bytes: 947952
#include<bits/stdc++.h>
using namespace std;
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    long long sum=0,m;
    cin>>n;
    vector<long long> a(n),cs(n+1);
    cs[0]=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        cs[i+1]=a[i]+cs[i];
        sum+=a[i];
    }
    m=sum;
    for(int i=1;i<n;i++){
        if(abs(sum-2*cs[i])<m){
            m=abs(sum-2*cs[i]);
        }
    }
    cout<<m;
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
#define reps(i,n) for(ll i=1;i<=(n);++i)
using ll = long long;
using str = string;
constexpr long long INF = (1LL<<60);
constexpr long long MOD = (1e9+7);
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>inline void dump(Head&& head, Tail&&... tail){cout<<head<<", ";dump(forward<Tail>(tail)...);}
template<typename T>inline istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}

main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout<<fixed<<setprecision(10);

  ll a,b;
  cin>>a>>b;
  b*=2;
  a-=b;
  cout<<(max(0ll,a))<<endl;


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define eb emplace_back
#define ll long long
#define nl '\n'
#define in() ( { int a ; scanf("%d",&a); a; } )
 
const int N = 3e5 + 9;
const int mod = 1e9 + 7;
//int dx[]={1,0,-1,0,1,-1,-1,1};
//int dy[]={0,1,0,-1,1,1,-1,-1};

map<string, ll>mp;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    ll n, i;
    string s;
    cin >> n;
    for(i = 0; i < n; i++){
        cin >> s;
        mp[s]++;
    }
    cout << "AC x " << mp["AC"] << nl;
    cout << "WA x " << mp["WA"] << nl;
    cout << "TLE x " << mp["TLE"] << nl;
    cout << "RE x " << mp["RE"] << nl;
}

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

int main() {
  int n, d;
  cin >> n >> d;
  
  int count =  0;
  int ans = 0;
  
  while(count < n) {
    count += 2 * d + 1;
    ans++;
  }
  
  cout << ans << endl;
}

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

int getsum (int x){
  int sum = 0;
  for(;;){
    if (x == 0) return sum;
    else{
      sum += x % 10;
      x /= 10;
    }
  }
}

int main(){
  int N,mini = INT_MAX;
  cin >> N;
  for (int i = 1; i < N;i++){
    mini = min(getsum(i) + getsum(N-i),mini);
  }
  cout << mini << endl;
}

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

int main() {
  int N, X;
  cin >> N >> X;
  int ans = N;
  int min = 10000;
  for (int i = 0; i < N; i++) {
    int m;
    cin >> m;
    X -= m;
    if (m < min) {
      min = m;
    }
  }
  ans += X / min;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"

using namespace std;

//constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;



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

	cin >> N;
	string s;
	cin >> s;
	vector<int>r;
	vector<int>g;
	vector<int>b;
	for (int i = 0; i < N * 3; i++) {
		if (s[i] == 'R')r.push_back(i);
		if (s[i] == 'G')g.push_back(i);
		if (s[i] == 'B')b.push_back(i);
	}
	vector<int>a(N);
	vector<int>c(N);
	vector<int>box(N);
	for (int i = 0; i < N; i++) {
		a[i] = min({ r[i],g[i],b[i] });
		c[i] = max({ r[i],g[i],b[i] });
		box[i] = r[i] + b[i] + g[i] - a[i] - c[i];
	}
	long long int ans = 1;
	for (int i = 1; i <= N; i++) {
		ans *= i;
		ans %= MOD;
	}
	int index = 0;
	for (int i = 0; i < N; i++) {
		while (index < N&&a[index] < box[i])index++;
		ans *= index - i;
		ans %= MOD;
	}
	reverse(box.begin(), box.end());
	reverse(c.begin(), c.end());
	index = 0;

	for (int i = 0; i < N; i++) {
		while (index<N&&c[index]>box[i])index++;
		ans *= index - i;
		ans %= MOD;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3088
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define ll long long
#define pb(x) push_back(x)
#define pr(x) cerr<<#x<<"="<<(x)<<endl
#define pri(x,lo) {cerr<<#x<<"={";for (int ol=0;ol<=lo;ol++)cerr<<x[ol]<<",";cerr<<"}"<<endl;}
#define N 1000
#define md 1000000007
int n,m,k,dp[2000010],sta,id,o,p,q,go[2000010][23],put[2000010],need1[30],need2[30],i,ans;
void add(int &x,int y){x+=y;if (x>md) x-=md;}
int main()
{
	scanf("%d %d %d",&n,&m,&k);n--;
	for (i=1;i<=k;i++)
	{
		scanf("%d %d %d",&o,&p,&q);o--;p--;
		need1[o]|=(1<<p);
		need2[o]|=(1<<p)*q;
	}
	memset(go,-1,sizeof(go));
	for (sta=0;sta<(1<<n);sta++)
	{
		id=0;
		for (i=0;i<n;i++)
			if (sta&(1<<i))
			{
				if (i>0&&!(sta&(1<<(i-1)))) go[sta][id]=sta^(1<<i)^(1<<(i-1));
				id++;
			}
	}
	memset(put,-1,sizeof(put));
	for (sta=0;sta<(1<<n);sta++)
		for (i=n-1;i>=0;i--)
			if ((sta&(1<<i))==0){put[sta]=sta^(1<<i);break;}
	dp[0]=1;
	for (i=0;i<m;i++)
	{
		for (sta=0;sta<(1<<n)-1;sta++)  add(dp[put[sta]],dp[sta]);
		for (int id=0;id<n;id++)
			for (int sta=(1<<n)-1;sta>=0;sta--)
			if (go[sta][id]!=-1) add(dp[go[sta][id]],dp[sta]);
		for (sta=0;sta<(1<<n);sta++) if ((sta&need1[i])!=need2[i]) dp[sta]=0;
	}
	for (sta=0;sta<(1<<n);sta++) add(ans,dp[sta]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 190848
use std::io::stdin;
use std::str::FromStr;

fn main(){
    let (_, x): (i64, i64) = get_pair();
    let ls: Vec<i64> = get_vec();
    let mut ans = 1;
    let mut d = 0;
    for &l in ls.iter() {
        if d + l > x { break; }
        d += l;
        ans += 1
    }
    println!("{}", ans);
}

#[allow(dead_code)]
fn get_line() -> String {
    let mut s = String::new();
    match stdin().read_line(&mut s){
        Ok(_) => {s.trim().to_string()}
        Err(_) => String::new()
    }
}

#[allow(dead_code)]
fn get_vec<T: std::str::FromStr>() -> Vec<T> {
    let line = get_line();
    line.split_whitespace().filter_map(|x| x.parse().ok()).collect()
}

#[allow(dead_code)]
fn get_one<T: FromStr + Copy>() -> T {
    let v = get_vec();
    v[0]
}

#[allow(dead_code)]
fn get_pair<T: FromStr + Copy>() -> (T, T) {
    let v = get_vec();
    (v[0], v[1])
}

#[allow(dead_code)]
fn get_triple<T: FromStr + Copy>() -> (T, T, T) {
    let v = get_vec();
    (v[0], v[1], v[2])
}

#[allow(dead_code)]
fn get_chars() -> Vec<char> {
    get_line().chars().collect()
}

#[allow(dead_code)]
fn vec_min(xs: &Vec<i64>) -> i64 {
    xs.iter().map(|&x|x).fold(std::i64::MAX, std::cmp::min)
}

#[allow(dead_code)]
fn vec_max(xs: &Vec<i64>) -> i64 {
    xs.iter().map(|&x|x).fold(std::i64::MIN, std::cmp::max)
}

#[allow(dead_code)]
fn vec_sum(xs: &Vec<i64>) -> i64 {
    xs.iter().fold(0, |acc, &x| acc+x)
}


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

using namespace std;

int main() {
  int n = 0;
  cin >> n;
  set<int> s;
  for (int i = 0; i < n; ++i) {
    int tmp = 0;
    cin >> tmp;
    s.insert(tmp);
  }
  printf("%lu\n", s.size());
}

Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;

typedef long long ll;

int
main(int argc, char *argv[])
{
  int a, b;
  cin >> a >> b;
  cout << max(a - 2 * b, 0) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int N; cin >> N;
    vector<int> A(N);
    REP(i, 0, N) cin >> A[i];

    vector<int> B;
    REP(i, 0, N) {
        if (i % 2 == 0) {
            B.insert(B.end(), A[i]);
        } else {
            B.insert(B.begin(), A[i]);
        }
    }

    if ((N - 1) % 2 == 0) {
        for (int i = B.size() - 1; i >= 0; i--) {
            cout << B[i];
            if (i != 0) cout << " ";
        }
        cout << endl;
    } else {
        for (int i = 0; i < B.size(); i++) {
            cout << B[i];
            if (i != B.size() - 1) cout << " ";
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3828
#include<iostream>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a==1&&b==0&&c==0||a==0&&b==1&&c==0||a==0&&b==0&&c==0){
		cout<<"Close"<<endl;
	}else if(a==1&&b==1&&c==0||a==0&&b==0&&c==1){
		cout<<"Open"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
double a,b,c,x,maxc;
int main(){
    cin>>x;
    if(x==1){cout<<1<<endl;return 0;}
    for(double i=2;i<x;i++){
        double u=2;
        while(1){
            if(pow(i,u)>x)break;
            double ah=pow(i,u);
            maxc=max(maxc,ah);
            u++;
        }
    }
    cout<<maxc<<endl;
}


Measured memory_bytes: 256
a = input()
n = len(a)
cnt = [0]*(ord('z')-ord('a')+1)


res = 0
for s in a:
    idx = ord(s) - ord('a')
    res += cnt[idx]
    cnt[idx]+= 1
ans = (n*(n-1)/2)-res+1
print(int(ans))

Measured memory_bytes: 3500
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long Int;

void go(string ans, string str){
  int n = str.size() / 2;
  for(int i = 1;i <= n;i++){
    char nxt = ans[i-1];
    if(str[i] == 'x'){
      nxt = (char)((int)'W' + (int)'S' - (int)nxt);
    }
    if(ans[i] == 'W'){
      nxt = (char)((int)'W' + (int)'S' - (int)nxt);
    }
    ans += nxt;
  }
  if(ans[0] != ans[n] || ans[1] != ans[n+1])return;
  for(int i = 0;i < n;i++)cout << ans[i];
  cout << endl;
  exit(0);
}

int main(){
  int n;
  string str;
  cin >> n;
  cin >> str;
  str += str;
  go("SS", str);
  go("SW", str);
  go("WS", str);
  go("WW", str);
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 972
#include<stdio.h>
#include<string.h>
int main(void)
{	
	int n,x,y,a,b,c,d;
	scanf("%d",&n);
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	scanf("%d",&d);
	x=n/a*b;
	y=n/c*d;
	if(n%a>0){
		x=x+b;
	}
	if(n%c>0){
		y=y+d;
	}
	if(x<y){
		printf("%d\n",x);
	}
	else{
		printf("%d\n",y);
	}
	
	return 0;
}


Measured memory_bytes: 2736
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};
//fixed << setprecision(2)
bool  Array_check(ll y, ll x,ll d,ll w) {
	if (x < 0 || x >= w || y<0 || y>=d) {
		return false;
	}
	else {
		return true;
	}
	
}

//小文字=大文字+32

int main() {
	ll r, d, x;
	cin >> r >> d >> x;
	rep(i, 10) {
		x = r * x - d;
		cout << x<<endl;
	}
}
	



Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define gc getchar()
using namespace std;
typedef long long ll;
const int N=100009;
int n;
ll X[N],P[N],S;
int read()
{
	int x=1;
	char ch;
	while (ch=gc,ch<'0'||ch>'9') if (ch=='-') x=-1;
	int s=ch-'0';
	while (ch=gc,ch>='0'&&ch<='9') s=s*10+ch-'0';
	return s*x;
}
int main()
{
	n=read(),S=read();
	for (int i=1;i<=n;i++) X[i]=read(),P[i]=read();
	int l=1,r=n,last=0;
	ll ret=0;
	for (;;)
	{
		if (X[l]>=S)
		{
			ret+=X[r]-S;
			break;
		}
		if (X[r]<=S)
		{
			ret+=S-X[l];
			break;
		}
		if (P[l]>=P[r])
		{
			if (last!=1)
			{
				last=1;
				ret+=X[r]-X[l];
			}
			P[l]+=P[r];
			r--;
		}
		else
		{
			if (last!=2)
			{
				last=2;
				ret+=X[r]-X[l];
			}
			P[r]+=P[l];
			l++;
		}
	}
	printf("%lld\n",ret);
	return 0;
}


Measured memory_bytes: 1792
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
#define out(args...){vector<string> a_r_g_s=s_p_l_i_t(#args, ','); e_r_r(a_r_g_s.begin(), args); }
vector<string> s_p_l_i_t(const string &s, char c){vector<string> v;int d=0,f=0;string t;for(char c:s){if(!d&&c==',')v.pb(t),t="";else t+=c;if(c=='\"'||c=='\'')f^=1;if(!f&&c=='(')++d;if(!f&&c==')')--d;}v.pb(t);return move(v);}
void e_r_r(vector<string>::iterator it) {}
template<typename T, typename... Args> void e_r_r(vector<string>::iterator it, T a, Args... args){ if(*it==" 1"||*it=="1") cerr<<endl; else cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; e_r_r(++it, args...);}
const ll MOD=1e9+7;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n,t;
  cin>>n>>t;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  int g=0;
  for(int x:a) g=__gcd(x,g);
  //out(g,1);
  int f=0;
  for(int x:a){
    if(x>=t && (x-t)%g==0)
      f=1;
  }
  cout<<(f?"POSSIBLE":"IMPOSSIBLE")<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>

using namespace std;

#define ll long long

void solve()
{
    ll A, B, C;
    cin >> A >> B >> C;

    cout << max(C - (A - B), (ll)0) << endl;
    return;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
a = list(map(int,input().split()))

for i in range(k):
    table = [0 for _ in range(n*2)]
    # imos法
    for j in range(n):
        ai = a[j]
        # 電球が照らす左端
        table[max((j-ai)*2-1,0)] += 1
        # 電球が照らす右端
        table[min((j+ai)*2+1,n*2-1)] -= 1
    # 累積和
    for j in range(n*2):
        if j > 0:
            table[j] += table[j-1]
    for j in range(n):
        a[j] = table[j*2]
    flag = True
    for j in range(n):
        if a[j] != n:
            flag = False
            break
    if flag:
        print(*a)
        exit()
print(*a)

Measured memory_bytes: 191292
#include <iostream>
#include <set>
#include <cmath>
using namespace std;

int n, a[100000];

int main()
{
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    int cnt = a[0];
    for (int i = 1; i < n; ++i)
        cnt += pow(-1, i) * a[i];
    cout << cnt << " ";
    for (int i = 1; i < n; ++i)
        cout << (cnt = 2 * a[i - 1] - cnt) << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 1664
import java.util.Random;
import java.util.Scanner;

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

        int n;
        while (true) {
            n = scanner.nextInt();
            if (n == 0) break;

            int sum = 0, sum2 = 0;
            for (int i = 0; i < n; ++i) {
                int a = scanner.nextInt();
                sum += a;
                sum2 += a * a;
            }

            System.out.println(Math.sqrt(sum2 / (double)n - Math.pow((sum / (double)n), 2)));
        }
    }
}


Measured memory_bytes: 31348
import java.util.Scanner;
import java.util.Arrays;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int x=1,y=1;
        while(x != 0 || y != 0){
            y = sc.nextInt();
            x = sc.nextInt();
            if (x == 0 && y == 0) break;
            for(int i=0;i<y;i++){
                for(int j=0;j<x;j++){
                    System.out.print('#');
                }
                System.out.println();
            }
            System.out.println();
        }
        
        sc.close();
    }
}



Measured memory_bytes: 36748
# AGC005A - STring
def main():
    X = input().rstrip()
    ans, p = 0, 0  # pair
    for i in X:
        if i == "S":
            p += 1
        else:
            if p:
                p -= 1
            else:
                ans += 1  # remaining T
    ans += p  # add remaining S
    print(ans)


if __name__ == "__main__":
    main()

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N+1);
  vector<int> B(N+1);
  for(int i=1;i<=N;i++){
    cin >> A.at(i);
    B.at(A.at(i))=i;
  }
  for(int i=1;i<=N;i++) cout << B.at(i) << " ";
}

Measured memory_bytes: 1536
#include <iostream>
#include <cmath>
#include <vector>
#include <cstdlib>
#include <algorithm>

using namespace std;


long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}


long long int bikkuri(int x,int y) {
    long long int temp = 1;
    for (int i = x; i < y + 1; i++) {
        temp *= i;
        if (temp >= 1000000007) {
            temp = temp % 1000000007;
        }
    }
    return temp;
}

long long int my_c(int x,int y) {
    long long int temp;
    temp = bikkuri(x - y + 1, x) * modinv(bikkuri(1, y), 1000000007);
    if (temp >= 1000000007) {
        temp = temp % 1000000007;
    }
    return temp;
}

int main() {
    int n, k;
    cin >> n >> k;
    long long int ans;
    for (int i = 0; i < k; i++) {
        ans = my_c(k - 1, i) * my_c(n - k + 1, i + 1);
        if (ans >= 1000000007) {
            ans = ans % 1000000007;
        }
        cout << ans << endl;
    }

    
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
#define rep(i,x,n) for(int i=x; i<n; i++)
#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> inline bool chmin(T &a, T b){if(a>b){a=b; return true;}return false;}

int main(){
  ll k,a;
  cin >> k;
  queue<ll> lun;
  rep(i,1,10){
    lun.push(i);
  }
  rep(i,0,k){
    a= lun.front();
    lun.pop();
    if(a%10!=0){
      lun.push(10*a+(a%10)-1);
    }
    lun.push(10*a+(a%10));
    if(a%10!=9){
      lun.push(10*a+(a%10)+1);
    }
  }
  cout << a << endl;
  
}


Measured memory_bytes: 1792