akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
typedef pair<ll, int> P;
bool used[300005];
priority_queue<ll, vector<ll>, greater<ll> > Q1;
priority_queue<P, vector<P>, greater<P> > Q2;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  int a[3*N]; FOR(i,0,3*N) cin >> a[i];
  CLR(used);
  vector<pair<int, int> > b;
  // どこで前半後半きれるか全探索
  ll pre = 0, bak = 0;
  FOR(i,0,N) {
    pre += a[i];
    Q1.push(a[i]);
  }
  FOR(i,N,3*N) {
    b.push_back(make_pair(a[i], i));
  }
  sort(b.begin(), b.end());
  FOR(i,0,N) {
    bak += b[i].first;
    used[b[i].second] = true;
  }
  FOR(i,N,2*N) {
    Q2.push(P(b[i].first, b[i].second));
  }
  ll ans = pre - bak;
  FOR(i,N,2*N) {
    Q1.push(a[i]);
    pre += a[i];
    pre -= Q1.top();
    Q1.pop();
    if(used[i]) {
      P p = Q2.top(); Q2.pop();
      while(used[p.second] && !Q2.empty()) p = Q2.top(),Q2.pop();
      used[p.second] = true;
      bak -= a[i];
      bak += p.first;
    }
    used[i] = true;
    ans = max(ans, pre - bak);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 7152
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=200005,mod=1000000007;
int n,ans,a[N],b[N],jc[8005],ijc[8005];
struct array{
	struct arr{
		int a[4005];
		int& operator [] (int n){
			return a[n+2000];
		}
	}a[4005];
	arr& operator [] (int n){
		return a[n+2000];
	}
}f;
int fastpow(int a,int x){
	int res=1;
	while(x){
		if(x&1){
			res=1LL*res*a%mod;
		}
		x>>=1;
		a=1LL*a*a%mod;
	}
	return res;
}
int add(int a,int b){
	a+=b;
	return a<mod?a:a-mod;
}
int cut(int a,int b){
	a-=b;
	return a>=0?a:a+mod;
}
int c(int n,int m){
	return 1LL*jc[n]*ijc[m]%mod*ijc[n-m]%mod;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&a[i],&b[i]);
		f[a[i]][b[i]]++;
	}
	for(int i=2000;i>=-2000;i--){
		for(int j=2000;j>=-2000;j--){
			f[i][j]=add(f[i][j],add(f[i+1][j],f[i][j+1]));
		}
	}
	jc[0]=1;
	for(int i=1;i<=8000;i++){
		jc[i]=1LL*jc[i-1]*i%mod;
	}
	ijc[8000]=fastpow(jc[8000],mod-2);
	for(int i=7999;i>=0;i--){
		ijc[i]=1LL*ijc[i+1]*(i+1)%mod;
	}
	for(int i=1;i<=n;i++){
		ans=add(ans,cut(f[-a[i]][-b[i]],c(2*a[i]+2*b[i],2*a[i])));
	}
	printf("%lld\n",1LL*ans*500000004%mod);
	return 0;
}

