akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define re register
#define LL long long
inline int read() {
	char c=getchar();int x=0;while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+c-48,c=getchar();return x;
}
const LL inf=1e15;
const int maxn=2e5+5;
int l[maxn<<2],r[maxn<<2];LL mx[maxn<<2][2],tag;
int pos[maxn],d[maxn],n,A,B,Q;
inline LL min(LL a,LL b) {return a<b?a:b;}
void build(int x,int y,int i) {
	l[i]=x,r[i]=y;mx[i][0]=mx[i][1]=inf;
	if(x==y) {pos[x]=i;return;}
	int mid=x+y>>1;
	build(x,mid,i<<1),build(mid+1,y,i<<1|1);
}
void change(int x,LL v,int o) {
	x=pos[x];mx[x][o]=min(v,mx[x][o]);x>>=1;
	while(x) mx[x][o]=min(mx[x][o],v),x>>=1;
}
LL query(int x,int y,int i,int o) {
	if(x<=l[i]&&y>=r[i]) return mx[i][o];
	int mid=l[i]+r[i]>>1;LL now=inf;
	if(x<=mid) now=min(now,query(x,y,i<<1,o));
	if(y>mid) now=min(now,query(x,y,i<<1|1,o));
	return now;
}
inline LL ABS(LL x) {return x>=0?x:-x;}
int main() {
	n=read(),Q=read(),A=read(),B=read();
	for(re int i=1;i<=Q;i++) d[i]=read();
	build(1,n,1);
	change(A,ABS(d[1]-B)+A,0);change(A,ABS(d[1]-B)-A,1);
	change(B,ABS(d[1]-A)+B,0);change(B,ABS(d[1]-A)-B,1);
	for(re int i=2;i<=Q;i++) {
		LL x=query(d[i],n,1,0)-d[i],y=query(1,d[i],1,1)+d[i];
		x=min(x,y);
		LL a=min(mx[pos[d[i-1]]][0]-d[i-1],mx[pos[d[i-1]]][1]+d[i-1]);
		if(x<a+ABS(d[i]-d[i-1])) {
			x+=tag;tag+=ABS(d[i]-d[i-1]);x-=tag;
			change(d[i-1],x+d[i-1],0),change(d[i-1],x-d[i-1],1);
		}
		else tag+=ABS(d[i]-d[i-1]);
	}
	LL ans=inf;
	for(re int i=1;i<=n;i++) {
		int x=pos[i];
		ans=min(ans,mx[x][1]+i);
	}
	printf("%lld\n",ans+tag);
	return 0;
}

Measured memory_bytes: 17408
#include <stdio.h>

int A[10000000];
int n;

int BS(int key)
{
	int l=0;
	int r=n;
	int m;
	
	while (l<r){
		m=(l+r)/2;
		if(key==A[m])
		{
			return 1;
		}
		if(key>A[m])
		{
			l=m+1;
		}
		else if(key<A[m])
		{
			r=m;
		}
	}
	return 0;
}


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




Measured memory_bytes: 2108
if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))
    a = sorted(a)

    huru = [False] * (10 ** 6 + 1)
    visited = [False] * (10 ** 6 + 1)
    for i in range(n):
        if huru[a[i]]:
            continue

        if visited[a[i]]:
            huru[a[i]] = True
        tmp = a[i] * 2
        while tmp <= 10 ** 6:
            huru[tmp] = True
            tmp += a[i]
        visited[a[i]] = True

    ans = 0
    for i in range(n):
        if not huru[a[i]]:
            ans += 1
    print(ans)

Measured memory_bytes: 35616
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
bool bo[100];
#define ll long long int
int main()
{
	ll n,x;
	cin>>n>>x;
	ll a[n+10];
	for(ll i=0;i<n;i++) cin>>a[i];
	ll re=0;
	if(a[0]>x)
	{
		re=a[0]-x;
		a[0]=x;
	}
	for(ll i=0;i<n-1;i++)
	{
		if((a[i]+a[i+1])>x)
		{
			ll q1=x-a[i];
			ll q2=a[i+1]-q1;
			re+=q2;
			a[i+1]=q1;
		}
	}
	cout<<re<<endl;
}


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

