akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<deque>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef pair<int,int> P;
template<class T> inline bool chmax(T&a , T b){
    if(a<b){
        a=b; return true;
    }else{
        return false;
    }
}
template<class T> inline bool chmin(T&a , T b){
    if(a>b){
        a=b; return true;
    }else{
        return false;
    }
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

ll memo[402][402];
bool flag[402][402];
int a[402];
ll cum[402];

ll dp(int l,int r){
    if(flag[l][r]) return memo[l][r];
    flag[l][r] = true;
    ll fans=LINF;
    for(int m=l;m<=r-1;m++){
        chmin(fans, dp(l,m)+dp(m+1,r));
    }
    return memo[l][r] = fans + cum[r+1] - cum[l];
}


int main(){
    int n;
    cin >> n;
    rep(i,n) cin >> a[i];

    rep(i,n) flag[i][i] = true;

    cum[0]=0;
    for(int i=0;i<n;i++){
        cum[i+1] = cum[i] + a[i];
    }

    ll ans = dp(0,n-1);
    cout << ans << endl;
}

Measured memory_bytes: 1664
n,x=map(int,input().split())
l=list(map(int,input().split()))
d=[0]
for i in range(n):
    d.append(d[i]+l[i])
#print(d)
ans=0
for i in range(len(d)):
    if d[i]<=x:
        ans+=1

print(ans)

Measured memory_bytes: 38384
/**
 *    author:  tourist
 *    created: 01.08.2019 14:06:11       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, a, b;
  cin >> n >> a >> b;
  if (a % 2 == b % 2) {
    cout << (b - a) / 2 << '\n';
  } else {
    cout << min(a - 1, n - b) + 1 + (b - a - 1) / 2 << '\n';
  }
  return 0;
}


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

int main() {
	int a,b,c;
	cin >>a>>b>>c;
	if(a<=b && b<=c){
		cout <<a<<" "<<b<<" "<<c<<endl;
	} else if(a<=c && c<=b){
		cout <<a<<" "<<c<<" "<<b<<endl;
	} else if(c<=b && b<=a){
		cout <<c<<" "<<b<<" "<<a<<endl;
	} else if(a<=b && c<=a){
		cout <<c<<" "<<a<<" "<<b<<endl;
	} else if(b<=a && a<=c){
		cout <<b<<" "<<a<<" "<<c<<endl;
	} else if(b<=c && c<=a){
		cout <<b<<" "<<c<<" "<<a<<endl;
	}
}



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

int main()
{
	
	string str;
	cin >> str;
	for(int i = 0; i < 4; i++){
		cout << str[i];
	}
	cout << " ";
	for(int i = 4; i < str.size(); i++){
		cout << str[i];
	}
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 256
from collections import deque

def bfs(sx, sy, gx, gy):
    d = [[float('inf')] * W for _ in range(H)]

    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    que = deque()
    que.append((sx, sy))
    d[sy][sx] = 0

    while que:
        p = que.popleft()
        if p[0] == gx and p[1] == gy:
            break
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]                
            if 0 <= ny and ny <= H-1 and 0 <= nx and nx <= W-1 and \
                    grid[ny][nx] != '#' and d[ny][nx] == float('inf'):
                d[ny][nx] = d[p[1]][p[0]] + 1
                que.append((nx, ny))
    return d[gy][gx]


H, W = map(int, input().split())
grid = [list(input()) for _ in range(H)]

a = bfs(0, 0, W-1, H-1)
white = 0
for x in grid:
    white += x.count('.')

if a == float('inf'):
    answer = -1
else:
    answer = white - (a + 1)
print(answer)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std ;
 
int main(){
  int n,m,a,b;
  cin>>n>>m;
  a=min(n,m);
  b=max(n,m);
  
  for(int i=1;i<=b;i++){
    cout<<a;
  }
  cout<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int a[3],b;
	for(int i=0;i<3;i++){
		cin>>a[i];
	}
	
	sort(a,a+3);
	
	cin>>b;
	
	for(int i=0;i<b;i++){
		a[2]=a[2]*2;
	}
	
	b=a[0]+a[1]+a[2];
	
	cout<<b<<endl;
	
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //StringBuilder bd = new StringBuilder();
        ArrayList<String> A = new ArrayList<String>();
        //int[] A = new int[26];
        //Arrays.fill(A, 0);
        //String str;

        while (true) {
            String str = sc.nextLine();
            String newstr = "";
            if (str.equals("-")) {
                for (int i=0; i<A.size(); i++) {
                    System.out.println(A.get(i));
                }
                break;
            }
            int m = sc.nextInt();
            int h = 0;
            for (int i=0; i<m; i++) {
                h += sc.nextInt();
            }
            while (h > str.length()) {
                h -= str.length();
            }
            for (int i=h; i<str.length(); i++) {
                newstr += str.substring(i, i+1);
            }
            for (int i=0; i<h; i++) {
                newstr += str.substring(i, i+1);
            }
            A.add(newstr);
            String dummy = sc.nextLine();
        }

    }
}


Measured memory_bytes: 26736
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    string S;
    ll N, i, j, ans=0, l, r, countl, countr;

    cin >> S;
    N = S.size()+1;

    for(i=0; i<N; i++){
        if(i==0){
            if(S[i]=='<') ans += 0;
            else{
                j = 0;
                while(S[j]=='>'){
                    j++;
                }
                ans += j;
            }
        }

        else if(0<i && i<N-1){
            l = i-1;
            r = i;
            if(i==1){
                countl=0; countr=0;

                while(l>=0 && S[l]=='<'){
                    l--;
                    countl++;
                }
                while(r<=N-2 && S[r]=='>'){
                    r++;
                    countr++;
                }
            }
            else{
                if(S[i-1]=='<'){
                    countl++;
                }
                else{
                    countl = 0;
                }

                if(S[i-1]=='>' && S[i]=='>'){
                    countr--;
                }
                else if(S[i-1]=='<' && S[i]=='>'){
                    j = i;
                    while(S[j]=='>'){
                        j++;
                        countr++;
                    }
                }
                else{
                    countr = 0;
                }
            }

            ans += max(countl, countr);
        }

        else if(i==N-1){
            if(S[i]=='>') ans += 0;
            else{
                j = N-2;
                while(S[j]=='<'){
                    j--;
                }
                ans += N-2-j;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
  string S;
  cin>>S;
  if(S=="hi"||S=="hihi"||S=="hihihi"||S=="hihihihi"||S=="hihihihihi"){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
 
struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;
 
template<typename T1,typename T2>
ostream &operator<<(ostream &os,const pair<T1,T2>&p){
    os<<p.first<<" "<<p.second;
    return os;
}
 
template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
    return os;
}

void generate(){
    const int mx=300;
    cout<<mx<<" "<<mx<<endl;
    rep(i,mx){
        rep(j,mx){
            cout<<'a';
        }cout<<endl;
    }
}

// 今見てる列を左みてどのタイミングで沈めるか決めればいい
signed main(){
    int h,w;cin>>h>>w;
    vector<string> g(h);
    rep(i,h) cin>>g[i];

    ll ans=0;

    ll dp[h+1][h+1],cost[h+1][h+1];
    rep(k,w-1){
        rep(j,h+1){
            ll c=0;
            // cost[0][j]
            for(int ni=0,nj=j;ni<h and nj<h;ni++,nj++)c+=(ll)(g[h-1-ni][k]==g[h-1-nj][k+1]);
            cost[0][j]=c;
            for(int t=1;j+t<=h;t++)cost[t][j+t]=cost[t-1][j+t-1]-(ll)(g[h-1-(t-1)][k]==g[h-1-(j+t-1)][k+1]);
        }
        
        rep(i,h+1){
            ll c=0;
            // cost[0][j]
            for(int ni=i,nj=0;ni<h and nj<h;ni++,nj++)c+=(ll)(g[h-1-ni][k]==g[h-1-nj][k+1]);
            cost[i][0]=c;
            for(int t=1;i+t<=h;t++)cost[i+t][t]=cost[i+t-1][t-1]-(ll)(g[h-1-(i+t-1)][k]==g[h-1-(t-1)][k+1]);
        }

        // cout<<k<<" "<<k+1<<endl;
        // rep(i,h+1){
        //     rep(j,h+1){
        //         cout<<i<<","<<j<<" : "<<cost[i][j]<<endl;
        //     }
        // }
        rep(i,h+1)rep(j,h+1)dp[i][j]=LINF;
        dp[0][0]=0;
        rep(i,h+1)rep(j,h+1){
            ll src=dp[i][j];
            if(i<h)chmin(dp[i+1][j],src+cost[i][j]);
            if(j<h)chmin(dp[i][j+1],src+cost[i][j]);
        }
        ans+=dp[h][h];
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

int main()
{
    int n,k;
    cin>>n>>k;
    int mn =1e9,fst=0,ans=0;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    cout<<ceil((float)(n-1) / (k-1))<<endl;
    return 0;
}


Measured memory_bytes: 640
N=int(input())
a=list()
for i in range(0,N):
	x=input()
	a.append(x)
M=int(input())
b=list()
for i in range(0,M):
	x=input()
	b.append(x)
A=dict()
B=dict()
for i in a:
	x=a.count(i)
	A[i]=x
for i in b:
	x=b.count(i)
	B[i]=x
res=list()
for i in A:
	if i in B:
		A[i]-=B[i]
m=0
#print(A)
#print(B)
for i in A:
	if A[i]>m:
		m=A[i]
#print(A)
print(m)
		

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

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





































Measured memory_bytes: 256
import sys
import numpy as np

stdin = sys.stdin

ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))  # applies to only numbers
rs = lambda: stdin.readline().rstrip()  # ignores trailing space

N = ri()
A = np.array(rl())
c = np.bincount(A)
answer = c[0]

for i in range(1, len(c)-1):
    result = c[i-1] + c[i] + c[i+1]
    if result > answer:
        answer = result

print(answer)
# 32


Measured memory_bytes: 23432
n = int(input())
Adj = [[] for _ in range(n+1)]
C = [[0]*(n+1) for _ in range(n+1)]

for i in range(n):
    tmp = list(map(int,input().split()))
    for j in range(tmp[1]):
        C[tmp[0]][tmp[2+j]] = 1

for i in range(n):
    print(*C[i+1][1:])


Measured memory_bytes: 6388
#include<stdio.h>
main(){
  int N,i,j,S;
  scanf("%d",&N);
  int L[2*N];
  for(i=0;i<2*N;i++)scanf("%d",&L[i]);
  for(i=0;i<2*N-1;i++){
    for(j=i+1;j<2*N;j++){
      if(L[i]>L[j])S=L[i],L[i]=L[j],L[j]=S;
    }
  }
  S=0;
  for(i=0;i<N;i++)S+=L[2*i];
  printf("%d",S);
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
main()
{
    int a,b,c,d;
    int w=0,x=0,y=0,sum1=0,sum2=0;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if (a>b)
    {
      for (x=0;x<b;x++) sum1=sum1+=c;
      w=a-b;
      for (x=0;x<w;x++) sum2=sum2+=d;
      printf("%d",sum1+sum2);
    }
    else printf("%d",a*c);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll maxn=1e5+1;
ll n,a[maxn],b[maxn],c[maxn],dp[3][maxn];
int e;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i]>>b[i]>>c[i];
	dp[0][0]=a[0];dp[1][0]=b[0];dp[2][0]=c[0];
	for(int i=1;i<n;i++)
	{
		dp[0][i]=max(dp[1][i-1],dp[2][i-1])+a[i];
		dp[1][i]=max(dp[0][i-1],dp[2][i-1])+b[i];
		dp[2][i]=max(dp[0][i-1],dp[1][i-1])+c[i];
	}
	cout<<max({dp[0][n-1],dp[1][n-1],dp[2][n-1]})<<endl;
	return 0;
}

Measured memory_bytes: 4992
#pragma GCC optimize("O3")

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pii>
#define read(FILE)  freopen(FILE, "r", stdin);
#define out(FILE) freopen(FILE, "w", stdout);
#define clr(x, y) memset(x,y,sizeof(x));
#define IO ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(),x.end()
#define rep(i, m, n) for(int i=m ; i<n ; i++)
#define forr(i, m, n) for(int i=m ; i<=n ; i++)
#define endl '\n'
#define pb push_back
#define re return
const int N = 2e5 + 2;
const int OO = 1e9 + 7;
using namespace std;
int n;
void dfs(string s, char mx){
    if(s.size()==n){
        cout<<s<<endl;
    }
    else{
        for(char c='a';c<=mx;c++){
            if(c==mx){
                dfs(s+c,char(mx+1));
            }
            else{
                dfs(s+c,mx);
            }
        }
    }
}
int main() {

    IO;
    cin>>n;
    dfs("",'a');


}


Measured memory_bytes: 1536
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

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

		List<Integer> list = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			list.add(sc.nextInt());
		}

		Collections.sort(list);
		
		int sum = 0;
		for (int i = 1; i < list.size(); i++) {
//			if (list.get(i - 1) == list.get(i)){
//				continue;
//			}
			sum += list.get(i) - list.get(i - 1);
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 21844
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 25 00:39:05 2019

@author: yuta
"""

def dic(n,m):
    x = ''.join(sorted(n))
    y = ''.join(sorted(m,reverse = True))
    if x < y:
        print("Yes")
    else:
        print("No")
dic(input(),input())

Measured memory_bytes: 2940
N = gets.to_i
h = gets.split.map{|i| i.to_i}

c = Array.new(N)

c[0] = 0
c[1] = (h[1] - h[0]).abs

for i in 2 .. N - 1
    a = c[i - 1] + (h[i] - h[i - 1]).abs
    b = c[i - 2] + (h[i] - h[i - 2]).abs
    c[i] = (a < b) ? a : b
end

puts c[N - 1]

Measured memory_bytes: 8716
N=int(input())
A=list(map(int,input().split()))
cur=A[0]
ans=0
rp=1

for lp in range(N):
 while rp<N and cur & A[rp]==0:
  cur+=A[rp]
  rp+=1
 ans+=rp-lp
 cur-=A[lp]

print(ans)

Measured memory_bytes: 23560
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    ll n, a, b;
    cin >> n >> a >> b;
    ll r = n / (a+b);
    ll m = n % (a+b);
    cout << r*a + min(a,m);
    return 0;
}


Measured memory_bytes: 256
from fractions import gcd
from functools import reduce
def lcm(x, y):
  return (x * y) // gcd(x, y)
n = int(input())
a = list(map(int, input().split()))
t = reduce(lcm, a, 1) - 1
print(sum(t % a[i] for i in range(n)))


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

int main() {
  string str;
  // cin >> str;
  getline(cin, str);

  rep(i, str.length()) {
    if(!isalpha(str[i])) {
      cout << str[i];
    } else if(islower(str[i])) {
      cout << (char)toupper(str[i]);
    } else {
      cout << (char)tolower(str[i]);
    }
  }

  cout << endl;
  
  return 0;
}



Measured memory_bytes: 3188
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int N,a[100001],odd=0,fours=0;
  cin >> N;
  REP(i,N)cin >> a[i];
  REP(i,N){
    if(a[i] % 4 == 0)
      fours++;
    else if(a[i] % 2 == 1)
      odd++;
  }
  if(odd <= fours || ((odd + fours == N) && (odd - 1 == fours))){
    cout << "Yes" << endl;
  }else
    cout << "No" << endl;
  
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

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



Measured memory_bytes: 640
import Data.List

main :: IO()
main = do
    nx <- map read.words <$> getLine :: IO [Int]
{-
    lis <- scan (nx !! 0)
-}
    lis <- map read.words <$> getLine :: IO [Int]
    let list = sort lis
    print(solve (nx !! 1) list)

{-
scan :: Int -> IO [Int]
scan 0 = return []
scan n = do
    s <- getLine
    l <- scan$ n-1
    return$ s:l
-}

solve :: Int -> [Int] -> Int
solve _ [] = 0
solve x [a]
    | (x == a) = 1
    | otherwise = 0
solve x a
    | x < (a !! 0) = 0
    | otherwise = 1 + (solve (x - (a !! 0)) (tail a))

Measured memory_bytes: 1020
#include <iostream>
#include <vector>
#include <unordered_map>
#include <cmath>
#include <stdlib.h>
#include <queue>
#include <set>
#include <algorithm>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
  ll k, x;
  cin >> k >> x;

  if (k * 500 >= x)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  return 0;
}


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

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

using namespace std;

typedef long long ll;

int main()
{
    ll N;
    cin >> N;
    vector<ll> X(N);
    vector<ll> sortedX(N);
    REP(i, N)
    {
        cin >> X[i];
        sortedX[i] = X[i];
    }
    sort(sortedX.begin(), sortedX.end());

    ll medianOne, medianTwo;
    medianOne = sortedX[N / 2 - 1];
    medianTwo = sortedX[N / 2];
    REP(i, N)
    {
        ll median;
        if (X[i] <= medianOne)
        {
            median = medianTwo;
        }
        else if (X[i] >= medianTwo)
        {
            median = medianOne;
        }
        cout << median << endl;
    }
}


Measured memory_bytes: 5376
// Anve$hi $hukla
#include <bits/stdc++.h>
using namespace std;
struct ${$(){ios_base::sync_with_stdio(false);cin.tie(NULL);}}$;

typedef long long LL;
const int Mod = 1e9 + 7;

int main() {
   int n;
   cin >> n;
   vector <int> a(n), b(n), x(n), y(n);

   for(int i = 0; i < n; i++) {
      cin >> a[i];
   }    
   for(int i = 0; i < n; i++) {
      cin >> b[i];
   }
   x[0] = y[0] = a[0];

   for(int i = 1; i < n; i++) {
      if(a[i] > a[i - 1])
         x[i] = y[i] = a[i];
      else
         x[i] = 1, y[i] = a[i];
   }
   x[n - 1] = max(x[n - 1], b[n - 1]);
   y[n - 1] = min(y[n - 1], b[n - 1]);

   for(int i = n - 2; i >= 0; i--) {
      if(b[i] > b[i + 1]) {
         x[i] = max(x[i], b[i]);
         y[i] = min(y[i], b[i]);
      } else {
         x[i] = max(x[i], 1);
         y[i] = min(y[i], b[i]);
      }
   }
   long long ans = 1;
   for(int i = 0; i < n; i++) {
      if(x[i] > y[i]) {
         cout << 0 << endl;
         return 0;
      }
      ans = ans * (y[i] - x[i] + 1);
      if(ans >= Mod)
         ans %= Mod;
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 1792
"""
辞書
"""
n = int(input())
s = set()
for _ in range(n):
    com,string = input().split()
    if com == "insert":
        s.add(string)
    elif com == "find":
        flg = string in s
        if flg:
            print("yes")
        else:
            print("no")


Measured memory_bytes: 30992
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen(".in.txt", "r", stdin);
	freopen(".out.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n; cin >> n;
	cout << (!(n % 1000) ? 0 : (n/1000 + 1) * 1000 - n);

	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define FASTIO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define vi vector<ll>
#define all(a) (a).begin(), (a).end()
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define tr(it, a)   for(auto it=a.begin();it!=a.end();it++)
#define pb push_back
#define endl  "\n"
#define mem(a,b)  memset(a,b,sizeof(a))
const ll MAX=1e5+3;
const ll mod=1e9+7;
int main()
{
   FASTIO
   int t=1;
   //cin>>t;
   while(t--)
  {
      ll n;cin>>n;
        string a,b,c="";cin>>a>>b;
        rep(i,0,n)
        {
           c+=a[i];
           c+=b[i];
        }
        cout<<c;
   }
 return 0;
}



Measured memory_bytes: 256
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define f first
#define s second
typedef long long ll;
typedef unsigned long long ull;

void IO(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("test.txt","r",stdin);
    #endif
}

const int N=1e6+3,M=1e3+5,mod=1e9+7,dx[]={1,-1,0,0},
                                    dy[]={0,0,1,-1};
const double eps=1e-9;


int tc,n,a[N],b[N],c[N],d[N],m,q;

char s[N];

vector<int> v;

int get(){
    int ans = 0;
    for(int i = 0 ; i < q ; i++)
        if (v[b[i] - 1] - v[a[i] - 1] == c[i])
            ans += d[i];
    return ans;
}

int solve(int last = 1){
    if (sz(v) >= n)
        return get();
    int ans = 0;
    for(int i = last ; i <= m ; i++){
        v.push_back(i);
        ans = max(ans,solve(i));
        v.pop_back();
    }
    return ans;
}

int main(){
    //IO();   
    scanf("%d %d %d",&n,&m,&q);
    for(int i = 0 ; i < q ; i++)
        scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]);
    printf("%d",solve());
}


Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;

string s;
int cache[N][2];

int dp(int idx, int less)
{
	if(idx == s.size())
		return 1;
	int &ans = cache[idx][less];
	if(ans != -1)
		return ans;
	if(!less)
	{
		if(s[idx] == '0')
			ans = dp(idx + 1, less);
		else
		{
			ans = dp(idx + 1, 1);
			ans += 2 * dp(idx + 1, 0);
		}
	}
	else
	{
		ans = dp(idx + 1, 1);
		ans += 2 * dp(idx + 1, 1);
	}
	ans %= MOD;
	return ans;
}

int32_t main()
{
	IOS;
	memset(cache, -1, sizeof(cache));
	cin >> s;
	int ans = dp(0, 0);
	cout << ans;
	return 0;
}

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

int main(){
    int n,m;
    cin >> n >> m;
    priority_queue<P> job;
    priority_queue<int> ok;
    rp(i,n){
        int a,b;
        cin >> a >> b;
        job.push(make_pair(m-a,b));
    }
    ll money=0ll;
    for(int day=m; day>=0; day--){
        bool nxt=false;
        while(!job.empty()){
            P p=job.top();
            if(p.first<day) break;
            job.pop();
            ok.push(p.second);
        }
        if(ok.empty()) continue;
        money+=(ll)ok.top();
        ok.pop();
    }
    cout << money << endl;
    return 0;
}

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

int main() {
	int n, d; cin >> n >> d;
	if (n <= d * 2 + 1) { cout << 1 << endl; return 0; }
	int ans = 1; n = n - d - 1;
	ans += n / (d + d + 1);
	if (n % (d + d + 1) > d) ans++;
	cout << ans << endl;
}


Measured memory_bytes: 256
H,W = map(int,input().split())
S = []
for i in range(H):
    S.append(input())
Ans = "Yes"
for i in range(H):
    for j in range(W):
        check = ""
        if j-1 >= 0:
            check += S[i][j-1]
        if j+1 <= W-1:
            check += S[i][j+1]
        if i-1 >= 0:
            check += S[i-1][j]
        if i+1 <= H-1:
            check += S[i+1][j]
        if S[i][j]=="#" and "#" not in check:
            Ans = "No"
print(Ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll red[100005];
ll green[100005];
ll trans[300005];
ll ans[200005];
//ll Pow(ll base , ll power)
//void sieve_eratosthenes(int n);
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll x,y,a,b,c;
ll v_r=0,v_g=0,v_t=0;
cin>>x>>y>>a>>b>>c ;
for(ll i=0;i<a;i++)cin>>red[i];
for(ll i=0;i<b;i++)cin>>green[i];
for(ll i=0;i<c;i++)cin>>trans[i];
sort(red,red+a,greater<ll>());
sort(green,green+b,greater<ll>());
ll sum =0 ;
int i=0 ;
int xx=x,yy=y;
c++;
while(x|y){
    if(x>0)trans[c++]=red[i],x--;

    if(y>0)trans[c++]=green[i],y--;
    i++;

}

sort(trans,trans+c,greater<ll>());
for(int j=0;j<xx+yy;j++)
{

    sum+=trans[j];
}
cout<<sum<<endl;
}

/*
void sieve_eratosthenes(int n)
    {
bool primes[n+2]={false};
for(int i=3;i<=n;i+=2)
    primes[i]=1;
    primes[2]=1;
for(int i=3;i*i<=n;i+=2)
{
    if(primes[i]==1){
    for(int j=i*i;j<=n;j+=i)
        primes[j]=0;
    }
}
for(int i=2;i<=n;i++)
    if(primes[i]==1)
    cout<<i<<endl;
return;
    }
ll Pow(ll base , ll power)
        {
            if(power==0)return 1;
            ll x = Pow(base,power/2);
            x*=x;
            if(power&1)
                return base*x;
            else
                return x;
        }
*/


Measured memory_bytes: 4224
s = input()
k = int(input())

cnt = 0
# 1の連続数
one_cnt = 0
for i in s:
    cnt += 1

    if i == "1":
        one_cnt += 1

    # 最後の数字までに1以外が含まれなかった場合
    if cnt == len(s):
        ans = 1

    # 1以外の数値が出現した時点でbreak
    if i != "1":
        ans = i
        break

# Kが1の連続カウント数以下の場合、答えは1となる。
if k <= one_cnt:
    print(1)
else:
    print(ans)

Measured memory_bytes: 3060
/// NHDanDz
#include <bits/stdc++.h>
#define nmax 500005
#define MOD 1000000007
#define F first
#define S second
#define PB push_back
#define reset(a) memset(a,0,sizeof(a))
#define pii pair<int,int>
#define ll long long
#define DANGCUTO "COLOR3"
#define endl '\n'
#define sz() size()
using namespace std;
vector <int> s[nmax];
string a;
int in[nmax] , dd[nmax];
ll kq(0);
void DFS(int u , int val)
{
    dd[u] = max(dd[u] , val);
    for(auto v: s[u])
    {
        DFS(v,val + 1);
    }
}
int main()
{
    cin >> a;
    reset(in);
    for(int i = 0 ; i < a.size() ; i++)
    {
        if(a[i] == '<')
        {
            s[i + 1] .PB(i + 2);
            in[i + 2]++;
        }
        else
        {
            in[i + 1]++;
            s[i + 2].PB(i + 1);
        }
    }
    for(int i = 1; i <= a.sz() + 1; i++)
    {
        if(in[i] == 0)
        {
            //cout << i << endl;
            DFS(i,0);
        }
    }
    for(int i = 1; i <= a.size() + 1; i++)
    {
        kq += 1ll*dd[i];
    }
    cout << kq;
    return 0;
}


Measured memory_bytes: 47620
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N int
	fmt.Scan(&N)

	var S string
	var P int
	keys := make([]string, N)
	m := make(map[string]int)
	for i := 0; i < N; i++ {
		fmt.Scan(&S, &P)
		k := S + string(100-P)
		keys[i] = k
		m[keys[i]] = i + 1
	}
	sort.Strings(keys)

	for _, k := range keys {
		fmt.Println(m[k])
	}
}