Measured memory_bytes: 64384
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
/*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
int main() {
    string s,t;
    cin >>s >> t;
    bool che = 1;
    for(int i=0;i<s.size();i++){
        if(s.at(i)!=t.at(i))che=0;
    }
    if(che){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}
    



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

int main(){
  string s;
  int K;
  cin >> s >> K;
  int leng = s.size();
  vector<string> d;
  for (int i=0; i<K; i++){
    for (int l=0; l+i<leng; l++){
      d.push_back(s.substr(l, i+1));
    }
  }
  sort(d.begin(), d.end());
  d.erase(unique(d.begin(), d.end()), d.end());
  cout << d[K-1] << endl;
  return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define all(v)   v.begin(), v.end()
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define START cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define isOdd(n)    (n&1)
#define LLMAX LLONG_MAX
#define LLMIN LLONG_MIN
#define IMN INT_MIN
#define IMX INT_MAX
#define pow(n, m) power((ll)n, (ll)m)
#define numOfDigits(n)  ((n)? (ll)(log10(n))+1 : 1)
#define mem(x, val)    memset(x, val, sizeof(x)) //be careful
#define var auto
#define MOD 1000000007


typedef long long ll;
typedef long double ld;
typedef double dd;
typedef pair<int, int> pii;

int main()
{
    START
    //freopen("test cases\\in.txt", "r", stdin) ;
     string s; cin>>s;
     int n = s.size();
     char c = s.back();
     int c1 = 0, c2 = 0;
     for(int i = n-1; i+1>=0; i--)
        if(s[i]!=c)c1++, c = s[i];

    c = s[0];
    for(int i = 0; i<n; i++)
        if(s[i]!=c)c2++, c = s[i];
    cout<<min(c1, c2);
	return 0;
}


Measured memory_bytes: 512
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G;
		int N = I[0], W = I[1];
		var dp = new long[W + 1];
		for (var i = 0;i<N;i++)
		{
			I = G;
			int w = I[0], v = I[1];
			for (var x = W; x >= w; x--) dp[x] = Max(dp[x], dp[x - w] + v);
		}
		WriteLine(dp[W]);
	}
}


Measured memory_bytes: 13376
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main() {
	int a,b,tmp,count;
	while(cin >> a >> b){
		count = 0;
		tmp = a + b;
		while(tmp > 0){
			count++;
			tmp /= 10;
		}
		cout << count << endl;
	}
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<string.h>
#define LEN 100005

int min(int,int);

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P x){
  Q[tail] = x;
  tail = (tail+1)%LEN;
}

P dequeue(){
  P x = Q[head];
  head = (head+1)%LEN;
  return x;
}

int min(int a,int b){return a<b?a:b;}

int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1;
  tail = n+1;

  while(head != tail){
    u = dequeue();
    c = min(q,u.t);
    u.t -= c;
    elaps += c;
    if(u.t>0){
      enqueue(u);
    }

    else{
      printf("%s %d\n",u.name,elaps);
    }
  }

  
  return 0;
}

Measured memory_bytes: 10756
n=int(input())

w=[]

for i in range(n):
    s=input()
    w.append(s)
    
w2 = list(set(w))

f=1

if len(w)>len(w2):
   f=-1

pre = list(w[0])

for i in range(1, n):
   now = list(w[i])
   
   if not pre[len(pre)-1]==now[0]:
       f=-1
   pre = []
   pre = now
       
if f>0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define fast ios_base::sync_with_stdio(false)
#define cintie cin.tie(NULL)
int main()
{
	ll n,i;
	cin>>n;
	ll a[n+10];
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	ll f=0;
	for(i=1;i<=n;i++)
	{
		if(a[i]!=i)
		f=f+1;
	}
	if(f<=2)
	{
		cout<<"YES"<<endl;
	}
	else
	{
		cout<<"NO"<<endl;
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include<queue>
#include<vector>
#define INF 1e9
using namespace std;

int main()
{
    char s[20];
    while(cin>>s)
    {
        int c1=0;
        int flag=0,flag2=1;
        if(s[0]=='A')
        {
            for(int i=1;s[i]!='\0';i++)
            {
                if(s[i]=='C'&&s[i+1]!='\0'&&i!=1)
                    c1++;
                if(s[i]!='C'&&s[i]>='A'&&s[i]<'Z')
                    flag2=0;
            }
            if(c1==1&&flag2==1)
                flag=1;
        }
        if(flag==1)
            printf("AC\n");
        else
            printf("WA\n");
    }
    return 0;
}










Measured memory_bytes: 256
from collections import deque
n = int(input())
c = input()
d = deque()
a = 0; b = 0
for i in range(n):
    d.append(c[i])
for _ in range(len(d)):
    if d[0] == "R":
        d.popleft()
    else:
        break
for _ in range(len(d)):
    if d[-1] == "W":
        d.pop()
    else:
        break
for i in range(len(d)):
    if d[i] == "R": a += 1
for i in range(a):
    if d[i] == "W": b += 1
print(b)

Measured memory_bytes: 11008
import sys
a,b,c = map(int,input().split())
if a >= c or b >= c:
    print("No")
    sys.exit()
if a**2+b**2+c**2-2*a*b-2*a*c-2*b*c > 0:
    ans = "Yes"
else:
    ans = "No"
print(ans)

Measured memory_bytes: 9048
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;




class Main{


	static	ArrayList<Integer> one ;
	static	ArrayList<Integer> two ;
	static	ArrayList<Integer> three ;
	static	ArrayList<Integer> four ;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		long[] v =  new long[n];

		for(int i = 0;i < n;i++){
			v[i] = sc.nextLong();
		}
		Arrays.sort(v);
		int j = 0;
		for(int i = 0;i < n;i++){
			if(v[n-1-i] == v[n-1]){
				j++;
			}
		}
		

		long[][] pdp = new long[51][51];
		pdp[0][0] = 1;
		for (int x = 1; x <= 50; x++) {				//組み合わせの数の計算
			for (int k = 0; k <= x; k++) {
				if (k - 1 >= 0) {
					pdp[x][k] = pdp[x-1][k-1] + pdp[x-1][k];
				} else {
					pdp[x][k] = pdp[x-1][k];
				}
			}
		}

		if(j <= a){
			long sum = 0;
			for(int i = 0;i < a;i++){
				sum += v[n-1-i];
			}

			double ans = (double)sum/a;

			int c = 0;

			for(int i = 0;i < n;i++){				//基準数の個数
				if(v[i] == v[n-a]){
					c++;
				}
			}
			int h = 0;
			for(int i = 0;i < n;i++){
				if(v[i] > v[n-a]){
					h++;
				}
			}
			
			
			long ansnum = pdp[c][c-(a-h)];
			


			System.out.println(ans);
			System.out.println(ansnum);
			
		}else{		
			long sum = 0;
			for(int i = 0;i < a;i++){
				sum += v[n-1-i];
			}
			double ans = (double)sum/a;
			
			
			int c = 0;
			for(int i = 0;i < n;i++){				//最大値と同じ値を持つ個数を調べる
				if(v[i] == v[n-1]){
					c++;
				}
			}


			long ansc = 0;
			
			
			for(int i = a;i <= Math.min(c, b);i++){
				ansc += pdp[c][i];
			//System.out.println(pdp[c][i]);

			}
			
			System.out.println(ans);
			System.out.println(ansc);
			
			
			
		}




	}
	
	static long sum(long ue,long sita){
		long counter = sita;
		long u = 1;
		for(long i = 0;i < counter;i++){
			u *= ue;
			ue--;
		}
		long s = 1;
		for(long i = 0;i < counter;i++){
			s *= sita;
			sita--;
		}
		
		return u/s;
		
	}
}

class Pair implements Comparable{
	Character from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}




Measured memory_bytes: 25172
#include <cstdio>
#include <numeric>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int n;
	scanf("%d",&n);
	vector<long long> dat(n);
	long long ac1 = (long long)n*(long long)(n+1ll)/2;
	for (int i = 0; i < n; i++) {
		scanf("%lld",&dat[i]);
	}
	long long sum = accumulate(dat.begin(), dat.end(), 0ll);
	if (sum % ac1) {
		puts("NO");
		return 0;
	}
	long long ops = sum / ac1;
	vector<long long> d1(n), d2(n);
	for (int i = 0; i < n; i++) {
		d1[i] = dat[(i+1)%n] - dat[i];
		d1[i] -= ops;
	}
	for (int i = 0; i < n; i++) {
		if (d1[i] % n) {
			puts("NO");
			return 0;
		}
		long long curcnt = -d1[i] / n;
		if (curcnt < 0) {
			puts("NO");
			return 0;
		}
		ops -= curcnt;
		if (ops < 0){
			puts("NO");
			return 0;
		}
	}
		if (ops != 0){
			puts("NO");
			return 0;
		}
	puts("YES");
	return 0;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  int l = 0, r = n-1;
  while(1){
    while(l != n && s.at(l) != 'W') l++;
    while(r != -1 && s.at(r) != 'R') r--;
    if(r < l) break;
    swap(s.at(l), s.at(r));
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3760
import java.util.*; 

class Main{
  public static void main(String args[]){
    Scanner scn = new Scanner(System.in);
    int count =0;
    String one =scn.next();
    String two =scn.next();
    for(int i=0;i<one.length();i++){
      if(one.charAt(i)!=two.charAt(i)){
        count++;
        continue;
      }
    }   
    System.out.println(count);
  }
}

Measured memory_bytes: 40952
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e18;

int main()
{
    ll n;
    cin>> n;
    vector<ll> p(1000001,0),q;
    
    for(ll i=2;i<=1000000;i++){
        if(p[i]==0){
            q.push_back(i);
            for(ll j=i;j<=1000000;j+=i){
                p[j]=1;
            }
        }
        
    }
    vector<pll> ans;
    ll sum=0;
    for(auto x:q){
        if(n%x==0){
            ll cnt=0;
            while(n%x==0){
                cnt++;
                n/=x;
            }
            ans.push_back(make_pair(x,cnt));
        }
    }
    if(n!=1){
        ans.push_back(make_pair(n,1));
    }
    for(auto x:ans){
        ll i=1;
        while(x.se-i>=0){
            sum++;
            x.se-=i;
            i++;
        }
    }
    cout << sum << endl;
    return 0;
} 

Measured memory_bytes: 12132
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val N = in.nextInt
  val ABs = Array.fill(N)((in.nextInt, in.nextInt))
  val As = ABs.map(_._1).sorted
  val Bs = ABs.map(_._2).sorted

  def diff(i: Int): Int = Bs(i) - As(i)
  println(diff(N / 2) + 1 + (if (N % 2 == 1) 0 else diff(N / 2 - 1)))
}

Measured memory_bytes: 67572
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch Test | diff Test.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Test.cpp && ./a.out

/*
 
 5/2/2020
 
 21:07-
 
 */