void Main() {
    // input
    u_int64_t A, B, N;
    cin >> A >> B >> N;

    // translate
    u_int64_t ans = 0;
    if (B == 1) {
        cout << 0 << endl;
        return;
    }

    if (N < B) {
        cout << (A * N) / B << endl;
        return;
    }

    for (u_int64_t x = B-1; x <= N; x += B) {
        u_int64_t num = (A * x) / B - A * (x / B);
        ans = max(ans, num);
    }


    // output
    cout << ans << endl;

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3608
#include <stdio.h>
#define H 250

int main(){
    int A[H], i, n, p, l, r; //l means left index, r is right one 

    //input
    scanf("%d", &n);
    for(i = 1; i<n+1; i++) scanf("%d", &A[i]);

    //print
    for(i = 1; i<=n; i++){
	p = i / 2;
	l = 2 * i;
	r = l + 1;
	printf("node %d: key = %d, ", i, A[i]);
	//when the node has an parent
	if(i != 1) printf("parent key = %d, ", A[p]);
	//when the node has left key
	if(l <= n) printf("left key = %d, ", A[l]);
	//when the node has right key
	if(r <= n) printf("right key = %d, ", A[r]);
	printf("\n");
    }
    return 0;
}



Measured memory_bytes: 2108
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
#define MP make_pair
#define F first
#define S second
using namespace std;
typedef long long ll;
int h, w, k;
char c[330][330];
int ans[330][330], num[330];

int main () {
	ios::sync_with_stdio(false);
	cin >> h >> w >> k;
	int id = 0;
	int first = 1e9;
	for (int i = 1; i <= h; i ++) {
		int st = -1;
		for (int j = 1; j <= w; j ++) {
			cin >> c[i][j];
			if (c[i][j] == '#') {
				id ++, num[i] ++;
				if (st == -1) {
					st = 0;
					for (int l = 1; l < j; l ++)
						ans[i][l] = id;
				}
			}
			// cerr << i << " " << j << " : " << id << endl;
			ans[i][j] = id;
		}
		if (!num[i]) {
			for (int j = 1; j <= w; j ++)
				ans[i][j] = ans[i - 1][j];
		}
		else
			first = min (first, i);
	}
	for (int i = 1; i < first; i ++)
		for (int j = 1; j <= w; j ++)
			ans[i][j] = ans[first][j];
	for (int i = 1; i <= h; i ++) {
		for (int j = 1; j <= w; j ++)
			cout << ans[i][j] << " ";
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<map>

using namespace std;

int main(){
	long long n, k, ans = 0;
	cin >> n >> k;
	map<int, long long> mp;
	for(int i = 0; i < n; i++){
		int a, b;
		cin >> a >> b;
		mp[a] += b;
	}
	long long sum = 0;
	for(auto&& i : mp){
		sum += i.second;
		if(sum >= k){
			ans = i.first;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4224
n=int(input())
a=[]
b=[]
c=[]

for _ in range(n):
	tmp=list(map(int,input().split()))
	a.append(tmp[0])
	b.append(tmp[1])
	c.append(tmp[2])
dp=[[0 for j in range(n)]for i in range(3)]
dp[0][0]=a[0]
dp[1][0]=b[0]
dp[2][0]=c[0]
for i in range(1,n):
	dp[0][i]=a[i]+max(dp[1][i-1],dp[2][i-1])
	dp[1][i]=b[i]+max(dp[2][i-1],dp[0][i-1])
	dp[2][i]=c[i]+max(dp[0][i-1],dp[1][i-1])
print(max(dp[0][n-1],dp[1][n-1],dp[2][n-1]))


Measured memory_bytes: 32620
s = input();

v1 = [];
v2 = [];

rev = 0;

q = int(input());

for i in range(q):
    t = [i for i in input().split()];
    if t[0] == "1":
        rev = 1 - rev;
    else:
        if rev == 0:
            if t[1] == "1":
                v2.append(t[2]);
            else:
                v1.append(t[2]);
        else:
            if t[1] == "1":
                v1.append(t[2]);
            else:
                v2.append(t[2]);

res = "";

if rev == 0:
    v2.reverse();
    for i in v2:
        res += i;
    res += s;
    for i in v1:
        res += i;
else:
    v1.reverse();
    for i in v1:
        res += i;
    res += s[::-1];
    for i in v2:
        res += i;

print(res);




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

int main() {
int n;
cin >> n;
int one_rank = n % 10;

if (one_rank == 2 || one_rank==4|| one_rank==5|| one_rank==7|| one_rank==9){
  cout<<"hon" << endl;
}else if(one_rank == 3){
  cout << "bon" << endl;
}else{
  cout << "pon" << endl;
};
  return 0;
}


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

using namespace std;

typedef long long ll;
int main() {
    int a, b, x, y;
    scanf("%d%d%d%d", &a, &b, &x, &y);
    printf("%lf %d\n", double(a)*double(b) / 2, x + x == a&&y + y == b);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)

/* exchange */
#define chmin(a, b) (a) = min((ll)(a), (ll)(b))
#define chmax(a, b) (a) = max((ll)(a), (ll)(b))

/* output */
#define I(x) cin >> x;
#define D(x) cerr << (x) << " ";
#define BR cerr << "\n";
#define P(x) cout << (x) << endl;
#define FIX cout << fixed << setprecision(10);

/* const */
const int ARRAY = 100005;
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;

ll N = 0;
ll ret = 0;

int main(void){
  
  I(N);
  vl A(N);
  REP(i, N) {
    I(A[i]);
  }

  ll money = 1000;
  ll stock = 0;
  ll prev = A[0];
  bool up = false;

  FOR(i, 1, N) {
    ll now = A[i];
    if (!up && (now - prev > 0)) {
      // 上昇傾向への切り替わり = 買い
      stock += money / prev;
      money -= prev * stock;
      up = true;
    } else if (up && (now - prev < 0)) {
      money += prev * stock;
      stock = 0;
      up = false;
    }
    prev = now;
  }

  if (stock > 0) {
    money += A[N-1] * stock;
  }

  P(money);

}


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

#define int             long long int
#define ld              long double
#define ff              first
#define ss              second
#define mp              make_pair
#define pb              push_back
#define endl            "\n"

#define si              set <int>
#define vi              vector <int>
#define pii             pair <int, int>
#define vpii            vector <pii>
#define mii             map <int, int>
#define que_max         priority_queue <int>
#define que_min         priority_queue <int, vi, greater<int>>

#define loop(i,s,e)     for(int i=s;i<e;i++)
#define rloop(i,e,s)    for(int i=e;i>=s;i--)
#define mset(a,f)       memset(a,f,sizeof(a))


#define M               1000000007
#define sz(x)           ((int) x.size())
#define all(p)          p.begin(), p.end()

#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define Print(a,x,y)    for (int i=x; i<y; i++) cout<< a[i]<< " "; cout << endl

const int inf = INT_MAX;
const long long INF = LLONG_MAX;

inline int power(int a, int b)
{
	int x = 1;
	while (b)
	{
		if (b & 1) x *= a;
		a *= a;
		b >>= 1;
	}
	return x;
}

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 3e5 + 7;
vector <vi > adj(N);

bool vis[N];

int dp[105][4][2];
int k;
vi num;
// f==0 -> the digits so far in the seq we have built are all equal to corresponding digits in
// given no and f==1 -> represents f = the number we are building has already become
// smaller than b
int go(int pos, int cnt, int f)
{
	if (pos == (sz(num)) and cnt == k) return 1;
	if (pos == sz(num)) return 0;
	if (cnt > k) return 0;
	int &ans = dp[pos][cnt][f];
	if (ans != -1) return ans;
	int lmt;
	if (f == 0) lmt = num[pos];
	else lmt = 9;
	int res = 0;

	loop(i, 0, lmt + 1)
	{
		int nf = f;
		int ncnt = cnt;
		if (i != 0)
			ncnt++;
		if (i < num[pos])
			nf = 1;
		res += go(pos + 1, ncnt, nf);
	}
	return ans = res;
}
void solve()
{
	string n;
	cin >> n >> k;
	//bug(n);
	loop(i, 0, sz(n))
	{
		int x = n[i] - '0';
		num.pb(x);
	}
	//print(num);
	mset(dp, -1);
	cout << go(0, 0, 0);

	return;
}

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cout << setprecision(9) << fixed;

	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}


	return 0;
}


Measured memory_bytes: 7296
import java.util.*;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] b = new int[n-1];
        for(int i = 0;i < n-1;i++){
            b[i] = sc.nextInt();
        }

        long sum = b[0];
        for(int i = 1;i < n-1;i++){
            sum += Math.min(b[i], b[i-1]);
        }
        sum += b[n-2];
        System.out.println(sum);
    }
}

Measured memory_bytes: 21716
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>	
#include <cmath>
#include <string>
#include<math.h>
#include<sstream>//���炵���̂Œ���
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define Cout(s) cout<<s<<endl
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
string Yes(bool b) { if (b) { return "Yes"; } else { return "No"; } }
string YES(bool b) { if (b) { return "YES"; } else { return "NO"; } }
//================================================

int a = 1, b = 0, c, d, n, k = 0, ans = 0;
string s, t;
int mod = 1000000007;

int main()
{
	cin >> n >> s;
	string ans, xx = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
	rep(i, sz(s)) {
		ans += xx[s[i] - 'A' + n];
	}
	cout << ans << endl;

	return 0;
}


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

int main() {
  int N;
  cin >> N;
  int B[110];
  for(int i = 1; i <= N - 1; ++i) {
    cin >> B[i];
  }
  int score = 0;
  score += B[1];     // A[1];
  score += B[N - 1]; // A[N];
  for(int i = 1; i < N - 1; ++i) {
    score += min(B[i], B[i + 1]);
  }
  cout << score << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;
int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int dy[8] = {1, 1, 0, -1, -1, -1, 0, 1};

int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  cout << x2 + (y1 - y2) << " " << y2 - (x1 - x2) << " " << x1 + (y1 - y2)
       << " " << y1 - (x1 - x2) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MM 1000000000;
#define mod MM + 7;
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 100005
#define NIL -1
int main(){
    string s; cin >> s;
    int a, b, c, d;
    a = s[0] - '0';
    b = s[1] - '0';
    c = s[2] - '0';
    d = s[3] - '0';

    if(a+b+c+d == 7) cout << a << '+' << b << '+' << c << '+' << d << '=' << '7';
    else if(a+b+c-d == 7) cout << a << '+' << b << '+' << c << '-' << d << '=' << '7';
    else if(a+b-c+d == 7) cout << a << '+' << b << '-' << c << '+' << d << '=' << '7';
    else if(a-b+c+d == 7) cout << a << '-' << b << '+' << c << '+' << d << '=' << '7';
    else if(a+b-c-d == 7) cout << a << '+' << b << '-' << c << '-' << d << '=' << '7';
    else if(a-b+c-d == 7) cout << a << '-' << b << '+' << c << '-' << d << '=' << '7';
    else if(a-b-c+d == 7) cout << a << '-' << b << '-' << c << '+' << d << '=' << '7';
    else if(a-b-c-d == 7) cout << a << '-' << b << '-' << c << '-' << d << '=' << '7';
    cout << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<ll,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int H,W;
    cin>>W>>H;
    
    priority_queue<pii> que;
    rep(i,W){
        ll a; cin>>a;
        que.push({-a,0});
    }
    rep(i,H){
        ll a; cin>>a;
        que.push({-a,1});
    }
    
    H++,W++;
    ll sum=0;
    while(!que.empty()){
        pii p=que.top();que.pop();
        if(p.second==0){
            if(H<=0) continue;
            sum+=-1ll*p.first*H;
            W--;
        }else{
            if(W<=0) continue;
            sum+=-1ll*p.first*W;
            H--;
        }
    }
    cout1(sum)
}

Measured memory_bytes: 6512
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

H, N = MAP()
A = LIST()

if sum(A) >= H:
    Yes()
else:
    No()


Measured memory_bytes: 13960
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ZYCSwing
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        private static final int N = (int) 1e5 + 10;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            long c = in.nextLong();
            long[] x = new long[N];
            long[] y = new long[N];
            int[] v = new int[N];

            long[] ldp = new long[N];
            long[] rdp = new long[N];

            for (int i = 1; i <= n; ++i) {
                x[i] = in.nextLong();
                y[i] = c - x[i];
                v[i] = in.nextInt();
            }

            long res = 0;

            x[0] = 0;
            x[n + 1] = c;
            ldp[0] = 0;
            for (int i = 1; i <= n; ++i) {
                ldp[i] = ldp[i - 1] + v[i] - (x[i] - x[i - 1]);
                res = Math.max(res, ldp[i]);
            }

            y[0] = c;
            y[n + 1] = 0;
            rdp[n + 1] = 0;
            for (int i = n; i >= 1; --i) {
                rdp[i] = rdp[i + 1] + v[i] - (y[i] - y[i + 1]);
                res = Math.max(res, rdp[i]);
            }

            long[] lldp = new long[N];
            long[] rrdp = new long[N];

            lldp[0] = 0;
            for (int i = 1; i <= n; ++i) {
                lldp[i] = Math.max(lldp[i - 1], ldp[i] - x[i]);
            }

            rrdp[0] = 0;
            for (int i = n; i >= 1; --i) {
                rrdp[i] = Math.max(rrdp[i + 1], rdp[i] - y[i]);
            }

            for (int l = 1, r = n + 1; l < n; ++l) {
                while (x[l] >= y[r]) {
                    --r;
                }
                while (x[l] < y[r]) {
                    ++r;
                }
                res = Math.max(res, ldp[l] + rrdp[Math.max(r, l + 1)]);
            }

            for (int l = 0, r = n; r > 1; --r) {
                while (x[l] < y[r]) {
                    ++l;
                }
                while (x[l] >= y[r]) {
                    --l;
                }
                res = Math.max(res, lldp[Math.min(l, r - 1)] + rdp[r]);
            }

            out.println(res);
        }

    }
}



