akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<bits/stdc++.h>
// iteration and input/output stream
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define printarr(x) rep(i,0,x.size()) cout<<x[i]<<" "; cout<<endl;

#define si(x) int x; scanf("%d", &x)
#define sll(x) ll x; scanf("%lld", &x)
#define pi(x) printf("%d", x)
#define pll(x) printf("%lld", x)
#define nl prinf("\n")
#define tr(cont,it) \
for(decltype(cont.begin()) it = cont.begin(); it!= cont.end() ; it++)

#define tc() int tcase; cin >> tcase ; rep(tc,1,tcase+1)
//STL shortcuts
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define F first
#define S second
#define MP make_pair

// Error detection
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

using namespace std;

typedef long long int ll; // 64 bit integer
typedef unsigned long long int  ull; // 64 bit unsigned integer
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<int,ll> pill;

inline void smax(int &x , int y) { x = max(x , y) ; }
inline void smin(int &x , int y) { x = min(x , y) ; }

#define MOD 1000000007
#define inf 4000000000000000000LL
#define SYNC std::ios::sync_with_stdio(false);  cin.tie(NULL);

ll gcd(ll a,ll b){ return ((b==0)? a:gcd(b,a%b) ); }

int main()
{
    SYNC
    ll n,h,w;
    cin>>n>>h>>w;
    cout<<(n-h+1)*(n-w+1);
}


Measured memory_bytes: 256
#include <iostream>


#include <string>


#include <algorithm>


#include <utility>


#include <iomanip>


#include <functional>


#include <queue>


#include <stack>


#include <map>


#include <set>


#include <vector>


#include <cmath>


#include <cctype>


#include <cstdio>


#include <bitset>


#define ll long long


#define INF 1000000000000000001


#define MOD 1000000007


using namespace std;




int A[1000][999];


map<pair<int,int>, int> mp;


queue<pair<int,int> > que;


queue<pair<int,int> > battle_que;


int main(){


    


    ll N;


    cin >> N;



    for(int i=0; i<N; i++){


        for(int j=0; j<N-1; j++){


            cin >> A[i][j];


            A[i][j]--;


            if(mp.count(make_pair(i,A[i][j]))==0){


                mp[make_pair(i,A[i][j])]=0;


            }


            if(j==0){


                que.push(make_pair(i,A[i][j]));


           //     cout<<"que: "<<i<<" "<<A[i][j]<<endl;


            }


        }


    }


    


    int index[1000]={};



    ll cnt=0;


    while(!que.empty()){


        pair<int,int> temp = que.front();


        que.pop();


        


        if(mp[temp]==0){


            mp[temp]=1;


        }


        


        if(mp[make_pair(temp.second, temp.first)]==1){


        //    cout<<"battle: "<<temp.first<<" "<<temp.second<<endl;


            battle_que.push(make_pair(min(temp.first,temp.second),max(temp.first,temp.second)));


            


            index[temp.first]++;


            index[temp.second]++;


            


            cnt++;


            if(index[temp.first]<N-1){


                que.push(make_pair(temp.first, A[temp.first][index[temp.first]]));


            }


            if(index[temp.second]<N-1){


                que.push(make_pair(temp.second, A[temp.second][index[temp.second]]));


            }


        }


    }


    


    if(cnt != N*(N-1)/2){


        cout<<-1<<endl;


    }else{


        ll daycnt = 1;


        ll day[1000]={};


        


        while(!battle_que.empty()){


            int a=battle_que.front().first;


            int b=battle_que.front().second;


            battle_que.pop();


            


            if(day[a]==daycnt || day[b]==daycnt){


                daycnt++;


            }


            day[a]=daycnt;


            day[b]=daycnt;


        


        }


        


        cout<<daycnt<<endl;


    }


    return 0;


}

Measured memory_bytes: 70656
//**************************
//*** writer  :  Alex Hu **
//************************

#include<bits/stdc++.h>

using namespace std;

#define CLEAN(a,b) memset(a,b,sizeof(a))
#define mkp make_pair
#define pb push_back
#define rept(i,a,b) for(int i=(int)(a);i<(int)(b);i++)

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi; 
 
int cl[100005];
int lst[100005];
vector<int> eds[100005];
int n,m,q;
 
void dfs1(int v,int d,int c){
	if(!cl[v])
		cl[v]=c;
	if(lst[v]>=d)
		return;
	lst[v]=d;
	if(d==0)
		return;
	for(int u=0;u<eds[v].size();u++)
		dfs1(eds[v][u],d-1,c);
}
 
vector<int> vv,dd,cc;
 
