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

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);

  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  vector<int> m(N);
  int cnt = 0;
  int mn = 0;
  for (int i = 0; i < N; i++) {
    int found = false;
    if (mn < a[i]) {
      for (int j = 0; j < cnt; j++) {
        if (m[j] < a[i]) {
          m[j] = a[i];
          found = true;
          break;
        }
      }
    }
    if (!found) {
      m[cnt] = a[i];
      mn = a[i];
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int [] in = new int [32];
        in [0]= 1; in [1]=1;in [2]= 1; in [3]=2; in [4]=1; in [5]=2; 
      in [6]=1;in [7]= 5; in [8]=2; in [9]=2;in [10]= 1;in [11]=5;
      in [12]=1; in [13]=2; in [14]=1;in [15]= 14; 
      in [16]=1;in [17]= 5; in [18]=1; in [19]=5; in [20]= 2;in [21]= 2;
      in [22]=1; in [23]=15; in [24]=2; in [25]=2; in [26]=5;in [27]= 4; in [28]=1;
      in [29]=4; in [30]=1;in [31]= 51;
		int b = in[a-1];
        System.out.println(b);
	}
}


Measured memory_bytes: 23764
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val ps = readLine()!!.split(" ").map { it.toInt() }
    val flags = mutableListOf<Int>()
    for (i in 1..n) {
        if (i != ps[i-1]) {
            flags.add(i)
        }
    }
    if (flags.isEmpty()) {
        println("YES")
    }
    else if (flags.size == 2) {
        if (flags[0] == ps[flags[1] - 1] && flags[1] == ps[flags[0] - 1]) {
            println("YES")
        }
        else {
            println("NO")
        }
    }
    else {
        println("NO")
    }
}

Measured memory_bytes: 37808
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
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; }
ll MOD = 1000000007;

int main(void){
  long double w,h,x,y; cin >> w >> h >> x >> y;
  cout << w*h/2;
  if(x == w/2 && y == h/2) cout << " " << 1 << endl;
  else cout << " " << 0 << endl;
  return 0;
}


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

const int DIM = 805;
const int dx[5] = { 0, -1, 0, 1, 0 };
const int dy[5] = { 0, 0, 1, 0, -1 };

int dst[DIM][DIM]; char arr[DIM][DIM];

deque<pair<int, int>> que;

inline int f( int x, int k ) {
    if( x % k == 0 )
        return x / k;
    else
        return x / k + 1;
}

int main( void ) {
    
    int n, m, k;
    cin >> n >> m >> k;
    
    pair<int, int> ip;
    for( int i = 1; i <= n; i ++ ) {
        cin >> ( arr[i] + 1 );
        
        for( int j = 1; j <= m; j ++ ) {
            if( arr[i][j] == 'S' )
                ip = make_pair( i, j );
        }
    }
    
    dst[ip.first][ip.second] = 1;
    for( que.push_back( ip ); que.empty() == false; que.pop_front() ) {
        pair<int, int> px = que.front();
        
        for( int d = 1; d <= 4; d ++ ) {
            pair<int, int> py = make_pair( px.first + dx[d], px.second + dy[d] );
            
            if( dst[py.first][py.second] == 0 && arr[py.first][py.second] == '.' ) {
                dst[py.first][py.second] = dst[px.first][px.second] + 1;
                que.push_back( py );
            }
        }
    }
    
    int ans = numeric_limits<int> :: max();
    for( int i = 1; i <= n; i ++ ) {
        for( int j = 1; j <= m; j ++ ) {
            if( dst[i][j] == 0 || dst[i][j] - 1 > k )
                continue;
            
            if( i == 1 || i == n || j == 1 || j == m )
                ans = 0;
            else
                ans = min( ans, min( min( f( i - 1, k ), f( n - i, k ) ),
                                     min( f( j - 1, k ), f( m - j, k ) ) ) );
        }
    }
    
    cout << ans + 1 << endl;
    return 0;
}

Measured memory_bytes: 3456
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());

using ll = long long int;
const ll MOD = 1000000007;

ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a % b);
}

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

ll mod_add(ll a, ll b) {
    return (a + b) % MOD;
}

ll mod_sub(ll a, ll b) {
    return (a + MOD - b) % MOD;
}

ll mod_mul(ll a, ll b){
    return (a * b) % MOD;
}

ll mod_pow(ll base, ll po) {
    if(po == 0)
        return 1;
    else if(po == 1)
        return base;
    ll new_base = mod_pow(base, po / 2);
    return mod_mul(mod_mul(new_base, new_base), po % 2 == 0 ? 1 : base);
}

ll mod_div(ll a, ll b){
    return mod_mul(a, mod_pow(b, MOD - 2));
}

int main(){
    int a, b;
    cin >> a >> b;
    cout << max(max(a + b, a * b), a - b) << endl;
    return 0;
}


Measured memory_bytes: 256
import numpy as np
a = input()+"RA"
b = np.zeros(len(a),int)
for i in range(len(a)):
#  print(*b)
  if i==0:
    b[1]+=1
    continue
  if a[i-1]=="R" and a[i]=="R":
    b[i+1]+=b[i]+1
    b[i]=0
  if a[i-1]=="R" and a[i]=="L":
    b[i-1]+=int(b[i]/2)+b[i]%2
    b[i]=int(b[i]/2)
    b[i+1]=1
  if a[i-1]=="L" and a[i]=="L":
    b[i+1]=b[i]+1
    b[i]=0
  if a[i-1]=="L" and a[i]=="R":
    b[i-b[i]-1]+=int(b[i]/2)
    b[i-b[i]]+=int(b[i]/2)+b[i]%2
    b[i+1]=1
    b[i]=0