Measured memory_bytes: 512
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    a, b, c = input().split()
    print((a[0] + b[0] + c[0]).upper())


if __name__ == '__main__':
    main()


Measured memory_bytes: 61944
// by adiforluls
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define FAST         ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll           long long
#define ld           long double
#define pb           push_back
#define mp           make_pair
#define pii          pair<int,int>
#define mii          map<int,int>
#define vi           vector<int>
#define vll          vector<long long>
#define all(a)       (a).begin(),(a).end()
#define clz(a)       __builtin_clz(a) // count leading zeroes
#define ctz(a)       __builtin_ctz(a) // count trailing zeroes
#define popc(a)      __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define lul          1000000007
#define rep(i,a,b)   for(int i=a;i<b;i++)
#define rfor(i,a,b)  for(int i=a; i>=b; i--)
#define SIZE         1000005
#define F            first
#define S            second
#define mod          998244353

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " = " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " = " << arg1<<" |";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define endl         '\n'
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key(k)
// find_by_order(k)
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;

void solve()
{ 
    int n; cin>>n;
    vi a(n);
    rep(i,0,n) cin>>a[i];
    vector<vll> dp(n,vll(n,-1));
    rfor(i,n-1,0)
    {
        rep(j,i,n)
        {
            if(i==j) dp[i][j] = a[i];
            else dp[i][j] = max(a[i]-dp[i+1][j],a[j]-dp[i][j-1]);
        }
    }
    cout<<dp[0][n-1];
} 
int main()
{   
    FAST;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; t=1;
    while(t--){
       solve();
    }
    return 0;
}

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