const int MAX_N=200+1;
int r[10];
int N,M,R;
LL mx[MAX_N][MAX_N];

const LL Inf=1e18;
void solve() {
  REP(k,N)REP(i,N)REP(j,N) SMIN(mx[i][j],mx[i][k]+mx[k][j]);
  sort(r,r+R);
  LL res=Inf;
  do {
    LL ans=0;
    REP(i,R-1) ans+=mx[r[i]][r[i+1]];
    SMIN(res,ans);
  } while(next_permutation(r,r+R));
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N>>M>>R;
  REP(i,R) cin>>r[i],r[i]--;
  REP(i,N)REP(j,N) mx[i][j]=i==j?0:Inf;
  REP(i,M) {
    int u,v; LL w; cin>>u>>v>>w;
    --u,--v;
    mx[u][v]=mx[v][u]=w;
  }
  solve();
  
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) > (b) ? (b) : (a))
#define abs(x) ((x) > 0 ? (x) : -(x))
#define MOD (ll)1000000007 //10^9 + 7
#define endl printf("\n")
typedef long long ll;
#define MAX_N (1 << 17)

bool judge(int *a, int s, int g, int x, bool dp[5010][9010]) {
  dp[s][0] = true;
  for (int i = s; i < g; i++) {
    for (int j = 0; j <= x; j++) {
      dp[i + 1][j] = dp[i][j];
      if (j - a[i] >= 0) dp[i + 1][j] |= dp[i][j - a[i]];
    }
  }
  return dp[g][x];
}

