akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		class qube{
			Scanner sc = new Scanner(System.in);
			int [] face = new int[6],faces = new int[6];
			Integer i,j,dump=0,check;

			qube(){
				for(i=0;i<6;i++){
					face[i]=sc.nextInt();
				}
				for(i=0;i<6;i++){
					faces[i]=sc.nextInt();
				}
			}

			void swap(int a,int b){
				dump = this.face[a];
				this.face[a] = this.face[b];
				this.face[b] = dump;

			}

			void move(String es){
				if(es.equals("E")){
					swap(0,2);
					swap(0,5);
					swap(0,3);
				}
				else if(es.equals("N")){
					swap(4,5);
					swap(4,1);
					swap(4,0);
				}

			}
			boolean comp(){
				check = 0;
				for(i=0;i<3;i++){
					for(j=0;j<3;j++){
						if(face[i]==faces[j] && face[5-i]==faces[5-j]){
							check++;
							break;
						}
						/*else if(face[i]==faces[5-j] && face[5-i]==faces[j]){
							check++;
							break;
						}*/
					}
				}
				if(check == 3){
					return true;
				}
				else{
					return false;
				}
			}

		}
		Integer k;

		qube q = new qube();
		for(k=0;;k++){
			if(q.faces[1]==q.face[1]){
				break;
			}
			q.move("N");
			if(k.equals(3)){
				q.move("E");
			}
		}
		while(true){
			if(q.faces[0]==q.face[0]){
				break;
			}
			q.move("E");
		}
		if(q.comp() == true){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}

	}

}


Measured memory_bytes: 26436
#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
int main()
{
    long long n,m,i,j,k,s=0;
    cin>>n>>m;
    for(i=0;i<n-1;i++)
    {
        for(j=i+1;j<n;j++)
        {
            s++;
        }
    }
    for(i=0;i<m-1;i++)
    {
        for(j=i+1;j<m;j++)
        {
            s++;
        }
    }
    cout<<s<<endl;

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    AB = sorted(range(N), key=lambda x: A[x])

    s = 0
    for i in AB:
        if B[i] > M:
            s += M*A[i]
            break
        else:
            s += A[i]*B[i]
            M -= B[i]

    print(s)
    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int()] * (N)  # type: "List[int]"
    B = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, M, A, B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 16436
#include <stdio.h>

int main(void){
    int n,m,A[10000],x,i=0,sum=0,ans;

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

    x=m;

    while(x!=0){
        scanf(" %d",&A[i]);
        x--;
        i++;
    }

    for(i=0;i<m;i++){
        sum=sum+A[i];
    }

    ans=n-sum;

    if(ans>=0){
        printf("%d\n",ans);
    }else{
        printf("-1\n");
    }

    return 0;
}

Measured memory_bytes: 3236
#include<bits/stdc++.h>
#include<string>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;
int main()
{
    fastio;
    string str,a;
    cin>>str;
    int i,n= str.length();
    for (i=0;i<n;i++)
    {
        if (i%2==0)
            a.push_back(str[i]);
    }
    cout<<a<<endl;
}

Measured memory_bytes: 592
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

vector<pair<ll, ll>> prime_factorize(ll N) {
    vector<pair<ll, ll>> res;
    for (ll a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        ll ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}
template<typename T>
T factorial(T a){
  if(a == 2) return 2;
  return a * (factorial(a-1));
}

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    int now = 1;
    int broken = 0;
    for(int i = 0; i < N; i++){
        if(A[i] == now){
            now++;
        }else broken++;
    }
    if(now == 1) puts("-1");
    else cout << broken << endl;
}

