akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
//#define int long long
using namespace std;
signed main()
{
	int n;
	cin>>n;
	int a[n],b[n],c[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i]>>b[i]>>c[i];
	}
	int ans=0;
	int r[n][3];
	r[0][0]=a[0];
	r[0][1]=b[0];
	r[0][2]=c[0];
	for(int i=1; i<n; i++)
	{
		r[i][0]=a[i]+max(r[i-1][1],r[i-1][2]);
		r[i][1]=b[i]+max(r[i-1][0],r[i-1][2]);
		r[i][2]=c[i]+max(r[i-1][1],r[i-1][0]);	
	}
	cout<<max(r[n-1][0],max(r[n-1][1],r[n-1][2]));
}

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

#define gc( ) std::getchar( )
#define pc( i ) std::putchar( i )
#define space ' '
#define enter '\n'
#define RE cout << "Passing [" << __FUNCTION__ << "] on " << __LINE__ << enter
#define DEBUG(...) for( auto &i: __VA_ARGS__ ) cout << i << " "; cout << enter
using std::make_pair;

template < typename T >
inline T read( )
{
 T x = 0;
 char ch = gc( );
 bool f = 0;
 while( !std::isdigit( ch ) )
 {
  f = ( ch == '-' );
  ch = gc( );
 }
 while( std::isdigit( ch ) )
 {
  x = x * 10 + ( ch - '0' );
  ch = gc( );
 }
 return f ? -x : x;
}

template < typename T >
void print( T x )
{
 if( x < 0 )
 {
  x = -x;
  pc( '-' );
 }
 if( x < 10 )
 {
  pc( x + 48 );
  return;
 }
 print < T > ( x / 10 );
 pc( x % 10 + 48 );
 return ;
}

namespace Solution
{
#define IOS std::ios::sync_with_stdio( false ), std::cin.tie( 0 ), std::cout.tie( 0 )
#define Rep( i, j, k ) for( int i = j; i >= k; --i )
#define rdi( ) read < int > ( )
#define rdl( ) read < long long > ( )
#define pti( i ) print < int > ( i ), putchar( space )
#define ptl( i ) print < long long > ( i ), putchar( space )
#define For( i, j, k ) for( int i = j; i <= k; ++i )
 using std::cin;
 using std::cout;
 using std::endl;
 using std::vector;
 using std::map;
 using std::queue;
 using std::deque;
 using std::set;
 using std::pair;
 const int N = 204001, mod = 1e9 + 7;
 int x;
 void Fakemain( )
 {
  cin >> x;
  cout << ( x ^ 1 );
  return;
 }

} // namespace Solution

int main( int argc, char* argv[] )
{
 Solution::Fakemain( );
 return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}

int main(){
  string s,a; cin>>s>>a;
  s = s+s;
  if(s.find(a)==string::npos){ cout <<"No\n";}
  else{ cout <<"Yes\n";}
}


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

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

int main() {
  int n,a,b;
  int ans;
  cin >> n>>a>>b;
  cout << (n*a<b?n*a:b) << endl;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;


int main(){
    int n; cin>>n;
    if(n%10==2||n%10==4||n%10==5||n%10==7||n%10==9){
        cout<<"hon"<<endl;
    }
    else if(n%10==0||n%10==1||n%10==6||n%10==8){
        cout<<"pon"<<endl;
    }
    else cout<<"bon"<<endl;
}








Measured memory_bytes: 3600
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		long t = sc.nextLong();
		int q = sc.nextInt();
		
		long[] a = new long[n];
		boolean[] d = new boolean[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextLong();
			d[i] = (sc.nextInt() == 1);
		}
		
		for(int i = 0; i < q; i++) {
			int x = sc.nextInt() - 1;
			if(d[x]) {
				int y = -1;
				for(int j = x + 1; j < n; j++) {
					if(!d[j]) {
						y = j;
						break;
					}
				}
				
				if(y == -1) {
					System.out.println(a[x] + t);
				}else {
					int z = -1;
					if(y - x > 1) {
						z = y - 1;
					}
					
					if(z == -1) {
						if(t * 2 <= a[y] - a[x]) {
							System.out.println(a[x] + t);
						}else {
							System.out.println((a[x] + a[y]) / 2);
						}
					}else {
						if(t * 2 <= a[y] - a[z]) {
							System.out.println(a[x] + t);
						}else {
							long p = (a[y] + a[z]) / 2;
							if(t <= p - a[x] || p - a[x] <= (a[y] - a[z]) / 2) {
								System.out.println(a[x] + t);
							}else {
								System.out.println(p);
							}
						}
					}
				}
			}else {
				int y = -1;
				for(int j = x - 1; j >= 0; j--) {
					if(d[j]) {
						y = j;
						break;
					}
				}
				
				if(y == -1) {
					System.out.println(a[x] - t);
				}else {
					int z = -1;
					if(x - y > 1) {
						z = y + 1;
					}
					
					if(z == -1) {
						if(t * 2 <= a[x] - a[y]) {
							System.out.println(a[x] - t);
						}else {
							System.out.println((a[x] + a[y]) / 2);
						}
					}else {
						if(t * 2 <= a[z] - a[y]) {
							System.out.println(a[x] - t);
						}else {
							long p = (a[y] + a[z]) / 2;
							if(t <= a[x] - p || a[x] - p <= (a[z] - a[y]) / 2) {
								System.out.println(a[x] - t);
							}else {
								System.out.println(p);
							}
						}
					}
				}
			}
		}
	}
}


