akhauriyash/Code-Regression huggingface dataset:
a,b,c = map(int,input().split())
loop = [[a,b,c]]
count = 0
for i in range(200):
    if a % 2 == 1 or b % 2 == 1 or c % 2 == 1:
        break
    x = a // 2
    y = b // 2
    z = c // 2
    a = y + z
    b = x + z
    c = x + y
    count += 1
    if [a,b,c] in loop:
        count = -1 
        break
    loop.append([a,b,c])
print(count)

Measured memory_bytes: 3064
w, h, n = map(int, input().split())
x1, y1, x2, y2 = 0, 0, w, h
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1 :
        x1 = max(x, x1)
    elif a == 2:
        x2 = min(x, x2)
    elif a == 3:
        y1 = max(y, y1)
    else:
        y2 = min(y, y2)
print(max((x2-x1), 0) * max((y2-y1), 0))


Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
using namespace std;
int main(void){
    // Your code here!
    while(1){
    int n = 0;
    scanf("%d",&n);
    if(n==0)break;
    
    int a[1000] = { 0 };
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    
    long long int sa = 1000000;
    
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            if(a[i]>a[j]){
                if(a[i]-a[j]<sa && a[i]-a[j]>=0)sa = a[i]-a[j];
            }
            else{
                if(a[j]-a[i]<sa&& a[j]-a[i]>=0)sa = a[j]-a[i];
            }
        }
    }
    
    cout << sa << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3132
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>

using namespace std;

int main()
{
	int n,l;
	string s[101];
	cin>>n>>l;
	for(int i=1;i<=n;i++)cin>>s[i];
	sort(s+1,s+n+1);
	for(int i=1;i<=n;i++)cout<<s[i];
}