int main(){
 
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		--a;--b;
		eds[a].push_back(b);
		eds[b].push_back(a);
	}
	cin>>q;
	for(int i=0;i<q;i++){
		int v,d,c;
		cin>>v>>d>>c;
		--v;
		vv.push_back(v);
		dd.push_back(d);
		cc.push_back(c);
	}
	reverse(vv.begin(),vv.end());
	reverse(dd.begin(),dd.end());
	reverse(cc.begin(),cc.end());
	for(int i=0;i<q;i++){
		int v,d,c;
		v=vv[i];
		d=dd[i];
		c=cc[i];
		dfs1(v,d,c);
	}
	for(int i=0;i<n;i++){
		cout<<cl[i]<<endl;
	}
 
	return 0;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var raw = ReadLine().Split().Select(int.Parse).ToArray();
            var N = raw[0];
            var M = raw[1];

            var A = ReadLine().Split().Select(int.Parse).OrderByDescending(s => s).ToArray();
            var test = A.Sum();
            var sum = 1 / (4 * M) * test;
            WriteLine(1 / (double)((4 * M)) * A.Sum() > A[M - 1]  ? "No" : "Yes");
        }
    }
}


Measured memory_bytes: 13396
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if (n == 1) {
            System.out.println("Hello World");
        } else {
            int a = sc.nextInt();
            int b = sc.nextInt();
            System.out.println(a+b);
        }
    }
}

Measured memory_bytes: 21716
#include<iostream>
using namespace std;
int main(){
	int a1,a2,a3,i,j,as=0,max=0,min=0;
	cin>>a1;
	cin>>a2;
	cin>>a3;
	if(a1>=a2){
		if(a2>=a3){
			max=a1;
			min=a3;
		}
		else if(a2<=a3){
			if(a1>=a3){
				max=a1;
				min=a2;
			}
			else if(a1<=a3){
				max=a3;
				min=a2;
			}
		}
	}
	if(a1<=a2){
		if(a1>=a3){
			max=a2;
			min=a3;
		}
		else if(a1<=a3){
			if(a2>=a3){
				max=a2;
				min=a1;
			}
			else if(a2<=a3){
				max=a3;
				min=a1;
			}
		}	
	}
as=max-min;
cout<<as;
}


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

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      String[] str = br.readLine().split(" ");
      int x = Integer.parseInt( str[0] );
      int y = Integer.parseInt( str[1] );
      int z = calcRemaider(x, y);

      int[] aDiv,az;
      int result=0;

      aDiv = commonDivisor( x>y ? y : x );
      az = commonDivisor(z);
      for( int i=0, j=0, max = az.length; i<max; i++ ) {
        for( j=0; aDiv[j] <= az[i]; j++){
          if(aDiv[j] == az[i]) result = aDiv[j];
        }
      }

      System.out.println(result);
    }
  }

  static int[] commonDivisor(int n) {
    int[] div = new int[5000];
    int[] buf = new int[5000];
    int counter = 0;

    for(int i=1, j=0, max=n; i<max; i++){
      if( n%i == 0) {
        div[j++] = i;
        max = n/i;
        buf[++counter] = max;
      }
    }
    int[] ret = new int[(counter)*2];
    for(int i=0 ; i != counter; i++){
      ret[i] = div[i];
      ret[counter + i] = buf[counter-i];
    }

    return ret;
  }

  static int calcRemaider(int x, int y) {
    int z = x>y ? x%y : y%x;

    if( x > y &&  z == 0 ) {
      System.out.println(y);
      System.exit(0);

    } else if( z == 0 ) {
      System.out.println(x);
      System.exit(0);
    }

    return z;
  }
}


Measured memory_bytes: 24436
N = int(input())
a =[[0 for i in range(10)] for j in range(10)]
for i in range(1,N+1):
    l = list(str(i))
    a[int(l[0])][int(l[-1])] += 1
ans = 0
for i in range(1,10):
    for j in range(i,10):
        if i == j:
            ans += a[i][j]**2
        else:
            ans += a[i][j] * a[j][i] * 2
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
void solve(int test,int test1)
{
    string s,t;
    cin>>s>>t;
    int mini=0,count=0;
    for(int i=0;i<=s.size()-t.size();i++)
    {
        count=0;
        for(int j=0;j<t.size();j++)
        {
           if(s[i+j]==t[j])
                count++;
        }
       
        mini=max(count,mini);

    }
   cout<<t.size()-mini;
}

int main()
{
    int test;
   // cin>>test;
    int test1=test;
    test=1;
  while(test--)
  {

    solve(test,test1);

  }


    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#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++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<string> vs;
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
const double PI = acos(-1.0);

int main() {
    int N;
    cin >> N;
    vll v(N + 1, 0);
    rep2(i, 1, N + 1){
        rep2(j, 1, N / i + 1){
            v[i * j]++;
        }
    }
    ll ans = 0;
    rep(i, N + 1){
        ans += v[i] * i;
    }
    cout << ans << endl;
}


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

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int N, Q; cin >> N >> Q;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];

    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}

