akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m-1); i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;


// initialization
const int F_MAX = int(2e5)+10;
ll fac[F_MAX], finv[F_MAX], inv[F_MAX];
void binom_init() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < F_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;
  }
}

// binom mod MOD
ll binom(int n, int k) {
  if (k < 0 || n < k) return 0;
  return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}


int main() {
  binom_init();
  ll h, w, a, b; cin >> h >> w >> a >> b;
  ll ans = 0;
  rep(i, h-a) {
    ans += binom(b-1+i, i) * binom(h-i-1+w-b-1, h-i-1);
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;
typedef long long ll;

string str_cmp(string s1, string s2)
{
  if(s1 == "-")
    return s2;
  else if(s2 == "-")
    return s1;
  else if(s1.size()>s2.size())
    return s1;
  else if(s1.size()<s2.size())
    return s2;
  else
    {
      for( int i=0;i<s1.size();i++ )
	{
	  if(s1[i]>s2[i])
	    return s1;
	  else if (s1[i]<s2[i])
	    return s2;
	}
    }
  return s1;
}

int main()
{
  vector<int>n = {0,2,5,5,4,5,6,3,7,6};
  ll N, M;
  cin >> N >> M;
  vector<string>dp(N+10, "-");
  vector<int>a(M);
  for(int i=0;i<M;++i)
    {
      cin >> a[i];
    }

  dp[0] = "";
  for(int i=0;i<N;++i)
    {
      if(dp[i] == "-")
	continue;
      for(int j=0;j<M;++j)
	dp[i+n[a[j]]] = str_cmp(dp[i+n[a[j]]], dp[i]+(char)(a[j]+'0'));
    }
  /*
  for( int i=0;i<N+1;i++ )
    cout << i << ":" << dp[i] << " ";
  cout << endl;
  */
  cout << dp[N] << endl;
}


Measured memory_bytes: 43136
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

typedef long long ll;
const int MAX_N = 1e5+10;

int main(int argc, char const *argv[])
{
    ll n, a[MAX_N], b[MAX_N];
    cin >> n;
    for (ll i = 0; i < n; ++i) scanf("%lld %lld", &a[i], &b[i]);

    priority_queue<ll> pq;
    for (ll i = 0; i < n; ++i) {
        pq.push(a[i]+b[i]);
    }

    ll ans = 0;

    for (int i = 0; i < n; ++i) {
        if (i%2==0) ans += pq.top();
        pq.pop();
    }
    for (int i = 0; i < n; ++i){
        ans -= b[i];
    }

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

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

int main(){
    bool nonprime[100001] = {};
    nonprime[0] = nonprime[1] = true;
    for(int i = 2; i < 100001; i++){
        if(!nonprime[i]){
            for(int j = i+i; j < 100001; j+=i){
                nonprime[j] = true;
            }
        }
    }

    int sum[100001] = {};
    bool stand[100001] = {};

    for(int i = 3; i < 100001; i+=2){
        sum[i] = sum[i-2];
        if(!nonprime[i] && !nonprime[(i+1)/2])  sum[i]++, stand[i] = true;
    }

    int q;
    scanf("%d\n", &q);

    int l, r;
    for(int i = 0; i < q; i++){
        scanf("%d %d\n", &l, &r);
        int ans = sum[r] - sum[l] + stand[l];
        printf("%d\n", ans);
    }

    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#define for0(i,n) for(int i=0;i<n;i++)
#define sp <<" "<<
#define pb(v,i) v.push_back(i)
#define er(v,i) v.erase(v.begin()+i)
#define MOD 1000000007
using namespace std;

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


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

int main(){
  int n,m;
  cin >> n;
  vector<int> T(n);
  int sum = 0;
  for (int i=0; i<n; ++i){
    cin >> T[i];
    sum +=T[i];
  }
  cin >> m;
  int ans = sum;
  for (int i=0; i<m; ++i){
    int p,x;
    cin >> p >> x;
    p --;
    int tmp = sum + x - T[p];
    cout << tmp << endl;
  }
  return 0;
}

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

template <class T>
inline void read(T &res)
{
	char ch; bool flag = false; res = 0; 
	while (ch = getchar(), !isdigit(ch) && ch != '-');
	ch == '-' ? flag = true : res = ch ^ 48;
	while (ch = getchar(), isdigit(ch))
		res = res * 10 + ch - 48;
	flag ? res = -res : 0;
}

const int N = 305;
const int M = 605;
const int mod = 1e9 + 7;
int s1[M], s2[M], a[M], b[M], f[2][N][M];
bool tag[M], del[M]; 
int n, m, cnt;

inline void add(int &x, int y)
{
	x += y;
	x >= mod ? x -= mod : 0;
}

inline void Delete(int x)
{
	del[x] = true;
	for (int i = 1; i <= m; ++i)
		if (!del[i] && a[i] > a[x])
			--a[i];
}

int main()
{	
	read(n);
	m = n << 1;
	for (int i = 1; i <= m; ++i)
		read(a[i]);
	for (int i = 1; i <= m; i += 2)
		if (~a[i] && ~a[i + 1])
		{
			Delete(i);
			Delete(i + 1);
		}
	n = 0; 
	for (int i = 1; i <= m; i += 2)
		if (!del[i])
		{
			if (~a[i])
				tag[a[i]] = true;
			if (~a[i + 1])
				tag[a[i + 1]] = true;
			if (a[i] == -1 && a[i + 1] == -1)
				++cnt;
			++n;
		}
	m = n << 1;
	f[m + 1 & 1][0][0] = 1;
	for (int i = m; i >= 1; --i)
	{
		int now = i & 1, lst = now ^ 1;
		s1[i] = s1[i + 1] + tag[i];
		s2[i] = s2[i + 1] + !tag[i];
		if (tag[i])
		{
			for (int j = 0; j <= s1[i]; ++j)
				for (int k = 0; k <= s2[i]; ++k)
				{
					f[now][j][k] = j > 0 ? f[lst][j - 1][k] : 0;
					add(f[now][j][k], f[lst][j][k + 1]);
				}	
		}
		else
		{
			for (int j = 0; j <= s1[i]; ++j)
				for (int k = 0; k <= s2[i]; ++k)
					f[now][j][k] = (1ll * f[lst][j + 1][k] * (j + 1) 
				                  + (k > 0 ? f[lst][j][k - 1] : 0) + f[lst][j][k + 1]) % mod; 
		}
	}
	int res = f[1][0][0];
	for (int i = 1; i <= cnt; ++i)
		res = 1ll * res * i % mod;
	printf("%d\n", res);
	return 0;
}

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

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

		Arrays.sort(X);
		int[] Y = new int[M-1];
		for (int i=0;i<M-1;i++) {
			Y[i] = Math.abs(X[i+1]-X[i]);
		}
		Arrays.sort(Y);
		if (N>=M) {
			for (int i=0;i<M-1;i++) {
				Y[i] = 0;
			}
		}else if(M != 1) {
			for (int i=M-2;i>(M-2)-(N-1);i--) {
				Y[i] = 0;
			}
		}
		int sum = 0;
		for (int i=0;i<M-1;i++) {
			sum += Y[i];
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 50076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

struct edge {
    int from, to, cost;
};

bool reachableFrom1[2505];
bool reachableToN[2505];
vector<int> g[2505];
vector<int> rg[2505];

void dfs(int v) {
    if (reachableFrom1[v]) return;
    reachableFrom1[v] = true;
    for (int nv : g[v]) {
        dfs(nv);
    }
}

void rdfs(int v) {
    if (reachableToN[v]) return;
    reachableToN[v] = true;
    for (int nv : rg[v]) {
        rdfs(nv);
    }
}

int main() {
    int n, m, p;
    cin >> n >> m >> p;
    vector<edge> edges;
    rep(i, 0, m) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        c -= p;
        c *= -1;
        edge tmp = {a, b, c};
        edges.push_back(tmp);
        g[a].push_back(b);
        rg[b].push_back(a);
    }

    dfs(0);
    rdfs(n - 1);

    vector<int> dist(n, INF);
    dist[0] = 0;
    rep(i, 0, n) {
        for (auto e : edges) {
            if (!reachableFrom1[e.from] || !reachableToN[e.from]) continue;
            if (!reachableFrom1[e.to] || !reachableToN[e.to]) continue;
            if (dist[e.from] == INF) continue;
            if (dist[e.to] > dist[e.from] + e.cost) {
                if (i == n - 1) {
                    cout << -1 << endl;
                    return 0;
                }
                dist[e.to] = dist[e.from] + e.cost;
            }
        }
    }

    cout << max(0, -dist[n - 1]) << endl;
    return 0;
}


Measured memory_bytes: 640
n = int(input())
arr = list(map(int,input().split()))
ans = [0 for i in range(n)]

if n%2 == 0:
    ind = 0
    for i in range(0,n-1,2):
        ans[ind] = arr[n-1-i]
        ind += 1
    for i in range(0,n-1,2):
        ans[ind] = arr[i]
        ind += 1
else:
    ind = 0
    for i in range(0,n,2):
        ans[ind] = arr[n-1-i]
        ind += 1
    for i in range(1,n-1,2):
        ans[ind] = arr[i]
        ind += 1

for i in range(n-1):
    print(ans[i],end=" ")
print(ans[-1])


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

/* define*/
#define Yes(X) puts ( X ? "Yes" : "No")
#define YES(X) puts ( X ? "YES" : "NO")
#define FOR(i, a, b) for ( i = a, i < b ; i++)
#define REP(i, n) for ( i = 0; i < n ; i++)
#define DER(i, n) for ( i = 0; n ; i--)
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))
#define max3(a, b, c) ((max((a), (b)) > (c)) ? max((a), (b)) : (c))
#define min3(a, b, c) ((min((a), (b)) < (c)) ? min((a), (b)) : (c))

/* const */
const int MOD = 1e9 + 7;

/* alias */
typedef long long ll;

/* function */
int cmp(const void *a, const void *b) {
	return *(int*)a - *(int*)b;
}
int cmp2(const void *a, const void *b) {
	return *(int*)b - *(int*)a;
}

/* main */
int i, j, k;

int main() {
	int  n, a, c = 1;
	scanf("%d", &n);
	REP(i, n) {
		scanf("%d", &a);
		if (a % 2 == 0)c *= 2;
	}
	printf("%d", (int)pow(3, n) - c);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  map<string,int> data;
  int MAX=0;
  for(int i=0;i<N;i++){
    string tmp;
    cin>>tmp;
    data[tmp]++;
    MAX=max(data[tmp],MAX);
  }
  
  for(auto tmp:data){
    if(tmp.second==MAX){
      cout<<tmp.first<<endl;
    }
  }
  return 0;
  
}

Measured memory_bytes: 25216
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

	Scanner sca = new Scanner(System.in);
	int n = sca.nextInt();
	String s = sca.next();
	String t = sca.next();
	char a;
	char b;

	StringBuilder sb = new StringBuilder("");


	for(int i = 0; i < n; i++) {
		a = s.charAt(i);
		b = t.charAt(i);
		sb.append(a);
		sb.append(b);
	}
	System.out.println(sb);

	sca.close();
	}
}

