akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main(){
    string N;
    cin >> N;
    
    long long int dig_N = stoll(N);
    
    long long int power = 1;
    for (int i = 0; i < N.length() - 1; i++) {
        power *= 10;
    }

    if ((dig_N + 1) % power == 0){
        int total = 0;
        for (int i = 0; N[i]; i++)
            total += (N[i] - '0');
        cout << total << endl;
        return 0;
    }
    
    
    if (dig_N == N.length() * 10 -1) {
        int total = 0;
        for (int i = 0; i < N.length(); i++) {
            total += (N[i] - '0');
        }
        cout << total;
        return 0;
    }
    
    long long int first_dig = (N[0] - '0') - 1;
    cout << (N.length() - 1) * 9  + first_dig<< endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <assert.h>
inline void cmax(int &x, int y)
{
	if (y > x)
		x = y;
}
inline void cmax(int &x, int &y, int z)
{
	if (z > x)
		y = x, x = z;
	else if (z > y)
		y = z;
}
inline int abs(int x)
{
	return x < 0 ? -x : x;
}
typedef int ixn[200001];
typedef int ixe[399999];
int N, E, G;
ixn head, f0, f1, g, q, fa, f, w;
ixe next, to;
char s[200002];
long long O = 1;
std::vector < int > V[200001];
std::vector < std::pair < int, int > > C[200001];
void BFS()
{
	int H = 0, T = 1, u;
	q[1] = 1;
	while (H < T)
		for (int e = head[u = q[++H]]; e; e = next[e])
			if (to[e] != fa[u])
				fa[q[++T] = to[e]] = u;
	for (int i = N; i; i--)
	{
		int u = q[i];
		for (int e = head[u]; e; e = next[e])
			if (to[e] != fa[u])
				cmax(f0[u], f1[u], f0[to[e]] + 1);
	}
	for (int i = 1; i <= N; i++)
	{
		int u = q[i], first = f0[u], second = f1[u];
		if (i > 1)
			cmax(first, second, g[u] + 1);
		for (int e = head[u]; e; e = next[e])
			if (to[e] != fa[u])
				g[to[e]] = f0[to[e]] + 1 == first ? second : first;
	}
}
int F(int x)
{
	return f[x] == x ? x : f[x] = F(f[x]);
}
inline void activate(int u)
{
	// printf("activate(%d)\n", u);
	w[u] = 1;
	G++;
}
inline void connect(int u, int v)
{
	// printf("connect(%d, %d)\n", u, v);
	u = F(u), v = F(v);
	if (u != v)
	{
		G -= w[u] + w[v];
		f[v] = u;
		w[u] |= w[v];
		G += w[u];
	}
}
int main()
{
	scanf("%d", &N);
	for (int i = 1, u, v; i < N; i++)
	{
		scanf("%d%d", &u, &v);
		next[++E] = head[u], to[E] = v, head[u] = E;
		next[++E] = head[v], to[E] = u, head[v] = E;
	}
	scanf("%s", s + 1);
	BFS();
	for (int i = 2; i <= N; i++)
		C[std::max(abs(f0[i] - g[i]) - 1, 0)].push_back({ i, fa[i] });
	for (int i = 1; i <= N; i++)
		if (s[i] == '1')
			V[std::max(f0[i], i == 1 ? 0 : g[i] + 1)].push_back(i);
	for (int i = 1; i <= N; i++)
		f[i] = i;
	for (int i = N; i; i--)
	{
		for (int u : V[i])
			activate(u);
		for (auto e : C[i])
			connect(e.first, e.second);
		O += G;
		// printf("i=%d G=%d\n", i, G);
	}
	printf("%lld\n", O);
	return 0;
}


Measured memory_bytes: 25472
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<iostream>



int main() {
	int num;
	for (int i = 1;;i++) {
		std::cin >> num;

		if (num == 0)break;

		printf("Case %d: %d\n", i, num);
	}



//	system("pause");
	return 0;
}


Measured memory_bytes: 3096
import math
import queue
from collections import defaultdict
import itertools as it

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=qb
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
def dq():
	return queue.deque()
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1

n = readInt()

s = int(str(n)[-1])


if s in [2,4,5,7,9]:
	print("hon")
elif s in [0,1,6,8]:
	print("pon")
else:
	print("bon")

Measured memory_bytes: 9788
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    int a, b, c;
    cin >> a >> b >> c;
    if(b / a > c)
        cout << c << endl;
    else
        cout << b / a;
    return 0;
}

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

