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

int main(){
  int n;
  cin >> n;
  vector<int> S(13, 0);
  vector<int> H(13, 0);
  vector<int> C(13, 0);
  vector<int> D(13, 0);
  
  for(int i = 0; i < n; i++){
    char a;
    int b;
    cin >> a >> b;
    if(a == 'S') S.at(b - 1) = 1;
    if(a == 'H') H.at(b - 1) = 1;
    if(a == 'C') C.at(b - 1) = 1;
    if(a == 'D') D.at(b - 1) = 1;
  }
  
  for(int i = 0; i < 13 ; i++){
    if(S.at(i) == 0) cout << 'S' << " " << i + 1 << endl;
  }
  for(int i = 0; i < 13 ; i++){
    if(H.at(i) == 0) cout << 'H' << " " << i + 1 << endl;
  }
  for(int i = 0; i < 13 ; i++){
    if(C.at(i) == 0) cout << 'C' << " " << i + 1 << endl;
  }
  for(int i = 0; i < 13 ; i++){
    if(D.at(i) == 0) cout << 'D' << " " << i + 1 << endl;
  }
}



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

string y[3],s;
int p;
long long f(int x){
	if( x == 3 ){
		if( s[p] == '(' ){
			p++;
			long long ans = f(0);
			p++;
			return ans;
		}else{
			long long ans = 0;
			while( s[p] >= '0' && s[p] <= '9' )
				ans = ans * 10 + s[p++] - '0';
			return ans;
		}
	}else{
		long long ans = f(x+1);
		while( y[x].find(s[p]) != -1 ){
			if( s[p] == '+' ){
				p++;
				ans += f(x+1);
			}else if( s[p] == '-' ){
				p++;
				ans -= f(x+1);
			}else if( s[p] == '*' ){
				p++;
				ans *= f(x+1);
			}
		}
		return ans;
	}
}
int main(){
	cin >> s;
	s += "~";
	long long ans;
	int fl = 0;
	for(int i = 0 ; i < 3 ; i++){
		for(int j = 0 ; j < 3 ; j++){
			for(int k = 0 ; k < 3 ; k++){
				y[0] = y[1] = y[2] = "";
				y[i] += "+";
				y[j] += "-";
				y[k] += "*";
				p = 0;
				if(!fl){
					ans = f(0);
					fl =1;
				}else ans = max(ans,f(0));
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1200
#include "bits/stdc++.h"
#define ll long long
#define ALL(x) x.begin(),x.end()
using namespace std;

vector<ll> v[250000];
int c[250000]={0};
vector<pair<ll,ll>> px;


void ser(ll pre,ll now){
if(pre!=-1){
  c[now]+=c[pre];
}

  for(ll i=0;i<v[now].size();i++){
    if(v[now][i]!=pre){
      ser(now,v[now][i]);
    }
  }


}

int main(){
ll n,q;
cin>>n>>q;
ll tmp,tmp1,tmp2;
for(ll i=0;i<n-1;i++){
  cin>>tmp>>tmp1;
  v[tmp-1].push_back(tmp1-1);
  v[tmp1-1].push_back(tmp-1);
}

for(ll i=0;i<q;i++){
  cin>>tmp>>tmp1;
  c[tmp-1]+=tmp1;
}



ser(-1,0);

ll ans=0;
for(ll i=0;i<n;i++){
  cout<<c[i]<<" ";
}

}


Measured memory_bytes: 24704
#include <cstdio>

using namespace std;

int n, A[50];

int solve(int i, int m)
{
    if (m == 0) return 1;
    if (i == n) return 0;
    int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
    return res;
}

int main()
{
    int q, M;

    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", &A[i]);
    scanf("%d", &q);
    for (int i = 0; i < q; i++) {
        scanf("%d", &M);
        if (solve(0, M)) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}



Measured memory_bytes: 2696
#include <bits/stdc++.h>
using namespace std;
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main()
{
    COMinit();

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

    for (int i = 1; i <= k; i++) {
        cout << (COM(n - k + 1, i) * COM(k - 1, i - 1)) % MOD << endl;
    }

    return 0;
}

Measured memory_bytes: 12160
N=int(input())
if N < 105:
    print(0)
elif 105 <= N and N < 135:
    print(1)
elif 135 <= N and N < 165:
    print(2)
elif 165 <= N and N < 189:
    print(3)
elif 189 <= N and N < 195:
    print(4)
elif 195 <=N :
    print(5)

Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	return n
}

func main() {
	sc.Split(bufio.ScanWords)
	m, d := getInt(), getInt()

	var t1, t2, ans int
	for i := 1; i <= m; i++ {
		for j := 1; j <= d; j++ {
			if j < 10 {
				t1 = 0
			} else {
				t1 = j / 10
			}
			t2 = j % 10
			if t1 >= 2 && t2 >= 2 && i == t1*t2 {
				ans++
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

Ai = 0
Bi = 0
t = 0
result = 0

while True:
    if Ai>=N:
        break
    elif t + A[Ai] <= K:
        t += A[Ai]
        Ai += 1
    else:
        break
result = Ai

while True:
    if Bi >=  M:
        break
    if t + B[Bi] <= K:
        t += B[Bi]
        Bi += 1
        if Ai+Bi > result:
            result = Ai+Bi
    else:
        if Ai < 1:
            break
        t -= A[Ai-1]
        Ai -= 1

print(result)

Measured memory_bytes: 40452
s = input()
a = "keyence"
if s[:7] == a or s[-7:] == a:
    print("YES")
else:
    pos = 0
    for i in range(7):
        if s[i] != a[i]:
            pos = i
            break
    # print(pos, a[-7 + pos :])
    if a[-7 + pos :] == s[-7 + pos :]:
        print("YES")
    else:
        print("NO")


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

#define mp                  make_pair
#define F                   first
#define S                   second
#define pb                  push_back
#define FOR(i,j,n)          for(int i=j;i<n;i++)
#define F0R(i,j,n)          for(int i=j;i<=n;i++)
#define RFOR(i,j,n)         for(int i=n-1;i>=j;i--)
#define RF0R(i,j,n)         for(int i=n;i>=j;i--)
#define FOREACH(x,v)        for(auto x:v)
#define ITFOR(it,v)         for(v::iterator it =v.begin();it!=v.end();++it)
#define __in_arr__(a,j,n)   FOR(i,j,n)cin >> a[i];
#define __out_arr__(a,j,n)  FOR(i,j,n)cout << a[i];
#define LOG                 cout << "[ !" << __LINE__ << "L ] " << endl;
#define PLOG(x)             cout << "[ !" << __LINE__ << "L ] " \<<x<<endl;

using namespace std;

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

map<int,bool> m;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int N;
    cin >> N;
	FOR(i,0,N){
		int x;cin >> x;
		m[x] = !m[x];
	}
	int ans = 0;
	for(auto x : m)
		if(x.S)
			ans ++;
	cout << ans << endl;
    return 0;
}


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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using namespace std;

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

    int a, b, c; cin >> a >> b >> c;
    a*b*c == 175 ? cout << "YES" : cout << "NO";
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
using intl = int64_t;
using graph = vector<vector<int> >;
int main(){
    int d,t,s;
    cin >> d >> t >> s;
    if(d<=t*s){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3620
#include<iostream>
#include<iomanip>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<vector>
#include<functional>
#include<complex>

using namespace std;

typedef long long            ll;
typedef unsigned             ui;
typedef unsigned long long   ull;
typedef pair<int,int>        i_i;
typedef pair<ll,int>         ll_i;
typedef pair<ll,ll>          ll_ll;
typedef pair<double,int>     d_i;
typedef pair<double,double>  d_d;
typedef vector<int>          vi;
typedef vector<vector<int> > vii;

#ifdef DEBUG
#define dprintf      printf
#define dputs        puts
#define dout(x)      cout<<#x" = "<<(x)<<endl
#define darray(x,n)  {int i;rep(i,n)cout<<#x"["<<i<<"] = "<<*((x)+i)<<endl;}
#define dloop(i,s,g) for(int (i)=(s);(i)<(g);(i)++)
#define drep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define dstop()      scanf("%*c")
#else
#define dprintf      (1)?0:printf
#define dputs        (1)?0:puts
#define dout(x)
#define darray(x,n)
#define dloop(i,s,g) if(int i=0){}else
#define drep(i,n)    if(int i=0){}else
#define dstop()
#endif

#define F    first
#define S    second
#define pb   push_back
#define mp   make_pair

#define loop(i,s,g) for((i)=(s);(i)<(g);(i)++)
#define rep(i,n)    for((i)=0;(i)<(n);(i)++)
#define all(x)      (x.begin(),x.end())
#define in(T,...) T __VA_ARGS__; impl(__VA_ARGS__)
#define array(T,id,n) T id[(n)]; for(int i=0;i<(n);i++)cin>>id[i]
#define putv(n)     cout<<(n)<<endl

//#define int long long
#ifndef int
#define INF __INT32_MAX__
#else
#define INF __INT64_MAX__
#endif

void impl(){};
template <typename T,typename... TS >
void impl(T &head,TS &... tail)
{
  cin>>head;
  impl(tail ...);
}

signed main(void)
{
  in(int,a,b,c);
  if(a==b)
    putv(c);
  else if(a==c)
    putv(b);
  else
    putv(a);
  return 0;
}


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

int main()
{
	int n; cin>>n;
	int ar[n];
	for(int i=0;i<n;i++) cin>>ar[i];
	int dp[n]={0};
	dp[1]=abs(ar[0]-ar[1]);
	for(int i=2;i<n;i++){
		dp[i]=min(abs(ar[i]-ar[i-1])+dp[i-1],abs(ar[i]-ar[i-2])+dp[i-2]);
	}
//	for(int i=0;i<n;i++) cout<<dp[i]<<" ";
	cout<<dp[n-1]<<endl;
} 


Measured memory_bytes: 1024
import sys


N = int(input())
t, x, y = 0, 0, 0
ans = 'No'
for s in sys.stdin.readlines():
    nt, nx, ny = map(int, s.split())
    T = nt - t
    D = abs(nx - x) + abs(ny - y)
    if T < D or T % 2 != D % 2:
        break
    t, x, y = nt, nx, ny
else:
    ans = 'Yes'

print(ans)


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

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int i,j,n;
    cin>>n;
    int t=n/2;
    vector<double> p(n);
    for(i=0;i<n;i++)
        cin>>p[i];
    vector<vector<double>> prob(n+1);
    prob[1]=vector<double> (t+1,-1);
    prob[1][0]=p[0];
    prob[1][1]=1-p[0];
    for(i=2;i<=n;i++)
    {
        prob[i]=vector<double> (t+1,-1);
        for(j=0;j<=t;j++)
        {
            if(prob[i-1][j]!=-1)
            {
                prob[i][j]=prob[i-1][j]*p[i-1];
            }
        }
        for(j=0;j<t;j++)
        {
            if(prob[i-1][j]!=-1)
            {
                if(prob[i][j+1]==-1)
                    prob[i][j+1]=prob[i-1][j]*(1-p[i-1]);
                else
                {
                    prob[i][j+1]+=prob[i-1][j]*(1-p[i-1]);
                }  
            }   
        }
    }
    double ans=0;
    for(j=0;j<=t;j++)
        ans+=prob[n][j];
    cout<<setprecision(10)<<ans<<endl;

}

Measured memory_bytes: 35584
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 50;
int vis[maxn];
void init()
{
	vis[0] = 1;
	vis[1] = 1;
	for(int i = 2;i < maxn;i ++)
	{
		if(! vis[i])
		{
			vis[i] = 0;
			for(int j = 2*i;j < maxn; j += i)
			{
				vis[j] = 1;
			}
		}
	}
}
int main()
{
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    init();
    vector<int> ans;
    if(n % 2 == 0) ans.push_back(2),n --;
    for(int i = 3;i < maxn;i++){
        if(!vis[i] && i % 10 == 1){
            ans.push_back(i);
            n--;
        }
        if(n == 0) break;
    }
    for(int i = 0;i < ans.size();i++) {
        if(i == ans.size() - 1) cout << ans[i] << endl;
        else cout << ans[i] << " ";
    }
    return 0;
}


Measured memory_bytes: 4224
import java.util.Scanner
import scala.annotation.tailrec

object Main{
  val sc = new Scanner(System.in)
  def main(args: Array[String]): Unit ={
    val n = sc.nextInt

    val l = List.fill(n)(sc.nextInt).sorted(Ordering[Int].reverse)

    val r =
      l.foldLeft(2 * l(0)) {(res, acc) =>
        if(res == acc) res
        else gcd(res, acc)
      }
    println(r)
  }

  @tailrec
  def gcd(a: Int, b: Int): Int ={ (a, b) match{
    case (a , 0) => a
    case _ => if(a < b) gcd(b, a) else gcd(a % b, b)
  }
  }
}

Measured memory_bytes: 72820
import java.util.*;
public class Main{

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);

        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        
        int result = 0;
        for(int i = a; i <= b; i++){
            if(c % i == 0) result++;
            
        }
        System.out.println(result);

    }

}



Measured memory_bytes: 26236
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<int> _size; // 属する連結成分の大きさ

    UnionFind(int N) : par(N), _size(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) {
            par[i] = i;
            _size[i] = 1;
        }
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        _size[ry] += _size[rx];
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(int x){
        int rx = root(x);
        return _size[rx];
    }
};

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> A(M), B(M);
    REP(i, M) {
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
    }
    //cout << "auau" << endl;
    ll Nmax = N * (N - 1) / 2;

    vector<ll> d;
    ll tmp = 0;
    d.push_back(Nmax);
    //cout << "auau" << endl;
    UnionFind U = UnionFind(N);
    //cout << "auau" << endl;

    for (ll i = M - 1; i >= 1; i--){
        //REP(i, N) cout << U.root(i);
        //cout << endl;
        if (U.same(A[i], B[i]))  tmp = 0;
        else{
            int s1 = U.size(A[i]);
            int s2 = U.size(B[i]);
            U.unite(A[i], B[i]);
            tmp = s1 * s2;
            
            //cout << "from" << i << endl;
        }
        //cout << A[i] << B[i] << endl;
        //cout << i <<":" << tmp << endl;
        d.push_back(*(d.end() - 1) - tmp);
    }
    //cout << "auau" << endl;
    for (ll i = d.size() - 1; i >=0; i--) cout << d[i] << endl;

    return 0;
}


Measured memory_bytes: 4596
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

s=input()
dp=[[0]*(len(s)+1) for i in range(4)]
dp[0][0]=1
lst="ABC"
for i in range(len(s)):
    for j in range(3):
        m1=1
        m2=0
        if s[i]=="?":
            m1=3
            m2=1
        
        if lst[j]==s[i]:
            m2=1
        
        dp[j][i+1]+=m1*dp[j][i]
        dp[j+1][i+1]+=m2*dp[j][i]
        dp[j][i+1]%=mod
        
    if s[i]=="?":
        dp[3][i+1]+=3*dp[3][i]
    else:
        dp[3][i+1]+=dp[3][i]
    dp[3][i+1]%=mod

print(dp[-1][-1]%mod)
# print(dp)

Measured memory_bytes: 46572
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int cnt[10];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int a, b, c;
    cin >> a >> b >> c;
    cnt[a]++; cnt[b]++; cnt[c]++;
    for(int i = 1; i <= 9; i++){
        if(cnt[i] == 2){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
//In the name of Allah
#include <iostream>

using namespace std;
long long int n,m;
int main()
{
    cin>>n>>m;
    if(m>n*2)
    {


    n*=2;
    m+=n;
    cout<<m/4;
    return 0;
    }
    cout<<m/2;

    return 0;
}


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

int main() {
    string t, p;
    cin >> t >> p;
    const auto l_t = t.length();
    const auto l_p = p.length();
    if (l_t < l_p) exit(0);
    for (auto i = 0; i <= l_t - l_p; ++i)
        if (t.substr(i, l_p) == p) cout << i << endl;
}


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

Measured memory_bytes: 596
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int D = sc.nextInt();
		int T = sc.nextInt();
		int S = sc.nextInt();
		if(T*S>=D){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}
		sc.close();
	}
}

Measured memory_bytes: 35616
#include <algorithm>
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <climits>
#include <utility>
#include <deque>
using namespace std;

int main()
{
	int n, x;
	cin >> n >> x;
	vector<int> ls(n);
	for (auto& l : ls)cin >> l;

	int boundNum = 1, d = 0;
	for (auto l : ls) {
		d += l;
		if (d <= x)boundNum++;
		else break;
	}

	cout << boundNum << endl;
	return 0;
}

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

int main(){
	int N,M;	
  cin>>N>>M;
  int L[M],R[M];
  for(int i=0;i<M;i++){
  	cin>>L[i]>>R[i];
  }
  int LL=L[0],RR=R[0];
  for(int i=0;i<M;i++){
  	LL=max(LL,L[i]);
    RR=min(RR,R[i]);
  }
  if(LL>RR){
  	cout<<0;
  }else{
  	cout<<RR-LL+1;
  }
  return 0;
  
}

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

int main(){
  int N; cin >> N;
  vector<int> H(N);
  for(int i=0; i<N; i++){
    cin >> H[i];
  }
  int temp_st; temp_st = 0;
  int temp = temp_st;
  int ans; ans = 0; //if0のパターンも書いておく必要がある.
  if(N == 1){
    ans = H[0];
  }else{
    for(int i=0; i<N; i++){
      if(temp <= H[i]){
        temp = H[i];
      }else{
        ans += temp - temp_st;
        temp_st = H[i];
        temp = H[i];
      }
    }
    if(H[N-2]<=H[N-1]){
      ans += H[N-1]-temp_st;
    } //terminal
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
while line = gets
  arr = []
  
  line.chomp!.each_char do |c|
    arr << c.to_i
  end
  
  n = arr.length - 1
  
  n.times do |i|
    (n - i).times do |j|
      arr [j] =  (arr[j] + arr[j + 1]) % 10
    end
  end
  
  puts arr[0]
end

Measured memory_bytes: 6088
#include<iostream>
#include<string>
   
using namespace std;
   
int main(){
    int n;
    int a[11000],b[11000],c[11000],d[11000];
    int t[11000],k[11000];
    cin>>n;
    for(int i=0;i<(n*(n-1))/2;i++){
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        t[i]=0;
    }
    for(int i=0;i<(n*(n-1))/2;i++){
        if(c[i]>d[i])
            t[a[i]]+=3;
        if(c[i]<d[i])
            t[b[i]]+=3;
        if(c[i]==d[i]){
            t[a[i]]++;
            t[b[i]]++;
        }
    }
    int j=1;
    int h=0;
    for(int g=n*3;g>=0;g--){
        for(int i=1;i<n+1;i++){
            if(g==t[i]){
                k[i]=j;
                h++;
            }
        }
        j+=h;
        h=0;
    }
    for(int i=1;i<n+1;i++){
        cout<<k[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 1292
#include<bits/stdc++.h>
using namespace std; 
#define max(a, b) (a < b ? b : a) 
#define min(a, b) ((a > b) ? b : a) 
#define mod 1e9 + 7 
#define FOR(a, c) for (int(a) = 0; (a) < (c); (a)++) 
#define FORL(a, b, c) for (int(a) = (b); (a) <= (c); (a)++) 
#define FORR(a, b, c) for (int(a) = (b); (a) >= (c); (a)--) 
#define INF 1000000000000000003 
typedef long long int ll; 
typedef vector<int> vi; 
typedef vector<long long int> vl; 
typedef pair<int, int> pi; 
typedef pair<long long int, long long int> pl; 
#define F first 
#define S second 
#define pb push_back 
#define POB pop_back 
#define MP make_pair 
int main()
 {
	ll t;
	//cin>>t;
	//while(t--)
	//{
		ll a,b,c,x=0;
	cin>>a>>b>>c;
	for(int i=a;i<=b;i++)
	{if(i%c==0)
	x++;
	}
	cout<<x<<endl;
	//}
	return 0;
}


Measured memory_bytes: 3616
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	int n, a, b, sum = 0,n1,n2,n3,n4,n5;
	scanf("%d%d%d", &n, &a, &b);
	for(int i = 1; i <= n; i++)
	{
		n1 = i/10000;
		n2 = (i - (n1 * 10000))/1000;
		n3 = (i - n1*10000 - n2*1000)/100;
		n4 = (i - n1*10000 - n2*1000 - n3*100)/10;
		n5 = i%10;
		if(n1+n2+n3+n4+n5 >= a && n1+n2+n3+n4+n5 <= b) sum += i;
	}
	printf("%d\n", sum);
	return 0;
}

Measured memory_bytes: 256
# xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]


# xとyの属する集合の併合
def unite(x, y):
    x = find(x)
    y = find(y)

    if x == y:
        return False
    else:
        # sizeの大きいほうがx
        if par[x] > par[y]:
            x, y = y, x
        par[x] += par[y]
        par[y] = x
        return True


# xとyが同じ集合に属するかの判定
def same(x, y):
    return find(x) == find(y)


n, q = map(int, input().split())
par = [-1] * n

for i in range(q):
    j, x, y = map(int, input().split())
    if j == 0:
        unite(x, y)
    else:
        print(1 if same(x, y) else 0)



Measured memory_bytes: 5768
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    set<int> st;
    cin>>n>>k;
    for(int i =1;i<=k;i++){
        int d;
        cin>>d;
        while(d--){
            int a;
            cin>>a;
            st.insert(a);
        }
    }
    cout<<n-st.size()<<endl;
}

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

int main() {   
    //動物の総数がx
    //足の本数の総数がy
    int X;
    int Y;
    cin >> X >> Y;

    string answer = "No";
    for (int t=0; t<=X; t++) {
        for (int k=0; k<=Y; k++) {
            if ((t + k) == X) {
                if ((t * 2) + (k * 4) == Y) {
                    answer = "Yes";
                    break;                    
                }
            }
        }
    }

    cout << answer;
    return 0;
}

Measured memory_bytes: 3576
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.nextLine();
		String T = sc.nextLine();
		int s = S.length();
		int ans = 0;

	    for(int i = 0;i<S.length();i++) {
	    	if(!((S.charAt(i)==(T.charAt(i))))){
	    		ans ++;
	    	}
	    }
	    System.out.println(ans);

	}

}


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

class FirstGrader{
public:
	FirstGrader(int _N);
	~FirstGrader();
	long long int Execute();

private:
	int N;
	int num[100];
	long long int memo[101][21];
	enum PM{Plus, Minus};
	long long int correctEq(int index, int sum);
};

FirstGrader::FirstGrader(int _N) : N(_N){
	for (int i = 0; i < _N; i++){
		cin >> num[i];
	}
	// memoを-1で初期化
	for (int i = 0; i < 101; i++){
		for (int j = 0; j < 21; j++){
			memo[i][j] = -1;
		}
	}
}
FirstGrader::~FirstGrader(){};

long long int FirstGrader::correctEq(int index, int sum){
	if (index == N-2) {
		if (sum == num[N-1]) return 1;
		else return 0;
	}
	if (memo[index][sum] >=0) return memo[index][sum];

	memo[index][sum] = 0;
	if (sum + num[index + 1] <= 20) memo[index][sum] += correctEq(index+1, sum+num[index+1]);
	if (sum - num[index + 1] >= 0) memo[index][sum] += correctEq(index+1, sum-num[index+1]);

	return memo[index][sum];
}

long long int FirstGrader::Execute(){
	return correctEq(0, num[0]);
}

int main(){
	int N;
	cin >> N;
	
	FirstGrader* fg = new FirstGrader(N);
	cout << fg->Execute() << endl;
	
	delete fg;
	return 0;
}

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

int n, ans = 1e9;
vector<int> v;

int test(int u){
  int tot = 0;
  for(int i = 0; i < n; i++){
    tot += ((v[i] - u) * (v[i] - u));  
  }
  return tot;
}

int main(){
  cin>>n;
  v = vector<int> (n);
  for(int i = 0; i < n; i++) cin>>v[i];
  for(int i = 0; i < 100; i++){
  	ans = min(ans, test(i));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
#define rep(i,l,r) for((i)=(l);(i)<(r);(i)++)
#define erep(i,l,r) for((i)=(l);(i)<=(r);(i)++)
#define drep(i,l,r) for((i)=(l);(i)>=(r);(i)--)
#define MOD 1000000007
#define ll long long
#define MAX(a,b) ((a)>(b)?(a):(b))
using namespace std;
int main(){
    int n,i,j;
    cin>>n;
    int b[n],ans=0,a[n];
    rep(i,0,n-1)cin>>b[i];
    a[0]=b[0];
    a[1]=b[0];
    rep(i,1,n-1){
        if(a[i]<b[i])a[i+1]=b[i];
        else{
            a[i]=b[i];
            a[i+1]=b[i];
        }
    }
    rep(i,0,n)ans+=a[i];
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int main(){cout<<fixed<<setprecision(10);
		   ll n,k;
           cin>>n>>k;
           vll v(n);
           rep(i,0,n)cin>>v[i];
           ll sum=0;
           rep(i,0,n){
            sum+=v[i]; 
           }
           ll cnt=0;
           ll ans=0;
           
           while(k>0){
             
            ll back=min(k,cnt);
             ll f=k;
             ll b=0;
             if(k>=n){
               ll val=sum;
               back+=(k-n);
               vll ss(n);
               ss=v;
               sort(all(ss));
               rep(i,0,n){
                 if(ss[i]<0){
                   val-=ss[i];
                 }
                 else break;
               }
               chmax(ans,val);
             }
             else{
               
               while(f>=0){
                 ll val=0;
                 vll ss(0);
                 rep(i,0,f){
                   val+=v[i];
                   ss.pb(v[i]);
                 }
                 rep(i,0,b){
                  val+=v[n-1-i];
                   ss.pb(v[n-1-i]);
                 }
                 sort(all(ss));
                 rep(i,0,back){
                  if(ss[i]<0){
                   val-=ss[i]; 
                  }
                   else break;
                 }
                 chmax(ans,val);
                 //if(val==3)cout<<f<<" "<<b<<" "<<back<<endl;
                 f--;
                 b++;
               }
             }
             k--;
             cnt++;
           }
           cout<<ans<<endl;
}

Measured memory_bytes: 3616
#pragma comment(linker, "/STACK:256000000")
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
#include <set>
#include <array>
#include <unordered_set>
#include <deque>
#include <queue>
#include <iomanip>
#include <fstream>
#include <string>
#include <climits>
#include <sstream>

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define vi vector<ll>
#define pii pair<int, int>
#define fi(n) for(ll i = 0; i < (n); i++)
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define RFOR(i, k, n) for(int i = (k); i >= (n); i--)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define umin(a, b) a = min(a, b)
#define umax(a, b) a = max((ll)a, (ll)b)

//const long long LINF = LLONG_MAX;
//const long long LINF = 1e14;
const int INF = 1e9 + 1;
using namespace std;

int main()
{
	std::ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	vector<ll> v(n);
	fi(n)
		cin >> v[i];
	if (v[0] != 0)
		return cout << -1 << endl, 0;
	ll answ = 0;
	FOR(i, 1, n)
	{
		if (v[i] <= v[i - 1])
			answ += v[i - 1];
		else if (v[i] - v[i - 1] > 1)
			return cout << -1 << endl, 0;
	}
	cout << answ + v.back() << endl;
  	return 0; 
}

Measured memory_bytes: 1792
a = gets.chomp.to_i
e = gets.chomp.to_i
e = gets.chomp.to_i
e = gets.chomp.to_i
e = gets.chomp.to_i
k = gets.chomp.to_i
 
d = e - a

if d > k
  puts ':('
else
  puts 'Yay!'
end

Measured memory_bytes: 1788
def main():
    n = int(input())
    ans = 0
    for a in range(1, 10 ** 3 + 1):
        mb = (n - 1) // a
        if mb < a:
            continue
        ans += 2 * (mb - a) + 1
    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;

int main(void)
{
    int n, m, u, v;
    cin >> n >> m;

    vector<int> deg(n, 0);

    while (m--)
    {
        cin >> u >> v, --u, --v;
        deg[u]++, deg[v]++;
    }

    for_each(deg.begin(), deg.end(), [](int x) { cout << x << endl; });
    return 0;
}


Measured memory_bytes: 3528
import sys
input=sys.stdin.readline
n=int(input())
lr=[list(map(int,input().split())) for _ in range(n)]
lr.sort(key=lambda x:x[0])
lr.sort(key=lambda x:x[1])
mae=[]
l=0
r=10**9
for i in range(n-1):
    ll,rr=lr[i]
    l=max(ll,l)
    r=min(rr,r)
    mae.append(r-l+1)

usi=[]
l=0
r=10**9+1
for i in range(n-1,0,-1):
    ll,rr=lr[i]
    l=max(ll,l)
    r=min(rr,r)
    usi.append(r-l+1)
usi.reverse()

ans=0

for i in range(n-1):
    ans=max(mae[i]+usi[i],ans)

lr2=[(0,-1)]
ll=0
rr=10**9
for i in range(n-1):
    l,r=lr[i]
    ll=max(ll,l)
    rr=min(rr,r)
    lr2.append((ll,rr))
lr3=[(0,-1)]
ll=0
rr=10**9
for i in range(n-1,0,-1):
    l,r=lr[i]
    ll=max(ll,l)
    rr=min(rr,r)
    lr3.append((ll,rr))
lr3.reverse()

ans2=0
for i in range(n):
    l,r=lr[i]
    rr=min(lr2[i][1],lr3[i][1])
    ll=max(lr2[i][0],lr3[i][0])
    d=max(0,rr-ll+1)
    ans2=max(ans2,r-l+1+d)


ans=max(ans,ans2)



print(ans)


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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

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

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll mod = 1000000007;

int main() {
    ll N, A, B;
    cin >> N >> A >> B;
    ll ans = N / (A + B) * A + min(N % (A + B), A);
    cout << ans << endl;
}

Measured memory_bytes: 3640
n = 10
def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d
H, W = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(10)]
d = warshall_floyd(c)
ans = 0
for _ in range(H):
    tmp = list(map(int, input().split()))
    for i in tmp:
        if i == -1:
            continue
        ans += c[i][1]
print(ans)


Measured memory_bytes: 3064
n, k = [int(x) for x in input().split()]
a_list = [int(x) - 1 for x in input().split()]

ci = 0
temp_dict = {0: 0}
temp_list = [0]
for i in range(1, k + 1):
    temp = a_list[ci]
    if temp in temp_dict:
        ci = temp_list[(k - i) % (i - temp_dict[temp]) + temp_dict[temp]]
        break
    temp_dict[temp] = i
    temp_list.append(temp)
    ci = temp
print(ci + 1)

Measured memory_bytes: 32232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,B) for(ll I=0;I<B;++I)
ll MOD=1e9+7;
int main(){
	string s;
	cin>>s;
	reverse(s.begin(),s.end());
	ll dp[13]={};
	dp[0]=1;
	ll ten=1;
	for(char x:s){
		ll dp2[13]={};
		FOR(j,10){
			ll add = ten*j%13;
			if(x=='?'||(j==(x-'0')))FOR(i,13)(dp2[(add+i)%13]+=dp[i])%=MOD;
		}
		FOR(i,13)dp[i]=dp2[i];
		(ten*=10)%=13;
	}
	cout<<dp[5]<<endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
//typedef pair<ll, P> T;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define revrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define f first
#define s second
#define pb push_back

ll mod = 1000000007;
const ll INF = 100000000000010000;

//ll bit[200010];
//ll kai[3010];

//void pres(double A, ll x = 20) { printf("%.20f\n", x); }

/*ll sum(ll i)
{
	i += 1;
	ll t = 0;
	while (i > 0)
	{
		t += bit[i];
		i -= i & -i;
	}
	return t;
}

void update(ll i, ll x)
{
	i += 1;
	while (i <= 200005)
	{
		bit[i] += x;
		i += i & -i;
	}
}*/

/*`ll SAIKI(ll S) {
	for (ll T = S; ; T = (T - 1) & S) {

	}
}*/

void test() {
	cout << "888888888888888888888888" << endl;
}

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

ll pow_mod(ll x, ll y) {
	if (y == 0) return 1;
	if (y % 2 == 1) {
		return x * pow_mod(x, y - 1) % mod;
	}
	else {
		ll half = pow_mod(x, y / 2);
		return half * half % mod;
	}
}

ll div_mod(ll x) {
	return pow_mod(x, mod - 2);
}

/*ll com(ll x, ll y) {
	return kai[x] * div_mod(kai[y] * kai[x - y] % mod) % mod;
	//毎回オーダーlog(n)かかる
}*/

/*void kaijo() {
	kai[0] = 1;
	for (ll i = 1; i <= 3004; i++) {
		kai[i] = kai[i - 1] * i % mod;
	}
}*/

string S;

void solve() {
	cin >> S;
	bool jud = true;
	rep(i, S.length()) {
		if (i % 2 == 0) {
			if (S[i] == 'L') jud = false;
		}
		else {
			if (S[i] == 'R') jud = false;
		}
	}
	if (jud) cout << "Yes" << endl;
	else cout << "No" << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	ll N;
	cin >> N;
}


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

int main(){
  int n, d, sum = 0;
  cin >> n >> d;
  for(int i=0; i < n; i++){
  	double p, q, ans;
    cin >> p >> q;
    ans = pow(p*p+q*q,0.5);
    if(ans <= d){
    	sum += 1;
    }
  }
  cout <<sum <<endl;
}

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

int main(){
  string S;cin>>S;
  string T;cin>>T;
  int ans = 0;
  for(int i=0;i<S.size();i++){
    if(S[i] != T[i]) ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3852
#include<iostream>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long int
#define hell 1000000007LL
using namespace std;
ll power(ll x, ll y, ll z){ 
    if(y==0)
     return 1;
    else
    {
        ll p=power(x,y/2,z);
        if(y%2==0)
         return (p*p)%z;
        else
        return (x*((p*p)%z))%z;
    }}
ll gcd(ll x,ll y)
{
    if(y==0)
     return x;
    else
    return gcd(y,x%y);
}
ll po(ll x)
{
    ll c=0;
    while(x>0)
    {
        x=x&(x-1);
        c++;
    }
    return c;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    ll n,x,t;
    cin>>n>>x>>t;
    ll y=ceil((1.0*n)/x);
    cout<<y*t;}

Measured memory_bytes: 3756
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")
// -------------------</optimizations>--------------------
 
#include <bits/stdc++.h>
 
using namespace std;
 
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define f first
#define s second
#define sz(x) ll(x.size())
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout << (x) << endl
#define watch2(x,y) cout << (x) << " " << (y) << endl
#define watch3(x,y,z) cout << (x) << " " << (y) << " " << (z) << endl
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
 
typedef long long ll;
typedef long double ld; 
typedef pair<ll,ll> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
 
const ll mod = 1e9 + 7;
const int inf = 1e9 + 5;
const int N = 1e5 + 5;

signed main(){
    fastio;
    int i,j,n;
    cin>>n;
    cout<<(n+1)/2;
    return 0;
}

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

int main() {
  int n;
  ll d, a;
  cin >> n >> d >> a;
  vector<P> p(n);
  rep(i, n) { cin >> p[i].first >> p[i].second; }  //座標、体力
  sort(p.begin(), p.end());
  d = d * 2;              //攻撃範囲
  ll tot = 0;             //今与えてるダメージの総和
  queue<pair<ll, ll>> q;  //いつまで有効か、ダメージの大きさ
  ll ans = 0;
  rep(i, n) {
    ll x = p[i].first;
    ll h = p[i].second;
    while (q.size() && q.front().first < x) {
      tot -= q.front().second;
      q.pop();
    }
    h -= tot;
    if (h > 0) {
      ll num = (h + a - 1) / a;
      ans += num;
      ll damage = num * a;
      tot += damage;
      q.emplace(x + d, damage);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vl vector<ll>
#define pl pair<ll,ll>
#define rep(i,b) for(ll i=0;i<b;i++)
#define all(v) (v).begin(),(v).end()

int main(){
ll n,q,Q,t,x;
cin>>n>>q;
stack<ll>S[n];
rep(i,q){
    cin>>Q;
    switch(Q){

        case 1:
            cin>>t;
            if(!S[t].empty())cout<<S[t].top()<<endl;
            break;
        case 2:
            cin>>t;
            if(!S[t].empty())S[t].pop();
            break;
        case 0:
            cin>>t>>x;
            S[t].push(x);
            break;
    }
}
}


Measured memory_bytes: 5152
#include<cstdio>
#include<cstring>
#include<cmath>
#include <cstdlib>
#include<algorithm>
#define eps 1e-8
using namespace std;
const int N = 1000010;
struct Point{
	double x,y;
	Point(){
	}
	Point(double xx,double yy){
		x=xx;
		y=yy;
	}
}p[N];
Point O;
double R;
double sqr(double x){
	return x*x;
}
double dist(Point a,Point b){
	return sqrt(sqr(a.x-b.x)+sqr((a.y-b.y)));
}
Point cnt(Point a,Point b){
	return Point((a.x+b.x)/2,(a.y+b.y)/2.0);
}
Point cnt(Point a,Point b,Point c){   //求三角形abc外心
	double x1=a.x,y1=a.y;
	double x2=b.x,y2=b.y;
	double x3=c.x,y3=c.y;

	double a1=2*(x2-x1);
	double b1=2*(y2-y1);
	double c1=x2*x2+y2*y2-x1*x1-y1*y1;

	double a2=2*(x3-x2);
	double b2=2*(y3-y2);
	double c2=x3*x3+y3*y3-x2*x2-y2*y2;

	double x=(c1*b2-c2*b1)/(a1*b2-a2*b1);
	double y=(a1*c2-a2*c1)/(a1*b2-a2*b1);

	return Point(x,y);
}
int n;
void work(){ //求最小圆
	random_shuffle(p+1,p+n+1);
    O=p[1];
    R=0;
    int i,j,k;
    for(i=2;i<=n;i++){
    	if(dist(O,p[i])<R+eps) continue;
    	O=p[i];
    	R=0;
    	for(j=1;j<i;j++){
    		if(dist(O,p[j])<R+eps) continue;
    		O=cnt(p[i],p[j]);
    		R=dist(O,p[i]);
    		for(k=1;k<j;k++){
    			if(dist(O,p[k])<R+eps) continue;
    			O=cnt(p[i],p[j],p[k]);
    			R=dist(O,p[i]);
			}
		}
	}
	printf("%.18f\n",R);
}


int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	  scanf("%lf%lf",&p[i].x,&p[i].y);
    work();
	return 0;
}


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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define pb push_back
#define ins insert
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)

#define pi 3.1415926535897932384626433832
const int pinf=LLONG_MAX;
const int ninf=LLONG_MIN;
const int mod=1000000007;

using namespace std;

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("../in.txt","r",stdin);
    //FILE *fptr2=freopen("out.txt","w",stdout);


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

    vector <pair <int,int> > a(m);

    loop(i,0,m)
    {
        cin>>a[i].first>>a[i].second;
    }

    sort(all(a));

    int l=a[0].first;
    int r=a[0].second;

    loop(i,1,m)
    {
        if(a[i].first<=r)
        {
            l=a[i].first;
            r=min(r,a[i].second);
        }
        else
        {
            cout<< "0";
            return 0;
        }
    }

    cout<<r-l+1;



    return 0;
}


Measured memory_bytes: 4728
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const ll LINF = 1e18;
const double PI = acos(-1);
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() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vi B;
	REP(i, N) {
		int a;
		cin >> a;
		B.push_back(a);
	}
	vi ans;
	while (!B.empty()) {
		bool deleted = false;
		REPR(i, SZ(B)) {
			if (B[i] == i + 1) {
				ans.push_back(B[i]);
				B.erase(B.begin() + i);
				deleted = true;
				break;
			}
		}
		if (!deleted) {
			cout << -1 << endl;
			return 0;
		}
	}
	rev(ans);
	REP(i, SZ(ans)) {
		cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 256
n=int(input())
dict1={}
flag=0
arr=[]
for i in range(n):
    s=str(input())
    if(i==0):
        dict1[s]=1
        arr.append(s)
    else:
        if(arr[-1][-1]!=s[0]):
            flag=1
        else:
            try:
                dict1[s]+=1
                flag=1
            except:
                KeyError
                dict1[s]=1
            arr.append(s)
if(flag==0):
    print("Yes")
else:
    print('No')



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}


map<ll,int> primeFactorMp(ll n){
	map<ll,int> ret;
	for(ll i=2;i*i<=n;i++)if(n%i==0){n/=i;ret[i--]++;}
	if(n-1)ret[n]++;
	return ret;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll p,q,ans=1;
	cin>>p>>q;
	auto qm=primeFactorMp(q);
	auto pm=primeFactorMp(p);
	for(auto &x:qm){
		x.sc=max(0,x.sc-pm[x.fs]);
		if(x.sc)ans*=x.fs;
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 3228
N = int(input())
H = [int(x) for x in input().split()]
# print(N, H)

ans = 0
while True:
    if sum(H) == 0:
        break
    begin = 0
    end = 0
    for i in range(N):
        if H[i] != 0:
            begin = i
            break
    # print(H, begin, end)
    for i in range(begin, N):
        # print(H[i])
        if H[i] == 0:
            # print('end={}'.format(i - 1))
            end = i - 1
            break
        end = i
    # print(H, begin, end)
    for i in range(begin, end + 1):
        H[i] -= 1
    ans += 1

print(ans)


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin() x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin() x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

ll n, a, b, c;
vll l;
ll ans=LONG_LONG_MAX;

void dfs(ll i, ll x, ll y, ll z, ll mp)
{
	if (i == n){
		if (x==0||y==0||z==0) return;
		ll sum = mp+abs(a-x)+abs(b-y)+abs(c-z);
		ans = min(ans, sum);
		return;
	}
	dfs(i+1, x+l[i], y, z, mp+((x>0)?10:0));
	dfs(i+1, x, y+l[i], z, mp+((y>0)?10:0));
	dfs(i+1, x, y, z+l[i], mp+((z>0)?10:0));
	dfs(i+1, x, y, z, mp);
	return;
}

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> a >> b >> c;
	rep(i, n){
		ll temp;
		cin >> temp;
		l.pb(temp);
	}
	dfs(0, 0, 0, 0, 0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
using namespace std;

void solve(){
  int a, b; cin >> a >> b;
  int ans;
  if((a + b) % 2 == 0) ans = (a + b) / 2;
  else ans = (a + b) / 2 + 1;
  cout << ans << endl;
  return;
}

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


Measured memory_bytes: 256