Measured memory_bytes: 21776
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double

bool go(vector<ll> &vec,ll n,ll mid ,ll k){
	ll p=0;
	for(ll i=1;i<=n;i++){
		p+=ceil((vec[i]-1)/mid);
		if(p>k) return 0;
	}
//	cout<<p<<endl;
	if(p>k) return 0;
	else return 1;
}
int main()
{
	ll n,k;
	cin>>n>>k;
	vector<ll> vec(n+1,0);
	ll ans=0;
	for(ll i=1;i<=n;i++){
		cin>>vec[i];
		ans=max(ans,vec[i]);
	}
	
	ll l=1,r=ans;
	ll x=500;
	while(l<=r&&x>0){
		x--;
		ll mid=(l+r)/2.0;
//		cout<<(int)l<<" "<<(int)r<<endl;
		bool bb=go(vec,n,mid,k);
		if(bb==1){
			ans=min(ans,mid);
			r=mid-1;
		}
		else{
			l=mid+1;
		}
	}
	cout<<(int)round(ans)<<endl;
}


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

typedef long long ll;

ll N;
map<ll, ll> C;
ll R;

int main() {
  cin >> N;
  ll cnt = 0;
  for (ll i = 1; i <= N; ++i) {
    ll p;
    cin >> p;
    if (i == p)
      ++cnt;
    else {
      R += (cnt + 1) / 2;
      cnt = 0;
    }
  }
  R += (cnt + 1) / 2;
  cout << R << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18

template <std::uint_fast64_t mod>
class ModInt {
    using u64 = std::uint_fast64_t;

   public:
    u64 x;
    ModInt(const ll x = 0) : x(x < 0 ? (mod - (-x % mod)) % mod : x % mod) {}

    ModInt operator+(const ModInt r) { return ModInt(*this) += r; }
    ModInt operator*(const ModInt r) { return ModInt(*this) *= r; }
    ModInt operator-(const ModInt r) { return ModInt(*this) -= r; }
    ModInt operator/(const ModInt r) { return ModInt(*this) /= r; }
    ModInt operator-() { return ModInt(mod - x); }

    ModInt &operator+=(const ModInt r) {
        x += r.x;
        if (x >= mod) x -= mod;
        return *this;
    }
    ModInt &operator-=(const ModInt r) {
        if (x < r.x) x += mod;
        x -= r.x;
        return *this;
    }
    ModInt &operator*=(const ModInt r) {
        x *= r.x;
        if (x >= mod) x %= mod;
        return *this;
    }
    ModInt &operator/=(ModInt r) {
        if (!(x % r.x)) {
            x /= r.x;
            return *this;
        }
        u64 p = mod - 2;
        while (p > 0) {
            if (p & 1) *this *= r;
            r *= r;
            p >>= 1;
        }
        return *this;
    }
    ModInt &operator++(int) { return (*this) += 1; }
    ModInt &operator++() { return (*this) += 1; }
    ModInt &operator--(int) { return (*this) -= 1; }
    ModInt &operator--() { return (*this) -= 1; }

    bool operator<(const ModInt r) { return x < r.x; }
    bool operator>(const ModInt r) { return x > r.x; }
    bool operator<=(const ModInt r) { return x <= r.x; }
    bool operator>=(const ModInt r) { return x >= r.x; }
    bool operator==(const ModInt r) { return x == r.x; }
    bool operator!=(const ModInt r) { return x != r.x; }

    ModInt inv() { return (ModInt)1 / (*this); }
    int get_mod() { return mod; }

    friend std::istream &operator>>(std::istream &in, ModInt &m) {
        ll a;
        in >> a;
        if (a < 0) a = mod - (-a % mod);
        if (a >= mod) a %= mod;
        m.x = a;
        return in;
    }
    friend std::ostream &operator<<(std::ostream &out, const ModInt &m) {
        out << m.x;
        return out;
    }
};
constexpr std::uint_fast64_t mod = 1e9 + 7;
using mint = ModInt<mod>;

int main() {
    ll N, K;
    cin >> N >> K;
    mint ans = 0;
    for (ll k = K; k <= N + 1; k++) {
        ll cnt = k * N - k * (k - 1) + 1;
        ans += cnt;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
inf = float('inf')

n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [inf] * n
dp[0] = 0

for i in range(1, n):
    dp[i] = min(dp[i - j] + abs(h[i] - h[i - j]) for j in range(1, k + 1) if i - j >= 0)

print(dp[n - 1])


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

int main(){
	string s;
	cin >> s;
	
	if(s[0] == 'A') cout << 'T';
	if(s[0] == 'C') cout << 'G';
	if(s[0] == 'G') cout << 'C';
	if(s[0] == 'T') cout << 'A';
	
	return 0;
}
		
		

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int K, A, B;
  cin >> K >> A >> B;
  int a = 0;
  for (int i = A; i <= B; i++) {
    if (i % K == 0) {
      a = 1;
      break;
    }
  }
  if (a == 1) {
    cout << "OK" << endl;
  } else {
    cout << "NG" << endl;
  }
  return 0;
}

Measured memory_bytes: 3636
n=int(input())
it=[input() for i in range(n)]
s="abcdefghijklmnopqrstuvwxyz"
ss={}
j=0
for i in s:
    ss[i]=j
    j+=1
st=[0 for i in range(26)]
for i in it[0]:
    st[ss[i]]+=1
for i in range(1,n):
    aa={}
    for j in it[i]:
        try:
            aa[j]+=1
        except:
            aa[j]=1
    k=[0]*26
    for i in aa:
        k[ss[i]]=aa[i]
    for i in range(26):
        st[i]=min(st[i],k[i])
for i in range(26):
    print(s[i]*st[i],end="")


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

int main() {
  int N;
  cin >> N;
  vector<int> x(N);
  vector<int> y(N);
  for(int i=0;i<N;i++){
    cin >> x[i];
  }
  copy(x.begin(),x.end(),y.begin());
  sort(y.begin(),y.end());
  int s,l;
  s=y[N/2-1];
  l=y[N/2];
  for(int i=0;i<N;i++){
    if(x[i]<=s)cout << l << endl;
    else cout << s << endl;
  }
}




Measured memory_bytes: 3712
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		char[] ch= sc.next().toCharArray();
		sc.close();

		for(int i = 0;i < ch.length;i++){
			ch[i] += N;
			if(ch[i] > 'Z'){
				ch[i] -= 26;
			}
			System.out.print(ch[i]);
		}
	}
}