int main(){
  string str;
  int k,num[11]={};
  cin>>str>>k;
  str='0'+str; 
  for(int i=0,a;i<k;i++)cin>>a,num[a]=1;

  string ans;
  int m=0;
  while(num[m])m++;
  for(int i=str.size()-1;i>=0;i--){
    if(i==0&&str[i]=='0')break;
    int cnt=str[i]-'0';
    while(cnt<10&&num[cnt])cnt++;
    if(cnt==10) {
      cnt=m;
      int idx=i-1;
      while(1){
	str[idx]++;
	if(str[idx]-'0'<10) break;
	str[idx--]='0';
      }
    }
    if(str[i]-'0'!=cnt) 
      for(int j=0;j<ans.size();j++) ans[j]=m+'0';
    ans=(char)(cnt+'0')+ans;
  }
  if(ans[0]=='0') ans=ans.substr(1);
  cout <<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 256
N = int(input())
a = []
visited = []
for i in range(N):
    a.append(int(input()))
    visited.append(False)

visited[0] = True
cur = 1
cnt = 0
while True:
    cur = a[cur-1]
    cnt = cnt + 1
    if cur == 2:
        print(cnt)
        break
    elif visited[cur-1]:
        print(-1)
        break
    else:
        visited[cur-1] = True


Measured memory_bytes: 55256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

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

    cout << s[0] << s.size() - 2 << s[s.size() - 1] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
vector<int> DP[5001];

int main()
{
	int N, K; cin >> N >> K;
	vector<int>a(N);
	vector<bool>b(N);

	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());

	for (int i = 0; i < N; i++) {
		if (a[i] >= K) {
			b[i] = true;
			continue;
		}
		for (int j = K-1; j >= 0; j--) {
			if (DP[j].size() != 0) {
				if (j + a[i] >= K) {
					while(DP[j].size()){
						if (DP[j][0] == -1) {
							DP[j].erase(DP[j].begin());
							continue;
						}
						b[DP[j][0]] = true;
						DP[j].erase(DP[j].begin());
					}
					b[i] = true;
					DP[j].push_back(-1);
					break;
				}
				else {
					for (int k = 0; k < DP[j].size(); k++) {
						DP[j + a[i]].push_back(DP[j][k]);
					}
					DP[j + a[i]].push_back(i);
					break;
				}
			}
		}
		DP[a[i]].push_back(i);
	}

	int ans = 0;
	for (int i = 0; i < N; i++)if (b[i] == false) {
		ans++;
	}
	cout << ans << endl;

    return 0;
}


Measured memory_bytes: 61824
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 100000000;
const int MAX_N = 100;
typedef pair<int , int> P;
typedef long long ll;
 
int main () {
  ll N, count;
  count = 0;
  cin >> N;
  string s = "zabcdefghijklmnopqrstuvwxy";
  string ans = "";
  if (N < 27) {
    ll tmp = N % 26;
    ans = s[tmp];
  } else {
    for (;;) {
      if (N <= 0) {
        break;
      }
      ll tmp = N % 26;
      N /= 26;
      if (count != 0 && N == 1 && tmp == 0) {
        N = 0;
      }
      if (tmp == 0) {
        --N;
      }
      // printf("%lld\n", N);
      ans = s[tmp] + ans;
      ++count;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <queue>
using namespace std;
int H,W;
typedef pair<int, int> P;
//flag[y座標][x座標]
bool flag[50][50];
int dx[] = {-1,0,1,0};
int dy[] = {0,1,0,-1};
int dp[50][50];

int bfs(){
    queue<P> que;
    que.push(P(0,0));
    flag[0][0] = true;
    while(!que.empty()){
        P pair;
        pair = que.front();
        int x = pair.first;
        int y = pair.second;

        if(pair.first==W-1 && pair.second==H-1) break;
        que.pop();

        for(int i=0;i<4;i++){
            int gx = x + dx[i];
            int gy = y + dy[i];
            if(gx<0 || gy <0 || gx>=W || gy>=H) continue;
            if(flag[gy][gx]==false) {
                que.push(P(gx, gy));
                dp[gy][gx] = dp[y][x] + 1;
                flag[gy][gx] = true;
            }
        }
    }
    return dp[H-1][W-1];
}


int main(){
    cin >> H >> W;
    char s[H][W];
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            flag[i][j] = false;
            dp[i][j] = 0;
        }
    }
    int black_count=0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> s[i][j];
            if(s[i][j]=='#'){
                flag[i][j]= true;
                black_count++;
            }
        }
    }
    dp[0][0] = 1;
    int count = bfs();
    if(count==0) cout <<"-1" <<"\n";
    else{
        int answer = H*W - count - black_count;
        cout << answer <<"\n";
    }
    return 0;
}