using ll = long long;
using pii = pair<int, int>;

#define vt          vector
#define sz(x)       (int)(x).size()
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

signed main() {
    ios::sync_with_stdio(0), cin.tie(0);

    int n;
    ll c;
    cin >> n >> c;
    vt<ll> x(n), v(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> v[i];
    }

    ll ans = 0;

    vt<ll> psl(n + 1);
    for (int i = 0; i < n; i++) {
        psl[i + 1] = psl[i] + v[i];
    }
    vt<ll> mxl(psl);
    for (int i = 0; i < n; i++) {
        mxl[i + 1] -= 2 * x[i];
    }
    for (int i = 0; i < n; i++) {
        mxl[i + 1] = max(mxl[i], mxl[i + 1]);
    }

    vt<ll> psr(n + 1);
    for (int i = 0; i < n; i++) {
        psr[n - i - 1] = psr[n - i] + v[n - i - 1];
    }
    vt<ll> mxr(psr);
    for (int i = 0; i < n; i++) {
        mxr[n - i - 1] -= 2 * (c - x[n - i - 1]);
    }
    for (int i = 0; i < n; i++) {
        mxr[n - i - 1] = max(mxr[n - i], mxr[n - i - 1]);
    }

    for (int i = 0; i <= n; i++) {
        ans = max({
            ans,
            psl[i] - (i ? x[i - 1] : 0) + mxr[i],
            psr[i] - (i != n ? c - x[i] : 0) + mxl[i]
        });
    }

    cout << ans;
}


