akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x,long long int y) 
{ 
    long long int res = 1;     // Initialize result 
  // x=x;
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x); 
   
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x);  // Change x to x^2 
    } 
    return res; 
}
long long int power(long long int x,long long int y,long long int m) 
{ 
    long long int res = 1;     // Initialize result 
   x=x%m;
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x)%m; 
   
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x)%m;  // Change x to x^2 
    } 
    return res; 
}

long long int gcd(long long int a, long long int b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
 } 
 long long int lcm(long long int a, long long int b)  
 { 
     long long int temp;
    
    return (a*b)/gcd(a, b);  
 }
 
int main() {
        long long int t=0,b[1000000]={0};
        string c;
        string s;
       long long int n,m,o=0,l,d=0,i,j,p=0,k,f;
       double pie=3.141592653589793238;
    long long int MOD=1000000007;
    cin>>n>>k;
    
    if(k>n)
    {
        for(i=0;i<k;i++)
        cout<<n;
    }
    else
    {
        for(i=0;i<n;i++)
        cout<<k;
        
    }
    //cout<<P;
 return 0;
}

Measured memory_bytes: 256
import numpy as np

n, k, q = map(int, input().split())
Ans = [int(input()) for i in range(q)]
L = np.array([int(k-q) for i in range(n)], dtype=int)

for i in range(q):
  L[Ans[i]-1] += 1
L = L > 0

for i in range(n):
  if L[i] == False:
    print("No")
  else:
    print("Yes")

Measured memory_bytes: 21092
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<math.h>

using namespace std;


int main()
{
	
	int X, Y;
	cin >> X >> Y;
	
	int a, b;
	
	if(Y % 2 != 0){
		cout << "No" << endl;
		return 0;
	}
	else{
		a = 2 * X - Y / 2;
		b = Y / 2 - X;
	
		if(a >= 0 && b >= 0){
			if(a == 0 && b == 0){
				cout << "No" << endl;
				return 0;
			}
			else{ 
				cout << "Yes" << endl;
				return 0;
			} 
		}
		else{
			cout << "No" << endl;
			return 0;
		}	
	}
	

}

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

using ld = double;
using point = std::complex<ld>;
using polygon = std::vector<point>;

struct line {
    line() : a(0, 0), b(0, 0) {}
    line(point a_, point b_) : a(a_), b(b_) {}
    point a, b;
};

ld dot(point const& a, point const& b) {
    return std::real(std::conj(a) * b);
}
ld cross(point const& a, point const& b) {
    return std::imag(std::conj(a) * b);
}

point proj(line const& l, point const& p) {
    ld t = dot(p - l.a, l.a - l.b) / std::norm(l.a - l.b);
    return l.a + t * (l.a - l.b);
}

point reflect(line const& l, point const& p) {
    return p + (proj(l, p) - p) * 2.0;
}

point read_point() {
    ld x, y; cin >> x >> y;
    return point{x, y};
}

int main() {
    int n;
    while(cin >> n, n) {
        const auto sp = read_point();
        polygon ps;
        for(int i = 0; i < n; ++i) {
            ps.emplace_back(read_point());
        }

        vector<int> ord(n);
        iota(begin(ord), end(ord), 0);
        int ans = 0;
        do {
            auto ts = ps;
            vector<point> lvs, rvs;
            for(auto i : ord) {
                const auto a = ts[i], b = ts[(i + 1) % n];
                lvs.push_back(a + (b - a) / abs(b - a) * 1e-6 - sp);
                rvs.push_back(b + (a - b) / abs(b - a) * 1e-6 - sp);
                if(cross(rvs.back(), lvs.back()) < 0) swap(lvs.back(), rvs.back());
                for(int j = 0; j < n; ++j) {
                    if(j == i || (i + 1) % n == j) continue;
                    ts[j] = reflect(line{a, b}, ts[j]);
                }
            }
            auto lv = lvs[0], rv = rvs[0];
            bool check = true;
            for(int i = 1; i < n; ++i) {
                if(cross(lv, lvs[i]) <= 0) swap(lv, lvs[i]);
                if(cross(rv, rvs[i]) >= 0) swap(rv, rvs[i]);
                check &= cross(rv, lv) >= 0;
            }
            ans += check;
        } while(next_permutation(begin(ord), end(ord)));

        cout << ans << endl;
    }
}



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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  int n; cin >> n;
  int sum = 0;
  int tmp = n;
  while(tmp > 0) {
    sum += tmp % 10;
    tmp /= 10;
  }
  if(n % sum == 0) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


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

const ll mod = 1e9;
ll counter[20][20];

int main() {
    int n;
    cin >> n;
    ll ans = 0;
    while (n--) {
        double a;
        cin >> a;
        ll val = a * mod + 0.5;
        int n2 = 1, n5 = 1;
        while (val > 0 && val % 2 == 0) {
            val /= 2;
            n2++;
        }
        while (val > 0 && val % 5 == 0) {
            val /= 5;
            n5++;
        }
        n2 = min(n2, 19);
        n5 = min(n5, 19);
        for (int i = 20 - n2; i <= 19; i++) {
            for (int j = 20 - n5; j <= 19; j++) {
                ans += counter[i][j];
            }
        }
        counter[n2][n5]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3716
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		String ans = "";
		String s1 = scan.next();
		String s2 = scan.next();
		char new_string[] = new char[2*n];
		for(int i=0;i<n;i++) {
			new_string[2*i] = s1.charAt(i);
			new_string[2*i+1] = s2.charAt(i);
		}
		for(int i=0;i<2*n;i++) {
			ans += String.valueOf(new_string[i]);
		}
		System.out.println(ans);
	}

}