Measured memory_bytes: 21844
import fractions
N = int(input())
A = [int(i) for i in input().split()]


def segfunc(x, y):
    return fractions.gcd(x, y)


def init(init_val):
    # set_val
    for i in range(N):
        seg[i+num-1] = init_val[i]
    # built
    for i in range(num-2, -1, -1):
        seg[i] = segfunc(seg[2*i+1], seg[2*i+2])


def update(k, x):
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1], seg[k*2+2])


def query(p, q):
    if q <= p:
        return ide_ele
    p += num-1
    q += num-2
    res = ide_ele
    while q-p > 1:
        if p & 1 == 0:
            res = segfunc(res, seg[p])
        if q & 1 == 1:
            res = segfunc(res, seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res, seg[p])
    else:
        res = segfunc(segfunc(res, seg[p]), seg[q])
    return res


#####単位元######
ide_ele = 0

# num:n以上の最小の2のべき乗
num = 2**(N-1).bit_length()
seg = [ide_ele]*2*num

# 'init(a)': 配列aで初期化。O(N)
# 'update(k,x)': a[k]をxに変更 O(logN)
# 'query(p,q)': [p, q)について "segfunc" したものを返す O(logN)
# 'ide_ele': 単位元。


init(A)
ans = 0
for i in range(N):
    ans = max(ans, fractions.gcd(query(0, i), query(i+1, N)))
