akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b==c)cout<<"Yes"<<endl;
    else if(a+c==b)cout<<"Yes"<<endl;
    else if(b+c==a)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int a,b;
  scanf("%d %d",&a,&b);
  if (a+b>=a-b) {
    if (a+b>=a*b) {
      printf("%d\n",a+b);
    }else{
      printf("%d\n",a*b);
    }
  }else{
    if (a-b>=a*b) {
      printf("%d\n",a-b);
    }else{
      printf("%d\n",a*b);
    }
  }
  return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define piii pair<pii,int>
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;

const int N= (1<<18)+5 ;
ll arr[N];
pair<ll,ll> mxp[N];
ll ans[N];

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	int n;
	cin>>n;
	for(int i=0;i<1<<n;i++){
		cin>>arr[i];
		mxp[i] = {i,-1};
	}
	for(int i=1;i<1<<n;i++){
		int j = 0;
		set<pair<ll,ll>,greater<> > x;
		x.insert({arr[i],i});
		while(j<n){
			if((1<<j)&i){
				x.insert({arr[mxp[i^(1<<j)].fi],mxp[i^(1<<j)].fi});
				x.insert({arr[mxp[i^(1<<j)].fi],mxp[i^(1<<j)].fi});
			}
			j++;
		}
		auto it = x.begin();
		ll tans = (*it).fi + (*++it).fi;
		it--;
		ans[i] = max(tans, ans[i-1]);
		mxp[i] = {(*it).se,(*++it).se};
		cout<<ans[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 11264
# B - Palace
N = int(input())
T, A = map(int,input().split())
H = list(map(int, input().split()))

ave = 0
tmp = 0
ans_t = 10**5
ans = 0
for i in range(N):
    ave = T - H[i]*0.006
    tmp = abs(A - ave)
    if ans_t > tmp:
        ans_t = tmp
        ans = i + 1
    else:
        pass

print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#define REP(i,n) for (int i=1;i<=(n);++i)
#define FOR(i,a,b) for (int i=(a);i<=(b);++i)
#define ROF(i,a,b) for (int i=(a);i>=(b);--i)
#define FEC(p,u) for (edge*p=head[u];p;p=p->nxt)
using namespace std;
typedef long long LL;

LL n, s, b;
int main(){
	cin >> n >> s;
	if (s == n) { cout << n+1 << endl; return 0; }
	//if (s > n/2+1) { cout << -1 << endl; return 0; }
	for (b = 2; b*b <= n; ++b) {
		LL t = 0;
		for (LL x = n; x; x /= b) t += x%b;
		if (t == s) { cout << b << endl; return 0; }
	}
	LL sqn = b-1;
	b = -1;
	for (LL u = 1; u*u <= n-s && u <= s; ++u)
		if ((n-s)%u == 0){
			LL bb = (n-s)/u+1;
			if (bb <= sqn || bb*2 <= s) break;
			if (u < bb && s-u < bb) b = bb;
		}
	cout << b << endl;
	return 0;
}


Measured memory_bytes: 256
N,X=map(int,input().split())
l=list(map(int,input().split()))
L=sorted(l)
kids=0
ans=0
for i in range(N):
  kids+=L[i]
  if kids<=X:
    ans+=1
  else:
    break
    
if sum(L)>=X:
  print(ans)
  
else:
  print(ans-1)

Measured memory_bytes: 3060
(format t "~d~%"
	(let* ((k (read))
	       (n (read))
	       (a (make-sequence 'vector n)))
	  (loop for i upto (1- n) do (setf (elt a i) (read)))
	  (- k (max (loop for i from 1 upto (1- n)
		       maximize (- (elt a i) (elt a (1- i))))
		    (- (+ k (elt a 0)) (elt a (1- n)))))))

Measured memory_bytes: 69476
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int main() {
	int n, s[1000], sum;
	double a, avg, ssum;

	while (1) {
		ssum = 0;
		sum = 0;

		cin >> n;

		if (n == 0)
			break;

		for (int i = 0; i < n; i++) {
			cin >> s[i];

			sum += s[i];
		}

		avg = 1.0*sum / n;

		for (int i = 0; i < n; i++) {
			ssum += pow(s[i] - avg, 2);
		}

		a = ssum / n;

		cout << sqrt(a) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1236
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		int M = input.nextInt();
		int START = input.nextInt();
		int C1 = 0;
		int C2 = 0;
		int[] toll = new int[M];
		for (int i = 0; i < M; i++) {
			toll[i] = input.nextInt();
		}
		for (int i = START+1; i<=N; i++) {
			for (int check = 0; check < M; check++) {
				if (i==toll[check]) {
					C1++;
					break;
				}
			}
		}
		for (int i = START-1; i>=0; i--) {
			for (int check = 0; check < M; check++) {
				if (i==toll[check]) {
					C2++;
					break;
				}
			}
		}
		System.out.println(Math.min(C1, C2));
	}
}

Measured memory_bytes: 21844
<?php
while (true){
    list($n, $x) = explode(" ", trim(fgets(STDIN)));
    if ($n == 0 && $x == 0) {
        break;
    }
    $count = 0;
    for ($first_num = 1; $first_num <= $n; $first_num++) {
        for ($second_num = $first_num + 1; $second_num <= $n; $second_num++) {
            for ($third_num = $second_num + 1; $third_num <= $n; $third_num++) {
                if ($first_num + $second_num + $third_num == $x) {
                   $count++;
                }
            }
        }
    }
echo $count. PHP_EOL;
}


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

int main(){
  string S;
  cin>>S;
  int l=S.size();
  int a=0,b=0;
  for(int i=0;i<l;i++){
    if(S[i] == '0') a++;
    else b++;
  }
  cout << 2*min(a,b) <<endl;
}

Measured memory_bytes: 512
#include<stdio.h>
int main(void) {
	int n;
    int p[1][21];

	scanf("%d", &n);

	int i;

	for (i = 0; i < n; i++) {
		scanf("%d", &p[0][i]);
	}

	int count = 0;

	for (i = 1; i < n-1; i++) {
		if (p[0][i-1]< p[0][i]&&  p[0][i]< p[0][i +1]|| p[0][i - 1] > p[0][i] && p[0][i] > p[0][i + 1]){
			count++;
			
		}
	}




	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 128
[a,b,h,m]=list(map(int,input().split()))
fun=60*h+m
import math

tyo=(2*math.pi/60)*fun
tan=(math.pi/360)*fun
tyoo=tyo//(2*math.pi)
tyo=tyo-2*math.pi*tyoo

theta=abs(tyo-tan)
ans=math.sqrt(a**2+b**2-2*a*b*math.cos(theta))

print(ans)

Measured memory_bytes: 9540
#include<stdio.h>
#include<string.h>
int main()
{
    char str[11],ch;
    int a,b,c;
    scanf("%s",str);
    ch=str[3];
    str[0]='2';
    str[1]='0';
    str[2]='1';
    str[3]='8';
    str[4]='/';
    str[5]='0';
    str[6]='1';
    str[7]='/';
    printf("%s\n",str);

    return 0;
}


Measured memory_bytes: 128
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.TreeMap;

class Main {

	public static void main(String[] args) {

		Scanner sc = null;
		Map<Integer, Integer> nums = new TreeMap<Integer, Integer>();
		try {
			sc = new Scanner(System.in);
			int maxValue = 0;
			while (sc.hasNextInt()) {
				int num = sc.nextInt();
				nums.put(num, nums.containsKey(num) ? nums.get(num) + 1 : 1);
				if (maxValue < nums.get(num)) {
					maxValue = nums.get(num);
				}
			}
			for (Entry<Integer, Integer> entry : nums.entrySet()) {
				if (maxValue == entry.getValue()) {
					System.out.println(entry.getKey());
				}
			}

		} finally {
			sc.close();
		}
	}
}

Measured memory_bytes: 26308
N,K=map(int,input().split())
S=input()
SC=[]
c=1
for i in range(N-1):
    if S[i]!=S[i+1]:
        SC.append(c)
        c=1
    else:
        c+=1

SC.append(c)

L=len(SC)

if L<=K+1:
    print(N-1)

else:
    ans=sum(SC[0:2*K+1])-1
    for i in range(2*K+1,L):
        if SC[i]>1:
            ans+=SC[i]-1
    print(ans)

Measured memory_bytes: 4724
/*
题意

给出一个字符串，每次操作可以使得字符串缩短一位，且第$i$位必须要保证与变换前的这一位或下一位相同，问使得整个字符串全相同最少的操作次数

Sol

300P的题我都要想10min啊，还是太菜了。。
首先我们可以枚举一个字母，强行让他成为最后的答案
对于末尾与它不同的数只能一个个删掉，而中间的数需要从下一个与它相同的一个个传递而来
取一下max即可
所以，，我们就用一个$O(26n)$的算法A掉了一个$n \leqslant 100$的题？？？？
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN = 1e6 + 10, INF = 1e9 + 10;
int N;
char s[MAXN];
int check(char x) {
	int pre = 0, ans = 0;
	for(int i = 1; i <= N; i++)
		if(s[i] == x) 
			ans = max(ans, i - pre - 1), pre = i;
	return max(ans, N - pre);
}
main() {
	scanf("%s", s + 1);
	N = strlen(s + 1);
	int ans = INF;
	for(char i = 'z'; i >= 'a'; i--) 
		ans = min(ans, check(i));
	printf("%d", ans);
	return 0;
}
/*
1
12 11
*/


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

using namespace std;

typedef vector <int> vi;
typedef list <int> li;

vi x[100001];
int ind[100001];
bool isvisited[100001];
li y;

void bfs(int a)
{
	queue <int> qqq;
	qqq.push(a);
	isvisited[a] = true;
	while(!qqq.empty())
	{
		int p = qqq.front();
		qqq.pop();
		y.push_back(p);
		for(int i = 0;i < x[p].size();i ++)
		{
			int xx = x[p][i];
			ind[xx] --;
			if(!isvisited[xx] && ind[xx] == 0)
			{
				isvisited[xx] = true;
				qqq.push(xx);
			}
		}
	}
}

void topo (int v)
{
	for(int i = 0;i < v;i ++)
		for(int j = 0;j < x[i].size();j ++)
			ind[x[i][j]] ++;
	for(int i = 0;i < v;i ++)
		if(!ind[i] && !isvisited[i])
			bfs(i);
	for(list <int> :: iterator it = y.begin();it != y.end();it ++)
	{
		cout << * it << endl;
	}
	//cout << endl;
}

int main()
{
	int v,e;
	int a,b;
	scanf("%d %d",&v,&e);
	for(int i = 1;i <= e;i ++)
	{
		scanf("%d %d",&a,&b);
		x[a].push_back(b);
	}
	topo (v);
	return 0;
} 

Measured memory_bytes: 6236
/* Author: $%U%$
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/
#include <bits/stdc++.h>
using namespace std;
#define fore(i, a, b) for (int i = a, to = b; i < to; i++)
#define all(v) v.begin(), v.end()
#define SZ(v) (int)v.size()
#define pb push_back
typedef long long Long;
typedef pair<int, int> Pair;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  int k, a, b;
  cin >> k >> a >> b;
  int top = (a + k - 1) / k;
  if (top * k <= b) {
    cout << "OK\n";
  } else {
    cout << "NG\n";
  }

  return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;
char a[1000001];
int l,h,hh;
int main()
{
	cin>>a;
	l=strlen(a);
	for(int i=0;i<=l;i++)
	{
		if(a[i]=='A')
		{
			h=i;
			break;
		}
	}
	for(int i=l-1;i>=0;i--)
	{
		if(a[i]=='Z')
		{
			hh=i;
			break;
		}
	}
	cout<<hh-h+1<<endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ff double
#define endl "\n"
#define TEST_CASE   int t;cin>>t;while(t--)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;

void solve(){
  ff n ;
  cin>>n;
  cout<<ceil(n/2)<<endl;

}


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




Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
typedef long long LL;
#define F(i) for(int i=0;i<n;i++)
int main(){
	string s;
	int k;
	cin>>s;
	cin>>k;
	int l=s.size();
	for(int i=0;i<l;i++){
		if(i+1==k){cout<<s[i];break;}
		if(s[i]!='1'){cout<<s[i];break;}
		if(i+1==l){cout<<1;break;}
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(), (v).end()
#define lp(i, n) for (int i = 0; i < (n) ; ++i)
#define sz(v) (ll)(v).size()
#define int long long
#define mod 1000000007

int32_t main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        string str; cin >> str;
        int an = 0;
        lp(i, str.size()/2) {
                if (str[i] != str[str.size() - 1 - i]) an++;
        }
        cout << an;
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <iomanip>

#include <map>
#include <set>
#include <queue>
#include <stack>

#define ALL(a) (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 rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdbl vector<double>
#define vstr vector<string>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	ll N,L;
	cin >> N >> L;

	ll a[N];
	rep(i,N) cin >> a[i];

	// a[i-1] + a[i] >= L を満たすiが存在すれば
	// 1,2, ..., i-1, N-1, N-2, ..., i+1, i と切ればよい
	// 存在しなければ切れない

	FOR(i,1,N){
		if((a[i-1]+a[i]) >= L){
			cout << "Possible" << endl;
			FOR(j,1,i) cout << j << endl;
			RFOR(j,N,i)	cout << j << endl;
			return 0;
		}
	}

	cout << "Impossible" << endl;
}

Measured memory_bytes: 1664
#include <iostream>
#define N 100000
using namespace std;
int n,S[N],q,T,result,cnt,i;
int binarySearch(int);
int main(){
  cin >> n;
  for(i=0;i<n;i++) cin >> S[i];
  cin >> q;
  cnt=0;
  for(i=0;i<q;i++){
    cin >> T;
    result=binarySearch(T);
    if(result==1) cnt++;
  }
  cout << cnt << endl;
  return 0;
}
int binarySearch(int key){
  int left=0,right=n,mid;
  while(left<right){
    mid=(left+right)/2;
    if(S[mid]==key) return 1;
    else if(key<S[mid]) right=mid;
    else left=mid+1;
  }
  return 0;
}

Measured memory_bytes: 1548
/*
 _    _    _______   _    _
| |  / /  |  _____| | |  / /
| | / /   | |       | | / /
| |/ /    | |_____  | |/ /
| |\ \    |  _____| | |\ \
| | \ \   | |       | | \ \
| |  \ \  | |_____  | |  \ \
|_|   \_\ |_______| |_|   \_\

*/
/*#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <cstring>
#include <string>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <assert.h>*/

#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define right(x) x << 1 | 1
#define left(x) x << 1
#define forn(x, a, b) for (int x = a; x <= b; ++x)
#define for1(x, a, b) for (int x = a; x >= b; --x)
#define mkp make_pair
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define y1 kekekek

const ll ool = 1e18 + 9;
const int oo = 1e9 + 9, base = 1e9 + 7;
const ld eps = 1e-7;
const int N = 2e6 + 6;

int n;
ll d[N], a[N];
vector < int > g[N];

void dfs(int v, int par) {
    if (sz(g[v]) == 1) {
        d[v] = a[v];
        return;
    }
    ll sum = 0, mx = 0;
    for (auto to : g[v]) {
        if (to == par) continue;
        dfs(to, v);
        sum += d[to];
        mx = max(mx, d[to]);
    }
    ll need = sum - a[v];
    ll lim = (mx <= sum / 2 ? sum / 2 : sum - mx);
    if (lim < need || a[v] > sum) {
        cout << "NO\n";
        exit(0);
    }
    d[v] = a[v] - need;
    if (d[v] < 0) {
        cout << "NO\n";
        exit(0);
    }
}

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

	cin >> n;
	forn(i, 1, n) {
        cin >> a[i];
	}

	forn(i, 1, n - 1) {
        int x, y;
        cin >> x >> y;
        g[x].eb(y);
        g[y].eb(x);
	}
	
	if (n == 2) {
        cout << (a[1] == a[2] ? "YES" : "NO") << "\n";
        return 0;
	}

    int root = 1;
    while (sz(g[root]) == 1) ++root;

    dfs(root, 0);

    cout << (d[root] == 0 ? "YES" : "NO") << "\n";

	return 0;
}


Measured memory_bytes: 61312
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
f=int(input())
g=int(input())
h=int(input())
i=int(input())
j=int(input())
print(a+b+c+d+e+f+g+h+i+j)


Measured memory_bytes: 5584
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N;
  cin>>N;
  
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  
  
  sort(A.begin(),A.end());
  
  int ans=A[N-1]/2;
  
  for(int i=0;i<N-1;i++){
    ans+=A[i];
  }
  
  
  cout<<ans<<endl;
}

Measured memory_bytes: 3644
n=int(input())
A=["-1"]+list(map(int,input().split()))

S={}
D={}

for i in range(1,n+1):
    a=A[i]
    if a+i in S.keys():
        S[a+i]+=1
    else:
        S[a+i]=1
    if i-a in D.keys():
        D[i-a]+=1
    else:
        D[i-a]=1
    
ans=0

for k in S.keys():
    if k in D.keys():
        ans+=S[k]*D[k]

print(ans)

Measured memory_bytes: 53400
/*
If you want to shine like a sun, first burn like a sun.
*/

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds;
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define vpi vector<ppi>
#define vpl vector<ppl>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf 9e18
#define minf -9e18
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set
#define pi 3.141592653589793
#define MAXN 100005
#define test1(x) cout << #x " = " << x << endl;
#define test2(x,y) cout << #x " = " << x << " " << #y " = " << y << endl;
const ll infinity = 9e18;

/*
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
bool isprime(ll n){if(n < 2) return 0; ll i = 2; while(i*i <= n){if(n%i == 0) return 0; i++;} return 1;}
*/
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }


int main()
{
    fast

/*
    #ifndef ONLINE_JUDGE
        freopen("input.txt",  "r",  stdin);
        freopen("output.txt", "w", stdout);
    #endif
//*/

        
    ll a,b;
    cin>>a>>b;

    cout<<LCM(a,b);









    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#define MAX 100005
#define NIL -1

/*
p: parent
l: left-child
r: right sibling
*/
struct Node{ int p, l, r; };
struct Node T[MAX]; // Tree

int depth(int u){
	int d = 0;
	if (T[u].p == -1){ return 0; }
	return 1 + depth(T[u].p);
}

void print_child(int u){
	if (u == -1){ return 0; }  
	if (T[u].r == -1){ printf("%d", u); return 0; }
	printf("%d, ", u);
	print_child(T[u].r);
}

void print(int u){
	printf("node %d: parent = %d, depth = %d, %s, [", u, T[u].p, depth(u), T[u].p == -1 ? "root" : (T[u].l == -1 ? "leaf" : "internal node"));
	print_child(T[u].l);
	printf("]\n");
}

main(){
	int i, j, d, v, c, l, n;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		T[i].p = T[i].l = T[i].r = NIL;
	}

	for (i = 0; i < n; i++){
		scanf("%d %d", &v, &d);
		for (j = 0; j < d; j++){
			scanf("%d", &c);
			T[c].p = v;
			if (j){
				T[l].r = c;
			}
			else{
				T[v].l = c;
			}
			l = c;
		}
	}
	for (i = 0; i < n; i++) print(i);
	return 0;
}

Measured memory_bytes: 1784
#include <iostream>
using namespace std;
int main(void){
    string o, e;
    cin >> o >> e;
    
    int ol = o.length();
    int el = e.length();

    
    for(int i = 0; i < ol; ++i){
        if((i == ol - 1) && (ol == el + 1)){
            cout << o[i];
        } else if((i != ol - 1) || (ol == el)) {
            cout << o[i] << e[i];
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    cout << std::fixed << std::setprecision(10);
    lli a, b;
    cin>>a>>b;
    out(max(a+b, max(a-b, a*b)));
}

Measured memory_bytes: 3604
import sys
readline = sys.stdin.readline
N = int(readline())
T = []
S = 0
for i in range(N):
    a, b = map(int, readline().split())
    T.append((b, a))
    S += a
T.sort(reverse=1)
cur = 0
while cur < N:
    t, v = T[cur]; cur += 1
    if t < S:
        print("No")
        break
    S -= v
    while cur < N and t == T[cur][0]:
        S -= T[cur][1]
        cur += 1
else:
    print("Yes")

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


using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define repv(arr)  for(auto it=arr[i].begin();it!=arr[i].end();it++)  
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vl vector<long long int>
#define sortA(arr)   sort(arr.begin(),arr.end())
#define search(arr,c)  binary_search(arr.begin(),arr.end(),c)
#define pb   push_back
#define ll long long
#define LCM(a,b) boost::math::lcm(a,b)
#define cl_bf cin.ignore(numeric_limits<streamsize>::max(), '\n');

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  	int n;
 	vi arr(5);
  int index;
  rep(i,0,5){
    cin>>arr[i];
    if(arr[i]==0)
      index=i;
  }
  cout<<index+1<<endl;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pi;
int p[55];
vector<pi>edge;
int u_find(int a){
	if(!p[a]) return a;
	return p[a] = u_find(p[a]);
}
void merge(int a,int b){
	a = u_find(a);
	b = u_find(b);
	if(a==b) return;
	p[a] = b;
}
bool solve(int num,int n){
	memset(p,0,sizeof(p));
	for(int i=0; i<edge.size(); i++){
		if(i!=num) merge(edge[i].first,edge[i].second);
	}
	for(int i=1; i<=n; i++){
		if(u_find(1)!=u_find(i)) return true;
	}
	return false;
}
int main(){
	int n,m;
	cin>>n>>m;
	
	while(m--){
		int a,b;
		cin>>a>>b;
		edge.push_back(pi(a,b));
	}
	int ret = 0;
	for(int i=0; i<edge.size(); i++){
		if(solve(i,n)) ret++;
	}
	cout<<ret;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main()
{
 int i,j,k,l,ns,nt;
 string s,t;
 cin >> s;
 cin >> t;
 ns=s.length();
 nt=t.length();
 int a[ns+1][nt+1];
 for(i=0;i<=ns;i++)
 {
  for(j=0;j<=nt;j++)
  {
   if(i==0 || j==0)
   a[i][j]=0;
   else if(s.at(i-1)==t.at(j-1))
   a[i][j]=a[i-1][j-1]+1;
   else
   a[i][j]=max(a[i-1][j],a[i][j-1]);
  }
 }
 l=a[ns][nt];
 char x[l];
 i=ns;
 j=nt;
 k=l-1;
 while(i>0 && j>0)
 {
  if(s.at(i-1)==t.at(j-1))
  {
   x[k]=s.at(i-1);
   i--;
   j--;
   k--;
  }
  else if(a[i-1][j]>a[i][j-1])
  i--;
  else
  j--;
 }
 for(i=0;i<l;i++)
 cout << x[i];
 return 0;
}

Measured memory_bytes: 35456
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int k = sc.nextInt();
		// スペース区切りの整数の入力
		int a = sc.nextInt();
        int b = sc.nextInt();

        boolean canSuccess = false;
        for (int i = a; i <= b; i++) {
            canSuccess = (i % k) == 0;
            if(canSuccess) {
                break;
            }
        }

		// 出力
		System.out.println(canSuccess ? "OK" : "NG");
	}
}

Measured memory_bytes: 35840
#include <stdio.h>
#include <stdlib.h>

int main(void){
    long long a,b;
    scanf("%lld%lld",&a,&b);
    if (a*b<=0){
        printf("Zero\n");
    } else if (a>0){
        printf("Positive\n");
    } else {
        if (((b*-1)-(a*-1))%2==0){
            printf("Negative\n");
        } else {
            printf("Positive\n");
        }
    }
	return 0 ;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<P, ll> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e5) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int n;
    cin >> n;
    vector<ll> a(n+1, 0);
    for(int i=0;i<n;i++){
        cin >> a[i+1];
        a[i+1] += a[i];
    }
    ll ans = LLINF;
    for(int i=2;i<=n-2;i++){
        int id1, id2;
        ll p, q, r, s;
        id1 = lower_bound(a.begin(), a.begin()+i, a[i]/2) - a.begin();
        if(abs(a[id1]-(a[i]-a[id1])) < abs(a[id1-1]-(a[i]-a[id1-1]))){
            p = a[id1]; q = a[i]-a[id1];
        }
        else{
            p = a[id1-1]; q = a[i]-a[id1-1];
        }
        id2 = lower_bound(a.begin()+i, a.end(), (a[n]+a[i])/2) - a.begin();
        if(abs((a[id2]-a[i])-(a[n]-a[id2])) < abs((a[id2-1]-a[i])-(a[n]-a[id2-1]))){
            r = a[id2]-a[i]; s = a[n]-a[id2];
        }
        else{
            r = a[id2-1]-a[i]; s = a[n]-a[id2-1];
        }
        ans = min(ans, max({p,q,r,s}) - min({p,q,r,s}));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1920
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n');
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr('time : ' + end + 'ms');
  myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var N = nextInt();
  var list = new Array(N);
  for(var i = 0; i < N; i++){
  	var Ai = nextInt();
  	list[i] = {
  		check : []
  	};
  	for(var j = 0; j < Ai; j++){
  		var tmp = nextIntArray();
  		list[i].check.push([tmp[0] - 1, tmp[1]]);
  	}
  }
  var max = 0;
  for(var i = 0; i < (1 << N); i++){
  	var selected = [];
    for(var j = 0; j < N; j++){
      if((i & (1 << j)) != 0){
        selected.push(j);
      }
    }
    var count = selected.length;
    var isOK = true;
    for(var j = 0; j < selected.length; j++){
    	var tmpcheck = list[selected[j]].check;
    	for(var k = 0; k < tmpcheck.length; k++){
    		if(tmpcheck[k][1] == 0){
    			if(selected.indexOf(tmpcheck[k][0]) != -1){
    				isOK = false;
    				break;
    			}
    		}else{
    			if(selected.indexOf(tmpcheck[k][0]) == -1){
    				isOK = false;
    				break;
    			}
    		}
    	}
    }
    if(isOK){
    	max = Math.max(max, count);
    }
  }
  myout(max);
}

Measured memory_bytes: 36052
s = input()
k = int(input())
ren = []
n = 1
p = s[0]
for i in range(1,len(s)):
    if p == s[i]:
        n += 1
    else:
        ren.append(n)
        p = s[i]
        n = 1
ren.append(n)

ans = 0
if ren[0] == len(s):
    ans = (ren[0]*k)//2
elif s[0] == s[-1]:
    ans = ren[0]//2 + ren[-1]//2 - (ren[0]+ren[-1])//2
    ren[0] += ren[-1]
    ren[-1] = 0
    for i in ren:
        ans += (i//2)*k
else:
    for i in ren:
        ans += (i//2)*k

print(ans)


Measured memory_bytes: 3064
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;文字列 -> 整数
(defn Int [s] (Integer/parseInt s))
;文字列 -> 文字列
(defn Str [s] s)

;scanf的なノリで1行をいい感じに読み取る
;定数が重いので注意
(defn input [varTypes]
    (mapv 
        (fn [f s] (f s)) ;文字列sに関数fを適用する
        varTypes         ;適用する関数
        (clojure.string/split 
            (read-line)  ;1行を読み込み
            #" "         ;区切り文字
        )
    )
)

;スペース区切りの整数を受け取る
;速い
(defn inputFast [varType]
    (map
        varType
        (clojure.string/split 
            (read-line)  ;1行を読み込み
            #" "         ;区切り文字
        )
    )
)

(defn floor [a b] (quot a b))
(defn ceil [a b] (floor (- (+ a b) 1) b))
(defn abs [a] (if (>= a 0) a (- 0 a)))

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
(let [[a b] (inputFast Int)]
    (println 
        (if (= (mod (* a b) 2) 1)
            "Odd"
            "Even"
        )
    )
)

Measured memory_bytes: 65432
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>

using namespace std;

#define ll long long

void solve()
{
    ll N;
    cin >> N;
    vector<ll> A(N + 1);
    vector<ll> B(N);

    for (ll i = 0; i < N + 1; i++)
    {
        cin >> A.at(i);
    }
    for (ll i = 0; i < N; i++)
    {
        cin >> B.at(i);
    }

    ll count = 0;
    for (ll i = N - 1; i >= 0; i--)
    {
        // i+1の処理
        if (A.at(i + 1) >= B.at(i))
        {
            A.at(i + 1) -= B.at(i);
            count += B.at(i);
            B.at(i) = 0;
        }
        else
        {
            B.at(i) -= A.at(i + 1);
            count += A.at(i + 1);
            A.at(i + 1) = 0;
        }

        // iの処理
        if (A.at(i) >= B.at(i))
        {
            A.at(i) -= B.at(i);
            count += B.at(i);
            B.at(i) = 0;
        }
        else
        {
            B.at(i) -= A.at(i);
            count += A.at(i);
            A.at(i) = 0;
        }
    }

    cout << count << endl;

    return;
}

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


Measured memory_bytes: 1792
def print_grid(table):
    for t in table:
        temp = ''.join(t)
        temp = temp.replace('1','#')
        temp = temp.replace('0','.')
        print(temp)

A, B = map(int, input().split())
h=100
w = 100
K = 50
table = [['0' for i in range(h)] for j in range(w)]
for i in range(K) :
    for j in range(w):
        table[i][j] = '1'
x,y = 0,0
for a in range(A-1):
    table[x][y] = '0'
    y = y + 2
    if(y > 99):
        y = 0
        x = x + 2
x,y = 51,0
for b in range(B-1):
    table[x][y] = '1'
    y = y + 2
    if(y > 99):
        y = 0
        x += 2
print('100 100')
print_grid(table)


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

int N, K;

int main() {
    cin >> N >> K;
    
    if (K % 2 == 0) {   //Kが偶数のとき
        int n = N / K;  //N以下のKの倍数
        int half = (N + K / 2) / K; //N以下のKで割った余りK / 2
        cout << 1ll * n * n * n + 1ll * half * half * half << endl;
    } else {    //Kが奇数のとき
        int n = N / K;  //N以下のKの倍数の数
        cout << 1ll * n * n * n << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt(),a = sc.nextInt(),b = sc.nextInt();
    x -= a + b;
    while(x>=b){
      x -= b;
    }
    System.out.println(x);
  }
}


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

int main(){
    int a,b;
    cin >> a >> b;
    if( (a*b) % 2 == 0) cout << "No" << endl;
    else cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define task "TASK"
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))

const int N=100010;



main(){
    //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);
    int n=in;
    cout<<(n&1 ? n>1 ? n/2 : 0 : n/2-1);
}


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

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll s[110000];
bool ok;
ll a1, ans;
int main() {
	a1 = 1;
	ll n;
	cin >> n;
	REP(i, n) {
		cin >> s[i];
	}
	REP(i, n - 1) {
		if (s[i] >= s[i + 1])a1++;
	}
	cout << a1 << endl;
	cout << n << endl;
}




Measured memory_bytes: 3888
MAX = 1000000
MOD = 1000000007

fac = [None] * MAX
finv = [None] * MAX
inv = [None] * MAX

def comb_init():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, MAX):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

def comb(n, k):
    if n < 0 or k < 0 or n < k:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD

comb_init()
X, Y = map(int, input().split())

n = (2 * Y - X) // 3
m = (2 * X - Y) // 3

if (X + Y) % 3 != 0 or n < 0 or m < 0:
    print(0)
    exit()

print(comb(n + m, n))


Measured memory_bytes: 127408
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int x = 0;
    x = n % 10 % 10;
    if (x == 2 || x == 4 || x == 5 || x == 7 || x == 9) {
      System.out.println("hon");
    } else if (x == 0 || x == 1 || x == 6 || x == 8) {
        System.out.println("pon");
    } else if (x == 3) {
      System.out.println("bon");
    }
  }

}

Measured memory_bytes: 35700
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
=begin
=end

class Rr
  def initialize(n, qtm, vnm,vtm)
    @qtm=qtm
    @nm = Array.new(n)
    @tm = Array.new(n)
    0.upto(n-1).each{|i|
      @nm[i] = vnm[i].to_s
      @tm[i] = vtm[i].to_i
    }
  end

  def exe()
    t=0
    nm_e=[]
    tm_e=[]
    while @nm.length > 0 do
      nm=@nm.shift
      tm=@tm.shift
      if tm <= @qtm then
        t += tm
        nm_e.push(nm) 
        tm_e.push(t) 
      else
        t += @qtm
        @nm.push(nm) 
        @tm.push(tm - @qtm)
      end
    end
    0.upto(nm_e.length-1).each{|i|
      printf("%s %d\n", nm_e[i] , tm_e[i])
    }
  end

end

class Main
  def initialize()
    #fh = open("x.txt")
    fh = STDIN
    name=[]
    time=[]
    n,q = fh.gets.chomp.split.map{|x| x.to_i}
    0.upto(n-1){|i| name[i],time[i] = fh.gets.chomp.split}

    rr = Rr.new(n, q, name, time)
    rr.exe()
  end
end

if $0==__FILE__ then
  Main.new()
end

Measured memory_bytes: 16116
# DP(配るDP)
INF = float('inf')

N = int(input())

c = [1]
t = 6
while t <= N:
    c.append(t)
    t *= 6
t = 9
while t <= N:
    c.append(t)
    t *= 9

dp = [INF] * (N + 1)
dp[0] = 0
for i in range(N):
    t0 = dp[i] + 1
    for j in c:
        t1 = i + j
        if t1 <= N and dp[t1] > t0:
            dp[t1] = t0
        if t1 == N:
            break
print(dp[N])


Measured memory_bytes: 3828
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
typedef pair<int, int> P;
int main(void){
    int n, m;
    long long ans = 0;
    set<int> day;
    P p[100000];
    cin >> n >> m;
    for(int i=0;i<n;i++){
        int a, b;
        cin >> a >> b;
        p[i] = P(b, a);
    }
    sort(p, p+n, greater<P>());
    for(int i=1;i<=m;i++){
        day.insert(i);
    }
    for(int i=0;i<n;i++){
        int a = p[i].second, b = p[i].first;
        auto itr = day.lower_bound(a);
        if(itr != day.end()){
            ans += b;
            day.erase(itr);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
#define ll long long int
#define REP(i,a,b)  for(i=a;i<=b;i++)
#define REPr(i,a,b) for(i=b;i>=a;i--)
#define pi 3.14159265358979323846
#define pb push_back
#define umap(x,y) unordered_map<x,y>
#define f first
#define s second
using namespace std;

//intialization for a tree
vector<int> adj[100005];
bool visited[100005]={false};

void solve(){
    int n;  cin>>n; 
    cout<<n+(n*n)+(n*n*n)<<endl;;
}

int main(){
    int t;
    t=1;

    while(t--){
        solve();
    }
}

Measured memory_bytes: 5944
#include <bits/stdc++.h>
using namespace std ;
#define gc getchar
#define ll long long
#define inf 1000009
typedef long long LL;
 LL gcd(LL a, LL b) { return (b == 0 ? a : gcd(b, a % b)); }
 LL Lcm(LL a, LL b) { return (a * (b / gcd(a, b))); }
LL isPrime(LL x)  { ll s = sqrt(x); for (ll i = 2; i <= s; i++) if (x % i == 0) return 0; return 1;} 
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ll n,k;cin>>n>>k;

		if(n<k)
		{
			if(abs(n-k)< abs(abs(n-k)-abs(k)))
			cout<<abs(n-k)<<endl;
			else cout<<abs(abs(n-k)-abs(k))<<endl;
		}
		else
		{
			if(n%k==0)
			cout<<"0\n";
			else
			{
		     n=n%k;
			if(abs(n-k)< abs(abs(n-k)-abs(k)))
			cout<<abs(n-k)<<endl;
			else cout<<abs(abs(n-k)-abs(k))<<endl;
			}
			
			
		}
	}
	

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

n=int(input())
l=[]
for _ in range(1,n+1):
    s,p=input().split()
    p=int(p)*-1
    t=(s,p,_)
    l.append(t)
l=sorted(tuple(l))
for i in range(n):
    print(l[i][2])


Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	s := sc.NextLine()

	ah := 0
	bh := 0
	for i:=0; i<N; i++ {
		if s[i] == 'R' {
			ah ++
		} else if s[i] == 'B' {
			bh++
		}
	}

	if ah > bh {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

// ===============================================

// *** int
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

// *** int64
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

// **** float
func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

// *** []int 一行読み取って
func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}

// *** string 一行読み読み取って
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}

// ======================================================
type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}

func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}

func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include <stdio.h>

void selectionSort(int *,int);

int main(){
  int N,A[100],i;

  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }

  selectionSort(A,N);

  return 0;

}
void selectionSort(int *a,int n)
{
  int i,j,k,num=0,minj=0,count=0;
  for(i=0;i<n;i++){
    minj = i;
    for(j=i;j<n;j++){
      if(a[j]<a[minj]){
	minj=j;
      }
    }
    if(minj!=i){
	num=a[i];
	a[i]=a[minj];
	a[minj]=num;
       count++;
      }
  }
  for(k=0;k<n;k++){
      printf("%d",a[k]);
      if(k!=n-1)printf(" ");
      }
    printf("\n");
    printf("%d\n",count);
}

