akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

using lnt = long long;
using Real = long double;

#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(lnt i=0;i<(n);++i)
#define RANGE(i, a, b) for(lnt i=(a);i<(b);++i)
#define RREP(i, n) for(lnt i=(n)-1;i>= 0;--i)

#define ln '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define dcout cout<<fixed<<setprecision(20)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)

constexpr int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
constexpr Real eps = 1e-9; const Real pi = acosl(-1);
constexpr lnt BIG = INT_MAX/10, BBIG = LLONG_MAX/10;

template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<class T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<class T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
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;}

using pint = pair<int, int>; using plnt = pair<lnt, lnt>;
using vint = vector<int>; using vlnt = vector<lnt>;
constexpr lnt MOD = 1e9+7;

int main(){
	summon_tourist;

	lnt N; cin >> N;
	lnt origN = N;
	string S = "";
	while(N > 0){
		N--;
		lnt md = N % 26;
		S += char('a'+md);
		N /= 26;
	}
	reverse(ALL(S));
	cout << S << ln;
}

Measured memory_bytes: 3652
#include<stdio.h>
#include<algorithm>
#include<string>
#include<vector>
#include<string.h>

using namespace std;

vector<string> s;
string cs;
int curr[10], n;

void dfs(int pos, int depth){
	if(pos==n){
		s.push_back(cs);
		return;
	}
	if(curr[pos]!=-1){
		cs+='a'+curr[pos];
		dfs(pos+1, depth);
		for(int i=pos+1;i<n;++i){
			if(curr[i]==-1){
				curr[i]=curr[pos];
				dfs(pos+1, depth);
				curr[i]=-1;
			}
		}
		cs.pop_back();
	}
	else{
		cs+='a'+depth;
		curr[pos]=depth;
		dfs(pos+1, depth+1);
		for(int i=pos+1;i<n;++i){
			if(curr[i]==-1){
				curr[i]=depth;
				dfs(pos+1, depth+1);
				curr[i]=-1;
			}
		}
		curr[pos]=-1;
		cs.pop_back();
	}
}

int main(){
	memset(curr, -1, sizeof(curr));
	scanf("%d", &n);
	curr[0]=0;
	dfs(0, 1);
	sort(s.begin(), s.end());
	for(auto& i:s) puts(i.c_str());
	return 0;
}


Measured memory_bytes: 9588
n=int(input())
s=[input() for i in range(n)]
from collections import Counter
c=Counter(s)
c=list(c.most_common())

m=0
ans=[]
for k,v in c:
  if v>=m:
    ans.append(k)
    m=v
ans.sort()
print(*ans,sep='\n')


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


using namespace std;


using ll = long long;

template<long long M>
class modint {
    public:
        long long a;
        modint(const long long x = 0LL) : a((x % M + M) % M) {}
        long long &value() { return a; }
        modint operator+(const modint rhs) const {
            return modint(*this) += rhs;
        }
        modint operator-(const modint rhs) const {
            return modint(*this) -= rhs;
        }
        modint operator*(const modint rhs) const {
            return modint(*this) *= rhs;
        }
        modint operator/(const modint rhs) const {
            return modint(*this) /= rhs;
        }
        modint &operator+=(const modint rhs) {
            a += rhs.a;
            if (a >= M) {
                a -= M;
            }
            return *this;
        }
        modint &operator-=(const modint rhs) {
            if (a < rhs.a) {
                a += M;
            }
            a -= rhs.a;
            return *this;
        }
        modint &operator*=(const modint rhs) {
            a = a * rhs.a % M;
            return *this;
        }
        modint pow(long long n) const {
            modint ret(1);
            modint x = *this;
            while (n) {
                if ((n & 1) == 1) {
                    ret *= x;
                }
                n >>= 1;
                x *= x;
            }
            return ret;
        }
        modint inv() const {
            return pow(M - 2);
        }
        modint &operator/=(const modint rhs) {
            return *this *= rhs.inv();
        }
};

const long long M = 1000000007;

using mint = modint<M>;


int main(void) {
    ll N;
    cin >> N;
    vector<ll> A(N);
    mint acc = 0;
    mint diag = 0;
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
        acc += A[i];
        diag += A[i] * A[i];
    }
    mint ans = (acc * acc - diag) / 2;
    cout << ans.a << endl;
}


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

using namespace std;

typedef long long LL;
const int MAXN=4096;
LL dp[MAXN][MAXN],a[MAXN];
int n;

int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		dp[i][i]=a[i];
	}
	for(int len=2;len<=n;len++){
		for(int l=1;l<n;l++){
			int r=l+len-1;
			if(r>n) break;
			dp[l][r]=max(a[l]-dp[l+1][r],a[r]-dp[l][r-1]);
		}
	}
	cout<<dp[1][n]<<endl;
	return 0;
}


Measured memory_bytes: 96256
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }


int main() {
	IOS;
	int n;
	cin >> n;
	vector<ll> a(n);
	REP(i, n) {
		cin >> a[i];
	}
	int ind = 0;
	ll maxv = 0;
	vector<P> ret;
	REP(i, n) {
		if (chmax(maxv, abs(a[i]))) {
			ind = i;
		}
	}
	if (a[ind] < 0) {
		REP(i, 2) {
			ret.push_back(P(ind, n - 1));
		}
		RREP(i, n - 1) {
			REP(j, 2) {
				ret.push_back(P(i + 1, i));
			}
		}
	} else {
		REP(i, 2) {
			ret.push_back(P(ind, 0));
		}
		REP(i, n - 1) {
			REP(j, 2) {
				ret.push_back(P(i, i+1));
			}
		}
	}
	put(ret.size());
	REP(i, ret.size()) {
		cout << ret[i].first+1 << " "<< ret[i].second+1 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
typedef long long ll;

int main() {
  long long N;
  long long res;
  cin >> N;

  vector<long long> A(N);
  ll sum = 0;
  ll mod = 1e9 + 7;
  REP(i, N) {
    cin >> A[i];
    sum += A[i] % mod;
    sum %= mod;
  }

  res = 0;
  REP(i, N - 1) {
    sum -= A[i];
    if (sum < 0) {
      sum += mod;
    }
    res += (sum * A[i]) % mod;
    res %= mod;
  }
  cout << res << endl;
}


Measured memory_bytes: 4788
#include<bits/stdc++.h>
#define INF 2147483647
#define inf 1000000007
#define int long long
#define SYOU(x) setprecision(x)
#define abs(x,y) (max(x,y)-min(x,y))
#define mp make_pair
#define fi first
#define se second
using namespace std;
int i[111100];
bool ii[11111];
int u;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=0,e=0,f=0,g=1,h=2,j;
  cin >>a;
  b=a/2;
  if(a%2==0) c=b;
  else c=b+1;
  cout <<c*b<<'\n';
  return (0);
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

long long n,i,s,j,k;

long long __gcd(long long a,long long b)
{
    int r=0;
    while (b != 0)
    {
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}

int main()
{
    cin >> n;
    for (i=1;i<=n;i++)
        for (j=1;j<=n;j++)
            for (k=1;k<=n;k++)
                s+=__gcd(__gcd(i,j),k);
    cout << s;
}

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

int main(){
    int N,K,Q; cin >> N >> K >> Q;

    map <int,int> m;
    for (int i=0; i<Q; i++){
        int a;
        cin >> a;
        m[a-1]++;
    }
    
    for (int i=0; i<N; i++){
        if (m[i]<Q-K+1) cout << "No" << endl;
        else cout << "Yes" << endl;
    }

}


Measured memory_bytes: 5376
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
int main()
{
    vector<string>ara;
    int h,w,value,i;
    string s;
    while(scanf("%d%d",&h,&w)==2)
    {
        getchar();
        value=h;
        while(value--)
        {
            getline(cin,s);
            ara.push_back(s);
            s.clear();
        }
        for(i=0;i<w+2;i++)printf("#");
        printf("\n");
        for(i=0;i<ara.size();i++)
        {
            cout<<"#"<<ara[i]<<"#"<<endl;
        }
        for(i=0;i<w+2;i++)printf("#");
        printf("\n");
        ara.clear();
    }
    return 0;
}



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

int main() {
  int a;
  cin >> a;
  if (105 > a) {
    cout << 0 << endl;
  }
  else if (135 > a) {
    cout << 1 << endl;
  }
  else if (165 > a) {
    cout << 2 << endl;
  }
  else if (189 > a) {
    cout << 3 << endl;
  }
  else if (195 > a) {
    cout << 4 << endl;
  }
  else {
    cout << 5 << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
//////////////////////////////////////////////////
// Range Query - RMQ and RUQ with Lazy Segment Tree
// https://www.slideshare.net/iwiwi/ss-3578491
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_F&lang=jp

struct LazySegmentTree{
    // for vertex n
    // par (n-1)/2
    // chi 2n+1,2n+2

    // index i
    // bottom vertex n+i-1
    const int NONNUM = -1; //ありえない数字
    int segn2; // imply actually vertex number
    vector<ll> data,lazy; 
     
    LazySegmentTree(int n){
        segn2=1;
        while(segn2<n) segn2*=2; //必要分2^Mを取る
         
        data.resize(segn2*2,INT_MAX);
        lazy.resize(segn2*2,NONNUM);
    }
    
    //lazy_propagate
    inline void eval(int k,int l,int r){
        if (lazy[k] != NONNUM){ // lazy nonzero
            data[k] = lazy[k]; // itself
            
            if (r-l > 1){
                lazy[2*k+1] = lazy[k];
                lazy[2*k+2] = lazy[k];
            }

            lazy[k] = NONNUM;
        }
    }

    ll query(int a,int b,int l=0,int r=-1,int k=0){
        if(r<0) r=segn2; // when calling function at first
        if (r <= a || b <= l) return INT_MAX; //disjoint

        eval(k,l,r);

        if (a <= l && r <= b) return data[k]; //include
        
        ll vl = query(a,b,l,(l+r)/2,k*2+1);
        ll vr = query(a,b,(l+r)/2,r,k*2+2);
        return min(vl,vr);
    }
     
    
    void update(int a,int b ,ll x, int l = 0, int r=-1,int k = 0){
        if(r==-1) r=segn2;

        eval(k,l,r);
        
        if (b <= l || r <= a) return;

        if (a <= l && r <= b){
            lazy[k] = x;
            eval(k,l,r);
            return;
        }else{
            //一部のみ含むとき，子ノードを計算してその結果をもらう
            update(a,b,x,l,(l+r)/2,2*k+1);
            update(a,b,x,(l+r)/2,r,2*k+2);
            data[k] = min(data[2*k+1] , data[2*k+2]);
        }
        
    }
};

// 0-indexed
// sum [s,t) --> s,t+1
// update [s,t,x) --> s,t+1,x

int main(){
    int N,q;
    SCD2(N,q);
    LazySegmentTree seg(N);

    REP(i,q){
        int d; SCD(d);
        if (d==0){
            int s,t,x;
            SCD3(s,t,x);
            seg.update(s,t+1,x);
        }else{
            int s,t; SCD2(s,t);
            PRINTLLD(seg.query(s,t+1));
        }
    }
}



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

int main() {
  int N, Q;
  string S;
  cin>>N>>Q>>S;
  
  vector<int> sum(N+1,0);
  for(int i=1;i<N;i++){
    if(S[i-1]=='A'&&S[i]=='C') sum[i+1]=sum[i]+1;
    else sum[i+1]=sum[i];
  }                   

  rep(i, Q){
    int l,r;
    cin>>l>>r;
    cout<<sum[r]-sum[l]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>

using namespace std;
string str;

int main() {
    while (cin >> str) {
        if (str[0] == str[str.size() - 1]) {
            if (str.size() % 2 == 0)
                cout << "First" << endl;
            else
                cout << "Second" << endl;
        } else {
            if (str.size() % 2 == 0)
                cout << "Second" << endl;
            else
                cout << "First" << endl;
        }
    }
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
typedef long long lint;
const int N=3e5+5;
int n,esum[N];
char str[N];

namespace utils{
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
	template <class T> inline void apn(T &x,const T y){x=x<y?x:y;}
	template <class T> inline void apx(T &x,const T y){x=x>y?x:y;}
	inline int nxi(){
		int x=0;
		char c;
		while(((c=getchar())>'9'||c<'0')&&c!='-');
		const bool f=(c=='-')&&(c=getchar());
		while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
		return f?-x:x;
	}
}
using namespace utils;

int main(){
	n=nxi();
	scanf("%s",str+1);
	for(int i=1; i<=n; ++i){
		esum[i]=esum[i-1]+(str[i]=='E');
	}
	int ans=1e9;
	for(int i=1; i<=n; ++i){
		apn(ans,(esum[n]-esum[i])+(i-1-esum[i-1]));
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 5280
def wf(N, cost):
    for k in range(N):
        for i in range(N):
            c_ik = cost[i][k]
            for j, (c_kj, c_ij) in enumerate(zip(cost[k], cost[i])):
                temp = c_ik + c_kj
                if temp < c_ij:
                    cost[i][j] = temp

import sys
import itertools
N, M, R = map(int, input().split())
r = list(map(int, input().split()))
cost = [[float("inf")] * N for _ in range(N)]
for _ in range(M):
    A, B, C = map(int, sys.stdin.readline().split())
    cost[A - 1][B - 1] = C
    cost[B - 1][A - 1] = C

wf(N, cost)

ans = float('inf')
for place in itertools.permutations(r):
    temp_cost = 0
    current_place = place[0]
    for next_place in place[1:]:
        temp_cost += cost[current_place - 1][next_place - 1]
        current_place = next_place

    if temp_cost < ans:
        ans = temp_cost

print(ans)



Measured memory_bytes: 4676
#include<stdio.h>
#include<stdlib.h>

#define SENTINEL 1000000000

int count=0;

int main(){
  int A[500000];
  int n,i;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  mergeSort(A,0,n);
  for(i=0;i<n;i++){
    printf("%d",A[i]);
    if(i<n-1)printf(" ");
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}
void merge(int A[],int left,int mid,int right){
  int n1,n2,i,j,k;
  int *L,*R;
  n1=mid-left;
  n2=right-mid;
  L=(int *)malloc(sizeof(int)*(n1+1));
  R=(int *)malloc(sizeof(int)*(n2+1));
  for(i=0;i<=n1-1;i++){
    L[i]=A[left+i];
  }
  for(j=0;j<=n2-1;j++){
    R[j]=A[mid+j];
  }
  L[n1]=SENTINEL;
  R[n2]=SENTINEL;
  i=0;
  j=0;
  for(k=left;k<=right-1;k++){
   if(L[i]<=R[j]){
      A[k]=L[i];
      i++;
      count++;
    }
    else{
      A[k]=R[j];
      j++;
      count++;
    }
  }
  free(L);
  free(R);
}

void mergeSort(int A[],int left,int right){
  int i,mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}





Measured memory_bytes: 5452
#include<stdio.h>

int main(){
	int H,W,m,n;
	for(;;){
		scanf("%d %d",&H,&W);
		if(H==W && H==0) break;
		
		if(H<=2){
			for(m=0;m<H;m++){
				for(n=0;n<W;n++) printf("#");
				printf("\n");
			}
		}
		else{
			for(m=1;m<=H;m++){
				if(m==1 || m==H){
					for(n=0;n<W;n++) printf("#");
					printf("\n");
				}
				if(m!=1 && m!=H){
					printf("#");
					for(n=0;n<W-2;n++) printf(".");
					printf("#");
					printf("\n");
				}
			}
			printf("\n");
		}
	}
return 0;
}

Measured memory_bytes: 572
#include <iostream>
using namespace std;
typedef long long ll;

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

    for(int j = 0; j < n; j++) {
        ll u = a + (n-1-j)*c - j*d;
        ll v = a - j*c + (n-1-j)*d;
        if(u <= b && b <= v) {
            cout << "YES" << endl;
            return 0;
        }
    }

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

Measured memory_bytes: 256
N = int(input())
a = []
for i in range(N):
    a.append(input())

M= int(input())
b=[]
for i in range(M):
    b.append(input())
    
c=[]
for s in set(a+b):
    c.append(a.count(s)-b.count(s))

print(max(0,max(c)))


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

using namespace std;

template <class T>inline T updmax(T &a, T b) { return a = max(a, b); }
template <class T>inline T updmin(T &a, T b) { return a = min(a, b); }

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int a, b, c;
	cin >> a >> b >> c;
	cout << max(0, c-(a-b)) << endl;

	return 0;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i, n) cin >> v[i];
    rep(i, n) v[i]--;

    vector<int> ans;

    for (int k = n - 1; k >= 0; k--) {
        int i = [&] {
            int ans = -1;
            rep(j, k+1) {
                if(v[j]== j) ans = j;
            }
            return ans;
        }();

        if (i == -1) {
            cout << -1 << endl;
            ret();
        }

        ans.push_back(i);

        vector<int> next;
        rep(j, v.size()) {
            if (j == i) continue;
            next.push_back(v[j]);
        }
        v = next;

    }
    reverse(ans.begin(), ans.end());
    for (int i : ans) cout << (i + 1) << endl;

}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll a, b, c;
    cin >> a >> b >> c;
    cout << min({a + b, b + c, a + c}) << endl;
    return 0;
}


Measured memory_bytes: 3612
#include <stdio.h>
#include <set>
using namespace std;
int main(){
    int n,temp;
    set<int> s;
    scanf("%d",&n);
    while(n--){
        scanf("%d",&temp);
        s.insert(temp);
    }
    scanf("%d",&n);
    while(n--){
        scanf("%d",&temp);
        s.insert(temp);
    }
    
    for(int i:s)printf("%d\n",i);   
}


Measured memory_bytes: 21516
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


ll A,B;
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A>>B;
	if(abs(B-A)%2==0) {
		cout<<(A+B)/2<<endl;
	}
	else {
		cout<<"IMPOSSIBLE"<<endl;
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
        int best=0;
        int sum=0;
        for (int i=0; i<N; i++) {
            int di = sc.nextInt();
            if(best<di){
                best=di;
            }
            sum=sum+di;
        }
        sum=sum-best/2;
        System.out.println(sum);
	}
}

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

#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

int main() {
    int n;cin>>n;
    int x0 = 0,y0 = 0,t0 = 0;
    
    rep(i,n) {
        int t,x,y;cin>>t>>x>>y;
        int d = (t-t0)-abs(x-x0)-abs(y-y0);
        if(d>=0 && abs(d)%2==0){
            x0 = x;
            y0 = y;
            t0 = t;
        }
        else {
            cout<<"No"<<endl;
            return 0;
        }
    }

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

Measured memory_bytes: 256
/*
 _____ ____ _____   ___   ___   ___   ___ 
|_   _/ __ \_   _| |__ \ / _ \ |__ \ / _ \
  | || |  | || |      ) | | | |   ) | | | |
  | || |  | || |     / /| | | |  / /| | | |
 _| || |__| || |_   / /_| |_| | / /_| |_| |
|_____\____/_____| |____|\___/ |____|\___/ 
*/
#include <bits/stdc++.h>
#include <fstream>
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define per(i, a, b) for (int i = (a); i > (b); i--)
#define a(x) (x.begin(), x.end())
#define ar(x) (x.rbegin(), x.rend())
#define pb push_back
#define Pb() pop_back()
#define ll long long int
#define ull unsigned long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sc scanf
#define scin(x) sc("%d", &(x))
#define scln(x) sc("%lld", &(x))
#define pf prllf
#define ms(a, b) memset(a, b, sizeof(a))
#define mp make_pair
#define db double
#define EPS 10E-10
#define ff first
#define ss second
#define sqr(x) (x) * (x)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define DBG pf("HI\n")
#define MOD 1000000007
#define CIN                       \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define RUN_CASE(t, T) for (__typeof(t) t = 1; t <= T; t++)
#define CASE(t) prllf("Case %d: ", t)
#define CASEL(t) prllf("Case %d:\n", t)
#define intlimit 2147483647
#define longlimit 9223372036854775807
#define infinity (1 << 28)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a) * (b) / gcd(a, b))
#define PI 2 * acos(0.0)
using namespace std;
int main()
{
    CIN;
    int a,b,c;
    cin >> a >> b >> c;
    if(a+b+c>21){
        cout << "bust";
    }else{
        cout << "win";
    }
}
// Abcd1234?

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = sorted([A[i] - i - 1 for i in range(len(A))])
# print('B', B)


def f(x):
    v = 0
    for i in range(len(B)):
        v += abs(B[i] - x)
    return v


if len(B) % 2 == 0:
    b1 = B[len(B) // 2 - 1]
    b2 = B[len(B) // 2]
    ans = min(f(b1), f(b2))
else:
    b = B[len(B) // 2]
    ans = f(b)
print(ans)


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

using namespace std;


int main() {
int64_t a;
  cin>>a;
  vector<int>party(a);
  for(int i=0;i<a;i++)
  {
  int d;
    cin>>d;
    party.at(i)=d;
  
  }
  
  int64_t p=10000000000;
  for(int i=1;i<101;i++)
  {
 int64_t f=0;
    for(int j=0;j<a;j++)
  {
  f=f+(party.at(j)-i)*(party.at(j)-i);
  }
  p=min(p,f);
  }
  cout<<p;
}



Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int N;
    vector<int> length;
    int sum;
    int l;
    cin>>N;
    for(int i =0;i<2*N;i++)
{
    cin>>l;
    length.push_back(l);
}
    sort(length.begin(),length.end());
    for(int i =0;i<2*N;)
{
     sum+=length[i];
    i+=2;       
}
cout<<sum;
return 0;
}

Measured memory_bytes: 256
#include<iostream> 
#include<cstring> 
#include<cstdlib> 
using namespace std; 
  
/* Returns length of LCS for X[0..m-1], Y[0..n-1] */
void lcs( char *X, char *Y, int m, int n ) 
{ 
   int L[m+1][n+1]; 
  
   /* Following steps build L[m+1][n+1] in bottom up fashion. Note 
      that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */
   for (int i=0; i<=m; i++) 
   { 
     for (int j=0; j<=n; j++) 
     { 
       if (i == 0 || j == 0) 
         L[i][j] = 0; 
       else if (X[i-1] == Y[j-1]) 
         L[i][j] = L[i-1][j-1] + 1; 
       else
         L[i][j] = max(L[i-1][j], L[i][j-1]); 
     } 
   } 
  
   // Following code is used to print LCS 
   int index = L[m][n]; 
  
   // Create a character array to store the lcs string 
   char lcs[index+1]; 
   memset(lcs,'\n',sizeof(lcs));
   // lcs[index] = ''; // Set the terminating character 
  
   // Start from the right-most-bottom-most corner and 
   // one by one store characters in lcs[] 
   int i = m, j = n; 
   while (i > 0 && j > 0) 
   { 
      // If current character in X[] and Y are same, then 
      // current character is part of LCS 
      if (X[i-1] == Y[j-1]) 
      { 
          lcs[--index] = X[--i]; // Put current character in result 
           j--;     // reduce values of i, j and index 
      } 
  
      // If not same, then find the larger of two and 
      // go in the direction of larger value 
      else if (L[i-1][j] > L[i][j-1]) 
         i--; 
      else
         j--; 
   } 
  
   // Print the lcs 
   for(int i =0;i<L[m][n];i++)
   cout << lcs[i];
   cout<<endl; 
} 
  
/* Driver program to test above function */
int main() 
{ 
  char X[3000+5];
  char Y[3000+5];
  cin>>X;
  cin>>Y;
  int m = strlen(X); 
  int n = strlen(Y); 
  lcs(X, Y, m, n); 
  return 0; 
} 

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

int main(void){
  int n[100],x[300];
  int l = 0;
  while(1){
    cin >> n[l] >> x[l];
    if((n[l] == 0)&&(x[l] == 0))
      break;
    l++;
  }
  int numberOfStreet[l];
  for(int m = 0; m < l; m++){
    numberOfStreet[m] = 0;
    for(int i = 1; i <= n[m]; i++){
      for(int j = 1; j <= n[m]; j++){
        for(int k = 1; k <= n[m]; k++){
          if(i + j + k == x[m]){
            if(!((i == j)||(j == k)||(k == i))){
              numberOfStreet[m]++;
            }
          }
        }
      }
    }
  }
  for(int m = 0; m < l; m++){
    cout << numberOfStreet[m] / 6 << endl;
  }

  return 0;
}


Measured memory_bytes: 3068
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    // x*(x-1)/2 >= N;
    int x = 1;
    while ((long)x*(x+1)/2 < N) {
      x++;
    }
    long diff = (long)x*(x+1)/2 - N;
    StringBuilder ans = new StringBuilder();
    for (int i = 1; i <= x; i++) {
      if (i == diff) continue;
      ans.append(i).append('\n');
    }
    System.out.println(ans.toString());
  }
}

Measured memory_bytes: 21844
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int W,n,c=1;
	while(scanf("%d%d",&W,&n),W){
		int w[n],v[n]; rep(i,n)scanf("%d,%d",v+i,w+i);
		int opt[n][W+1]; rep(i,n)rep(j,W+1)opt[i][j]=0;
		
		rep(i,n)rep(j,W+1){
			int a=i>0?opt[i-1][j]:0,b=i>0&&j>=w[i]?opt[i-1][j-w[i]]:0;
			if(j<w[i])opt[i][j]=a;
			else opt[i][j]=max(a,v[i]+b);
		}
		int mx=0,mi;
		rep(j,W+1)if(opt[n-1][j]>mx)mx=opt[n-1][j],mi=j;
		printf("Case %d:\n%d\n%d\n",c++,mx,mi);
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define RFOR(i,m,n) for(int i=m;i>=n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

int n;
int a[1000000];
P b[1000000];

int main(){
  cin>>n;
  rep(i,n){
    cin>>a[i];
    b[i] = P(a[i],i);
  }

  sort(b,b+n);

  int ans=0;
  rep(i,n){
    if(i%2==0&&b[i].second%2){    
      ans++;
    }
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 5120
from collections import Counter


def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)


def combination(n, r, mod=10**9+7):
    """
    nCr mod m
    """
    if n < r:
        return 0
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


n, m = map(int, input().split())
mod = 10**9+7

c = Counter(prime_factorize(m))

ans = 1
for v in c.values():
    ans *= combination(v+n-1, n-1)
    ans %= mod

print(ans)

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

int main(){
  int n;
  cin >> n;
  ll a[n];
  int c = 0;
  ll m = INF, sum = 0;
  rep(i, n){
    cin >> a[i];
    if(a[i] < 0) c++;
    if(abs(a[i]) < m) m = abs(a[i]);
    sum += abs(a[i]);
  }
  if(c % 2) cout << sum - 2*m << endl;
  else cout << sum << endl;
  return 0;
}


Measured memory_bytes: 1024
N = int(input())
W = list(map(int, input().split()))

result = 10000000000

for t in range(1, N-1, 1):
    s = []
    l = []
    for i in range(N):
        if i <= t:
            s.append(W[i])
        else:
            l.append(W[i])

    ret = abs(sum(s) - sum(l))
    if ret < result:
        result = ret

print(result)


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

int main() {
    li n;
    cin >> n;
    vector<li> as(n), bs(n);
    vector<pair<li, li>> elems;
    for (int i = 0; i < n; ++i) {
        cin >> as[i] >> bs[i];
        elems.emplace_back(as[i], i + 1);
        elems.emplace_back(bs[i], -(i + 1));
    }

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

    set<li> a_use, b_use;
    li cost = 0;
    for (int i = 0; i < n; ++i) {
        cost += elems[i].first;
        li idx = elems[i].second;
        if (idx > 0) {
            a_use.insert(idx);
        } else {
            b_use.insert(-idx);
        }
    }

    if (a_use.empty() or b_use.empty()) {
        cout << cost << endl;
    } else {
        bool intersect = false;
        for (auto &&a_elem  : a_use) {
            intersect |= b_use.find(a_elem) != b_use.end();
        }
        if (intersect) {
            cout << cost << endl;
        } else {
            if (elems[n].second != -elems[n - 1].second) {
                cout << cost + elems[n].first - elems[n - 1].first << endl;
            } else {
                li ans = min(cost + elems[n + 1].first - elems[n - 1].first, cost + elems[n].first - elems[n - 2].first);
                cout << ans << endl;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 10548
n,kona = map(int, input().split())
e = [int(input()) for i in range(n)]
min = 1001
x=0 #kotae
for i in range(n):
    kona -= e[i] 
    if e[i] < min:
        min = e[i]

x = n
d = kona // min
x = x + d
print(x)


Measured memory_bytes: 3060
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 29 20:55:46 2019

@author: YudNK
"""

n = int(input())
l = [int(i) for i in input().split()]
count = 0
for i in (range(len(l) - 2)):
    s = l[i:i + 3]
    t = sorted(s)
    if s[1] == t[1]:
        count +=1

print(count)

Measured memory_bytes: 3060
#include <stdio.h>
#define INF 1001001001
int min(int x, int y) {
	return x < y ? x : y;
}
int main() {
	int h, w, dp[100][100];
	char s[101][101];
	scanf("%d%d", &h, &w);
	for (int i = 0; i < h; i++) {
		scanf("%s", s[i]);
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			dp[i][j] = INF;
		}
	}
	if (s[0][0] == '#')
		dp[0][0] = 1;
	else
		dp[0][0] = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (i != 0)
				dp[i][j] =
					min(dp[i][j],
						dp[i - 1][j] +
							(s[i][j] == '#' && s[i - 1][j] == '.' ? 1 : 0));
			if (j != 0)
				dp[i][j] =
					min(dp[i][j],
						dp[i][j - 1] +
							(s[i][j] == '#' && s[i][j - 1] == '.' ? 1 : 0));
		}
	}
	printf("%d\n", dp[h - 1][w - 1]);
	return 0;
}

Measured memory_bytes: 256
function main(input) {
    const args = input.split(' ');
    const a = parseInt(args[0], 10);
    const b = parseInt(args[1], 10);
  
  (a * b) % 2 === 0 ? console.log('Even') : console.log('Odd');
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29516
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,X;
  cin>>N>>X;
  vector<int> m(N);
  for(int i=0;i<N;i++){
    cin>>m[i];
  }
  sort(m.begin(),m.end());
  int Y=0;
  for(int j=0;j<N;j++){
    Y+=m[j];
  }
  cout<<N+(X-Y)/m[0]<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define last last2
#define FR first
#define SE second

using namespace std;

typedef pair<int,int> pr;

namespace SETS {

int fa[300005];

void init(int n) {
  for(int i=1;i<=n;i++) fa[i]=i;
}

int find_father(int x) {
  return (fa[x]==x)?x:fa[x]=find_father(fa[x]);
}

bool check(int x,int y) {
  x=find_father(x);y=find_father(y);
  return x==y;
}

void merge(int x,int y) {
  x=find_father(x);y=find_father(y);
  if (x==y) return;
  fa[x]=y;
}

}

inline int id(int x,int y,int z) {
  return (x-1)*6+y*2+z+1;
}

vector <pr> e[50005];

bool vis[2][1000005];

void pre(int s,int mod) {
  for(int i=0,j=s;i<(mod<<1);i++,j=j*2%mod)
    vis[i&1][j]=1;
}

int main() {
  int n,m,k,mod;
  scanf("%d%d%d%d",&n,&m,&k,&mod);
  int g=0,last=-1;
  for(int i=1;i<=m;i++) {
  	int x,y,z;
  	scanf("%d%d%d",&x,&y,&z);
  	e[x].push_back(pr(y,z));
  	e[y].push_back(pr(x,z));
  	if (last!=-1) g=__gcd(g,abs(z-last)); 
  	last=z;
  }
  if (!g) g=mod;
  mod=__gcd(mod,3*g);
  int v=e[1][0].SE%g;
  pre(v,mod);
  SETS::init(6*n);
  for(int i=1;i<=n;i++)
    for(int j=0;j<e[i].size();j++) {
    	int u=e[i][j].FR,v=e[i][j].SE/g;
    	for(int k=0;k<3;k++) {
    		SETS::merge(id(i,k,0),id(u,(2*k+v)%3,1));
    		SETS::merge(id(i,k,1),id(u,(2*k+v)%3,0));
		}
	}
  for(int i=1;i<=k;i++) {
  	int x,y,z;
  	scanf("%d%d%d",&x,&y,&z);
  	z=(z+v)%mod;
  	bool ok=0;
  	for(int j=0;j<3;j++)
  	  for(int k=0;k<2;k++)
  	    if (SETS::check(id(y,0,0),id(x,j,k))&&vis[k][(z-j*g%mod+mod)%mod]) ok=1;
  	puts((ok)?"YES":"NO");
  }
  return 0;
}

Measured memory_bytes: 6528
A = int(input())
B = int(input())
C = int(input())
X = int(input())
ans = 0

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if (500 * i + 100 * j + 50 * k) == X:
                ans += 1

print(ans)


Measured memory_bytes: 3060
/*
  AOJ 1269
 */
#include <stdio.h>
#include <string.h>

char prime_flag[65536];

int prime1120[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,
		 67,71,73,79,83,89,97,101,103,107,109,113,127,131,
		 137,139,149,151,157,163,167,173,179,181,191,193,
		 197,199,211,223,227,229,233,239,241,251,257,263, 
		 269,271,277,281,283,293,307,311,313,317,331,337,
		 347,349,353,359,367,373,379,383,389,397,401,409,
		 419,421,431,433,439,443,449,457,461,463,467,479,
		 487,491,499,503,509,521,523,541,547,557,563,569,
		 571,577,587,593,599,601,607,613,617,619,631,641,
		 643,647,653,659,661,673,677,683,691,701,709,719,
		 727,733,739,743,751,757,761,769,773,787,797,809,
		 811,821,823,827,829,839,853,857,859,863,877,881,
		 883,887,907,911,919,929,937,941,947,953,967,971,
		 977,983,991,997,1009,1013,1019,1021,1031,1033,
		 1039,1049,1051,1061,1063,1069,1087,1091,1093,1097,
		 1103,1109,1117 };
int prime_sum[15];
int prime_table[1121];

int memo[1121][15][188];

prime2num(int x)
{
  while(prime_table[x]==0)
    x--;
  return(prime_table[x]);
}
make_prime_sum()
{
  int i,s;

  for(i=s=0;i<=14;i++)
    {
      prime_sum[i]=s;
      s += prime1120[i];
    }
}

int back_search(int n)
{
  int i;

  if(n<2)
    return(-1);
  for(i=n-1;i>=0;i--)
    if(prime_table[i])
      return(i);
  return(-1);
}

int solve(int n,int k,int up)
{
  int ret,n1,idx;

  
  if((ret=memo[n][k][prime2num(up)])>=0)
    return(ret);
  
  if(k==1)
    {
      if(n <= up && prime_table[n])
	ret=1;
      else
	ret=0;
    }

  else if(n < prime_sum[k])
    {
      ret=0;
    }
  else if(n ==prime_sum[k])
    {
      ret=1;
    }
  else
    {
      ret=0;
      n1=n;
      while((n1=back_search(n1)) != -1)
	{
	  if(n1 <= up)
	    ret+=solve(n-n1,k-1,n1-1);
	  n1=n1-1;
	}
    }
  memo[n][k][prime2num(up)]=ret;
  return(ret);
}
void prepare()
{
  int i,c;
  memset(prime_table,0,sizeof(prime_table));
  for(i=c=0;i<sizeof(prime1120)/sizeof(int);i++)
    prime_table[prime1120[i]]=++c;
}

main()
{
  int n,k,ret;

  memset(memo,-1,sizeof(memo));
  make_prime_sum();
  prepare();

  while(scanf("%d %d",&n,&k) && (n||k))
    {
      ret=solve(n,k,n);
      printf("%d\n",ret);
    }

  return(0);
}

Measured memory_bytes: 12964
#ifdef OJ_MISC_OFFLINE

#include "prolog.h"

#else
#define PRINT
#define LCERR
#endif

#include <algorithm>
#include <array>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

namespace {

using namespace std;

class Solution {
public:
    int virus_tree_2(int N, int K, const vector<pair<int, int>>& edges) {
        vector<vector<int>> g(N + 1);
        for (const auto& e : edges) {
            auto a = e.first;
            auto b = e.second;
            g[a].emplace_back(b);
            g[b].emplace_back(a);
        }
        int64_t ways_to_color = 1;
        dfs(g, K, 1, 0, 0, 0, ways_to_color);
        return ways_to_color % 1000000007;
    }

    void dfs(const vector<vector<int>>& g, int K, int cur_node, int parent_node,
             int level, int colored_sib_cnt, int64_t& ways_to_color) {
        ways_to_color *= (K - min(level, 2) - colored_sib_cnt);
        ways_to_color %= 1000000007;
        int colored_child_count = 0;
        for (auto next : g[cur_node]) {
            if (next == parent_node) continue;
            dfs(g, K, next, cur_node, level + 1, colored_child_count, ways_to_color);
            colored_child_count += 1;
        }
    }

private:

};

int solve() {
    Solution solution;
    // handle IO here
    int N, K;
    cin >> N >> K;
    vector<pair<int, int>> edges;
    for (int i = 0; i < N - 1; ++i) {
        edges.emplace_back();
        cin >> edges.back().first >> edges.back().second;
    }
    auto result = solution.virus_tree_2(N, K, edges);
    cout << result << endl;
    return 0;
}

} // anonymous namespace

#ifdef OJ_MISC_OFFLINE

#include "epilog.h"

#else

int main() {
    return solve();
}

#endif


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

int main() {
  int a,b;
  string s,t,u;
  cin>>s>>t>>a>>b>>u;
  if(s==u){
    cout<<a-1<<" "<<b;
  }else{
    cout<<a<<" "<<b-1;
  }
}

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

using namespace std;


int main() {

    int n, res, i;
    cin >> n;

    while(i = n*2) {

        if(n%2 == 0){
            res = n;
            break;
        }

        else if(i%2 == 0 && i%n==0) {
            res = i;
            break;
        }
    }

    cout << res << '\n';

    return 0;
}



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

using namespace std;

#define ll long long int
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define MOD 1000000007

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll a,b,n;
    cin>>a>>b>>n;

    cout<<(a*min(b-1,n))/b;
}

Measured memory_bytes: 3704
#include <iostream>                                             
using namespace std;                                            
                                                                
int main() {                                                    
  int n;                                                        
  while (cin >> n) {                                            
    int ans = 0;                                                
    for (int a=0; a<10; a++) {                                  
      for (int b=0; b<10; b++) {                                
        for (int c=0; c<10; c++) {                              
          for (int d=0; d<10; d++) {                            
            if (a+b+c+d==n) {                                   
              ans++;                                            
            }                                                   
          }                                                     
        }                                                       
      }                                                         
    }                                                           
    cout << ans << endl;                                        
  }                                                             
  return 0;                                                     
}                                                               
                       

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

int main() {
    vector<int> v(5);
    for(int i=0; i<5; i++) cin >> v[i];

    int marge = 0;
    int sum = 0;
    for(int i=0; i<5; i++) {
        if(v[i] % 10 != 0) {
            marge = max(marge, 10-v[i]%10);
        }
        while(v[i] % 10 != 0) {
            v[i]++;
        }
        sum += v[i];
    }
    cout << sum-marge << endl;
}



Measured memory_bytes: 3580
///"    "\\\

# include <bits/stdc++.h>

# define pb push_back

using namespace std;

int k , z = 0 , o , p = 0 ;

	
int main() {

	int n , x , y ;
	cin >> n >> x >> y ;
	n -= x ;
	int u = n / y ;
	cout << n - ( y * u );

}

///"    "\\\

Measured memory_bytes: 256
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
	string n;
	cin >> n;
	int l = n.length();
	int x = stoi(n);
	int sum=0;
	for (int i = 1; i < l+1; ++i) {
		sum += x / (int)pow(10, l-i) % 10;
	}
	string ans = "No";
	if (x % sum == 0) ans = "Yes";
	cout << ans << endl;
	return 0;
} 

Measured memory_bytes: 512
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>

using namespace std;

int main() {
    vector<int> h(10);
    for (size_t i=0; i<10; ++i)
        scanf("%d", &h[i]);

    sort(h.begin(), h.end(), greater<int>());
    for (size_t i=0; i<3; ++i)
        printf("%d\n", h[i]);

    return 0;
}

Measured memory_bytes: 2660
n = int(input())
A = list(map(int, input().split()))

app_flag = True
for i in A:
    if i % 2 == 0:
        if i % 3 == 0 or i % 5 == 0:
            pass
        else:
            app_flag = False

if app_flag:
    print('APPROVED')
else:
    print('DENIED')

Measured memory_bytes: 38384
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    Map<Integer, Integer> map = new HashMap<>();

    for (int i = 0; i < N; i++) {
      Integer key = sc.nextInt();
      map.computeIfPresent(key, (k, v) -> (v + 1));
      map.putIfAbsent(key, 1);
    }

    List<Integer> list = new ArrayList<>();
    map.entrySet().forEach(e -> list.add(e.getValue()));
    Collections.sort(list, Comparator.reverseOrder());
    int ans = list.stream().skip(K).mapToInt(n -> n).sum();
    System.out.println(ans);
    sc.close();
  }
}


Measured memory_bytes: 104072
# N, K = map(int, input().split())
# line = list(map(int, input().split()))
line = input()
ans = 0
isChange = False

for i in range(len(line)-1):
    if line[i] == line[i+1] and isChange == False:
        isChange = True
    elif line[i] == line[i+1] and isChange == True:
        isChange = False
    if isChange:
        ans += 1

if ans < len(line) - ans:
    print(ans)
else:
    print(len(line) - ans)


Measured memory_bytes: 3188