Measured memory_bytes: 7928
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
const int N=2e5+10;
int main()
{
    int a,b,c;
     cin>>a>>b>>c;
       if(c>=a-b)
     cout<<c-(a-b)<<endl;
      else
		 cout<<0<<endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*

data class Edge<T: Comparable<T>>(val from: Int, val to: Int, val weight: T) {
    constructor(from: Long, to: Long, weight: T) : this(from.toInt(), to.toInt(), weight)
}

class Graph<T: Comparable<T>>(val n: Int, val zero: T, val inf: T, val plus: (T, T) -> T) {
    val edges = Array(n) { ArrayList<Edge<T>>() }
}

val INF = 1e+15.toLong()

inline fun <reified T: Comparable<T>>bellmanFord(g: Graph<T>, s: Int): Triple<Array<T>, Array<Int>, Array<Boolean>> {
    val N = g.n
    val dist = Array(N) { g.inf }
    val prev = Array(N) {-1}

    dist[s] = g.zero

    for (k in 1 .. N) {
        for (v in 0 until N) {
            for (e in g.edges[v]) {
                if (dist[e.from] != INF && dist[e.to] > g.plus(dist[e.from], e.weight)) {
                    dist[e.to] = g.plus(dist[e.from], e.weight)
                    prev[e.to] = e.from
                }
            }
        }
    }

    val dist2 = dist.copyOf()
    for (k in 1 .. N) {
        for (v in 0 until N) {
            for (e in g.edges[v]) {
                if (dist2[e.from] != INF && dist2[e.to] > g.plus(dist2[e.from], e.weight)) {
                    dist2[e.to] = g.plus(dist2[e.from], e.weight)
                }
            }
        }
    }

    val affectedByNegativeLoop = Array(N) { idx -> dist[idx] != dist2[idx] }

    return Triple(dist, prev, affectedByNegativeLoop)
}

fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map { s -> s.toInt() }
    val g = Graph(N, 0L, INF) { a: Long, b: Long -> a + b}

    for (i in 1 .. M) {
        val (a, b, c) = readLine()!!.split(" ").map {s -> s.toLong()}
        g.edges[(a - 1).toInt()].add(Edge(a - 1, b - 1, -c))
    }

    val (dist, prev, affectedByNegativeLoop) = bellmanFord(g, 0)

    if (affectedByNegativeLoop[N - 1]) {
        println("inf")
    } else {
        println(-dist[N - 1])
    }
}