print(ans)


Measured memory_bytes: 91488
// lcmとかはg++ -std=c++17 default.cppみたいなかんじで
//vector<vector<ll>> piyo(tate,vector<ll> (yoko));

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1000000000
#define ll long long
#define ln cout<<endl;
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define double long double
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;


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

    ll c,d,n,m,maxi=0,f=0,mini=INF,sum=0;
    string str;
    cin>>n>>m;
    
    vector<ll> h(n);
    rep(i,n) cin>>h[i];
    vector<ll> tf(n);
    rep(i,n) tf[i]=1;
    vector<ll> a(n);
    vector<ll> b(m);
    rep(i,m){
        cin>>c>>d;
        a[c-1]=max(a[c-1],h[d-1]);
        a[d-1]=max(a[d-1],h[c-1]);
    }
    rep(i,n){
        if(a[i]<h[i]) sum++;
    }


    
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 6368
#include <cstdio>
#include <iostream>
using namespace std;
int N = 60;
int f(int t){
	int c=t% N;
	t/=N;
	printf("%02d:%02d:%02d\n",t/N,t%N,c);
	return 0;
}
int main(){
	while (1){
		int h,m,s,t;
		cin>>h>>m>>s;
		if (h==-1&&m==-1&&s==-1)break;
		t=7200-(h*N+m)*N-s;
		f(t);
		f(t*3);
	}
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define sz size()
#define bgn begin()
#define en end()
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
#define Q queue
#define pri priority_queue
#define Pri priority_queue<int,vector<int>,greater<int>>?//小さい順
#define PriP priority_queue<P<int,int>,vector<P<int,int>>,greater<P<int,int>>>
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define all(a)  (a).begin(),(a).end()
#define elif else if

int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int ketas(int a){
  string b=to_string(a);
  int c=0;
  fo(i,keta(a)){
    c+=b[i]-'0';
  }
  return c;
}
bool prime(int a){
  if (a < 2)
    return false;
  else if (a == 2)
      return true;
  else if (a % 2 == 0)
      return false;
  for (int i = 3; i <= sqrt(a) + 1; i += 2){
      if (a % i == 0)
          return false;
  }
  return true;
}
int INF=1000000007;

int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int modinv(int a, int m)
{
    int b = m, u = 1, v = 0;
    while (b)
    {
        int t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}
int lcm(int a, int b)
{
    int c = modinv(gcd(a, b), INF);
    return ((a * c) % INF) * (b % INF) % INF;
}
int kaijou(int a){
  int b=1;
  fo(i,a)
    b*=i+1;
  return b;
}
//12だったら{(2,2),(3,1)}みたいな
V<P<int,int>> factorize(int n){
  V<P<int,int>> res;
  for(int i=2; i*i<=n; i++){
    if(n%i)
      continue;
    res.emplace_back(i,0);
    while(n%i==0){
      n/=i;
      res.back().second++;
    }
  }
  if(n!=1)
    res.emplace_back(n,1);
  return res;
}

int pow_kai(int a, int b){
  int c=1;
  while(b>0){//bit全部捨てるまで
    if(b%2){//一番右のbitが1
      c=c*a;
    }
    a=a*a;
    b>>=1;//全体右に1つシフト
  }
  return c;
}

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

//コード
signed main(){
  string s;
  cin>>s;
  int n=s.size()+1;

  V<int> a(n,0);
  fo(i,s.size()){
    if(s[i]=='<')
      a[i+1]=max(a[i+1],a[i]+1);
  }
  for(int i=s.size()-1; i>=0; i--){
    if(s[i]=='>')
      a[i]=max(a[i],a[i+1]+1);
  }

  int ans=0;
  fo(i,n){
    ans+=a[i];
  }
  cout<<ans<<endl;
}

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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

int main()
{
    int n;
    cin >> n;

    map<int, int> a, b;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;

        if(i % 2)
            b[x]++;
        else
            a[x]++;
    }

    vector<pair<int, int>> p;
    for(auto i: b)
        p.Pb({i.Y, i.X});

    sort(All(p));
    int L = p.size();

    int ans = INT_MAX;
    for(auto i: a){
        int x = i.Y;
        if(i.X == p[L - 1].Y){
            if(L == 1)
                ans = min(ans, n / 2 - x + p[L - 1].X);
            else
                ans = min(ans, n - x - p[L - 2].X);
        }
        else
            ans = min(ans, n - x - p[L - 1].X);

    }

    p.clear();

    for(auto i: a)
        p.Pb({i.Y, i.X});

    sort(All(p));
    L = p.size();

    for(auto i: b){
        int x = i.Y;
        if(i.X == p[L - 1].Y){
            if(L == 1)
                ans = min(ans, n / 2 - x + p[L - 1].X);
            else
                ans = min(ans, n - x - p[L - 2].X);
        }
        else
            ans = min(ans, n - x - p[L - 1].X);

    }

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 8568
#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 all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

struct edge { int to, cost; };

int n, m;
vector<edge> g[101];
bool used[101][101];
int d[100];

void dijkstra(int s) {
	priority_queue<P, vector<P>, greater<P>> que;
	fill(d, d + n, inf);
	d[s] = 0;
	que.push(P(0, s));

	while (que.size()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (d[v] < p.first) continue;
		for (auto& c : g[v]) {
			edge e = c;
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
	rep(i, n) {
		for (auto& c : g[i]) {
			edge e = c;
			if (d[i] + e.cost == d[e.to]) {
				used[i][e.to] = true;
				used[e.to][i] = true;
			}
		}
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	rep(i, m) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		g[a].push_back({ b,c });
		g[b].push_back({ a,c });
	}
	rep(i, n) dijkstra(i);
	int ans = m;
	rep(i, n - 1) {
		for (int j = i + 1; j < n; ++j) {
			if (used[i][j]) ans--;
		}
	}
	cout << ans << endl;
	return 0;
}


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

template<class Iterator>
int LIS(Iterator l, Iterator r){
	auto x = *l;
	pair<int, decltype(x)> p1x(1, x);
	vector<pair<int, decltype(x)>> dp(r - l, p1x);
	for(Iterator i = l; i < r; i++){
		pair<int, decltype(x)> val(0, *i);
		//lower_boundなら狭義, upper_boundなら広義の単調増加
		*lower_bound(dp.begin(), dp.end(), val) = val;
	}
	return lower_bound(dp.begin(), dp.end(), p1x) - dp.begin();
}

template<class Iterator, class Compare>
int LIS(Iterator l, Iterator r, Compare comp){
	auto x = *l;
	pair<int, decltype(x)> p1x(1, x);
	vector<pair<int, decltype(x)>> dp(r - l, p1x);
	const auto compair = [&](pair<int, decltype(x)> a, pair<int, decltype(x)> b){
		return a.first != b.first ? a.first < b.first : comp(a.second, b.second);
	};
	for(Iterator i = l; i < r; i++){
		pair<int, decltype(x)> val(0, *i);
		//lower_boundなら狭義, upper_boundなら広義の単調増加
		*lower_bound(dp.begin(), dp.end(), val, compair) = val;
	}
	return lower_bound(dp.begin(), dp.end(), p1x, compair) - dp.begin();
}

int main(){
	int N, i;
	scanf("%d", &N);
	vector<int> A(N);
	for(i = 0; i < N; i++){
		scanf("%d", &A[i]);
//		A[i] = -A[i];
	}
/*	printf("%d\n", LIS(A.begin(), A.end()));
	return 0;
*/	vector<pair<int, int>> B(N);
	for(i = 0; i < N; i++){
		B[i].first = i;
		B[i].second = A[i];
	}
	printf("%d\n", LIS(B.begin(), B.end(), [](pair<int, int> a, pair<int, int> b){
		if(a.second != b.second){
			return a.second > b.second;
		}
		else{
			return a.first < b.first;
		}
	}));
	return 0;
}

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

public class Main {

	static long count = 0;
	
	public static void main(String[] args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		String[] strArray = reader.readLine().split(" ");
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) arr[i] = Integer.parseInt(strArray[i]);
		mergeSort(arr, 0, arr.length);
		System.out.println(count);
	}

	private static void mergeSort(int[] arr, int left, int right) {
		if (left + 1 < right) {
			int mid = left + (right - left) / 2;
			mergeSort(arr, left, mid);
			mergeSort(arr, mid, right);
			merge(arr, left, mid, right);
		}
	}
 
	private static void merge(int[] arr, int left, int mid, int right) {		
		int n1 = mid - left;
		int n2 = right - mid;		
		int[] L = new int[n1 + 1];
		int[] R = new int[n2 + 1];
		for (int i = 0; i < n1; i++) L[i] = arr[left + i];
		for (int i = 0; i < n2; i++) R[i] = arr[mid + i];
		L[n1] = R[n2] = Integer.MAX_VALUE;
		int i = 0, j = 0;
		for (int k = left; k < right; k++) {
			if (L[i] <= R[j]) {
				arr[k] = L[i];
				i++;
			} else {
				if (i < n1) {
					count += n1 - i;
				}
				arr[k] = R[j];
				j++;
			}
		}
	}
}



Measured memory_bytes: 61052
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e5 + 7;

#include <math.h>
#define PI 3.14159265358979323846264338327950L

vector<vector<int>> V;
int N, M, Q;


int main() {
    char a;
    cin >> a;

    if ((int)a < (int)'a') {
        cout << "A" << endl;
    }
    else {
        cout << "a" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3592
n, m = map(int, input().split())
li = [list(map(int, input().split())) for _ in range(m)]

ball_cnt = [1] * 10**6
check = [0] * 10**6

check[1] += 1

for i in range(m):
    x = li[i][0]
    y = li[i][1]
    
    if check[x] == 1:
        check[y] = 1
    
    ball_cnt[x] -= 1
    ball_cnt[y] += 1
    
    if ball_cnt[x] == 0:
        check[x] = 0
        
print(sum(check))

Measured memory_bytes: 42588
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        int z = 0;
        int k = 0;
        for(int i=0; i<S.length(); i++){
            char tmp = S.charAt(i);
            if(tmp==')'){
                z++;
            }else{
                z--;
            }
            k=Math.max(k,z);
        }
        for(int i=0; i<k; i++){
            S="("+S;
        }
        int x=0;
        for(int i=0; i<S.length(); i++){
            char tmp = S.charAt(i);
            if(tmp=='('){
                x++;
            }else{
                x--;
            }
        }
        for(int i=0; i<x; i++){
            S=S+")";
        }
        System.out.println(S);
    }
}

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

int main(){
    string s;
    cin >> s;
    int count = 0;
    if(s[0] == '1')
        count++;
    if(s[1] == '1')
        count++;
    if(s[2] == '1')
        count++;
    cout << count << endl;
    return 0;
}

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

int main(){

	int i, j;
	int ans;

	for(i=1;i<=9;i++){
		for(j=1;j<=9;j++){
		
		cout << i <<"x" << j <<"=" << i*j << endl;
		
		}

	}

	return 0;



}

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

using namespace std;

int main() {
	long long a, b, c, d;
	cin >> a >> b >> c >> d;

	long long x = max(a * c, b * d);
	long long y = max(a * d, b * c);

	cout << max(x, y) << '\n';

	return 0;
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), m = sc.nextInt(); long k = sc.nextLong();
        int[] a = new int[n];
        long[] pa = new long[n+1];
        int[] b = new int[m];
        long[] pb = new long[m+1];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        for (int i = 0; i < m; i++) {
            b[i] = sc.nextInt();
        }
        for (int i = 1; i <= n; i++) {
            pa[i] = pa[i-1] + a[i-1];
        }
        for (int i = 1; i <= m; i++) {
            pb[i] = pb[i-1] + b[i-1];
        }
        int lo = 0, hi = n + m, bans = 0;
        while (lo <= hi) {
            int mid = (lo + hi) / 2;
            boolean can = false;
            for (int ba = 0; ba <= Math.min(n, mid); ba++) {
                if (mid - ba <= m && pa[ba] + pb[mid - ba] <= k) {
                    can = true;
                    break;
                }
            }
            if (can) {
                bans = mid;
                lo = mid + 1;
            } else {
                hi = mid - 1;
            }
        }
        System.out.println(bans);

    }
}


Measured memory_bytes: 64084
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int a[22];
int m[205];

bool dfs (int ind, int curr, int n )
{
	if (curr == 0 ) return true;
	if (curr < 0 || ind >= n ) return false;
	if (dfs (ind + 1, curr - a[ind], n ) ) return true;
	if (dfs (ind + 1, curr, n ) ) return true;

	return false; 
} 

int main()
{
	memset (a, 0, sizeof (a ) );
	memset (m, 0, sizeof (m ) );
	ios_base::sync_with_stdio(0);

	int n, q;
	cin >> n;
	rep (i, n ) cin >> a[i];
	cin >> q;
	rep (j, q ) cin >> m[j];

	rep (k, q ){
		bool ok = dfs (0, m[k], n );
		cout << (ok ? "yes" : "no" ) << endl;
	} // end rep
		
	return 0;
}

Measured memory_bytes: 1184
#include <stdio.h>

int main(void)
{
  int student[31]={0};
  int i, num;

  student[0] = 1;
  for(i = 0; i < 28; i++){
    scanf("%d", &num);
    student[num] = 1;
  }

  for(i = 1; i < 31; i++){
    if(student[i] == 0)
      printf("%d\n", i);
  }

  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//order_of_key(x) : number of items less than x
//find_by_order(x) : iterator to x

#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F                   first
#define S                   second
#define all(v)              (v).begin(),(v).end()
#define pi                  3.14159265359
ll INF=1e18+10;
ll MOD=998244353;
ll mod=1e9+7;

ll expo(ll a,ll b)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b=b/2;
    }
    return res;
}