Measured memory_bytes: 94892
using System;
class ATorT{
	public static void Main(){
		string[] str = Console.ReadLine().Split(' ');
		int n = int.Parse(str[0]);
    int a = int.Parse(str[1]);
		int b = int.Parse(str[2]);
    int ans =a*n;
		if(ans>b){
			ans=b;
		}
		Console.WriteLine("{0}",ans);
	}
}

Measured memory_bytes: 13140
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 1000000007
#define i_5 1000000005

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=1000000000000;/*10^12*/
#define rep(i,l,r) for(ll i=l;i<=r;i++)
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}


//////////////////////////////////////
#define MAX_N 1000000//調節！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！
int par[MAX_N],dep[MAX_N];//depはrankのこと
//n要素で初期化
void init(int n){
    for(int i=0;i<=n-1;i++){
        par[i]=i;
        dep[i]=0;
    }
}
//木の根を求める
int find(int x){
    return par[x]==x?x:par[x]=find(par[x]);
}
//xとyの属する集合を併合
void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y)return;
    if(dep[x]<dep[y]){
        par[x]=y;
    }else{
        par[y]=x;
        if(dep[x]==dep[y])dep[x]++;
    }
}
//xとyが同じ集合に属するか否か
bool same(int x,int y){
    return find(x)==find(y);
}
//////////////////////////////////////
struct edge{int u,v,cost;};
bool comp(const edge& e1,const edge& e2){
    return e1.cost<e2.cost;
}
#define MAX_E 1000000//調節！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！
edge es[MAX_E];
int v,e;//頂点数vと辺数e

