akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define nl printf("\n")
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
ll pow1(ll a, ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
		{
			ans=ans*a;
		}
		a=a*a;
		b=b>>1;
	}
	return ans;
}
int main()
{
	int arr[3],i;
	for(i=0;i<3;i++)
		cin>>arr[i];
	sort(arr,arr+3);
	int ans = (arr[2]*10)+arr[0]+arr[1];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
N=int(input())
a = 0
w = 0
t = 0
r = 0
for i in range(N):
  S=input();
  if S[0] == "A":
    a+=1
  elif S[0] == "W":
    w+=1
  elif S[0] == "T":
    t+=1
  else:
    r+=1
print("AC x",a)
print("WA x",w)
print("TLE x",t)
print("RE x",r)



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

vector<ll> divisor(ll n) {
    vector<ll> res;
    for (ll i = 1; i * i <= n; ++i) {
        if (n % i == 0 ) {
            res.push_back(i);
            if (n / i != i) res.push_back(n / i);
        }
    }
    sort(all(res));
    return res;
}

ll g(ll a, ll b) {
    return a*a*a*a + a*a*a * b + a*a * b*b + a * b*b*b + b*b*b*b;
}


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

    vector<ll> f = divisor(x);
    vector<ll> d = divisor(x);

    rep(i, f.size()) d.push_back(f[i] * (-1));

    ll a, b;
    for (auto e: d) {
        ll s = x / e;

        bool ok = false;

        for (ll i = -1000; i <= 1000; ++i) {
            a = e + i;
            b = i;
            ll t = g(a, b);

            if (s == t) {
                ok = true;
                break;
            }
        }

        if (ok) break;
    }

    cout << a << " " << b << endl;
}


Measured memory_bytes: 3604
#include <iostream>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int res = 0;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    res += (x - 1);
  }
  cout << res;
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <cstring>
using namespace std;
#define sci(n) scanf("%lld", &(n))
#define scd(n) scanf("%Ld", &(n))
typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> pll;
int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	LL a, b, c;
	cin >> a >> b >> c;
	LL ans = a - b;
	cout << max((LL)0,c - a + b);
	return 0;
}

Measured memory_bytes: 256
# frozen_string_literal: true

# induce sort (internal routine)
def sa_is_induce(s, ls, sum_l, sum_s, lms)
  n = s.size
  sa = [-1]*n

  #buf = *sum_s # deep copy
  buf = Marshal.load(Marshal.dump(sum_s)) # deep copy
  lms.each{ |lms|
    if lms != n then
      sa[buf[s[lms]]] = lms
      buf[s[lms]] += 1
    end
  }

  #buf = *sum_l # deep copy
  buf = Marshal.load(Marshal.dump(sum_l)) # deep copy
  sa[buf[s[-1]]] = n-1
  buf[s[-1]] += 1
  sa.each{ |v|
    if v>=1 && !ls[v-1] then
      sa[buf[s[v-1]]] = v-1
      buf[s[v-1]] += 1
    end
  }

  #buf = *sum_l # deep copy
  buf = Marshal.load(Marshal.dump(sum_l)) # deep copy
  sa.reverse_each{ |v|
    if v>=1 && ls[v-1] then
      buf[s[v-1]+1] -= 1
      sa[buf[s[v-1]+1]] = v-1
    end
  }

  return sa
end

# SA-IS (internal routine)
def sa_is(s, upper)
  n = s.size

  return [] if n == 0
  return [0] if n == 1

  ls = [false]*n
  (n-2).downto(0){ |i|
    ls[i] = s[i]==s[i+1] ? ls[i+1] : s[i]<s[i+1]
  }

  sum_l = [0]*(upper+1)
  sum_s = [0]*(upper+1)
  s.zip(ls){ |s, ls|
    if ls then
      sum_l[s+1] += 1
    else
      sum_s[s] += 1
    end
  }
  0.upto(upper){ |i|
    sum_s[i] += sum_l[i]
    sum_l[i+1] += sum_s[i] if i<upper
  }

  lms = (1 ... n).select{ |i| !ls[i-1] && ls[i] }
  m=lms.size
  lms_map = [-1]*(n+1)
  lms.each_with_index{ |lms, id| lms_map[lms] = id }

  sa = sa_is_induce(s, ls, sum_l, sum_s, lms)

  return sa if m == 0

  sorted_lms = sa.select{ |sa| lms_map[sa] != -1 }
  rec_s = [0]*m
  rec_upper = 0
  rec_s[lms_map[sorted_lms[0]]] = 0
  1.upto(m-1){ |i|
    l, r = sorted_lms[i-1, 2]
    end_l = lms[lms_map[l]+1]||n
    end_r = lms[lms_map[r]+1]||n
    same = true
    if end_l-l != end_r-r then
      same = false
    else
      while l < end_l do
        break if s[l] != s[r]
        l+=1
        r+=1
      end
      same = false if l==n || s[l]!=s[r]
    end
    rec_upper += 1 if not same
    rec_s[lms_map[sorted_lms[i]]] = rec_upper
  }

  sa_is(rec_s, rec_upper).each_with_index{ |rec_sa, id|
    sorted_lms[id] = lms[rec_sa]
  }

  return sa_is_induce(s, ls, sum_l, sum_s, sorted_lms)
end