ll inv(ll a)
{
    return expo(a,mod-2);
}

int main()
{
    ll n,k;cin>>n>>k;
    ll ans=1;
    ll cur=1;
    k=min(k,n);
    rep(i,1,k+1)
    {
        cur=(cur*(n-i))%mod;
        cur=(cur*inv(i))%mod;
        ll curr=(cur*cur)%mod;
        curr=(curr*n)%mod;
        curr=(curr*inv(n-i))%mod;
        ans=(ans+curr)%mod;
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int a,b,c,d,e,f;
    cin>>a>>b>>c;
    d=a+b;
    if (c>d or c<a)
    {
        cout<<"NO";
        return 0;
    }
    else if (d==c)
    {
        cout<<"YES";
        return 0;
    }
    else if (d>c && c>=a)
    {
        cout<<"YES";
        return 0;
    }
    return 0;
}

Measured memory_bytes: 256
# frozen_string_literal: true

n = gets.to_i
a = []
b = []
c = []
n.times do |i|
  ai, bi, ci = gets.split.map(&:to_i)
  a[i] = ai
  b[i] = bi
  c[i] = ci
end

# [a, b, c]
dp = Array.new(n) { Array.new(3, 0) }
dp[0][0] = a[0]
dp[0][1] = b[0]
dp[0][2] = c[0]

(n - 1).times do |i|
  dp[i + 1][0] = [dp[i][1], dp[i][2]].max + a[i + 1]
  dp[i + 1][1] = [dp[i][0], dp[i][2]].max + b[i + 1]
  dp[i + 1][2] = [dp[i][0], dp[i][1]].max + c[i + 1]
end

puts dp[n - 1].max


Measured memory_bytes: 12416
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			long n = scanner.nextLong(), m = scanner.nextLong();
			if (1L == n) {
				if (1L == m) {
					System.out.println(1);
				} else {
					System.out.println(m - 2);
				}
			} else {
				if (1L == m) {
					System.out.println(n - 2);
				} else {
					System.out.println((n - 2) * (m - 2));
				}
			}
		}
	}
}