Measured memory_bytes: 21844
/* ex9_1
   bonbonc    */

#include <stdio.h> 
#include<stdlib.h>
#include<string.h>
#define SIZE 100
typedef struct{
    int size;
    int count;
    char data[SIZE];
    char *top;
} stack;

void initialize_stack(stack *stk);
void print_stack(stack *stk);
void push(stack *stk,char token);
char pop(stack *stk);

stack stk;

int main(void){
    int i=0;
    char string[SIZE];//入力を受け取るchar配列

    initialize_stack(&stk);//スタックを初期化

    scanf("%s", string);//入力を受け取る
    for(i=0;i<strlen(string);i++){//stringを一文字ずつ見ていく
        if(string[i]=='0' || string[i]=='1'){//0か1ならスタックにプッシュ
            push(&stk,string[i]);
        }else if(string[i]=='B'){//Bならスタックから一文字pop、スタックがからの場合は何もしない
            if(stk.count>0){
                pop(&stk);
            }
        }
    }  
    print_stack(&stk);//stackの中身を出力
    printf("\n");
    return 0;
}

void initialize_stack(stack *stk){//スタックの初期化
    stk->count = 0;//要素数を0にする
    stk->size = SIZE;//スタックの大きさをSIZEにする
    stk->top = &(stk->data[SIZE]);//topを配列の末尾にする
}

void push(stack *stk,char token){//スタックにプッシュする
    if(stk->count>=stk->size){
        printf("Error: stack overflow.");//これ以上プッシュ出来ないとき終了する
        exit(1);
    }else{
        stk->top--;//topを配列の一つ手前にする
        *(stk->top)=token;//topにtokenを格納
        stk->count++;//要素数を1増やす
    }
    return;
}

char pop(stack *stk){
    char ret_char;//返す文字
    if(stk->count<=0){
        printf("Error: stack underflow");//返す文字が無いとき、終了
        exit(1);
    }else{
        ret_char = *(stk->top);//topの文字をret_charに代入
        stk->count--;//要素数を1減らす
        stk->top++;//topを1つ後ろにずらす
        return ret_char;//ret_charを返す
    }

}

void print_stack(stack *stk){
    int i=0,j=0;
    for(i=0;i<stk->count;i++){//要素数の数だけループを回す
        j = SIZE-i-1;//配列を後ろから参照するためのインデックスを準備
        putchar((stk->data[j]));//一文字ずつ出力する
    }
    return;
}

Measured memory_bytes: 1612
s=input()
t=input()
n=len(s)
m=len(t)
s1=''
dp=[[0 for _ in range(m+1)] for _ in range(n+1)]
for i in range(n+1):
  for j in range(m+1):
    if i==0 or j==0:
      continue
    if s[i-1]==t[j-1]:
    
      dp[i][j]=1+dp[i-1][j-1]
    else:
      dp[i][j]=max(dp[i-1][j],dp[i][j-1])
l=dp[n][m]#ans
i=n#s
j=m#t
while(i>=0 and j>=0):
    if s[i-1]==t[j-1]:
      s1+=s[i-1]
      i-=1
      j-=1
    elif dp[i][j-1]>dp[i-1][j]:
      j-=1
    else:
      i-=1
s2=''
for u in range(dp[n][m]-1,-1,-1):
  s2+=s1[u]
print(s2)

Measured memory_bytes: 120796
#include<stdio.h>
#include<string.h>
 
 
typedef struct  {
    int first;
    int second;
    int third;
    int forth;
    int fifth;
    int sixth;
} Dice;
 
int main() {
    Dice one;
    int q, i;
 
    scanf("%d ", &one.first);
    scanf("%d ", &one.second);
    scanf("%d ", &one.third);
    scanf("%d ", &one.forth);
    scanf("%d ", &one.fifth);
    scanf("%d", &one.sixth);
 
    scanf("%d\n", &q);
 
    for(i = 0; i < q; ++i) {
        int a[2];
        scanf("%d %d", &a[0], &a[1]);
         
        if(a[0] == one.first){
            if(a[1] == one.second) printf("%d\n", one.third);
            if(a[1] == one.third) printf("%d\n", one.fifth);
            if(a[1] == one.forth) printf("%d\n", one.second);
            if(a[1] == one.fifth) printf("%d\n", one.forth);
        }
        if(a[0] == one.second){
            if(a[1] == one.first) printf("%d\n", one.forth);
            if(a[1] == one.third) printf("%d\n", one.first);
            if(a[1] == one.forth) printf("%d\n", one.sixth);
            if(a[1] == one.sixth) printf("%d\n", one.third);
        }
        if(a[0] == one.third){
            if(a[1] == one.second) printf("%d\n", one.sixth);
            if(a[1] == one.first) printf("%d\n", one.second);
            if(a[1] == one.sixth) printf("%d\n", one.fifth);
            if(a[1] == one.fifth) printf("%d\n", one.first);
        }
        if(a[0] == one.forth){
            if(a[1] == one.second) printf("%d\n", one.first);
            if(a[1] == one.sixth) printf("%d\n", one.second);
            if(a[1] == one.first) printf("%d\n", one.fifth);
            if(a[1] == one.fifth) printf("%d\n", one.sixth);
        }
        if(a[0] == one.fifth){
            if(a[1] == one.first) printf("%d\n", one.third);
            if(a[1] == one.third) printf("%d\n", one.sixth);
            if(a[1] == one.forth) printf("%d\n", one.first);
            if(a[1] == one.sixth) printf("%d\n", one.forth);
        }
         if(a[0] == one.sixth){
            if(a[1] == one.second) printf("%d\n", one.forth);
            if(a[1] == one.third) printf("%d\n", one.second);
            if(a[1] == one.forth) printf("%d\n", one.fifth);
            if(a[1] == one.fifth) printf("%d\n", one.third);
        }
    }
    return 0;
}