Measured memory_bytes: 25812
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
	int a,b,c,x=0,y=0,z=0;
	cin>>a>>b>>c;
    x=a;
    a=b;
    b=x;
    y=a;
    a=c;
    c=y;
    cout<<a<<" "<<b<<" "<<c<<endl;
	return 0;
}

Measured memory_bytes: 256
from collections import deque
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n,q = map(int,readline().split())
ki = [[] for _ in range(n)]

for i in range(n-1):
    a,b = map(int,readline().split())
    a,b = a-1,b-1
    ki[a].append(b)
    ki[b].append(a)

stack = [0]
parent = [0]*n
order = []

while stack:
    x = stack.pop()
    order.append(x)
    for i in ki[x]:
        if i == parent[x]:
            continue
        parent[i] = x
        stack.append(i)

query = [0]*n
for i in range(q):
    p,x = map(int,readline().split())
    p -= 1
    query[p] += x

for x in order:
    count = query[x]
    for y in ki[x]:
        if y == parent[x]:
            continue
        query[y] += count

print(*query)

Measured memory_bytes: 94464
n,q = list(map(int,input().split(" ")))
time = [tuple(input().split(" ")) for i in range(n)]


def process_queue(n,q,time):
    r = []
    c = 0
    while time:
        if int(time[0][1]) > q:
            time.append((time[0][0],int(time[0][1])-q,))
            time.pop(0)
            c+=q
        else:
            c+=int(time[0][1])
            r.append((time[0][0],c,))
            time.pop(0)
    return r
lst = [("p1","150",),("p2","80",),("p3","200"),("p4","350",),("p5","20")]
r = process_queue(n,q,time)
for i in r:
    print("{} {}".format(i[0],i[1]))