# suffix array for array of integers
def suffix_array(s, upper = nil)
  if not upper then
    # compression
    n = s.size
    idx = (0 ... n).sort_by{ |l, r| s[l] < s[r] }
    t = [0]*n
    upper = 0
    t[idx[0]] = 0
    idx.each_cons(2){ |i, j|
      upper += 1 if s[i] != s[j]
      t[j] = upper
    }
    s = t
  end

  return sa_is(s, upper)
end

# suffix array for string
def suffix_array(s)
  return sa_is(s.bytes, 255)
end

# lcp array for array of integers
def lcp(s, sa)
  n = s.size
  rnk = [0]*n
  sa.each_with_index{ |sa, id|
    rnk[sa] = id
  }
  
  lcp = [0]*(n-1)
  h = 0
  n.times{ |i|
    h -= 1 if h > 0
    next if rnk[i] == 0
    j = sa[rnk[i]-1]
    h += 1 while j+h<n && i+h<n && s[j+h]==s[i+h]
    lcp[rnk[i]-1] = h
  }
  return lcp
end

# lcp array for string
def lcp_array(s, sa)
  return lcp(s.bytes, sa)
end

s = gets.chomp
lcp = lcp_array(s, suffix_array(s))
ans = s.size*(s.size+1)/2
lcp.each{ |lcp|
  ans -= lcp
}
puts ans


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