Measured memory_bytes: 2144
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

int N;
vector<int> a;

void solve() {
	vector<int> res;
	for (int i = 0; i < N; ++i) {
		int pivot = -1;
		for (int j = (int)a.size() - 1; j >= 0; --j) {
			if (a[j] == j) {
				pivot = j;
				break;
			}
		}
		if (pivot == -1) {
			cout << -1 << endl;
			return;
		}

		res.push_back(pivot + 1);
		a.erase(a.begin() + pivot);
	}
	reverse(res.begin(), res.end());
	for (auto v : res) cout << v << endl;
}


int main() {
	cin >> N;
	a.resize(N);
	for (int i = 0; i < N; ++i) cin >> a[i], --a[i];
	solve();

	return 0;
}


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

int main(){
    ll n,k;
    cin>>n>>k;
    vector<vector<int>> next(60,vector<int>(n));
    rep(v, n) cin>>next[0][v], next[0][v]--;
    for(int d=0;d+1<60;d++){
        rep(v,n){
            next[d+1][v]=next[d][next[d][v]];
        }
    }
    int v=0;
    rep(d,60){
        if(k&(1LL<<d)) v=next[d][v];
    }
    cout<<v+1<<endl;
}

Measured memory_bytes: 51048
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a;
    cin>>a;
    if(a%7==0){
        cout<<"thu"<<endl;
    }else if(a%7==1){
        cout<<"fri"<<endl;
    }else if(a%7==2){
        cout<<"sat"<<endl;
    }else if(a%7==3){
        cout<<"sun"<<endl;
    }else if(a%7==4){
        cout<<"mon"<<endl;
    }else if(a%7==5){
        cout<<"tue"<<endl;
    }else if(a%7==6){
        cout<<"wed"<<endl;
    }
}



Measured memory_bytes: 3100
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    int cnt =0; 
    for(int i= 0; i<S.length()/2; i++){
      if(S.charAt(i)!=S.charAt(S.length()-i-1)){
        cnt++;
      }
    }
    System.out.println(cnt);
  }
}


Measured memory_bytes: 35596
import java.util.*;

public class Main {

    public static void main(String[] args) {
	    // write your code here
        Scanner sc = new Scanner(System.in);

        // 整数の入力
        String s = sc.next();
        int nearestGap = Integer.MAX_VALUE;

        for(int i = 0; i < s.length() - 2; i++) {
            int value = Integer.parseInt(s.substring(i, i + 3));
            int gap = Math.abs(753 - value);
            if (gap < nearestGap) {
                nearestGap = gap;
            }
        }

        // 出力
        System.out.println(nearestGap);
    }
}

Measured memory_bytes: 22612
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a, b, i;
  	int number[3]={1, 2, 3};
  	cin >> a>>b;
    for(i=0;i<3;++i){
	if(number[i] !=a && number[i]!=b)
    	cout<<number[i]<<endl;  
    }
 }


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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define int long long
#define itn int
#define pb push_back
#define m_p make_pair
#define m_t meke_tuple
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a));reverse(all(a))
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) a.size()
#define ENDL cout<<endl
#define debg(a) cout<<#a<<" "<<a<<endl;
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define show(a) rep(ghf,SZ(a)){rep(kjh,SZ(a[ghf])){cout<<(a[ghf][kjh]<10?" ":"")<<a[ghf][kjh]<<" ";}ENDL;}
#define out(a) cout<<(a)<<endl
#define fi first
#define se second
#define Vec vector
#define P pair
typedef long long ll;
typedef string str;
typedef vector<ll> V;
typedef pair<ll,ll> Pi;
typedef vector<Pi> VP;
const long long INF = 1LL<<60;
const long long MOD = 1e9+7;
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 max(int a,int b){if(a>b)return a; return b;}
int min(int a,int b){if(a>b)return b; return a;}
void Yes(){cout<<"Yes"<<endl;}
void No(){cout<<"No"<<endl;}
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin>>n;
  V a(n);
  rep(i,n)cin>>a[i];

  bool zero=false;
  int sum=0,num=0,mn=abs(a[0]);
  rep(i,n){
    sum+=abs(a[i]);
    if(a[i]==0)zero=true;
    if(a[i]<0)num++;
    chmin(mn,abs(a[i]));
  }
  if(zero || num%2==0)
    out(sum);
  else 
    out(sum-mn*2);
  
  
  return 0;
}



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

using namespace std;

long long r,g,b;