Measured memory_bytes: 13688
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int n;
    cin >> n;
    vp a(n);
    rep(i,n){
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(all(a));
    rep(i,n){
        if(a.back().second == i){
            cout << a[n-2].first << endl;
        }else{
            cout << a[n-1].first << endl;
        }
    }
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define show(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define sset(s) cout<<#s<<":";each(i,s)cout <<" "<<i;cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 501;

int flag[MAX_N][MAX_N];

int main()
{
    while(1){
        int n;
        cin >> n;
        if(n == 0){
            break;
        }
        int w,h;
        cin >> w >> h;
        rep(i,w+1){
            rep(j,h+1){
                flag[i][j] = 0;
            }
        }
        rep(i,n){
            int a,b;
            cin >> a >> b;
            flag[a][b]++;
        }
        rep(i,w){
            rep(j,h+1){
                flag[i+1][j] = flag[i][j] + flag[i+1][j];
            }
        }
        rep(i,w+1){
            rep(j,h){
                flag[i][j+1] += flag[i][j];
            }
        }
        int ans = 0;
        int s,t;
        cin >> s >> t;
        for(int i=s;i<=w;i++){
            for(int j=t;j<=h;j++){
                ans = max(ans,flag[i][j]-flag[i-s][j]-flag[i][j-t]+flag[i-s][j-t]);
            }
        }
        cout << ans << "\n";
    }
}

Measured memory_bytes: 3172
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n;
  int ans=100000;
  cin>>n;
  for(int i=0;i<n;i++){
    ans=ans+ans/100*5;
   /*   ans+=900;
   ans=(int)ans/1000;
   ans=ans*1000;*/
    if(ans%1000!=0)ans+=1000-ans%1000;
  }
  printf("%d\n",ans);
  //cout<<(int)ans<<endl;
}

Measured memory_bytes: 1144
#include <stdio.h>
#include <math.h>
#include <string.h>

int n;
int circle[24][4];
char bitDP[(1<<24)]; // ??????????????????bit??§??????
int overlap[24]; // ?????????????????????bit??§??????

int main()
{
	int i, j, bit;
	int next, ans;
	
	while(scanf("%d",&n) != EOF) {
		if(n == 0) {
			break;
		}
		
		for(i = 0; i < n; i++) {
			scanf("%d",&circle[i][0]);
			scanf("%d",&circle[i][1]);
			scanf("%d",&circle[i][2]);
			scanf("%d",&circle[i][3]);
			
			overlap[i] = 0;
			for(j = 0; j < i; j++) {
				int distance_x = circle[i][0] - circle[j][0];
				int distance_y = circle[i][1] - circle[j][1];
				double distance_circle = sqrt(pow(distance_x, 2) + pow(distance_y, 2));
				if(circle[i][2] + circle[j][2] > distance_circle) {
					overlap[i] += (1 << j);
				}
			}
		}
		
		memset(bitDP, -1, sizeof(bitDP));
		bitDP[0] = 0;
		
		ans = 0;
		for(bit = 0; bit < (1 << n); bit++) {
			if(bitDP[bit] == -1) {
				continue;
			}
			if(ans < bitDP[next]) {
				ans = bitDP[next];
			}
			
			for(i = 0; i < n; i++) {
				if(((1 << i) & bit) || !((overlap[i] & bit) == overlap[i])) {
					continue;
				}
				
				for(j = i+1; j < n; j++) {
					if(((1 << i) | (1 << j)) & bit) {
						continue;
					}
					if(!((overlap[j] & bit) == overlap[j])) {
						continue;
					}
					if(circle[i][3] != circle[j][3]) {
						continue;
					}
					
					next = (((1 << i) | (1 << j)) | bit);
					if(bitDP[next] < bitDP[bit] + 2) {
						bitDP[next] = bitDP[bit] + 2;
					}
				}
			}
		}
		printf("%d\n",ans);
	}
	
	return 0;
}

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

#define ll long long
#define F first
#define S second
#define ii pair < int , int >
#define ever (;;)

const int N = 100100;

int n,a[N],dp[N],k;

int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);

    for(int i=n-1;i>=1;i--)
    {
        dp[i] = 2e9;

        for(int j=i+1;j<=min(i+k,n);j++)
            dp[i] = min( dp[i] , abs(a[i]-a[j]) + dp[j] );
    }

    printf("%d\n",dp[1]);
}


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

int main(){
  int g[13];
  g[1]=1;g[2]=3;g[3]=1;g[4]=2;g[5]=1;g[6]=2;g[7]=1;g[8]=1;g[9]=2;g[10]=1;g[11]=2;g[12]=1;
  int x,y;
  cin>>x>>y;
  if(g[x]==g[y])cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}



Measured memory_bytes: 256
import math 
n,k=map(int,input().split())
if k==0:
    print(n**2)
if k>=1:
    ans=0
    flow=0
    for some in range(k+1,n+1):
        flow=math.floor(n/some)*(some-k)
        ans+=flow
        if  math.floor(n/some)*some+k>n:
            ans=ans
        if math.floor(n/some)*some+k<=n:
            ans=ans+n+1-math.floor(n/some)*some-k

    print(ans)

Measured memory_bytes: 3064
def solve():
    n, x = map(int, input().split())
    s = list(map(int, input().split()))
    cnt, tmp, flg = 0, 0, False
    for i in range(n - 1):
        if i == 0 and s[i] > x:
            cnt += s[i] - x
            s[i] = x
        if s[i] + s[i + 1] > x:
            tmp = s[i] + s[i + 1] - x
            cnt += tmp
            s[i + 1] -= tmp
    print(cnt)



solve()