bool dp1[5010][9010], dp2[5010][9010];

int
main(int argc, char *argv[])
{
  int a[9010], x, y;
  char s[9010];

  scanf("%s", s);
  scanf("%d %d", &x, &y);

  int k = 0, l = 0;
  int n = strlen(s);
  int d[8010];
  for (int i = 0; i < n; i++) {
    if (s[i] == 'T') d[l++] = i;
  }
  int f = -1;
  for (int i = 0; i < l; i++) {
    a[i] = d[i] - f - 1;
    f = d[i];
  }
  a[l] = n - f - 1;
  l++;
  
  int b[9000], c[9000], e = 0, o = 0;
  int sum1 = 0, sum2 = 0;
  for (int i = 0; i < l; i++) {
    if (i % 2 == 0) sum1 += (b[e++] = a[i]);
    else sum2 += (c[o++] = a[i]);
  }

  int p = sum1 - x, q = sum2 - y;
  if (p % 2 == 0 && q % 2 == 0 && p >= 0 && q >= 0) {
    if (judge(b, 1, e, p / 2, dp1) && judge(c, 0, o, q / 2, dp2)) {
      printf("Yes\n");
      return 0;
    }
  }

  printf("No\n");

  

  return 0;
}


Measured memory_bytes: 70784
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
main () {
	double a, b, c;
	cin >> a >> b >> c;
	double t = M_PI*c/180;
	printf("%.6f\n", a*b*sin(t)/2);
	printf("%.6f\n", a+b+sqrt(a*a+b*b-2*a*b*cos(t)));
	printf("%.6f\n", b*sin(t));
}