int main(){
    int n, t, e;
    cin >> n >> t >> e;
    int x[n];
    for(int i = 0; i < n; i++)  cin >> x[i];
    for(int i = 0; i < n; i++){
        if(abs(t/x[i]*x[i]-t) <= e || abs((t/x[i]+1)*x[i]-t) <= e){
            cout << i+1 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 3124
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>PP;
const ll MOD = 998244353;
int T[55];
string S[55];
int main(){
  int n;cin >>n;
  for(int i=1;i<=n;i++){
    cin>>S[i]>>T[i];
  }
  string x;cin>>x;
  int off=0;
  int ans=0;
  for(int i=2;i<=n;i++){
    if(S[i-1]==x)off++;
    if(off==1)ans+=T[i];
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<deque>
using namespace std;
const int N=200100;
int n,a[N];
deque<int> q;
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    bool f=0;
    for(int i=1;i<=n;++i)
    {
        int t;
        cin>>t;
        if(!f)
            q.push_back(t);
        else 
            q.push_front(t);
        f=!f;
    }
    if(!f)
        while(!q.empty())
        {
            cout<<q.front()<<' ';
            q.pop_front();
        }
    else
        while(!q.empty())
        {
            cout<<q.back()<<' ';
            q.pop_back();
        }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3072
N = int(input())

def low_divisors(N):
  K=1
  low_divs = []
  while K*K <= N:
    if N%K == 0:
      low_divs.append(K)
    K += 1

  return low_divs

L_divs = low_divisors(N)
D = []

for i in range(len(L_divs)):
  D.append(L_divs[i]+N//L_divs[i])
  
print(min(D)-2)

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

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/10;
    public static final int inf = Integer.MAX_VALUE/10;

    static void solve(InputReader in, PrintWriter out){
        double n = in.nd();
        /*int ans = 0;
        for (int i = 0; i*4 <= n; i++) {
            if((n-i*4)%7==0) ans++;
        }
        out.println(ans>0?"Yes":"No");*/
        out.println(Math.round(Math.ceil(5*n/7))<=Math.round(Math.floor(3*n/4))?"Yes":"No");
    }

    public static void main(String[] args) throws Exception{
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public Double nd(){
            return Double.parseDouble(ns());
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 21204
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define MOD (long long int)(1e9+7)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}

int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  ll n;cin>>n;
  vector<ll> A(n);
  rep(i,n){
    cin>>A[i];

  }
  sort(all(A));
  if(A.back() - A[0] >= 2){
    cout<<"No"<<endl;
    return 0;
  }

  if(A[n-1] == A[0]){
    ll max = n / 2;
    if(A[0] > max){
      if(A[0]+1 == n){
        cout<<"Yes"<<endl;
        return 0;
      }
      cout<<"No"<<endl;
    }else{
      cout<<"Yes"<<endl;
    }
    return 0;
  }

  ll m = 0;
  rep(i,n-1){
    m++;
    if(A[i] != A[i+1]) break;
  }

  ll k = n-m;
  if(k == 1){
    cout<<"No"<<endl;
    return 0;
  }
  ll min = m + 1;
  ll max = m + k/2;
  if(min <= A.back() && A.back() <= max){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }

  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std ;
#define Next( i, x ) for( register int i = head[x]; i; i = e[i].next )
#define rep( i, s, t ) for( register int i = (s); i <= (t); ++ i )
#define drep( i, s, t ) for( register int i = (t); i >= (s); -- i )
#define re register
#define int long long
int gi() {
	char cc = getchar() ; int cn = 0, flus = 1 ;
	while( cc < '0' || cc > '9' ) {  if( cc == '-' ) flus = - flus ; cc = getchar() ; }
	while( cc >= '0' && cc <= '9' )  cn = cn * 10 + cc - '0', cc = getchar() ;
	return cn * flus ;
}
const int N = 1e6 + 5 ;
const int P = 998244353 ; 
int fpow( int x, int k ) {
	int ans = 1, base = x ;
	while( k ) {
		if( k & 1 ) ans = ans * base % P ;
		base = base * base % P, k >>= 1 ; 
	} return ans ; 
}
int n, m, ans, fac[N], inv[N] ; 
int C( int x, int y ) {
	if( y > x ) return 0 ;
	return fac[x] * inv[y] % P * inv[x - y] % P ; 
}
signed main()
{
	n = gi(), m = gi() ; if( n < m ) swap( n, m ) ; fac[0] = 1, inv[0] = 1 ;
	rep( i, 1, 2 * n ) fac[i] = fac[i - 1] * i % P, inv[i] = fpow( fac[i], P - 2 ) ;
	ans = max( n, m ) ; int num = 0 ;
	rep( i, 1, m ) num = ( num + C( n + m - 2 * i, n - i ) * C( 2 * i, i ) % P ) % P ;
	num = num * fpow( 2, P - 2 ) % P * fpow( C(n + m, n), P - 2 ) ;
	ans = ( ans + num ) % P ;
	printf("%lld\n", ans ) ;
	return 0 ;
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  while(cin>>n,n){
    ll ans=1,ans2=n;
    for(ll i=2;i<=110000;i++){
      ll nn=n-(i*(i+1))/2;
      if(nn>=0&&nn%i==0){
	ans=i;
	ans2=nn/i+1;
      }
    }
    cout<<ans2<<" "<<ans<<endl;
  }
  return 0;
}



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

int main(){
    string A,B,C ;
    cin>>A>>B>>C;
    cout<<((A[A.size()-1] == B[0]) && (B[B.size()-1] == C[0] ) ? "YES" : "NO")<<endl;
     
    return 0;
}


Measured memory_bytes: 256
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1149&lang=jp
#include<iostream>
#include<fstream>
#include<array>
#include<vector>
#include<utility>
#include<algorithm>

using namespace std;

#define fin cin

bool cmp(pair<int, int> _p1, pair<int, int> _p2)
{
    return _p1.first * _p1.second < _p2.first * _p2.second;
}



int main()
{
   // ifstream fin("in.txt");

    int n{0}, w{0}, d{0};

    while(true)
    {
        fin >> n >> w >> d;

        if( !(n | w | d) )break;

        vector< pair<int, int> > cake{pair<int, int> (w, d)};

        vector<int> p(n);
        vector<int> s(n);


        for(int i = 0; i < n; i++)
        {
            fin >> p[i] >> s[i];
        }




        for(int i = 0; i < n; i++)
        {
            //cake[p[i]]???s[i]??§??????
            //cake[p[i]].first = w
            //cake[p[i]].second = d

            int w = cake[p[i] - 1].first;
            int d = cake[p[i] - 1].second;
            

            int mod = s[i] % (d + w);


            //????????????
            if(mod < w)
            {
                pair<int, int> cake1{mod, d};
                pair<int, int> cake2{w - mod, d};

                if(mod <= w / 2)
//                if(cake1.first * cake1.second < cake2.first * cake2.second)
                {
                    cake.push_back(cake1);
                    cake.push_back(cake2);
                }
                else
                {
                    cake.push_back(cake2);
                    cake.push_back(cake1);                    
                }

            }
            //?¨??????????
            else
            {
                mod -= w;
                pair<int, int> cake1{w, mod};
                pair<int, int> cake2{w, d - mod};

                if(mod <= d / 2)
                {
                    cake.push_back(cake1);
                    cake.push_back(cake2);
                }
                else
                {
                    cake.push_back(cake2);
                    cake.push_back(cake1);              
                }
            }

            auto itr = cake.begin();
            itr += (p[i] - 1);
            cake.erase(itr);
            
            for_each(cake.begin(), cake.end(), 
            [](auto p){
      //          cout << p.first << " : " << p.second << endl;
                });
            
           // cout << endl;
        
        }

        vector<int> area{};
        for_each(cake.begin(), cake.end(), 
        [&](auto p){
            area.push_back(p.first * p.second);
        });

        sort(area.begin(), area.end());

        for_each(area.begin(), --area.end(), 
        [](auto p){
            cout << p << " ";
        });

        cout << area[area.size() - 1] << endl;

    }
    


    return 0;
}

Measured memory_bytes: 3056
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

#define T0(T) T
#define T1(T) vector<T0(T)>
#define T2(T) vector<T1(T)>
#define T3(T) vector<T2(T)>

#define V0(v, T,    ...) v
#define V1(v, T, n, ...) T1(T)(n, V0(v, T, __VA_ARGS__))
#define V2(v, T, n, ...) T2(T)(n, V1(v, T, __VA_ARGS__))
#define V3(v, T, n, ...) T3(T)(n, V2(v, T, __VA_ARGS__))

int main() {
	LL n, k;
	cin >> n >> k;
	vector<LL> h(n + 2);
	inc1(i, n) { cin >> h[i]; }
	
	LL INF = 1e15;
	auto dp = V3(INF, LL, n + 2, n + 2, n + 2);
	dp[0][0][0] = 0;
	incII(i, 0, n) {
	incII(u, 0, k) {
	incII(p, 0, n + 1) {
		setmin(dp[i + 1][u    ][i + 1], dp[i][u][p] + max(0LL, h[p] - h[i + 1]));
		setmin(dp[i + 1][u + 1][p    ], dp[i][u][p]);
	}
	}
	}
	
	LL ans = INF;
	incII(u, 0, k) { setmin(ans, dp[n + 1][u][n + 1]); }
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 219776
n = gets.chomp.to_i
p = gets.chomp.split.map(&:to_i)

diff_count = (1..n).zip(p).inject(0) do |diffs, ary|
  if ary[0] == ary[1]
    diffs += 0
  else
    diffs += 1
  end
end

if diff_count < 3
  puts 'YES'
else
  puts 'NO'
end

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
using namespace std;
 
typedef pair<int,int> pii;
 
int main(){
    int n, m, a, b, c;
    cin >> n >> m;
    vector<int> d(n), cnt(n);
    vector<vector<pii> > G(n);
     
    for(int i = 0; i < m; ++i){
        cin >> a >> b >> c;
        G[a].push_back(pii(b, c));
        ++cnt[b];
    }
     
    queue<int> q;
    q.push(0);
    while(!q.empty()){
        for(int i = 0; i < G[q.front()].size(); ++i){
            int t = G[q.front()][i].first;
            d[t] = max(d[t], d[q.front()] + G[q.front()][i].second);
            if(!--cnt[t]){ q.push(t); }
        }
        q.pop();
    }
     
    cout << d.back() << endl;
}

Measured memory_bytes: 1220
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
using static AtCoder.Tool;
namespace AtCoder
{
    class AC
    {
        const int mod = 1000000007;
        const int INF = int.MaxValue / 2;
        const long SINF = long.MaxValue / 2;
        static readonly int[] dx = { 0, 1, 0, -1 };
        static readonly int[] dy = { 1, 0, -1, 0 };
        

        static void Main(string[] args)
        {
            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);
            var cin = new Scanner();

            int N = int.Parse(Console.ReadLine());
            var A = cin.SplitReadL();
            Sort(A);
            Reverse(A);
            Dictionary<long, int> d = new Dictionary<long, int>();
            for(var i = 0; i < N; i++)
            {
                if (!d.ContainsKey(A[i])) { d[A[i]] = 0; }
                d[A[i]]++;
            }
            long ans = 0;

            for (var i = 0; i < N; i++)
            {
                for(var e = 31; e > 0; e--)
                {
                    long s = (1L << e);
                    if (d.ContainsKey(s - A[i]) && d[s - A[i]] > 0)
                    {
                        if (s - A[i] == A[i])
                        {
                            if (d[A[i]] >= 2)
                            {
                                d[A[i]] -= 2;
                                ans++;
                            }
                        }
                        else
                        {
                            if (d[A[i]] > 0)
                            {
                                d[A[i]]--;
                                d[s - A[i]]--;
                                ans++;
                            }
                        }
                        break;
                    }
                }
            }

            Console.WriteLine(ans);
            

            //Console.Out.Flush();
        }
        
    }
    public class Scanner
    {
        public int[] SplitRead()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReadL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }
    }

    public static class Tool
    {
        static public void Initialize<T>(ref T[] array, T initialvalue)
        {
            for (var i = 0; i < array.Length; i++)
            {
                array[i] = initialvalue;
            }
        }
    }
}


Measured memory_bytes: 47680
#include <bits/stdc++.h>
#define meow(args...) fprintf(stderr, args)
template<class T1, class T2> inline bool cmin(T1 &a, const T2 &b) {return b<a?(a=b, true):false;}
template<class T1, class T2> inline bool cmax(T1 &a, const T2 &b) {return a<b?(a=b, true):false;}
template<class Type> Type read() {
	Type a;
	bool b;
	unsigned char c;
	while(c=getchar()-48, (c>9)&(c!=253));
	for(a=(b=c==253)?0:c; (c=getchar()-48)<=9; a=a*10+c);
	return b?-a:a;
}
auto rd=read<int>;
typedef unsigned u32;
typedef long long s64;
typedef unsigned long long u64;
//const u32 P=;
//u32 &inc(u32 &a, u32 b) {return (a+=b)<P?a:(a-=P);}
//u32 &dec(u32 &a, u32 b) {return (a-=b)&0x80000000?(a+=P):a;}
//u32 sum(u32 a, u32 b) {return inc(a, b);}
//u32 dif(u32 a, u32 b) {return dec(a, b);}

const int N=2e5;
int n, a[N];
bool chk(int s) {
	std::vector<std::pair<int, int>> d;
	for(int i=1, j; i<n; ++i)
		if(a[i]<=a[i-1]) {
			while(!d.empty()&&d.back().first>a[i]) d.pop_back();
			for(j=a[i]; !d.empty()&&d.back().first==j&&++d.back().second==s; --j) d.pop_back();
			if(j==0) return false;
			if(d.empty()||d.back().first!=j) d.emplace_back(j, 1);
		}
	return true;
}
int main() {
	bool ascent=true;
	n=rd();
	std::generate(a, a+n, rd);
	for(int i=1; i<n; ++i) ascent&=a[i-1]<a[i];
	if(ascent) {
		puts("1");
	} else {
		int l=2, r=n;
		while(l<r) {
			int s=(l+r)/2;
			if(chk(s)) r=s; else l=s+1;
		}
		printf("%d\n", l);
	}
	return 0;
}


Measured memory_bytes: 1024
#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>
#include <complex>
#define ll long long
#define INF 1000000000000000001
#define MOD 1000000007
using namespace std;



int main(){
    int S, W;
    cin >> S >> W;
    if(W>=S){
        cout<<"unsafe"<<endl;
    }else{
        cout<<"safe"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3620
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}"<<endl;
  return o;
}

//逆元　a/b の modをとるとき -> a*modinv(b)%mod
long long modinv(long long a, long long m = 1e9+7) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m; 
  if (u < 0) u += m;
  return u;
}
ll const mod = 1e9+7;

// combination
const int MAX = 510000;
const ll MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// べき乗
ll modpow(ll x, ll n) {
    x = x%MOD;
    if(n==0) return 1;  //再帰の終了条件

    else if(n%2==1) {
        return (x*modpow(x, n-1))%MOD;  //nが奇数ならnを1ずらす
    }
    else return modpow((x*x)%MOD, n/2)%MOD;  //nが偶数ならnが半分になる
}

int main() {
  long double n,m,d;
  long double ans=0;
  cin >> n >> m >> d;
  if (d>0) ans += (m-1)*2*(n-d)/(n*n);
  else ans += (m-1)*(n-d)/(n*n);
  cout << setprecision(10) << ans << endl;
}


Measured memory_bytes: 3788
#include <cmath>
#include <cstdio>
#include <limits>
#include <tuple>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>
#include <iomanip>

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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  map<ll, ll> rp;
  vector<ll> p(n);
  rep(i, n) {
    ll u;
    cin >> u;
    --u;
    rp[u] = i;
    p.at(i) = u;
  }

  ll s = p.at(0);
  vector<ll> a(n), b(n);
  a.at(s) = 0;
  b.at(s) = 0;
  for (int i = s + 1; i < n; ++i) {
    if (rp.at(i) > rp.at(i - 1)) {
      b.at(i) = b.at(i - 1) - 1;
      a.at(i) = rp.at(i) - b.at(i);
    } else {
      a.at(i) = a.at(i - 1) + 1;
      b.at(i) = rp.at(i) - a.at(i);
    }
  }
  for (int i = s - 1; i >= 0; --i) {
    if (rp.at(i) < rp.at(i + 1)) {
      b.at(i) = b.at(i + 1) + 1;
      a.at(i) = rp.at(i) - b.at(i);
    } else {
      a.at(i) = a.at(i + 1) - 1;
      b.at(i) = rp.at(i) - a.at(i);
    }

  }

  ll minab = min(*min_element(all(a)), *min_element(all(b)));
  rep(i, n) {
    cout << a.at(i) - minab + 1 << " ";
  }
  cout << endl;
  rep(i, n) {
    cout << b.at(i) - minab + 1 << " ";
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 2432
import java.util.Scanner;

class Main {

	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int count = in.nextInt();
		int w = 0;
		int p = 0;
		int max=0;
		double totalw=0;
		int[] c = new int[n];
		for (int i = 0; i < n; i++) {
			c[i] = in.nextInt();
			totalw+=c[i];
			if (max< c[i]) {
				max = c[i];
			}
		}
		
		p=(int)Math.ceil(totalw/count);
		if(max>p) {
			p=max;
		}
		int t = 1;
		boolean flg = true;
		do {
			flg = true;
			t = 1;
			w = 0;

			for (int i = 0; i < n; i++) {
				if (w + c[i] > p) {
					t += 1;
					w = c[i];
				} else {
					w += c[i];
				}
				if (t > count) {
					p+=1;
					flg = false;
					break;
				}
			}


		}while(!flg);

		System.out.println(p);
		in.close();
	}

}



Measured memory_bytes: 70596
#include<bits/stdc++.h>
using namespace std;
int main(){

    string s;
    cin>>s;
    if(s=="Sunny"){
        cout<<"Cloudy"<<endl;
    }
    else if(s=="Cloudy"){
        cout<<"Rainy"<<endl;
    }
    else if (s=="Rainy"){
        cout<<"Sunny"<<endl;

    }

}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
#define task "tst"
using namespace std;
const ll N = 1e6 + 9;
const ll inf = 1e8;
typedef pair<ll,ll> LL;

ll n,k,a[N],i,j,b[N];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    }
    cin>>n>>k;
    for (i = 1;i <= n;i++) cin>>a[i];
    if (k > 50) for (i = 1;i <= n;i++) cout<<n<<" ";
    else{
        for (i = 1;i <= k;i++){
            memset(b,0,sizeof(b));
            for (j = 1;j <= n;j++){
                b[max(1ll,j - a[j])]++;
                b[j + a[j] + 1]--;
            }
            //for (j = 1;j <= n;j++) cout<<b[j]<<" "; cout<<"\n";
            for (j = 1;j <= n;j++) a[j] = a[j - 1] + b[j];
        }
        for (i = 1;i <= n;i++) cout<<a[i]<<" ";
    }
}


Measured memory_bytes: 12944
#include <iostream>
#include <utility>
#include <string>
#include <queue>
#include <map>

using namespace std;

typedef pair<string,int> P;

int main() {
	string str;
	char col[3]={'r','g','b'};

	while(cin>>str,str[0]!='0') {
		queue<P> que;
		map<string,bool> mp;

		mp[str]=true;
		que.push(P(str,0));
		int ans=-1;
		while(!que.empty()) {
			P p=que.front();
			que.pop();
			int len=p.first.length();
			bool f=true;
			for(int i=0;i<len-1;i++) {
				if(p.first[i]!=p.first[i+1]) {
					f=false;
					pair<int,int> tmp(p.first[i],p.first[i+1]);
					for(int j=0;j<3;j++) {
						if(p.first[i]!=col[j]&&p.first[i+1]!=col[j]) {
							p.first[i]=p.first[i+1]=col[j];
							break;
						}
					}
					if(mp[p.first]==false) {
						mp[p.first]=true;
						que.push(P(p.first,p.second+1));
					}
					p.first[i]=tmp.first;
					p.first[i+1]=tmp.second;
				}
			}
			if(f) {ans=p.second;break;}
		}
		if(ans==-1) {
			cout<<"NA"<<endl;
		}else {
			cout<<ans<<endl;
		}
	}
}

Measured memory_bytes: 2912
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int N = Integer.parseInt(sc.next());
    	Set<Integer> a = new HashSet<Integer>();

    	for (int i=0; i<N; i++){
    		a.add(Integer.parseInt(sc.next()));
    	}

    	System.out.println(a.size());
    }
}

Measured memory_bytes: 22612
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;

int n, k;
vector<string> c;
string a, b;
int main()
{
	int i, j;
	cin >> a;
	cin >> k;
	for (i = 0; i < a.size(); i++) {
		for (j = 0; j < k; j++) {
			if (i + j >= a.size()) break;
			c.push_back(a.substr(i, j + 1));
		}
	}
	sort(c.begin(), c.end());
	unique(c.begin(), c.end());
	cout << c[k - 1];
    return 0;
}


Measured memory_bytes: 1660
s = input()
mmyy, yymm = False, False
if "01" <= s[:2] <= "12":
	mmyy = True
if "01" <= s[2:] <= "12":
    yymm = True
    
if yymm and mmyy:
	print('AMBIGUOUS')
elif yymm:
	print('YYMM')
elif mmyy:
	print('MMYY')
else:
	print('NA')

Measured memory_bytes: 3060
# frozen_string_literal: true
def query(num)
  p(num)
  STDOUT.flush
  state = gets
  exit if state == "Vacant\n"
  state
end

n = gets.to_i
l = 0
ls = query(l)
r = n - 1
query(r)

loop do
  m = (l + r) / 2
  ms = query(m)

  if ((m - l).even? && ls != ms) || ((m - l).odd? && ls == ms)
    r = m
  else
    l = m
    ls = ms
  end
end


Measured memory_bytes: 2384
#include<stdio.h>
 
int main(void){
  int N,i;
  scanf("%d",&N);
 
  int a[N],min=1001,max=-1;
 
  for(i=0;i<N;i++){
    scanf("%d", &a[i]);
    if(a[i]>max){
      max=a[i];
    }
    if(a[i]<min){
      min=a[i];
    }
  }
 
  printf("%d", max-min);
 
  return 0;
}

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


int main(void){
    char c;
    cin >> c;
    string jadge="aiueo";
    for(int i=0; i<5; i++){
        if(jadge[i]==c){
            cout << "vowel" << endl;
            return 0;
        }
    }

    cout << "consonant" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
int adj[305][305];
pii dp[305][305];
bool check(pii a, pii b){
    if(b.first < a.first || (a.first == b.first && b.second < a.second)) return 1;
    return 0;
}
int main(){
    int n, m, l, q, a, b, c;
    scanf("%d%d%d", &n, &m, &l);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(i != j) dp[i][j] = pii(1e9, 0), adj[i][j] = 1e9+1;
            else dp[i][j] = pii(0, 0);
        }
    }
    for(int i=1;i<=m;i++){
        scanf("%d%d%d", &a, &b, &c);
        adj[a][b] = c;
        adj[b][a] = c;
    }
    for(int k=1;k<=n;k++){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]);
            }
        }
    }

    for(int i=1;i<=n;i++){
        queue<int> q;
        q.push(i);
        while(!q.empty()){
            int u = q.front();
            q.pop();
            for(int j=1;j<=n;j++){
                if(adj[u][j] <= l){
                    pii x = dp[i][u];
                    if(x.second + adj[u][j] <= l) x.second += adj[u][j];
                    else x.first++, x.second = adj[u][j];

                    if(check(dp[i][j], x)){
                        q.push(j);
                        dp[i][j] = x;
                    }
                }
            }
        }
    }

    scanf("%d", &q);
    while(q--){
        int s, t;
        scanf("%d%d", &s, &t);
        if(dp[s][t].first == 1e9) printf("-1\n");
        else printf("%d\n", dp[s][t].first);
    }
}

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