Measured memory_bytes: 102208
#include <stdio.h>
#include <strings.h>

int main() {
    int n, b, r, f, v ;
    int room[4][3][10];
    for(int i = 0; i < 4; i++) {
        for(int j = 0; j < 3; j++) {
            for(int k = 0; k < 10; k++) {
                room[i][j][k] = 0;
            }
        }
    }
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        scanf("%d %d %d %d", &b, &r, &f, &v);
        room[b-1][r-1][f-1] += v;
    }
    for(int i = 0; i < 4; i++) {
        for(int j = 0; j < 3; j++) {
            for(int k = 0; k < 10; k++) {
                printf(" %d", room[i][j][k]);
            }
            puts("");
        }
        if (i != 3) puts("####################");
    }
}


Measured memory_bytes: 2048
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)
n, q = map(int, input().split())
un = UnionFind(n)
for _ in range(q):
  t, u, v = map(int, input().split())
  if t == 0:
    un.union(u, v)
  else:
    print(1 if un.same(u, v) else 0)

Measured memory_bytes: 11484
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

bool a[MOD];
vector<int> sosu;
void mk(){
  for(int i=2;i<=1000000;i++){
    if(a[i]==0){
      sosu.push_back(i);
      for(int j=i;j<=1000000;j+=i){
	a[j]=1;
      }
    }
  }
}

signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  mk();
  int ans=0;
  int l[1000];
  int n;
  cin>>n;
  lp(i,n){
    cin>>l[i];
    if(l[i]!=1)sosu.push_back(l[i]);
    ans=max(ans,l[i]);
  }
  if(ans==1){
    cout<<0<<endl;
    return 0;
  }
  lp(i,sosu.size()){
    int now=sosu[i];
    int sum=0;
    lp(j,n){
      if(l[j]%sosu[i]==0){
	sum+=l[j];
      }
    }
    ans=max(ans,sum);
  }
  cout<<ans<<endl;
  return 0;
}



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