int kruskal(){
    sort(es,es+e,comp);
    init(v);
    int res=0;
    for(int i=0;i<e;i++){
        edge e=es[i];
        if(!same(e.u,e.v)){
            unite(e.u,e.v);
            res+=e.cost;
        }
    }
    return res;
}
///////////////////////////////////////////

int main(){
    cin>>v>>e;
    rep(i,0,e-1){
        cin>>es[i].u>>es[i].v>>es[i].cost;
    }
    cout<<kruskal()<<endl;
    
    return 0;
}



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


int main() {
	int N;
	scanf("%d", &N);
	int *A = new int[N];
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}
	std::sort(A, A + N);
	int d = 1;
	for (int i = 1; i < N; i++) {
		if (A[i] > 0) {
			d = i;
			break;
		}
	}
	if (A[N - 1] <= 0)d = N - 1;
	int res = 0;
	for (int i = 0; i < N; i++) {
		res += (i < d) ? -A[i] : A[i];
	}
	printf("%d\n", res);
	int x = A[d - 1];
	for (int i = d + 1; i < N; i++) {
		printf("%d %d\n", x, A[i]);
		x -= A[i];
	}
	printf("%d %d\n", A[d], x);
	x = A[d] - x;
	for (int i = 0; i < d - 1; i++) {
		printf("%d %d\n", x, A[i]);
		x -= A[i];
	}
	return 0;
}

Measured memory_bytes: 2304
#include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#define inf 99999999
using namespace std;
typedef double db;
typedef long long ll;
string s;
int ans=-1;
int main()
{
	cin>>s;
	for(int i=1;i<=s.size();i++)
	{
		if(s[i]!=s[i-1])
			ans++;
	}
	cout<<ans;
	return 0;
}