int main(){

	long long n;
	string s;

	cin >> n >> s;

	for(long long i=0;i<n;++i){
		if(s[i] == 'R') ++r;
		if(s[i] == 'G') ++g;
		if(s[i] == 'B') ++b;
	}

    long long ans=r*g*b;
    for(long long i=0;i<n;++i){
    	for(long long j=1;j<n;++j){
    		long long l=i-j;
    		long long rr=i+j;
    		if(l>=0 and l<n and rr>=0 and rr<n and s[l]!=s[i] and s[rr]!=s[i] and s[l]!=s[rr]) ans--;
    	}
    }
    cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long int
#define ll long long int
#define ld long double
#define pb push_back 
#define ff first 
#define ss second
#define all(c) c.begin(), c.end()
#define sz(z) (int)z.size()
#define rep(i,a,b) for(int i=a; i<b; ++i)
#define rev(i,a,b) for(int i=a; i>=b; i--)
//Debugging tools 
#define debug(v) cout<<#v<<endl;for(ll i=0; i<v.size(); i++) cout<<v[i]<<" "; cout<<endl;
#define debugn(v,n) cout<<#v<<endl;for(ll i=0; i<n; i++) cout<<v[i]<<" "; cout<<endl;
#define deb(sum) cout<<#sum<<" = "<<sum<<endl;
//Predefined values
#define INF (ll)1e18
#define endl "\n"
#define pi 3.142857142857143

const ll MOD = 1e9 + 7;

int n,m, com=0;
const int MAX = 2e5 + 5;
int mxSize=0;
vector<int> adj[MAX];
vector<int> vis(MAX);

void dfs(int p, int ch){
    vis[ch] = 1;
    com++;
    for(int x : adj[ch]){
        if(!vis[x]){
            dfs(ch,x);
        }
    }
}

int main() { 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int t=1;    
    //cin>>t;
    while(t--){
        cin>>n>>m;
        rep(i,0,m){
            int v,u;
            cin>>u>>v;
            adj[u].pb(v);
            adj[v].pb(u);
        }
        rep(i,1,n+1){
            if(!vis[i]){
                com=0;
                dfs(0,i);
                mxSize = max(com, mxSize);
            }
        }
        cout<<mxSize<<endl;

    }
  return 0;
 }

















Measured memory_bytes: 21168
#include <bits/stdc++.h>
#define M 1000000007
#define U 998244353
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define N 2505
#define U 998244353
#define bs binary_search
#define endl '\n'
#define FILEIO     freopen("input.txt","r",stdin); freopen("output.txt","w", stdout);
#define PI 3.1415926535
#define INF (int)1e15
using namespace std;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int po(int n, int exp){
    int prod=1;
    rep(i,0,exp)
        prod*=n;
    return prod;
}
int n,m,p;
vector<int> g[N];
vector<pair<pair<int,int>,int>> edge;
vector<int> vis(N,0);
int dfs(int i, int d)
{
    if(i==d) return 1;
    if(vis[i]) return 0;
    // if(d==n) cout<<i<<" ";
    vis[i] = 1;
    int ans = 0;
    rep(j,0,sz(g[i]))
        ans = ans|dfs(g[i][j], d);
    return ans;
}
map<pair<int,int>,int> mp;
signed main()
{
    ios_base::sync_with_stdio(0);
    // cin.tie(0);
    // cout.tie(0);
    int TESTS=1;
    // cin>>TESTS;
    while(TESTS--)
    {   
        cin>>n>>m>>p;
        int tm = m;
        while(tm--){
            int a,b,w;
            cin>>a>>b>>w;
            edge.pb({{a,b},p-w});
            g[a].pb(b);
        }
        vector<int> d(N,INF);
        d[1] = 0;
        rep(i,0,n-1){
            rep(j,0,m){
                if(d[edge[j].fr.fr]<INF)
                    d[edge[j].fr.sc] = min(d[edge[j].fr.sc], d[edge[j].fr.fr]+edge[j].sc);
            }
        }
        vector<int> change;
        rep(j,0,m){
            if(d[edge[j].fr.fr]<INF){
                // trace(edge[j].fr.fr, edge[j].fr.sc, d[edge[j].fr.fr], d[edge[j].fr.sc]);
                if(d[edge[j].fr.sc]>d[edge[j].fr.fr]+edge[j].sc) change.pb(edge[j].fr.sc);
            }
        }
        for(auto j:change){
            // cout<<j;
            vis.assign(N,0);
            if(dfs(1,j)){
                vis.assign(N,0);
                if(dfs(j,n)){
                    cout<<-1;
                    r0;
                }
            }
        }
      if(d[n]>0){
        cout<<0;
        r0;
      }
        cout<<-d[n];
    }   
} 


Measured memory_bytes: 768
n,x = [int(i) for i in input().split()]
a = [i for i in range(1,2*n)]

def swap(a,i,j):
    b = a[i]
    a[i] = a[j]
    a[j] = b

if x==1 or x==2*n -1:
    print("No")
else:
    print("Yes")
    if x==n:
        pass
    elif x>n:
        swap(a,n-1,x-1)
        swap(a,n,2*n-2)
        swap(a,n+1,0)
    else:
        swap(a,n-1,x-1)
        swap(a,n-2,0)
        swap(a,n-3,2*n-2)
    for i in a:
        print(i)

Measured memory_bytes: 12532
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;

bool used[10000010];
std::vector<ll> primes;

void sieve() {
  used[0] = used[1] = true;

  for( ll i = 2; i <= 10000000; ++i ) if( !used[i] ) {
    primes.emplace_back( i );

    for( ll j = i; j <= 10000000; j += i ) {
      used[j] = true;
    }
  }

  return;
}

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

  ll ans = 0;

  repi( i, 1, N+1 ) {
    ans += i*(N/i)*(N/i+1)/2;
  }

  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 3640
N = int(input())

R = "Yes"
pr = input()
W = []
for i in range(1, N):
  W.append(pr)
  s = input()
  if pr[len(pr)-1:] != s[:1]:
    R = "No"
    break
  if s in W:
    R = "No"
    break
  pr = s
    
print(R)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int calc(int prev,int n,int k,int s) {
    if(k==0) {
        return s==0;
    }
    if(s<0) return 0;
    int sum=0;
    for(int i=prev+1;i<=n;i++) {
        sum+=calc(i,n,k-1,s-i);
    }
    return sum;
}
int main() {
    int n,k,s;
    while(scanf("%d %d %d",&n,&k,&s),n) {
        printf("%d\n",calc(0,n,k,s));
    }
}

Measured memory_bytes: 3220
module DoublyLinkedList = struct

  type t = {
    mutable data : int;
    mutable next : t;
    mutable prev : t;
  }

  let make () =
    let rec head = { data = 0; next = head; prev = head } in
    head

  let insert data head =
    let x = { data = data; next = head.next; prev = head } in
    head.next.prev <- x;
    head.next <- x

  let delete x =
    x.next.prev <- x.prev;
    x.prev.next <- x.next

  let delete_first head = delete head.next

  let delete_last head = delete head.prev

  let delete_node data head =
    let rec doit ite =
      if ite == head then None
      else if ite.data = data then Some ite
      else doit ite.next in
    match doit head.next with
    | None -> ()
    | Some ite -> delete ite

  let iteri f head =
    let rec doit i ite =
      if ite == head then ()
      else begin
        f i ite.data;
        doit (i + 1) ite.next
      end in
    doit 0 head.next

end

module L = DoublyLinkedList

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let n = read_int () in
  let head = L.make () in
  for _ = 0 to n - 1 do
    match split_on_char ' ' (read_line ()) with
    | ["insert"; n] -> L.insert (int_of_string n) head
    | ["delete"; n] -> L.delete_node (int_of_string n) head
    | ["deleteFirst"] -> L.delete_first head
    | _ -> L.delete_last head
  done;
  L.iteri (fun i n -> if i <> 0 then print_string " "; print_int n) head;
  print_newline ()

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

using namespace std;
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;

int n , m , a , b;
typedef long long ll;

int fac[maxn * 2];

int Pow(int a , int b)
{
    if(b == 0)return 1;
    int r = Pow(a , b / 2);
    if(b & 1)return (ll)r * r % mod * a % mod;
    return (ll)r * r % mod;
}

int C(int n , int k)
{
    if(k > n)return 0;
    return (ll)fac[n] * Pow((ll)fac[k]*fac[n-k] % mod,mod-2) % mod;
}

int main(){
    cin >> m >> n >> a >> b;
    fac[0] = 1;
    for(int i = 1 ; i <= 2e5 ; ++i)fac[i] = (ll)fac[i - 1] * i % mod;
    int res = 0;
    for(int i = b + 1 ; i <= n ; ++i)
    {
        res += (ll)C(i + m - a - 2 , i - 1) * C(a - 1 + n - i , n - i) % mod;
        if(res >= mod)res -= mod;
//        cout << res << endl;
    }
    cout << res;
}


Measured memory_bytes: 1024
#define dbg(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#define dpri(x) dbg(#x ": %d\n", x)
#define dprs(x) dbg(#x ": %s\n", x)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef long long ll;
const int MYINF = 1e9+7;

typedef struct {
	int top;
	int north;
	int south;
	int east;
	int west;
	int bottom;
} dice;

void dice_init(dice *d, int v1, int v2, int v3, int v4, int v5, int v6) {
	d->top = v1;
	d->north = v5;
	d->south = v2;
	d->east = v3;
	d->west = v4;
	d->bottom = v6;
}

enum direction {
	DIR_N,
	DIR_S,
	DIR_E,
	DIR_W,
	DIR_L,
	DIR_R,
};

void rotate(dice *d, int dir) {
	int tmp;
	switch (dir) {
	case DIR_N:
		tmp = d->top;
		d->top = d->south;
		d->south = d->bottom;
		d->bottom = d->north;
		d->north = tmp;
		break;
	case DIR_S:
		tmp = d->top;
		d->top = d->north;
		d->north = d->bottom;
		d->bottom = d->south;
		d->south = tmp;
		break;
	case DIR_E:
		tmp = d->top;
		d->top = d->west;
		d->west = d->bottom;
		d->bottom = d->east;
		d->east = tmp;
		break;
	case DIR_W:
		tmp = d->top;
		d->top = d->east;
		d->east = d->bottom;
		d->bottom = d->west;
		d->west = tmp;
		break;
	case DIR_L:
		tmp = d->north;
		d->north = d->east;
		d->east = d->south;
		d->south = d->west;
		d->west = tmp;
	case DIR_R:
		tmp = d->north;
		d->north = d->west;
		d->west = d->south;
		d->south = d->east;
		d->east = tmp;
		break;
	default:
		fprintf(stderr, "Unspported direction: %d\n", dir);
		exit(1);
	}
	return;
}

void dice_dump(dice *d) {
	printf("top:    %d\n", d->top);
	printf("east:   %d\n", d->east);
	printf("bottom: %d\n", d->bottom);
	printf("west:   %d\n", d->west);
	printf("north:  %d\n", d->north);
	printf("south:  %d\n", d->south);
}

int match_top(dice *d, const dice*to) {
	int i; 
	if (d->top == to->top) return 1;
	for (i = 0; i < 3; i++) {
		rotate(d, DIR_E);
		if (d->top == to->top) return 1;
	}
	if (d->north == to->top) {
		rotate(d, DIR_S);
		return 1;
	}
	if (d->south == to->top) {
		rotate(d, DIR_N);
		return 1;
	}
	return 0;
}

int match_top_south(dice *d, const dice *to) {
	int i;
	if (match_top(d, to)) {
		if (d->south == to->south) return 1;
		for (i = 0; i < 3; i++) {
			rotate(d, DIR_R);
			if (d->south == to->south) return 1;
		}
	}
	return 0;
}

int main(int argc, char **argv)
{
	int i, v[6], q, top, south;
	dice d, e;
	
	for (i = 0; i < 6; i++) {
		scanf("%d", &v[i]);
	}
	dice_init(&d, v[0], v[1], v[2], v[3], v[4], v[5]);

	scanf("%d", &q);
	for (i = 0; i < q; i++) {
		scanf("%d %d", &top, &south);
		dice_init(&e, top, south, -1, -1, -1, -1);
		if (match_top_south(&d, &e)) {
			printf("%d\n", d.east);
		}
		else printf("-1");
	}
	return 0;
}

Measured memory_bytes: 596
//#include"libraries.h"
#include<bits/stdc++.h>
#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(int i=0;i<j;i++)
#define rep1(i,j) for(int i=1;i<=j;i++)
#define rep0d(i,j) for(int i=j-1;i>=0;i--)
#define MOD 1000000007
 
using namespace std;

struct nCr{
  vector<lli> f, rf, f156;
  lli count=0;
  nCr(lli num, int bignum): f(num), rf(num), f156(num){
      count = num;
      f[0] = 1; f156[0]=1;
      rep1(i, num) f[i] = (f[i - 1] * i) % MOD;
      rep1(i, num) f156[i] = (f156[i - 1] * (bignum-i+1))%MOD;
      rep0(i, num+1) rf[i] = inv(f[i]);
  }
    
  lli inv(lli x) {
      lli res = 1;
      lli k = MOD - 2;
      lli y = x;
      while (k) {
          if (k & 1) res = (res * y) % MOD;
          y = (y * y) % MOD;
          k /= 2;
      }
      return res;
  }
  lli C(lli n, lli k) {
      lli a = f156[k];
      lli c = rf[k];
   
      return (a * c) % MOD;
  }
};

lli binf(lli num){
    lli f=2,ans=1;
    while(num>0){
        if(num&1){
            ans*=f;
            ans%=MOD;
        }
        f*=f; f%=MOD;num>>=1;
    }
    return ans;
}
int main(){
    int n,a,b;
    cin >> n >> a >> b;

    nCr comb(200000,n);
    lli num=binf(n);
    num-=comb.C(n,a)+comb.C(n,b)+1;
    num+=2*MOD;
    num%=MOD;
    cout << num;

}


Measured memory_bytes: 5504
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <vector>
#include <queue>
#include <functional>
#include <math.h>
#include <string.h>

using std::endl;

#define ll long long int
#define LEP(a, n) for(int a = 0; a < n; ++a)
#define INF 1145141919810
#define OUT std::cout
#define IN std::cin
#define itn int
#define fro for
#define sdt std

int N;
int data[2][123];
int ans = 0;
int buf;
int main()
{
	
	IN >> N;

	LEP(a, N)
	{
		IN >> data[0][a];
	}
	LEP(a, N)
	{
		IN >> data[1][a];
	}

	LEP(a, N)
	{
		buf = 0;
		LEP(b, a + 1)
		{
			buf += data[0][b];
		}
		for(int b = a; b < N; ++b)
		{
			buf += data[1][b];
		}
		ans = std::max(ans, buf);
	}

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

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#define S std::string
S f(S s,S x,S y){
	while (s.find(x)!=S::npos)
		s.replace(s.find(x),x.size(),y);
	return s;
}
int main(void){
	S s,a="apple",b="peach",x="X";
	getline(std::cin,s);
	std::cout<<f(f(f(s,a,x),b,a),x,b)<<"\n";
} 

Measured memory_bytes: 1212
def main():
    n,k,*a=map(int,open(0).read().split())
    a,f=sorted(a[:n]),sorted(a[n:],reverse=1)
    ok=10**12
    ng=-1
    while ok-ng>1:
        mid=(ok+ng)//2
        l=k
        for b,g in zip(a,f):
            if b*g>mid:l-=b-mid//g
        if l<0:ng=mid
        else:ok=mid
    print(ok)
main()

Measured memory_bytes: 49412
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>
#include <stack>
#include <bitset>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}

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

  int n;
  cin >> n;
  vector<int> a(n);
  vector<P> b(n);
  REP(i,n) {
    cin >> a[i];
    b[i].first = a[i];
    b[i].second = i;
  }

  sort(b.begin(), b.end(), greater<P>());

  /*
  REP(i,n) {
    
  }
  */

  int max_idx = b[0].second;
  int snd_idx = b[1].second;

  REP(i,n) {
    if(i == max_idx){
      cout << b[1].first << endl;
    }
    else cout << b[0].first << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3968
//#pragma region ALL(include define etc)
#include <iostream>   // swap(a, b)
#include <string>
#include <cmath>      // abs(絶対値) sin cos tan(角度 / 180.0 * 3.141592)
#include <vector>     // vec.push_back(a) vec.pop_back()
#include <algorithm>  // max(a, b) min(a, b) reverse() sort()
#include <functional> // sort(a, a + N, greater<型>());
#include <math.h>
#include <iomanip>
#define int long long
#define ll long long
#define double long double
using namespace std;
//#pragma endregion

signed main()
{
	// 10^18 = 1000000000000000000

	//int h1, h2, m1, m2, k;
	//int box, box1,box2;

	//int N;
	int n;
	//char n;
	//int a = -111, b = -111;
	//int m;
	int k;
	//string s;
	//string t;
	//int m1, m2;
	//int a, b, c, k;
	//int x, y;

	//int box[1000000000000000000];
	//int box;
	//int box2;
	int p[1111];

	//long double aaa;

	//int k, d;
	int all = 0;
	//double all;
	//double a, b;
	//double h, m;
	//int a[30000] = { 0 };
	//double c, d, e;

	//double mbox, hbox;
	//double box, box2;

	//int box[10000] = { 0 };

	//bool flag = true;
	bool flag = false;

	//string str;

	//cin >> h1 >> m1 >> h2 >> m2 >> k;
	cin >> n >> k;
	//cin >> a >> b;
	//cin >> x >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> p[i];
	}

	sort(p, p + n);
	//n = n - 'Z';

	for (int i = 0; i < k; i++)
	{
		all += p[i];
	}

	/*if (n > 0)
	{
		cout << "a\n";
	}
	else
	{
		cout << "A\n";
	}*/
	//n = t.length();

	cout << all << "\n";

	/*if (flag == true)
	{
		cout << "Yes\n";
	}
	else
	{
		cout << "No\n";
	}*/

	/*if (n == 0)
	{
		cout << x;
	}*/

	//cout << fixed << setprecision(111) << all;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC target ("avx")
#pragma GCC target ("avx2")
#pragma GCC target ("fma")
#pragma GCC optimize ("Ofast")
#pragma GCC optimization ("unroll-loops, no-stack-protector")
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppld pair <pld, pld>
#define ppll pair <pll, pll>
#define pldl pair <ld, ll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#pragma 03
using namespace std;
using namespace __gnu_pbds;
template <class T>
using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
// wow, quite elegant actually. :D
// the idea is EXTREMELY simple, but of course, I overcomplicated it.
ll dp[5005][5005];
ll mod = 1e9 + 7;
int main(){
	fastio;
	ll n; cin >> n;
	string s; cin >> s;
	ll m = s.length();
	if (n == m){
		cout << 1 << endl; return 0;
	}
	dp[0][0] = 1;
	for (ll i = 1; i <= n; i++){
		for (ll j = 0; j <= i; j++){
			if ((j == 0) && (i == 1)) dp[i][j] = 1;
			else if ((j == 0) && (i > 1)) dp[i][0] = (dp[i - 1][0] + (2 * dp[i - 1][1])) % mod;
			else dp[i][j] = (dp[i - 1][j - 1] + (2 * dp[i - 1][j + 1])) % mod;
 		}
	}
	cout << dp[n][m];
}

Measured memory_bytes: 120300
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;

int n;
set <int> se;

int main(){
    cin>>n;
    REP(i,n){
        int a;
        cin>>a;
        if(se.count(a)){
            se.erase(a);
        }
        else{
            se.insert(a);
        }
    }
    cout<<se.size()<<endl;
    return 0;
}

Measured memory_bytes: 4864
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>

typedef long double ld;
typedef long long ll;

using namespace std;

#define MAXN (100100)

priority_queue<int, std::vector<int>, std::greater<int> > q1, q2;

int aa[MAXN], bb[MAXN], cc[MAXN];

void fillq(priority_queue<int, std::vector<int>, std::greater<int> > & q, int a[MAXN], int n, int s) {
	sort(a, a + n);
	reverse(a, a + n);
	for (int i = 0; i < min(n, s); i++) {
		q.push(a[i]);	
	}
	while (q.size() != s) {
		q.push(0);
	}
}

int main() {
	int x, y;
	int a, b, c;
	cin >> x >> y >> a >> b >> c;
	for (int i = 0; i < a; i++) {
		cin >> aa[i];
	}
	for (int i = 0; i < b; i++) {
		cin >> bb[i];
	}
	for (int i = 0; i < c; i++) {
		cin >> cc[i];
	}
	fillq(q1, aa, a, x);
	fillq(q2, bb, b, y);
	
	sort(cc, cc + c);
	reverse(cc, cc + c);
	for (int i = 0; i < c; i++) {
		int f1 = q1.top();
		int f2 = q2.top();
		if (f1 < f2) {
			if (cc[i] > f1) {
				q1.pop();
				q1.push(cc[i]);
			}
		} else {
			if (cc[i] > f2) {
				q2.pop();
				q2.push(cc[i]);
			}
		}
	}
	ll ret = 0;
	while (!q1.empty()) {
		ret += q1.top();
		q1.pop();
	}
	while (!q2.empty()) {
		ret += q2.top();
		q2.pop();
	}
	cout << ret << endl;
	return 0;
}


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

int main() {
  int a,b;
  bool chk = true;
  cin >> a >> b;
  
  if(a == 0 && b == 0){
  	cout << 0;
    chk = false;
  }
  if(a==1 && b == 0){
  	cout << 1;
    chk = false;
  }
  if(a == 0 && b == 1){
  	cout << 0;
    chk = false;
  }
  if(a==1 && b == 1){
  	cout << 0;
    chk = false;
  }
  
  if(chk==true) cout << (a*(a-1)/2) + (b*(b-1)/2);
  
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		if ( A+B >= C) System.out.println("Yes");
		else System.out.println("No");
	}
}


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

int main() {
 int N,X;
  cin >> N >> X;
  int l[N];
  for(int i=0; i<N; i++){
   cin >> l[i]; 
  }
  int d[N];
  d[0]=0;
  int ans=N+1;
  for(int i=1; i<N+1; i++){
   d[i]=d[i-1]+l[i-1];
    if(d[i]>X){
      ans=i;
      break;
    }
 
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import heapq
n,m =map(int, input().split())

a = list(map(int, input().split()))
a = [-i for i in a]
heapq.heapify(a)

for _ in range(m):
    tmp_mx = heapq.heappop(a)*(-1)
    tmp_mx = tmp_mx //2
    heapq.heappush(a,-tmp_mx)

print(-sum(a))


Measured memory_bytes: 14180
from collections import defaultdict

N, A = map(int, input().split())
X = list(map(int, input().split()))
X =[x - A for x in X]

d = defaultdict(int)
d[0] = 1

for x in X:
  for k, v in list(d.items()):
    d[k+x] += v

print(d[0]-1)

Measured memory_bytes: 3572
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int a, b; vector<int>v(5);
	while (cin >> a >> b, a || b) {
		v[0] = a + b;
		rep(i, 1, 5) {
			cin >> a >> b;
			v[i] = a + b;
		}
		cout << char('A' + distance(v.begin(), max_element(all(v))))<<" "<<*max_element(all(v)) << endl;
	}
	return 0;
}

Measured memory_bytes: 3072
import sys; input = sys.stdin.buffer.readline
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	C = list(reversed(sorted(getlist())))
	ans = 0
	for i in range(N):
		ans += pow(2, 2 * N - 2, con) * (i + 2) * C[i]
		ans %= con

	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 75760
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	cin >> n;
	
	vector<int> L(n);
	for(int i = 0; i < n; ++i) {
		cin >> L[i];
	}
	
	sort(L.begin(), L.end());

	ll ans = 0;
	for(int i = 0; i < n; ++i) {
		for(int j = i + 1; j < n; ++j) {
			int k = L[i] + L[j];
			int x = lower_bound(L.begin(), L.end(), k) - L.begin();
			int cnt = x - j - 1;
			
			ans += cnt;
		}
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.StringTokenizer;

class Main {

    public static void main(String[] args) throws IOException {
        init();

        int N = nextInt();

        int[] h = new int[N];

        for (int i = 0; i < h.length; i++) h[i] = nextInt();

        int[] dp = new int[N];

        for (int i = N - 1; i >= 0; i--) {
            if (i == N - 1) dp[i] = 0;
            if (i + 1 < dp.length) dp[i] = dp[i + 1] + Math.abs(h[i + 1] - h[i]);
            if (i + 2 < dp.length) dp[i] = Math.min(dp[i], dp[i + 2] + Math.abs(h[i + 2] - h[i]));
        }

        System.out.println(dp[0]);
    }

    //Input Reader
    private static BufferedReader reader;
    private static StringTokenizer tokenizer;

    private static void init() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    private static String next() throws IOException {
        String read;
        while (!tokenizer.hasMoreTokens()) {
            read = reader.readLine();
            if (read == null || read.equals(""))
                return "-1";
            tokenizer = new StringTokenizer(read);
        }

        return tokenizer.nextToken();
    }

    private static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
}

Measured memory_bytes: 33716
n, c = int(input()), input()

wa = [0] * (n+2)
for i in range(n):
    if(c[i]=='W'): wa[i+1]+=1
for i in range(n+1):
    wa[i+1] += wa[i]

ans = n;
for i in range(n+2):
    w = wa[i]
    r = n-i - (wa[n] - wa[i])
    ans = min(ans, max(w, r))
print(ans)

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

int main() {
   int a,b,c,x;
  cin>>a>>b>>c>>x;
  int ans=0;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      for(int k=0;k<=c;k++){
        int total=500*i+100*j+50*k;
        if(total==x)ans++;
      }
    }
  }
  
  cout<<ans<<endl;
    
    
  

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
bool inside(int x, int y, int H, int W) {
  return 0 <= x && x < H && 0 <= y && y < W;
}
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> A(H);
  rep(i, H) cin >> A[i];
  int tmpX = 0, tmpY = 0;
  int preX = -1, preY = 0;
  int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
  while(true) {
    int cnt = 0;
    int nextX, nextY;
    rep(i, 4) {
      int nx = tmpX+dx[i], ny = tmpY+dy[i];
      if(inside(nx, ny, H, W) &&
	 !(nx == preX && ny == preY) &&
	 A[nx][ny] == '#') {
	cnt++;
	nextX = nx, nextY = ny;
      }
    }
    if(cnt > 1 || nextX < tmpX || nextY < tmpY) {
      cout << "Impossible" << endl;
      return 0;
    }
    if(tmpX == H-1 && tmpY == W-1) {
      if(cnt == 0) break;
      else {
	cout << "Impossible" << endl;
	return 0;
      }
    }
    preX = tmpX, preY = tmpY;
    tmpX = nextX, tmpY = nextY;
  }
  cout << "Possible" << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split(' ')))
B = list(map(int,input().split(' ')))
C = list(map(int,input().split(' ')))
tmp = 60
ans = 0
for i in A:
    ans = ans + B[i-1]
    if i-1 == tmp:
        ans = ans + C[i-2]
    tmp = i
print(ans)

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

int f(int a){
    if (a % 2 == 0){
        return a / 2;
    }else{
        return 3*a + 1;
    }
}


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

    int m = 1;
    while (true){
        if (s == 4 || s == 2 || s == 1){
            cout << m + 3 << endl;
            return 0;
        }
        s = f(s);
        m++;
    }
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

int main(){
    int n;
    cin >> n;
    ll res = 0;
    for (ll i = 1; i <= n; ++i) {
        if(i % 3 != 0 && i % 5 != 0) res += i;
    }
    cout << res << endl;
}

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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll MOD = 1000000000+7;

class Solver {
  public:
    bool solve() {
        int N; cin >> N;
        vector<int> A(N); cin >> A;
        vector<int> cnt(N);
        vector<int> ans(N);
        rep(i, N) {
            if(A[i] == 0) {
                ans[i] = 3 - cnt[A[i]];
            } else {
                ans[i] = cnt[A[i] - 1] - cnt[A[i]];
            }
            cnt[A[i]]++;
        }
        // debug(A);
        // debug(ans);
        ll ans2 = 1;
        for(int a : ans) ans2 = (ans2 * a) % MOD;
        cout << ans2 << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 1408