akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
  ll n, k;
  cin >> n >> k;

  ll ans = 1;
  if (n < k)
    ans = 0;

  if (k % 2 == 0)
  {
    ll res = (n - k / 2) / k + 1;
    for (int i = 0; i < 3; ++i)
    {
      ans *= res;
    }
    res = n / k;
    ll tmp = 1;
    for (int i = 0; i < 3; ++i)
    {
      tmp *= res;
    }
    ans += tmp;
  }
  else
  {
    ll res = n / k;
    for (int i = 0; i < 3; ++i)
    {
      ans *= res;
    }
  }
  if (k == 2 * n)
    ans = 1;
  else if (n < k)
    ans = 0;
  else if (n == k)
    ans = 1;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define rep(i,m,n) for(int i = (m);i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
#define Vec(a) vector <int> a
const int INF = 1 << 20;
const int MOD = 1e9+7;





int main(){
  
  int n;
  while(cin >> n,n){
    int m;
    cin >> m;
    P xy[4][m-1];
    vector <int> res;
    int x,y;
    int flag = m;
    REP(i,m){
      int aa,bb;
      if(i == 0){
	cin >> x >> y;
      }
      else{
	
	cin >> aa >> bb;
	if(aa-x == 0){
	  xy[0][i-1] = mk(0,bb-y);
	  xy[1][i-1] = mk(0,y-bb);
	  xy[2][i-1] = mk(y-bb,0);
	  xy[3][i-1] = mk(bb-y, 0);
	}
	else{
	  xy[0][i-1] = mk(aa-x,0);
	  xy[1][i-1] = mk(x-aa,0);
	  xy[2][i-1] = mk(0,aa-x);
	  xy[3][i-1] = mk(0, x-aa);

	}
	x = aa;
	y = bb;
      }
    }
    /*
    REP(i,4){
      cout << endl;
      REP(j,m-1){
	cout << xy[i][j].first << "  " << xy[i][j].second << endl;
      }
      cout << endl << endl;
      }
    */
    REP(i,n){
      
      cin >> m;
      P p[m-1];
      //int x,y;
      REP(j,m){
	if(j == 0){
	  cin >> x >> y;
	}
	else{
	  int aa,bb;
	  cin >> aa >> bb;
	  if(aa-x == 0){
	    p[j-1] = mk(0,bb-y);
	  }
	  else{
	    p[j-1] = mk(aa-x,0);

	  }
	  //cout << p[j-1].first << "     " << p[j-1].second << endl;
	  x = aa;
	  y = bb;
	  
	}
      }
      /*
      REP(j,m-1){
	cout << p[j].first << "     " << p[j].second << endl;
	}*/
    
      bool resf = false;
      REP(j,4){
	bool f = true;
	REP(k,m-1){
	  if(p[k] != xy[j][k]){
	    f = false;
	  }
	}
	if(f){
	  resf = true;
	}
      }
      P pp[m-1];
      REP(j,m-1){
	pp[j].first = p[m-2-j].first*-1;
	pp[j].second = p[m-2-j].second*-1;
	//cout << pp[j].first << "        " << pp[j].second << endl;
      }
      
      REP(j,4){
	bool f = true;
	REP(k,m-1){
	  if(pp[k] != xy[j][k]){
	    f = false;
	  }
	}
	if(f){
	  resf = true;
	}
      }
      if(resf == true && flag == m){
	res.pb(i+1);
	//cout << i+1 << endl;
      }
    }
    REP(i,res.size()){
      cout << res[i] << endl;
    }
    cout << "+++++" << endl;
  }

  return 0;
}



Measured memory_bytes: 3024
using System;

public class Coins
{
    public int c10 { get; set; }
    public int c50 { get; set; }
    public int c100 { get; set; }
    public int c500 { get; set; }
    public int ctotal { get; set; }
}

public class Hello
{
    public static void Main()
    {
        var first = true;
        while (true)
        {
            var a = int.Parse(Console.ReadLine().Trim());
            if (a == 0) break;
            string[] line = Console.ReadLine().Trim().Split(' ');
            var c10 = int.Parse(line[0]);
            var c50 = int.Parse(line[1]);
            var c100 = int.Parse(line[2]);
            var c500 = int.Parse(line[3]);
            var ctotal = c10 + c50 + c100 + c500;
            var minc0 = new Coins { c10 = c10, c50 = c50, c100 = c100, c500 = c500, ctotal = ctotal };
            var w1 = new Coins();
            var minc = 999999999; var minca = new Coins(); var mincb = new Coins();
            var wt = c10 * 10 + c50 * 50 + c100 * 100 + c500 * 500;
            w1.c10 = c10; w1.c50 = c50; w1.c100 = c100; w1.c500 = c500; w1.ctotal = ctotal;
            var w2 = getChenge(wt - a);
            if (ctotal + w2.ctotal - w1.ctotal < minc)
            {
                minc = ctotal + w2.ctotal - w1.ctotal;
                minca.c10 = w1.c10;
                minca.c50 = w1.c50;
                minca.c100 = w1.c100;
                minca.c500 = w1.c500;
                mincb.c10 = w2.c10;
                mincb.c50 = w2.c50;
                mincb.c100 = w2.c100;
                mincb.c500 = w2.c500;
            }
            print(minc0, minca, mincb, first);
            if (first) first = false;
        }
    }
    public static void print(Coins c0, Coins c1, Coins c2, bool first)
    {
        if (!first) Console.WriteLine();
        var w10 = c1.c10 - c2.c10;
        var w50 = c1.c50 - c2.c50;
        var w100 = c1.c100 - c2.c100;
        var w500 = c1.c500 - c2.c500;
        if (w10 >= 1) Console.WriteLine("10 {0}", w10);
        if (w50 >= 1) Console.WriteLine("50 {0}", w50);
        if (w100 >= 1) Console.WriteLine("100 {0}", w100);
        if (w500 >= 1) Console.WriteLine("500 {0}", w500);
    }
    public static Coins getChenge(int a)
    {
        var c = new Coins();
        c.c500 = a / 500;
        var a2 = a % 500;
        c.c100 = a2 / 100;
        var a3 = a2 % 100;
        c.c50 = a3 / 50;
        var a4 = a3 % 50;
        c.c10 = a4 / 10;
        c.ctotal = c.c10 + c.c50 + c.c100 + c.c500;
        return c;
    }
}




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

using namespace std;

int main(){
    int N;
    string X;
    cin >> N;
    vector<int> t(N);
    vector<string> s(N);
    for(int i=0;i<N;++i){
        cin >> s[i];
        cin >> t[i];
    }
    cin >> X;

    int time=0;
    int falled=N+1;
    for (int i = 0; i < N; ++i)
    {
        if(s[i]==X) falled = i;
        if(i > falled) time += t[i]; 
    }

    cout << time << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    char[] s = sc.next().toCharArray();
    char[] t = sc.next().toCharArray();
    
    Arrays.sort(s);
    Arrays.sort(t);
    char[] tt = new char[t.length];
    for (int i = 0; i < tt.length; i++) {
      tt[i] = t[t.length-1-i];
    }
    
    String S = String.valueOf(s);
    String T = String.valueOf(tt);
    
    System.out.println(S.compareTo(T) < 0 ? "Yes" : " No");
  }
}