Measured memory_bytes: 3584
#include <iostream>
using namespace std;
int main( void )
{
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int X = 0;
  int n = N;
  while( n > 0 ){
    X += n % 10;
    n /= 10;
  }
  if( N % X == 0 ){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
while(n=gets.to_i)!=0
a=(1..n).map{gets.to_i}
#p (0...n).map{|i|(i...n).map{|j|a[i..j].inject :+}.max}.max
p (0...n).inject(a[0]){|m,i|(i...n).inject(0){|s,j|s+=a[j];(m<s)?(m=s):s};m}
end

Measured memory_bytes: 6112
n,m = map(int,input().split())
lists = [list(map(int,input().split())) for i in range(m)]
for i in range((10**3) + 1):
    num = str(i)
    flag = True
    if len(num) == n:
        for s,c in lists:
            if num[s-1] != str(c):
                flag = False
        if flag:
            print(num)
            exit()
print(-1)

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

int main() {
  int N, A;
  
  cin >> N >> A;

  int x ;
  x = N % 500;
  
  if(x <= A){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
    
  // ここにプログラムを追記
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define st(p) ll p=0
#define in(s) ll s; cin>>s
#define pr(r) cout<<r<<endl
#define pr2(m,n) cout<<m<<" "<<n<<endl
#define wh(t) ll t; cin>>t; while(t--)
#define arr(a,n) ll a[n]; fr(i,n) cin>>a[i]
#define fr(i,a) for(ll i=0LL;i<a;i++)
#define fab(i,a,b) for(ll i=a;i<=b;i++)
#define fba(i,a,b) for(ll i=b;i>=a;i--)
#define rf(i,a) for(ll i=a;i>=0LL;i--)
#define sup ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define MX 10000000007
#define MAX 10000007
#define endl "\n"
#define ll long long int
#define v1 vector<ll>v 
#define v2 vector<int>v
#define vp1 vector<pair<ll,ll>> vp
#define vp2 vector<pair<int,int>>vp
#define pb push_back
#define fs first
#define sd second
ll k[105][100005];

int main() 
{
    sup;
    in(n); in(w);
    vector<ll> v(n+2);
    vector<ll> wt(n+2);
    fr(i,n)
    {
        cin>>wt[i]>>v[i];
    }
    fr(i,n+1)
    {
        fr(j,100001)
        {
            if(j==0)
            k[i][j]=0;
            else if(i==0)
            k[i][j]=10000000000000005;
            else if(v[i-1]<=j)
            k[i][j]=min(wt[i-1]+k[i-1][j-v[i-1]],k[i-1][j]);
            else
            k[i][j]=k[i-1][j];
            
        }
    }
    ll ans=0;
    rf(i,100000)
    {
        if(k[n][i]<=w)
        {
            ans=i;
            break;
        }
    }
    pr(ans);
    return 0;
}



Measured memory_bytes: 80128
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


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;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

vector<pair<char,ll>> runlength(string s,vector<pair<char,ll>> p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
    return p;
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
  return p;
}


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

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}


vector<vector<ll>> G;

void dfs(ll v,vector<bool> &reached,ll &ans){
  bool isEnd=true;
  rep(i,reached.size()) if(!(reached[i]) && i!=v) isEnd=false;
  if(isEnd){
    ans++;
    return;
  }
  reached[v]=true;
  for(auto nv:G[v]){
    if(reached[nv]) continue;
    dfs(nv,reached,ans);
  }
  reached[v]=false;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n,m,ans=0;
  cin>>n>>m;
  vector<bool> reached(n,false);
  G.assign(n,vector<ll>());
  rep(i,m){
    ll a,b;cin>>a>>b;
    G[a-1].push_back(b-1);
    G[b-1].push_back(a-1);
  }
  dfs(0,reached,ans);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
# -*- coding:utf-8 -*-
"""解答
1 + 2 + 3 + ... + t >= X
のとき、Xを満たす和を作れるので、このときのtが答え。

なぜなら、左辺の和がXを超えた場合、
・1を引く（t=1のときジャンプしない）
・2を引く（t=2のときジャンプしない）
・3を引く（t=3のときジャンプしない）
...
という風にできるから。

左辺は、和の公式で (1+t)*t/2 で求まる。
よって、
(1+t)*t/2 >= X
t^2 + t - 2X >= 0

2次方程式の解の公式より、
t = -1±√(1+4*2X)/2

計算量はO(1)
"""
import math

def solve():
    X = int(input())

    t = (-1 + math.sqrt(1+4*2*X))/2  # tは必ず正なので±は+の場合のみでOK
    t = math.ceil(t)

    print(t)
        

if __name__ == "__main__":
    solve()


Measured memory_bytes: 3060
import java.util.*;

public class Main {

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

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

        Arrays.sort(aArr, Collections.reverseOrder());

        int scoreA = 0;
        int scoreB = 0;
        for (int i = 0; i < n; i++) {
            if (i % 2 == 0) {
                scoreA += aArr[i];
            } else {
                scoreB += aArr[i];
            }
        }

        System.out.println(scoreA - scoreB);
    }
}


Measured memory_bytes: 21716
import java.util.Arrays;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] a = new int[m];
        int b[] = new int[m];
        int map[][] = new int[n][n];
        for (int i = 0; i < m; i++) {
            a[i] = sc.nextInt() - 1;
            b[i] = sc.nextInt() - 1;
            map[a[i]][b[i]] = 1;
            map[b[i]][a[i]] = 1;
        }
        boolean visited[] = new boolean[n];
        int ans = 0;
        for (int i = 0; i < m; i++) {
            map[a[i]][b[i]] = 0;
            map[b[i]][a[i]] = 0;
            Arrays.fill(visited, false);
            DFS(0, map, visited);
            int visitCount = 0;
            for (int j = 0; j < visited.length; j++) {
                if (visited[j]) {
                    visitCount++;
                }
            }
            if (visitCount == visited.length) {

            } else {
                ans++;
            }
            map[a[i]][b[i]] = 1;
            map[b[i]][a[i]] = 1;
        }
        System.out.println(ans);
        sc.close();
    }

    public static void DFS(int s, int[][] map, boolean[] visited) {
        for (int i = 0; i < map.length; i++) {
            if (!visited[i] && map[s][i] == 1) {
                visited[i] = true;
                DFS(i, map, visited);
            }
        }
    }
}


Measured memory_bytes: 23892
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<random>
#include<functional>
#include<utility>

typedef long long ll;

#define rep(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define P pair<int, int>
#define PLI pair<ll, int>
#define PLL pair<ll, ll>
#define VI vector<int>
#define VII vector<VI>

using namespace std;


const int MOD = 10007;
int N;
string S;
int dp[1005][1 << 3] = {};
int main(){
	cin >> N >> S;
	dp[0][1] = 1;
	for (int i = 0; i < N; i++) {
		int b;
		if (S[i] == 'J') b = 1;
		if (S[i] == 'O') b = 1<<1;
		if (S[i] == 'I') b = 1<<2;
		for (int bit1 = 0; bit1 < 1 << 3; bit1++) {
			if(!(bit1 & b)) continue;
			for (int bit2 = 0; bit2 < 1 << 3; bit2++) {
				if (!(bit1 & bit2)) continue;
				dp[i + 1][bit1] += dp[i][bit2];
				dp[i + 1][bit1] %= MOD;
			}
		}
	}
	int ans = 0;
	rep(bit, 1 << 3) ans += dp[N][bit], ans%=MOD;
	cout << ans << endl;


	return 0;
}


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

using namespace std;