Measured memory_bytes: 35668
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


ll gcd(ll a,ll b){
    if(b == 0){
        return a;
    }else{
        return gcd(b, a%b);
    }
}

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll n;
    cin>>n;
    vector<ll> v(n);
    vector<ll> f(n/2), b(n/2);
    for(ll i=0;i<n;++i){
        cin>>v[i];
        if(i % 2 == 0){
            f[i/2] = v[i];
        }else if (i % 2 == 1){
            b[i/2] = v[i];
        }
    }

    vector<pair<ll,ll>> x(100000), y(100000);
    for(ll i=0;i<100000;++i){
        x[i].first = 0;
        x[i].second = i + 1;
        y[i].first = 0;
        y[i].second = i + 1;
    }
    for(ll i=0;i<n/2;++i){
        x[f[i]].first++;
        y[b[i]].first++;
    }
    sort(x.begin(), x.end(), greater<>());
    sort(y.begin(), y.end(), greater<>());

    ll e_1 = x[0].second;
    ll o_1 = y[0].second;

    ll ans;
    if(e_1 != o_1){
        ans = (n / 2 - x[0].first) + (n / 2 - y[0].first);
    }else if(e_1 == o_1){
        ll e = (n / 2 - x[0].first) + (n / 2 - y[1].first);
        ll o = (n / 2 - x[1].first) + (n / 2 - y[0].first);
        ans = min(e, o);
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] a= new int[3];
		for(int i=0;i<3;i++) {
			a[i]=sc.nextInt();
		}
		int kari=0;
		for(int i=0;i<3;i++) {
			for(int j=2;j>i;j--) {
				if(a[j]<a[j-1]) {
					kari=a[j];
					a[j]=a[j-1];
					a[j-1]=kari;
				}
			}
		}
		for(int i=0;i<3;i++) {
			System.out.printf(a[i]+"");
			if(i==2) {
				System.out.println("");
			}else {
				System.out.printf(" ");
			}
		}
	}
}