int main() {
    int N;
    int A[1000002];
    int Min = 1000000000;
    cin >> N;
    int beforemin = 12345;
    int aftermin = 56789;
    for (int i = 0; i < N; ++i) cin >> A[i];

	while(true){
   		for(int i = 0; i < N; ++i) if((A[i] != 0) && (A[i] < Min)) Min = A[i];
   		if(beforemin == Min) break;
   		for(int i = 0; i < N; ++i) if(A[i] != Min) A[i] = A[i] % Min;
		beforemin = Min;
	}
	cout << Min << endl;

}

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

using namespace std;

int gcd(int a,int b){
	return b==0?a:gcd(b,a%b);
}
int main(){
  int n;
  long long res=0;
  cin>>n;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      for(int k=1;k<=n;k++){
        res+=gcd(gcd(i,j),k);
      }
    }
  }
  cout<<res<<endl;    
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; i++)
using namespace std;
using ll = long signed long;

int main() {

    constexpr ll LINF = ~0ull >> 1;

    vector<ll> anss;

    for (ll n; cin >> n, n; ) {

        ll ans = -1;

        vector<vector<ll>> g(30);
        vector<bitset<50>> l(n);
        REP(i, n) {
            l[i].flip(i);
        }
        REP(i, n) {
            ll f; cin >> f;
            REP(j, f) {
                ll x; cin >> x; x--;
                g[x].push_back(i);
            }
        }
        REP(i, 30) {
            REP(j, g[i].size()) {
                REP(k, j) {
                    ll a = g[i][j], b = g[i][k];
                    auto atmp = l[a], btmp = l[b];
                    l[a] |= btmp;
                    l[b] |= atmp;
                    if (l[a].count() == n || l[b].count() == n) {
                        ans = i+1;
                    }
                    if (ans != -1) break;
                }
                if (ans != -1) break;
            }
            if (ans != -1) break;
        }

        anss.push_back(ans);

    }

    for (ll ans : anss) cout << ans << endl;

}


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