Measured memory_bytes: 23892
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    a,b,k=map(int,input().split())
    if(a>=k):
        print(a-k,b)
    else:
        k-=a
        b=max(0,b-k)
        print(0,b)
resolve()

Measured memory_bytes: 38460
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    int x[1010], y[1010], z[1010];
    rep(i, N) cin >> x[i] >> y[i] >> z[i];
    int ans = -INF2;
    rep(bit, 8) {
        vector<int> v;
        int sum = 0;
        rep(j, N) {
            int cost = 0;
            if (bit & (1 << 0)) cost += x[j];
            else cost -= x[j];
            if (bit & (1 << 1)) cost += y[j];
            else cost -= y[j];
            if (bit & (1 << 2)) cost += z[j];
            else cost -= z[j];
            v.push_back(cost);
        }
        sort(v.begin(), v.end(), greater<int>());
        rep(i, M) sum += v[i];
        ans = max(ans, sum);
    }
    cout << ans << endl;

    return 0;
}


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

int main()
{
	int n, a;
	cin >> n;
	a=n/1000;
	
	if (a==0)
	{
		a++;
		cout << 1000*a-n << endl;
	}
	else if(n-1000*a==0)
		cout << 0 << endl;
	else
		cout << 1000*(a+1)-n << endl;
	return 0;
} 

Measured memory_bytes: 3676
#include <iostream>
#include <string>
#include <vector>
#include <string>

using namespace std;

void vec_cout(vector<int> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout<< vec[i];
    }
}

int determine(vector<int> &animal, int a, char c, int N){
    if (animal[a]==-1){
        c= (c=='o')?'x':'o';
    }
    if (c=='o'){
        if (animal[(a+1)%N]!=0 && animal[(N+a-1)%N] != animal[(a+1)%N]){
            //cout << a << ' ' << animal[(N+a-1)%N] << ' ' << animal[(a+1)%N] << endl;
            return -1;
        }
        animal[(a+1)%N]=animal[(N+a-1)%N];
    }else{
        if (animal[(a+1)%N]!=0 && animal[(N+a-1)%N] == animal[(a+1)%N]){
            //cout << a << ' ' << animal[(N+a-1)%N] << ' ' << animal[(a+1)%N] << endl;
            return -1;
        }
        animal[(a+1)%N]=-1*animal[(N+a-1)%N];
    }
    return 1;
}

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

    string line;
    cin >> line;

    int flag=0;
    vector<int> ans;

    vector<vector<int>> initial(4,vector<int>(2,0));
    initial={{1,1},{-1,-1},{1,-1},{-1,1}};

    for(int i=0; i<4; i++){
        vector<int> animal(N,0);
        animal[0]=initial[i][1];
        animal[N-1]=initial[i][0];
        flag=1;
        for(int j=0; j<N; j++){
            if (determine(animal,j,line[j],N)==-1){
                flag=0;
                break;
            }
        }
        if (flag==1){
            ans=animal;
            break;
        }
        //vec_cout(animal);
        //cout<<endl;
    }
    if (flag==0){
        cout << -1 << endl;
    }else{
        for(int i=0; i<N; i++){
            if(ans[i]==1){
                cout << 'S';
            }else{
                cout << 'W';
            }
        }
        cout<<endl;
    }
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF LONG_LONG_MAX
using namespace std;

signed main(){
    int a,b,c; cin>>a>>b>>c;
    if(a+b+1<c) cout<<a+b*2+1<<endl;
    else cout<<b+c<<endl;
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int a = ri(), b = ri();
	int p = ri(), q = ri(), r = ri();
	printf("%f\n", b + ((double) (p * b - (b - a) * q) / (r + q)));
	return 0;
}




Measured memory_bytes: 3228
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define endl '\n'
#define mod 1000000007
#define inf 1000000000000000000
const double pi = acos(-1);
const int sz = 200002;
int n,m, k;
int main() {
	io
	int x1,x2,x3,x4,x5;
	cin>>x1>>x2>>x3>>x4>>x5;
	if(x1 == 0) cout<<1<<endl;
	else if(x2 == 0) cout<<2;
	else if(x3 == 0) cout<<3;
	else if(x4 == 0) cout<<4;
	else cout<<5;
	
}



Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <vector>
#include <unordered_set>
using namespace std;
const int MAX_N = 1e6;
unordered_set<string> used_edge;
vector<int> used_node(MAX_N, false);
vector<vector<int>> edge(MAX_N, vector<int>{});