int main()
{
    //freopen("in.txt", "r", stdin);
    string str;
    cin >> str;
    int n = (int) str.length();
    int cnt = 0;
    for(int i=0; i<n/2; i++){
        if(str[i] != str[n-1-i]) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef pair<int, pii> pip;
 
 
 
const int INF = 1000000;
const double EPS = 1e-8;
const int mod = 1e9 + 7;

int main(){
	int n;
	string s;
	vi v;
	while(cin>>n && n){
		cin>>s;
		v = vi(n, 0);
		int b = 0;
		for(int i = 0; i < s.size(); i++){
			if(s[i] == 'M') v[i%n]++;
			else if(s[i] == 'S') {
				b += v[i%n] + 1; v[i%n] = 0;
			}
			else {
				v[i%n] += b + 1; b = 0;
			}
		}
		sort(all(v));
		rep(i, n) printf("%d ", v[i]);
		printf("%d\n", b);
	}
}

Measured memory_bytes: 1220
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;

int main(){
    string tmp[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    string s;
    cin >> s;
    int ans = 0;
    for(int i = 0; i < 7; ++i){
        if(s == tmp[i]) {ans = i; break;}
    }
    cout << 7 - ans << endl;
    return 0;
}


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

#define ll long long int
#define vll vector<ll>
#define vllv vector<vector<ll>> 
#define vpii vector<pair<ll,ll>>
#define sz size()
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

ll ceil1(ll n,ll m){if(n%m==0){return n/m;}return n/m +1;}
vll factor(ll n){
    vll ans;
    if(n>0)ans.pb(1);if(n==2)ans.pb(2);
    for(ll i=2;i*i<=n;i++){if(n%i==0){ans.pb(i);if(n/i!=i)ans.pb(n/i);}}if(n>2)ans.pb(n);
    return ans;
}
ll fact(ll n){
	
    ll res = 1; 
    for (ll i = 2; i <= n; i++) 
        res = res * i; 
    return res; 
} 
  
int nCr(ll n, ll r) 
{ 
    return fact(n) / (fact(r) * fact(n - r)); 
} 
  
void dfs(vllv &v,ll k,vll &par,vll &dis,ll p)
{
 
    par[k]=p;
    dis[k]=dis[p]+1;
    for(ll i=0;i<v[k].sz;i++){
        if(v[k][i]!=p){
            dfs(v,v[k][i],par,dis,k);
        }
    }
}
bool sortbysec(const pair<string,int> &a,const pair<string,int> &b){return (a.second<b.second);} 


ll ston(string s) 
{ 
    stringstream geek(s); 
    ll x = 0; 
    geek >> x; 
    
  
    return x; 
}
ll pow2(ll n,ll k){ll ans=1;
    while(k>0){
        if(k%2==1)ans=ans*n;n=n*n;k/=2;
    }return ans;}
bool prime(int n){
    int i,j;
    for(i=2;i<=sqrt(n);i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}
bool bserch(vector<string> a, string s){
	ll l=0,r=a.sz-1,mid;
	while(l<=r){
		mid=(l+r)/2;
		if(a[mid]==s)return true;
		if(a[mid]<s){
			l=mid+1;
		}else{
			r=mid-1;
		}
	}
	return false;
}

bool sortcol(const vector<int>& v1, 
               const vector<int>& v2){ 
 return v1[0] < v2[0]; } 

 ll degit(ll n)
 {
 	ll t=0;
 	while(n>0)
 	{
 		t++;
 		n/=10; 	}
 		return t;
 }

void solve()
{
	ll n;
	cin>>n;
	vll a(n),fr(10000000,0),done(10000000,0);
	for(ll i=0;i<n;i++)
		cin>>a[i],fr[a[i]]++;
	for(ll i=0;i<10000000;i++)
	{
		
		if(fr[i]>0 && done[i]==0)
		{
			for(ll j=i*2;j<=10000000;j+=i)
				done[j]=1;
			if(fr[i]>=2)
				done[i]=1;
		}
	}
	ll ans=0;
	for(ll i=0;i<n;i++)
	{
		if(done[a[i]]==0)
		{
			ans++;
		}
	}
	cout<<ans;
	return;
}

int main()
{
	fast;
    ll q;
    q=1;
    // cin>>q;
    while(q--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 161020
#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()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	int n = s.size();
	bool elf = true;
	for (int i = 0; i < n; i += 2) {
		if (s.substr(i, 2) != "hi") elf = false;
	}
	puts(elf ? "Yes" : "No");
	return 0;
}

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

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

  string vowels = "aiueo";
  for (int i = 0; i < vowels.size(); i++){
    if (c == vowels.at(i)) {
     cout << "vowel" << endl;
     return 0;
    }
  }
  cout << "consonant" << endl;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;

public class Main {
    private static final StringBuilder builder = new StringBuilder();
    public static void main(String[] args) throws IOException {
        int n = readInt();
        boolean[] arr = new boolean[n];
        for (int i = 0; i < n; i++) {
            int buf = System.in.read();
            arr[i] = buf != 'R';
        }

        int count = 0;
        int i = 0, j = arr.length - 1;
        while (!arr[i]) {
            i++;
            if (i >= arr.length) break;
        }
        while (arr[j]) {
            j--;
            if (j < 0) break;
        }

        while (i < j) {
            i++; j--;
            while (!arr[i]) {
                i++;
                if (i >= arr.length) break;
            }
            while (arr[j]) {
                j--;
                if (j < 0) break;
            }

            count++;
        }

        System.out.print(count);
    }

    private static void read() {
        builder.setLength(0);
        while (true) {
            try {
                int b = System.in.read();
                if (b == ' ' || b == '\n' || b == -1) {
                    break;
                } else {
                    builder.appendCodePoint(b);
                }
            } catch (IOException e) {
                break;
            }
        }
    }

    private static int readInt() {
        read();
        return Integer.parseInt(builder.toString());
    }

    private static int readInt(int radix) {
        read();
        return Integer.parseInt(builder.toString(), radix);
    }

    private static long readLong() {
        read();
        return Long.parseLong(builder.toString());
    }

    private static long readLong(int radix) {
        read();
        return Long.parseLong(builder.toString(), radix);
    }

    private static BigInteger readBigInteger() {
        read();
        return new BigInteger(builder.toString());
    }

    private static BigInteger readBigInteger(int radix) {
        read();
        return new BigInteger(builder.toString(), radix);
    }

    private static double readDouble() {
        read();
        return Double.parseDouble(builder.toString());
    }

    private static BigDecimal readBigDecimal() {
        read();
        return new BigDecimal(builder.toString());
    }

    private static float readFloat() {
        read();
        return Float.parseFloat(builder.toString());
    }

    private static void skipLine() {
        while (true) {
            try {
                int b = System.in.read();
                if (b == '\n' || b == -1) {
                    break;
                }
            } catch (IOException e) {
                break;
            }
        }
    }

    private static void skip() {
        while (true) {
            try {
                int b = System.in.read();
                if (b == ' ' || b == '\n' || b == -1) break;
            } catch (IOException e) {
                break;
            }
        }
    }

}


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


using namespace std;

#define fastio() ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define ll long long
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()


void go(){
	int a,b,c;cin>>a>>b>>c;
	int k;cin>>k;
	int s=a+b+c;
	int s1=s,s2=s,s3=s;
	int ans=0;
	vector<int> vals{a,b,c};
	while(k) {
		s1-=vals[0], s1+=vals[0]*2;
		s2-=vals[1], s2+=vals[1]*2;
		s3-=vals[2], s3+=vals[2]*2;
		ans=max({s1,s2,s3});
		vals[0]*=2;
		vals[1]*=2;
		vals[2]*=2;
		k--;
	}
	cout << ans;
}
int main(){
   
   fastio();
   cin.tie(0);
   cout.tie(0);

   go();

   return 0;
}




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

using namespace std;
using ll = long long;
const int F = 26;
const int def = 1e6;


int n;
vector<int> c(F);
vector<vector<int>> a;


void init() {
    cin >> n;
    a.resize(n, vector<int>(F));
    for(int i = 0; i < F; i++)cin >> c[i];
    for(int i = 0; i < n; i++)for(int j = 0; j < F; j++)cin >> a[i][j];
}


vector<int> calc(int rng) {
    vector<int> last(F, -1);
    vector<int> ans;
    for(int i = 0; i < n; i++){ 
        vector<int> cur = a[i];
        for(int j = 0; j < F; j++)cur[j] += (i - last[j]) * (c[j] + rng);
        int ind =  max_element(cur.begin(), cur.end()) - cur.begin();
        last[ind] = i;
        ans.emplace_back(ind);
    }
    return ans;
}

int chack(vector<int> p) {
    int sum = 0;
    vector<int> last(F, -1);
    for(int i = 0; i < n; i++) {
        sum += a[i][p[i]];
        last[p[i]] = i;
        for(int j = 0; j < F; j++)sum -= (i - last[j]) * c[j];
    }
    return sum;
}


int main()
{
    srand((unsigned)time(NULL));   
    init();


    vector<int> ans;
    int M = 4 * 1e4, nax = -1e9;
    for(int I = 1; I <= M; I++) {
        int sed = rand() % (rand() % ((I/50) + 1) + 1) * ((rand() % 2)? 1 : -1);
        vector<int> cur = calc(sed);
        int k = chack(cur);
        if(k > nax) {
            nax = k;
            ans = cur;
        }
    }

    for(auto i : ans)cout << i + 1 << endl;
}

/*
satisfaction: 424801
score: 1424801
*/


Measured memory_bytes: 3648
import java.util.*;

public class Main {
	int n, cnt;
	int[][] c;
	
	void up(int m){
		int tmp = c[m][0];
		c[m][0] = c[m][1];
		c[m][1] = c[m][5];
		c[m][5] = c[m][4];
		c[m][4] = tmp;
	}
	
	void right(int m){
		int tmp = c[m][1];
		c[m][1] = c[m][3];
		c[m][3] = c[m][4];
		c[m][4] = c[m][2];
		c[m][2] = tmp;
	}
	
	boolean check(int m){
		for(int i=m-1;i>=0;i--){
			int cc = 0;
			for(int j=0;j<6;j++) if(c[i][j]==c[m][j]) cc++;
			if(cc==6) return true;
		}
		return false;
	}
	
	boolean func(int m){
		for(int i=0;i<4;i++){
			for(int j=0;j<4;j++){
				if(check(m)) return true;
				right(m);
			}
			up(m);
		}
		right(m);
		up(m);
		for(int i=0;i<4;i++){
			if(check(m)) return true;
			right(m);
		}
		up(m);
		up(m);
		for(int i=0;i<4;i++){
			if(check(m)) return true;
			right(m);
		}
		cnt++;
		return false;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		
		while(true){
			n = sc.nextInt();
			if(n==0) break;
			
			c = new int[n][6];
			cnt = 1;
			for(int i=0;i<n;i++){
				for(int j=0;j<6;j++){
					char a = sc.next().charAt(0);
					if(a=='R') c[i][j] = 0;
					else if(a=='Y') c[i][j] = 1;
					else if(a=='B') c[i][j] = 2;
					else if(a=='M') c[i][j] = 3;
					else if(a=='G') c[i][j] = 4;
					else if(a=='C') c[i][j] = 5;
				}
				if(i!=0) func(i);
			}
			System.out.println(n-cnt);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 28860
#include<bits/stdc++.h>
using namespace std;
int n,x,y,z,aa,bb,cc,ans=1e9,a[9];
int si[4];
void dfs(int pos)
{
    if(pos==n+1)
    {
        if(si[1]==0||si[2]==0||si[3]==0) return;
        int res=abs(aa-x)+abs(bb-y)+abs(cc-z)+(si[1]-1)*10+(si[2]-1)*10+(si[3]-1)*10;
        ans=min(ans,res);
        return ;
    }
    for(int i=0;i<4;i++)
    {
        if(i==1) aa+=a[pos],si[1]++;
        else if(i==2) bb+=a[pos],si[2]++;
        else if(i==3) cc+=a[pos],si[3]++;
        dfs(pos+1);
        if(i==1) aa-=a[pos],si[1]--;
        else if(i==2) bb-=a[pos],si[2]--;
        else if(i==3) cc-=a[pos],si[3]--;
    }
}
int main()
{
    scanf("%d%d%d%d",&n,&x,&y,&z);
    aa=bb=cc=0;
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    dfs(1);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back
//#define mp make_pair




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

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

ll a, b, c, k;

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

if(k%2==0)

cout <<  a-b << endl;

else cout << b-a << endl;

return 0;}


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

int main(void)
{
	int n, m;
	while (cin >> n >> m, n && m){
		vector <int> taro(n, 0), hanako(m, 0);
		int tarosum = 0, hanakosum = 0;
		for (int i = 0; i < n; i++){
			cin >> taro[i];
			tarosum += taro[i];
		}
		for (int i = 0; i < m; i++){
			cin >> hanako[i];
			hanakosum += hanako[i];
		}
		for (int i = 0; i < n; i++){
			for (int j = 0; j < m; j++){
				int tmp1 = tarosum - taro[i] + hanako[j];
				int tmp2 = hanakosum - hanako[j] + taro[i];
				if (tmp1 == tmp2){
					cout << taro[i] << " " << hanako[j] << endl;
					goto RE;
				}
			}
		}
		cout << "-1" << endl;
		RE :;
	}
	
	return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <string>
#include <stdio.h>

using namespace std;

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

    int length=str.length();
    int bit;
    long long int sum=0;
    for(bit=0; bit<(1<<(length-1)); bit++) {
        // cout << bit << endl;
        int i, start=0;
        for(i=0; i<length-1; i++) {
            if(bit & (1<<i)) {
                // cout << i << ' ';
                // cout << atoi(str.substr(start, i-start+1).c_str()) << ' ';
                sum += atoll(str.substr(start, i-start+1).c_str());
                start = i+1;
            }
        }
        // cout << atoi(str.substr(start).c_str());
        sum += atoll(str.substr(start).c_str());
        // if(str.substr(start)=="9999999999") {
        //     cout << "aaaa" << endl;
        //
        // cout << endl;
    }

    cout << sum << endl;

    return 0;
    
}

Measured memory_bytes: 256
func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}
 
let fc=readLine()!
let re=readLine()!
var result=0

for num in 0...2{
  let a=fc.index(fc.startIndex,offsetBy:num)
  let b=re.index(re.startIndex,offsetBy:num)
 
  if fc[a]==re[b] {
    result+=1
  }
}
print(result)

Measured memory_bytes: 7908
//Magic 2

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll,ll>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int a,b,c,k;cin>>a>>b>>c>>k;
    //aka<midori<ao
    int ans = 0;
    while(b<=a){
        b*=2;
        ans++;
    }
    while(c<=b){
        c*=2;
        ans++;
    }
    if(k<ans)cout<<"No"<<nnn;
    else cout<<"Yes"<<nnn;
    return 0;
}

Measured memory_bytes: 3632