Measured memory_bytes: 512
#include<stdio.h>
int main(void){
    int i,a=0,b=0,c=0;
    char s[4];
    scanf("%s",s);
    for(i=0;i<3;i++){
        if(s[i]=='a'){
            a=1;
        }
        if(s[i]=='b'){
            b=1;
        }
        if(s[i]=='c'){
            c=1;
        }
    }
    if(a==1&&b==1&&c==1){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 128
# -*- coding: utf-8 -*-

import sys
from math import factorial

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
S = input()

# 最初が白だったらどうやっても無理
if S[0] == 'W':
    print(0)
    exit()

# 閉じていない区間の数を保持する
remaining = 1
ans = 1
for i in range(1, N*2):
    # 現在位置が白で残り区間が奇数個 or 現在位置が黒で残り区間が偶数個
    # => この位置は左端にする
    if (S[i] == 'W') ^ (remaining%2 == 0):
        remaining += 1
        # 閉じていない区間数に応じて通り数が増える
        # (今回の左端をどの右端と組ませるかなので、remainingをかける)
        ans *= remaining
        ans %= MOD
    else:
        remaining -= 1
    # 途中で左端が足りなくなったらNG
    if remaining < 0:
        print(0)
        exit()
# 最後に右端が余ったらNG
if remaining != 0:
    print(0)
else:
    # 問題なければ、通り数に順番の分(N!)をかければ答え
    print(ans*factorial(N)%MOD)


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

int main(){
  string S;
  cin >> S;
  
  if (S == "Sunny"){
    cout << "Cloudy" << endl;
  }
  else if( S == "Cloudy"){
    cout << "Rainy" << endl;
  }
  else if(S == "Rainy"){
    cout << "Sunny" << endl;
  }
}
    
    
  

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

typedef long long ll;

int main() {
    int n, q, l, r, sum;
    vector<int> t;
    string s;

    cin >> n >> q >> s;
    t.resize(n);
    fill(t.begin(), t.end(), 0);

    for(int i = 1; i < n; i++) {
        if(s.at(i - 1) =='A' && s.at(i) =='C')
            t.at(i) = t.at(i - 1) + 1;
        else t.at(i) = t.at(i - 1);
    }

    f(i, q) {
        cin >> l >> r;
        cout << t.at(r - 1) - t.at(l - 1) << endl;
    }

    return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
#include<math.h>
int main()
{
    int a,b,k,x;
    double y;
    scanf("%d%d",&a,&b);
    if(b>=1&&b<=9)
        k=a*10+b;
    if(b>=10&&b<=99)
        k=a*100+b;
    if(b==100)
        k=a*1000+b;
   // printf("%d",k);
    x=sqrt(k);
    y=sqrt(k);
    if(x==y)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;

}

Measured memory_bytes: 128
#include <bits/stdc++.h> 
using namespace std;
int main(void){
    // Your code here!
   int N,K;
   cin >> N >> K;
   int h[100010];
   int dp[100010];
   h[0] = -1000000;
   for(int i = 1; i <= N; i++) cin >> h[i];
   dp[0] = 1000000;
   dp[1] = 0;
   for(int i = 2; i <= N; i++){
       dp[i] = 1000000000;
       for(int j = 1; j <= K; j++){
           if(i >= j){
               dp[i] = min(dp[i] , dp[i-j] + abs(h[i]-h[i-j]));
           }
       }
   }
   
  cout << dp[N] << endl;
  
}


Measured memory_bytes: 1024
<?php

fscanf(STDIN, '%d %d', $r, $c);

$rowSum = array_fill(0, $c + 1, 0);

for ($i = 0; $i < $r; $i++) {
    $sheet[$i]   = explode(' ', trim(fgets(STDIN)));
    $sheet[$i][] = array_sum($sheet[$i]);

    foreach ($sheet[$i] as $k => $v) {
        $rowSum[$k] += $v;
    }

    $view[$i] = implode(' ', $sheet[$i]);
}

$view[] = implode(' ', $rowSum);

echo implode(PHP_EOL, $view), PHP_EOL;

Measured memory_bytes: 8512
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
#define ENDL cout<<endl

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};
int main(){
    CIN(N);
    if(N == 1){
        COUT("Hello World");
    }else{
        CIN(A);CIN(B);
        COUT(A+B);
    }
    //CIN(a);
    //CIN(b);
    //CIN(c);
    //SCIN(str);
    
    return 0;
}


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

int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    if(a&1 || b&1 || c&1){
        cout<<0<<endl;
        return 0;
    }
    if(a==b && b==c){
        cout<<-1<<endl;
        return 0;
    }
    
    ll ans=0;
    set<tuple<long,long,long>>s;
    s.emplace(a,b,c);
    while(1){
        ll ah=a/2,bh=b/2,ch=c/2;
        a=bh+ch;b=ah+ch;c=ah+bh;
        if(s.count(make_tuple(a,b,c))){
            cout<<-1<<endl;
            return 0;
        }
        ans++;
        if(a%2==1 || b%2==1 || c%2==1){
            cout<<ans<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3616
#include<cstdio>
#include<algorithm>
#include<vector>
#include<iostream>
#include<map>
#include<queue>
#include<cstring>
#include<string>
#include<cstdlib>
#include<cmath>
#include<set>
using namespace std;
const int maxn=1e5+5;
const int N=55;
typedef unsigned long long ull;
typedef long long ll;
int w[N];
int p[N];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m,ans=0;
    cin>>n>>m;
    for(int i=0; i<n; i++)
        cin>>w[i];
    int r=min(n,m),o,t;
    for(int i=0; i<=r; i++)
    {
        for(int j=0; j<=r-i; j++)
        {
            for(o=0; o<i; o++)
                p[o]=w[o];
            for(t=0; t<j; t++)
                p[o+t]=w[n-t-1];
            sort(p,p+i+j);
            int k=0,sum=0;
            while(k+i+j<m&&p[k]<0)
                k++;
            while(k<i+j)
                sum+=p[k],k++;;
            ans=max(ans,sum);
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main() {
	ios::sync_with_stdio(false);
	cin >> a >> b >> c;
	if(b - a == c - b)
		cout << "YES\n";
	else
		cout << "NO\n";
	return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author NikuKyabe
 */

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n)  FOR(i,0,(n))


class BPostalCode {
public:
	void solve(std::istream& in, std::ostream& out) {
    int a,b;
    in >> a >> b;
    string s;
    in >> s;
    REP(i,s.length()){
      if(i == a) {
        if(s[i] != '-'){
          out << "No" << endl;
          return;
        }
      }
      else{
        if(s[i] < '0' || s[i] > '9'){
          out << "No" << endl;
          return;
        }
      }
    }
    out << "Yes" << endl;
	}
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
	BPostalCode solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3660
import java.util.Scanner;
class Main{
    public static void main(String[]arge){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int []A=new int[n];
        for(int i=0; i<n; i++){
            A[i]=sc.nextInt();
        }
        
        for(int i=0; i<n; i++){
             int v=A[i];
             int j=i-1;
             while(j>=0 && A[j]>v){
                 A[j+1]=A[j];
                 j--;
             }
             A[j+1]=v;

             for(int k=0; k<n; k++){
                if(k>0)System.out.print(" ");
                System.out.print(A[k]);
             }
             System.out.println();
        }
       

        
    }
}     

Measured memory_bytes: 25956
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> v1(100010, 0), v2(100010, 0);
  rep(i, n){
    int v;
    cin >> v;
    if (i % 2 == 0) v1[v]++;
    else v2[v]++;
  }
  int a11,a12,a21,a22;
  int max11 = -1;
  int max12 = -1;
  int max21 = -1;
  int max22 = -1;
  rep(i, 100010){
    if (v1[i] > max11){
      a11 = i;
      max11 = v1[i];
    }
    if (v2[i] > max21){
      a21 = i;
      max21 = v2[i];
    }
  }
  rep(i, 100010){
    if (v1[i] > max12 && i != a11){
      a12 = i;
      max12 = v1[i];
    }
    if (v2[i] > max22 && i != a21){
      a22 = i;
      max22 = v2[i];
    }
  }
  
  int ans;
  if (a11 != a21){
    ans = n - max11 - max21;
  }
  else{
    ans = min(n-max11-max22, n-max12-max21);
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3996
#include <stdio.h>

int main(int argc, const char* argv[])
{
	int itemNum, popItemNum, totalVotes = 0, choosenItem = 0;
	int votesArray[100];
	double winVotes = 0;

	scanf("%d %d", &itemNum, &popItemNum);

	// Counting total number of votes, also creating an array with partial votes
	for (int i = 0; i < itemNum; i++)
	{
		int partVotes;
		scanf("%d", &partVotes);
		totalVotes += partVotes;
		votesArray[i] = partVotes;
	}

	winVotes = totalVotes / (4.0 * popItemNum);

	// Using popItemNum(M) as counter to judge if the requirement of task is fulfilled. 
	// If goes beyond 0, then it means M popular items can be selected. 

	for (int i = 0; i < itemNum; i++)
	{
		if (votesArray[i] >= winVotes)
		{
			choosenItem++;
		}
	}

	if (popItemNum <= choosenItem)
	{
		printf("Yes \n");
	}
	else
	{
		printf("No \n");
	}

	return 0;
}

Measured memory_bytes: 1660
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#define PI 3.14159265359
typedef long long ll;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
using namespace std;


ll llmin(ll x, ll y){
	if (x < y) return x;
	return y;
}

ll llmax(ll x, ll y){
	if (x > y) return x;
	return y;
}

char grid[1001][1001];
bool visited[1001][1001];
queue<pair<int, int> > que;
queue<pair<int, int> > que2;
int h, w, ans;
int ch, cw, gh, gw;
int dx[4] = {0, -1, 0, 1};
int dy[4] = {1, 0, -1, 0};

bool is_range(int nowx, int nowy){
	if (nowx <= h && nowx >= 0 && nowy <= w && nowy >= 0) return true;
	return false;
}



int main(){
	cin >> h >> w;
	cin >> ch >> cw >> gh >> gw;
	for (int i = 1; i <= h; i++){
		for (int j = 1; j <= w; j++){
			cin >> grid[i][j];
		}
	}

	que.push(make_pair(ch, cw));

	while(1){
		if (que.empty() && que2.empty()){
			cout << -1 << endl;
			return 0;
		}
		while(!que.empty()){
			pair<int, int> p = que.front();
			que.pop();
			int nx = p.first, ny = p.second;
			visited[nx][ny] = true;
			que2.push(make_pair(nx, ny));
			if (nx == gh && ny == gw){
				cout << ans << endl;
				return 0;
			}
			for (int i = 0; i < 4; i++){
				if (is_range(nx+dx[i], ny+dy[i])){
					if (!visited[nx+dx[i]][ny+dy[i]] && grid[nx+dx[i]][ny+dy[i]] == '.'){
						visited[nx+dx[i]][ny+dy[i]] = true;
						que.push(make_pair(nx+dx[i], ny+dy[i]));
						que2.push(make_pair(nx+dx[i], ny+dy[i]));
					}
				}
			}
		}
		while(!que2.empty()){
			pair<int, int> p = que2.front();
			que2.pop();
			int nx = p.first, ny = p.second;
			for (int i = -2; i <= 2; i++){
				for (int j = -2; j <= 2; j++){
					if (is_range(nx+i, ny+j)){
						if (!visited[nx+i][ny+j] && grid[nx+i][ny+j] == '.'){
							que.push(make_pair(nx+i, ny+j));
						}
					}
				}
			}
		}
		ans++;
	}
	
	return 0;
}


Measured memory_bytes: 9188
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def rangeI(it, l, r):
    for i, e in enumerate(it):
        if l <= i < r:
            yield e
        elif l >= r:
            break

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

MOD = 10**9+7

n,m,q = get_nums_l()
abcd = []
for _ in range(q):
    s = input()
    abcd.append(list(map(int, s.split())))
#abcd = list(map(lambda s: list(map(int, s.split())), map(lambda s: s.strip(), sys.stdin.readlines())))

def solve(A):
    score = 0
    for query in abcd:
        if A[query[1]-1] - A[query[0]-1] == query[2]:
            score += query[3]
    return score


ans = 0

def dfs(A):
    global ans
    if len(A) == n:
        # log(A)
        ans = max(ans, solve(A))
    elif len(A) == 0:
        for a in range(1, m+1):
            dfs([a])
    else:
        for a in range(A[-1], m+1):
            dfs(A+[a])

dfs([])
print(ans)


Measured memory_bytes: 75152
mod = 10**9+7

s = input()
n = len(s)

dp = [0]*13
dp[0] = 1

for i in range(n):
  dp2 = [0]*13  
  for j in range(10):
    if s[i] == '?' or s[i] == str(j):
      for k in range(13):
        dp2[(k*10 + j)%13] += dp[k]
        dp2[(k*10 + j)%13] %= mod
        
  dp = dp2

print(dp[5])

Measured memory_bytes: 68432
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  int x; cin >> x;
  if(x >= 30) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3620
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        
        int[] left = new int[n];
        for (int i = 0; i < n; i++) {
            left[i] = sc.nextInt();
        }
        int[] right = new int[m];
        for (int i = 0; i < m; i++) {
            right[i] = sc.nextInt();
        }
        
        long[] suml = new long[n+1];
        for (int i = 1; i <= n; i++) {
            suml[i] = suml[i-1] + left[i-1];
        }
        long[] sumr = new long[m+1];
        for (int i = 1; i <= m; i++) {
            sumr[i] = sumr[i-1] + right[i-1];
        }
        
        int max = 0;
        int j = m;
        for (int i = 0; i < n + 1; i++) {
            while (j > 0 && suml[i] + sumr[j] > k) {
                j--;
            }
            
            if (suml[i] + sumr[j] <= k) {
                max = Math.max(max, i + j);
            }
        }
        
        System.out.println(max);
    }
}

Measured memory_bytes: 62860
#include <stdio.h>
#include <cmath>
#include <algorithm>
#define NMAX 100005

using namespace std;

int dp[NMAX];
int h[NMAX];
int n;

int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;++i)
    {
        scanf("%d",&h[i]);
    }
    for (int i=2;i<=n;++i)
    {
        dp[i] = dp[i-1] + abs(h[i] - h[i-1]);
        if (i>2)
        {
            int v = dp[i-2] + abs(h[i] - h[i-2]);
            dp[i] = min(dp[i], v);
        }
    }
    printf("%d\n", dp[n]);
    return 0;
}


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

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using P = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

struct nvec : public vector<int> {
  int base;
  nvec(int len, int base) : vector<int>(len), base(base) {}
  nvec& operator=(ll in) {
    for (int i = 0; i < size(); i++) {
      if (in == 0) break;
      at(i) = in % base;
      in /= base;
    }
    return *this;
  };
  operator ll() const noexcept {
    ll out, b;
    out = 0;
    b = 1;
    for (int i = 0; i < size(); i++) {
      if (at(i)) out += at(i) * b;
      b *= base;
    }
    return out;
  };
  nvec& operator++() {
    for (int i = 0; i < size(); i++) {
      at(i)++;
      if (at(i) < base) break;
      at(i) = 0;
    }
    return *this;
  };
  nvec& operator--() {
    for (int i = 0; i < size(); i++) {
      if (0 < at(i)) {
        at(i)--;
        break;
      }
      at(i) = base - 1;
    }
    return *this;
  };
  nvec& operator++(int dummy) { return operator++(); }; // 後置(a++)のoverload
  nvec& operator--(int dummy) { return operator--(); }; // 後置(a--)のoverload
};
nvec& operator+=(nvec& a, int b) {
  for (int i = 0; i < a.size(); i++) {
    if (b == 0) break;
    a.at(i) += (b % a.base);
    if (0 < b) {
      b /= a.base;
      if (a.base <= a.at(i)) {
        a.at(i) -= a.base;
        b++;
      }
    } else {
      b /= a.base;
      if (a.at(i) < 0) {
        a.at(i) += a.base;
        b--;
      }
    }
  }
  return a;
}
nvec& operator-=(nvec& a, int b) { return a += -b; }
nvec operator+(nvec a, int b) { return a += b; }
nvec operator-(nvec a, int b) { return a += -b; }
ostream& operator<<(ostream& os, const nvec& a) {
  string s;
  for (int i = a.size() - 1; 0 <= i; i--) {
    s += to_string(a.at(i));
  }
  return (os << s);
}

void solve() {
  int n, k;
  cin >> n >> k;
  nvec a(32, k);
  a = n;
  dump(a);
  int ans = 0;
  rep(i, 32) {
    dump(i, a[31-i]);
    if (a[31 - i]) {
      ans = 31 - i + 1;
      break;
    }
  }
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>
#include <numeric>
#include <stdio.h>
#include<cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main() {
  int MAX = 101010;
  vector<int> is_prime(MAX, 1);
  is_prime[0] = 0; is_prime[1] = 0;
  for (int i = 2; i < MAX; i++) {
    if (!is_prime[i]) continue;
    for (int j = i*2; j < MAX; j += i) is_prime[j] = 0;
  }

  vector<int> a(MAX, 0);
  for (int i=0; i < MAX; i++) {
    if ( i % 2 == 0) continue;
    if( is_prime[i] && is_prime[(i+1)/2]) a[i] = 1;
  }

  vector<int> s(MAX+1, 0);
  for (int i = 0; i< MAX +1; i++) s[i+1] = s[i] + a[i];

  int Q; cin >> Q;
  for( int q = 0; q < Q; q++) {
    int l, r;
    cin >> l >> r;
    ++r;

    cout << s[r] - s[l] << endl;
  }

  return 0;
}

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

using namespace std;

const int MAXN = 110;

int n;
int ans;

int v[2*MAXN];

int main()
{
	scanf("%d",&n);

	n *= 2;

	for(int i = 1 ; i <= n ; i++)
		scanf("%d",&v[i]);

	sort( v + 1 , v + n + 1 );

	for(int i = n ; i > 1 ; i -= 2 )
		ans += min( v[i] , v[i - 1] );

	printf("%d\n",ans);
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    int N; cin >> N;
    vector<int> a(N);
    REP(i,N) cin >> a[i];
    int ans = INF;
    for(int i=-100; i<=100; i++){
        int sum = 0;
        REP(j,N){
            sum += (i-a[j]) * (i-a[j]);
        }
        ans = min(ans,sum);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#define REP(i, a, n) for(int i = a; i < n; i++)
using namespace std;


int n, m;

char table[256];
char c, d;

int main(void) {
  while(1) {
    cin >> n;
    if(n == 0) break;
    REP(i, 0, 256) table[i] = (char) i;
    REP(i, 0, n) {
      cin >> c >> d;
      table[c] = d;
    }
    cin >> m;
    REP(i, 0, m) {
      cin >> c;
      cout << table[c];
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int gc(int a,int b)
{
  if(a%b==0)return b;
  int c=a%b;
  return gc(b,c);
}
int main()
{
  long long a,b,c;//未将这里改为longlong导致错误i 
  cin>>a>>b;
  if(a<b){c=a;a=b;b=c;}
  int s=gc(a,b);
  long long ans;
  ans=(a/s)*b;
  cout<<ans;
  return 0;
}

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

int main() {
	// your code goes here
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	long long int a,b,c,k;
	cin>>a>>b>>c>>k;
	long long int ans=0;
	while(a-- && k>0) {ans=ans+1;k--;}
	while(b-- && k>0) {k--;}
	while(c-- && k>0) {ans=ans-1;k--;}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3612
N, M = map(int, input().split(' '))
cards = N * M

if N > 1 and M > 1:
    front = (N-1)*2 + (M-1)*2
    print(cards - front)
elif N == 1 and M == 1:
    print(1)
else:
    print(max(N, M) - 2)


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

#define int long long
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define fr(i,j,k) for(i = j; i < (k); i++)
#define all(x) x.begin(), x.end()
#define el '\n'
#define remax(a,b) a = max(a, b)
#define remin(a,b) a = min(a, b)
#define sz(x) int32_t(x.size())

typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpi;
// --------------------------------------------------------------------

const pii dxy[] = { {-1, 0}, {1, 0}, {0, 1}, {0, -1} };
const int mod = 1e9 + 7;
const int INF = 2e18;
const ld EPS = 1e-9;
const int NN = 1e5 + 2;


void solve() {
      int i = 0, j = 0, k = 0, n = 0, m = 0; 
      cin >> n;
      vi a(n);
      fr(i, 0, n) {
            cin >> a[i];
      }
      sort(all(a));
      int ans;
      if(n == 2) {
            ans = a[1]-a[0];
      } else {
            if(n & 1) {
                  int op1 = 0, op2 = 0;
                  fr(i, 0, n/2-1){
                        op1 -= 2*a[i];
                  }
                  op1 -= a[i];
                  i++;
                  op1 -= a[i];
                  for(++i; i < n; i++) {
                        op1 += 2*a[i];
                  }

                  fr(i, 0, n/2) {
                        op2 -= 2*a[i];
                  }
                  op2 += a[i];
                  i++;
                  op2 += a[i];
                  for(++i; i < n; i++) {
                        op2 += 2*a[i];
                  }

                  ans = max(op1, op2);
            } else {
                  ans = 0;
                  fr(i, 0, n/2-1) {
                        ans -= 2*a[i];
                  }
                  ans -= a[i];
                  i++;
                  ans += a[i];
                  for(++i; i < n; i++) ans += 2*a[i];
            }
      }

      cout << ans << el;

}

int32_t main() {
      ios::sync_with_stdio(false); cin.tie(0); 
      int T = 1; 
      // cin >> T;
      for(int tc = 1; tc <= T; tc++) {
            solve();
       }
      return 0;
}

Measured memory_bytes: 1024