c=list(b)
del c[-2:]
print(*c)

Measured memory_bytes: 19668
#include <stdio.h>
int main(){
    int n,m,i = 0;
    while(1){
        scanf( "%d %d", &n, &m );
        if( n == 0 && m == 0 ){ break; }
        if( n > m ){
            i = n;
            n = m;
            m = i;
        }
        printf("%d %d\n" , n , m );
        
    }
}


Measured memory_bytes: 2052
import java.util.*;

class Main {
        public static void main(String args[]) {
                try (Scanner sc = new Scanner(System.in)) {
                        int a, b;
                        char c;
                        while (true) {
                                a = sc.nextInt();
                                c = sc.next().charAt(0);
                                b = sc.nextInt();
                                switch (c) {
                                        case '?':
                                                return;
                                        case '+':
                                                System.out.println(a + b);break;
                                        case '-':
                                                System.out.println(a - b);break;
                                        case '*':
                                                System.out.println(a * b);break;
                                        case '/':
                                                System.out.println(a/b);break;
                                }
                        }
                }
        }
}

Measured memory_bytes: 26148
#include<stdio.h>

int gcd(int p,int q){
int r; r=p%q;
while(r>0){p=q;q=r;r=p%q;}
return q;}

int main(){
int a;
int x,y,z;
int sum=0;
scanf("%d",&a);
for(x=1;x<=a;x++){
for(y=1;y<=a;y++){
for(z=1;z<=a;z++){
sum+=gcd(x,gcd(y,z));
}
}
}
printf("%d",sum);

return 0;}

Measured memory_bytes: 1732
#include<bits/stdc++.h>
using namespace std;
long long n,s;

long long f(long long b,long long n){return n<b?n:f(b,n/b)+n%b;}

int main()
{
	scanf("%lld%lld",&n,&s);
	if(s>n){printf("-1");return 0;}
//	if(s==1){printf("%lld\n",n);return 0;}
    if(s==n){printf("%lld\n",n+1);return 0;}
	long long q=sqrt(n)+1;
//	cout<<q<<endl;
	for(long long i=2;i<=q;i++)
	{
//		cout<<i<<endl;
		if(f(i,n)==s){printf("%lld\n",i);return 0;}
	}
	n-=s,q=sqrt(n)+1;
//	cout<<q<<endl;
	long long ans=100000000000;
	for(long long i=1;i<=q;i++)
	if(!(n%i))
	{
		long long b=n/i+1;
		if(f(b,n+s)==s) ans=min(ans,b);
//		{
//			printf("%lld\n",b);
//			return 0;
//		}
	}
	printf("%lld\n",ans==100000000000?-1:ans);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

//============================================================================
#define pred(x) ((x)-1)
#define succ(x) ((x)+1)
#define True    1
#define False   0
//#define max(x,y) (((x)<(y))?y:x)
//============================================================================
#define MAX_BUFFER  102
//============================================================================
char Xbuffer[1024];
unsigned char Ybuffer[MAX_BUFFER];
char Zbuffer[MAX_BUFFER][MAX_BUFFER];
short MaxX;
//============================================================================
char *next(char *ptr)
{
    while(*ptr && *ptr!=' ')
        ptr++;
    return ++ptr;
}
//----------------------------------------------------------------------------
short putmatrix(char *src)
{
    short y,x,n,i,j;

    sscanf(src, "%hd", &y);
    src=next(src);
    sscanf(src, "%hd", &n);
    src=next(src);
    for (i=j=0; i<n; i++){
        sscanf(src, "%hd", &x);
        //if (Zbuffer[pred(x)][pred(idx)]=='0')
            Zbuffer[pred(y)][pred(x)]='1';
        src=next(src);
        if (j<x)
            j=x;
    }
    return j;
}
//----------------------------------------------------------------------------
void input(FILE *file)
{
    short xl,xidx,zl;
    long i,j,n,m,l,mat; char *ptr,buffer[20];

    memset(Zbuffer, '0', sizeof(Zbuffer));
    fgets(buffer, sizeof(buffer)-1, file);
    sscanf(buffer, "%d", &n);
    for (i=MaxX=0; i<n; i++){
        fgets(Xbuffer, sizeof(Xbuffer), file);
        xl=pred(strlen(Xbuffer));
        Xbuffer[xl]=0;
#ifdef DESKTOP
        printf("X: %s\n", Xbuffer);
#endif
        sscanf(Xbuffer, "%hd", &xidx);
        zl=putmatrix(Xbuffer);
        if (MaxX<zl)
            MaxX=zl;
    }
    for (i=0; i<n; i++){
        for (j=0; j<MaxX; j++){
            if (j) printf(" ");
            printf("%c", Zbuffer[i][j]);
        }
        printf("\n");
    }
}
//============================================================================
#ifndef DESKTOP
int main()
{
    input(stdin);
    return 0;
}
#endif

Measured memory_bytes: 600
#include <iostream>

using namespace std;

int main(){
    int N, M;
    while(cin >> N >> M){
        int l = 1 ,r = N;
        for(int i=0;i<M;i++){
            int L, R; cin >> L >> R;
            l = max(L, l);
            r = min(R, r);
        }
        cout << max(0, r-l+1) << endl;
    }
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto& e : a) cin >> e;
    sort(rbegin(a), rend(a));

    int alice = 0, bob = 0;
    for (int i = 0; i < n; i++) (i % 2 == 0 ? alice : bob) += a[i];
    cout << alice - bob << endl;
}