Measured memory_bytes: 604
n = int(input())
a = list(map(int, input().split()))

count_list = {}
s = 0
for i in range(n):
  s += a[i]
  count_list[s] = count_list.get(s, 0) + 1

count = 0
count += count_list.get(0, 0) * (count_list.get(0, 0)+1)
for i in count_list.keys():
  if i!=0:
    #count+= count_list[i] * count_list.get(-i, 0)
    count += count_list[i] * (count_list[i]-1)
print(count//2)

Measured memory_bytes: 111312
#include<stdio.h>
int main(void){
  int n;
  scanf("%d",&n);
  if(n==1||n%2!=0){printf("No");
                       return 0;
                      }
  char s[n];
  scanf("%s",&s);
  for(int i=0;i<n/2;i++){
    if(s[i]!=s[n/2+i]){printf("No");
                       return 0;
                      }
  }
printf("Yes");
  return 0;
}

Measured memory_bytes: 128
N, M = [int(i) for i in input().split()]

store = []
for _ in range(N):
    A, B = [int(i) for i in input().split()]
    store.append((A, B))

store = sorted(store, key=lambda s: s[0])
number, price = 0, 0

for a, b in store:
    if M - (number + b) > 0:
        number += b
        price += a * b
    else:
        price += (M - number) * a
        break

print(price)


Measured memory_bytes: 18900
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <tuple>
#include <utility>
#include <functional>
#include <set>
#include <map>
#include <bitset>
#include <list>

using namespace std;


#define INF pow(10, 9)
// typedef priority_queue<tuple<int,int,int>, vector< tuple<int, int, int> >, greater< tuple<int, int, int> > > PQ;

typedef long long int ll;




int main(void)
{

    ll N, X, M;
    cin >> N >> X >> M;

    const int Max = pow(10, 5);
    int count[Max] = {0};
    vector<int> As(Max+3, 0); //As[0]は使わない

    ll A_new = X;
    int index = 1;

    while(count[A_new]==0 )
    {
        count[A_new] ++;
        As[index++] = A_new;
        A_new = A_new * A_new %M;
        if(A_new <0) A_new += M;
        // cout << index-1 << " " << As[index-1] << endl;
    }

    int A_looped = A_new;



    if(N < index)
    {
        ll Sum = 0;
        for(int i=1; i<=N; i++)
        {
            Sum += As[i];
        }
        cout << Sum << endl;
    }
    else
    {
        ll Sum_bef =0;
        ll Sum_loop = 0;
        int index_loop_start=0;
        for(int i=1; i<=index; i++)
        {
            if(As[i] == A_looped)
            {
                index_loop_start = i;
                break;
            }
            else
            {
                Sum_bef += As[i];
            }
        }

        int N_loop_index = index-index_loop_start;
        for(int i=0; i<N_loop_index; i++)
        {
            Sum_loop += As[index_loop_start+i];
        }

        ll times_loop = (N-index_loop_start+1)/N_loop_index;
        ll residual = (N-index_loop_start+1)- times_loop * N_loop_index;

        // cout << index << "! " << index_loop_start << ", " << N_loop_index << "// " << times_loop << "::: " << residual << endl;
        // cout << Sum_bef << " b " << Sum_loop << endl;

        for(int i=0; i<residual; i++)
        {
            Sum_bef += As[index_loop_start+i];
        }
        ll Sum = Sum_bef+Sum_loop * times_loop;
        cout << Sum << endl;
    }




    return 0;
}


Measured memory_bytes: 4040
import sys; input = sys.stdin.buffer.readline
from collections import defaultdict
import bisect
con = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	A = getlist()
	B = getlist()
	ans = 0
	for i in range(29):
		mul = 2 ** (i + 1)
		mul2 = 2 ** i
		Aex = [A[j] % mul for j in range(N)]
		Bex = [B[j] % mul for j in range(N)]
		Aex.sort()
		Bex.sort()
		cnt = 0
		p, q, r = N - 1, N - 1, N - 1
		for j in range(N):
			var = Aex[j]
			while p >= 0 and mul2 - var <= Bex[p]:
				p -= 1
			while q >= 0 and mul - var <= Bex[q]:
				q -= 1
			while r != 0 and mul + mul2 - var <= Bex[r]:
				r -= 1
			cnt += q - p
			cnt += N - 1 - r
			
			# if var <= 2 ** i:
			# 	cnt += bisect.bisect_left(Bex, mul - var) - (bisect.bisect_left(Bex, mul2 - var))
			# else:
			# 	cnt += bisect.bisect_left(Bex, mul - var)
			# 	cnt += N - bisect.bisect_left(Bex, mul + mul2 - var)
		# print(Aex)
		# print(Bex)
		# print(cnt)
		if cnt % 2 != 0:
			ans += 2 ** i

	print(ans)

if __name__ == '__main__':
	main()

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

using namespace std;

int main(){
	int n;
	cin>>n;
	int x=0,y=0;
	int t=0;
	int a,b,c;
	for(int i=1;i<=n;i++)
	{
		cin>>c>>a>>b;
		if(abs(x-a)+abs(y-b)>c-t)
		{
			cout<<"No";
			return 0;
		}
		if((abs(x-a)+abs(y-b))%2==0 &&(c-t)%2==1)
		{
			cout<<"No";
			return 0;
		}
		if((abs(x-a)+abs(y-b))%2==1 &&(c-t)%2==0)
		{
			cout<<"No";
			return 0;
		}
		x=a;y=b;t=c;
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
import math

k = int(input())

ans = 0

IJ = [[0 for j in range(k+1)] for i in range(k+1)]

for i in range(1, k+1):
    for j in range(1, k+1):
        IJ[i][j] = math.gcd(i, j)

for i in range(1, k+1):
    for j in range(1, k+1):
        for h in range(1, k+1):
            ans += math.gcd(IJ[i][j], h)


print(ans)


Measured memory_bytes: 68596
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;

int main()
{
    while (true) {
        int h, w;
        cin >> h >> w;

        if (!h && !w) {
            break;
        }

        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                putchar((i + j) & 1 ? '.' : '#');
            }
            putchar('\n');
        }
        putchar('\n');
    }
}



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

#include<atcoder/all>
using namespace atcoder;

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;

int main(){
    int n, m;
    cin >> n >> m;
    dsu d(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        d.merge(a, b);
    }
    int cnt = 0;
    rep(i, n) if(d.leader(i) == i) cnt++;
    cout << cnt-1 << endl;
    return 0; 
}
 

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

int main()
{
    string s;
    cin >>s;

    int a=0, b=0, c=0, d=0;
    rep(i,s.size())
    {
        if(s[i]=='N') ++a;
        else if(s[i]=='S') ++b;
        else if(s[i]=='E') ++c;
        else if(s[i]=='W') ++d;
    }

    string ans="Yes";
    if( (a>0&&b==0) || (a==0&&b>0) || (c>0&&d==0) || (c==0&&d>0) ) ans="No";
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

int n, ans = 0, v[22];

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> v[i];

	for (int i = 0; i < n; ++i) {
		int c;
		cin >> c;

		if (v[i]-c > 0)
			ans += v[i]-c;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256