Measured memory_bytes: 256
class fenwick_tree:
    """
    区間の一点更新と，区間和の取得がO(log n)で可能なデータ構造
    1-indexedで実装
    """

    def __init__(self, N):
        self.size = N
        self.tree = [0] * (N+1)

    def init_array(self, A):
        for i, a in enumerate(A, start=1):
            self.add(i, a)

    def sum_until(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & (-i)
        return s

    def sum_acc(self, i, j):
        """ [i,j] の和を返す """
        return self.sum_until(j) - self.sum_until(i-1)

    def add(self, i, x):
        if i <= 0:
            return
        while i <= self.size:
            self.tree[i] += x
            i += i & (-i)


class fenwick_tree_RAQ_and_RSQ():
    """
    Range Add Queryと，Range Sum QueryがどちらもO(logn)
    BIT 2本使う
    1-indexed 半閉区間
    """

    def __init__(self, n):
        self.p = fenwick_tree(n+1)
        self.q = fenwick_tree(n+1)

    def init_array(self, A):
        for i, a in enumerate(A):
            pass

    def add_interval(self, i, j, w):
        """ [i,j]にwを加算 """
        j += 1
        self.p.add(i, -w*i)
        self.p.add(j, w*j)
        self.q.add(i, w)
        self.q.add(j, -w)

    def sum_until(self, i):
        """ [1,c)の和を求める """
        if i <= 0 or self.p.size < i:
            raise IndexError
        return self.p.sum_until(i) + self.q.sum_until(i)*(i)

    def sum_acc(self, i, j):
        """ [i,j] の区間和を取得 """
        return self.sum_until(j+1) - self.sum_until(i)


def main():
    N, Q = (int(i) for i in input().split())
    bit = fenwick_tree_RAQ_and_RSQ(N)
    for _ in range(Q):
        com, *A = (int(i) for i in input().split())
        if com == 0:
            (x, y, w) = A
            bit.add_interval(x, y, w)
        elif com == 2:
            x = A[0]
            print(bit.sum_until(x))
        else:
            x, y = A
            print(bit.sum_acc(x, y))


if __name__ == '__main__':
    main()



Measured memory_bytes: 11816
#include <bits/stdc++.h>
 
using namespace std;
 
const int INF = 0x0fffffff;

int N;

int X[101010];
int r[101010][20];

int L;
int Q;

 
int main(int argc, char* argv[]) {
    // for cin
    ios::sync_with_stdio(false);
    cin.tie(0);
 
    cin >> N;

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

    cin >> L;

    for (int i = 0; i < N; ++i) {
        r[i][0] = lower_bound(X+i, X+N, X[i]+L+1)-1-X;
        //r[i][0] = upper_bound(X+i, X+N, X[i]+L)-1-X;
    }


    for (int j = 0; j < 19; ++j) {
        for (int i = 0; i < N; ++i) {
            r[i][j+1] = r[r[i][j]][j];
        }
    }

    cin >> Q;

    while (Q--) {
        int a;
        int b;

        cin >> a >> b;
        a--;
        b--;

        if (a > b) { 
            swap(a, b);
        }
        // always a < b

        int ans = 0;
        
        for (int i = 19; i >= 0; i--) {
            if (r[a][i] < b) {
                a = r[a][i];
                ans += 1 << i;
            }
        }

        cout << ans+1 << endl;
    }
    
    //Y[N-1] = 0;
    //for (int i = 0; i < N-1; ++i) {
    //    Y[i] = X[i+1] - X[i];
    //}


    //while (Q--) {
    //    int a;
    //    int b;

    //    cin >> a >> b;
    //    a--;
    //    b--;

    //    if (a > b) { 
    //        swap(a, b);
    //    }
    //    // always a < b

    //    int ans = 1;

    //    int pos = a;
    //    int l = L;

    //    //cout << "a: " << a << ", b: " << b << endl;
    //    
    //    while (true) {
    //        while (l >= Y[pos]) {
    //            l -= Y[pos];
    //            pos++;
    //        }

    //        if (pos >= b) {
    //            break;
    //        } else {
    //            l = L;
    //            ans++;
    //        }
    //    }

    //    cout << ans << endl;
    //}

    ////slove();
 
    return 0;
}


Measured memory_bytes: 9088
#include<bits/stdc++.h>
#define int long long
#define vi vector<int>
#define pb push_back
#define log(x,b) (log(b)/log(x))
#define rep(i,x,y) for(int i=(x);i<(y);i++)
using namespace std;
const int mod=1e9;

int32_t main()
{
    int n;
    cin>>n;
    int res=0;
    for(int i=1;i<mod;i++){
        n-=i;
        res++;
        if(n<=0)break;
    }
    cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
#include<cstring>
#include<cmath>
#include<iterator>
#include<cstdlib>
#define IOS   ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ses   "\n"
#define whp   " "
#define mxi 99999

#define rep0(i,a,b) for(int i=a; i<b; i++)
#define rep1(i,a,b) for(int i=a; i<=b; i++)
#define rep0in(i,a,b) for(int i=a-1; i>=b; i--)
#define rep1in(i,a,b) for(int i=a; i>b; i--)
#define repv(i,a) for(auto i=a.begin(); i!=a.end();++i)

///set <int, greater <int> > ::iterator it;
///vector<pair<int,int> >a;
#define MS(a,b) memset(a,b,sizeof(a));

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll fx[4]= {1,-1,0,0};
ll fy[4]= {0,0,1,-1};
int smallest(int x, int y, int z)
{
    int c = 0;
    while (x && y && z) {
        x--;
        y--;
        z--;
        c++;
    }
    return c;
}
bool rs(ll a, ll b){
    return(a>b);

    }
int main()
{
    ll n; cin>>n;
    cout<<n+pow(n,2)+pow(n,3)<<endl;

return 0;
}



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

int main(){
  ll A,B,C;
  cin>>A>>B>>C;
  if(A%2==0||B%2==0||C%2==0){
    cout<<0<<endl;
  }else{
    cout<<min(A*B,min(B*C,C*A))<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 10000009+7

ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
ll lcm(ll a, ll b){return a*b/gcd(a, b);}
ll fexp(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%MOD; b/=2;a=a*a%MOD;}return ans;}
//ll inverse(ll a, ll p){return fexp(a, p-2);}

int main() {
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t=1;
    //cin>>t;
	while(t--)
	{
	   // ll maxn=0;
	  ll n,maxw;
	  cin>>n>>maxw;
	 
	  ll dp[100000+1];
	  dp[0]=0;
	    for(int i=1;i<100001;i++)
	    {
	        dp[i]=1000000000000;
	    }
	
	  for(ll j=0;j<n;j++)
	  {
	      ll w,v;
	      cin>>w>>v;
	      
	      for(ll i=100000;i-v>=0;i--)
	     {
	       dp[i]=min(dp[i],dp[i-v]+w);
	     }
	   
	  }
	
	ll mn=dp[1];
	int id=1;
     for(int i=0;i<100001;i++)
    {
        if(i>id&&dp[i]<=maxw)
        {
            id=i;
        }
        
    }
    
	cout<<id<<endl;
	}	
	return 0;
}


Measured memory_bytes: 1024
import Control.Monad
dist a b c d = abs(a-c)+abs(b-d)

main = do
  [n,m] <- map read.words <$> getLine 
  ab <- replicateM n $ map read . words <$> getLine :: IO [[Int]]
  cd <- replicateM m $ map read . words <$> getLine :: IO [[Int]]
  mapM print.map snd.map minimum.(map (\[a,b]->map (\ ([c,d],i)->(dist a b c d,i)) $ zip cd [1..])) $ ab 


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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sc.next());
		}

		int b[];
		b = a.clone();
		Arrays.sort(b);

		int max = 0;
		for (int i = 0; i < n; i++) {
			if (a[i] != b[n - 1]) {
				max = b[n - 1];
			} else {
				max = b[n - 2];
			}
			System.out.println(max);
		}

	}

}