Measured memory_bytes: 256
import copy

N = int(input())
C = list(list(input().split()))
Cb, Cs = copy.copy(C), copy.copy(C)


def BubbleSort(C, N):
    for i in range(N):
        for j in range(N-1, i, -1):
            if C[j-1][1] > C[j][1]:
                C[j-1], C[j] = C[j], C[j-1]
    for i in range(N):
        C[i] = "".join(C[i])
    print(" ".join(map(str, C)))


def SelectionSort(C, N):
    for i in range(N):
        minj = i
        for j in range(i,N):
            if C[minj][1] > C[j][1]:
                minj = j
        C[i], C[minj] = C[minj], C[i]
    for i in range(N):
        C[i] = "".join(C[i])
    print(" ".join(map(str, C)))

def StableCheck(Cin, Cout, N):
    for i in range(1,10):
        check1, check2 = [], []
        for j1 in Cin:
            if str(i) in j1:
                check1.append(j1)
        for j2 in Cout:
            if str(i) in j2:
                check2.append(j2)
        if check1 != check2:
            print("Not stable")
            exit()
    print("Stable")

BubbleSort(Cb, N)
StableCheck(C, Cb, N)
SelectionSort(Cs, N)
StableCheck(C, Cs, N)


Measured memory_bytes: 6344
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;

LL a[60];
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
	LL k;
	scanf("%lld",&k);
	LL sum = k % 50;
	LL cnt = k / 50;
	for(int i = 1 ; i <= 50 ; i++){
		a[i] = 49;
	}
	for(int i = 1 ; i <= 50 ; i++){
		a[i] += cnt;
	}
	if(sum != 0){
		for(int i = 1 ; i <= sum ; i++){
			a[i] += (50 - sum);
		}
		for(int i = sum + 1 ; i <= 50 ; i++){
			a[i] -= sum;
		}
	}
	printf("50\n");
	for(int i = 1 ; i < 50 ; i++){
		printf("%lld ",a[i]);
	}
	printf("%lld\n",a[50]);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int a, b, c;
  cin >> a >> b >> c;

  if (a < b && b < c )
  {
  	cout << "Yes"<< endl;
  }

  else 
  {
  	cout << "No" << endl;
  }

}


Measured memory_bytes: 3104
#!/usr/bin/env python3
N, M = map(int, input().split())
ans = [None] * N
flag = True
for i in range(M):
    s, c = map(int, input().split())
    s -= 1
    if ans[s] == None:
        ans[s] = str(c)
    elif ans[s] != str(c):
        flag = False
if flag == False:
    print(-1)
    exit()
if N != 1 and ans[0] == str(0):
    print(-1)
    exit()
for i in range(N):
    if ans[i] == None:
        ans[i] = str(0)
    if (i == 0 and ans[0] == str(0) and N != 1):
        ans[0] = str(1)
print(''.join(ans))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (ll)(1E9+7)
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}