int dfs(int prev, int v){
    string key = to_string(min(prev, v)) + "_" + to_string(max(prev, v));
    auto itr = used_edge.find(key);
    if(itr != used_edge.end()){return 0;}
    else{used_edge.insert(key);}
    if(used_node[v]){return 1;}
    used_node[v] = true;

    int child_num = 0;
    for(auto dest:edge[v]){
        if(prev == dest){continue;}
        if(dfs(v, dest) == 1){
            child_num++;
            cout << v+1 << " " << dest+1 << endl;
        }
    }
    if(child_num % 2 == 0){
        return 1;
    }
    else{
        cout << v+1 << " " << prev + 1 << endl;
        return 0;
    }
}

int main(){
    int n, m; cin >> n >> m;
    if(m % 2 == 1){
        cout << -1 << endl;
        return 0;
    }
    for(int i=0; i<m; i++){
        int a, b; cin >> a >> b; a--; b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    dfs(-1, 0);
    return 0;
}

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

namespace abc167_d
{
  class Program
  {
    static void Main(string[] args)
    {
      var N = CIn.ReadInt();
      var K = CIn.ReadLong();
      var A = CIn.ReadIntArray(N).Select(e => e - 1).ToArray();

      var a = Enumerable.Repeat(-1, N).ToArray();
      var b = new List<int>();
      var c = 0;

      for (int i = 0; a[c] == -1; i++)
      {
        if (i == K)
        {
          Console.WriteLine(c + 1);
          return;
        }

        a[c] = i;
        b.Add(c);
        c = A[c];
      }

      var loop = b.Count - a[c];
      var ans = b[(int)((K - a[c]) % loop) + a[c]] + 1;

      Console.WriteLine(ans);
    }
  }

  static class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }
      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(int n)
    {
      var array = new string[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = Read();
      }
      return array;
    }

    public static int[] ReadIntArray(int n)
    {
      var array = new int[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadInt();
      }
      return array;
    }

    public static long[] ReadLongArray(int n)
    {
      var array = new long[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadLong();
      }
      return array;
    }

    public static double[] ReadDoubleArray(int n)
    {
      var array = new double[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadDouble();
      }
      return array;
    }

    public static char[,] ReadCharMatrix(int h, int w)
    {
      var array = new char[h, w];
      for (var i = 0; i < h; i++)
      {
        var l = Console.ReadLine().ToCharArray();
        for (var j = 0; j < w; j++)
        {
          array[i, j] = l[j];
        }
      }
      return array;
    }
  }
}

Measured memory_bytes: 49944
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <math.h>
#include <stdio.h>

using namespace std;

int main() {
    int H, W;
    cin >> H >> W;
    string S[H];
    for (int i = 0; i < H; ++i) {
        cin >> S[i];
    }
    const int dx[8] = { 1, 0,-1, 0, 1, 1,-1, -1 };
    const int dy[8] = { 0, 1, 0,-1, 1,-1, 1, -1 };
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (S[i][j] == '#') continue;
            int num = 0;
            for (int d = 0; d < 8; ++d) {
                const int ni = i + dy[d];
                const int nj = j + dx[d];

                if (ni < 0 or ni >= H) continue;
                if (nj < 0 or nj >= W) continue;
                if (S[ni][nj] == '#') num++;
            }
            S[i][j] = char(num + '0');
        }
    }
    for (int i = 0; i < H; ++i) {
        cout << S[i] << endl;
    }
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

const int MAXN=233;
const int P=1E9+7;
const ll INF=1E18;

template<typename T1,typename T2>
	void Inc(T1 &a,T2 b){a+=b;if(a>=P) a-=P;}

template<typename T1,typename T2>
	void Dec(T1 &a,T2 b){a-=b;if(a<0) a+=P;}

template<typename T1,typename T2>
	T1 Add(T1 a,T2 b){a+=b;return a>=P?a-P:a;}

template<typename T1,typename T2>
	T1 Sub(T1 a,T2 b){a-=b;return a<0?a+P:a;}

int times(ll a,ll b)
{
	if(a<b) swap(a,b);
	if(b==0) return 0;
	return times(b,a%b)+1;
}

int q,LIM;
ll fib[MAXN];
vector<pair<ll,ll> > ep[MAXN];