Measured memory_bytes: 107544
import sys

N = int(input())
testimonies = {i: [] for i in range(N)}

for i in range(N):
    M = int(input())
    for j in range(M):
        q, r = map(int, input().split(' '))
        testimonies[i].append([q-1, r])

res = 0
for i in range(2**N):

    bit = bin(i)[2:].zfill(N)
    honests = [j for j, b in enumerate(bit) if b == '1']  # 正直者
    flag = True

    for j, b in enumerate(bit):
        # 発言を検証

        if b == '0':
            continue

        for testimony in testimonies[j]:
            if ((testimony[0] in honests) and testimony[1] == 0) or ((testimony[0] not in honests) and testimony[1] == 1):
                flag = False
        
        if not flag:
            break
    
    if flag:
        res_ = sum([1 for k in bit if k == '1'])
        if res < res_:
            res = res_
        
print(res)
                      

Measured memory_bytes: 46044
from functools import reduce
mod=10**9+7
def f(A,B):
 if B==0:
  den=1
  num=1
 else:
  den=reduce(lambda x,y:x*y%mod,range(A,A-B,-1))
  num=reduce(lambda x,y:x*y%mod,range(1,B+1))

 return den*pow(num,mod-2,mod)%mod
n,m=map(int,input().split())
print(f(n,2)+f(m,2))