int main() {
	int n,a=0,b=0;
	cin >> n;
	vi v(n);
	rep(i, n) {
		cin >> v[i];
	}
	sort(all(v),greater<int>());
	for(int i=0;i<n;i++){
		if ((i+1) % 2) {
			a += v[i];
		}
		else {
			b += v[i];
		}
	}
	cout << a - b << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;


vector<int> v[1010];
int a[1010];
pint dfs(int x){
    if(v[x].empty())return {0,a[x]};
    bitset<5050> b=1;
    int sum=0;
    for(auto to:v[x]){
        pint p=dfs(to);
        if(p.first==-1)return {-1,-1};
        b=(b<<p.first|b<<p.second);
        sum+=p.first+p.second;
    }
    for(int i=a[x];i>=0;i--){
        if(b[i])return {a[x],sum-i};
    }
    return {-1,-1};
}

int main(){
    int n;cin>>n;
    rep(i,n-1){
        int x;cin>>x;
        v[x-1].push_back(i+1);
    }
    rep(i,n)cin>>a[i];
    if(dfs(0).first==-1)cout<<"IM";
    cout<<"POSSIBLE"<<endl;
    return 0;
}

Measured memory_bytes: 1664
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

void solve()
{
	int A, B, C, D;
	cin >> A >> B >> C >> D;

	while(A * C > 0)
	{
		C -= B;
		if (C <= 0)
		{
			cout << "Yes" << endl;
			return;
		}

		A -= D;
		if (A <= 0)
		{
			cout << "No" << endl;
			return;
		}
	}
}

int main()
{
	solve();

	return 0;
}

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

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(A: int, B: int, C: int):
    grp = {A, B, C}
    if len(grp) == 2:
        print(YES)
    else:
        print(NO)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    solve(A, B, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<int> data(M);
  ll sum = 0;
  for (int i = 0; i < M; i++)
  {
    cin >> data.at(i);
    sum += data.at(i);
  }
  ll ans = N - sum;
  if(ans<0){
    cout << -1 << endl;
  }else{
    cout << ans << endl;
  }
  return 0;
}

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

#define G1 1
#define G2 2
#define G3 3

using namespace std;

int main(void) {
	int i, x, y;
	string ans;
	vector<int> group(12);
	cin >> x >> y;
	ans = "No";
	group[0] = G1;
	group[2] = G1;
	group[4] = G1;
	group[6] = G1;
	group[7] = G1;
	group[9] = G1;
	group[11] = G1;
	group[3] = G2;
	group[5] = G2;
	group[8] = G2;
	group[10] = G2;
	group[1] = G3;
	if (group[x - 1] == group[y - 1]) {
		ans = "Yes";
	}
	cout << ans << endl;
	return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>							
typedef long long ll;
#define pb push_back
#define mod 1000000007ll
const ll maxn = 9e18;
using namespace std;
const ll maxsize = 100000009;

void solve() {
	int n;
	string s, t;
	cin >> n >> s;
	t = s.substr(n / 2);
	if(1 & n) {
		cout << "No" << endl;
		return;
		}
	for(int i = 0; i < n / 2; ++i) {
		if(s[i] != t[i]) {
			cout << "No" << endl;
			return;
			}
		}
		cout <<"Yes" << endl;
	}

int main() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cout.precision(35);
	solve();
	return 0;
}
 
 
 



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

using pii = pair<int, int>;

int main() {
    int r, c, n; cin >> r >> c >> n;
    auto on_bound = [&] (int x, int y) {
        return x == 0 || y == 0 || x == r || y == c;
    };
    auto to_one_dim = [&] (int x, int y) {
        if(x == 0) {
            return y;
        } else if(y == c) {
            return x + c;
        } else if(x == r) {
            return c - y + c + r;
        } else {
            return r - x + c + r + c;
        }
    };
    vector<pii> ps;
    for(int i = 0; i < n; ++i) {
        int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
        if(!on_bound(x1, y1) || !on_bound(x2, y2)) continue;
        ps.emplace_back(to_one_dim(x1, y1), i);
        ps.emplace_back(to_one_dim(x2, y2), i);
    }
    sort(begin(ps), end(ps));

    vector<int> st;
    vector<bool> appear(n);
    bool ok = true;
    for(auto const& p : ps) {
        if(!appear[p.second]) {
            st.push_back(p.second);
            appear[p.second] = true;
        } else { // pop
            if(st.back() != p.second) {
                ok = false;
                break;
            }
            st.pop_back();
        }
    }

    if(ok) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 2420
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <array>

using namespace std;

#define forange(counter, end) forstep(counter, 0, end)
#define forstep(counter, begin, end) forstep_type(size_t, counter, begin, end)
#define forange_type(type, counter, end) forstep_type(type, counter, 0, end)
#define forstep_type(type, counter, begin, end) for (type counter = begin, forstep_type_end_##counter = end; counter < forstep_type_end_##counter; counter++)

const int D = 365;
const int C = 26;

array<int, C> contest;
array<array<int, C>, D> satisfaction;

int decr(const int c, const int last, const int now) {
	return contest[c] * (now - last);
}

int getScore(const array<int, C>& last, const int open, const int day) {

	int score = 0;

	forange(c, C)
	{
		if (c == open)
		{
			score += satisfaction[day][c];
		}
		else
		{
			score -= decr(c, last[c], day);
		}
	}

	return score;
}

int getScore(const array<int, D>& cont) {

	int score = 0;
	array<int, C> last;
	last.fill(-1);

	forange(d, D)
	{
		score += getScore(last, cont[d], d);
		last[cont[d]] = d;
	}

	return 1000000 + score;
}

struct Data {
	array<int, C> last;
	array<int, D> c;
	int score = 0;

	bool operator<(const Data& o) const {
		return score < o.score;
	}
};

array<int, D> think() {

	priority_queue<Data> qData;
	{
		Data first;
		first.last.fill(-1);

		qData.push(first);
	}

	const int BeamWidth = 80;

	forange(d, D)
	{
		decltype(qData) next;
		forange(w, BeamWidth)
		{
			if (qData.empty()) break;

			const auto top = qData.top();
			qData.pop();

			forange(c, C)
			{
				Data nextData = top;
				const int score = getScore(nextData.last, c, d);

				nextData.last[c] = d;
				nextData.c[d] = c;
				nextData.score += score;

				next.push(nextData);
			}

		}

		qData.swap(next);
	}

	const auto& top = qData.top();

	cerr << "score:" << getScore(top.c) << endl;

	return top.c;
}

int main() {

	int d;
	cin >> d;

	for (auto& c : contest)
	{
		cin >> c;
	}

	forange(d, D)
	{
		forange(s, C)
		{
			cin >> satisfaction[d][s];
		}
	}

	const auto ans = think();

	for (const auto& a : ans)
	{
		cout << (a + 1) << endl;
	}

	return 0;
}


Measured memory_bytes: 16064
#include <stdio.h>
#include <ctype.h>
 
int main()
{
    int ch;
    while((ch=getchar()) != EOF) {
        if(isupper(ch)) putchar(tolower(ch));
        else if(islower(ch)) putchar(toupper(ch));
        else putchar(ch);
        if(ch=='\n') break;
    }
    return 0;
}

Measured memory_bytes: 524
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    r = f()[0]

    if r<1200:
        print('ABC')
    elif r<2800:
        print('ARC')
    else:
        print('AGC')

solve()


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
using ll = long long;

unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

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

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll a, n, b, k;
    cin >> n >> a >> b >> k;
    ll ans = 0;
    vector<ll> bik(n+1);
    bik.at(0) = 1;

    for (int i = 0; i < n; i++) {
        bik.at(i + 1) = bik.at(i) * (i + 1) % 998244353;
    }

    for (int i = 0; i < n+1; i++) {
        if ((k - a * i) % b == 0 && k >= a * i && (k - a * i) / b <= n) {
            ll z = (k - a * i) / b;
            ans += bik.at(n) * modinv(bik.at(i), 998244353) % 998244353 * modinv(bik.at(n - i), 998244353) % 998244353 * bik.at(n) % 998244353 * modinv(bik.at(z), 998244353) % 998244353 * modinv(bik.at(n - z), 998244353) % 998244353;
            ans %= 998244353;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    string s;
    cin>>s;
    stack<char>st;
    int cnt=0;
    for(int i=0;i<s.length();i++){
        if(st.size()==0){
            st.push(s[i]);
        }
        else{
            if(st.top()=='0' && s[i]=='1'){
                st.pop();
                cnt+=2;
            }
            else if(st.top()=='1' && s[i]=='0'){
                 st.pop();
                 cnt+=2;
            }
            else
                st.push(s[i]);
        }
    }
    cout<<cnt<<endl;

    return 0;
}


Measured memory_bytes: 3780
#include <bits/stdc++.h>
#define ll long long
#define N 100005
#define f first
#define PI 3.14159265
#define s second
using namespace std;
int main() {
    double a,b,x;
    cin>>a>>b>>x;
    if(2*x<=a*a*b)
        cout<<fixed<<setprecision(12)<<atan(a*b*b/(2*x))*180/PI;
    else
        cout<<fixed<<setprecision(12)<<atan((2*b-2*x/(a*a))/a)*180/PI;
    return 0;
}


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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int []l = new int[3];
			for(int i = 0; i < 3; i++) {
				l[i] = sc.nextInt();
			}
			Arrays.sort(l);
			if(l[0] == 0) break;
			StringBuilder sb = new StringBuilder();
			int n = sc.nextInt();
			for(int i = 0; i < n; i++) {
				int r = sc.nextInt();
				if(l[0] * l[0] + l[1] * l[1] < 4 * r * r) {
					sb.append("OK");
				}else {
					sb.append("NA");
				}
				sb.append("\n");
			}
			System.out.print(sb.toString());
		}
		sc.close();
	}
}