Measured memory_bytes: 66464
#include<iostream>
using namespace std;
int a,b;
int main(){
	cin>>a>>b;
	for(int i=b*10;i<(b+1)*10;i++){
		if((int)(i * 0.08) == a){
			cout<<i;
			return 0;
	}
	}
	cout<<"-1";
	return 0;	
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define LB(c, x) lower_bound(c.begin(), c.end(), x)
#define UB(c, x) upper_bound(c.begin(), c.end(), x)
#define LI(c, x) distance(c.begin(), LB(c, x))
#define UI(c, x) distance(c.begin(), UB(c, x))

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
ll modpow(ll a, ll b, ll m) {
    if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll h = modpow(a, b / 2, m);
        return h * h % m;
    } else {
        return a * modpow(a, b - 1, m) % m;
    }
}
ll comb(ll a, ll b, ll m) {
    if (b > a - b) {
        return comb(a, a - b, m);
    }
    ll c = 1, d = 1;
    REP(i, b) {
        c *= (a - i);
        d *= (b - i);
        c %= m;
        d %= m;
    }
    return c * modpow(d, m - 2, m) % m;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, X;
    cin >> N >> X;
    vector<int> L(N);
    REP(i, N) {
        cin >> L[i];
    }
    int D = 0, res = 0;
    REP(i, N) {
        if (D > X) {
            break;
        }
        res++;
        D += L[i];
    }
    if (D <= X) {
        res++;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
ll strtoint(string str);
int main(){
	fast;
	string s; cin>>s;
	if(s[0]=='A'&&s[1]=='A'&&s[2]=='A' || s[0]=='B'&&s[1]=='B'&&s[2]=='B')cout<<"No\n";
	else
		cout<<"Yes\n";
	return 0;
}
ll strtoint(string str){
	ll x=0;
	stringstream ss;
	ss<<str;
	ss>>x;
	return x;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

using ll = long long;

ll N, D;

int main()
{
  scanf( "%lld%lld", &D, &N );

  ll ans = N==100 ? 101 : N;

  rep( i, D )
    ans *= 100;

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

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  cout << a[0] << b[1] << c[2] << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;

#define REP(i,n) for(int i = 0; i < int(n); i++)
#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define fi first 
#define se second

const ll MOD = (ll)1e9 + 7;

//Class - Union Find Tree
template<class T> class Union_Find {
public:
	vector<int> prnt;
	vector<int> rank;
	vector<T> dist;

	Union_Find(int N = 1) :prnt(vector<int>(N)), rank(vector<int>(N, 0)), dist(vector<int>(N, 0)) {
		for (int i = 0; i < N; ++i) prnt[i] = i;
	}

	int root(int x) {
		if (prnt[x] == x) return x;
		else {
			int r = root(prnt[x]);
			dist[x] += dist[prnt[x]];
			return prnt[x] = r;
		}
	}

	T updated_dist(int x) {
		root(x);
		return dist[x];
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y, T d) {
		d += updated_dist(x);
		d -= updated_dist(y);
		x = root(x); y = root(y);
		if (x == y) return false;
		if (rank[x] < rank[y]) {
			swap(x, y);
			d = -d;
		}
		if (rank[x] == rank[y]) ++rank[x];
		prnt[y] = x;
		dist[y] = d;
		return true;
	}

	T diff(int x, int y) {
		return updated_dist(y) - updated_dist(x);
	}
};

int main() {
	ll N, M, X; cin >> N >> M >> X;
	vector<pair<ll, pair<int, int>>> edge(M);

	//入力
	REP(i, M) {
		int U, V;
		ll W;
		cin >> U >> V >> W;
		U--;
		V--;
		edge[i] = { W,{ U,V } };
	}

	//重みでソート
	sort(ALL(edge));

	//コーナーケース
	if (N <= 2 || M < 2) {
		cout << 0 << endl;
		return 0;
	}

	//2の累乗をメモ
	vector<ll> pow2(M + 1, 1);
	FOR(i, 1, M + 1) pow2[i] = (pow2[i - 1] * 2) % MOD;

	//M-1個の最小全域木の重み
	vector<ll> sum(M - 1, 0);
	FOR(B, 1, M) {

		//UnionFind木
		Union_Find<int> UF(N);

		//最小辺とBを用いた最小全域木
		sum[B - 1] += edge[0].fi + edge[B].fi;
		UF.merge(edge[0].se.fi, edge[0].se.se, 1);
		UF.merge(edge[B].se.fi, edge[B].se.se, 1);

		//クラスカル法による最小全域木の構築
		FOR(j, 1, M) {
			int U = edge[j].se.fi;
			int V = edge[j].se.se;
			ll W = edge[j].fi;

			//連結済ならcontinue
			if (UF.same(U, V)) continue;

			//辺をmergeし重みを加える
			UF.merge(U, V, 1);
			sum[B - 1] += W;
		}
	}

	//最小全域木の重みでソート
	sort(ALL(sum));

	//軽い方からsum[i] == Xとなるものを数え上げ
	ll ans = 0;
	REP(i, M - 1) if (sum[i] == X) (ans += ((2 * pow2[M - 2 - i]) % MOD)) %= MOD;

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
N = int(input())
li = []
for i in range(N):
  li.append(list(map(int, input().split())))

HYOU = li[0]

def f(a, b):
  syou = b // a
  amari = b % a
  if amari == 0:
    c = syou
  else:
    c = syou + 1
  return c

for i in range(N-1):
  if li[i][0] <= li[i+1][0] and li[i][1] <= li[i+1][1]:
    HYOU = li[i+1]
#    print(HYOU)
  elif li[i][0] <= li[i+1][0] and li[i][1] > li[i+1][1]:
    c = f(li[i+1][1], li[i][1])
    li[i+1] = [li[i+1][0]*c, li[i+1][1]*c]
    HYOU = li[i+1]
#    print("これ")
#    print(HYOU)
  elif li[i][0] > li[i+1][0] and li[i][1] <= li[i+1][1]:
    c = f(li[i+1][0], li[i][0])
    li[i+1] = [li[i+1][0]*c, li[i+1][1]*c]
    HYOU = li[i+1]
#    print(HYOU)
  else:
    c1 = f(li[i+1][1], li[i][1])
#    print("c1は" + str(c1))
    hyou1 = [li[i+1][0]*c1, li[i+1][1]*c1]
#    print("hyou1は" + str(hyou1))
    c2 = f(li[i+1][0], li[i][0])
#    print("c2は" + str(c2))
    hyou2 = [li[i+1][0]*c2, li[i+1][1]*c2]
#    print("hyou2は" + str(hyou2))
    if hyou1[0] <= hyou2[0] and hyou1[0] >= li[i][0] and hyou1[1] >= li[i][1]:
      li[i+1] = hyou1
      HYOU = li[i+1]
#      print(HYOU)
    elif hyou2[0] <= hyou1[0] and hyou2[0] >= li[i][0] and hyou2[1] >= li[i][1]: 
      li[i+1] = hyou2
      HYOU = li[i+1]
#      print(HYOU)
    elif hyou1[0] > hyou2[0] and hyou1[0] >= li[i][0] and hyou1[1] >= li[i][1]:
      li[i+1] = hyou1
      HYOU = li[i+1]
#      print(HYOU)
    elif hyou2[0] > hyou1[0] and hyou2[0] >= li[i][0] and hyou2[1] >= li[i][1]: 
      li[i+1] = hyou2
      HYOU = li[i+1]
#      print(HYOU)


print(sum(HYOU))


Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <list>
#define N 10000
using namespace std;

list<int> l;
bool color[N]={false};
vector<int> adj[N];
int n;

void topo(int k){
	for(int i=0;i<adj[k].size();i++){
		if(!color[adj[k][i]])topo(adj[k][i]);
	}
	if(!color[k])l.push_front(k);
	color[k]=true;
}

int main(void){
	int u,v;
	int e;
	cin>>n>>e;
	for(int i=0;i<e;i++){
		cin>>u>>v;
		adj[u].push_back(v);	
	}
	for(int i=0;i<n;i++){
		if(!color[i])topo(i);
	}
	for(list<int>::iterator it=l.begin();it!=l.end();it++)cout<<*it<<endl;
	return 0;
}


Measured memory_bytes: 3956
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
bool a[22][22];

ll dp[22][1<<22];

ll calc(int v, int used) {
    if (v >= n) return 1;
    if (dp[v][used] < 0) {
        ll res = 0;
        for (int i = 0; i < n; i++) {
            if (a[v][i] && !(used & (1<<i))) {
                res += calc(v+1, used | (1<<i));
                res %= mod;
            }
        }
        dp[v][used] = res;
    }
    return dp[v][used];
}

ll solve() {
    memset(dp, -1, sizeof(dp));
    return calc(0, 0);
}

void input() {
    cin >> n;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            cin >> a[i][j];
}

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

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 721280
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader(); 
        String s = r.s();
        System.out.printf("%c%d%c", s.charAt(0), s.length()-2, s.charAt(s.length()-1));
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long(ss[j]);            
            return ll;
        }
    }
}

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

const int INF = 99999999;

int main(){
  int N, M;
  vector<int> a(30), b(30);

  cin >> N >> M;
  for(int i=0; i<M; i++) cin >> a[i] >> b[i];

  vector<int> A = {1, 2, 3, 4, 5, 6, 7, 8};

  int cnt = 0;
  do{
    vector<bool> pass(8, false);
    for(int i=0; i<N-1; i++){
      for(int j=0; j<M; j++){
        if (a[j] == A[i] && b[j] == A[i+1]) pass[i] = true;
        if (b[j] == A[i] && a[j] == A[i+1]) pass[i] = true;
      }
    }

    bool flag = true;
    for(int i=0; i<N-1; i++) flag = flag && pass[i];
    if (flag) cnt++;
  }while(next_permutation(A.begin()+1, A.begin()+N));

  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define all(a)  (a).begin(),(a).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 gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

const ll INF = 1LL << 60;

int main(){
  int n; cin >> n;
  vi x(n+1);
  rep(i, n+1) cin >> x[i];
  sort(all(x));
  int s[n];
  rep(i, n) s[i] = x[i+1] - x[i];
  int ans = s[0];
  rep(i, n) ans = gcd(ans, s[i]);
  std::cout << ans << '\n';
}


Measured memory_bytes: 1024
towers,path = gets.chomp!.split(" ").map(&:to_i)
heights = gets.chomp!.split(" ").map(&:to_i)
flags = []
towers.times{
    flags << 1
}

path.times{
    twins = gets.chomp!.split(" ").map(&:to_i)

    if heights[twins[0]-1] == heights[twins[1]-1]
        flags[twins[1]-1] = 0
        flags[twins[0]-1] = 0
    elsif  heights[twins[0]-1] >= heights[twins[1]-1]
        flags[twins[1]-1] = 0
    else
        flags[twins[0]-1] = 0
    end
}

p flags.count(1)

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

int main() {
	string S; cin >> S;
	reverse(S.begin(), S.end());
	long long pos = 0;
	while (pos < S.size()) {
		if (pos < S.size() - 4 && S.at(pos) == 'm' && S.at(pos + 1) == 'a' && S.at(pos + 2) == 'e' && S.at(pos + 3) == 'r' && S.at(pos + 4) == 'd') {
			pos += 5;
		}
		else if (pos < S.size() - 4 && S.at(pos) == 'e' && S.at(pos + 1) == 's' && S.at(pos + 2) == 'a' && S.at(pos + 3) == 'r' && S.at(pos + 4) == 'e') {
			pos += 5;
		}
		else if (S.at(pos) == 'r' && pos < S.size() - 1 && S.at(pos + 1) == 'e') {
			if (pos < S.size() - 5 && S.at(pos + 2) == 's' && S.at(pos + 3) == 'a' && S.at(pos + 4) == 'r' && S.at(pos + 5) == 'e') {
				pos += 6;
			}
			else if (pos < S.size() - 4 && S.at(pos + 2) == 'm' && S.at(pos + 3) == 'a' && S.at(pos + 4) == 'e' && S.at(pos + 5) == 'r' && S.at(pos + 6) == 'd') {
				pos += 7;
			}
			else {
				cout << "NO" << endl;
				return 0;
			}
		}
		else {
			cout << "NO" << endl;
			return 0;
		}
	}
	if (pos != S.size()) cout << "NO" << endl;
	else cout << "YES" << endl;
}


Measured memory_bytes: 512
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <bitset>
using namespace std;

#define INF (1ll<<60)


long long M = 1000000007;


int main(int argc, char const *argv[]) {
    int n;cin>>n;
    bitset<5000000> bs;
    vector<int> a(n);
    bs[0] = 1;
    for(int i=0;i<n;++i)cin>>a[i];
    for(int i=0;i<n;++i)bs |= (bs<<a[i]);
    int su = 0;
    for(int i=0;i<n;++i)su += a[i];
    for(int i=0;i<=su;++i){
        if(2*i>=su && bs[i]){
            cout<<i<<endl;
            return 0;
        }
    }
    return 0;
}

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

int n, m;

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

    cin >> n >> m;

    priority_queue<int> pque;
    for(int i = 1; i <= n; i++){
        int x;  cin >> x;
        pque.push(x);
    }

    while(m--){
        int u = pque.top();
        pque.pop();
        u /= 2;
        //cerr << u << ' ' << u / 2 << '\n';

        pque.push(u);
    }

    ll ans = 0;
    while(!pque.empty()){
        ans += pque.top();
        pque.pop();
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 892
import sys

S = sys.stdin.read()
S = S.lower()

char_dict = {}
for i in range(97, 97+26):
    char_dict[chr(i)] = 0

for i in S:
    if 97 <= ord(i) < 97+26:
        char_dict[i] += 1

for i in range(97, 97+26):
    print("{} : {}".format(chr(i), char_dict[chr(i)]))



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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

vector<vector<int>> G;
int n, m, a, b;

void dfs(int v, vector<bool> &seen, int &ans) {
  bool ok = true;
  rep(i, n) if (!seen[i] && i != v) ok = false;

  if (ok) ans++;

  seen[v] = true;
  for (auto nv : G[v]) {
    if (seen[nv]) continue;
    dfs(nv, seen, ans);
  }
  seen[v] = false;
}

int main() {
  cin >> n >> m;
  G.assign(n, vector<int>());
  rep(i, m) {
    cin >> a >> b;
    a--, b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  vector<bool> seen(n, false);
  int ans = 0;
  dfs(0, seen, ans);

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
s = input()
N = len(s)
ans = 0
temp = 0
for i in range(2**(N-1)):
	temp = [s[0]]
	for n in range(N-1):
		if (i >> n) & 1:
			ans += int("".join(temp))
			temp = [s[n+1]]
		else:
			temp.append(s[n+1])
	ans += int("".join(temp))
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
const ll N = 1000030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    1e9+7;

int main()
{
int n;
cin>>n;
cout<<(n+1)/2;
}

Measured memory_bytes: 256
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        h: usize,
        w: usize,
        mut aa: [[usize; w]; h],
    }

    let mut count = 0;
    let mut from_to = vec![];

    let mut prev = None;

    for i in 0..h {
        let range: Box<dyn Iterator<Item=usize>> = 
        if i % 2 == 0 {
            Box::new(0..w)
        } else {
            Box::new((0..w).rev())
        };

        for j in range {
            if let Some((x, y)) = prev {
                from_to.push((x+1, y+1, i+1, j+1));
                aa[i][j] += 1;
            }

            if aa[i][j] % 2 != 0 {
                prev = Some((i,j));
            } else {
                prev = None;
            }
        }
    }

    println!("{}", from_to.len());
    for (fx, fy, tx, ty) in from_to {
        println!("{} {} {} {}", fx, fy, tx, ty);
    }
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); ++i)
#define RREP(i, x, n) for (int i = x - 1; i >= (int)(n); --i)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, n, 0)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1e9 + 7

using namespace std;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main(void)
{
    int a;
    cin >> a;
    if (a - 2)
    {
        cout << "Hello World" << endl;
    }
    else
    {
        int A, B;
        cin >> A >> B;
        cout << A + B << endl;
    }
    return 0;
}

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

using namespace std;

#define rep(i, x)   for (__typeof(x) i = 0; i < x; i++)
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define debug(x)       { cerr << #x << " = " << x << endl; }
#define repi(i, x)  for (__typeof(x) i = x-1; i >= 0; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;
typedef vector<vector<int> > vvi;
typedef pair<ll, ll>   pairl;
typedef vector<ll>     vl;
typedef vector<ll>     vll;
typedef vector<vector<ll> > vvl;
const   int            infi = numeric_limits<int>::max();
const   ll             infl = numeric_limits<ll>::max();
const   double         eps = 0;
const   int            ms  = 0;
const ll MOD = 1000000007;



int main()
{
    ios::sync_with_stdio(false);//endl->"\n"
    cin.tie(0);
    int N;
    cin >> N;
    vl A(N);
    rep(i, N)cin >> A[i];
    ll ans = 1;
    vl C(3,0);
    rep(i, N){
        int c = 0;

        rep(j, 3){
            if(C[j] == A[i]){
                c++;
                if(c == 1){
                    C[j]++;
                }
            }
        }
        
    ans = (ans*c)%MOD;

    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
#include<numeric>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;


//最大公約数
template<class T> T gcd(T a, T b)
{
	while (true)
	{
		T r;
		if (a%b == 0) return b;
		else
		{
			r = a % b;
			a = b;
			b = r;
		}
	}
}
//最小公倍数
template<class T> T lcm(T a, T b)
{
	return a / gcd(a, b)*b;
}
//文字0~9をint型0~9に変換
int char_to_int(char c)
{
	if (c == '0') return 0;
	if (c == '1') return 1;
	if (c == '2') return 2;
	if (c == '3') return 3;
	if (c == '4') return 4;
	if (c == '5') return 5;
	if (c == '6') return 6;
	if (c == '7') return 7;
	if (c == '8') return 8;
	if (c == '9') return 9;
	else return -1;
}
//a^b mod MODを計算
long long int ModPower(long long int a, long long int b, long long int MOD)
{
	if (b == 0) return 1;
	else if (b % 2 == 0)
	{
		long long int d = ModPower(a, b / 2, MOD);
		return (d*d) % MOD;
	}
	else
	{
		return (a*ModPower(a, b - 1, MOD)) % MOD;
	}
}
//nCr mod MODを計算
long long int ModCombi(long long int n, long long int r, long long int MOD)
{
	if (n == 0 || r == 0) return 1;

	long long int Kn = 1, Kr = 1, Knr = 1;

	long long int temp = 1;
	for (long long int i = 1; i <= n; i++)
	{
		temp *= i;
		temp %= MOD;
		if (i == n) Kn = temp;
		if (i == r) Kr = temp;
		if (i == n - r) Knr = temp;
	}

	long long int x = ModPower(Kr, MOD - 2, MOD);
	long long int y = ModPower(Knr, MOD - 2, MOD);

	long long int ans;
	ans = Kn * x;
	ans %= MOD;
	ans *= y;
	ans %= MOD;

	return ans;
}
//int型10進数をord桁のstring型2進数に変換する
string binary(int x, int ord)
{
	int y;
	string ans = "";
	for (int i = 0; i < ord; i++)
	{
		y = x / (int)pow(2, ord - 1 - i);
		y %= 2;
		if (y == 0) ans += "0";
		else ans += "1";
	}

	return ans;
}
//ord桁のstring型2進数をint型10進数に変換する
int rep_binary(string x, int ord)
{
	int res = 0;
	for (int i = 0; i < ord; i++)
	{
		if (x[i] == '1') res += (int)pow(2, ord - 1 - i);
	}
	return res;
}


/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/

int nb(char a)
{
	return 0 + (a - 'a');
}

int D[100005][26];
char s[100005], t[100005];

int main()
{
	cin >> s >> t;
	int ls = strlen(s);
	int lt = strlen(t);

	D[ls - 1][nb(s[0])] = 1;
	for (int i = 1; i < ls; i++)
	{
		D[i - 1][nb(s[i])] = 1;
	}
	for (int i = 0; i < ls; i++)
	{
		int x = i - 2;
		if (x < 0) x += ls;
		int y = 2;
		while (true)
		{
			if (D[x][nb(s[i])] == 0)
			{
				D[x][nb(s[i])] = y;
				x--;
				if (x < 0) x += ls;
				y++;
			}
			else break;
		}
	}

	long long int ans;
	int pos;
	if (t[0] == s[0])
	{
		ans = 1;
		pos = 0;
	}
	else
	{
		if (D[0][nb(t[0])] == 0)
		{
			cout << -1 << endl;
			return 0;
		}
		else
		{
			ans = 1 + (long long int)D[0][nb(t[0])];
			pos = ans - 1;
		}
	}
	for (int i = 1; i < lt; i++)
	{
		int p = D[pos][nb(t[i])];
		if (p == 0)
		{
			cout << -1 << endl;
			return 0;
		}
		else
		{
			ans += p;
			pos = (pos + p) % ls;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 10624
import collections
N, M = map(int, input().split())
G = collections.defaultdict(list)
for _ in range(M):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a)
    
dist = [-1] * (N + 1)
que = collections.deque()

dist[1] = 0
que.append(1)

while len(que):
    v = que.popleft()
    for nv in G[v]:
        if dist[nv] != -1:
            continue
        dist[nv] = dist[v] + 1
        que.append(nv)

memo = collections.defaultdict(int)
memo[0] = 1

print('Yes')
for i in range(2, N+1):
    memo[dist[i]] = i
for dis in dist[2:]:
    print(memo[dis-1])

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

#define CIN1(a) long long a;cin >> a;
#define CIN2(a,b) long long a,b;cin >> a >> b;
#define CIN3(a,b,c) long long a,b,c;cin >> a >> b >> c;
#define rep(i,n) for(int i=0,i##_len=(n); i<i##_len; ++i)

int main(){
    CIN1(d) 
    string ans;
    switch (d){
    case 22:ans = "Christmas Eve Eve Eve";break;
    case 23:ans = "Christmas Eve Eve";break;
    case 24:ans = "Christmas Eve";break;
    case 25:ans = "Christmas";break;
    }
    cout << ans << endl;
}

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

int main(){
  int N; cin >> N;
  vector<long long> A(100001,0);
  for(int i=0; i<N; i++){
    int a; cin >> a;
    A[a]++;
  }
  long long sum=0;
  for(long long i=1; i<=100000; i++){
    sum+=A[i]*i;
  }
  
  int Q; cin >> Q;
  for(int i=0; i<Q; i++){
    long long B,C; cin >> B >> C;
    long long b=A[B],c=A[C];
    sum-=b*B;
    A[B]=0;
    sum+=b*C;
    A[C]+=b;
    cout << sum << endl;
  }
}

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

int main() {
	int N;
	cin >> N;
	int cnt = 0, max = 0;
	int before;
	cin >> before;
	for (int i = 1; i < N; i++) {
		int tmp;
		cin >> tmp;
		if (before >= tmp) {
			cnt++;
		} else {
			max = std::max(cnt, max);
			cnt = 0;
		}
		before = tmp;
	}
	max = std::max(cnt, max);
	cout << max << endl;
}


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


int main() {

    int h, w;
    cin >> h >> w;
    char a[110][110], b[102][102];
    for (int i = 0; i < h; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < h + 2; ++i) {
        for (int j = 0; j < w + 2; ++j) {
            b[i][j] = '#';
        }
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            b[i+1][j+1] = a[i][j];
        }
    }
    for (int i = 0; i < h + 2; ++i) {
        for (int j = 0; j < w + 2; ++j) {
            cout << b[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
def main():
    N,X = map(int,input().split())
    L=[int(i) for i in input().split()]
    Ls = 0
    count = 1
    for i in range(N):
        Ls = Ls+L[i]
        #print(Ls)
        if Ls<=X:
            count+=1
    print(count)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
/*input
11 14
3 1 4 1 5 9 2 6 5 3 5
8 9 7 9 3 2 3 8 4 6 2
*/

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll INF = 2001001001001;
// typedef pair<ll, int> pli;

int main() {
    int n;
    ll k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    vector<ll> f(n);
    rep(i, n) cin >> f[i];

    sort(a.begin(), a.end());
    sort(f.begin(), f.end(), greater<ll>());

    // vector<pli> c(n);
    // rep(i, n) {
    //     pli p = {a[i]*f[i], a[i]};
    //     c[i] = p;
    // }
    // sort(c.begin(), c.end(), greater<pli>())

    ll lb = 0, ub = INF;
    rep(i, 100) {
        ll mid = (lb+ub)/2;
        ll t = 0;
        rep(i, n) {
            t += max((ll)0, a[i]-mid/f[i]);
        }
        if (t > k) lb = mid;
        else ub = mid; 
    }
    cout << ub << endl;
}

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

const int nm = 2e5;
int n, d, a, l[nm];long long ans = 0;
pair<int, int> m[nm];

//bit
long long bit[nm + 1];
void add(int i, int x) {
	i++;
	for (int j = i; j <= nm; j += j & -j)
		bit[j] += x;
}
long long sum(int i) {
	long long rv = 0;
	for (int j = i; j > 0; j -= j & -j)
		rv += bit[j];
	return rv;
}
long long sum(int l, int r) {
	return sum(r) - sum(l);
}

int main() {
	cin >> n >> d >> a;
	for (int i = 0, x, h; i < n; i++) {
		cin >> x >> h;
		h = (h + a - 1) / a;
		m[i] = make_pair(x, h);
	}
	sort(m, m + n);
	for (int i = 0, j = 0; i < n; i++) {
		while (m[j].first < m[i].first - 2 * d)
			j++;
		l[i] = j;
	}
	for (int i = 0; i < n; i++) {
		long long r = m[i].second-sum(l[i], i);
		if (r >0) {
			ans += r;
			add(i,r);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 4096
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll fac(ll a) { return a > 1 ? fac(a - 1) * a : 1; }
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int>v(n);
  rep(i,n)cin >> v[i];
  sort(v.rbegin(),v.rend());
  ll ans = 0;
  REP(i,1,n)ans += v[i];
  if(v[0] < ans)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256