akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

#define MAX 2000000

void insert(int *,int);
int extractMax(int *);
void maxHeapify(int *,int);


int size;

int main(){
  int input,i,max;
  char order[8];
  int S[MAX];


  for(i=0;i<MAX;i++){
    scanf("%s",order);

    if(order[2]=='d')break;

    else if(order[2]=='s'){
      size++;
      scanf("%d",&input);
      insert(S,input);
    }

    else if(order[2]=='t'){
      max=extractMax(S);
      printf("%d\n",max);
    }
  }


  return 0;

}

void insert(int *S,int k){
  int tmp;
  int s=size;
  /*if(k < S[k]){
    fprintf(stderr,"new key is smaller than current key\n");
    exit(1);
    }*/
  S[s]=k;
  while(s > 1 && S[s/2] < S[s]){
    tmp=S[s];
    S[s]=S[s/2];
    S[s/2]=tmp;
    s=s/2;
  }

}


int extractMax(int *S){
  int max;
  /* if(size<1){
    fprintf(stderr,"heap underflow");
    exit(2);
    }*/
  max=S[1];
  S[1] = S[size];
  size--;
  maxHeapify(S,1);
  return max;
}

void maxHeapify(int *A,int i){
  int l,r,largest,tmp;
  l=2*i;
  r=2*i+1;
  if(l<=size && A[l]>A[i])
    largest = l;
  else
    largest = i;
  if(r<=size && A[r]>A[largest])
    largest = r;


  if(largest != i){
    tmp=A[i];
    A[i]=A[largest];
    A[largest]=tmp;
    maxHeapify(A,largest);
  }
}  

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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define mem(x,val) memset((x),(val),sizeof(x))
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define PI acos(-1.0) 
#define N 111111

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

int a[30] ;

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

  for(int i = 0 ;i<s.length() ;i++){
    if(a[s[i]-'a']){
      printf("no");
      return 0 ;
    }
    else a[s[i]-'a']++ ;
  }

  printf("yes") ;
	
  return 0 ;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////