Measured memory_bytes: 26264
#include <stdio.h>

int main(){

  int array[124] = {};
  int i,j,v = 0,n,k;
  scanf("%d",&n);
  
  for(i = 0;i < n;i++){
    scanf("%d",&array[i]);
  }

  for(i = 1;i <= n;i++){
    v = array[i];
    j = i - 1;
    for(k = 0;k < n;k++){
      if (k != n - 1) printf("%d ",array[k]);
      else printf("%d",array[k]);
    }
    printf("\n");
    
    while(j >= 0 && array[j] > v){
      array[j + 1] = array[j];
      j--;
      array[j + 1] = v;
    }
  }

  return 0;
}

Measured memory_bytes: 2708
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

signed main(){

	string s;
	cin>>s;

	lli cnt=0;
	lli last=s.size()-1;
	for(lli i=s.size()-1;i>=0;i--){
		if(s.at(i)=='B'){
			cnt += (last-i);
			last--;
		}
	}
	cout<<cnt<<endl;

	return 0;
}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-
"""
Created on Sun Mar  3 20:59:27 2019

@author: doppe
"""
A, B, K = map(int, input().split())

num = 0
if (A > B):
    max = A
else:
    max = B

for i in range(max, 0, -1):
    if (A % i == 0 and B % i == 0):
        num += 1
    if (num == K):
        break

print(i)

Measured memory_bytes: 3060
N,M=map(int,input().split())
s=[0]*M
c=[0]*M
for i in range(M):
    s[i],c[i]=map(int,input().split())
ans=['#' for i in range(N+1)]

for i in range(M):
    if(ans[s[i]]=='#'):
        ans[s[i]]=str(c[i])
    for j in range(i+1,M):
        if(s[i]==s[j]):
            if(c[i]!=c[j]):
                print('-1')
                exit()

if(2<=N):
    if(ans[1]=='#'):
        ans[1]='1'
    elif(ans[1]=='0'):
        print('-1')
        exit()
else:
    if(ans[1]=='#'):
        ans[1]=0
        pass
    print(ans[1])
    exit()
a=ans[1:]

a=''.join(a).replace('#','0')
print(a)