int main()
{
	fib[0]=fib[1]=1;LIM=1;
	for(int i=2;fib[i-1]<=INF;i++)
		fib[i]=fib[i-1]+fib[i-2],++LIM;
	ep[1].emplace_back(1,2);
	ep[1].emplace_back(1,3);
	for(int i=1;i<LIM;i++)
	{
		for(auto x:ep[i])
		{
			ll t=x.first+x.second;
			while(t<=fib[i+3])
			{
				if(times(x.second,t)==i+1)
					ep[i+1].emplace_back(x.second,t);
				t+=x.second;
			}
		}
		sort(ep[i+1].begin(),ep[i+1].end());
		ep[i+1].erase(unique(ep[i+1].begin(),ep[i+1].end()),ep[i+1].end());
	}
	scanf("%d",&q);
	while(q--)
	{
		ll A,B,Ans1=1,Ans2=0;
		scanf("%lld%lld",&A,&B);
		if(A>B) swap(A,B);
		while(fib[Ans1+1]<=A&&fib[Ans1+2]<=B)
			++Ans1,assert(Ans1<=LIM);
		if(Ans1==1) printf("1 %lld\n",1ll*A*B%P);
		else
		{
			for(auto x:ep[Ans1-1])
			{
				if(A>=x.second)
					Inc(Ans2,(B-x.first)/x.second%P);
				if(B>=x.second)
					Inc(Ans2,(A-x.first)/x.second%P);
			}
			printf("%lld %lld\n",Ans1,Ans2);
		}
	}
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

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

    ll N;
    cin >> N;
    multiset<ll> st;
    REP(i, N){
    	ll tmp;
    	cin >> tmp;
    	st.insert(tmp);
    }

    ll res = 0;
    while((int)st.size()>0){
    	auto itr = st.end();
    	itr--;
    	ll val = *itr;
    	st.erase(itr);

    	ll tmp = 1;
    	while(tmp<=val){
    		tmp *= 2;
    	}
    	auto tar = st.find(tmp-val);
    	if(tar != st.end()){
    		res++;
    		st.erase(tar);
    	}
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 9600
S = input()
k = ["dream", "dreamer" ,"erase", "eraser"]
ans = "NO"

while len(S) > 0:
  a = len(S)
  for i in k:
    if S[-1*len(i):] == i:
      S = S[0:-1*len(i)]
      break
  if a == len(S):
    break
  elif len(S) == 0:
    ans="YES"
print(ans)


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

template <typename T, typename _ = void>
struct is_container : std::false_type {};
template <typename T>
struct is_container<T, std::void_t<decltype(std::declval<T>().begin()),
                                   decltype(std::declval<T>().end())>>
    : std::true_type {};
template <typename T, typename _ = void>
struct is_pair : std::false_type {};
template <typename T>
struct is_pair<T, std::void_t<decltype(std::declval<T>().first),
                              decltype(std::declval<T>().second)>>
    : std::true_type {};
template <typename T>
void debug(const T& v) {
  if constexpr (is_pair<T>::value) {
    std::cerr << "{";
    debug(v.first);
    std::cerr << ", ";
    debug(v.second);
    std::cerr << "}";
  } else if constexpr (is_container<T>::value) {
    std::cerr << "{";
    for (auto it = v.begin(); it != v.end(); ++it) {
      if (it != v.begin()) std::cerr << ", ";
      debug(*it);
    }
    std::cerr << "}";
  } else {
    std::cerr << v;
  }
}
template <typename T, typename... Ts>
void debug(const T& value, const Ts&... args) {
  debug(value);
  std::cerr << ", ";
  debug(args...);
}
#if DEBUG
#define dbg(...)                        \
  do {                                  \
    cerr << #__VA_ARGS__ << ": ";       \
    debug(__VA_ARGS__);                 \
    cerr << " (L" << __LINE__ << ")\n"; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define rd(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  if constexpr (std::is_same<T, bool>::value) {
    std::cout << (value ? "Yes" : "No");
  } else {
    std::cout << value;
  }
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  write_to_cout(value);
  std::cout << ' ';
  write_to_cout(args...);
}
#define wt(...)                 \
  do {                          \
    write_to_cout(__VA_ARGS__); \
    cout << '\n';               \
  } while (0)

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

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& v) {
  for (T& vi : v) is >> vi;
  return is;
}

template <typename T, typename U>
bool chmax(T& a, U b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <typename T, typename U>
bool chmin(T& a, U b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

#include <boost/hana/functional/fix.hpp>
auto Fix = boost::hana::fix;

using ll = long long;

template <typename T>
using low_priority_queue =
    std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <typename T>
using V = std::vector<T>;
template <typename T>
using VV = V<V<T>>;

using namespace std;

int main() {
  rd(int, n);
  V<int> a(n);
  cin >> a;
  sort(all(a), greater());
  int alice = 0, bob = 0;
  rep(i, n)((i & 1) ? bob : alice) += a[i];
  wt(alice - bob);
}


Measured memory_bytes: 3572
/*author : Yashvardhan
Saturday, April 04, 2020
5:35 PM
*/

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#define int ll
#define pb push_back
#define vi vector<int>
#define pi pair<int,int>
#define vpi vector<pi>
#define ff first
#define ss second
#define mp make_pair
#define endl '\n'
#define all(a) a.begin(), a.end()
#define initialise(a, x) memset(a, x, sizeof(a))
#define rev(Y) reverse(all(Y))
#define printArr(name,from,to) for(int x = from; x < to; x++) cout << name[x] << " ";


#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#ifdef __APPLE__
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << "  ";
	__f(comma + 1, args...);}
#else
#define debug(...)
#endif

template <typename T> ostream& operator << (ostream& os,const vector<T>& v){for(int i=0;i<v.size();++i) os<<v[i]<<" ";return os;} 
template <typename T> ostream& operator << (ostream& os,const set<T>& v){for(auto it:v) os<<it<<" ";return os;} 
template <typename T, typename S> ostream& operator << (ostream& os, const pair<T,S>& v) {os<<v.ff<<" "<<v.ss;return os;}

const int mod = 1e9 + 7;
const int inf = 2e18;
const int ninf = -2e18;

int takemod(int a){return ((a%mod)+mod)%mod;}

int pow(int a, int b, int m)
{
	int ans = 1;
	a %= m;
	while (b)
	{
		if (b & 1)
			ans = (ans * a) % m;
		b /= 2;
		a = (a * a) % m;
	}
	return ans;
}

int modinv(int a){return takemod( pow( takemod(a), mod-2,mod ) );}


signed main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);

	#ifdef __APPLE__
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("error.txt","w",stderr);
	#endif

	time_t t1, t2;
	t1 = clock();
	
	int n,k;
	cin >> n >> k;

	int quot = n/k;
	int rem = n%k;

	if(!rem){
		cout << 0 << endl;
		return 0;
	}

	int val = quot*k;
	n -= val;

	int ans = min(n,abs(n-k));
	cout << ans << endl;
	

	t2 = clock();
	cerr << endl << t2-t1 << endl;
	
	return 0;
}



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

using namespace std;

int main(void) {
    int count, n;
    count = n = 0;
    string s;
    cin >> n >> s;
    for(int i=0; i<n-2;++i) {
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') {
            count++;
        }
    }
    cout << count << '\n';
    return 0;
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
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; }
typedef long long ll;
const int MAX_N = 1e+6;
int par[MAX_N];//親
int pank[MAX_N];//木の深さ