Measured memory_bytes: 3572
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace At
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Read();
            WriteLine("ABC" + input);
        }

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

using namespace std;

int main(){
	int a[5];
	int ans = 0;
	for (int i = 0; i < 5; i++){
		scanf("%d", a + i);
		if (a[i] == 0){
			ans = i + 1;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 3684
#include <iostream>
#include <vector>
#include <string>
 
using namespace std;
 
int main() {
    int n;
    cin >> n;
    vector<string> blue(n);
    for (int i = 0; i < n; i++) {
        cin >> blue[i];
    }
    int m;
    cin >> m;
    vector<string> red(m);
    for (int i = 0; i < m; i++) {
        cin >> red[i];
    }

    int ans = 0;
    auto calc = [&](string s){
        int buf = 0;
        for(string t: blue){
            if(t == s) buf++;
        }
        for(string t: red){
            if(t == s) buf--;
        }
        return buf;
    };

    for(string t: blue){
        ans =max(ans, calc(t));
    }

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

Measured memory_bytes: 256
/**
 * 
 * AOJ No.0040 Affine Cipher
 * 
 * @author 	yuichirw <y.iky917@gmail.com>
 * @see		http://rose.u-aizu.ac.jp/onlinejudge/ProblemSet/description.jsp?id=0040&lang=jp
 */
import java.util.*;
import static java.lang.Math.*;

public class Main {
	static int n;
	static String line;
	static Scanner sc = new Scanner(System.in);
	
	static boolean read() {
		if(!sc.hasNextLine()) return false; 
		line = sc.nextLine();
		return true;
	}
	
	static String solve() {
		int a = 1;
		while(true) {
			for(int b = 0; b <= 25; b++) {				
				if(a <= 26) {
					if(gcd(26, a) != 1) break;
				} else {
					if(gcd(a, 26) != 1) break;
				}
				
				char[] str = line.toCharArray();
				int r, f;
				for(int i = 0; i < str.length; i++) {
					if(str[i] == ' ') continue;
					r = str[i] - 'a';
					f = (a * r + b) % 26;
					str[i] = (char)(f + 'a');
				}
				
				String _str = new String(str);
				String[] parsed = _str.split(" ");
				for(int i = 0; i < parsed.length; i++) {
					if(parsed[i].equals("that") || parsed[i].equals("this")) {
						return _str;
					}
				}
			}
			a++;
		}
	}
	
	static long gcd(long a, long b) {
		if(b == 0) return a;
		return gcd(b, a % b);
	}
	
	public static void main(String[] args) {
		n = sc.nextInt(); sc.nextLine();
		while(n-- > 0 && read()) {
			System.out.println(solve());
		}
	}
}

Measured memory_bytes: 12000
#include <iostream>

using namespace std;
#define MAX 100000
typedef long long llong;
int n, k;
llong T[MAX];

int check(llong P) {
    int i = 0;
    for (int j = 0; j < k; j++) {
        llong s = 0;
        while (s + T[i] <= P) {
            s += T[i];
            i++;
            if (i == n) {
                return n;
            }
        }
    }
    return i;
}

int solve() {
    llong left = 0;
    llong right = 100000 * 10000;
    llong mid;
    while (right - left > 1) {
        mid = (left + right) / 2;
        int v = check(mid);
        if (v >= n) {
            right = mid;
        } else {
            left = mid;
        }
    }
    return right;
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> T[i];
    }
    llong ans = solve();
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3868
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

       while(sc.hasNext())
       {
           int a = sc.nextInt( );

           String op1 = sc.next();
           char op = op1.charAt(0);

           int b = sc.nextInt( );

          if (op=='+')
              System.out.println(a+b);
          else if (op=='-')
              System.out.println(a-b);
          else if (op=='*')
              System.out.println(a*b);
          else if (op=='/')
              System.out.println(a/b);
          else if (op=='?')
              break;

       }

    }

}



Measured memory_bytes: 26316
//atcoder clange
#include <stdio.h>
int main(void){
    int N;
      scanf("%d", &N);//数値の取得
  int i= 0;
  int A[N];
  for(i=0;i<N;i++){
	scanf("%d",&A[i]);
  }
	int save = 0;
  int max1 = 0;
  
  /*
  for(i=0;i<N;i++){
	save = A[i];
    A[i] = 0;
   	nummax = max(A,N);
    printf("%d\n",nummax);
    A[i] = save;
     } 
     */
  int no_1 = 0;
  int no_2 = 0;
  
  for(i=0;i<N;i++){
	if(no_1 < A[i]){
        no_2=no_1;
        no_1=A[i];
    }else if(no_2 < A[i]){
        no_2=A[i];
    }
  }
    
  for(i=0;i<N;i++){
   if(A[i] == no_1){
    printf("%d\n",no_2); 
   }else{
    printf("%d\n",no_1); 
   }
  }
    
  
    return 0;
}
     
     


Measured memory_bytes: 2304
#include <iostream>
#include <cctype>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <cstring>
#include <fstream>
#include <cmath>
#include <stack>
#include <algorithm>
#include <queue>
#include <iterator>
#include <limits>
#define PI 3.1415926535
#include <sstream>
#define MAX 100
#define swap(a,b,t) (t=a,a=b,b=t)
using namespace std;

bool isvalid(int N,int D)
{
     if(N>=0 && N<D)
     return true;
     return false;
}
     

int main()
        { 
        int q,w,t;
        cin>>q>>w;
        t=max(q,w);
        cout<<max(2*t-1,q+w);
        //system("pause");
        return 0;
        } 
        
        





Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s string
	fmt.Scan(&s)

	for x := 'a'; x <= 'z'; x++ {
		if !strings.Contains(s, string(x)) {
			fmt.Println(string(x))
			return
		}
	}

	fmt.Println("None")
}


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

void trace(int A[], int N){
  for(int i = 0; i < N; ++i){
    if(i > 0) cout << ' ';
    cout << A[i];
  }
  cout << endl;
}

void insertionSort(int A[], int N){
  for(int i = 1; i < N; ++i){
    int v = A[i];
    int j = i - 1;
    while(j >= 0 && A[j] > v){
      A[j+1] = A[j];
      --j;
    }
    A[j+1] = v;
    trace(A, N);
  }
}


int main(){
  int N, A[100];
  cin >> N;
  for(int i = 0; i < N; ++i){
    cin >> A[i];
  }
  trace(A, N);
  insertionSort(A, N);

  return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[310];
int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    ll k = 0;
    for (int i = 2; i < n; i++) {
        k ^= a[i];
    }
    if ((k ^ a[0] ^ a[1]) == 0) {
        cout << 0 << endl;
        return 0;
    }
    if (k > a[0] + a[1]) {
        cout << -1 << endl;
        return 0;
    }
    k = a[0] + a[1] - k;
    if (k % 2 == 1) {
        cout << -1 << endl;
        return 0;
    }
    k /= 2;
    if (a[0] + a[1] < k * 2) {
        cout << -1 << endl;
        return 0;
    }
    if (k >= a[0]) {
        cout << -1 << endl;
        return 0;
    }
    ll lft = a[0] + a[1] - k * 2;
    ll base = a[0];
    a[0] = k;
    for (ll i = 60; i >= 0; i--) {
        if (!((k >> i) & 1)) {
            if (lft >= (1LL << i)) {
                lft -= (1LL << i);
                if (a[0] + (1LL << i) <= base) {
                    a[0] += (1LL << i);
                }
            }
        }
    }
    if (lft) {
        cout << -1 << endl;
        return 0;
    }
    if (a[0] == 0) {
        cout << -1 << endl;
        return 0;
    }
    cout << base - a[0] << endl;
    return 0;
}

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

using namespace std;

int main()
{
    int a, b, c, k, i, x;

    cin >> a >> b >> c >> k;

    if(a >= k)
    {
        x = k;
        k = k - a;
    }
    else
    {
        x = a;
        k = k - a;
    }
    if(k > b)
    {
        k = k - b;
    }
    else
        {
            cout << x << endl;
            return 0;
        }
    if(k)
    {
        x = x - k;
    }

    cout << x << endl;





    return 0;
}


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

using namespace std;

template<class V, class E>
struct Graph
{
	int sz;
	vector<V> v;
	vector<vector<E>> e;
	Graph(int n) : sz(n), v(n), e(n) {}
	template<class... Args>
	inline void assign_vertex(int pos, Args... args) {
		v[pos] = V(args...);
	}
	template<class... Args>
	inline void add_edge(int pos, Args... args) {
		e[pos].emplace_back(args...);
	}
	inline int size() {
		return sz;
	}
};
struct Vertex{};
using vertex = Vertex;
struct Edge
{
	int to;
	int cost;
	Edge(int t, int c) : to(t), cost(c) {}
	Edge() {}
};

using edge = Edge;
using graph = Graph<vertex, edge>;

int Diameter(graph& G) {
	auto dfs = [&G](auto f, int start, int& goal, int par = -1) -> int {
		goal = start;
		int res = 0;
		for (auto& e: G.e[start]) {
			if (e.to == par) continue;
			int t;
			int r = f(f, e.to, t, start);
			r += e.cost;
			if (r > res) {
				res = r;
				goal = t;
			}
		}
		return res;
	};
	int g;
	dfs(dfs, 0, g);
	return dfs(dfs, g, g);
}

int main() {
	int N;
	cin >> N;
	graph G(N);
	for (int i = 0; i < N - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--;b--;
		G.add_edge(a, b, 1);
		G.add_edge(b, a, 1);
	}
	int d = Diameter(G);
	if (d % 3 == 1) cout << "Second" << endl;
	else cout << "First" << endl;
}

Measured memory_bytes: 18560
#include <iostream>

using namespace std;

int main()
{
	int n;
	cin >> n;
	
	long long ans = 1;
	for(int i = 1; i <= n; i++)
	{
		ans *= i;
		ans %= (1000000000 + 7);
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N, K, L = map(int, input().split())
E = [[] for i in range(N)]
for i in range(K):
  p, q = map(int, input().split())
  E[p-1].append(q-1)
  E[q-1].append(p-1)
F = [[] for i in range(N)]
for i in range(L):
  r, s = map(int, input().split())
  F[r-1].append(s-1)
  F[s-1].append(r-1)
C = list(range(N))
for n in range(N):
  if C[n] != n:
    continue
  q = [n]
  while q:
    c = q.pop()
    ds = E[c]
    for d in ds:
      if C[d] != n:
        C[d] = n
        q.append(d)
D = list(range(N))
for n in range(N):
  if D[n] != n:
    continue
  q = [n]
  while q:
    c = q.pop()
    ds = F[c]
    for d in ds:
      if D[d] != n:
        D[d] = n
        q.append(d)
#print(C)
#print(D)
Nums = {}
for i in range(N):
  c, d = C[i], D[i]
  if (c, d) in Nums:
    Nums[(c, d)] += 1
  else:
    Nums[(c, d)] = 1
rs = []
for i in range(N):
  c, d = C[i], D[i]
  r = Nums[(c, d)]
  rs.append(r)
print(" ".join(map(str, rs)))


Measured memory_bytes: 98084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define INT(str) stoi((str), 0)
#define INTB(str) stoi((str), 0, 2) // 2進数の文字列を int に
//cout << fixed << setprecision(15);

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll r = 0, t = a[0];
  rep(i, n) {
    r += max(0ll, t - a[i]);
    t = max(t, a[i]);
  }
  cout << r << endl;
}


Measured memory_bytes: 4780
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
struct node
{int c,t;}a[105];
inline int read()
{
	int ans=0,f=1;char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){ans=ans*10+(c-'0');c=getchar();}
	return ans*f;
}
bool cmp(node a,node b)
{
	return a.c<b.c;
}
int main()
{
	int n=read(),T=read();
	for(int i=1;i<=n;i++){a[i].c=read();a[i].t=read();}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++){
		if(a[i].t<=T){
			printf("%d\n",a[i].c);return 0;
		}
	}
	printf("TLE\n");
	return 0;
}

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

int main()
{
	int N;
	cin >> N;
	vector<int> p(N);
	for(int i(0);i<N;++i) cin >> p[i];
	sort(p.begin(),p.end());
	int sum(0);
	for(int i(0);i<N;++i) sum += p[i];
	cout << sum - p[N-1]/2 << endl;
	return 0;
}

Measured memory_bytes: 256