int main()
{   
    string s;
    int k;
    cin>>s>>k;
    int n=s.size();
    set<string> st;
    for(int j=1;j<=5;j++){
        for(int i=0;i<n-j+1;i++){
            st.insert(s.substr(i,j));
        }
    }
    auto it = st.begin();
    while(--k) it++;
    cout<<*it<<endl;
    
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[222222];
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){//線分の交差判定
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
void init_fact(int n){
	kaijo[0]=1;
	for(int i=1;i<=n;i++){
		kaijo[i]=kaijo[i-1]*i;
		kaijo[i]%=MOD;
	}
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	int memo=modpow(a,b/2);
	return memo*memo%MOD;
}
int comb(int a,int b){
	return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int g(int x){
	x=modpow(x,MOD-2);
	return x;
}
int n,k;
int solve(int i){
	if(i==1)return n-k+1;
	int ans=comb(k-1,i-1);
	int memo=n-k;
	int cnt=0;
	for(int j=0;j<memo;j++){
		if(memo-j-1<i-2)continue;
		cnt+=comb(memo-j-1,i-2)*(j+1)%MOD;
		cnt%=MOD;
	}
	ans*=cnt;
	return ans%MOD;
}
signed main(){
	cin>>n>>k;
	init_fact(10000);
	for(int i=1;i<=k;i++){
		cout<<solve(i)<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstring>

#define reset(a, b) memset(a, b, sizeof(a))

typedef long long int lli;

int n;
lli a;
bool res = true;

int main()
{
    std::cin >> n;
    while (n--) { std::cin >> a; if (a % 2 == 1) res = false; }
    std::cout << (res ? "second" : "first");
}


Measured memory_bytes: 256
import sys

MOD = 10**9 + 7

N = int(input())
Cs = [int(sys.stdin.readline())-1 for _ in range(N)]

numCs = [0] * (2 * 10**5)
anss = [0] * N
numCs[Cs[0]] = 1
anss[0] = 1
for i, C in enumerate(Cs[1:], 1):
    if C == Cs[i-1]:
        anss[i] = anss[i-1]
    else:
        numCs[C] += anss[i-1]
        anss[i] = numCs[C] % MOD

print(anss[-1])


Measured memory_bytes: 54876
/*
      author  : nishi5451
      created : 14.08.2020 23:56:55
*/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;


int main(){
    int n,m,c;
    cin >> n >> m >> c;
    vector<int> b(m);
    rep(i,m) cin >> b[i];
    int ans = 0;
    rep(i,n){
        int now = c;
        rep(j,m){
            int a;
            cin >> a;
            now += a*b[j];
        }
        if(now > 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
ans=999

N=int(input())
for p in range(1,N//2+1):
    q= N-p

    p=list(str(p))
    p=list(map(int,p))
    q=list(str(q))
    q=list(map(int,q))

    ans=min(ans,sum(p)+sum(q))

print(ans)
               

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

using ll = long long;

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

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

    string s;
    cin >> s;

    if ((s.length() % 2 == 0) ^ (s[0] == s[s.length() - 1])) {
        cout << "Second" << endl;
    } else {
        cout << "First" << endl;
    }
    return 0;
}

Measured memory_bytes: 512
// AtCoder template
// 見た奴全員saba!
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)



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

    int n; string s; cin >> n >> s;
    int ans = 1;
    rep(i,n-1){
        if(s[i] != s[i+1]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
X,Y = input().split()
list = ["A","B","C","D","E","F"]

for i in range(6):
    if list[i] == X:
        X = 10 + i
    if list[i] == Y:
        Y = 10 + i
if X > Y:
    print(">")
elif X == Y:
    print("=")
else:
    print("<")


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

int main() {
  int x,y;
  while(cin>>x>>y,x){
    double z=1<<30;
    for(int i=0;i<=x;i++)z=min(z,fabs(sqrt(i*i+(x-i)*(x-i))-y));
    printf("%.9f\n",z);
  }
  return 0;
}


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

using namespace std;

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

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

string s;

int single(int& pos);

int figure(int& pos);

int solve(int& pos);

int main(){
	int T;
	cin>>T;
	for(int i = 0; i < T; i++){
		cin>>s;
		int pos = 0;
		cout<<solve(pos)<<endl;
	}
	
	return 0;
}

int single(int& pos){//??°??????????????????????????¢??°
	if(s[pos]!='('){
		int res = 0;
		while('0'<=s[pos] && s[pos]<='9'){
			res *= 10;
			res += s[pos]-48;
			pos++;
		}
		return res;
	}else{
		return solve(++pos);
	}
}

int figure(int& pos){//????????????????????????????????¢??°
	int res = single(pos);
	while(1){
		if(s[pos]=='*'){
			res *= single(++pos);
		}else if(s[pos]=='/'){
			res /= single(++pos);
		}else {
			return res;
		}
	}
}

int solve(int& pos){//?????¨???????¨????????????¢??°(????????????????¨?????????????????????¨?????????)
	int res = figure(pos);
	while(s[pos]!='=' && s[pos]!=')'){
		if(s[pos]=='+') res += figure(++pos);
		else if(s[pos]=='-') res -= figure(++pos);
	}
	pos++;
	return res;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	t=1;
	
	//cin >> t;
	while(t--)
	{
		long n;
		cin >> n;
		long  i;
		long x[n],y[n];
		long h[n];
		
		
		for(i=0;i<n;i++)
		{
			cin >> x[i] >> y[i] >> h[i];
			
		}
		long flag =0,j;
		for(i=0;i<=100;i++)
		{
			for(j=0;j<=100;j++)
			{
				long k;
				for(k=0;k<n;k++)
				{
					if(h[k]==0)
					{
						continue;
						
					}
					else
					{
						break;
					}
				}
				long height = h[k] + abs(x[k]-i) + abs(y[k]-j);
				
				flag = 0;
				
				for(k=0;k<n;k++)
				{
					long height2 = height - abs(i-x[k]) - abs(j-y[k]);
					if(height2<0)
					{
						height2 = 0;
						
					}
					if(height2!=h[k])
					{
						flag = 1;
						break;
					}
				}
				if(flag==0)
				{
					cout << i << " " << j << " " << height;
				}
			}
		}
		
		
	}
	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 n = Integer.parseInt(sc.next());
        int T = Integer.parseInt(sc.next());
        
        int minC = 10000;
        for(int i = 0; i < n; i++){
            int c = Integer.parseInt(sc.next());
            int t = Integer.parseInt(sc.next());
            if(t <= T && c < minC){
                minC = c;
            }
        }
        
        if(minC < 10000){
            System.out.println(minC);
        }else{
            System.out.println("TLE");
        }
    }
}

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

char M(char a, char b) {
    if(a == 'T' && b == 'F') return 'F';
    return 'T';
}

int main() {
    int n; cin >> n;
    char ans; cin >> ans;
    for(int i = 1; i < n; ++i) {
        char b; cin >> b;
        ans = M(ans, b);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

int main(){
  ll n, k;
  ll minnum, maxnum;
  cin >> n >> k;
  ll ans = 0;
  for(ll i=k; i<=n+1; ++i){
    minnum = i * (i-1) /2;
    maxnum = (n+(n-i+1)) * i /2;
    ans += maxnum - minnum +1;
    ans %= MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3600
#include<iostream>


using namespace std;

void MaxHeapify(int a[], int i, int x){
	int l = 2*i+1, r = 2*i+2;
	int largest = i;

	if(l < x && a[l] > a[i]){
		largest = l;
	}if(r < x && a[r] > a[largest]){
		largest = r;
	}if(largest != i){
		swap(a[i], a[largest]);
		MaxHeapify(a, largest, x);
	}
}

void buildMaxHeap(int a[], int x){
	for(int i =(x-2)/2; i >= 0; --i){
		MaxHeapify(a, i, x);
	}
}

void printMaxHeap(int *value, int number){
	for(int i=0; i<number; i++){
		cout << " " << value[i];
	}
	cout << endl;
}

int main(){
	int num, value[500010];

	cin >> num;

	for(int i =0; i <num; i++){
		cin >> value[i];
	}

	buildMaxHeap(value, num);
	printMaxHeap(value, num);

	return 0;
}


Measured memory_bytes: 5004
#include <stdio.h>
#include <string.h>

int main(void) {
	char mondai[20];
	int kazubak[9];
	int kazu[9];
	int kazubak2[9];
	int i,j;
	int tuika;
	int tuikaok[9];
	int out;
	while(1) {
		if(scanf("%s",mondai)==-1)break;
		for(i=0;i<9;i++)kazubak[i]=0;
		for(i=0;i<13;i++)kazubak[mondai[i]-'1']++;
		for(i=0;i<9;i++)tuikaok[i]=0;
		memset(tuikaok,0,sizeof(tuikaok));
		for(tuika=0;tuika<9;tuika++) {
			memcpy(kazu,kazubak,sizeof(kazu));
			kazu[tuika]++;
			if(kazu[tuika]>4)continue;
			for(i=0;i<9;i++) {
				memcpy(kazubak2,kazu,sizeof(kazubak2));
				if(kazu[i]<2)continue;
				kazu[i]-=2;
				for(j=0;j<7;j++) {
					while(kazu[j]>0 && kazu[j+1]>0 && kazu[j+2]>0) {
						kazu[j]--;
						kazu[j+1]--;
						kazu[j+2]--;
					}
				}
				for(j=0;j<9;j++)kazu[j]=kazu[j]%3;
				for(j=0;j<9;j++) {
					if(kazu[j]>0)break;
				}
				memcpy(kazu,kazubak2,sizeof(kazu));
				if(j>=9) {
					tuikaok[tuika]=1;
					break;
				}
				memcpy(kazubak2,kazu,sizeof(kazubak2));
				if(kazu[i]<2)continue;
				kazu[i]-=2;
				for(j=0;j<9;j++)kazu[j]=kazu[j]%3;
				for(j=0;j<7;j++) {
					while(kazu[j]>0 && kazu[j+1]>0 && kazu[j+2]>0) {
						kazu[j]--;
						kazu[j+1]--;
						kazu[j+2]--;
					}
				}
				for(j=0;j<9;j++) {
					if(kazu[j]>0)break;
				}
				memcpy(kazu,kazubak2,sizeof(kazu));
				if(j>=9) {
					tuikaok[tuika]=1;
					break;
				}
			}
		}
		for(i=0,out=0;i<9;i++) {
			if(tuikaok[i]) {
				if(out)printf(" ");
				out=1;
				printf("%d",i+1);
			}
		}
		if(out==0)printf("0");
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 0
n, m = map(int, input().split())
a=[input()for i in range(n)]
b=[input()for i in range(m)]

def same(x,y):
    for i in range(m):
        for j in range(m):
            if a[x+i][y+j]!=b[i][j]:
                return False
    return True

for x in range (n-m+1):
    for y in range(n - m + 1):
        if same(x,y):
            print('Yes')
            import sys
            sys.exit()
print('No')

Measured memory_bytes: 3064
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline



def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, A, B] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2])]
    print min(A * N,  B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2932
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b, a%b)

def lcm(a,b):
    return a // gcd * b

def main():
    K = int(input())
    A = [int(_n) for _n in input().split()]
    maxnum = 2
    minnum = 2
    for i in reversed(range(0,K)):
        mi = (minnum + A[i] - 1)//A[i] * A[i]
        ma = maxnum // A[i] * A[i]
        # print(mi,ma)
        if mi < minnum or mi > maxnum or ma < minnum or ma > maxnum:
            print(-1)
            return
        minnum = mi
        maxnum = ma+A[i]-1
    print(minnum,maxnum)
main()

Measured memory_bytes: 63984
import sys
input = sys.stdin.readline


def read():
    N, M = map(int, input().strip().split())
    return N, M


def solve(N, M):
    nScc = min(N, M//2)
    N -= nScc
    M -= nScc * 2
    if M >= 4:
        nScc += M // 4
    return nScc


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


Measured memory_bytes: 9060
S = list(input())
N = len(S)
dp = [[0]*13 for _ in range(N+1)]
dp[0][0] = 1
MOD = 10**9 +7

for i in range(1,N+1):
    R = [0]*13
    if S[i-1] == "?":
        for j in range(10):
            r = j * pow(10,N-i,13) %13 
            R[r] += 1 

    else:
        r = int(S[i-1]) * pow(10,N-i,13) %13
        R[r] += 1

    for k in range(13):
                for l in range(13):
                    dp[i][k] += dp[i-1][l] * R[(k-l)%13]
                    dp[i][k] %= MOD

print(dp[N][5])

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

using namespace std;

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

    vector<long> a(n);
    for(auto &x: a) cin >> x;

    long sum = 0;
    for(auto &x: a) sum += x;

    long res = 1;
    for(long qq=1; qq*qq<sum; qq++) {
        if(sum % qq != 0) continue;

        for(long q : {qq, sum/qq}) {
            vector<long> b(n);
            copy(a.begin(), a.end(), b.begin());

            for(auto &x: b) x %= q;
            sort(b.begin(), b.end());


            long s = 0;
            for(auto &x: b) s += q - x;

            long t = 0, r = 1e9;
            for(int i=0; i<n; i++) {
                r = min(max(t, s), r);
                t += b[i];
                s -= q - b[i];
            }
            r = min(max(t, s), r);

            if(r <= k)
                res = max(res, q);

        }
    }

    cout << res << endl;
}


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

#define SIZE_OF_ARRAY(array) sizeof(array)/sizeof(array[0])

struct ten{
    int list[10];
};

int main() {
    int N, M, Q;
    cin >> N >> M >> Q;
    int a[Q], b[Q], c[Q], d[Q];
    for(int i = 0; i < Q; i++){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    vector<ten> v;
    for(int aa = 1; aa <= M; aa++){
        for(int bb = aa; bb <= M; bb++){
            for(int cc = bb; cc <= M; cc++){
                for(int dd = cc; dd <= M; dd++){
                    for(int ee = dd; ee <= M; ee++){
                        for(int ff = ee; ff <= M; ff++){
                            for(int gg = ff; gg <= M; gg++){
                                for(int hh = gg; hh <= M; hh++){
                                    for(int ii = hh; ii <= M; ii++){
                                        for(int jj = ii; jj <= M; jj++){
                                            v.push_back({aa, bb, cc, dd, ee, ff, gg, hh, ii, jj});
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    int maxscore = 0;
    for(int vl = 0; vl < v.size(); vl++){
        int score = 0;
        // for(int i = 0; i < 10; i++){
        //     cout << v.at(vl).list[i] << " ";
        // }
        // cout << endl;
        for(int q = 0; q < Q; q++){
            if(v.at(vl).list[b[q]-1] - v.at(vl).list[a[q]-1] == c[q]){
                score += d[q];
            }
        }
        maxscore = std::max(score, maxscore);
    }
    cout << maxscore;
}

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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, K; cin >> N >> K;
  ll ans = 0;
  if (K % 2 == 1) {
    ll p = N / K;
    ans = p * p * p;
  }else if (K == 2) {
    ll odd = (N + 1) / 2;
    ll even = N / 2;
    ans = odd * odd * odd + even * even * even;
  }else {
    ll kk = K / 2;
    ll p = N / kk;
    ll odd = (p + 1) / 2;
    ll even = p / 2;
    ans = odd * odd * odd + even * even * even;
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int main(){
  int n; cin >> n;
  int a[200000 + 10];
  for(int i = 0; i < n; i++){
    scanf("%d", &a[i]);
  }
  sort(a, a + n);
  for(int i = 0; i < n; i++){
    if(a[i] == a[i + 1]){
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");
  return 0;
}



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

int main() {
	int h,w;
	
	while(1) {
		cin >> h >> w;
		char c;
		if (h==0 && w==0) break;
		
		for (int j=0;j<h;j++){
			for (int i=0;i<w;i++){
				c='#';
				if (i!=0 && i!=w-1 && j!=0 && j!=h-1) c='.';
				cout << c;
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3100
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

const DXY: [(i64, i64); 8] = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)];

use std::io::{stdout, Write, BufWriter};

fn main() {
    input! {
        h: i64,
        w: i64,
        map: [String; h as usize],
    }
    let out = stdout();
    let mut out = BufWriter::new(out.lock());

    let map = map.iter().map(|s| s.bytes().map(|b| if b == b'.' { b'0' } else { b } ).collect::<Vec<u8>>()).collect::<Vec<_>>();
    let mut ans = map.clone();
    for i in 0..h {
        for j in 0..w {
            if map[i as usize][j as usize] != b'#' {
                for &(dx, dy) in DXY.iter() {
                    if let Some(r) = map.get((i + dy) as usize) {
                        if let Some(&c) = r.get((j + dx) as usize) {
                            if c == b'#' { ans[i as usize][j as usize] += 1; }
                        }
                    }
                }
            }
        }
    }
    for r in ans { writeln!(out, "{}", String::from_utf8(r).unwrap()).unwrap(); }
}


Measured memory_bytes: 4352
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define Eps (1e-10)

int N;
bool flag[102];
double x[102],y[102];

int main() {
  while (scanf("%d",&N),N) {
    rep(i,N) scanf("%lf,%lf",x+i,y+i);
    fill(flag, flag + N, false);
    //rep(i,N) printf("%lf,%lf\n",x[i],y[i]);
    for (int i = 0; i < N; ++i) {
      for (int j = i+1; j < N; ++j) {
        for (int k = j+1; k < N; ++k) {
          for (int l = 0; l < N; ++l) {
            if (i == l || j == l || k == l) continue;
            if (flag[i] | flag[j] | flag[k] | flag[l]) continue;
            double S, subS[3], subSum = 0;
            S = fabs((x[i]*y[j] + x[j]*y[k] + x[k]*y[i] -
                      y[i]*x[j] - y[j]*x[k] - y[k]*x[i]) / 2);
            subS[0] = fabs((x[l]*y[j] + x[j]*y[k] + x[k]*y[l] -
                            y[l]*x[j] - y[j]*x[k] - y[k]*x[l]) / 2);
            subS[1] = fabs((x[i]*y[l] + x[l]*y[k] + x[k]*y[i] -
                            y[i]*x[l] - y[l]*x[k] - y[k]*x[i]) / 2);
            subS[2] = fabs((x[i]*y[j] + x[j]*y[l] + x[l]*y[i] -
                            y[i]*x[j] - y[j]*x[l] - y[l]*x[i]) / 2);
            rep(ii,3) subSum += subS[ii];
            if (fabs(S-subSum) < Eps) {
              //printf("(%d,%d,%d) : %d | %.3lf %.3lf\n", i,j,k,l,S,subSum);
              flag[l] = true;
            }
          }
        }
      }
    }
    printf("%d\n",count(flag, flag+N, true));
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
int comp(const void *a, const void *b) {
	return *(const int *)b - *(const int *) a;
}

int ri() {
	int r=0, c, s=0;
	for(;;){c=getchar_unlocked();if(c=='-'){s=1;break;}if(c<='9'&&c>='0'){r=c-'0';break;}}
	for(;;){c=getchar_unlocked();if(c<'0'||c>'9')break;r=r*10+c-'0';}
	if(s)r=-r;
	return r;
}

int main() {
	int n;
	scanf("%d", &n);
	int a[n];
	for (int i = 0; i < n; i++) a[i] = ri();
	int max = 0, x = 0;
	for (int i = 0; i < n; i++) if (max < a[i]) max = a[i], x = 1; else if (max == a[i]) x++;
	int max2 = 0;
	for (int i = 0; i < n; i++) if (a[i] != max && max2 < a[i]) max2 = a[i];
	for (int i = 0; i < n; i++) {
		if (x == 1 && a[i] == max) printf("%d\n", max2);
		else printf("%d\n", max);
	}
	return 0;
}


Measured memory_bytes: 2304
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main() {
    ll N;
    cin >> N;
    struct Dish {
        ll A;
        ll B;
    };
    auto comp_dish = [](Dish lhs, Dish rhs){ return lhs.A + lhs.B < rhs.A + rhs.B; };
    priority_queue<Dish, vector<Dish>, decltype(comp_dish)> dishes(comp_dish);
    for (int i = 0; i < N; i++) {
        ll A, B;
        cin >> A >> B;
        dishes.push(Dish{A, B});
    }
    ll t_score = 0;
    ll a_score = 0;
    bool t_phase = true;
    while (!dishes.empty()) {
        Dish dish = dishes.top();
        dishes.pop();
        if (t_phase) {
            t_score += dish.A;
        } else {
            a_score += dish.B;
        }
        t_phase = !t_phase;
    }
    cout << t_score - a_score << endl;
}


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

using namespace std;

int main(void) {
	int n;
	cin >> n;
	int ac = 0;
	int wa = 0;
	int tle = 0; int re = 0;

	for (int i = 0; i < n; i++) {
		string temp;
		cin >> temp;
		if (temp == "AC") {
			ac++;
		}
		else if (temp == "WA") {
			wa++;
		}
		else if (temp == "TLE") {
			tle++;
		}
		else {
			re++;
		}
	}

	cout << "AC x " << ac << endl <<
		"WA x " << wa << endl <<
		"TLE x " << tle << endl <<
		"RE x " << re << endl;

	return 0;
}

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

const int64_t MOD=1e9+7;


int main(){
  int N;
  cin>>N;
  int64_t ans=0;
  //0-A,1-G,2-C,3-Tとして先頭3文字がijkの条件を満たすn文字の総数dp[n][i][j][k];
  int64_t dp[N+1][4][4][4];

  //初期化
  for(int n=3;n<N+1;++n){
  for(int i=0;i<4;++i){
    for(int j=0;j<4;++j){
      for(int k=0;k<4;++k){
        if(n==3){
        if(i==0 && j==1 && k==2) dp[3][i][j][k]=0;
        else if(i==1 && j==0 && k==2) dp[3][i][j][k]=0;
        else if(i==0 && j==2 && k==1) dp[3][i][j][k]=0;
        else dp[3][i][j][k]=1;
        }
        else dp[n][i][j][k]=0;
      }
    }
  }
  }


  for(int n=4;n<N+1;++n){
    for(int i=0;i<4;++i){
      for(int j=0;j<4;++j){
        for(int k=0;k<4;++k){
          if(i==0 && j==1 && k==2) dp[n][i][j][k]=0;
          else if(i==1 && j==0 && k==2) dp[n][i][j][k]=0;
          else if(i==0 && j==2 && k==1) dp[n][i][j][k]=0;
          else{
          for(int l=0;l<4;++l){
            //AG*CやA*GCを除く
            if(i==0 && j==1 && l==2) continue;
            if(i==0 && k==1 && l==2) continue;
            dp[n][i][j][k] += dp[n-1][j][k][l];
            dp[n][i][j][k] %= MOD;
          }
        }
        }
      }
    }
  }

  for(int i=0;i<4;++i){
    for(int j=0;j<4;++j){
      for(int k=0;k<4;++k){
        ans += dp[N][i][j][k];
        ans %= MOD;
    }
  }
}

  cout<<ans<<endl;
}


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

int main(){
	int h, w, dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
	cin >> h >> w;
	vector<string> s(h);
	rep(i, h){
		cin >> s.at(i);
	}
	rep(i, h){
		rep(j, w){
			if(s.at(i)[j] == '.') continue;
			bool flag = false;
			rep(k, 4){
				int nx = j + dx[k], ny = i + dy[k];
				if(nx < 0 || w <= nx || ny < 0 || h <= ny) continue;
				if(s.at(ny)[nx] == '#') flag = true;
			}
			if(flag == false){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << 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 REP(i,n) for(int i=1;i<=n;i++)
typedef long long ll;
ll const MOD = 1000000007;

string t ="abcdefghijklmnopqrstuvwxyz";

int main(){
	int N;
	cin >> N;
	string s;
	cin >> s;
	
	map<char,int> mp;
	
	rep(i,N){
		mp[s[i]]++;
	}
	
	ll ans = 1;
	
	rep(i,t.size()){
		ans *= mp[t[i]] +1;
		ans %= MOD;
	}
	
	cout << ans - 1 << endl;
	
    return 0;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

const int mod = 1e9 + 7;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n, k; cin >> n >> k;
	vi v;
	for(int i = 1; (i - 1) * (i - 1) <= n; i++){
		v.pb(i);
		if(i < n / i + 1) v.pb(n / i + 1);
	}
	sort(all(v)); v.erase(unique(all(v)), v.end());
	
	int m = v.size();
	vi dp(m);
	dp[m - 1] = 1;
	
	rep(i, k - 1){
		vi next(m);
		for(int j = m - 2, to = 0; j >= 0; j--){
			(dp[j] += dp[j + 1]) %= mod;
			while(to < m - 1 && v[to] * (ll)v[j] <= n){
				next[to] += (ll)(v[j + 1] - v[j]) * dp[j] % mod;
				next[to] %= mod;
				to++;
			}
		}
		dp = next;
	}
	
	ll ans = 0;
	for(int i = m - 2; i >= 0; i--){
		(dp[i] += dp[i + 1]) %= mod;
		ans += (ll)dp[i] * (v[i + 1] - v[i]) % mod;
	}
	cout << ans % mod << endl;
	
	return 0;
}

Measured memory_bytes: 1148
#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int x;
	cin>>x;
	while(x>0)
	{
		int temp = x%10;
		if(temp==7)
		{
			cout<<"Yes";
			return 0;
		}
		x=x/10;

	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define MOD 998244353
typedef double ld;
#define PI 3.14159265


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

    int a , b , x;
    cin >> a >> b >> x;
    if((a <= x && a + b >= x)) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    Boolean chk = true;
    for(int i=0;i<3;i++){
      if(s.charAt(i)==s.charAt(i+1))chk=false;
    }
    if(chk)System.out.println("Good");
    else System.out.println("Bad");
  }
}


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

using namespace std;

struct data_t {
	int ID;
	int time;
	int ac;

	bool operator<(const data_t& right) const {
		if (ac == right.ac) {
			if (time == right.time) {
				return (ID > right.ID);
			}
			else {
				return (time < right.time);
			}
		}
		else {
			return (ac > right.ac);
		}
	}
};

int main(void) {
	int M,T,P,R;
	while (cin >> M >> T >> P >> R, M) {
		vector<data_t> data(T);
		for (int i = 0; i < T; ++i) {
			data[i].ID = i+1;
			data[i].time = 0;
			data[i].ac = 0;
		}

		int m,t,p,judge;
		vector< vector<int> > wrong(T,vector<int>(P,0));
		for (int i = 0; i < R; ++i) {
			cin >> m >> t >> p >> judge;
			if (judge != 0) {
				++wrong[t-1][p-1];
			}
			else {
				++data[t-1].ac;
				data[t-1].time += m + (20 * wrong[t-1][p-1]);
			}
		}
		sort(data.begin(),data.end());
		for (int i = 0; i < T; ++i) {
			cout << data[i].ID;
			if (i < T-1) {
				if (data[i].ac == data[i+1].ac && data[i].time == data[i+1].time) {
					cout << "=";
				}
				else {
					cout << ",";
				}
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3148
#include<stdio.h>
int sum(int n){
    if(n ==0)return 0;
    return n%10 +sum(n/10);
}
int main(){
    int a;
    scanf("%d", &a);
    if(a%sum(a)==0){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
} 

Measured memory_bytes: 128
N = int(input())

def dfs(s): # 文字列 s で始まる七五三数の個数
    if int(s) > N:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0 # s 自体が七五三数なら +1
    for c in '753':
        ret += dfs(s + c)
    return ret

print(dfs('0'))


Measured memory_bytes: 2940
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#include <immintrin.h>

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); bool s=false; if(c=='-'){s=true;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define xor_add(xmm0, xmm1, xmm2) do{ __m128i xmm7 = _mm_add_epi32(xmm1, xmm2); xmm0 = _mm_xor_si128(xmm0, xmm7); }while(0)

int a[200000];
int b[200000];
int main(void){
	int n=nextint();
	for(int i=0; i<n; i++){
		a[i]=nextint();
	}
	for(int i=0; i<n; i++){
		b[i]=nextint();
	}
	int ans=0;
	int m1=(n+3)/4*4;
	int m=(n+15)/16*16;
 
	__m128i xmm0 = _mm_setzero_si128();
	for(int i=0; i<m1; i+=4){
		__m128i xmm1 = _mm_set1_epi32(a[i+0]);
		__m128i xmm2 = _mm_set1_epi32(a[i+1]);
		__m128i xmm3 = _mm_set1_epi32(a[i+2]);
		__m128i xmm4 = _mm_set1_epi32(a[i+3]);
		for(int j=0; j<m; j+=8){
			__m128i xmm5 = _mm_loadu_si128((__m128i*)&b[j+0]);
			__m128i xmm6 = _mm_loadu_si128((__m128i*)&b[j+4]);
			xor_add(xmm0, xmm1, xmm5);
			xor_add(xmm0, xmm1, xmm6);
			xor_add(xmm0, xmm2, xmm5);
			xor_add(xmm0, xmm2, xmm6);
			xor_add(xmm0, xmm3, xmm5);
			xor_add(xmm0, xmm3, xmm6);
			xor_add(xmm0, xmm4, xmm5);
			xor_add(xmm0, xmm4, xmm6);
		}
	}
	int c[4];
	_mm_storeu_si128((__m128i*)&c, xmm0);
	ans^=c[0];
	ans^=c[1];
	ans^=c[2];
	ans^=c[3];
	if(n%2==1){
		for(int i=0; i<n; i++){
			ans^=a[i];
			ans^=b[i];
		}
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 3132
#include <iostream>

using namespace std;

int sc(int i){
  int c=0;
  while(i%2==0){
    i/=2;
    c++;
  }
  return c;
}


int main(){
  int N,i,k=0;
   cin >> N;
  while(N--){
    cin >>i;
     if(i%2==0)
       k+=(sc(i));
  }                                                                             
  cout << k <<endl;
}

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

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if(0)
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}

LL f(vector<LL> a){
    LL top=-114514;
    for(auto &it:a)chmax(top,it);
    return top;
}
int main(){
    int N;
    cin>>N;
    vector<LL> a(N);
    cin>>a;
    LL K=0;
    while(f(a)>1000){
        //cout<<f(a)<<" ";
        LL p=0;
        vector<LL> q(N);
        REP(i,N){
            LL nxt=a[i]%N;
            q[i]=(a[i]-nxt)/N;
            p+=q[i];
            a[i]=nxt;
        }
        REP(i,N){
            a[i]+=p-q[i];
        }
        K+=p;
        //cout<<f(a)<<endl;
    }
    while(f(a)>=N){
        sort(ALL(a));
        a.back()-=N+1;
        REP(i,N)a[i]++;
        K++;
    }
    cout<<K<<endl;
    return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn

object Main extends App {
  val n = StdIn.readInt
  val k = StdIn.readInt

  val ans = StdIn.readLine.split(" ").map(_.toInt)
    .map( i => math.min(i<<1, math.abs(i-k)<<1) ).sum

  println(ans)
}

Measured memory_bytes: 27340
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<string> > vvs(N);
  for (int i = 0; i < M; ++i) {
    int p;
    string S;
    cin >> p >> S;
    --p;
    vvs[p].push_back(S);
  }

  int AC = 0;
  int WA = 0;
  for (int p = 0; p < N; ++p) {
    bool accepted = false;
    int WA_p = 0;
    for (auto S : vvs[p]) {
      if (S == "AC") {
	accepted = true;
	break;
      } else {  // "WA"
	++WA_p;
      }	
    }
    if (accepted) {
      AC += 1;
      WA += WA_p;
    }
  }

  cout << AC << " " << WA << endl;
  
  return 0;
}


Measured memory_bytes: 10368
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int INF = 1e9;
#define put(n) cout<<(n)<<endl
#define rep(i,N) for(int(i)=0;(i)<(N);++(i))
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin() , (v).rend()
#define pb(n) push_back(n)


int main(){
    ll N,ans = 0,sum = 0;
    cin >> N;
    map<ll,ll> mp;
    ++mp[0];
    rep(i,N){
        int a; cin >> a;
        sum += a;
        ans += mp[sum];
        ++mp[sum];
    }
    cout << ans << endl;
}

Measured memory_bytes: 12800
n = list(map(int, list(str(int(input())))))
l = [sum(n)]
ln = len(n) - 1

def d(i):
    if i > len(n) - 1: return
    d(i+1)
    v2 = n[i] - 1 if n[i] != 0 else 9
    l.append(v2 + (ln - i) * 9)

d(0)
print(max(l))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define all(cont) cont.begin(), cont.end()
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef set<int> si;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
 
ll gcd(ll a,ll b){if(a<0)a=-a;if(b<0)b=-b;while(b!=0){a%=b;if(a==0)return b;b%=a;}return a;}
int mpow(int x,unsigned int y,int p){int res=1;x%=p;if(x==0)return 0;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int fpow(int x,unsigned int y){int t;if(y==0){return 1;}t=fpow(x,y/2);if(y%2==0){return t*t;}else{return x*t*t;}}
void swap(int *arr, int i, int j){int temp=arr[i];arr[i]=arr[j];arr[j]=temp;}
int nCr(int n,int k){int C[k+1];memset(C,0,sizeof(C));C[0]=1;for(int i=1;i<=n;i++){for(int j=min(i,k);j>0;j--)C[j]=C[j]+C[j-1];}return C[k];}
//int mod(int a,int b){int m=a%b;if(m<0){m=(b<0)?m-b:m+b;}return m;}
 
const int INF = 1e9+1;
const int MAX_N = 101;
const int mod = 1000000007;

void solve(){
	string one, two;
	cin >> one >> two;
	if(one.length() + 1 != two.length()){
		cout << "No";
		return;
	}
	for(int i =0; i < one.length(); ++i){
		if(one[i] != two[i]){
			cout << "No";
			return;
		}
	}
	cout << "Yes";
	return;
}
 
int main(){
	//freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	
	
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}	
	return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <ctype.h>

int main(int argc, char **argv){
	int c;
	int x;

	for(;;){
		// Input & CountUp
		x = 0;
		for(;;){
			c = getchar();
			// EOL/EOF Check
			if( c == EOF || c == '\n' ){
				break;
			}
			// Number Check
			if( !isdigit(c) ){
				continue;
			}
			// Convert & CountUp
			x += (char)(c-'0');
		}
		// Finish Check
		if( x == 0 ){
			break;
		}
		// Output
		printf("%d\n",x);
	}

	return 0;
}

Measured memory_bytes: 524
import java.util.Scanner;
import java.util.stream.LongStream;
 
public class Main {
    private static final long MOD = 1_000_000_007;
 
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final int k = scanner.nextInt();
 
        long max = LongStream.rangeClosed(n - k + 1, n).sum();
        long min = LongStream.range(0, k).sum();
 
        long sum = max - min + 1;
        sum %= MOD;
        for (int i = k; i <= n; i++) {
            max += n - i;
            min += i;
            sum += max - min + 1;
            sum %= MOD;
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 36000