//n要素で初期化
void init(int n){
    for(int i=0;i<n;i++){
        par[i]=i;
        pank[i]=0;
    }
}

//木の根を求める
int find(int x){
    if(par[x]==x){
        return x;
    }else{
        return par[x]=find(par[x]);
    }
}

//xとyの属する集合を併合
void unite(int x,int y){
    x = find(x);
    y = find(y);
    if(x==y)return;
    if(pank[x]<pank[y]){
        par[x]=y;
    }else{
        par[y]=x;
        if(pank[x]==pank[y])pank[x]++;
    }
}

//xとyが同じ集合に属するか否か
bool same(int x,int y){
    return find(x)==find(y);
}

int main(void){
    ll n,m;cin>>n>>m;
    init(n);
    map<int,int> mp;
    rep(i,n){
        int x;cin>>x;x--;
        mp[i]=x;
    }
    rep(i,m){
        int x,y;cin>>x>>y;x--;y--;
        unite(x,y);
    }
    ll res=0;
    rep(i,n){
        if(same(i,mp[i]))res++;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 9472
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map> 
#include<time.h>
using namespace std;
typedef long long ll;
const double pi=acos(-1.0);
const ll mod=1e9+7;
const int inf=0x3f3f3f3f;
//ll begin_time=clock();
//ll end_time=clock();printf("time=%lldms\n",end_time-begin_time);

int main()
{
	int a,b,c,d,e=0;
	scanf("%d",&a);
	scanf("%d%d",&b,&c);
	for(int i=b;i<=c;i++)
	{
		if(i%a==0)
		{
			printf("OK\n");
			e=1;
			break;
		}
	}
	if(!e)printf("NG\n");
	
}




Measured memory_bytes: 1648
#include<bits/stdc++.h>
#define clr(x) memset(x, 0, sizeof(x))
#define sz(x) (int)x.size()

using namespace std;

typedef long long ll;
typedef pair<long , long> pll;

const ll mx = 105;
const ll mod = 998244353;


vector<vector<int>> adj;


void solve(){
    
    ll x, i, j, k;

    cin>>x;

    ll init = 100;

    ll co = 0;

    while(init < x){
        init += init/100;
        co++;
    }
    cout<<co<<"\n";
  
}


int main(){

   ios_base::sync_with_stdio(false);
   cin.tie(0);

    ll t = 1;
    
   // cin>>t;

    while(t--){
        solve();
    }
   
}




Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <iomanip>
#include <queue>
#include <functional>
#include <cassert>
#include <cmath>


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

using namespace std;
using ll = long long;
using ull = unsigned long long;

int main() {

	int n;
	string s;

	cin >> n >> s;

	vector<int> w(n + 10);
	vector<int> e(n + 10);

	int nn = n - 1;
	w[0] = 0, e[nn] = 0;
	for (int i = 1; i <= nn; i++) {
		if (s[i - 1] == 'W') {
			w[i] = w[i - 1] + 1;
		}
		else {
			w[i] = w[i - 1];
		}
		if (s[nn - i + 1] == 'E') {
			e[nn - i] = e[nn - i + 1] + 1;
		}
		else {
			e[nn - i] = e[nn - i + 1];
		}
	}
	int ans = w[0] + e[0];
	for (int i = 0; i < n; i++) {
		ans = min(ans, w[i] + e[i]);
	}

	cout << ans NL;

	return 0;
}

Measured memory_bytes: 3076
#include <iostream>
using namespace std;
int main (void) {
    int N;
    string s, t;

    cin >> N;
    cin >> s;
    cin >> t;

    int ans = 2 * N;
    for (int i = 0, slen = s.length(); i <= slen; i++) {
        string st = s.substr(0, slen - i) + t;
        if (st.substr(0, slen) == s) {
            ans = st.length();
        }
    }

    cout << ans << endl;

    return 0;
}


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
typedef complex<ld> Point;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 1e5 + 5;
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

int char_to_int(char c) {
    return c - '0';
}

int main() {
    int n, q;
    string s;
    cin >> n >> s >> q;
    vector<set<int>> v(27);
    rep(i, n) {
        rep(j, 26) {
            if (s[i] == char('a' + j))
                v[j].insert(i);
        }
    }

    rep(i, q) {
        int query_distinction;
        cin >> query_distinction;
        if (query_distinction == 1) {
            int idx;
            char c;
            cin >> idx >> c;
            idx--;
            rep(j, 27) {
                if (v[j].find(idx) != v[j].end())
                    v[j].erase(idx);
            }
            v[c - 'a'].insert(idx);
        } else {
            int l, r;
            int cnt = 0;
            cin >> l >> r;
            l--, r--;
            rep(j, 27) {
                auto lb = v[j].lower_bound(l);
                if (lb == v[j].end()) continue;
                // debug(char(j + 'a'));
                // debug(*lb);
                if (*lb <= r) cnt++;
            }
            out(cnt);
        }
    }

    return 0;
}


Measured memory_bytes: 24196
#include<iostream>
#include<algorithm>
using namespace std;
string S,T,V="AIZUNYAN";
int main(){
	cin>>S;T=S;
	if(S.size()<8){cout<<S<<endl;return 0;}
	for(int i=0;i<S.size()-7;i++){
		string U=S.substr(i,8);
		char p[8];
		for(int j=0;j<8;j++){p[j]=U[j];}
		sort(p,p+8);U="";
		for(int j=0;j<8;j++){U+=p[j];}
		if(U=="AADINNUY"){
			for(int j=0;j<8;j++){
				T[i+j]=V[j];
			}
		}
	}
	cout<<T<<endl;
	return 0;
}

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

#define int long long int
#define ps psuh_back()
#define fi first
#define so second

signed main()
{
    int n,m;
    cin>>n>>m;
    if(n<m)
    {
        for(int i=0;i<m;i++) cout<<n;
    }
    else
    {
        for(int i=0;i<n;i++) cout<<m;
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

using ll = long long;
using P = pair<int, int>;

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; }

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }


int main() {
    ll x;
    cin >> x;
    ll now = 100;
    rep(i, 4000) {
        now += now / 100;
        if (x <= now) {
            cout << i + 1 << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3636
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
using namespace std;
using ll=long long;
#define mod  1000000007

int main(int argc, char const *argv[]) {
  int a,b;
  std::cin >> a >> b;
  if(a%2==0 || b%2==0) std::cout << "No" << '\n';
  else std::cout << "Yes" << '\n';
  return 0;
}

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

int main(){
	int shakkinn=100000;
	int n;
	int i;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		shakkinn *= 1.05;
		while (shakkinn % 1000 != 0) {
			shakkinn++;

	}
}
	printf("%d\n", shakkinn);
	return 0;
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
#include<iostream>
#include<queue>
using namespace std;
#define ll long long
#define PI 3.1415926535898
int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string a, b; int ans = 0;
	cin >> a>>b;
	for (int i = 0; i < 3; i++)
	{
		if (a[i] == b[i])
		{
			ans++;
		}

	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
M=998244353
d=[0]*90301
d[0]=1
e=[0]*90301
e[0]=1
z=1
s=0
for _ in range(input()):
	a=input();s+=a;i=s;z*=3
	while~i:d[i]+=d[i]+d[i-a]%M;e[i]+=e[i-a]%M;i-=1
i=s
while i*2>=s:z=(z-d[i]*3)%M;i-=1
z+=~s%2*e[s//2]*3
print z%M

Measured memory_bytes: 156648
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
ll gcd(ll a, ll b)
{
	if (b == 0)return a;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region LCM
ll lcm(ll a, ll b)
{
	return a / gcd(a, b) * b;
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int n; cin >> n;
	vector<ll> a(n); rep(i, n)cin >> a[i];
	vector<ll> s(n + 1);
	ll MOD = 1e9 + 7;
	rep(i, n)
	{
		s[i + 1] = s[i] + a[i];
		s[i + 1] %= MOD;
	}
	ll res = 0;
	rep(i, n - 1)
	{
		ll tmp = s[n] - s[i + 1];
		if (tmp < 0)tmp += MOD;
		res += a[i] * tmp;
		res %= MOD;
	}
	cout << res << endl;
}

Measured memory_bytes: 6420
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int main()
{
	int b, f, r, v;;
	int house[5][4][11];
	int i, n;

	for (b = 1; b <= 4; b++) {
		for (f = 1; f <= 3; f++) {
			for (r = 1; r <= 10; r++) house[b][f][r] = 0;
		}
	}
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d%d%d%d", &b, &f, &r, &v);
		house[b][f][r] += v;
	}

	for (b = 1; b <= 4; b++) {
		for (f = 1; f <= 3; f++) {
			for (r = 1; r <= 10; r++) printf(" %d", house[b][f][r]);
			putchar('\n');
		}
		if (b < 4) puts("####################");
	}
	return 0;
}



Measured memory_bytes: 2104
#include<stdio.h>
int main()
{
    char op;
    int a,b;
    int c;
    for(;;)
    {
        scanf("%d %c %d",&a,&op,&b);
        if(op=='+')
        {
            c=a+b;
        }
        else if(op=='-')
        {
            c=a-b;
        }
        else if(op=='*')
        {
            c=a*b;
        }
        else if(op=='/')
        {
            c=a/b;
        }
        else
        {
            break;
        }
        printf("%d\n",c);
    }
    return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#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 forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/*******************************head*******************************/
int n,m=0;
const int maxn=200005,inf=100000000;
pin p[maxn],tmp[maxn];
int a[maxn];
const double pi=acos(-1.0);
int main(){
	int x1,x2,y1,y2;
	read(x1);read(y1);read(x2);read(y2);read(n);
	rep(i,1,n)read(p[i].w1),read(p[i].w2);
	if(x1>x2){
		swap(x1,x2);swap(y1,y2);
	}
	if(y1>y2){
		y1=inf-y1;y2=inf-y2;
		rep(i,1,n)p[i].w2=inf-p[i].w2;
	}
	rep(i,1,n)
		if(p[i].w1<x1||p[i].w1>x2||p[i].w2<y1||p[i].w2>y2);
		else tmp[++m]=p[i];
	rep(i,1,m)p[i]=tmp[i];n=m;m=0;
	sort(p+1,p+1+n);	
	rep(i,1,n)if(p[i].w2>=a[m])a[++m]=p[i].w2;else a[lower_bound(a+1,a+m+1,p[i].w2)-a]=p[i].w2;
	double ans=100.*(x2-x1+y2-y1)+m*(5*pi-20);
	if(m==min(x2-x1,y2-y1)+1)ans+=5*pi;
	printf("%.13f\n",ans);
	return 0;
}


Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll mod=1000000007;
inline void multiply(ll mat1[][2], ll mat2[][2])
{
	ll res[2][2];
    ll i, j, k;
    for (i = 0; i < 2; i++)
    {
        for (j = 0; j < 2; j++)
        {
            res[i][j] = 0;
            for (k = 0; k < 2; k++)
            res[i][j]=(res[i][j]%mod + (mat1[i][k]*mat2[k][j])%mod)%mod;
        }
    }
    for (i=0;i<2;i++)
	{
		for (j=0;j<2;j++)
		mat1[i][j]=res[i][j];
	}
}
inline ll moduloexp(ll l,ll p)
{
	ll res=1;
	while (p>0)
	{
		if (p%2==1)
		{
			
			res*=l;
			res%=mod;
		}
		p/=2;
		l=(l*l)%mod;
	}
	return res;
}
inline ll modInverse(ll l,ll power, ll mod)
{
	l=moduloexp(l,power);
	return moduloexp(l,mod-2);
}
inline void fs(ll &number)
{
    bool negative = false;
    register ll c;
    number = 0;
    c = getchar();
    if (c=='-')
    {
        negative = true;
        c = getchar();
    }
    for (; (c>47 && c<58); c=getchar())
    number = number *10 + c - 48;
    if (negative)
    number *= -1;
}
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if (abs(a-c)<=d)
	cout<<"Yes";
	else if (abs(a-b)<=d&&abs(b-c)<=d)
	cout<<"Yes";
	else
	cout<<"No";	
}

Measured memory_bytes: 256
// -----------------------------------
// Author     : MatsuTaku
// Country    : Japan
// Created    : 05/23/20 20:47:37
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr ll inf = numeric_limits<ll>::max();

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

  int t; cin>>t;
  for (int _=0; _<t; _++) {
    ll n,a,b,c,d; cin>>n>>a>>b>>c>>d;
    vector<pair<ll,ll>> ops = {
        {2,a},{3,b},{5,c}
    };
    map<ll,ll> mem;
    mem[0] = 0;
    mem[1] = d;
    auto rec = [&](auto& rec, ll x) -> ll {
      if (mem.count(x)) {
        return mem[x];
      }
      ll res = ((long double)d*x < inf) ? d*x : inf;
      for (auto [m,cost]:ops) {
        res = min(res, rec(rec, x/m) + cost + d*(x%m));
        if (x%m!=0) {
          res = min(res, rec(rec, x/m+1) + cost + d*(m-x%m));
        }
      }
      mem[x] = res;
      return res;
    };
    cout << rec(rec, n) << endl;
  }

  return 0;
}


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

int main()
{
    int N, W;
    cin >> N >> W;
    int value[N], weight[N];
    for (int i = 0; i < N; i++) {
        cin >> value[i] >> weight[i];
    }
    // dp[i][w] := i 番目の品物までを見た時に重さがwを超えない時の価値の最大値
    int dp[N + 5][W + 5] = {};
    dp[0][0] = 0;
    for (int i = 0; i < N; i++) {
        for (int w = 0; w < W + 1; w++) {
            // i番目の品物を入れる時
            if (w - weight[i] >= 0) {
                dp[i + 1][w] = max(dp[i][w], dp[i + 1][w - weight[i]] + value[i]);
            }
            // 入れられない時
            dp[i + 1][w] = max(dp[i + 1][w], dp[i][w]);
        }
    }
    printf("%d\n", dp[N][W]);
}



Measured memory_bytes: 7252
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rep(a,b,c) for (int a=b;a<=c;a++)
using namespace std;
const int N=310;
int n,m,h[N],a[N][N],cnt[N],vis[N];
int main(){
	scanf("%d%d",&n,&m);
	rep(i,1,n) rep(j,1,m) scanf("%d",&a[i][j]);
	rep(i,1,n) h[i]=1;
	int ans=1e5;
	rep(k,1,m){
		memset(cnt,0,sizeof(cnt));
		rep(i,1,n) ++cnt[a[i][h[i]]];
		int mx=1;
		rep(i,1,m) if (cnt[mx]<cnt[i]) mx=i;
		ans=min(ans,cnt[mx]);
		vis[mx]=1;
		rep(i,1,n) while (vis[a[i][h[i]]]) ++h[i];
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<algorithm>
#include<queue>
#include<utility>
#include<tuple>
#include<cmath>
using namespace std;

class UnionFind
{
public:
	UnionFind(int sz) : size(sz), table(size, 0)
	{
		for(int i=0; i<size; i++)
			table[i] = i;
	};

	int find(int id)
	{
		if(id == table[id])
			return id;
		return table[id] = find(table[id]);
	};
	bool same(int id1, int id2)
	{
		return find(id1) == find(id2);
	};
	void unite(int id1, int id2)
	{
		id1 = find(id1);
		id2 = find(id2);
		table[max(id1, id2)] = table[min(id1, id2)];
	};

private:
	const int size;
	vector<int> table;
};

int main(void)
{
	int N;
	cin >> N;

	vector<long long> x(N), y(N);
	for(int i=0; i<N; i++)
		cin >> x[i] >> y[i];

	vector<pair<long long, int>> xx(N), yy(N);
	for(int i=0; i<N; i++)
	{
		xx[i] = make_pair(x[i], i);
		yy[i] = make_pair(y[i], i);
	}

	sort(xx.begin(), xx.end());
	sort(yy.begin(), yy.end());

	priority_queue<tuple<long long, int, int>> edge;
	for(int i=0; i<N-1; i++)
	{
		int from = i;
		int to = i + 1;

		edge.push(make_tuple(-abs(xx[to].first-xx[from].first), xx[from].second, xx[to].second));
		edge.push(make_tuple(-abs(yy[to].first-yy[from].first), yy[from].second, yy[to].second));
	}

	long long ret = 0;
	UnionFind uf(N);
	while(edge.empty() != true)
	{
		auto e = edge.top();
		edge.pop();

		int cost = -get<0>(e);
		int from = get<1>(e);
		int to = get<2>(e);

		if(uf.same(from, to) == true)
			continue;

		uf.unite(from, to);
		ret += cost;
	}

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 11248
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, k = sc.nextInt()
  val lr = List.fill(k)((sc.nextInt(), sc.nextInt()))

  val mod = 998244353
  def plus(a: Long, b: Long): Long = (a + b) % mod
  def minus(a: Long, b: Long): Long = (a - b + mod) % mod

  val dp = Array.fill(n)(0L)
  val dpSum = Array.fill(n+1)(0L)
  dp(0) = 1
  dpSum(1) = 1
  for (i <- 1 until n) {
    for ((l, r) <- lr) {
      dp(i) = plus(dp(i), minus(dpSum((i-l+1).max(0)), dpSum((i-r).max(0))))
    }
    dpSum(i+1) = plus(dpSum(i), dp(i))
  }

  println(dp(n-1))
}


Measured memory_bytes: 60568
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    Scanner sc = new Scanner(System.in);

    int h = sc.nextInt();
    int a = sc.nextInt();

    if (h % a == 0) {
      System.out.println(h / a);
    } else {
      System.out.println(h / a + 1);
    }
  }
}


Measured memory_bytes: 22100
#include <stdio.h>
int main(void){
int a=0,b=0,c=0;
int i,j,k;


scanf("%d %d %d",&a,&b,&c);

i=(a*10)+b+c;

j=a+(b*10)+c;

k=a+b+(c*10);


if(i>j)
j=i;

if(j<k)
printf("%d",k);
else
printf("%d",j);


return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll ;
#define rep(i, a, b) for (int i = a; i <= b; ++ i) 
const int N = 100005 ;
using namespace std ;

int n, e, ter[N], nxt[N], lnk[N], f[N], d[N] ;

void add(int x, int y) {
	ter[++ e] = y, nxt[e] = lnk[x], lnk[x] = e ;
}

void dfs(int p) {
	if (!lnk[p]) {
		f[p] = 1 ;
		return ;
	}
	for (int i = lnk[p]; i; i = nxt[i]) dfs(ter[i]) ;
	d[0] = 0 ;
	for (int i = lnk[p]; i; i = nxt[i]) {
		d[++ d[0]] = f[ter[i]] ;
	}
	sort(d + 1, d + d[0] + 1) ;
	reverse(d + 1, d + d[0] + 1) ;
	f[p] = 1 ;
	rep(i, 1, d[0]) {
		f[p] = max(f[p], d[i] + i) ;
	}
}

int main() {
	scanf("%d", &n) ;
	int x ;
	rep(i, 2, n) {
		scanf("%d", &x) ;
		add(x, i) ;
	}
	dfs(1) ;
	printf("%d\n", f[1] - 1) ;
	return 0 ; 
}

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

int main(){
    char s[3];

    // ページ数
    cin >> s;

    if((strcmp(s,"AAA")==0)||(strcmp(s,"BBB")==0)){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;

int main(){
  double x[3], y[3], p[2];

  while(cin >> x[0] >> y[0]){
    for(int i = 1; i < 3; i++){
      cin >> x[i] >> y[i];
    }
    cin >> p[0] >> p[1];

    // pを(0,0)として三角形の位置をづらす
    for(int i = 0; i < 3; i++){
      x[i] -= p[0];
      y[i] -= p[1];
    }

    // 辺の長さ
    double triEdge[3];
    double pEdge[3];
    // 12 23 31
    for(int i = 0; i < 3; i++){
      triEdge[i] = sqrt(pow(x[i % 3] - x[(i + 1) % 3], 2)
		     + pow(y[i % 3] - y[(i + 1) % 3], 2));
    }

    // 1p 2p 3p
    for(int i = 0; i < 3; i++){
      pEdge[i] = sqrt(pow(x[i], 2) + pow(y[i], 2));
    }
    
    // ヘロンの公式
    double s;
    double ans;
    // 123の面積
    s = (triEdge[0] + triEdge[1] + triEdge[2]) / 2;
    ans = sqrt(s * (s - triEdge[0])*(s - triEdge[1])
	       *(s - triEdge[2]));

    double area;
    // p12の面積
    s = (triEdge[0] + pEdge[0] + pEdge[1]) / 2;
    area = sqrt(s * (s - triEdge[0])*(s - pEdge[0])
	       *(s - pEdge[1]));

    // p13の面積
    s = (pEdge[0] + pEdge[2] + triEdge[2]) / 2;
    area += sqrt(s * (s - pEdge[0])*(s - pEdge[2])
	       *(s - triEdge[2]));

    // p23の面積
    s = (pEdge[1] + triEdge[1] + pEdge[2]) / 2;
    area += sqrt(s * (s - pEdge[1])*(s - triEdge[1])
	       *(s - pEdge[2]));
    
    if(fabs(ans - area) < 0.00001){
      cout << "YES" << endl;
    }
    else{
      cout << "NO" << endl;
    }
    
   
  }
  return 0;
}
  

Measured memory_bytes: 0
import math,sys
from sys import stdin, stdout
from collections import Counter, defaultdict, deque
input = stdin.readline
I = lambda:int(input())
li = lambda:list(map(int,input().split()))

def case():
    n,k=li()
    a=li()
    d=defaultdict(int)
    i=0
    d[1]=1
    c=0
    ans=[1]
    while(a[i] not in d):
        d[a[i]]=1
        c+=1 
        ans.append(a[i])
        i=a[i]-1
   # print(i)
    #print(ans)
    if(k<len(ans)):
        print(ans[k%len(ans)])
        return
    for j in range(len(ans)):
        if(ans[j]==a[i]):
            ans=ans[j:]
            k-=j
            break 

    #print(ans,k)
    print(ans[(k)%len(ans)])
    




for _ in range(1):
    case()

Measured memory_bytes: 37204