Measured memory_bytes: 62140
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] str = (br.readLine()).split(" ");
		int[] a = new int[n];
		int cnt = 0;
		for (int i = 0; i < n; i++)
			a[i] = Integer.parseInt(str[i]);
		for (int i = 0; i < n; i++) {
			int minj = i;
			for (int j = i; j < n; j++) {
				if (a[j] < a[minj]) {
					minj = j;
				}
			}
			if (a[i] != a[minj]) {
				int tmp = a[i];
				a[i] = a[minj];
				a[minj] = tmp;
				cnt++;
			}
		}
		for (int i = 0; i < n; i++){
			if(i!=n-1)System.out.print(a[i] + " ");
			else System.out.println(a[i]);
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 24168
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=0
for i in range(n):
    if(i!=0 and a[i-1]+1==a[i]):
        ans+=c[a[i-1]-1]
    ans+=b[a[i]-1]
print(ans)

Measured memory_bytes: 9196
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int MAXN = 524300;

int n;
LL pre[MAXN],a[MAXN];
LL f[MAXN],g[MAXN],S[MAXN];
LL fm[MAXN],gm[MAXN];
LL val[MAXN],pv[MAXN];
int top,sta[MAXN];

LL maxll(LL x,LL y){return x>=y?x:y;}

db calc(int x,int y){return 1.0*(S[y]-S[x])/(y-x);}

void solve(LL *f){
	sta[top=1]=0;
	fo(i,1,n){
		f[i]=f[i-1];
		int l=1,r=top,w;
		while(l<=r){
			int mid=(l+r)/2;
			db val=mid==top?0:calc(sta[mid],sta[mid+1]);
			if (val<i)w=mid,r=mid-1;
			else l=mid+1;
		}
		w=sta[w];
		f[i]=maxll(f[i],f[w]+1ll*(i-w)*(i-w+1)/2-pre[i]+pre[w]);
		S[i]=f[i]+1ll*i*(i-1)/2+pre[i];
		while(top>1&&calc(sta[top-1],sta[top])<calc(sta[top],i))top--;
		sta[++top]=i;
	}
}

void prepare(){
	solve(f);
	fo(i,1,n/2)swap(a[i],a[n-i+1]);
	fo(i,1,n)pre[i]=pre[i-1]+a[i];
	solve(g);
	fo(i,1,n/2)swap(g[i],g[n-i+1]);
	fo(i,1,n/2)swap(a[i],a[n-i+1]);
	fo(i,1,n)pre[i]=pre[i-1]+a[i];
	fo(i,1,n)fm[i]=maxll(fm[i-1],f[i]);
	fd(i,n,1)gm[i]=maxll(gm[i+1],g[i]);
}

int k;

LL cc(int l,int r){
	LL tmp=-1e+14;
	fo(i,l,r){
		int L=1,R=top,w;
		while(L<=R){
			int Mid=(L+R)/2;
			db val=Mid==top?0:calc(sta[Mid],sta[Mid+1]);
			if (val<i)w=Mid,R=Mid-1;
			else L=Mid+1;
		}
		w=sta[w];
		tmp=maxll(tmp,f[w]+g[i]+1ll*(i-w)*(i-w-1)/2-pre[i-1]+pre[w]);
	}
	return tmp;
}

void solve(int l,int r,LL qv){
	if (l==r){
		val[l]=qv;
		int i=l;
		S[i]=f[i]+1ll*i*(i+1)/2+pre[i];
		while(top>1&&calc(sta[top-1],sta[top])<calc(sta[top],i))top--;
		sta[++top]=i;
		return;
	}
	int mid=(l+r)/2;
	LL ql=maxll(qv,cc(mid+1,r));
	solve(l,mid,ql);
	solve(mid+1,r,qv);
}

void work(){
	for(int T=get();T;T--){
		int x=get(),v=get();
		LL ans=maxll(val[x]+a[x]-v,fm[x-1]+gm[x+1]);
		printf("%lld\n",ans);
	}
}

int main(){
	n=get();
	fo(i,1,n)a[i]=get();
	int N=1;
	while(N<=n)N<<=1;
	fo(i,n+1,N)a[i]=1e+9;
	fo(i,1,N)pre[i]=pre[i-1]+a[i];
	n=N;
	prepare();
	sta[top=1]=0;
	solve(1,n,-1e+14);
	fo(i,1,n)pv[i]=val[i];
	fo(i,1,n/2){
		swap(f[i],f[n-i+1]);
		swap(g[i],g[n-i+1]);
		swap(a[i],a[n-i+1]);
	}
	fo(i,1,n)swap(f[i],g[i]);
	fo(i,1,n)pre[i]=pre[i-1]+a[i];
	sta[top=1]=0;
	solve(1,n,-1e+14);
	fo(i,1,n/2)swap(val[i],val[n-i+1]);
	fo(i,1,n)val[i]=maxll(val[i],pv[i]);
	fo(i,1,n/2)swap(a[i],a[n-i+1]);
	work();
	return 0;
}

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

// ----------- define --------------
#define int long long
#define vi vector<int>
#define vc vector<char>
#define mii map<int,int>
#define ii pair<int,int>
#define fi first
#define sc second
#define all(x) (x).begin(),(x).end()
#define get_bit(x, k) ((x >> k) & 1)
// ---------------------------------

void MAIN() {
  struct tup {
    int fi, sc, th;
    tup() {}
    tup(int fi, int sc, int th):
      fi(fi), sc(sc), th(th) {}
  };
  int n; cin >> n;
  vector<tup> a(n);
  tup g(-1, -1, -1);
  for (auto &i : a) {
    cin >> i.fi >> i.sc >> i.th;
    if (i.th >= 1) g = i;
  }
  for (int i = 0; i <= 100; i++)
  for (int j = 0; j <= 100; j++) {
    int h = g.th + abs(i - g.fi) + abs(j - g.sc);
    int f = 0;
    for (auto &k : a) {
      int dh = h - abs(i - k.fi) - abs(j - k.sc);
      dh = max(dh, 0ll);
      if (dh != k.th) {
        f = 1;
        break;
      }
    }
    if (!f) {
      cout << i << ' ' << j << ' ' << h << '\n';
      return;
    }
  }
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3692
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000
#define MAXN 128
typedef long long ll;

ll dp[MAXN][21];
int N, a[MAXN];

int main(void) {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    dp[0][a[0]] = 1;
    for (int i = 0; i < N-1; i++) {
        for (int j = 0; j <= 20; j++) {
            if (j - a[i+1] >= 0) {
                dp[i+1][j] += dp[i][j-a[i+1]];
            }
            if (j + a[i+1] <= 20) {
                dp[i+1][j] += dp[i][j+a[i+1]];
            }
        }
    }
    if (0 <= a[N-1] && a[N-1] <= 20) cout << dp[N-2][a[N-1]] << endl;
    else cout << 0 << endl;
    return 0;
}

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

int main()
{
	int n,m,temp;
	cin>>n>>m;
	
	int sum=0;
	for(int i=1;i<=m;i++)
	{
		cin>>temp;
		sum+=temp;
	}
	if(n>=sum)
		cout<<n-sum<<endl;
	else
		cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 3632
function Main(input) {
	// n is the first element
	var splitInput = input.split("\n");
	var n = parseInt(splitInput[0])
	
	// plate array is [ aHappiness, bHappiness, sumABHappiness ] sorted by sumABHappiness
	var plateArray = splitInput.slice(1).map(function(e){
		var splitab = e.split(" ")
		return [parseInt(splitab[0]),parseInt(splitab[1]),parseInt(splitab[0])+parseInt(splitab[1])]
	}).sort(function(x,y) {
		if (x[2] > y[2]) {
			return (-1) // desc order
		}
		if (x[2] < y[2]) {
			return 1 // desc order
		}
		  return 0;
	})
	
	var aHappiness = 0
	var bHappiness = 0
	
	for (var i=0; i<n; i++){
		if (i%2 == 0) {
			aHappiness += plateArray[i][i%2]
		} else {
			bHappiness += plateArray[i][i%2]
		}
	}
	
	//output
	console.log(aHappiness-bHappiness)
}

// HOTFIX: If the I add the last \n even if the loop never goes to the last element of the list, an NaN error is thrown
var str = require("fs").readFileSync("/dev/stdin", "utf8")
Main(str.substring(0,str.length-1));

Measured memory_bytes: 56244
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		long[][] dp=new long[n+2][n+2];
		int[][] s=new int[n+1][n+1];
		long[] a=new long[n+1];
		for (int i=1;i<=n;++i)
			for (int j=i;j<=n;++j)
				dp[i][j]=Long.MAX_VALUE;
		for (int i=1;i<=n;++i) {
			a[i]=in.nextLong()+a[i-1];
			dp[i][i]=0;
			s[i][i]=i;
		}
		for (int l=1;l<n;++l)
			for (int i=1;i+l<=n;++i) {
				int j=i+l;
				for (int k=s[i][j-1];k<=s[i+1][j];++k)
					if (dp[i][j]>dp[i][k]+dp[k+1][j]+a[j]-a[i-1]) {
						s[i][j]=k;
						dp[i][j]=dp[i][k]+dp[k+1][j]+a[j]-a[i-1];
					}
				}
		System.out.println(dp[1][n]);
	}
}

Measured memory_bytes: 24276
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  int b[n - 1];
  REP(i, n - 1) {
    cin >> b[i];
  }
  ll sum = 0;
  if (n == 2) {
    sum += 2 * b[0];
    cout << sum << endl;
    return 0;
  }
  REP(i, n - 1) {
    if (i == 0) sum += b[0];
    else if (b[i - 1] <= b[i]) sum += b[i - 1];
    else if (b[i - 1] == b[i]) sum += b[i - 1];
    else sum += b[i];
  }
  sum += b[n - 2];

  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#include <climits>
#include <random>

#define ll long long

using namespace std;

struct item {
    int w;
    int c;
};

int main() {
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
    int n, k;
    scanf("%d %d", &n, &k);
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        scanf("%d", &a[i]);
    vector<bool> dp(k + 1);
    for (int remStones = 1; remStones <= k; remStones++) {
        for (int val : a) {
            if (val <= remStones && !dp[remStones - val])
                dp[remStones] = true;
        }
    }
    if (dp[k])
        printf("First");
    else
        printf("Second");
    return 0;
}

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

int main()
{
  int p,q,r;
  int x,y,z;
  cin >> p >> q >> r;
  x = p + q;
  y = q + r;
  z = r + p;
  
  if(x <= y){
      if(x <= z){
          cout << x;
      }
      else{
          cout << z;
      }
  }
  else{
      if(y <= z){
          cout << y;
      }
      else{
          cout << z;
      }
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>
#include <random>
//#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using pil = std::pair<int, long long>;
using pli = std::pair<long long, int>;
using plpii = std::pair<long long, std::pair<int, int>>;
using pdd = std::pair<double, double>;
using pis = std::pair<int, std::string>;

const long long INF = 1000000000000000001;
const long long _MOD_ = 1000000000000000009;
const long long _MOD = 1000000007;
const long long MOD = 998244353;
const int ALPHABET = 27;
const double pi = 3.14159265358979;

using namespace std;
//namespace mp = boost::multiprecision;

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

	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(max(a*c, a*d), max(b*c, b*d)) << "\n";

	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5 + 5, mod = 1e9 + 7;


int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n, k;
    cin >> n >> k;
    int cnt = 0;
    while(n){
        n/=k;
        cnt++;
    }
    cout << cnt;

    return 0;
}


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

int main()
{
	int n;
	cin >> n;
	int a[101];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int k = 0; k < n - 1; k++)
	{
		cout << a[k] << " ";
	}
	cout << a[n - 1] << endl;
	for (int i = 1; i < n; i++)
	{
		int v = a[i];
		int j = i - 1;
		while (j >= 0 && a[j] > v)
		{
			a[j + 1] = a[j--];
			a[j + 1] = v;
		}
		for (int k = 0; k < n-1; k++)
		{
			cout << a[k] << " ";
		}
		cout << a[n - 1] << endl;
	}
	return 0;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

ll my_sqrt(ll x) {
	ll sq = (ll)sqrt(x + 0.5);
	sq = max(sq - 10, 0ll);
	for(; sq * sq <= x; sq++);
	return sq - 1;
}

void solve(){
	ll s;
	cin >> s;
	ll sq = my_sqrt(s);
	ll dif = 0ll;
	if (sq * sq < s) {
		sq++;
		dif = sq * sq - s;
	}
	ll a = sq, b = sq, c = dif;
	if (dif > 1e9) {
		a = sq;
		b = sq;
		while(dif > 1e9) {
			b--;
			dif -= sq;
		}
	}
	printf("%lld %lld %lld %lld %lld %lld\n", 0ll, 0ll, a, dif, 1ll, b);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 256
N = int(input())
AB = []
for i in range(N):
    a,b = map(int,input().split())
    AB.append([a,b,a+b])

AB = sorted(AB, key=lambda x:x[2]*(-1))

A = 0
B = 0
for i in range(N):
    if i%2==0:
        A += AB[i][2]
    B += AB[i][1]
        
print(A-B)

Measured memory_bytes: 29264
#include<cstdio>
double ni(int n){
    double ret=1.0;
    if(n>=0){
        for(int i=0;i<n;i++){
            ret*=2;
        }
    }else{
        for(int i=0;i>n;i--){
            ret/=2;
        }
    }
    return ret;
}
int main(){
    double ins;
    for(;;){
        scanf("%lf",&ins);
        if(ins<0) break;
        int ar[12];
        for(int i=7;i>=-4;i--){
            double r=ni(i);
            if(ins>=r){
                ar[i+4]=1;
                ins-=r;
            }else{
                ar[i+4]=0;
            }
        }
        if(ins==0){
            for(int i=7;i>=0;i--){
                printf("%d",ar[i+4]);
            }
            printf(".");
            for(int i=-1;i>=-4;i--){
                printf("%d",ar[i+4]);
            }
            printf("\n");
        }else printf("NA\n");
    }
}

Measured memory_bytes: 0
//
// Created by yamunaku on 2019/12/09.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

ll modpow(ll x, ll a){
    ll ans=1;
    while(a){
        if(a&1) ans=ans*x%MOD;
        a>>=1;
        x=x*x%MOD;
    }
    return ans;
}

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


int main(){
    // CFS;
    int n;
    cin >> n;
    vl a(n);
    rep(i,n) cin >> a[i];
    ll ans = 0;
    rep(i,60){
        ll x=0, y=0;
        rep(j,n){
            if(a[j]&(1ll<<i)) x++;
            else y++;
        }
        ans = (ans + x*y%MOD*modpow(2, i)%MOD)%MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		String s = sc.next();
		
		String s2 = s.substring(0, a);
		String s3 = s.substring(a, a + 1);
		String s4 = s.substring(a + 1);
		
		
 
        // 正規表現のパターンを作成
        Pattern p = Pattern.compile("^[0-9]+$");
        Matcher m = p.matcher(s2);
        Matcher m2 = p.matcher(s4);
 
        if (m.find() && s3.equals("-") && m2.find()) System.out.println("Yes");
        else System.out.println("No");
        
	}
}

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

def main():
    Q = int(input())
    lr = [list(map(int, input().split())) for i in range(Q)]

    MAX = int(1e5)
    MAX_PRIME = MAX
    primes = []
    is_prime = [True] * (MAX_PRIME+1)
    for i in range(2, MAX_PRIME+1):
        if is_prime[i]:
            primes.append(i)
            for j in range(2*i, MAX_PRIME+1, i):
                is_prime[j] = False
    count = [0] * (MAX+1)
    for p in primes:
        if p&1:
            tmp = (p + 1) // 2
            if is_prime[tmp]:
                count[p] = 1
    for i in range(1, MAX+1):
        count[i] += count[i-1]
    
    # print(count[:10])
    for i in range(Q):
        l, r = lr[i]
        print(count[r] - count[l-1])
    



if __name__ == "__main__":
    main()

Measured memory_bytes: 32348
n,m,c= map(int, input().split())
multi= list(map(int, input().split()))

count=0
for i in range(n):
  ans= 0
  x = list(map(int, input().split()))
  for i in range(m):
    ans+= (x[i]*multi[i])
  if(ans> -c):
    count+= 1
print(count)

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

int main()
{
   
  	ll n,k;
  	cin>>n>>k;
   	ll w[n+1],v[n+1];
   	w[0]=0;
   	v[0]=0;
   	for (int i = 1; i <=n; ++i)
   	{
   		cin>>w[i]>>v[i];
   	}

   	ll dp[n+1][k+1];

   	for (int i = 0; i <=n ; ++i)
   	{
   		for (int j = 0; j <=k ; ++j)
   		{
   			if(j==0||i==0)
   				dp[i][j]=0;
   			else if(j>=w[i])
   			{
   				dp[i][j]=max(dp[i-1][j],v[i]+dp[i-1][j-w[i]]);
   			}
   			else
   			{
   				dp[i][j]=dp[i-1][j];
   			}
   		}
   	}
   	
   	
   	cout<<dp[n][k];
}



Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main(void) {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, m;
    cin >> n >> m;
    priority_queue<int> pq;
    while(n--) {
        int now;
        cin >> now;
        pq.push(now);
    }
    while(m--) {
        int now = pq.top();
        pq.pop();
        pq.push(now / 2);
    }
    ll ans = 0;
    while(!pq.empty()) {
        ans += pq.top();
        pq.pop();
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 892
n,m,k=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

a,b=[0],[0]
for i in range(n):
    a.append(a[i]+A[i])
for i in range(m):
    b.append(b[i]+B[i])

j,ans=m,0
for i in range(n+1):
    if a[i]>k:
        break
    while b[j] > k-a[i]:
        j-=1
    ans=max(ans,i+j)
print(ans)

Measured memory_bytes: 47460