Measured memory_bytes: 26244
#include<stdio.h>

int main()
{
char s[4];
int i;
int a=0;
for(i=0;i<4;i++)
{
scanf("%c",&s[i]);
if(s[i]=='+')
{
a+=1;
}
if(s[i]=='-')
{
a-=1;
}
}
printf("%d\n",a);
return 0;
}


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

ld dp[303][303][303];

int N, CA, CB, CC;

int main() {
	cin >> N;
	for(int i = 0, c; i < N; i++) {
		cin >> c;
		if(1 == c) CA++;
		else if(2 == c) CB++;
		else CC++;
	}

	for(int s = 1, se = CA+CB*2+CC*3; s <= se; s++) {
		for(int c = s/3; 0 <= c; c--) {
			for(int b = min(N, (s-c*3)/2); 0 <= b; b--) {
				int a = s - c*3 - b*2;
				if(N < a) continue;
				ld &ret = dp[a][b][c];
				ret = N;
				if(c) ret += dp[a][b+1][c-1] * c;
				if(b) ret += dp[a+1][b-1][c] * b;
				if(a) ret += dp[a-1][b][c] * a;
				ret /= a+b+c;
			}
		}
	}

	printf("%.30Lf\n", dp[CA][CB][CC]);
	return 0;
}

Measured memory_bytes: 432384
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair
int N, A[200000], ans[200000] ={};
int main(){
	cin >> N;
	for(int i=0; i<N; i++) cin >> A[i];

	for(int i=N; i>=1; i--){
		int sum = 0;
		for(int j=1; j*i<=N; j++) sum += ans[j*i-1];
		sum %= 2;
		if(sum != A[i-1]) ans[i-1]++;
	}

	int M = 0;
	for(int i=0; i<N; i++){
		assert(ans[i] <= 1);
		if(ans[i] == 1) M++;
	}
	cout << M << endl;
	for(int i=0; i<N; i++){
		if(ans[i] == 1){
			cout << i+1;
			M--;
			if(M > 0) cout << " ";
		}
	}
}


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    LL n;cin >> n;
    vector<LL> a(n);
    inc(i, 0, n) cin >> a[i];
    vector<LL> b(n, -1);

    dec(i, 0, n){
        if(a[i] == 0 && b[i] == -1){
            int j=i;
            for(;j>=0;j--){
                if(a[j] == 0){
                    b[j] = i;
                }else{
                    break;
                }
            }
        }
    }

    LL ans = 0;
    inc(i, 0, n){
        LL x = 0;
        LL s = 0;
        int j = i;
        while(j<n){
            if(a[j] == 0){
                j = b[j]+1;
                continue;
            }
            x ^= a[j];
            s += a[j];
            if(x != s){
                break;
            }
            j++;
        }
        ans += j-i;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3456
def main():

    import numpy as np
    
    n, k = map(int, input().split())
    a = np.array(input().split(), np.int64)
    f = np.array(input().split(), np.int64)
    a.sort()
    a = a[::-1]
    f.sort()
    right = np.max(a*f)
    left = 0
    while right > left:
        middle = (right + left)//2
        b = 0
        
        if np.sum(np.maximum(a-middle//f, 0)) <= k:
            right = middle
        else:
            left = middle+1

    print(right)
if __name__ == '__main__':
    main()

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

int main() {
  string c;
  int N, a=0, b=0, i;
  cin >> N;
  cin >> c;
  
  for(int i=0; i<N; i++) {
    if(c[i] == 'R')a++;
  }
  if(a==0||a==N)cout << 0;
  else {
    for(int i=0;i<a;i++) {
      if(c[i] == 'W')b++;
    }
    cout << b;
  }
}


Measured memory_bytes: 3708
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll t1,t2, r1, r2;
	cin >> t1 >> t2 >> r1 >> r2;
	if(r1 == -1 || r2 == -1){
		if(t1 == t2){
			print("Draw");
		}else if(t1 < t2){
			print("Alice");
		}else{
			print("Bob");
		}
	}else{
		if(r1 == r2){
			print("Draw");
		}else if(r1 > r2){
			print("Alice");
		}else{
			print("Bob");
		}
	}
	
}


Measured memory_bytes: 3176
#include <iostream>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
#define N 2701

ll C[N][N];

void init() {
  C[0][0] = C[1][0] = C[1][1] = 1;
  for (int i = 2; i < N; ++i) {
    for (int j = 0; j <= i; ++j) {
      if (j == 0) C[i][j] = 1;
      else C[i][j] = (C[i-1][j] + C[i-1][j-1]) % mod;
    }
  }
}

int main() {
  int S;
  cin >> S;
  if (S < 3) {
    cout << 0 << '\n';
    return 0;
  }
  init();
  ll ans = 0;
  for (int i = 1; i * 3 <= S; ++i) {
    ans = (ans + C[i+S-i*3-1][i-1]) % mod;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 41872
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

int n, c[30], s[400][30];
int d[30];
int ans[400];

int score() {
	int res = 0;
	int dd[30];
	fill(dd, dd + 30, 0);
	for (int i = 1; i <= n; i++) {
		res += s[i][ans[i]];
		dd[ans[i]] = i;
		for (int j = 1; j <= 26; j++)res -= c[j] * (i - dd[j]);
	}
	return res;
}

signed main() {
	std::random_device rnd;
	cin >> n;
	for (int i = 1; i <= 26; i++)cin >> c[i];
	for (int i = 1; i <= n; i++)for (int j = 1; j <= 26; j++)cin >> s[i][j];
	for (int i = 1; i <= n; i++) {
		int ma = -1000000000, p = 0;
		for (int j = 1; j <= 26; j++) {
			int cnt = 0;
			for (int k = 1; k <= 26; k++)if (j != k)cnt -= c[k] * (i - d[k]);
			cnt += s[i][j];
			if (ma < cnt) {
				ma = cnt;
				p = j;
			}
		}
		ans[i] = p;
		d[p] = i;
	}
	int q = 35;
	while (q) {
		for (int i = 1; i <= n; i++) {
			int ma = -1000000000, p = 0;
			for (int j = 1; j <= 26; j++) {
				ans[i] = j;
				if (ma < score()) {
					ma = score();
					p = j;
				}
			}
			ans[i] = p;
		}
		q--;
	}
	for (int i = 1; i <= n; i++)cout << ans[i] << endl;
	//cout << score() << endl;
}


Measured memory_bytes: 3672
#include <iostream>

using namespace std;

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

Measured memory_bytes: 3068
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

int solve(ll n, ll m, int u){
  ll num[2][2] = {{n,0},{m,0}};
  int f = 0;
  int res = 0;

  while(1){
    ll attack = num[f][0] + num[f][1];
    //debug(attack);
    
    if(u == f){
      ll q = min(attack, num[!f][0]);
      num[!f][0] -= q;
      attack -= q;
      num[!f][1] += q;
      q = min(attack, num[!f][1]);
      num[!f][1] -= q;
    }else{
      ll q = min(attack, num[!f][1]);
      num[!f][1] -= q;
      attack -= q;
      q = min(attack/2, num[!f][0]);
      num[!f][0] -= q;
      attack -= q * 2;
      if(attack && num[!f][0]){
        num[!f][1]++; num[!f][0]--;
      }
    }

    if(num[0][0] + num[0][1] <= 0 || num[1][0] + num[1][1] <= 0) break;
    res++;
    f = !f;
  }
  
  return res;
}

int main(){
  ll n, m;

  scanf("%lld%lld", &n, &m);

  cout << min(solve(n,m,0), solve(n,m,1)) << endl;
  
  return 0;
}



Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(j, m) for (int j = 0; j < (int)(m); j++)
#define rep2(i, l, n) for (int i = l; i < (int)(n); i++)


int main() {
    ll A,B,C,X;
    cin >> A >> B >> C >> X;
    ll count = 0;
    rep(i,A + 1) {
        rep(j,B + 1) {
            rep(k,C + 1) {
                if (X == 500*i + 100*j + 50*k) {
                    count++;
                }
            }
        }
    }
    cout << count << endl;
}



Measured memory_bytes: 3584
#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>

using namespace std;

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

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

int dp1[1005][1005];//number
int dp2[1005][1005];//last prime
int reached[1005][1005];

int caves[1004][1004];

bool in(int x,int y){
  if(x<0 || 1004<=x || y<0 || 1004<=y)return false;
  if(caves[x][y]!=0)return false;
  return true;
}


int main(void) {
  int i,j;
  int dx[4]={0,1,0,-1};
  int dy[4]={1,0,-1,0};
  int cnt=1004*1004;
  i=0,j=0;
  int k=0;
  while(cnt>0){
    caves[i][j]=cnt;
    if(!in(i+dx[k%4],j+dy[k%4]))k++;
    i=i+dx[k%4];
    j=j+dy[k%4];
    cnt--;
  }

  int max_n=1000005;
  vector<bool> prime(max_n,true);
  prime[0]=prime[1]=false;
  rep(i,max_n)if(prime[i]){
    for(j=2;i*j<max_n;j++)prime[i*j]=false;
  }

  int m,n;
  while(1){
    cin>>m>>n;
    if(m==0)break;
    rep(i,1004)rep(j,1004)dp1[i][j]=dp2[i][j]=reached[i][j]=0;
    int sx,sy;
    rep(i,1004)rep(j,1004)if(caves[i][j]==n)sx=i,sy=j;
    if(prime[n])dp1[sx][sy]=1,dp2[sx][sy]=n;
    reached[sx][sy]=1;
    int ans1=0,ans2=0;
    for(i=sx+1;i<1004;i++)rep(j,1004){
	vector< pair<int,pii> > p;
	int k;
	int d[3]={-1,0,1};
	rep(k,3)
	  p.push_back(pair<int,pii>(reached[i-1][j+d[k]],pii(dp1[i-1][j+d[k]],dp2[i-1][j+d[k]])));
	sort(all(p));
	if(p[2].first==0)continue;
	if(caves[i][j]>m){//洞穴を全部見終わったとき
	  if(ans1<p[2].second.first || (ans1==p[2].second.first && ans2<p[2].second.second)){
	    ans1=p[2].second.first;
	    ans2=p[2].second.second;
	  }
	}else{//遷移するとき
	  reached[i][j]=1;
	  //	  cout<<caves[i][j]<<" "<<dp1[i][j]<<" "<<dp2[i][j]<<endl;
	  if(prime[caves[i][j]]){
	    dp1[i][j]=p[2].second.first+1;//素数の個数
	    dp2[i][j]=caves[i][j];//一番最後の素数
 
	  }else{
	    dp1[i][j]=p[2].second.first;
	    dp2[i][j]=p[2].second.second;
	  }
	}
      }
    cout<<ans1<<" "<<ans2<<endl;
  }
}



Measured memory_bytes: 18980
N, K = list(map(int, input().split()))
l = [0] * 10 ** 5
for i in range(N):
    a, b = map(int, input().split())
    l[a-1] += b
count = 0
for j in range(10**5):
    count += l[j]
    if count >= K:
        print(j+1)
        break


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

int main(){
  int N,T,S=0;
  cin >> N;
  T = N;
  while(N>0){
  	S+=N%10;
    N/=10;
  }
  if((T%S)==0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

int main(){
  int n; cin >> n;
  vector<int> a(n);
  vector<int> vec(n);
  rep(i,n){
    int x; cin >> x;
    a.at(i) = vec.at(i) = x;
  }

  sort(all(vec));

  if(vec.at(n-1)!=vec.at(n-2)){
    rep(i,n){
      if(a.at(i)==vec.at(n-1)) cout <<vec.at(n-2) << endl;
      else cout << vec.at(n-1) << endl;
    }
  }else{
    rep(i,n) cout << vec.at(n-1) << endl;
  }
}

Measured memory_bytes: 3200
#include <iostream>

using namespace std;

void print(int A[], int N) {
    for (int k = 0; k < N-1; k++) {
        cout << A[k] << " ";
    }
    cout << A[N-1] << "\n";

}
void selectionSort(int A[], int N) {
    int count = 0;
    for (int i = 0; i < N; i++) {
        int minj = i;
        for (int j = i; j < N; j++) {
            if (A[j] < A[minj]) {
                minj = j;
            }
        }
        if (minj != i) {
            swap(A[i], A[minj]);
            count++;
        }

    }
    print(A, N);
    cout << count << "\n";
}
static int A[100];
int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> A[i];
    }
    
    selectionSort(A, n);
    return 0;

}


Measured memory_bytes: 3124