int main(){fastio
    ll n;cin>>n;
    string s[n];rep(i,0,n-1)cin>>s[i];
    ll ans=0;
    rep(i,0,n-1){
        if(s[i]=="E869120")ans++;
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3328
use std::io;
use std::io::BufRead;
use std::io::BufReader;

fn main() {
    let reader = io::stdin();
    let mut reader = BufReader::new(reader.lock());

    let mut v = Vec::with_capacity(2);
    for _ in 0..2 {
        let mut s = String::new();
        let _ = reader.read_line(&mut s);
        v.push(s);
    }

    for (x, y) in v[0].chars().zip(v[1].chars()) {
        print!("{}{}", x, y);
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
 
signed main() {
    int n, k;
    while(1){
        cin >> n >> k;
        if(n + k == 0) break;
        vector<string> s(n);
        set<string> st;
        rep(i, 0, n){
            cin >> s[i];
        }
        sort(all(s));
        do{
            string tmp = "";
            rep(i, 0, k){
                tmp += s[i];
            }
            //cout << tmp <<endl;
            if(st.count(tmp)) continue;
            st.insert(tmp);
        }while(next_permutation(all(s)));
        cout << st.size() <<endl;
    }
}

Measured memory_bytes: 3260
#define _CRT_SECURE_NO_WARNINGS
//#define DEBUG
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

void sort(int[], int, int, int[]);

int main(void) {
#ifdef DEBUG
	printf("");
#endif

	char S[100][101];
	char tmp[101];
	int N, L;
	int i, j, k;

	scanf("%d %d", &N, &L);

	for (i = 0; i < N; i++) {
		scanf("%s", &S[i]);
	}
	for (i = 0; i < N-1; i++) {
		for (j = i + 1; j < N; j++) {
			k = 0;
			while (S[i][k] == S[j][k]) {
				k++;
			}
			if (S[i][k] > S[j][k]) {
				strcpy(tmp,S[i]);
				strcpy(S[i],S[j]);
				strcpy(S[j], tmp);
			}
		}
	}

	for (i = 0; i < N; i++) {
		printf("%s", S[i]);
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define fio ios_base::sync_with_stdio(false)
using namespace std;
int main(){
  ll n,q;
  cin>>n;
  unordered_map<ll ,ll >mp;
  ll sum=0;
  for(int i=0;i<n;i++){
    ll a;
    cin>>a;
    mp[a]++;
    sum+=a;
  }
  cin>>q;
  while(q--){
  ll a,b;
  cin>>a>>b;
//cout<<mp[a]<<" "<<mp[b]<<"\n";
   ll k = mp[a];
    mp.erase(a);
    mp[b]+=k;
    sum=sum-k*a+k*b;
    cout<<(sum)<<"\n";
     }
  }


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

int main(){
  int n;
  cin>>n;
  map<string,long long>m;
  for(int i=1;i<=n;i++){
    string s=to_string(i);
    char F=s[0],S=s.back();
    string x="";
    x+=F;
    x+=S;
    // cout<<s<<' '<<x<<'\n';
    m[x]++;
  }
  long long answer=0;
  for(pair<string,long long>p:m){
    string s=p.first;
    if(s[0]==s[1]){
      answer+=p.second*p.second;
    }
    else{
      swap(s[0],s[1]);
      answer+=p.second*m[s];
    }
  }
  cout<<answer;
}

Measured memory_bytes: 256
n,m = list(map(int,input().split()))
ans = [-1] * n
total = 0
  
for i in range(m):
  s,c = list(map(int,input().split()))
  if ans[s-1] != -1 and ans[s-1] != c:
    print(-1)
    exit()
  
  else:
    ans[s-1] = c
  
if ans[0] == 0 and n >= 2:
  print(-1)
  exit()
  
elif ans[0] == -1 and n >= 2:
  ans[0] = 1
  
for i in range(n):
  if ans[i] == -1:
    ans[i] = 0
    
a = 0  
for i in range(n-1, -1, -1):
  total += ans[i] * 10**a
  a += 1

print(total)

Measured memory_bytes: 3064
from collections import Counter
import sys
input = sys.stdin.readline

N = int(input())
*A, = map(int, input().split())
C = Counter(A)
S = sum(A)

Q = int(input())
for _ in [0]*Q:
    b, c = map(int, input().split())
    if b not in C:
        print(S)
        continue
    S += (c-b)*C[b]
    C[c] += C[b]
    C[b] = 0
    print(S)


Measured memory_bytes: 21160
#include <stdio.h>
#include <math.h>
int main(void){  
  float A;
  float B;
  scanf("%f %f", &A,&B);
  //float c = (B-1)/(A-1);
  int y = (int) ceil((B-1)/(A-1));	
  printf("%d\n", y);
  

  return 0;
}

Measured memory_bytes: 128
x,n = map(int,input().split())
p = list(map(int,input().split()))
cnt = 0
sop = sorted(p)
for i in range (len(sop)):
    sop[i] -= x
while True:
    if -cnt not in sop:
        print(x-cnt)
        break
    elif cnt not in sop:
        print(x+cnt)
        break
    else:
        cnt +=1

Measured memory_bytes: 9216
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <set>
#include <map>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll W, H, x, y;
  std::cin >> W >> H >> x >> y;
  std::cout << (double)(W*H)/2 << " ";
  if(2*x==W&&2*y==H){
    std::cout << 1 << '\n';
  }else if(2*x==W|2*y==H){
    std::cout << 0 << '\n';
  }else{
    std::cout << 0 << '\n';
  }
  return 0;
}


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

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

int main() {
    int X; cin >> X;
    int Y; cin >> Y;
    int Z; cin >> Z;

    cout << Z << " " << X << " " << Y << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int n,m,x; 
	cin>>n>>m; 
	int a[n][2],b[n],c[m][2],d[n];
	for(int i=0;i<n;i++){
		for(int j=0;j<2;j++){
			cin>>a[i][j];
		}
	}
	for(int i=0;i<m;i++){
		for(int j=0;j<2;j++){
			cin>>c[i][j];
		}
	}
	for(int k=0;k<n;k++){;
		for(int l=0;l<m;l++){
			x=abs(a[k][0]-c[l][0])+abs(a[k][1]-c[l][1]);
			if(b[k]>x||l==0) {b[k]=x; d[k]=l+1;}
		}
	}
	for(int y=0;y<n;y++){
		cout<<d[y]<<endl;
	}
	return 0;
}



Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<cstring>
#include<bitset>
#include<stack>

#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define ALL(x) x.begin(),x.end()
#define mst(var,val) memset(var,val,sizeof(var))
#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ls rt<<1
#define rs rt<<1|1
#ifdef local
#define dbg(a) cout << #a": " << a << endl;
#else
#define dbg(a)
#endif // loacl


using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <double, double> pdd;
const ll inf=0x3f3f3f3f;
const long long INF=0x3f3f3f3f3f3f3f3fLL;
const double PI=acos(-1.0);
const long double eps=1e-6;
const int mod=998244353;
const int maxn=1e6+10;
const int N=1e5+10;
const int M=N<<1;
const ll mm=(1LL<<32);

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

template <class T>
inline void write(T x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    T y = 1;
    int len = 1;
    for (; y <= x / 10; y *= 10) ++len;
    for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}
ll qpow(ll a,ll b,ll MOD)
{
    ll ans=1;
    while(b)
    {
        if(b&1) ans=(ans*a)%MOD;
        b>>=1;
        a=(a*a)%MOD;
    }
    return ans;
}

double a[105];
int main()
{
#ifdef local
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
#endif // local
    IOS;
    int n;cin>>n;
    double sum=0;
    rep1(i,n)
    {
        double x;
        cin>>x;
        sum+=1.0/x;
    }
    sum=1.0/sum;
    printf("%.10f",sum);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    string s;
    cin>>s;
    for(int i=0;i<s.length();i++){
        if((i+1)%2==0&&s[i]=='R'){
            cout<<"No"<<endl;
            return 0;
        }
        if(i%2==0&&s[i]=='L'){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> t(n+3), v(n+2);
    for (int i = 2; i <= n+1; i++) cin >> t[i];
    for (int i = 1; i <= n; i++) cin >> v[i];
    partial_sum(begin(t), end(t), begin(t));

    double p = 0, ans = 0;
    for (double a = 0; a <= t.back(); a += .5) {
        priority_queue<double, vector<double>, greater<double>> pq;
        for (int i = 0; i < n+2; i++) pq.push(v[i] + max({ t[i] - a, a - t[i+1], .0 }));
        ans += 0.25 * (p + pq.top());
        p = pq.top();
    }

    cout << fixed << setprecision(10) << ans << endl;
}


Measured memory_bytes: 256
# C - Bugged
# DP Overkill

N = int(input())
s = [int(input()) for _ in range(N)]

dp = [0] + [-1]*sum(s)

while s:
    x = s.pop()
    for idx in reversed(range(len(dp))):
        if dp[idx] != -1 and idx + x <= len(dp) - 1:
            dp[idx+x] = dp[idx] + x
            
dp = set(dp)
if -1 in dp : dp.remove(-1)
dp = list(dp)
dp.sort(reverse = True)

for idx in range(len(dp)):
    if idx == len(dp) - 1:
        print(0)
    elif dp[idx] % 10 > 0:
        print(dp[idx])
        break

Measured memory_bytes: 3944
#B
A,B,C = list(map(int,input().split()))
K = int(input())

ans='No'
for k in range(K+1):
    k_b=k
    k_c=K-k
    
    if A < B*(2**k_b) and B*(2**k_b) < C*(2**k_c):
        ans='Yes'
    
print(ans)

Measured memory_bytes: 9176
#include<iostream>
using namespace std;
int main()
{
    int n,k;
    int maximum = -9999,repl = - 9999;
    cin >> n;
    int arr[n];
    for(int i = 0;i < n;i++)
    {
        cin >> arr[i];
        if(maximum < arr[i])
         {
            maximum = arr[i];
            k = i;
         }
    }
    for(int i = 0;i < n;i++)
    {
        if(i != k)cout << maximum << endl;
        else
        {
            for(int j = 0;j < n ;j++)
            {
                if(j != k)
                {
                    if(repl < arr[j])
                        repl = arr[j];
                }
            }
            cout << repl << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 2432
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()
 
#define REP(i,s,e)	for(int i=(s); i<(e); i++)
#define rep(i,n)	REP(i,0,n)
#define REPE(i,s,e)	for(int i=s; i>e; i--)
#define repe(i,n)	REPE(i,n,-1)


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<vi> vvi;
 
const int IMAX=((1<<30)-1)*2+1;
const int INF=100000000;
const double EPS=1e-10;
//int mod=1000000007




int main(){
	int n;
	while(cin >> n && n > 0){
		n = 1000 - n;
		int ans = 0;
		ans += n / 500;
		n %= 500;
		ans += n / 100;
		n %= 100;
		ans += n / 50;
		n %= 50;
		ans += n / 10;
		n %= 10;
		ans += n /5;
		n %= 5;
		ans += n / 1;
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1160
<?php
fscanf(STDIN, "%d", $n);

while ($n--) {
  $data[trim(fgets(STDIN))] = 1;
}

fscanf(STDIN, "%d", $m);

$isOpen = 0;
while ($m--) {
  $id = trim(fgets(STDIN));
  if (isset($data[$id])) {
    $isOpen ^= 1;
    if ($isOpen) {
      printf("Opened by %s\n", $id);
    } else {
      printf("Closed by %s\n", $id);
    }
  } else {
    printf("Unknown %s\n", $id);
  }
}

Measured memory_bytes: 6612
#include <bits/stdc++.h>
using namespace std;
     
int main() {
  string a;
  cin >> a;
  
  if (a.at(a.size()-1) == '0' || a.at(a.size()-1) == '1' || a.at(a.size()-1) == '6' || a.at(a.size()-1) == '8')
    cout << "pon" << endl;
  else if (a.at(a.size()-1) == '3') cout << "bon" << endl;
  else cout << "hon" << endl;
}

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

public class Main {

  public static void main(String[] args) {
    new Main().run();
  }

  public void run() {

    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(in.readLine());

      String[] lines;
      int maxK=0,maxV=0;
      int a,b;
      for(int i=0; i<n; i++) {
        lines = in.readLine().split(" ");
        a = Integer.parseInt(lines[0]);
        b = Integer.parseInt(lines[1]);
        if(a > maxK) {
          maxK = a;
          maxV = b;
        }
      }

      int ans = maxK + maxV;

      System.out.println(ans);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

Measured memory_bytes: 44144
x,k,d = map(int,input().split())
ans = 0
if x-k*d >=0:
    ans = x-k*d
elif x+k*d <= 0:
    ans = -(x+k*d)
else:
    a = -(x-k*d)//(2*d)
    ans = min(- (x+(2*a-k)*d),x+(2*(a+1)-k)*d)

print(ans)


Measured memory_bytes: 9128
#include <bits/stdc++.h> //JuniorMonster a.k.a Sho10
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio();cin.tie();cout.tie();
using namespace std;
ll n,min1=mod,x,ans,y;
int32_t main(){
CODE_START;
cin>>n;
cin>>x;
for(ll i=0;i<n;i++){
    cin>>y;
    min1=min(min1,y);
    x=x-y;
    ans++;
}
cout<<ans+x/min1;
return 0;}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn main() {
    println!(
        "{}",
        match read::<usize>() {
            25 => "Christmas",
            24 => "Christmas Eve",
            23 => "Christmas Eve Eve",
            _ => "Christmas Eve Eve Eve",
        }
    );
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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;}
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e17;
/* warshall_floyd(dist)
    入力：初期化した dist
    計算量：O(|V|^3)
    副作用：dis[i][j]にiからjへの最短路のコストを格納
*/
void warshall_floyd(vector<vector<long long>> &dist) {
    int V = dist.size();
    for (int k = 0; k < V; k++) {
        for (int i = 0; i < V; i++) {
            for (int j = 0; j < V; j++) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }
}

int main() {
    int h,w;
    cin >> h >> w;
    vector<vector<ll>>dist(10,vector<ll>(10,INF));
    rep(i,10) rep(j,10) {
        ll a;
        cin >> a;
        dist[i][j] = a;
    }
    warshall_floyd(dist);
    ll ans = 0;
    rep(i,h) rep(j,w) {
        int a;
        cin >> a;
        if(a==-1) continue;
        ans += dist[a][1];
    }
    cout << ans << endl;
}



Measured memory_bytes: 3656
main = getContents>>=print.solve.map read.tail.words

solve::[Int]->Int
solve (d:x:as) =x+eat d as

eat::Int->[Int]->Int
eat d [] =0
eat d (a:as) | (mod d a)==0 =(div d a) + (eat d as)
    | otherwise =(div d a) + 1 + (eat d as)

Measured memory_bytes: 892
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(long long int i = K; i < N; i++)
#define ll long long int
using namespace std;

vector<vector<ll>> V;
vector<bool> seen(200010, 0);
vector<ll> Ans(200010, 0);

void dfs(ll x){

    ll L = V[x].size();

    seen[x] = 1;

rep(i, 0, L){

    if(seen[V[x][i]])continue;

    Ans[V[x][i]] += Ans[x];

    dfs(V[x][i]);
    
}

}

int main(){
ll N, Q;cin >> N >> Q;

V.resize(N + 1);

rep(i, 1, N){

    ll a, b;cin >> a >> b;

    V[a].push_back(b);
    V[b].push_back(a);

}

rep(i, 0, Q){

    ll p, q;cin >> p >> q;

    Ans[p] += q;

}

dfs(1);

rep(i, 1, N + 1)cout << Ans[i] << endl;

}




Measured memory_bytes: 25168
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int n, m, q;
vector<int> a, b, c, d;
int ans;
 
void dfs(vector<int> A) {
  if (A.size() == n+1) {
    int now = 0;
    rep(i,q) {
      if (A[b[i]] - A[a[i]] == c[i]) now += d[i];
    }
    ans = max(ans, now);
    return;
  }
 
  A.push_back(A.back());
  while (A.back() <= m) {
    dfs(A);
    A.back()++;
  }
}
 
int main() {
  cin >> n >> m >> q;
  a = b = c = d = vector<int>(q);
  rep(i,q) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  dfs(vector<int>(1,1));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef vector<double> dvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
#define fs first
#define sc second
int main()	{
  string s,t;
  cin>>s>>t;
  t+=s;
  cout<<t<<endl;
}

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

Measured memory_bytes: 128
from itertools import product

n = int(input())

tfs = set()
for i in range(1,10):
    tfs |= set(product(['3', '5', '7'], repeat=i))

cnt = 0
for l in tfs:
    if ('3' in l) and ('5' in l) and ('7' in l):
        num = int(''.join(l))
        if num <= n:
            cnt += 1
print(cnt)


Measured memory_bytes: 16552
ans = [0,0,0,0]
for i in range(3):
    a = list(map(int,input().split()))
    for i in a:
        if i==1: ans[0]+=1
        elif i==2: ans[1]+=1
        elif i==3: ans[2]+=1
        else: ans[3]+=1
n = [0,0]
for i in ans:
    if i==1:
        n[0]+=1
if n[0]==2:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3064
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int r, g;
    cin >> r >> g;
    cout << (2 * g - r) << endl;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s: String = read();

    println!("{}", match s.as_str() {
        "SUN" => 7,
        "MON"=> 6,
        "TUE"=> 5,
        "WED"=> 4,
        "THU"=> 3,
        "FRI"=> 2,
        "SAT"=> 1,
        _ => 0,
    });
    
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <numeric>
#include <set>
#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
using namespace std;

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

	int N, K;
	string S;

	cin >> N >> K >> S;
	
	S[K - 1] = tolower(S[K - 1]);

	cout << S << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#define pb push_back
std::vector<int> vec[2005]; 
int main()
{
	int k = 44, n = k * (k - 1) + 1, cnt = 0; 
	printf("%d %d\n", n, k);
	for (int i = 0; i < k; i++)
	{
		for (int j = 0; j < k - 1; j++)
			vec[cnt].pb(j * k + i); 
		vec[cnt++].pb(n - 1); 
	}
	for (int i = 0; i < k - 1; i++)
	{
		for (int j = 0; j < k - 1; j++)
		{
			int y = j; 
			for (int x = 0; x < k - 1; x++)
			{
				vec[cnt].pb(y * k + x); 
				y = (y + i) % (k - 1); 
			}
			vec[cnt++].pb(i * k + k - 1); 
		}
	}
	for (int i = 0; i < cnt; i++)
	{
		for (int j = 0; j < k; j++)
			printf("%d%c", vec[i][j] + 1, " \n"[j + 1 == k]);
	}
	return 0;
}


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

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int k; string s;
    cin >> k >> s;
    if (s.size() > k) {
        cout << s.substr(0,k);
        cout << "...";
        cout << endl;
    }
    else cout << s << endl;
    return 0;
}


Measured memory_bytes: 3656
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	m, _ := strconv.Atoi(sc.Text())

	v := make([]bool, n+1, n+1)
	for i := 0; i <= n; i++ {
		v[i] = false
	}
	g := make(map[int][]int)
	for i := 0; i < m; i++ {
		sc.Scan()
		x, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		y, _ := strconv.Atoi(sc.Text())
		g[x] = append(g[x], y)
		g[y] = append(g[y], x)
		sc.Scan()
	}

	answer := 0
	st := make([]int, 0)
	for i := 1; i <= n; i++ {
		if !v[i] {
			answer++
			v[i] = true
			st = append(st, i)
			for len(st) > 0 {
				j := st[len(st)-1]
				st = st[:len(st)-1]
				for _, k := range g[j] {
					if !v[k] {
						v[k] = true
						st = append(st, k)
					}
				}
			}
		}
	}
	fmt.Println(answer)
}


Measured memory_bytes: 14976
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define rep(i,n) for (ll i=0;i<(n);i++)
typedef long long ll;
bool aaa[11111111];
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

 
int main() {
  ll n,c,aan,m,w=0,memo=0,sx=0,sy=1,ans=0,gx,gy;
  string ka,ss;
  bool flag=true,flag1=false;
  cin>>n>>c>>m;
  if(n<0)n*=-1;
  w=(ll)((n-(n%m))/m);
  aan=c;
  c-=w;
  if(c<1)cout<<n-m*aan<<endl;
  else{
    if(c%2==0)cout<<n%m<<endl;
    else cout<<-((n%m)-m)<<endl;
  }
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] = max(d[i],x);
    }
  }
  T get_max(int i) {//sum of [0,i]
    T x = 0;
    for (i++; i; i -= i&-i) {
      x = max(x,d[i]);
    }
    return x;
  }
  T sum(int l, int r) {// sum of [l,r)
    return sum(r-1) - sum(l-1);
  }
};
int dp[220000];
signed main(){
    int n;cin >> n;
    int h[n],a[n];
    rep(i,n)cin >> h[i];
    rep(i,n)cin >> a[i];
    BIT<int> bit(n);

    vector<P> hoge;
    rep(i,n){
        hoge.emplace_back(h[i],i);
    }
    sort(hoge.begin(),hoge.end());
    int ans = 0;
    rep(i,n){
        int j = hoge[i].second;
        if(j-1 >= 0)dp[j] = bit.get_max(j-1) + a[j];
        else dp[j] = a[j];
        //trace(j,dp[j]);
        ans = max(ans,dp[j]);
        bit.add(j,dp[j]);

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

Measured memory_bytes: 12632
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    H, W = map(int, input().split())
    S = [list(input()) for _ in range(H)]

    for i in range(H):
        for j in range(W):
            if j > 0 and S[i][j - 1] != "." and S[i][j] == "#":
                S[i][j] = "*"
            elif j < W - 1 and S[i][j + 1] != "." and S[i][j] == "#":
                S[i][j] = "*"
            elif i > 0 and S[i - 1][j] != "." and S[i][j] == "#":
                S[i][j] = "*"
            elif i < H - 1 and S[i + 1][j] != "." and S[i][j] == "#":
                S[i][j] = "*"

    print("No" if sum([s.count("#") for s in S]) else "Yes")


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
long long n, s, x, mn=9e9, a[200005];
int main() {
	int i;
	scanf("%lld", &n);
	for(i=0; i<n; i++) scanf("%lld", &a[i]), s += a[i];
	for(i=0; i<n-1; i++) {
		x += a[i];
		mn = min(mn, (long long)abs(s-2*x));
	}
	printf("%lld", mn);
	return 0;
}

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

using namespace std;

#define sp << " " <<

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
    }
    int dp[n];
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++)
    {
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    }
    cout << dp[n-1];
	return 0;
}


Measured memory_bytes: 1024
import sys
import math
INF=1e9
mod=1e9+7

def gcd(a,b):
    if (b==0):
        return a
    return gcd(b,a%b)
 
def lcm(a,b):
    return (a//gcd(a,b))*b
 

n,m=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
g=1
init=0
for i in range(n):
    a[i]//=2
num=a[0]
while(num%2==0):
    num/=2
    init+=1
for i in range(1,n):
    num=a[i]
    cnt=0
    while(num%2==0):
        num/=2
        cnt+=1
    if(cnt!=init):
        print(0)
        sys.exit()
for i in range(n):
    g=lcm(g,a[i])
#print(g)
ans=(m//g)
if(ans%2==1):
    print(ans//2+1)
else:
    print(ans//2)

Measured memory_bytes: 14244
fun main(args:Array<String>) {
    val (h,w) = readLine()!!.split(" ").map { it.toInt() }
    val target = (1..h).map { readLine()!!.map { it }.toMutableList() }.toMutableList()

    var flag = true
    while (flag) {
        flag = false
        if(target.isNotEmpty()) {
            for(i in target[0].lastIndex downTo 0) {
                if(target.all { it[i] == '.' }) {
                    target.forEach { it.removeAt(i) }
                    flag = true
                }
            }
            for(i in target.lastIndex downTo 0) {
                if(target[i].all { it == '.' }) {
                    target.removeAt(i)
                    flag = true
                }
            }
        }
    }
    target.forEach { println(it.joinToString("")) }
}




Measured memory_bytes: 38628
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const ll INF=1e+18;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

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

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

int main(){
    ll N,K;
    cin>>N>>K;
    vector<ll> A(N);
    vector<ll> F(N);
    REP(i,N) cin>>A[i];
    REP(i,N) cin>>F[i];
    sort(A.begin(),A.end());
    sort(F.begin(),F.end(),greater<ll>());
    ll l,r,mid;
    l=-1;
    r=INF;
    while(r-l>1){
        mid=(l+r)/2;
        ll cnt=K;
        REP(i,N){
            if(A[i]>mid/F[i]){
                cnt-=(A[i]-mid/F[i]);
            }
        }
        if(cnt<0){
            l=mid;
        }else{
            r=mid;
        }
    }
    cout<<r<<endl;
}

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

int INF = 1001001001;

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

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

int main() {
    int h, n;
    cin >> h >> n;
    vector<vector<int>> dp(n+1, vector<int>(h+1));
    rep(i,n+1)rep(j,h+1) {
        if (j == 0) dp[i][j] = 0;
        else dp[i][j] = INF;
    }
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        for (int j = 0; j <= h; j++) {
            chmin(dp[i+1][j], dp[i][j]);
            if (j - a >= 0) chmin(dp[i+1][j], dp[i+1][j-a] + b);
            else chmin(dp[i+1][j], b);
            //chmin(dp[i+1][j], dp[i][j]);
        }
    }
    cout << dp[n][h] << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

#define N_MAX 200002
typedef pair<ll, ll> P;

const ll MOD = 1000000007;

ll inv[N_MAX],fac[N_MAX],finv[N_MAX];

void init(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<N_MAX;i++){
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        fac[i]=fac[i-1]*(ll) i%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

ll comb(ll n, ll r){
  ll ans;
  if(n < r){
      ans = 0;
  }else{
      ans = (fac[n]*finv[r])%MOD;
      ans = (ans*finv[n-r])%MOD;
      ans = (ans+MOD)%MOD;
  }
  return ans;
}

ll N, K;
ll A[100000];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    init();
    cin >> N >> K;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    sort(A, A+N);
    ll ans = 0;
    for(int i = 0; i < N; i++){
        if(i+K-1 < N){
            ans -= comb(N-i-1, K-1)*A[i];
            ans %= MOD;
            ans += MOD;
            ans %= MOD;
        }
        if(i-K+1 >= 0){
            ans += comb(i, K-1)*A[i];
            ans %= MOD;
        }
    }
    cout << ans << endl;
}

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

typedef long long int ll;
typedef vector<long long>lve;
typedef vector<pair<ll,ll> > lvp;
typedef vector<pair<string,ll> > svp;

#define spc        ' '
#define endl       '\n'
#define F          first
#define S          second
#define pp         pop_back
#define pb         push_back
#define mp         make_pair 
#define GCD(x,y)   __gcd(x,y)
#define PI         2*acos(0.0)
#define lb         lower_bound
#define bs         binary_search
#define all(x)     x.begin(),x.end()
#define LCM(x,y)   ((x*y)/__gcd(x,y))
#define btpc       __builtin_popcountll
#define sp(x)      cout<<fixed<<setprecision(x)

const   long long  cs=2e5+5;
const   long long  inf=1e18;
const   long long  mod=1e9+7;
void solve()
{
    ll t,n,m,a,b,c,d,e,i,j,k,x,y,z,cnt=0,cnt1=0;
    bool flag = false;   vector<long long> v,v1;

    cin>>a>>b>>c;
    if(a==5) cnt++;
    else cnt1++;
    if(b==5) cnt++;
    else cnt1++;
    if(c==5) cnt++;
    else cnt1++;
    if(cnt==2 && cnt1==1) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);    cout.tie(NULL);

    /*freopen ("input.txt","r",stdin);
    freopen ("output.txt","w",stdout);*/

    // ll tc;
    // cin>>tc;
    // while(tc--)
    solve();

    return 0;
}


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

typedef struct BC{
  int b;
  int c;
}BC;

int cmp(const void *a,const void *b){
  return *(long long int*)a - *(long long int*)b;
}
int cmpst(const void *a,const void *b){
  return ((BC*)b)->c - ((BC*)a)->c;
}

int main(void){
  int n,m,i,j,pos=0;
  long long int ans=0;
  scanf("%d %d",&n,&m);
  long long int a[n];
  BC bc[m];
  
  for(i=0;i<n;i++) scanf("%lld",&a[i]);
  for(i=0;i<m;i++) scanf("%d %d",&bc[i].b,&bc[i].c);
  
  qsort(a,n,sizeof(long long int),cmp);
  qsort(bc,m,sizeof(struct BC),cmpst);
  
  for(i=0;i<m;i++){
    for(j=0;j<bc[i].b;j++){
      if(bc[i].c<=a[pos]) break;
      a[pos++]=bc[i].c;
    }
  }
  
  for(i=0;i<n;i++) ans += a[i];
  printf("%lld\n",ans);
  
  return 0;
}

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

int N,M;
string w[111];
int p[111];
string S;
int cost[111];

typedef pair<int,int> P;
vector<P> H[211];
set<int> dp[211];
int dp2[2111];
void init(){
  for(int i=0;i<=M;i++) H[i].clear();
  for(int i=0;i<=M;i++) dp[i].clear();
  memset( dp2, -1,sizeof( dp2 ) );
}


void solve1(){
  dp[0].insert( 0 );
  for(int i=0;i<M;i++){
    for( P np : H[i] ) {
      int to = np.first;
      for( int num : dp[i] ){
        int nc = np.second + num;
        dp[to].insert( nc );
      }
    }
  }
}

const int INF = (1<<29);
int solve2(int num){
  int &ret = dp2[num];
  if( ret != -1 ) return ret;
  if( num == 0 ) return ret = 0;
  ret = INF;
  for( int i=0;i<N;i++ )
    if( num - p[i] >= 0 )
      ret = min( ret, solve2( num - p[i] ) + cost[i] );
  return ret;
}

int main(){
  int ttt=1;
  while( cin >> N && N ){
    map<string,vector<int>> mv;
    for(int i=0;i<N;i++){
      cin >> w[i] >> p[i];
      cost[i] = w[i].size();
      mv[w[i]].push_back( i );
    }
    cin >> S;
    M = S.size();
    init();
    
    for(int i=0;i<S.size();i++){
      string s = "";
      for(int j=i;j<S.size();j++){
        s += S[j];
        for( int id : mv[s] ) 
          H[i].push_back( P( j+1, p[id] ) );        
      }
    }

    int res = M;
    solve1();
    if( !dp[M].empty() ) res = min( res, solve2( *dp[M].rbegin() ) );

    cout << "Case " << ttt++ << ": ";
    cout << res << endl;
  }
}

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

typedef long long ll;

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

const ll INF = 1LL << 60;

int N;
ll a[100010][3];
ll dp[100010][3];

int main() {
	cin >> N;
	for(int i=0; i<N; i++)
		for(int j=0; j<3; j++)
			cin >> a[i][j];

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if(j==k) continue;
				chmax(dp[i+1][k], dp[i][j]+a[i][k]);
			}
		}
	}

	ll res=0;
	for(int j=0; j<3; j++) chmax(res, dp[N][j]);
	cout << res << endl;
}


Measured memory_bytes: 4992
#include <cstdio>
#include <vector>

#define MAXN 100009

int ans;
bool viz[MAXN];
std::vector < int > g[MAXN];

bool dfs(int x) {
    viz[x] = 1;
    int cnt = 0;
    bool r = 0;
    for (auto &y : g[x]) {
        if (viz[y] == 0) {
            bool f = dfs(y);
            cnt += 1 - f;
            r |= f;
        }
    }
    if (cnt > 1)
        ans += cnt - 1, r = 1;
    return r;
}

int main() {
    int n;
    scanf("%d", &n);

    int rad = 0;
    for (int i = 1; i < n; i++) {
        int x, y;
        scanf("%d%d", &x, &y);
        x++;
        y++;

        g[x].push_back(y);
        g[y].push_back(x);

        if (g[x].size() > 2)
            rad = x;
        if (g[y].size() > 2)
            rad = y;
    }

    if (rad)
        bool r = dfs(rad);
    else ans = 1;

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

    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll mod_pow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll f[200010],finv[200010];

ll comb(ll n,ll r){
  if(n<0||r<0||n<r)return 0;
  return (f[n]*finv[n-r]%mod)*finv[r]%mod;
}

ll h,w,n;
vector<P> ps;
ll dp[3003][2];

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

  f[0]=1;
  rep(i,200001)f[i+1]=f[i]*(i+1)%mod;
  rep(i,200001)finv[i]=mod_pow(f[i],mod-2);
  cin>>h>>w>>n;

  rep(i,n){
    ll r,c;
    cin>>r>>c;
    r--;c--;
    ps.push_back(P(r,c));
  }
  ps.push_back(P(0,0)); ps.push_back(P(h-1,w-1));
  sort(all(ps));
  n=ps.size();
  dp[0][1]=1;
  repl(i,1,n){
    rep(j,i)rep(k,2){
      if(ps[j].fi<=ps[i].fi&&ps[j].se<=ps[i].se){
        ll di=ps[i].fi-ps[j].fi;
        ll dj=ps[i].se-ps[j].se;
        (dp[i][1-k]+=dp[j][k]*comb(di+dj,di)%mod)%=mod;
      }
    }
  }
  cout<<(dp[n-1][0]+mod-dp[n-1][1])%mod<<endl;

  return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
int main()
{
	//std::cout << "Hello, World" << std::endl;
	string s={};
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		s+="ACL";
	}
	cout<<s<<endl;
	return 0;
}


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

int main() {
    int a,b;cin>>a>>b;
    if(b%a==0)cout<<a+b<<endl;
    else cout<<b-a<<endl;
}

Measured memory_bytes: 256
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def S(): return sys.stdin.readline()
def LS(): return sys.stdin.readline().split()
def LS2(N): return [sys.stdin.readline().split() for i in range(N)]
def FILL(i,h,w): return [[i for j in range(w)] for k in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**5+10)
input = sys.stdin.readline

a,b = MI()
print(int((a+b+1)/2))


Measured memory_bytes: 59372
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;
int main()
{
    int W, H, N;
    std::cin >> W >> H >> N;
    std::vector<std::vector<int>> area(100, std::vector<int>(100, 0));
    int x, y, a;
    for (int i = 0; i < N; i++) {
        std::cin >> x >> y >> a;
        if (a == 1) {
            for (int h = 0; h < H; h++) {
                for (int j = 0; j < x; j++) {
                    area.at(h).at(j) = 1;
                }
            }
        }
        if (a == 2) {
            for (int h = 0; h < H; h++) {
                for (int j = x; j < W; j++) {
                    area.at(h).at(j) = 1;
                }
            }
        }
        if (a == 3) {
            for (int h = 0; h < y; h++) {
                for (int j = 0; j < W; j++) {
                    area.at(h).at(j) = 1;
                }
            }
        }
        if (a == 4) {
            for (int h = y; h < H; h++) {
                for (int j = 0; j < W; j++) {
                    area.at(h).at(j) = 1;
                }
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (area.at(i).at(j) == 0) {
                ans++;
            }
        }
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 3660
import itertools

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

num_list = [a, b, c, d, e]
factorial = list(itertools.permutations(num_list, 5))
ans_list = []
for list in factorial:
    tmp = 0
    for i in list:
        if tmp%10 == 0:
            tmp += i
        else:
            tmp += 10 - tmp%10
            tmp += i
    ans_list.append(tmp)

ans_list.sort()
ans = ans_list[0]

print(ans)

Measured memory_bytes: 9176
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    string s;
    int64 k;
    cin >> s >> k;
    int n = s.size();
    for (int i=0; i<n; i++) {
        if (i+1 == k) {
            cout << s[i] << endl;
            return 0;
        }

        if (s[i] != '1') {
            cout << s[i] << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    int n,m,i,j,k;
    string s,t;
    cin>>s>>t;
    int mn=1000;
    for(i=0;i<=(s.size()-t.size());i++){
        k=0;
        for(j=0;j<t.size();j++){
            if(s[i+j]!=t[j]){
               k++;
            }
        }
    mn=min(mn,k);
    }
    cout<<mn<<endl;
    return 0;
}


Measured memory_bytes: 3640
# -*- coding: utf-8 -*-
S = input()
Q = int(input())

reverse = 0
head = []
tail = []
for i in range(Q):
    query = input()
    if len(query) == 1:
        reverse = (reverse + 1) % 2

    else:
        t, F, C = query.split()
        if reverse == 0:
            if F == "1":
                head.append(C)
            else:
                tail.append(C)
        else:
            if F == "1":
                tail.append(C)
            else:
                head.append(C)

if reverse == 0:
    S = ''.join(head[::-1] + list(S) + tail)
else:
    S = ''.join(tail[::-1] + list(S[::-1]) + head)


print(S)


Measured memory_bytes: 9284
s = input()
K = int(input())

sn = len(s)
sub = set()

for subl in range(5+1):
    for i in range(len(s)):
        if i+subl <= sn:
            sub.add(s[i:i+subl])

subsort=sorted(sub)
#print(subsort)
print(subsort[K])



Measured memory_bytes: 4464
#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 3007;

double dp[MAXN][MAXN];
double p[MAXN];

int main()
{
#ifdef LOCAL
    freopen("data.txt", "r", stdin);
#endif
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
        scanf("%lf", &p[i]);
    fill(*dp, *dp + MAXN * MAXN, 1.0);
    for (int j = 1; j <= n; ++j)
        dp[0][j] = dp[0][j - 1] * p[j];
    for (int i = 1, i_ = n / 2 + 1; i != i_; ++i) {
        for (int j = i; j <= n; ++j) {
            dp[i][j] = dp[i - 1][j - 1] * (1 - p[j]) + dp[i][j - 1] * p[j];
        }
    }
    printf("%.9f\n", dp[n / 2][n]);
}

Measured memory_bytes: 70912