Measured memory_bytes: 85348
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        
        // 標準入力の取得
        int N = Integer.parseInt(scan.next());

        // List<String> W = new ArrayList<String>(N);
        String[] W = new String[N];
        for (int i = 0; i < N; i++) {
            // W.add(scan.next());
            W[i] = scan.next();
        }

        // 重複チェック
        Set<String> Wst = new HashSet<String>(Arrays.asList(W));
        if(!(Wst.size() == N)){
            System.out.println("No");
            return ;
        }
        
        // しりとりできてるかチェック
        for (int i = 0; i < N-1; i++) {
            if(W[i].charAt(W[i].length() - 1) != W[i+1].charAt(0)){
                System.out.println("No");
                return ; 
            }
        }
        System.out.println("Yes");
        return ; 
    }
}


Measured memory_bytes: 21844
x,y=map(int,input().split())
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result
if x/y>2 or x/y<0.5 or (x+y)%3!=0:
    print(0)
    exit()
a=(2*x-y)//3
print(cmb((x+y)//3,a)%(10**9+7))

Measured memory_bytes: 102156
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var N = input[0];
        var K = input[1];
        var S = Console.ReadLine().ToCharArray();
        
        for (var i = 0; i < S.Length; i++) {
            if (i == K - 1) {
                S[i] = Char.ToLower(S[i]);
            }
            Console.Write(S[i]);
        }
    }
}


Measured memory_bytes: 13268
import java.util.*;
import java.io.*;

import static java.lang.System.in;

public class Main {
    static long ans=0;
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), A = sc.nextInt(), B = sc.nextInt();
        if(!check(n,A,B)){
            System.out.println(-1);
            System.exit(0);
        }
        PrintWriter out = new PrintWriter(System.out);
        //int[] ans = new int[n+1];
        int lowerBound = 0;
        int start = 1;
        for(int cnt=1;cnt<=A;cnt++){
            int len = Math.min(B,n-start-A+cnt+1);
            for(int j=0;j<len;j++){
                out.print(lowerBound+len-j);
                out.print(" ");
            }
            start += len;
            lowerBound += len;
        }
        out.flush();
    }
    static boolean check(int n, int a, int b){
        if(a>n||b>n||b>n-a+1) return false;
        int shortest = n%a==0? n/a:(n/a+1);
        return b>=shortest;
    }
}


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

int dp[100];

//最大公約数
int gcd(int x, int y){
  if(x % y == 0) return y;
  return gcd(y, x % y);
}
//最小公倍数
int lcm(int x, int y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}


int main(){
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  vector<int> dp(n);
  dp[0] = 0; dp[1] = abs(h[1] - h[0]);

  for(int i = 2; i < n; i++){
    dp[i] = 1e9;
    REP(j,k+1){
      if(j > i) break;
      dp[i] = min(dp[i], abs(h[i] - h[i-j]) + dp[i-j]);
    }
  }
  cout << dp[n-1] << endl;
}




Measured memory_bytes: 1024
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] p = new int[N];
		for (int i = 0; i < N; i++) {
			p[i] = sc.nextInt();
		}
		sc.close();

		Arrays.sort(p);
		int sum = 0;
		for (int i = 0; i < K; i++) {
			sum += p[i];
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 38800
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.Arrays;
import java.util.List;

public class Main {
    public static void main(String[] args){
        PrintWriter out = new PrintWriter(System.out);
        Scanner sc = new Scanner(System.in);
        Task task = new Task();
        task.solve(sc, out);
        out.flush();
        sc.close();
    }
    static class Task{
        public void solve(Scanner sc, PrintWriter out){
            int sum  = 0;
            int[] nint = intLine(sc, 3);
            Arrays.sort(nint);

            int a1 = nint[0];
            int a2 = nint[1];
            int a3 = nint[2];

            int a1a2 = Math.abs(a2-a1);
            int a1a3 = Math.abs(a3-a1);

            if (a1a2 <= a1a3){
                sum += a1a2 + Math.abs(a2-a3);
             }else {
                sum += a1a3 + Math.abs(a2-a3);
            }


            out.println(sum);

        }
    }

    static int nint(Scanner sc){
        return Integer.parseInt(sc.next());
    }
    static long nlong(Scanner sc){
        return Long.parseLong(sc.next());
    }
    static double ndouble(Scanner sc){
        return Double.parseDouble(sc.next());
    }
    static float nfloat(Scanner sc){
        return Float.parseFloat(sc.next());
    }
    static String nstr(Scanner sc){
        return  String.valueOf(sc.next());
    }
    static long[] longLine(Scanner sc, int size){
        long[] lLine = new long[size];
        for (int i = 0; i < size; i++) {
            lLine[i] = nlong(sc);
        }
        return lLine;
    }
    static int[] intLine(Scanner sc, int size){
        int[] iLine = new int[size];
        for (int i = 0; i < size; i++) {
            iLine[i] = nint(sc);
        }
        return iLine;
    }
    static String[] strLine(Scanner sc, int size){
        String[] strLine = new String[size];
        for (int i = 0; i < size; i++) {
            strLine[i] = nstr(sc);
        }
        return strLine;
    }
}

Measured memory_bytes: 23764
#include<iostream>

int main()
{
	int a, b;
	std::cin >> a >> b;

	if (a > b)
		std::cout << "a > b" << std::endl;
	else if (a < b)
		std::cout << "a < b" << std::endl;
	else
		std::cout << "a == b" << std::endl;

}

Measured memory_bytes: 1156
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}