Measured memory_bytes: 256
module.exports=function(r){var t={};function e(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return r[n].call(o.exports,o,o.exports,e),o.l=!0,o.exports}return e.m=r,e.c=t,e.d=function(r,t,n){e.o(r,t)||Object.defineProperty(r,t,{enumerable:!0,get:n})},e.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},e.t=function(r,t){if(1&t&&(r=e(r)),8&t)return r;if(4&t&&"object"==typeof r&&r&&r.__esModule)return r;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:r}),2&t&&"string"!=typeof r)for(var o in r)e.d(n,o,function(t){return r[t]}.bind(null,o));return n},e.n=function(r){var t=r&&r.__esModule?function(){return r.default}:function(){return r};return e.d(t,"a",t),t},e.o=function(r,t){return Object.prototype.hasOwnProperty.call(r,t)},e.p="",e(e.s=0)}([function(r,t,e){e(1)(e(2).readFileSync("/dev/stdin","UTF-8").split("\n"))},function(r,t){function e(r,t){return function(r){if(Array.isArray(r))return r}(r)||function(r,t){var e=[],n=!0,o=!1,u=void 0;try{for(var i,a=r[Symbol.iterator]();!(n=(i=a.next()).done)&&(e.push(i.value),!t||e.length!==t);n=!0);}catch(r){o=!0,u=r}finally{try{n||null==a.return||a.return()}finally{if(o)throw u}}return e}(r,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}r.exports=function(r){for(var t=e(r[0].split(" ").map(function(r){return Number(r)}),2),n=t[0],o=t[1],u=[],i=0,a=0;a<n;a++){var f=e(r[a+1].split(" ").map(function(r){return Number(r)}),2),l=f[0],c=f[1];u.push({a:l,b:c}),i<l&&(i=l)}for(var p=0,s=0;s<n;s++)p+=Math.max(u[s].b,i);var d=o-p;if(d<=0){var b=m(o);console.log(b)}else{var v=Math.ceil(d/i),y=v+m(o-v*i);console.log(y)}function m(r){u.sort(function(r,t){return t.b-r.b});for(var t=0;t<n;t++){if(r<=0)return t;r-=Math.max(u[t].b,i)}return n}}},function(r,t){r.exports=require("fs")}]);

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

def main():
    S = input().strip()
    S = S.replace("eraser","")
    S = S.replace("erase","")
    S = S.replace("dreamer","")
    S = S.replace("dream","")
    if S == "":
        print("YES")
    else:
        print("NO")

if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
from collections import deque
N=int(input())

L1=[0 for _ in range(N)]
L2=[0 for _ in range(N)]
for i in range(N):
    x,y=map(int,input().split())
    L1[i],L2[i]=x-y,x+y


mi1=min(L1)
ma1=max(L1)
mi2=min(L2)
ma2=max(L2)

ans=max(ma1-mi1,ma2-mi2)
print(ans)


Measured memory_bytes: 100216
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=1e6+100;
struct poi
{
    int x,y;
    bool operator<(const poi&t)const{
        if(y!=t.y)
            return y<t.y;
        else
            return x<t.x;
    }
};
poi a[5000];
ll dp[2][6100];
int main()
{
    int n,rr;
    scanf("%d%d",&n,&rr);
    for(int i=0;i<n;i++){
        scanf("%d%d",&a[i].y,&a[i].x);
    }
    sort(a,a+n);
    int po=1;
    dp[0][a[0].y]=a[0].x+1;
    dp[0][0]=1;
    //cout<<a[2].x<<endl;
    for(int i=1;i<n;i++){
        int val=a[i].x,time=a[i].y;
        //cout<<val<<endl;
        for(int j=0;j<=6000;j++)
            {
                dp[(po-1)%2][j]=max(dp[po%2][j],dp[(po-1)%2][j]);
            }
        for(int j=0;j<rr;j++){
            if(dp[(po-1)%2][j]){
                //cout<<i<<" :*  "<<j<<endl;
                dp[po%2][j+time]=max(dp[po%2][j+time],dp[(po-1)%2][j]+val);
                //cout<<dp[po%2][j+time]<<endl;
            }
        }

        po++;
    }
    //cout<<dp[0][20]<<"   *  "<<dp[1][20]<<endl;
    ll maxe=-1;
    for(int i=0;i<=6000;i++){
        maxe=max(dp[(po-1)%2][i],maxe);
    }
    printf("%lld\n",maxe-1);
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>

using namespace std;
typedef pair<int, int> P;

void solve()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	while (cin >> n)
	{
		vector<int> seat(17);
		queue<P> que;
		int time = 0;
		int num = 0;
		while (true)
		{
			if (time % 5 == 0)
			{
				que.push(P(num, time));
				++num;
			}
			for (int i = 0; i < 17; ++i)
			{
				if (seat[i] > 0)
				{
					--seat[i];
				}
			}
			bool update = true;
			while (!que.empty() && update)
			{
				update = false;
				if (que.front().first % 5 == 1)
				{
					for (int i = 0; i + 4 < 17; ++i)
					{
						if (seat[i] == 0 && seat[i + 1] == 0 && seat[i + 2] == 0 && seat[i + 3] == 0 && seat[i + 4] == 0)
						{
							seat[i] = seat[i + 1] = seat[i + 2] = seat[i + 3] = seat[i + 4] = 17 * (que.front().first % 2) + 3 * (que.front().first % 3) + 19;
							if (que.front().first == n)
							{
								cout << time - que.front().second << endl;
								goto END;
							}
							que.pop();
							update = true;
							break;
						}
					}
				}
				else
				{
					for (int i = 0; i + 1 < 17; ++i)
					{
						if (seat[i] == 0 && seat[i + 1] == 0)
						{
							seat[i] = seat[i + 1] = 17 * (que.front().first % 2) + 3 * (que.front().first % 3) + 19;
							if (que.front().first == n)
							{
								cout << time - que.front().second << endl;
								goto END;
							}
							que.pop();
							update = true;
							break;
						}
					}
				}
			}
			++time;
		}
	END:
		;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1200
K, A, B = list(map(int, input().split()))

if K+1 > A:
  result = A
  K -= A-1
  if B > A+1:
    result += int(K/2) * (B-A)
    result += K % 2
  else:
    result += K
  print(result)
else:
  print(K+1)

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,M;
    cin >> N >> M;
    vector<int> A,B;
    vector<int> V(N,-1);//visited
    vector<vector<int>> atesaki(N);
/*    rep(i,M){
        int res1,res2;
        cin >> res1 >> res2;
        A.push_back(res1);
        B.push_back(res2);
    }
*/

    rep(i,M){
        int res1,res2;
        cin >> res1 >>res2;
        atesaki[res1-1].push_back(res2);
        atesaki[res2-1].push_back(res1);
    }

    queue<int> q;
    q.push(1);
    V[0] = 0;

    while(!q.empty()){
        int now = q.front();
        q.pop();

        rep(i, atesaki[now-1].size()){
            int next = atesaki[now-1][i];//aite
            //atesaki.at(now-1).at(i)の方がいいのかな
            if(V[next - 1] == -1){
                V[next - 1] = now;
                q.push(next);
            }
        }
    }
    int judge = 1;
    rep(i,N){
        if(V[i] == -1) judge = 0;
    }
    if(judge == 0) cout << "No" << endl;
    else {
        cout << "Yes" << endl;
        for(int i = 1; i < N ; i++){
            cout << V[i] << endl;
        }
    }
    return 0;
}


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

const int maxw = 1001;
const int maxn = 1001;
const int maxp = 10001;

int dp[maxn][maxw]={};
int w[maxn] = {};
int p[maxn] = {};
int W,N;

int main()
{
	int casenum = 0;
	
	while(cin >> W)
	{
		if(W==0)break;
		casenum++;
		cout << "Case " << casenum << ":" << endl;
		cin >> N;
		char t;
		rep(i,N) cin>>p[i] >> t >> w[i];

		memset(dp,0,sizeof(dp));
		rep(i,N)rep(j,W+1)
		{
			if(j-w[i]>=0) dp[i+1][j] = max(dp[i][j],dp[i][j-w[i]] + p[i]);
			else dp[i+1][j] = dp[i][j];
		}
		int ansp = 0,answ = 0;
		for(int j=W;j!=0;j--)if(ansp<= dp[N][j])
		{
			ansp = dp[N][j];
			answ = j;
		}
		
		cout << ansp << endl;
		cout << answ << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
using namespace std;

int main(){
	int a,b;
	cin >> a >> b;
	if(a%3==0 || b%3==0 || (a+b)%3==0){
		cout << "Possible" << endl;
	}else{
		cout << "Impossible" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
  a := make([]int, n)
	x := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
		x += a[i]
	}
	y := 0
	ans := 10000000000
	for i := 0; i < n-1; i++ {
		y += a[i]
		d := x - 2*y
		if d < 0 {
			d = -d
		}
		if d < ans {
			ans = d
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 5504
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair
#define MOD (LL)(1e9+7)
/*
//あまりは x より小さい
//y=1...
//x=0...
//この場合 x XOR y が 1... となり x より大きい

//y=1...
//x=1...
//このとき，商は 1 だから，y mod x = y - x

//y - x = x XOR y であればよい

//y=11...
//x=11... ok
//y=11...
//x=10... ok
//y=10...
//x=10... ok

//y=110...
//x=101... ng

//よって
//y=111111...0
//x=11...00000

LL L, R;
int main(){
	cin >> L >> R;
	
}*/

#define int long long
signed main(){
	int i, o, t, j, l, s, z;
	cin >> i >> o >> t >> j >> l >> s >> z;
	int K1 = o + (j/2)*2 + (l/2)*2 + (i/2)*2;
	int K2 = o + (j > 0 && l > 0 && i > 0 ? ((j-1)/2)*2 + ((l-1)/2)*2 + ((i-1)/2)*2 + 3 : 0);
	cout << max(K1, K2) << endl;
}

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

#define Nmax 50

int main(int argc, char const *argv[])
{
    /* code */
    int N = 0;
    scanf("%d\n", &N);

    int i = 0;
    char s[Nmax][100];
    int t[Nmax];
    for(i = 0; i < N; i ++)
    {
        scanf("%s %d\n", &s[i], &t[i]);
    }
    char X[100];
    scanf("%s", &X);
    
    /*
    printf("%d\n", N);
    for(i = 0; i < N; i ++)
    {
        printf("%s %d\n", s[i], t[i]);
    }
    printf("%s\n", X);
    */

    int T = 0;
    for(i = N - 1; i >= 0; i --)
    {
        if(strcmp(X, s[i]) != 0)
        {
            T += t[i];
        }
        else
        {
            break;
        }
        
    }
    printf("%d\n", T);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

int main()
{
    double a, b, x;
    cin >> a >> b >> x;

    double t = 0;

    if (a * a * b < 2.0 * x) {
        double c = 2.0 * (b - x / (a * a));
        t = c / a;
    } else {
        double c = 2.0 * x / (a * b);
        t = b / c;
    }

    double ans = atan(t) * 180.0 / M_PI;

    cout << setprecision(10) << ans << endl;

    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys

N=input()
S=["None"]+list(raw_input())
Q=input()
query=[ sys.stdin.readline().split() for _ in range(Q) ]

#BIT
bit=[ [ 0 for _ in range(N+1) ] for _ in range(27) ]  #中も外も1-indexed bit[1]:aのbit, bit[2]:bのbit ...

def add(idx,a,w):
    while a<=N:
        bit[idx][a]+=w
        a+=a&-a

def sum(idx,a):
    ret=0
    while 0<a:
        ret+=bit[idx][a]
        a-=a&-a
    return ret

for i,x in enumerate(S):
    if i==0: continue
    add(ord(x)-96,i,1)  #a~zのどのbit配列か,特定文字のbit配列の何番目,bitに代入する値


for q1,q2,q3 in query:
    q1=int(q1)
    q2=int(q2)
    if q1==1:
        before_q3=S[q2] #文字列Sの変更前の文字をbefore_q3に代入
        S[q2]=q3        #文字列Sの変更部分1文字を更新
        q3=ord(q3)-96                   #変更後の文字をアスキーコード10進数で表現
        before_q3=ord(before_q3)-96     #変更前の文字をアスキーコード10進数で表現
        add(q3,q2,1)                    #a~zのどのbit配列か,特定文字のbit配列の何番目,bitに代入する値
        add(before_q3,q2,-1)    #置き代えた文字は-1しなきゃいけない
    elif q1==2:
        q3=int(q3)
        cnt=0
        for i in range(1,27):
            if 0<sum(i,q3)-sum(i,q2-1):
                cnt+=1
        print cnt

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

using namespace std;

int main(){
        int a, b;
        cin>>a>>b;
        if(a<=0&&0<=b){
                cout<<"Zero"<<endl;
        }
        else if(0<a){
                cout<<"Positive"<<endl;
        }
        else{
                if(abs(b-a)%2!=0){
                        cout<<"Positive"<<endl;
                }
                else{
                        cout<<"Negative"<<endl;
                }
        }
        return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		// 入力値の取得
		String N = sc.next();

		// 結果の出力
		char lastChar = N.charAt(N.length() - 1);
		if (lastChar == '3') {
			System.out.println("bon");
		} else if (lastChar == '0' || lastChar == '1' || lastChar == '6' || lastChar == '8') {
			System.out.println("pon");
		} else {
			System.out.println("hon");
		}

		sc.close();
	}
}


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


    using namespace std;
    typedef long long ll;
    # define M_PI  3.14159265358979323846


    void solve(){
        int n;
        cin>>n;
        int total=1;
        int mini;
        cin>>mini;
        for(int i=1;i<n;i++){
            int k;
            cin>>k;
            if(k<mini){
                total++;
                mini=k;
            }
//            cout<<mini<<"IN"<<"\n";
        }
        cout<<total;
    }


    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
        int t=1;
//        cin>>t;
        for(int i=1;i<=t;i++){
            solve();
        }
        return 0;
    }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, l, r) for (int i = l; i<r;i++)
#define vi vector<int>
#define all(v) v.begin(),v.end()
#define pb(c) push_back(c)
#define vii vector<pair<int,int>>
#define ii pair<int,int>
#define max(a, b) (((a)<(b))?b:a)
#define min(a, b) ((a>b)?b:a)
#define mp(i, j) make_pair(i,j)
#define ull unsigned long long int
#define ll  long long int
#define pi 3.141592653589793238
#define mod ((int)1e9 + 7)
#define inf ((int)1e5)
#define eps 1e-14,
#define maxlg 18
#define left(i) ((i)<<1)
#define right(i) (((i)<<1)+1)
#define maxn 1051002
int can[3][103];
int dp[3][103];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
    //freopen("input", "r", stdin);//flush(cout);
#endif
    int n;
    cin>>n;
    rep (i,0,2) {
        rep (j,0,n) {
            int x;
            cin>>x;
            can[i][j]=x;
        }
    }

    for (int j=n-1;j>=0;j--) {
        for (int i = 1; i >= 0; i--) {
            dp[i][j] = can[i][j] + max(dp[i + 1][j], dp[i][j + 1]);

        }
    }
    cout<<dp[0][0];
     return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

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

    int h, n;
    cin >> h >> n;
    vs32 a(n), b(n);
    rep (i, n) cin >> a[i] >> b[i];

    int dp[h + 1];
    rep (i, h + 1) dp[i] = 1e9;
    dp[0] = 0;

    rep (i, n)
    {
        rep (j, h + 1)
        {
            dp[j] = MIN(dp[j], dp[MAX(0, j - a[i])] + b[i]);
        }
    }

    cout << dp[h] << "\n";
    return 0;
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <stdio.h>
using namespace std;

int main(){
	int a,b,c;
	char op;

	while(1){
	cin >> a >> op >> b;
		if(op=='?') break;
	switch(op){
		case '+':
			cout << a+b << endl;
			break;
		case '-':
			cout << a-b << endl;
			break;
		case '*':
			cout << a*b << endl;
			break;
		case '/':
			cout << a/b << endl;
			break;
		default:;
	}
	}

	return 0;
}


Measured memory_bytes: 3116
import java.util.*;
import java.lang.*;



public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        PriorityQueue<Long> goods = new PriorityQueue<>(Collections.reverseOrder());
        for(int n=0; n<N; n++) goods.add(sc.nextLong());
        for(int m=0; m<M; m++) goods.add(goods.poll()/2);

        long ans = 0;
        while(!goods.isEmpty()) ans += goods.poll();
        System.out.println(ans);
    }
}


Measured memory_bytes: 58656
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll n,k,k1;
    cin >> n >> k;
    if( k %2== 1) cout << (n/k)*(n/k)*(n/k) << endl;
    if( k %2== 0){
      k1 = k/2;
      ll a =  (((n/k1)+1)/2);
      ll b = (n/k1)/2;
      cout << a*a*a + b*b*b<<endl;
    }

    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


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

int main(){
    int a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;
    if(a==0){
        cout<<1<<endl;
        return 0;
    }
    if(b==0){
        cout<<2<<endl;
        return 0;
    }
    if(c==0){
        cout<<3<<endl;
        return 0;
    }
    if(d==0){
        cout<<4<<endl;
        return 0;
    }
    if(e==0){
        cout<<5<<endl;
        return 0;
    }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;

class P {
public:
    double x, y, z;
    P(){};
    P(double x, double y, double z) : x(x), y(y), z(z) {};
    P operator+(const P &p) {
        return P(x + p.x, y + p.y, z + p.z);
    }
    P operator-(const P &p) {
        return P(x - p.x, y - p.y, z - p.z);
    }
    P operator*(const double &n) {
        return P(x * n, y * n, z * n);
    }
    P operator/(const double &n) {
        return P(x / n, y / n, z / n);
    }
};

double dot(const P &a, const P &b) {
    return a.x * b.x + a.y * b.y + a.z * b.z;
}

P cross(const P &a, const P &b) {
    return P(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x);
}

int main() {
    P p[5];
    for (int i=0; i<5; ++i) cin >> p[i].x >> p[i].y >> p[i].z;

    P z = cross(p[3] - p[2], p[4] - p[2]);
    double a = dot(p[2] - p[0], z);
    double b = dot(p[1] - p[0], z);
    double c = abs(a);
    double d = abs(b) - c;

    if (abs(a) < eps || (b < -eps && eps < a) || (a < -eps && eps < b) || d < -eps) {
        cout << "HIT\n";
        return 0;
    }

    P i = (p[0] * d + p[1] * c) / (c + d);
    bool plus = false, minus = false;
    for (int k=0; k<3; ++k) {
        double t = dot(z, cross(p[(k + 1) % 3 + 2] - p[k + 2], i - p[k + 2]));
        if (-eps < t) plus = true;
        else if (eps > t) minus = true;
    }

    cout << ( ! plus || ! minus ? "MISS\n" : "HIT\n");
    return 0;
}

Measured memory_bytes: 3208
a,b = map(int, input().split())

genka_8_min=a*12.5
genka_8_max=(a+1)*12.5

if not genka_8_min.is_integer():
    genka_8_min=int(genka_8_min+1)

if genka_8_max.is_integer():
    genka_8=list(range(int(genka_8_min),int(genka_8_max)))
else:
    genka_8=list(range(int(genka_8_min),int(genka_8_max)+1))

genka_10_min=b*10
genka_10_max=(b+1)*10
genka_10=list(range(int(genka_10_min),int(genka_10_max)))

ans=set(genka_8)&set(genka_10)

if len(ans)==0:
    print(-1)
else:
    print(min(ans))

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

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

typedef long long ll;
typedef pair<int,int> P;

//-----------------------------------------------------------------------

int d[]={1000,100,10,1};
char c[]={'m','c','x','i'};

int translate(string s){
    int res=0;
    REP(i,s.size()){
	REP(j,4){
	    if(s[i]==c[j]){
		if(i>0 && '2'<=s[i-1] && s[i-1]<='9') res+=(s[i-1]-'0')*d[j];
		else res+=d[j];
	    }
	}
    }
    return res;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n; cin>>n;
    REP(i,n){
	string s1,s2;
	cin>>s1>>s2;
	int num=translate(s1)+translate(s2);

	REP(i,4){
	    int k=num/d[i];
	    num-=k*d[i];
	    if(k>1) cout<<k;
	    if(k>0) cout<<c[i];
	}
	cout<<endl;
    }
    
}



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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
 
//Write From this Line

//const ll mod = 1e9+7;
//const ll mod = 998244353;

const int dy[] = {0,0,1,-1};
const int dx[] = {1,-1,0,0};
const int inf = 1e9;
int main()
{
	int h, w;
	cin >> h >> w;

	int sh, sw;
	cin >> sh >> sw;
	int gh, gw;
	cin >> gh >> gw;
	sh--, sw--, gh--, gw--;

	vector<string> field(h);
	rep(i,h) cin >> field[i];

	vector<vector<bool>> seen(h, vector<bool> (w,false));
	vector<vector<int>> dist(h,vector<int>(w,inf));

	queue<P> q;
	queue<P> nq;
	q.push({sh,sw});
	dist[sh][sw] = 0;
	seen[sh][sw] = true; // コストが確定したらtrue
	while(1){
		bool u = true;
		while(!q.empty()){
			u = false;
			// BFSでコスト0で行けるところをマーキングする
			int y = q.front().first; 
			int x = q.front().second;
			nq.push({y,x});
			q.pop();
			rep(i,4){
				int ny = y + dy[i];
				int nx = x + dx[i];
				if(ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
				if(seen[ny][nx]) continue;
				if(field[ny][nx] == '#') continue;

				q.push({ny,nx});
				seen[ny][nx] = true;
				dist[ny][nx] = dist[y][x];
			}
		} 
		while(!nq.empty()) {
			u = false;
			// コスト0で行けるところはマーキング済み。
			// nq からワープを使って行けるとこを登録していく
			int y = nq.front().first; 
			int x = nq.front().second;
			nq.pop();

			for(int i = -2; i <= 2; i++){
				for(int j = -2; j <= 2; j++){
					int ny = y + i;
					int nx = x + j;
					if(ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
					if(seen[ny][nx]) continue;
					if(field[ny][nx] == '#') continue;

					dist[ny][nx] = dist[y][x] + 1;
					seen[ny][nx] = true;
					q.push({ny,nx});
				}
			}
		}
		if(u) break;
	}
	int ans = dist[gh][gw];
	if(ans == inf) ans = -1;
	cout << ans << endl;

	//rep(i,h){
	//	rep(j,w){
	//		cout << dist[i][j] << " ";
	//	}
	//	cout << endl;
	//}
}


Measured memory_bytes: 9640
#include<stdio.h>
#include <stdlib.h>
#include <string.h>
 
 
 
int main()
{
 
    int  N, A, B;
    
 // 整数の入力
    scanf("%d %d %d", &N, &A, &B);
//     printf("%d %d %d\n",N,A,B);
 
   if ((N*A)>B){
     printf("%d\n", B);
   } else {
     printf("%d\n", N*A);
   }
    return 0;
}

Measured memory_bytes: 128
n,m = map(int,input().split())
l = [list(map(int,input().split()))+[i] for i in range(m)]

l.sort(key=lambda x:(x[0],x[1]))
#print(l)

ans = []
cnt = 1
for i in range(m):
    number = '{:0=6}'.format(l[i][0])
    if i == 0:
        cnt = 1
    else:
        if l[i-1][0]==l[i][0]:
            cnt += 1
        else:
            cnt = 1
    number += '{:0=6}'.format(cnt)
    ans.append([number,l[i][2]])
    
ans.sort(key=lambda x:x[1])
#print(ans)

for i in range(m):
    print(ans[i][0])

Measured memory_bytes: 102616
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





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

	long long a, b, c;
	cin >> a >> b >> c;

	if (0 < c - a - b && 4 * a * b < (c - a - b) * (c - a - b))cout << "Yes" << endl;
	else cout << "No" << endl;



	return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "vector"
#include "iomanip"
#include "algorithm"
#include "vector"
#include "cmath"

typedef struct {
	int a;
	int b;
	int c;
}Drag;

int main() {
	int n;
	double ma, mb;
	std::cin >> n;
	std::cin >> ma;
	std::cin >> mb;

	std::vector<Drag> drag(n);
	for (int i = 0; i < n; ++i) {
		std::cin >> drag[i].a;
		std::cin >> drag[i].b;
		std::cin >> drag[i].c;
	}

	std::vector<std::vector<std::vector<int>>> v(n + 1, std::vector<std::vector<int>>(n * 10 + 1, std::vector<int>(n * 10 + 1, 10000)));
	v[0][0][0] = 0;

	for(int i = 1; i <= n; ++i)
		for(int j = 0; j <= n * 10; ++j)
			for (int k = 0; k <= n * 10; ++k) {
				int tmp_0 = v[i - 1][j][k];
				int tmp_1 = (j >= drag[i - 1].a && k >= drag[i - 1].b) ? v[i - 1][j - drag[i - 1].a][k - drag[i - 1].b] + drag[i - 1].c : 10000;
				v[i][j][k] = (tmp_0 < tmp_1) ? tmp_0 : tmp_1;
			}

	int min = 10000;
	int k_max = (ma > mb) ? ((double)n * 10 / ma) : ((double)n * 10 / mb);
	for (int i = 1; i <= k_max; ++i) {
		if (v[n][ma * i][mb * i] < min)
			min = v[n][ma * i][mb * i];
	}
	if (min == 10000)
		min = -1;

	std::cout << min;
}

Measured memory_bytes: 27264
#include<stdio.h>
#include<string.h>
int main(){
	int m;
	int n5=0,n7=0;
	int i;
	for(i=0;i<3;i++){
		scanf("%d",&m);
		if(m==5)
			++n5;
		if(m==7)
			++n7;
	}
	if(n5==2&&n7==1)
		printf("YES");
	else 
		printf("NO");
    return 0;
}

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

using namespace std;

int main()
{
  
  long long a,b,c,k;
  cin>>a>>b>>c>>k;
  if(k<=a)
    cout<<k;
  else if(k>a && k<=a+b)
    cout<<a;
  else if(k>a+b && k<=a+b+c)
  {
    long long ans = a + (k-a-b)*-1;
    cout<<ans;
  }
  
  return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 0; i < n; ++i)
#define rep3(i, a, b) for (ll i = a; i < b; ++i)
#define rep4(i, a, b, c) for (ll i = a; i < b; i += c)
#define erep(n) for (ll i = 0; i <= n; ++i)
#define erep2(i, n) for (ll i = 0; i <= n; ++i)
#define erep3(i, a, b) for (ll i = a; i <= b; ++i)
#define erep4(i, a, b, c) for (ll i = a; i <= b; i += c)
#define rrep(i, a, b) for (ll i = a; i > b; --i)
#define rrep2(i, a, b, c) for (ll i = a; i > b; i -= c)
#define errep(i, a, b) for (ll i = a; i >= b; --i)
#define errep2(i, a, b, c) for (ll i = a; i >= b; i -= c)
#define print(a) cout << a << endl;
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define cin(x) cin >> x;
const ll MOD = 1000000007;
const double PI = 3.14159265358979323846264338327950;
inline int newline() { putchar('\n'); return 0; }

int main() {
    int a, b, h, m;
    cin(a);
    cin(b);
    cin(h);
    cin(m);

    double th = double(h * 60 + m) / 720 * 2 * PI;
    double tm = double(m) / 60 * 2 * PI;
    double xh = a * cos(th), yh = a * sin(th);
    double xm = b * cos(tm), ym = b * sin(tm);

    double dx = xh - xm, dy = yh - ym;

    printf("%.20f\n", sqrt(dx * dx + dy * dy));
    return 0;
}

Measured memory_bytes: 4032
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    vector<int> v(3);
    REP(i,3) cin >> v[i];
    sort(ALL(v));
    OUT(v[2]-v[0])

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  while (1){
    int n, l, r;
    cin >> n >> l >> r;
    if (n == 0 && l == 0 && r == 0){
      break;
    }
    vector<int> A(n);
    for (int i = 0; i < n; i++){
      cin >> A[i];
    }
    int ans = 0;
    for (int i = l; i <= r; i++){
      int m = n;
      for (int j = 0; j < n; j++){
        if (i % A[j] == 0){
          m = j;
          break;
        }
      }
      if (m % 2 == 0){
        ans++;
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl
#define int ll

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e18 + 7;

vi pos, neg;
int zero = 0, n, k;	

bool ok(int m) {
	int cnt = 0;
	if(m > 0) {
		cnt += zero * (zero - 1) / 2;
		cnt += zero * (pos.size() + neg.size());
		cnt += pos.size() * neg.size();
		for(int i=0;i<(int)pos.size()-1;i++) {
			int ge = (m + pos[i] - 1) / pos[i];
			int j = lower_bound(pos.begin()+i+1, pos.end(), ge) - pos.begin();
			cnt += (j - i - 1);
		}for(int i=0;i<(int)neg.size()-1;i++) {
			int ge = (m + neg[i] - 1) / neg[i];
			int j = lower_bound(neg.begin()+i+1, neg.end(), ge) - neg.begin();
			cnt += (j - i - 1);
		}
	} else if(m == 0) {
		cnt += (ll)pos.size() * neg.size();
	} else {
		for(int i=0;i<pos.size();i++) {
			int g = -m / pos[i];
			int j = upper_bound(ALL(neg), g) - neg.begin();
			cnt += neg.size() - j;
		}	
	}
	return cnt <= k;
}

signed main()
{
	IO_OP;

	cin >> n >> k;
	k--;
	for(int i=0;i<n;i++){
		int t;
		cin >> t;
		if(t == 0) zero++;
		else if(t > 0) pos.PB(t);
		else neg.PB(-t);
	}
	sort(ALL(pos));
	sort(ALL(neg));
	int l = -INF, r = INF;
	while(l <= r) {
		int m = l + (r - l) / 2;
		if(ok(m)) {
			l = m + 1;
		} else {
			r = m - 1;
		}
	}
	cout << r << endl;
}





Measured memory_bytes: 2420
#N, x = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
a.sort()

now = a[0]
nowc = 1
ans = 0
for i in range(1, N):
    if now == a[i]:
        nowc += 1
    else:
        if nowc > now:
            ans += nowc - now
        elif nowc < now:
            ans += nowc
        now = a[i]
        nowc = 1

if nowc > now:
    ans += nowc - now
elif nowc < now:
    ans += nowc

print(ans)


Measured memory_bytes: 14692
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
namespace Ccs
{
    class Program
    {
        static void Main(string[] args)
        {

//            Console.WriteLine(-10 % 3);

            var n = Int64.Parse(Console.ReadLine());
//            Console.WriteLine(n);
            var log = new ArrayList();
            var i = 0;
            while(n != 0)
            {
                var r = n % (Int64)Math.Pow(2, i + 1);

                log.Add( r != 0 ? 1 : 0 );
                n +=  r * (i % 2 == 0 ? -1 : 1)*(n<0?-1:1);

//                Console.WriteLine(i + " " + r + " " + n);
                ++i;
            }

            if (log.Count == 0)
                Console.Write(0);
            else
                for (int j = 0; j < log.Count; ++j)
                    Console.Write(
                            log[log.Count-j-1]
                        );

            Console.WriteLine();
            
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int th,ta,ah,aa,i=0;
  cin >> th >> ta >> ah >> aa;
  while(th>0&&ah>0){
    if(i%2==0)
      ah -= ta;
    if(i%2==1)
      th -= aa;
    i++;
  }
  if(th>0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 3636
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Map;
import java.util.Scanner;
import java.util.HashMap;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
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);
        DFactorization solver = new DFactorization();
        solver.solve(1, in, out);
        out.close();
    }

    static class DFactorization {
        private static final long MOD = (int) 1e9 + 7;
        private static long[] frac;
        private static long[][] npr;
        private static long[] nhr;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 素因数分解 O(log(M)sqrt(N))
            Map<Integer, Integer> facs = new HashMap<>();
            int n = in.nextInt(), m = in.nextInt();
            int p;
            while ((p = getPrimeFactor(m)) > 0) {
                facs.merge(p, 1, (x, y) -> x + y);
                m /= p;
            }
            if (m > 1) {
                facs.merge(m, 1, (x, y) -> x + y);//最大でも2が29個含まれている場合のみ
            }

            // dp - 階乗 O(N + 30)
            frac = new long[n + 30];
            frac[0] = 1;
            for (int i = 1; i < frac.length; i++) {
                frac[i] = (frac[i - 1] * i) % MOD;
            }
            // dp - nPr O(90)
            // 0 <= r <= 30, n <= n' <= n + 30が成立する
            npr = new long[30][30]; // npr[x][y] = (n+y)Px
            Arrays.fill(npr[0], 1);
            for (int i = 0; i < 30; i++) {
                for (int j = 1; j < 30; j++) {
                    npr[j][i] = (npr[j - 1][i] * (n + i - j + 1)) % MOD;
                }
            }
            // dp - nHr O(30)
            nhr = new long[30]; // nhr[r] = nHr
            nhr[0] = 1;
            for (int r = 1; r < 30; r++) {
                nhr[r] = npr[r][r - 1] * pow(frac[r], MOD - 2) % MOD;
            }

            // calc O(log(M))
            long ans = 1;
            for (Integer count : facs.values()) {
                ans *= nhr[count];
                ans %= MOD;
            }

            // output O(1)
            out.println(ans);
        }

        private static int getPrimeFactor(int n) {
            for (int i = 2; i * i <= n; i++) {
                if (n % i == 0) {
                    return i;
                }
            }
            return -1;
        }

        private static long pow(long x, long y) {
            if (y == 0) {
                return 1;
            } else if (y % 2 == 0) {
                long z = pow(x, y / 2);
                return (z * z) % MOD;
            } else {
                return (x % MOD) * pow(x, y - 1) % MOD;
            }
        }

    }
}



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

int main(void){
   int N;
   cin>>N;
   vector<int> A(N);
   for(int i=0;i<N;i++){
      cin>>A[i];
   }
   map<int,int> count;
   for(int i=0;i<N;i++){
      count[A[i]]++;
   }
   int ans=0;
   for(auto c:count){
      if(c.second%2!=0) ans++;
   }
   cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 5376
from bisect import bisect as bi
a,b,q = (int(i) for i in input().split())
s = [int(input()) for i in range(a)]
t = [int(input()) for i in range(b)]
inf = float("inf")
s,t = [-inf]+s+[inf],[-inf]+t+[inf]
def f(x):
    bs,bt = bi(s,x),bi(t,x)
    return min(x-min(s[bs-1],t[bt-1]),max(s[bs],t[bt])-x,t[bt]-s[bs-1]+min(t[bt]-x,x-s[bs-1]),s[bs]-t[bt-1]+min(s[bs]-x,x-t[bt-1]))
for i in range(q):
    x = int(input())
    print(f(x))

Measured memory_bytes: 13324
a, b, c = map(int, input().split())
if a <= b <= c:
    print(a,b,c)
elif a <= c <= b:
    print(a,c,b)
elif b <= a <= c:
    print(b,a,c)
elif b <= c <= a:
    print(b,c,a)
elif c <= a <= b:
    print(c,a,b)
else:
    print(c,b,a)


Measured memory_bytes: 5592
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
double x[1001];
int main()
{
    int n;
    double t,a;
    double ans=999999,anss=1;
    cin>>n>>t>>a;
    for (int i=1;i<=n;i++)
    {
        cin>>x[i];
    }
    for (int i=1;i<=n;i++)
    {
        if ((t-x[i]*0.006)>a) {if((t-x[i]*0.006)-a<ans) {anss=i;ans=(t-x[i]*0.006)-a;}}
        else {if(a-(t-x[i]*0.006)<ans) {anss=i;ans=a-(t-x[i]*0.006);}}
    }
    cout<<anss<<endl;
    return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    // Your code here!
    ll n,m;
    cin>>n>>m;
    cout<<min(n%m,abs(n%m-m));
    
}

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

int main() {
  string s;
  cin >> s ;
  vector<char> a;
  
  for(int i =0; i < s.size() ; i++){
    if(s.at(i) == '0') a.push_back('0');
    else if(s.at(i) == '1') a.push_back('1');
    else if(s.at(i) == 'B' && a.size() > 0) a.pop_back();
  }
  for(int i=0; i < a.size() ; i++) cout << a.at(i) ;
}


Measured memory_bytes: 3580
// This code writed by chtholly_micromaker(MicroMaker)
#include <bits/stdc++.h>
#define reg register
#define int long long
using namespace std;
template <class t> inline void rd(t &s)
{
	s=0;
	reg char c=getchar();
	while(!isdigit(c))
		c=getchar();
	while(isdigit(c))
		s=(s<<3)+(s<<1)+(c^48),c=getchar();
	return;
}
string s,t;
int pn=0;
vector<int> dr[40];
int pos[40];
inline void pos_clear()
{
	for(int i=0;i<26;++i)
		pos[i]=0;
	pn=0;
	return;
}
inline void print()
{
	for(int i=0;i<26;++i)
		cout<<pos[i]<<" ";
	cout<<endl;
	return ;
}
signed main(void)
{
	ios::sync_with_stdio(false);cin.tie(0);
	reg int ans=0;
	cin>>s>>t;
	for(int i=0;i<(int)s.length();++i)
		dr[s[i]-'a'].push_back(i);
		/*
	for(int i=0;i<26;++i)
	{
		cout<<(char)(i+'a')<<": ";
		for(int j=0;j<(int)dr[i].size();++j)
			cout<<dr[i][j]<<" ";
		cout<<endl;
	}
	*/
	pos_clear();
	pn=-1;
	for(int i=0;i<(int)t.length();++i)
	{
		reg int x=t[i]-'a';
//		cout<<"opt: "<<t[i]<<endl;
		if(!dr[x].size())
		{
			cout<<"-1"<<endl;
			return 0;
		}
		if(pos[x]==(int)dr[x].size()||pn==(int)s.length())
		{
			ans+=(int)s.length()-pn;
//			cout<<"ans3+= "<<(int)s.length()-pn<<endl;
			pos_clear();
		}
		else
		{
//			bool flg=false;
			while(dr[x][pos[x]]<=pn)
			{
				++pos[x];
				if(pos[x]==(int)dr[x].size())
				{
//					cout<<"qwq"<<endl;
					ans+=(int)s.length()-pn;
//					cout<<"ans2+= "<<(int)s.length()-pn<<endl;
					pos_clear();
//					flg=true;
					break;
				}
			}
			ans+=dr[x][pos[x]]-pn;
//			if()
//			cout<<"ans1+= "<<dr[x][pos[x]]-pn<<endl;
			pn=dr[x][pos[x]];
		}
//		print();
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 1736
#include<iostream>
#include<set>
#include<algorithm>
#include<list>
#include<queue>

#define MAX 110

using namespace std;

class Node{
public:
  set<int> con;
};

typedef vector<Node> graph;
typedef vector< vector<int> > forest;

void MakeForest(const graph &g, bool exist[MAX], forest &f){
  bool vis[MAX]={false};
  for(int x=0;x<MAX;++x){
    if(!vis[x]&&exist[x]){
      queue<int> q;
      bool tvis[MAX]={false};
      q.push(x);
      tvis[x]=true;
      while(!q.empty()){
	int now=q.front();q.pop();const set<int> &C=g[now].con;
	for(set<int>::iterator its=C.begin();its!=C.end();++its){
	  if(!tvis[*its]){tvis[*its]=true;q.push(*its);}
	}
      }
      vector<int> tmp;
      f.push_back( tmp );
      for(int i=0;i<MAX;++i){
	if(tvis[i]){
	  vis[i]=true;
	  f.back().push_back( i );
	}
      }
    }
  }
}

int Backtrack(int pos, int now, int &bans, bool vis[], int memo[], const graph &G){
  const set<int> &C = G[pos].con;
  int ret = now;
  if(vis[pos]){return now;}
  vis[pos]=true;
  if(now+memo[pos]<=bans)return bans;
  for(set<int>::iterator itc=C.begin();itc!=C.end();++itc){
    int nx = *itc;
    bans=max(bans,now+1);
    ret=max(ret,Backtrack(nx,now+1,bans,vis,memo,G) );
    bans=max(bans,ret);
  }
  vis[pos]=false;
  return ret;
}

bool gtV(const vector<int> &v1, const vector<int> &v2){
  return v1.size()>v2.size();
}

int main()
{
  while(true){
    int ans = 2;
    int n;
    cin >> n;
    if( n == 0 )break;
    graph G(MAX);
    forest F;
    bool exist[MAX]={false,};
    for(int i = 0;  i < n ; ++i){
      int a,b;
      cin >> a >> b;
      exist[a]=exist[b]=true;
      G[a].con.insert(b);
      G[b].con.insert(a);
    }

    MakeForest(G,exist,F);

    int memo[MAX];
    for(int i=0;i<MAX;++i){
      memo[i]=MAX*MAX;
    }

    sort(F.begin(),F.end(),gtV);

    for(int f=0;f<F.size();++f){
      if(F[f].size()<=ans)continue;
      for(int i = 0; i < F[f].size(); ++i){
	int st=F[f][i];
	bool vis[MAX]={false,};
	int btret = Backtrack( st, 0, ans, vis, memo, G );
	memo[st]=btret;
	ans=max(ans,btret);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i, x) for (long long i = 0; i < x; i++)
#define repn(i, x) for (long long i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
vector<pair<string, P> > vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(long long N, long long M) {
    if (M % 2 == 0) {
        repn(i, M / 2) { cout << i << " " << M + 1 - i << endl; }
        repn(i, M / 2) { cout << M + i << " " << 2 * M + 2 - i << endl; }
    } else {
        repn(i, M / 2 + 1) { cout << i << " " << M + 2 - i << endl; }
        repn(i, M / 2) { cout << M + 1 + i << " " << 2 * M + 2 - i << endl; }
    }
}

int main() {
    long long N;
    scanf("%lld", &N);
    long long M;
    scanf("%lld", &M);
    solve(N, M);
    return 0;
}


Measured memory_bytes: 3772
import java.util.*;
import java.lang.*;

class Mod{
    static final long MOD = 1000_000_007;
    static final long[] fact = makeFactorialArray(1000000);
    static final long[] factInv = makeInversedArray(fact);

    public static long add(long a, long b){
        long tmp = (a+b)%MOD;
        return tmp>=0 ? tmp : tmp+MOD;
    }
    public static long adds(long... ar){
        long ans=0;
        for(long x:ar) ans = Mod.add(ans, x);
        return ans;
    }
    public static long sub(long a, long b){
        return add(a,-b);
    }
    public static long mult(long a, long b){
        long tmp = (a*b)%MOD;
        return tmp>=0 ? tmp : tmp+MOD;
    }
    public static long mults(long... ar){
        long ans=1;
        for(long x:ar) ans = Mod.mult(ans, x);
        return ans;
    }
    public static long power(long a, long x){ //calculate a^x
        if(x<0)return 0;
        if(x==0)return 1;
        if(x%2==0) {
            long half = power(a,x/2);
            return mult(half,half);
        }
        return (a*power(a,x-1)) % MOD;
    }
    public static long inverse(long a){
        return power(a,MOD-2);
    }
    public static long div(long a, long b){
        return mult(a, inverse(b));
    }
    public static long[] makeFactorialArray(int size){
        long[] array = new long[size];
        array[0]=1;
        for(int i=1;i<size;i++){
            array[i]=mult(array[i-1],i);
        }
        return array;
    }
    public static long[] makeInversedArray(long[] original){
        long[] array = new long[original.length];
        for(int i=0;i<original.length;i++){
            array[i] = inverse(original[i]);
        }
        return array;
    }
    public static long combination(long n, long r){
        int N = (int)n,  R = (int)r;
        if(n<0 || r<0 || n<r) return 0;
        return mults(fact[N],factInv[R],factInv[N-R]);
    }
    public static long permutation(long n, long r){
        int N = (int)n,  R = (int)r;
        if(n<0 || r<0 || n<r) return 0;
        return mult(fact[N], factInv[N-R]);
    }
}
public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        long[] A = new long[N];
        for(int n=0; n<N; n++) A[n]=sc.nextLong();
        Arrays.sort(A);

        long ans = 0;

        for(int n=0; n<N; n++){
            ans = Mod.add(ans,
                          Mod.mults(A[n],
                                    Mod.sub(Mod.combination(n, K-1),
                                            Mod.combination(N-n-1, K-1))));
        }

        System.out.println(ans);

    }

}


Measured memory_bytes: 98352