int main() {
  vector<int>v{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin >> k;
  cout << v[k-1];
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(long long i=0;i<n;i++)
using namespace std;
int main(){
    long long N,M;
    cin>>N>>M;
    if(abs(N-M)>=2){
        cout<<0<<endl;
        return 0;
    } else {
        long long na=1;
        long long ma=1;
        for(long long i=1;i<=N;i++)na = na*i%1000000007;
        for(long long y=1;y<=M;y++)ma = ma*y%1000000007;
        if(N!=M)cout<<(na*ma)%1000000007<<endl;
        else cout<<(2*na*ma)%1000000007<<endl;
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

template<class T> inline bool chmin(T& a, T b){
    if(a > b){
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}
vector<bool> seen;
void dfs(const Graph &G, int v){
    seen[v] = true; // vを訪問済みにする
    
    for(auto next_v: G[v]){
        if(seen[next_v]) continue; // next_vが探索済みならスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

int gcd(int a, int b){
    return b != 0 ? gcd(b, a%b) : a;
}
int main(){

    int k;
    cin >> k;

    int ans = 0;
    for(int a = 1; a <= k; a++){
        for(int b = 1; b <= k; b++){
            for(int c = 1; c <= k; c++){
                ans += gcd(a, gcd(b, c));
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3620
#include <stdio.h>

int main(void)
{
    int N;
    int A[N];
    int min;
    int max;

    do{
       scanf("%d", &N);
    }while(N < 1 || N > 1000000000);

    if(N%2 == 0){
        printf("%d", N);
    }else {
       printf("%d", 2 * N);
    }

}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int input;
		int first = 0, second = 0;
		int first_i = 0;
		
		for(int i = 0; i < N; i++) {
			input = Integer.parseInt(sc.next());
			if (first < input) {
				second = first;
				first = input;
				first_i = i;
				
			} else if (second < input) {
				second = input;
			}
		}
		
		for (int i = 0; i < N; i++ ) {
			if (i == first_i) {
				System.out.println(second);
			} else {
				System.out.println(first);
			}
		}
				 
		sc.close();
	}

}


Measured memory_bytes: 91148
#include<stdio.h>

int binarysearch(int* S, int size, int key)
{
    int left = 0, right = size;
    int mid;

    while(left < right){
        mid = (left + right) / 2;
        if(S[mid] == key){
            return mid;
        }else if(key < S[mid]){
            right = mid;
        }else if(key < S[mid + 1]){
            return size;
        }else{
            left = mid + 1;
        }
    };
    return size;
}

int main()
{
    int i, n, q, S[1000000], T[500000], C;
    scanf("%d", &n);
    for(i = 0; i < n; i++) scanf("%d", &S[i]);
    scanf("%d", &q);
    for(i = 0; i < q; i++) scanf("%d", &T[i]);

    C = 0;
    for(int i = 0; i < q; i++){
        if(binarysearch(S, n, T[i]) < n) C++;
    }
    printf("%d\n", C);

    return 0;
}

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

int main() {
    int n;
    cin >> n;
    int a[n], b[n];
    int mx[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        b[i] = a[i];
    }
    sort(b, b + n);

    for (int i = 0; i < n; i++) {
        if (a[i] == b[n - 1]) {
            cout << b[n - 2] << endl;
        } else {
            cout << b[n - 1] << endl;
        }
    }
}

Measured memory_bytes: 3200
#include<stdio.h>
int partition(int*,int,int);
int main(){
  int N,i,j;
  scanf("%d",&N);
  int a[N];
  for(i=0;i<N;i++){
    scanf("%d",&a[i]);
  }
  j=partition(a,0,N-1);
  printf("%d",a[0]);
  for(i=1;i<N;i++){
    if(i==j)printf(" [%d]",a[i]);
    else printf(" %d",a[i]);
  }
  printf("\n");
  return 0;
}
 int partition(int A[],int p,int r){
   int i,x,j,d,e;
  x=A[r];
  i=p-1;
  for(j=p;j<=r-1;j++){
    if(A[j]<=x){
      i=i+1;
      e=A[i];
      A[i]=A[j];
      A[j]=e;
    }
  }
  d=A[i+1];
  A[i+1]=A[r];
  A[r]=d;
  return i+1;
}



Measured memory_bytes: 2132
#include <iostream>
#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
#define MAX 100100
//#define NIL -1

vector<LL> parent(MAX);
vector<LL> length(MAX);

void init(LL n){
    for(LL i=0; i<n; i++){
        parent[i]=i;
        length[i]=1;
    }
}

int find(LL x){
    while(parent[x]!=x){
        x=parent[x];
    }
    return x;
}

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

bool unite(LL x, LL y){
    x=find(x);
    y=find(y);
    if(x==y){
        return false;
    }
    if(length[x]<length[y]){
        swap(x,y);
    }
    parent[y]=x;
    length[x]+=length[y];
    return true;
}

int main() {
    LL n;
    LL m;
    cin >> n >> m;
    LL tmp_a;
    LL tmp_b;
    vector<pair<LL, LL>> ab;
    for(LL i=0; i<m; i++){
        cin >> tmp_a >> tmp_b;
        tmp_a--;
        tmp_b--;
        ab.push_back(make_pair(tmp_a, tmp_b));
    }
    reverse(ab.begin(), ab.end());
    init(n);
    vector<LL> color_num(n, 1);
    vector<LL> ans(m);
    ans[0]=(n*(n-1))/2;
    for(LL i=1; i<m; i++){
        LL p0=find(ab[i-1].first);
        LL p1=find(ab[i-1].second);
        //cout << i << " " << p0 << " " << p1 << endl;
        if(p0!=p1){
            LL tmp0=color_num[p0];
            LL tmp1=color_num[p1];
            LL tmp2=tmp0+tmp1;
            ans[i]=ans[i-1]-(tmp2*(tmp2-1))/2+(tmp0*(tmp0-1))/2+(tmp1*(tmp1-1))/2;
            unite(p0, p1);
            LL p2=find(p0);
            //cout << i << " " << p0+1 << " " << p1+1 << " " << p2+1 << endl;
            if(p2!=p0){
                color_num[p1]=color_num[p0]+color_num[p1];
                color_num[p0]=0;
            }else{
                color_num[p0]=color_num[p0]+color_num[p1];
                color_num[p1]=0;
            }
        }else{
            ans[i]=ans[i-1];
        }
    }

    //for(int i=0; i<n; i++){
    //    cout << i+1 << " " << color_num[i] << endl;
    //}

    //LL p0 = find(ab[m-1].first);
    //LL p1 = find(ab[m-1].second);

    //cout << p0+1 << " " << p1+1 << endl;

    reverse(ans.begin(), ans.end());
    for(LL i=0; i<m; i++){
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 7984
//Binary Search 二分探索
#include <stdio.h>

int A[100000];
int n;


int binarySearch( int key );





int main()
{

  int m;
  int key;
  int i;
  int sum=0;

  scanf("%d",&n);
  for( i = 0; i < n; i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&m);
  for( i = 0; i < m; i++){
    scanf("%d",&key);
    if( binarySearch( key )) sum++;
  }

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

  return 0;
}
    



int binarySearch( int key ) //半分割って半分値より小さいか大きいかで考える方法
{

  int left = 0;
  int right = n;
  int mid;

  while( left < right ){ //左端が右より小ければループ     
    mid = (left + right) / 2;
    if( A[mid] == key ) return 1; //中間の値が一致すればリターン
    if( key < A[mid])   // 探す値が中間の値より小ければ右端を中間に設定する
      right = mid;
    else                //そうでなければ左端を中間+1に設定
      left = mid + 1;
  }

  return 0;
    
}



Measured memory_bytes: 2116
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, start, stop) for (int i = start; i < stop; i++)
#define FORR(i, start, stop) for (int i = start; i > stop; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define REMOVE(v,n) remove(vector<int> v,v+v.size(),int n)
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
#define V(v,i,j) vector(v.begin() + i, v.begin() + j)
#define SUM(v) FOR(i,0,v.size())
#define INSERT(va,vb) va.insert(va.end(), vb.begin(), vb.end())
using namespace std;
typedef vector<int> vint;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

//vector< vector<int> > v (size1, vector<int>(size2) );

int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll> h(n);
    FOR(i,0,n) cin>>h[i];
    
    vector<ll> dp(n,0);

    FOR(i,1,n){
        vector<ll> cost = {};
        FOR(j,1,k+1){
            if(i-j>=0){
                cost.pb(dp[i-j]+abs(h[i]-h[i-j]));
            }
        }
        ll ans = 100000000000;
        FOR(c,0,cost.size()){
            ans = min(ans,cost[c]);
        }
        dp[i] = ans;
    }

    cout << dp[n-1] << endl; 
}

Measured memory_bytes: 1792
s = input()
s2 = ""
for i in s:
    if i != "x":
        s2 += i
if s2 != s2[::-1]:
    print(-1)
else:
    temp = s2[:(len(s2) + 1) // 2]
    ans = 0
    num1 = 0
    num2 = len(s) - 1
    for i in range(len(temp)):
        count1 = 0
        while s[num1] != temp[i]:
            count1 += 1
            num1 += 1
        else:
            num1 += 1
        count2 = 0
        while s[num2] != temp[i]:
            count2 += 1
            num2 -= 1
        else:
            num2 -= 1
        ans += abs(count1 - count2)
    print(ans)

Measured memory_bytes: 9304
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
string alphabet = "abcdefghijklmnopqrstuvwxyz";
string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int g(int x){
  if(x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12)return 0;
  else if(x == 4 || x == 6 || x == 9 || x == 11)return 2;
  else return 3;
}

int main(){
  int a , b;
  cin >> a >> b;
  if(g(a) == g(b))cout << "Yes" << endl;
  else cout << "No" << endl;
}



Measured memory_bytes: 256