Measured memory_bytes: 4052
char *R="yuiophjklnm",s[33];
#define z(i) (strchr(R,s[i])?0:1)
int main(i,l,r,x){
  for(;scanf("%s",s),*s-'#';printf("%d\n",r))
    for(x=z(0),l=strlen(s),i=1,r=0;i<l;i++)
      if(x!=z(i))r++,x^=1;
exit(0);}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define f first
#define s second
int a[114514];
signed main(){
	ic(n)
	rep(0,i,n)cin>>a[i];
	int ans=0;
	sort(a,a+n);
	rep(0,i,n){
		rep(i+1,j,n){
			rep(j+1,k,n){
				if(a[i]+a[j]>a[k]){
					ans++;
				}	
			}
		}
	}
	cout<<ans<<endl;
}				

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

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin >> n >> k;
    vvint mpb(k,vint(k,0));
    vvint mpw(k,vint(k,0));
    REP(i,n){
        ll x,y;
        char c;
        cin >> x >> y >> c;
        int z = 0;
        z += (x/k);
        z += (y/k);
        x %= k;
        y %= k;
        int t;
        if(c=='B'){
            t = 1;
        }else{
            t = -1;
        }
        if(z%2==1){
            t = 0-t;
        }
        if(t==1){
            mpb[x][y]++;
        }else{
            mpw[x][y]++;
        }
    }
    vvint dpb(k+1,vint(k+1,0));
    vvint dpw(k+1,vint(k+1,0));
    REP(i,k){
        REP(j,k-1){
            mpb[i][j+1] += mpb[i][j];
            mpw[i][j+1] += mpw[i][j];
        }
    }
    REP(i,k){
        REP(j,k){
            dpb[i+1][j+1] = dpb[i][j+1] + mpb[i][j]; 
            dpw[i+1][j+1] = dpw[i][j+1] + mpw[i][j]; 
        }
    }
    int ans = 0;
    REP(i,k+1){
        REP(j,k+1){
            {
                int cnt = 0;
                cnt += dpb[k][k];
                cnt -= dpb[k][j];
                cnt -= dpb[i][k];
                cnt += 2*dpb[i][j];
                cnt += dpw[k][j];
                cnt += dpw[i][k];
                cnt -= 2*dpw[i][j];
                ans = max(cnt,ans);
            }
            {
                int cnt = 0;
                cnt += dpw[k][k];
                cnt -= dpw[k][j];
                cnt -= dpw[i][k];
                cnt += 2*dpw[i][j];
                cnt += dpb[k][j];
                cnt += dpb[i][k];
                cnt -= 2*dpb[i][j];
                ans = max(cnt,ans);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 18984
import sys

input = sys.stdin.readline


def main():
    n = int(input())
    v_list = sorted([int(i) for i in input().split()])
    result = sum(v_list[:2]) / 2
    # 累積関数に(x+y/2)を渡すのがクールと思ったけど
    # 累積系関数の指定できるやつ忘れた
    for i in v_list[2:]:
        result = (result + i) / 2
    print(result)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include<iostream>

int main() {
	int person[4][3][10];
	int b, f, r, p,i,n;

	for (b = 0; b < 4; b++) {
		for (f = 0; f < 3; f++) {
			for (r = 0; r < 10; r++) {
				person[b][f][r] = 0;
			}
		}
	}

	std::cin >> n;
		
	for (i = 0; i < n; i++) {
		std::cin >>b>>f>>r>>p;
		person[b-1][f-1][r-1] += p;
	}

		for (b = 0; b < 4; b++) {
			for (f = 0; f < 3; f++) {
				for (r = 0; r < 10; r++) {
					std::cout << " " << person[b][f][r];
				}
				std::cout << std::endl;
			}
			if (b != 3) {
				std::cout << "####################" << std::endl;
			}
		}
		return 0;
}


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

int main() {
  int h,w;
  cin >> h >> w;
  
  string head = "##";
  for(int i = 0; i < w; i++)  head += "#";
  cout << head << endl;
  
  for(int i = 0; i < h; i++) {
    string str;
    cin >> str;
    cout << "#" <<  str << "#" << endl;
  }
  cout << head << endl;
}
  

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


int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> V(M);
  for (int i = 0; i < M; ++i) {
    cin >> V.at(i).second >> V.at(i).first;
  }
  sort(V.begin(), V.end());
  int cur = 0, result = 0;
  for (int i = 0; i < M; ++i) {
    if (V.at(i).second <= cur) {
      continue;
    } else {
      cur = V.at(i).first - 1;
      ++result;
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 1024
s = gets.chomp
N = s.length
(N-1).times do |i|
    if s[i] == s[i+1]
        puts [i+1, i+2].join(' ')
        exit
    elsif i < N-2 && s[i] == s[i+2]
        puts [i+1, i+3].join(' ')
        exit
    end
end
puts '-1 -1'

Measured memory_bytes: 1916
#include "bits/stdc++.h"
using namespace std;

int main()
{
	int h, w, k;
	cin >> h >> w >> k;
	vector<vector<char>> c(h, vector<char>(w));
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			cin >> c.at(i).at(j);
		}
	}

	int ans = 0;
	for (int i = pow(2, h) - 1; i >= 0; i--)
	{
		for (int j = pow(2, w) - 1; j >= 0; j--)
		{
			int cnt = 0;
			for (int m = 0; m < h; m++)
			{
				if (i & (1 << m))
				{
					for (int n = 0; n < w; n++)
					{
						if (j & (1 << n))
						{
							if (c.at(m).at(n) == '#')
							{
								cnt++;
							}

						}
					}
				}
			}
			if (cnt == k)
			{
				ans++;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4008
n=int(input())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
a=sorted(make_divisors(n))
b=len(make_divisors(n))
if b%2==1:
  m=(b-1)//2
  c=a[m]
  print(2*c-2)
else:
  c=a[((b-2)//2)]
  d=a[(b//2)]
  print(c+d-2)

Measured memory_bytes: 3552
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <numeric>
#include <utility>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <stack>
#include <functional>
#include <ctime>
#include <queue>
#include <string>
#include <map>
#include <utility>
#include <sstream>
#include <cmath>
#define MAX_U   10
#define MIN_U   0
#define rep(i,n) for(int i=0;i<n;i++)
#define pb push_back
#define form(i,a,b) for(int i=(a);i<(b);i++)
#define sz(x) ((int)(x).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<char> vc;
typedef vector<string> vs;
typedef queue<int> qi;
const int INF=numeric_limits<int>::infinity();
void printa(){cout<<"\n";}
template<class T, class... A>void printa(const T&first,const A&... rest){cout<<first;printa(rest...);}
template<class... A>void printa(const A&... rest){printa(rest...);}
void prints(){cout<<" ";}
template<class T, class... A>void prints(const T&first,const A&... rest){cout<<first;prints(rest...);}
template<class... A>void prints(const A&... rest){prints(rest...);}
int factorial(int x){int f=1;for(int i=1;i<x+1;i++)f=f*i;return f;}
int sigma(int x){int s;for(int i=1;i<x+1;i++)s=s+i;return s;}
int middle(int x){if(x%2==0)return x/2;else return x/2+1;}
double heron(int a,int b,int c){double s;s=(a+b+c)/2;return sqrt(s*(s-a)*(s-b)*(s-c));}
double trapezium(int a,int b,int h){return (a+b)*h/2;}
double triangle(int a,int h){return a*h/2;}
void sorm(vector<int> vec){sort(vec.begin(),vec.end());}
void sorg(vector<int> vec){sort(vec.begin(),vec.end(),greater<int>());}
int cmp( const void *p, const void *q ) {if( *(double*)p > *(double*)q ) return 1;if( *(double*)p < *(double*)q ) return -1;return 0;}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //int a,b,c,d;
    int f=0;
    string st,tt,nt;
    //vi ad,bd,cd,dd;
    //vs as,bs,cs,ds;
    cin>>st;
    if(st[0]!='C')f++;
    if(st[1]!='O')f++;
    if(st[2]!='D')f++;
    if(st[3]!='E')f++;
    if(st[4]!='F')f++;
    if(st[5]!='E')f++;
    if(st[6]!='S')f++;
    if(st[7]!='T')f++;
    if(st[8]!='I')f++;
    if(st[9]!='V')f++;
    if(st[10]!='A')f++;
    if(st[11]!='L')f++;
    if(st[12]!='2')f++;
    if(st[13]!='0')f++;
    if(st[14]!='1')f++;
    if(st[15]!='6')f++;
    printa(f);
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define lowbit(x) (x&(-x))
using namespace std;
const int N=200010,mod=998244353;
int n,tr[N],ans;
struct P{
	int x,y,rk,A,B,C,D;
}a[N];
bool cmp1(P a,P b){
	return a.x<b.x;
}
bool cmp2(P a,P b){
	return a.y<b.y;
}
int qpow(int x,int n){
	int ret=1;
	while(n){
		if(n&1)
			ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;
		n>>=1;
	}
	return ret;
}
int query(int x){
	int ret=0;
	while(x){
		ret+=tr[x];
		x-=lowbit(x);
	}
	return ret;
}
void insert(int x,int v){
	int ret=0;
	while(x<=n){
		tr[x]+=v;
		x+=lowbit(x);
	}
	return;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&a[i].x,&a[i].y);
	sort(a+1,a+n+1,cmp1);
	for(int i=1;i<=n;i++)
		a[i].rk=i;
	sort(a+1,a+n+1,cmp2);
	for(int i=n;i>=1;i--){
		a[i].A=query(a[i].rk),a[i].B=query(n)-a[i].A;
		insert(a[i].rk,1);
	}
	memset(tr,0,sizeof(tr));
	for(int i=1;i<=n;i++){
		a[i].C=query(a[i].rk),a[i].D=query(n)-a[i].C;
		ans=(ans+qpow(2,n-1)+1ll*qpow(2,a[i].A+a[i].D)*(qpow(2,a[i].B)-1)%mod*(qpow(2,a[i].C)-1)+1ll*qpow(2,a[i].B+a[i].C)*(qpow(2,a[i].A)-1)%mod*(qpow(2,a[i].D)-1)-1ll*(qpow(2,a[i].A)-1)%mod*(qpow(2,a[i].B)-1)%mod*(qpow(2,a[i].C)-1)%mod*(qpow(2,a[i].D)-1))%mod;
		insert(a[i].rk,1);
	}
	printf("%d",(ans+mod)%mod);
	return 0;
}

Measured memory_bytes: 6400
N=int(input())
S=input()
A=[0]*N
A[0]=S[1:].count('E')
for i in range(1,N):
    if S[i-1]=='W':
        A[i]=A[i-1]+1
    else:
        A[i]=A[i-1]
    if S[i]=='E':
        A[i]-=1
print(min(A))

Measured memory_bytes: 15436
import java.io.{BufferedReader, InputStream, InputStreamReader, PrintWriter}
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}
import scala.collection.mutable.{ArrayBuffer, ListBuffer}

object Main {
  val MOD = 1000000007
  val out = new PrintWriter(System.out)
  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N, K = sc.nextInt()
    val A = Array.fill[Int](N)(sc.nextInt())
    val ans = ((N - 1) - 1) / (K - 1) + 1
    out.println(ans)
  }


  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = null

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next.toInt
    def nextLong(): Long = next.toLong
    def nextChar(): Char = next.charAt(0)
  }

  private def rep(n: Int)(f: Int => Unit): Unit = {
    (0 until n) foreach f
  }

  private def map[@specialized(Int, Long) A](n: Int)(f: Int => A): Seq[A] = {
    (0 until n) map f
  }
}


Measured memory_bytes: 36720
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
    int a,b;
    char op;
    while(true){
        cin >> a >> op >> b;
        fflush(stdin);
        if (op =='?') return 0;
        else if (op =='+') cout << a+b << endl;
        else if (op =='-') cout << a-b << endl;
        else if (op =='/') cout << a/b << endl;
        else if (op =='*') cout << a*b << endl;
    }
}

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

int main(){
  int n,m,x;
  cin >> n >> m >> x;
  int a[m];
  rep(i,m) cin >> a[i];
  
  int left = upper_bound(a,a+m,x) - a;
  int right = m - left;
  
  if(left<right) cout << left << endl;
  else cout << right << endl;

  return 0;
}


Measured memory_bytes: 256
n,p=map(int,input().split())
s=list(input())

if p==2 or p==5:
    ans=0
    for i in range(n):
        if int(s[n-i-1])%p==0:
            ans+=n-i-1+1

    print(ans)
    exit()


mods=[0]*p
mods[0]=1
num=0
fac=1

for i in range(n):
    num+=(int(s[n-i-1])*fac)
    num%=p

    fac=(fac*10)
    fac%=p
    mods[num]+=1

#print(mods)
ans=0
for item in mods:
    ans+=(item*(item-1))//2

#print(len(s))
#print(mods)
print(ans)





Measured memory_bytes: 62164
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; ++i)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define PB push_back
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define NCLR(a) memset((a), -1 ,sizeof(a))
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
typedef complex<double> Point;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 29;
static const LL LL_INF = 1ll << 60;
static const int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
static const int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 };

#ifdef WIN32
#define dump(x) cerr << #x << " = " << (x) << "\n"
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n"
#else
#define dump(x)
#define debug(x)
#endif

int n;
VI h;

void input() {
  cin >> n;
  h.resize( n + 1 );
  for ( int i = 0; i <= n && n; i++ ) {
    cin >> h[ i ];
  }
}

bool check( int elnum ) {
  int d;
  if ( !elnum ) {
    d = h[ 2 ] - h[ 1 ];
  }
  else if ( elnum == 1 ) {
    d = h[ 2 ] - h[ 0 ];
  }
  else {
    d = h[ 1 ] - h[ 0 ];
  }
  for ( int i = 2; i <= n; i++ ) {
    if ( elnum == i ) {
      continue;
    }
    if ( elnum == i - 1 ) {
      if ( d != h[ i ] - h[ i - 2 ] ) {
        return false;
      }
    }
    else {
      if ( d != h[ i ] - h[ i - 1 ] ) {
        return false;
      }
    }
  }
  return true;
}

void solve() {
  for ( int i = 0; i <= n; i++ ) {
    if ( check( i ) ) {
      cout << h[ i ] << "\n";
      return;
    }
  }
}

int main() {
  ios::sync_with_stdio( false );
  cin.tie( 0 );
  while ( true ) {
    input();
    if ( !n ) {
      break;
    }
#ifdef WIN32
    clock_t stime = clock();
#endif
    solve();
#ifdef WIN32
    clock_t etime = clock();
    cerr << "TIME : " << ( double ) ( etime - stime ) / CLOCKS_PER_SEC << "\n";
#endif
  }
return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define mod 1000000007
#define MOD 998244353
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
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;
}
int D;
int C[500];
int S[500][500];
vector<int>Ans;
int scoring(int day,int t){
    int score=0;
    Ans.push_back(t);
    score+=S[day][t];
    rep(j,26){
        int now=0;
        for(int k=1;k<=day;k++){
            if(Ans[k]==j)chmax(now,k);
        }
        score-=C[j]*(day-now);
    }
    Ans.pop_back();
    return score;
}
signed main() {
    cin>>D;
    rep(i,26)cin>>C[i];
    rep(i,D){
        rep(j,26)cin>>S[i+1][j];
    }
    vector<int>Ans;
    int s=0;
    Ans.push_back(-1);
    for(int now=1;now<=D;now++){
        int S=-INF;
        rep(j,26){
            S=max(S,scoring(now,j));
        }
        rep(j,26){
            if(S==scoring(now,j)){
                s+=S;
                Ans.push_back(j);
                break;
            }
        }
    }
    //cout<<s<<endl;
    for(int i=1;i<=D;i++)cout<<Ans[i]+1<<endl;
}



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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

class Prints {
private:
    class __Prints {
    public:
        __Prints(const char* sep, const char* term) : sep(sep), term(term) {}
        template <class... Args>
        void operator()(Args&&... args) const { print(std::forward<Args>(args)...); }

    private:
        const char *sep, *term;
        void print() const { std::cout << term; }
        void print_rest() const { std::cout << term; }
        template <class T, class... Tail>
        void print(T&& head, Tail&&... tail) const { std::cout << head, print_rest(std::forward<Tail>(tail)...); }
        template <class T, class... Tail>
        void print_rest(T&& head, Tail&&... tail) const { std::cout << sep << head, print_rest(std::forward<Tail>(tail)...); }
    };

public:
    Prints() {}
    __Prints operator()(const char* sep = " ", const char* term = "\n") const { return __Prints(sep, term); }
    template <class T>
    void print_vec(const std::vector<T>& vec, const char* sep = " ", const char* term = "\n") const {
        const size_t sz = vec.size();
        for (size_t i = 0; i < sz; i++) std::cout << vec[i] << (i == sz - 1 ? term : sep);
    }
};

Prints prints;

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    string S;
    cin >> S;
    ll ans = 0;
    bool is_g = true;
    for (auto c : S) {
        if (is_g) {
            if (c == 'p') {
                ans -= 1;
            }
        }
        else {
            if (c == 'g') {
                ans += 1;
            }
        }
        is_g ^= true;
    }
    prints()(ans);
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    cout << setprecision(18) << fixed;
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 3784
#include <algorithm>
#include <array>
#include <assert.h>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
typedef long long ll;
typedef long double ld;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<ld>> vvd;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const ll MOD = 998244353;

ll binpow(ll a, ll n) {
    ll res = 1;
    while (n) {
        if (n & 1) { res *= a; res %= MOD; }
        a *= a;
        a %= MOD;
        n >>= 1;
    }
    return res % MOD;
}

ll inv(ll x) { return binpow(x, MOD - 2); }

void add(ll& x, ll y) { x += y; if (x >= MOD) x -= MOD; }
void take(ll& x, ll y) { x -= y; if (x < 0) x += MOD; }

ll sum(ll a, ll b) { add(a, b); return a; }
ll sub(ll a, ll b) { take(a, b); return a; }
ll mul(ll x, ll y) { return (x * y) % MOD; }
ll rat(ll x, ll y) { assert(y); return mul(x, inv(y)); }

ll fact(ll a) {
    ll ans = 1;
    for (ll i = 2; i <= a; ++i) {
        ans *= i;
        ans %= MOD;
    }
    ans %= MOD;
    return ans;
}

const ll MAXN = 1e5 + 228;
ll ans = 1;
ll kek[3];
ll lol[3];

void foo(ll x) {
    ans = mul(ans, x);
}

const string CHARS = "RGB";
int ch2i(char ch) {
    return (int)CHARS.find(ch);
}

int other(int i, int j) {
    for (int k = 0; k < 3; ++k) {
        if (k != i && k != j) return k;
    }
    assert(false);
}

int main() {
    cout << setprecision(30);
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    ll n;
    string s;
    cin >> n >> s;

    for (int i = 0; i < 3 * n; ++i) {
        ll idx = ch2i(s[i]);
        if (lol[idx]) {
            foo(lol[idx]--);
            continue;
        }
        bool bad = true;
        for (int j = 0; j < 3; ++j) {
            if (j == idx) continue;
            if (!kek[j]) continue;
            bad = false;
            foo(kek[j]--);
            ++lol[other(idx, j)];
            break;
        }
        if (bad) {
            ++kek[idx];
        }
    }

    foo(fact(n));

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 720
def root(x,par):
    if x == par[x]:
        return x
    else:
        par[x] = root(par[x],par)
        return par[x]
 
def unite(x,y,par):
    x = root(x,par)
    y = root(y,par)
    if x==y:
        if x==0 and y==1:
            return
    else:
        par[x]=y

n,k,l = map(int,input().split())
road =[i for i in range(n)]
train = [i for i in range(n)]
ans =0
for _ in range(k):
    p,q = map(int,input().split())
    unite(p-1,q-1,road)
for _ in range(l):
    p,q = map(int,input().split())
    unite(p-1,q-1,train)

for i in range(n):
    root(i,train)
for i in range(n):
    root(i,road)

dual = [(i,j) for i,j in zip(road,train)]
ans ={}
for i in dual:
    if i in ans:
        ans[i] +=1
    else:
        ans[i] =1
for i in dual:
    print(ans[i],end=" ")
    


Measured memory_bytes: 50072
import java.util.Scanner;

public class Main{
	public static void main(String [] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int b,f,r,v;
		int house[][][] = new int[4][3][10];
		for(int i = 0; i < n; i++){
			b = sc.nextInt();
			f = sc.nextInt();
			r = sc.nextInt();
			v = sc.nextInt();
			house[b-1][f-1][r-1] += v;
		}
		for(int i = 0; i < 4; i++){
			for(int j = 0; j < 3; j++){
				for(int k = 0; k < 10; k++){
					System.out.print(" " + house[i][j][k]);
					if(k == 10 - 1){
						System.out.println("");
					}
				}
			}
			if(i != 3){
				System.out.println("####################");
			}
		}
	}
}

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

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (int &ai: a) cin >> ai;
    int q; cin >> q;
    while (q--) {
        int b, e, k; cin >> b >> e >> k;
        cout << count(a.begin() + b, a.begin() + e, k) << endl;
    }
    return 0;
}


Measured memory_bytes: 3088
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define ff first
#define ss second
#define setbits(x) __builtin_popcount(x)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define in insert
#define pb push_back
#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define endl "\n"
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

inline ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
inline ll power(ll a, ll n, ll m)
{
    if (n == 0)
        return 1;
    ll p = power(a, n / 2, m);
    p = (p * p) % m;
    if (n % 2)
        return (p * a) % m;
    else
        return p;
}
const ll MOD = 1000000007;
const int N = int(3e5) + 999;
#define int long long int

int32_t main(){
    IOS;

    int k;
    cin>>k;
    string s;
    cin>>s;

    for(int i=0;i<s.size();i++){
    	int num = s[i]-'A';
    	s[i] = (num+k)%26+'A';
    }

    cout<<s;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
     
    public class Main {
    	public static void main (String[] args) {
    		Scanner sc = new Scanner(System.in);
    		
    		int A = sc.nextInt();
    		int B = sc.nextInt();
    		
    		if (A <= 8 && B <= 8) {
    			System.out.println("Yay!");
    		} else {
    			System.out.println(":(");
    		}
    		
    	}
    }

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

#define REP(i,n) for(int i=0;i<int(n);i++)
#define ALL(v) (v).begin(),(v).end()

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

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}	 

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const int N_MAX=200020;

int main(){
	string s;
	cin>>s;
	int k;
	cin>>k;
	int n=s.size();
	vector<string> vs;
	for(int i=1;i<=k;i++){
		for(int j=0;j<n;j++){
			if(j+i-1>=n)continue;
			string t=s.substr(j,i);
			vs.push_back(t);
		}
	}
	sort(vs.begin(),vs.end());
	k--;
	for(int i=0;i<int(vs.size());i++){
		//cout<<vs[i]<<endl;
		if(k==0){
			cout<<vs[i]<<endl;
			return 0;
		}
		if(vs[i]!=vs[i+1]){
			k--;
		}
	}
}


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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

//===

// const ll mod = static_cast<int>(1e9 + 7);



int main() {
	int A, B, Q;
	cin >> A >> B >> Q;

	Vl s(A), t(B), x(Q);
	for (int i = 0; i < A; ++i) {
		cin >> s[i];
	}
	for (int i = 0; i < B; ++i) {
		cin >> t[i];
	}
	for (int i = 0; i < Q; ++i) {
		cin >> x[i];
	}

	for (int i = 0; i < Q; ++i) {
		ll ans = 2002002002002002002L;

		Vl::iterator sr_it, sl_it, tr_it, tl_it;
		sr_it = upper_bound(s.begin(), s.end(), x[i]);
	
		if (sr_it == s.begin()) {
			sl_it = sr_it;
		}
		else if (sr_it == s.end()) {
			--sr_it;
			sl_it = sr_it;
		}
		else {
			sl_it = sr_it - 1;
		}
		
		tr_it = upper_bound(t.begin(), t.end(), x[i]);

		if (tr_it == t.begin()) {
			tl_it = tr_it;
		}
		else if (tr_it == t.end()) {
			--tr_it;
			tl_it = tr_it;
		}
		else {
			tl_it = tr_it - 1;
		}

		ll dist;

		dist = abs(x[i] - *sr_it) + abs(*sr_it - *tr_it);
		ans = min(ans, dist);
		dist = abs(x[i] - *sr_it) + abs(*sr_it - *tl_it);
		ans = min(ans, dist);
		dist = abs(x[i] - *sl_it) + abs(*sl_it - *tr_it);
		ans = min(ans, dist);
		dist = abs(x[i] - *sl_it) + abs(*sl_it - *tl_it);
		ans = min(ans, dist);

		dist = abs(x[i] - *tr_it) + abs(*tr_it - *sr_it);
		ans = min(ans, dist);
		dist = abs(x[i] - *tr_it) + abs(*tr_it - *sl_it);
		ans = min(ans, dist);
		dist = abs(x[i] - *tl_it) + abs(*tl_it - *sr_it);
		ans = min(ans, dist);
		dist = abs(x[i] - *tl_it) + abs(*tl_it - *sl_it);
		ans = min(ans, dist);

		cout << ans << endl;
	}
 }


Measured memory_bytes: 3712
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <list>
using namespace std;

int main(){

    int n, m;
    cin >> n >> m;

    vector<pair<long long, long long>> ab(n);
    for(int i=0; i<n; i++){
        cin >> ab[i].first >> ab[i].second;
    }

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

    long long asum = 0;
    long long bsum = 0;
    for(int i=0; i<n; i++){
        if(bsum + ab[i].second <= m){
            bsum += ab[i].second;
            asum += ab[i].first * ab[i].second;
            if(bsum == m){
                break;
            }
        }
        else{
            asum += ab[i].first * (m - bsum);
            break;
        }
    }

    cout << asum;
    
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <iostream>
using namespace std;

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

	if ( (a == b && a != c) || (b == c && b != a) || (c == a && c != b) ) cout << "Yes" << endl;

	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
while True :
    x,y=input().split()
    x=int(x)
    y=int(y)
    if x==y==0 : break
    a=[]
    c=0
    for i in range(x) :
        b=input()
        a.append(int(b))
    for i in range(y) : 
        c=c+a[i]
        ans=c
    for i in range(y,x) :
        c=c+a[i]-a[i-y]
        ans=max(ans,c)
    print(ans)


Measured memory_bytes: 9612
import sys
input=sys.stdin.readline
N,M,S,T=map(int,input().split())
S-=1
T-=1
from collections import defaultdict
branch=defaultdict(dict)
for i in range(M):
    u,v,a,b=map(int,input().split())
    u-=1
    v-=1
    branch[u][v]=(a,b)
    branch[v][u]=(a,b)
def dijk(s,x):
    dist=[float('inf')]*N
    dist[s]=0
    check={s}
    while len(check)>0:
        now=check.pop()
        for nex,d in branch[now].items():
            if dist[now]+d[x]<dist[nex]:
                check|={nex}
                dist[nex]=dist[now]+d[x]
    return dist
en=dijk(S,0)
snuuk=dijk(T,1)
ans=[0]*N
ans[N-1]=en[N-1]+snuuk[N-1]
for i in range(N-2,-1,-1):
    ans[i]=min(ans[i+1],en[i]+snuuk[i])
for i in range(N):
    print(10**15-ans[i])

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

using namespace std;

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

    long int a,v,b,w,t,d_a,d_b;
    cin>>a>>v>>b>>w>>t;

    if(v<=w){
        cout<<"NO\n";
    }
    else{
        d_a = v*t;
        d_b = w*t;

        if(d_a>=(d_b+abs(a-b))){
            cout<<"YES\n";
        }
        else{
            cout<<"NO\n";
        }
        //cout<<d_a<<" "<<d_b;
    }


    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define fore(x,a,b) for(int x=a, qwert=b; x<qwert; x++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) ((int)(a).size())
#define FIN ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define fst first
#define snd second
using namespace std;
typedef long long ll;

const int N=101;
int n;
int dp[2][N], A[2][N];

int solve(int i, int j){
	if(j==n)return 0;
	int &r=dp[i][j];
	if(r!=-1)return r;
	r=A[i][j];
	if(i==1)return r+=solve(i,j+1);
	return r+=max(solve(i+1,j),solve(i,j+1));
}

int main(){memset(dp,-1,sizeof(dp));
	cin >> n;
	fore(x,0,2)fore(y,0,n)cin>>A[x][y];
	cout << solve(0,0) << "\n";	
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <cctype>

using namespace std;

int main(){
	int T;
	cin >> T;
	while(T--){
		string a, b;
		cin >> a >> b;
		for(int i = a.size() - 1; i >= 0; --i){
			if(a[i] == 'J'){
				b = b.substr(b.size() - 1) + b.substr(0, b.size() - 1);
			}else if(a[i] == 'C'){
				b = b.substr(1) + b.substr(0, 1);
			}else if(a[i] == 'E'){
				int half = b.size() / 2;
				for(int j = 0; j < half; ++j){
					swap(b[j], b[b.size() - half + j]);
				}
			}else if(a[i] == 'A'){
				reverse(b.begin(), b.end());
			}else if(a[i] == 'P'){
				for(int j = 0; j < b.size(); ++j){
					if(!isdigit(b[j])){ continue; }
					b[j] = (b[j] == '0' ? '9' : (b[j] - 1));
				}
			}else if(a[i] == 'M'){
				for(int j = 0; j < b.size(); ++j){
					if(!isdigit(b[j])){ continue; }
					b[j] = (b[j] == '9' ? '0' : (b[j] + 1));
				}
			}
		}
		cout << b << endl;
	}
	return 0;
}

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

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

  int x =  floor(n / 1.08);
  
  bool yes = false;
  int ans = 0;
  for(int i=x;i<x+10;i++) {
    if(floor(i * 1.08) == n) {
      yes = true;
      ans = i;
    }
  }

  if(yes) {
    cout << ans << endl;    
  } else {
    cout << ":(" << endl;
  }
}

Measured memory_bytes: 256
S = input()

ans = "Yes"
for i, s in enumerate(S):
    if (i+1) %2 == 1:
        if s == 'R' or s == 'U' or s == 'D':
            pass
        else:
            ans = 'No'
            #print(i, s, ans)
            break
    else:
        if s == 'L' or s == 'U' or s == 'D':
            pass
        else:
            ans = 'No'

            break
print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 1000000000;
const long INF64 = 1000000000000000ll;
const int MOD = 1000000007;

int main(){
	double n,y;
	
	std::cin >> n>>y;
  for (int i = 0; i <= n; i++) {
  	/* code */
  	double j=y/4000-n/4-9.0*i/4;
  	double k=-y/4000+n*5/4+5.0*i/4;
  	if(j<=-0.1||k<=-0.1||j-int(j)>0.2||k-int(k)>0.2)continue;
  	else{
  		std::cout << i<< ' '<< round(j)<<' ' <<round(k)<< std::endl;
  		exit(0);
  	}
  }
  std::cout <<-1 << ' '<<-1<< ' ' <<-1 << std::endl;
}

Measured memory_bytes: 256
inList = input().split()
stack = []
for i in inList:
    if i in ['+', '-', '*']:
        b, a = stack.pop(), stack.pop()
        if i == '+':
            stack.append(b + a)
        if i == '-':
            stack.append(a - b)
        if i == '*':
            stack.append(b * a)
    else:
        stack.append(int(i))
print(stack.pop())

Measured memory_bytes: 7720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define endl '\n'
#define all(x) (x).begin(),(x).end()
const int INF=500+5;
const int N=4000+5;
const ll oo=1e18+5;
const ll mod=998244353;

int t;
ll n;
int a,b,c,d;
map<ll,ll> maps;
vector<int> muls={2,3,5};

void min_self(ll& a,ll b){
	if(a>b) a=b;
}

ll calc(ll goal){
	if(!goal) return 0;
	if(goal==1) return d;
	if(maps.count(goal)) return maps[goal];
	ll minn=oo;
	if(d<oo/goal){
		min_self(minn,d*goal);
	}
	for(int i=0;i<3;++i){
		int mul=muls[i];
		ll cost=vector<ll>{a,b,c}[i];
		if(goal%mul==0){
			min_self(minn,cost+calc(goal/mul));
		}
		else{
			ll low=goal/mul*mul;
			min_self(minn,cost+d*(goal-low)+calc(goal/mul));
			ll high=low+mul;
			min_self(minn,cost+d*(high-goal)+calc(goal/mul+1));
		}
	}
	return maps[goal]=minn;
}

void solve(){
	cin>>n>>a>>b>>c>>d;
	cout<<calc(n)<<endl;
	maps.clear();
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 4408
N, M = map(int, input().split())
H  = list(map(int, input().split()))
ans_pin = [1] * N
for i in range(M):
  A, B = map(int, input().split())
  if H[A -1] < H[B-1] :
    ans_pin[A-1] = 0
  elif H[A -1] > H[B-1]:
    ans_pin[B-1] = 0
  else:
    ans_pin[A-1] = 0
    ans_pin[B-1] = 0
print(sum(ans_pin))

Measured memory_bytes: 20040
import numpy as np
import sys
read = sys.stdin.read


D = int(input())
CS = np.array(read().split(), np.int32)
C = CS[:26]
S = CS[26:].reshape((-1, 26))
del CS

last = np.zeros((26, ))
ans = []

def getContestType_at_d(d):
    s = -10000000
    for i in range(26):
        mask = np.ones((26, ))
        mask[i] = 0
        tmp = S[d][i] - np.sum(C * (d + 1 - last) * mask)
        if s < tmp:
            s = tmp
            t = i

    last[t] = d + 1

    return t + 1, s


for d in range(D):
    s = -10000000
    for i in range(26):
        mask = np.ones((26, ))
        mask[i] = 1
        score = S[d][i] - np.sum(C * (d + 1 - last) * mask)
        if s < score:
            s = score
            t = i

    last[t] = d + 1
    ans.append(t + 1)


print('\n'.join(map(str, ans)))

Measured memory_bytes: 27712
#include <cstdio>
#include <vector>
using namespace std;
int tax(int tr, int p){
  int a;
  a = (100 + tr) * p / 100;
  return a;
}

int X, Y, S;

int solve(){
  int MAX = 0;
  for(int i = 1; i < S; i++){
    for(int j = i; j < S; j++){
      if(tax(X, i) + tax(X, j) == S)
	MAX = max(MAX, tax(Y, i) + tax(Y, j));
    }
  }
  return MAX;
}

int main(){
  while(scanf("%d %d %d", &X, &Y, &S) && X > 0){
    printf("%d\n", solve());
  }
}

Measured memory_bytes: 1028
#include "bits/stdc++.h"
#include <unordered_set>

#define _CRT_SECURE_NO_WARNINGS

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP3(i, x, n) for(decltype(x) i = (x); i <= (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1; i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

const int INF = 1000000000;
const double PI = 3.1415926535897932384626433832795;

// N, E, S, W
const int dx[4] = { 1, 0, -1, 0};
const int dy[4] = { 0, 1, 0, -1};

using LL = long long int;
using LD = long double;
using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vl = vector<LL>;
using vd = vector<double>;
using vs = vector<string>;
using vvi = vector<vi>;

//==============================================
int n;
vi color, D, P;
vvi M;

int solve() {
	D[0] = 0;

	int u, minV;
	while (true) {
		u = -1;
		minV = INF;
		REP(i, n) {
			if (color[i] != 2 && D[i] < minV) {
				u = i;
				minV = D[i];
			}
		}

		if (u == -1) break;
		color[u] = 2;

		REP(i, n) {
			if (color[i] != 2 && M[u][i] != INF && D[i] > M[u][i]) {
				D[i] = M[u][i];
				P[i] = u;
				color[i] == 1;
			}
		}
	}

	int sum = 0;
	REP(i, n) {
		if (P[i] != -1) {
			sum += M[i][P[i]];
		}
	}

	return sum;
}

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

	cin >> n;

	color.resize(n);
	D.resize(n, INF);
	P.resize(n, -1);
	M.resize(n, vi(n, INF));

	int edge;
	REP(i, n) {
		REP(j, n) {
			cin >> edge;
			M[i][j] = (edge == -1 ? INF : edge);
		}
	}

	cout << solve() << "\n";
	return 0;
}

Measured memory_bytes: 3228
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();
        long Hz[] = new long[N];
        long sortedHz[] = new long[N];
        for (int i = 0; i < N; i++){
            Hz[i] = sc.nextInt();
        }
        Arrays.sort(Hz);
        for (int i = 0; i < N; i++) {
            sortedHz[N - i - 1] = Hz[i];
//            System.out.println(sortedHz[N - i - 1]);
        }

        long sum = 0;
        for (int i = 0; i < N; i++) {
            if (i <= K - 1){
                continue;
            }

            sum += sortedHz[i];
        }
        System.out.println(sum);
    }
}



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

int main() {
 int x,y;
    cin >> x >> y;
    
    bool result = false;
  
    rep(i,x + 1) {
     int j = x - i;
      int total = 2 * i + 4 * j;
         if(total == y) {
         result = true;
         }
    }
     if(result) {
     cout << "Yes";
     }
    else {
    cout << "No";
    }
}


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

int main(){
	int a,b,c;
	int temp;
	cin>>a>>b>>c;
	if(a>b){
		temp=a;
		a=b;
		b=temp;
	}
	if(b>c){
		temp=b;
		b=c;
		c=temp;
	}
	if(a>b){
		temp=a;
		a=b;
		b=temp;
	}
	cout<<a<<" "<<b<<" "<<c<<endl;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

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

    char b;
    cin >> b;
    if(b=='A')cout << 'T' <<endl;
    else if(b == 'T')cout << 'A' <<endl;
    else if(b == 'C')cout << 'G' <<endl;
    else cout << 'C' <<endl;
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define repr(i,x,n) for(int i=x; i<(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define INF 1e9
typedef long long ll;
using VI = vector<int>;
using VB = vector<bool>;
using VS = vector<string>;
using graph = vector<vector<int>>;

int main()
{
 int R,G,B,k,cnt=0;
 cin>>R>>G>>B>>k;
while (R>=G)
{
    cnt++;
    G*=2;
}
while (G>=B)
{
    cnt++;
    B*=2;
}
if (cnt<=k)
{
    cout<<"Yes"<<endl;
}
else cout<<"No"<<endl;


    return 0;
}

Measured memory_bytes: 3648
n = int(input())
x = list(map(int, input().split()))
pdlist = []
for i in range(max(x) + 1):
  p = i
  dlist = []
  for j in x:
    dlist.append(int((int(j) - int(p)) ** 2))
  sumd = sum(dlist)
  pdlist.append(sumd)
minpdlist = min(pdlist)
print(minpdlist)

Measured memory_bytes: 3060
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<iomanip>
using namespace std;

int main(){
	long a, b, r, g, l, x, y;

	while(1){
		cin >> a >> b;

		if(cin.eof()){
			break;
		}

		x = a;
		y = b;
		
		if(x < y){
			swap(x, y);
		}

		while(y > 0){
			r = x % y;
			x = y;
			y = r;
		}

		g = x;
		l = (a / g) * b;

		cout << g << " ";
		cout << l << endl;
	}

	return 0;
}

Measured memory_bytes: 3092
#include <stdio.h>
#define MAX 100000
int A[MAX], n;

int partition(int p, int r){
  int x,i,j,t;
  x = A[r];
  i = p - 1;
  for(j=p;j<r;j++){
    if(A[j] <= x){
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }
  t = A[i+1];
  A[i+1] = A[r];
  A[r] = t;
  
  return i+1;
}



int main(){
  int i, q;
  scanf("%d", &n);
  for(i=0;i<n;i++) scanf("%d", &A[i]);
  
  q = partition(0, n-1);
  
  for(i=0;i<n;i++){
    if(i)printf(" ");
    if(i == q)printf("[");
    printf("%d", A[i]);
    if(i == q)printf("]");
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 2112