int N;
string s;

void init()
{
}

void solve()
{
    int nl = 0, nr = 0;
    FOR(i, 1, N){
        if(s[i] == 'E') nr++;
    }
    int ret = nl + nr;
    FOR(i, 1, N){
        if(s[i-1] == 'W') nl++;
        if(s[i] == 'E') nr--;
        ret = min(ret, nl + nr);
    }
    cout << ret << endl;
}

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

// vim:set foldmethod=marker:


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 
const int mod=1e9+7;
 
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};
 
mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}
 
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
 
    return true;
}
 
map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}
 
void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}
 
int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  string ans="Right";
  if(a+b>c+d){
    ans="Left";
  }else if(a+b==c+d){
    ans="Balanced";
  }
  cout(ans);
  return 0;
}

Measured memory_bytes: 125568
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
const int INF = 1e9;
const long long LINF = 1e18;



int main(){
  int N; cin >> N;
  vector<int> h(N);
  for(int i = 0; i < N; i++){
    cin >> h[i];
  }
  int ans = 0;
  int now = 0;
  for(int i = 0; i < N; i++){
    if(now >= h[i]){
      now = h[i];
    }
    else{
      ans += h[i] - now;
      now = h[i];
    }
  }
  cout << ans << endl;
}
  
  


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
using namespace std;
int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;

  	if(a+b-c-d==0){
		cout << "Balanced" << endl;
    }else if(a+b-c-d>0){
		cout << "Left" << endl;
    }else{
  		cout << "Right" << endl;
    }
	return 0;
}

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

using namespace std;

int main() 
{
	int n;	cin >> n;
	for (int x : {2,4,5,7,9})
		if (n % 10 == x)
			cout << "hon\n";
			
	for (int x : {0, 1, 6, 8})
		if (n % 10 == x)
			cout << "pon\n";
			
	for (int x : {3})
		if (n % 10 == x)
			cout << "bon\n";
			
	
}

Measured memory_bytes: 3636
#include <string>
#include <cmath>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <queue>
#include <tuple>
#include <functional>
#include <set>
using namespace std;

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

    return 0;
}



Measured memory_bytes: 256
//
//  main.cpp
//  AtCoder_code_test
//
//  Created by parsley69 on 2019/05/25.
//  Copyright © 2019 parsley69. All rights reserved.
//
//

#include <iostream>
#include <fstream>
#include <set>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>
using namespace std;

int digitsum(int n) {
    int sum = 0;
    while (n > 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main(int argc, const char * argv[]) {
    
    int N;
    cin >> N;
    vector<int64_t> a(3 * N);
    for (int i = 0; i < 3 * N; i++) {
        cin >> a.at(i);
    }
    
    int64_t sum = 0;
    sort(a.begin(), a.end(), greater<int64_t>());
    for (int i = 0; i < N; i++) {
        sum += a.at(2 * i + 1);
    }
    
    cout << sum << endl;
    
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
#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;
	cin >> n;
	vector<vector<int> > c(n,vector<int>(n));
	REP(i,n){
		REP(j,n){cin >> c[i][j];
		}
	}
	long long ans = 0;
	REP(i,n){
		REP(j,i){
			if(i == j)continue;
			ans += min(c[i][j],c[j][i]);
		}
	}
	cout << ans << endl;
  return 0;
}

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

int main(){
	int n, d, count = 0;
	scanf("%d%d", &n, &d);
	long long int x, y;
	for(int i = 0; i < n; ++i){
		scanf("%lld%lld", &x, &y);
		count += (sqrt(x*x + y*y) <= d);
	}
	printf("%d\n", count);
	return 0;
}


Measured memory_bytes: 3804
a=[]
for i in input():
    if i=="S":
        a+=i
    
    if a:
        if i=="T" and a[-1]=="T":
            a+=i
        if i=="T" and a[-1]=="S":
            a.pop(-1)
    elif i=="T" and len(a)==0:
        a+=i    
print(len(a))

Measured memory_bytes: 10520
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
inline ll lin() { ll x; scanf("%lld",&x); return x;}
inline char chin() { char x; scanf("%c",&x); return x;}
inline string stin() { string x; cin >> x; return x;}
inline double din() { double x; scanf("%lf",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
char itoa(int n) { return n + '0';}
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  int k;
  cin >> k;
  queue<ll> q;
  rrep(i,9) q.push(i);
  rep(i,k) {
    ll x = q.front(); q.pop();
    if (i == k-1) {
      cout << x << endl;
      return 0;
    }
    if (x%10 != 0) q.push(10*x + x%10 - 1);
    q.push(10*x + x%10);
    if (x%10 != 9) q.push(10*x + x%10 + 1);
  }
  return 0;
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
static const int N = 100;

int main() {
  int M[N][N];
  int n, u, k, v;

  cin >> n;

  for ( int i = 0; i < n; i++ )
    for ( int j = 0; j < n; j++ ) M[i][j] = 0;

  for ( int i = 0; i < n; i++ ) {
    cin >> u >> k;
    u--;
    for ( int j = 0; j < k; j++ ) {
      cin >> v;
      v--;
      M[u][v] = 1;
    }
  }

  for ( int i = 0; i < n; i++ ) {
    for ( int j = 0; j < n; j++ ) {
      if ( j ) cout << " ";
      cout << M[i][j];
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 3108
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#define MOD 1000000007
#define INF 1000000000
typedef long long ll;
using namespace std;
typedef pair<int,int> P;
// 9/3
//約数を返す関数
#define N 1001
int is_prime[N+1];
int sum_prime[N+1];
void erasto(){
    for(int x=0;x<N;x++)is_prime[x]=1;
    is_prime[0]=0;
    is_prime[1]=0;
    for(int x=2;x*x<=N;x++){
        if(is_prime[x]!=0){
            for(int y=x*x;y<N;y+=x){
                is_prime[y]=0;
            }
        }
    }
    for(int x=1;x<=N;x++){
        sum_prime[x]=sum_prime[x-1]+is_prime[x];
        
    }
}

int main(void){
    int n;
    cin>>n;
    erasto();
    ll ans=1;
    for(int i=1;i<=n;i++){
        if(is_prime[i]){
            int tmp=0;
            for(int k=1;pow(i,k)<=n;k++){
                tmp+=n/pow(i,k);
            }
            //cout<<i<<" "<<tmp<<endl;
            //if(tmp==0)cout<<i<<endl;
            ans*=(tmp+1);
            ans%=MOD;
            //cout<<i<<" "<<ans<<endl;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
class Stack<T> {
    val values = emptyList<T>().toMutableList()

    fun push(value: T) = values.add(value)

    fun pop() = values.removeAt(values.size - 1)

    override fun toString() = values.toString()
}
class Queue<T> {
    val values = emptyList<T>().toMutableList()

    fun enqueue(value: T) = values.add(value)

    fun dequeue() = values.removeAt(0)

    override fun toString() = values.toString()
}

fun <T> List<T>.get1Origin(index: Int) = this[index - 1]
fun <T> List<T>.subList1Origin(fromIndex: Int, toIndex: Int) = this.subList(fromIndex - 1, toIndex - 1)
fun <T> MutableList<T>.set1Origin(index: Int, element: T) = this.set(index - 1, element)
fun <T> MutableList<T>.removeAt1Origin(index: Int) = this.removeAt(index - 1)

fun String.splitToString() = this.split(" ")
fun String.splitToInt() = this.split(" ").map { it.toInt() }
fun String.splitToLong() = this.split(" ").map { it.toLong() }

fun main(args: Array<String>) {
    val (a, b) = readLine()!!.splitToInt()
    val res = if (a < b) a.toString().repeat(b) else b.toString().repeat(a)
    println(res)
}

Measured memory_bytes: 37616
import java.util.*;

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

        int n = sc.nextInt();
        int k = sc.nextInt();

        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }

        int l = 1;
        int r = 1000000000;

        while(l < r){
            int mid = (r - l) / 2 + l;
            if(judge(mid, k, a)){
                r = mid;
            }else{
                l = mid + 1;
            }
            //System.out.println(l +" "+ r);
        }

        System.out.println(l);

    }

    static boolean judge(int l, int k, int[] a){
        int c = 0;
        for(int b : a){
            c += Math.ceil((double)b / l) - 1;
            if(c > k){
                return false;
            }
        }
        return true;
    }

}


Measured memory_bytes: 62748
#!/usr/bin/perl
use Data::Dumper;
use POSIX qw(floor ceil);

# 引数取り込み
my $a = <>;
my ( $b, $c ) = split( / /, $a );

# 処理開始
my $ans;

if( $b >= 10 ) {
    $ans = $c;
}
else {
    $ans = $c + 100 * ( 10 - $b );
}

print $ans;

1;

Measured memory_bytes: 7212