akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define erep(e, v) for (auto &&e : v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int) 1e9 : (int) 1e18)
#define EPS 0.0000000001
using namespace std;
template <class T, class S> void cmin(T &a, const S &b) {
    if (a > b) a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
    if (a < b) a = b;
}
template <typename Head, typename Value>
auto vectors(const Head &head, const Value &v) {
    return vector<Value>(head, v);
}
template <typename Head, typename... Tail> auto vectors(Head x, Tail... tail) {
    auto inner = vectors(tail...);
    return vector<decltype(inner)>(x, inner);
}
template <class T, class S> void join(T &a, S terminator) {
    for (auto itr = begin(a); itr != end(a); itr++) {
        if (itr != begin(a)) cout << terminator;
        cout << *itr;
    }
    cout << endl;
}
int W, H;
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
bool valid(int x, int y) { return (0 <= x && x < W) && (0 <= y && y < H); }
auto out(int a, int b) {
    (a > b ? a += 1 : b += 1);
    cout << a << " " << b << endl;
}
main() {
    int n, m;
    while (cin >> n >> m, n + m) {
        vector<int> v(n);
        erep(e, v) cin >> e;
        sort(all(v));
        int maxi = -10;
        rep(i, n) {
            rep(j, n) {
                if (i == j or v[i] + v[j] > m) continue;
                maxi = max(v[i] + v[j], maxi);
            }
        }
        cout << (maxi > 0 ? to_string(maxi) : "NONE") << endl;
    }
}


Measured memory_bytes: 3292
#import sys
#import numpy as np
import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
n,k=map(int,input().split())
a=list(map(int,input().split()))
x=k.bit_length()
res=0
for i in range(x):
  c1=0
  c0=0
  for j in range(n):
    if (a[j]>>i & 1)==1:
      c1+=1
    else:
      c0+=1
  if c0>c1:
    res+=2**i
ans=0
if res>k:
  for i in range(x):
    k_res=(k>>(x-i-1))&1
    r=res>>(x-i-1)&1
    if k_res==0 and r==1:
      res-=2**(x-i-1)
    if res<=k:
      break
      
for i in range(n):
  ans+=res^a[i]
print(ans)

Measured memory_bytes: 91872
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(x) (x).begin (),(x).end()
#define pb push_back
#define mp make_pair
#define vi vector<ll>
#define pii pair<ll,ll>
#define vii vector<pii>
#define mi map<ll,ll>
#define endl "\n"
#define si set<ll>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define M 1000000007LL


void solve()
{
    ll a,b,c; cin>>a>>b>>c;
    cout<<c<<" "<<a<<" "<<b;
}

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

   // cin>>t;

    while(t--) solve();

   return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
x=[0]*(n+1)
for i in a :
    x[i]+=1


ans=0
for i in x :
    n=i
    ans+=n*(n-1)//2

for i in a :
    n=x[i]
    ans1=ans-(n-1)
    print(ans1)


Measured memory_bytes: 32204
#山の数
n = int(input())
#各山の高さ
h = list(map(int, input().split()))
cou = 1
for i in range(1, n):
    if not max(h[:i+1]) == h[i]:
        continue

    if not h[i-1] <= h[i]:
        continue

    cou+=1

print (cou)


Measured memory_bytes: 2940
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }

int main() {
    long long int K;
    scanf("%lld",&K);
    long long int A[400000];
    for(long long int i = 0; i <= 9; ++i){
        A[i] = i;
    }
    long long int s = 10;


    for(long long int i = 1;i <= K; ++i){
        if(A[i] % 10 != 0) {
            A[s] = A[i] * 10 + (A[i] % 10) - 1;
            s++;
        }
        A[s] = A[i] * 10 + (A[i]%10);
        s++;
        if(A[i] % 10 != 9){
            A[s] = A[i] * 10 + (A[i]%10) + 1;
            s++;
        }
    }
    printf("%lld",A[K]);
    return 0;
}

int A(){
    int A,B,C;
    scanf("%d %d %d",&A,&B,&C);
    printf("%d %d %d",C,A,B);
    return 0;
}

int B(){
    int M, N;
    scanf("%d %d", &N, &M);
    int A[N];
    int SUM = 0;
    for (int i = 0; i < N; ++i) {
        scanf("%d", &A[i]);
        SUM += A[i];
    }
    qsort(A, sizeof(A) / sizeof(A[0]), sizeof(int), downint);

    if (A[M-1] >= 1.0*SUM / (4 * M)) {
        printf("Yes");
        return 0;
    } else {
        printf("No");
        return 0;
    }
}

int C(){
    long long int N,K;
    scanf("%lld %lld",&N,&K);
    if(N%K >= K-N%K){
        printf("%lld",K-N%K);
    }
    else{
        printf("%lld",N%K);
    }
    return 0;
}

Measured memory_bytes: 3072
<?php
	while (!feof(STDIN))
	{
		$stdin[] = fgets(STDIN);
	}
	$count = $stdin[0];
	$nums  = explode(' ', $stdin[1]);
	$count_operations = 0;

	$answer = shift_only($count, $nums);
	echo $answer;

	function is_even($count, $nums)
	{
		for ($i=0; $i<$count; $i++)
		{
			if($nums[$i] % 2 > 0)
			{
				return FALSE;
			}
		}
		return TRUE;
	}

	function do_one_half($count, $nums)
	{
		for ($i=0; $i<$count; $i++)
		{
			$nums[$i] = $nums[$i] / 2;
		}
		return $nums;
	}

	function shift_only($count, $nums)
	{
		global $count_operations;
		if (is_even($count, $nums))
		{
			$count_operations++;
			$nums = do_one_half($count, $nums);
			return shift_only($count, $nums);
		}
		else
		{
			return $count_operations;
		}
	}

Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define ull unsigned long long
#define INF 987654321

int main() {
    ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int l, r, d, cnt = 0;
    cin >> l >> r >> d;
    for (int i = l; i <= r; i++) {
        if (i % d == 0) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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

using namespace std;

const int N = 105;
int x, n, a[N];

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> x >> n;
    for(int i = 1; i <= n; ++i) {
        int v; cin >> v; a[v] = 1;
    }
    vector<pair<int, int>> v;
    for(int i = 0; i <= 101; ++i) {
        if(!a[i]) v.emplace_back(abs(x - i), i);
    }
    sort(begin(v), end(v));
    cout << v[0].second << '\n';
}


Measured memory_bytes: 3660
import math

a, b, x = map(int, input().split())

s = x / a
if x >= a*a*b / 2:
    num = 2 * (a*b - s) / a**2
    theta = math.degrees(math.atan(num))
else:
    num = 2 * s / b**2
    theta = 90 - math.degrees(math.atan(num))

print(theta)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
    int i,a,sum=0;cin>>a;
    int b[a];
    for(i=0;i<a;i++)cin>>b[i];
    sort(b,b+a);
    for(i=0;i<a;i++)sum+=(i!=a-1?b[i]:b[i]/2);
    cout<<sum<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main () {
  long long k;
  string s;
  cin >> s >> k;
  for(int i=0; i<k; i++) {
    if(s[i]>='2') {
      cout << s[i] << endl;
      return 0;
    }
  }
  cout << 1 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;
const long nPrime = 1000000007;
long Factorial(const long &n){
    long nReturn = 1;
    for(long i = 2; i <= n; i++){
        nReturn *= i;
        nReturn %= nPrime;
    }
    return nReturn;
}

long Inverse(const long &n){
    if (n % nPrime == 0){
        return 0;
    }
    long a = n, b = nPrime, u = 1, v = 0;
    while (b > 0) {
        long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= nPrime;
    if (u < 0){
        u += nPrime;
    }
    return u;    
}
int main(){
    long n;
    scanf("%ld", &n);
    
    if(n < 3){
        printf("0");
        return 0;
    }
    long nAns = 0;
    for(long i = 1; 3*i <= n; i++){
        long iDivideInv = Inverse(Factorial(n - 3*i)) * Inverse(Factorial(i - 1));
        iDivideInv %= nPrime;
        long k = Factorial(n - 2*i - 1);
        k *= iDivideInv;
        k %= nPrime;
        nAns += k;
        nAns %= nPrime;
    }
    printf("%ld", nAns);
    return 0;
}


Measured memory_bytes: 3244
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        long n = long.Parse(Console.ReadLine());

        List<long> arr = new List<long>();

        while (n > 0)
        {
            arr.Add(n);
            if (n % 2 == 0)
            {
                n /= 2;
            }
            else
            {
                n = (n - 1) / 2;
            }
        }

        long sum = 0;
        long x = 1;
        foreach (var a in arr)
        {
            sum += x;
            x *= 2;
        }

        Console.WriteLine(sum);
    }
}

Measured memory_bytes: 13268
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
#include <vector>
//#include <string>
//#include <list>
//#include <deque>
//#include <unordered_map>
//typedef long long LL;
//typedef long double LD;
using namespace std;

//#define MOD 1000000007
#define MAX 100100
//#define NIL -1

vector<int> parent(MAX);
vector<int> length(MAX);

void init(int n){
    for(int i=0; i<n; i++){
        parent[i]=i;
        length[i]=1;
    }
}

int find(int x){
    while(parent[x]!=x){
        x=parent[x];
    }
    return x;
}

bool same(int x, int y){
    return find(x)==find(y);
}

bool unite(int x, int y){
    x=find(x);
    y=find(y);
    if(x==y){
        return false;
    }
    if(length[x]<length[y]){
        swap(x,y);
    }
    parent[y]=x;
    length[x]+=length[y];
    return true;
}

int main() {
    int n;
    int m;
    int k;
    cin >> n >> m >> k;
    vector<int> F(n+1,0);
    vector<int> B(n+1,0);
    init(n);

    for(int i=0; i<m; i++){
        int a;
        int b;
        cin >> a >> b;
        unite(a, b);
        F[a]++;
        F[b]++;
    }

    for(int i=0; i<k; i++){
        int c;
        int d;
        cin >> c >> d;
        if(same(c, d)){
            B[c]++;
            B[d]++;
        }
    }

    for(int i=1; i<=n; i++){
        cout << length[find(i)] - F[i] - B[i] - 1 << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 2432
function main(input) {
    var nums = input.split('\n')[1].split(' ').map((n) => parseInt(n, 10));

    var count = 0;
    while(nums.every((n) => (n % 2) === 0)) {
        count++;
        nums = nums.map((n) => n / 2);
    }

    console.log(count);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21192
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>

using namespace std;
int main() {
	int H,W;
	cin>>H>>W;
	int *raw_data=new int[H*W];
	int table[H][W];
	int n;
	cin>>n;
	int counter=0;
	for(int i=0;i<n;i++){
		int temp;
		cin>>temp;
		for(int loop=0;loop<temp;loop++){
			raw_data[counter]=i+1;
			++counter;
		}
	}
	bool forward=true;
	int x=0;
	int y=0;
	for(int loop=0;loop<H*W;loop++){
		table[x][y]=raw_data[loop];
		if(forward){
			if(y==W-1){
				++x;
				forward=false;
			}else{
				++y;
			}
		}else{
			if(y==0){
				++x;
				forward=true;
			}else{
				--y;
			}
		}
	}
	for(int x=0;x<H;x++){
		for(int y=0;y<W;y++){
			cout<<(table[x][y])<<" ";
		}
		cout<<endl;
	}

	delete[] raw_data;




	return 0;

}


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

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

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

#define x1 gray_cat_x1
#define y1 gray_cat_y1

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

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

#define file "I1"

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

const int MAXN = 2e5 + 5;

ll pow_mod(ll v, ll st) {
	ll ans = 1ll;
	for(; st; st >>= 1) {
		if (st & 1) {
			ans = (ans * v) % MOD;
		}
		v = (v * v) % MOD;
	}
	return ans;
}

ll get_inv(ll v) {
	return pow_mod(v, MOD - 2);
}

void solve(){
	ll h, w, k;
	cin >> h >> w >> k;
	ll n = h + w;
	ll ans = ((k * k) % MOD * k - k) % MOD;
	ans = (ans * get_inv(3)) % MOD;
	ans = (ans * get_inv(n)) % MOD;
	ans = (ans * get_inv(n - 1)) % MOD;
	ans = (ans * h) % MOD;
	ans = (ans * w) % MOD;
	ans = (ans + k * (k + 3) / 2) % MOD;
	REPN(i, n - k + 1, n) {
		ans = (ans * i) % MOD;
	}
	cout << ans << endl;
}   

int main(){

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


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

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

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

        if x == y:
            return

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

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

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())



def main():
    from sys import stdin
    from collections import deque
    input = lambda: stdin.readline()
    N,M = map(int,input().split())
    uf = UnionFind(N+1)
    AB = deque()
    for i in range(M):
        AB.append(map(int,input().split()))
    diff_pairs = [0]*M
    AB.reverse()
    prev = 0
    for i,(a,b) in enumerate(AB):
        if not uf.same(a,b):
            num_a = uf.size(a)
            num_b = uf.size(b)
            prev += num_a * num_b
            uf.union(a,b)
        diff_pairs[M-i-1] = prev
    outputs = deque()
    sum_d = 0
    prev = diff_pairs[0]
    for i in range(1,M):
        sum_d += prev-diff_pairs[i]
        outputs.append(sum_d)
        prev = diff_pairs[i]
    outputs.append(sum_d+1)
    print('\n'.join(map(str,outputs)))



main()

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

int main(){

  int h,w;
  string s[110];
  int map[110][110]={};
  cin >> h >> w;

  for(int i = 0 ; i < h;i++){
    for(int j = 0; j < w;j++){
      map[i][j] = -1;
    }
  }

  for(int i = 0; i < h ; i++){
    cin >> s[i];
  }
  for(int i = 0 ; i < h;i++){
    for(int j = 0; j < w;j++){
      if(s[i][j] == 'c') map[i][j] = 0;
    }
  }

  

  for(int i = 0 ; i < h;i++){
    for(int j = 0; j < w;j++){
      if(map[i][j] != -1){
	if(map[i][j+1] != 0) map[i][j+1] = map[i][j]+1;
      }
    }
  }

  for(int i = 0 ; i < h;i++){
    for(int j = 0; j < w;j++){
      if(j != w-1)
	cout << map[i][j] << " ";
      else 
	cout << map[i][j];
    }
    cout << endl;
  }
  



  return 0;
}

Measured memory_bytes: 1284
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
const int inf = 1e9;
int dx[4] ={1, 0, -1, 0};
int dy[4] ={0, 1, 0, -1};

void color(int x, int y, int c, vector<vector<int> > &map){
    if(map[x][y]==c) return;
    map[x][y] = c;
    for(int i=0; i<4; i++){
        color(x+dx[i], y+dy[i], c, map);
    }
}

int main(){
    while(1){
        int n;
        cin >> n;
        if(n==0) break;

        vector<int> x(n), y(n);
        vector<int> ax(n+2), ay(n+2);
        for(int i=0; i<n; i++){
            cin >> x[i] >> y[i];
            ax[i] = x[i];
            ay[i] = y[i];
        }
        int xmax=-inf, xmin=inf;
        int ymax=-inf, ymin=inf;
        for(int i=0; i<4; i++){
            int x,y;
            cin >> x >> y;
            xmax = max(xmax, x);
            xmin = min(xmin, x);
            ymax = max(ymax, y);
            ymin = min(ymin, y);
        }
        ax[n] = xmax;
        ax[n+1] = xmin;
        ay[n] = ymax;
        ay[n+1] = ymin;

        sort(ax.begin(), ax.end());
        sort(ay.begin(), ay.end());
        ax.erase(unique(ax.begin(), ax.end()), ax.end());
        ay.erase(unique(ay.begin(), ay.end()), ay.end());
        int sx = ax.size();
        int sy = ay.size();
        map<int, int> xtoi, ytoi;
        for(int i=0; i<sx; i++) xtoi[ax[i]] = i*2;
        for(int i=0; i<sy; i++) ytoi[ay[i]] = i*2;

        vector<vector<int> > map(sx*2-1, vector<int>(sy*2-1, 0));
        for(int i=0; i<n; i++){
            if(x[i]==x[(i+1)%n]){
                int s = ytoi[y[i]];
                int e = ytoi[y[(i+1)%n]];
                if(s>e) swap(s,e);
                for(int j=s; j<e; j++){
                    map[xtoi[x[i]]][j] = 1;
                }
            }else{
                int s = xtoi[x[i]];
                int e = xtoi[x[(i+1)%n]];
                if(s>e) swap(s,e);
                for(int j=s; j<e; j++){
                    map[j][ytoi[y[i]]] = 1;
                }
            }
        }
        if(x[0]==x[1]){
            int fx = (y[1]>y[0])? xtoi[x[0]]-1: xtoi[x[0]]+1;
            int fy = (ytoi[y[0]]+ytoi[y[1]])/2;
            color(fx, fy, 1, map);
        }else{
            int fx = (xtoi[x[0]]+xtoi[x[1]])/2;
            int fy = (x[1]>x[0])? ytoi[y[0]]+1: ytoi[y[0]]-1;
            color(fx, fy, 1, map);
        }

        for(int i=xtoi[xmin]; i<xtoi[xmax]; i++){
            for(int j=ytoi[ymin]; j<ytoi[ymax]; j++){
                map[i][j] = 0;
            }
        }

        int ans=0;
        for(int i=0; i<sx-1; i++){
            for(int j=0; j<sy-1; j++){
                if(map[i*2+1][j*2+1]==1){
                    ans += (ax[i+1]-ax[i])*(ay[j+1]-ay[j]);
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

using namespace std;

int main() {
	int N, Y;
	cin >> N >> Y;

	for (int a = 0; a <= N; ++a) {
		for (int b = 0; b <= N; ++b) {
			int c = N - a - b;
			if (c < 0) continue;

			if (10000*a + 5000*b + 1000*c == Y) {
				cout << a << ' ' << b << ' ' << c;
				return 0;
			}
		}
	}

	cout << -1 << ' ' << -1 << ' ' << -1;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<climits>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n,m; cin >> n >> m;
  vector<int> P(m),Y(m);
  for(int i=0;i<m;i++){
    cin >> P[i] >> Y[i];
    P[i]--;
  }
  vector<vector<int>> vals(n);
  for(int i=0;i<m;i++) vals[P[i]].push_back(Y[i]);
  for(int i=0;i<n;i++){
    sort(vals[i].begin(),vals[i].end());
    vals[i].erase(unique(vals[i].begin(),vals[i].end()),vals[i].end());
  }

  for(int i=0;i<m;i++){
    int v = P[i];
    printf("%06d", v+1);
    int id = lower_bound(vals[v].begin(),vals[v].end(),Y[i]) - vals[v].begin();
    printf("%06d", id+1);
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 7808
n = int(input())
A = list(map(int, input().split()))

A.sort()
alice = 0
bob = 0
for i in range(n-1, -1, -2):
    if i >= 0:
        alice += A[i]
    if i >= 1:
        bob += A[i-1]

print(alice-bob)


Measured memory_bytes: 3060
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii, std.numeric, std.random;
import std.typecons, std.functional, std.traits,std.concurrency;
import std.algorithm, std.container;
import core.bitop, core.time, core.memory;
import std.bitmanip;
import std.regex;

enum INF = long.max/3;
enum MOD = 10L^^9+7;

//辞書順順列はiota(1,N),nextPermituionを使う


void end(T)(T v)
if(isIntegral!T||isSomeString!T||isSomeChar!T)
{
    import core.stdc.stdlib;
    writeln(v);
    exit(0);
}

T[] scanArray(T = long)()
{
    static char[] scanBuf;
    readln(scanBuf);
    return scanBuf.split.to!(T[]);
}

dchar scanChar()
{
    int c = ' ';
    while (isWhite(c) && c != -1)
    {
        c = getchar;
    }
    return cast(dchar)c;
}

T scanElem(T = long)()
{
    import core.stdc.stdlib;
    static auto scanBuf = appender!(char[])([]);

    scanBuf.clear;

    int c = ' ';
    while (isWhite(c) && c != -1)
    {
        c = getchar;
    }
    while (!isWhite(c) && c != -1)
    {
        scanBuf ~= cast(char) c;
        c = getchar;
    }
    return scanBuf.data.to!T;
}

dchar[] scanString(){
    return scanElem!(dchar[]);
}


void main()
{
  auto a=scanElem,b=scanElem,c=scanElem;
  if(a<=c&&b>=c)end("Yes");end("No");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;
int main(){
  string s; cin >> s;
  int n = s.size();
  int ans = INF;

  for(int c='a';c<='z';c++){
    bool ok = true;
    string str = s;
    rep(i,str.size()){
      if(str.at(i)!=c) ok = false;
    }

    if(ok){
      puts("0");
      return 0;
    }

    int num = str.size();

    while(true){
      ok = true;
      rep(i,num-1){
        if(str.at(i)==c || str.at(i+1)==c){
          str.at(i) = c;
        }else{
          ok = false;
        }
      }

      num--;

      if(ok){
        ans = min(ans,n - num);
        break;
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <complex>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;

int main(void)

{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << ketasitei;

	double r;
	cin >> r;
	cout << 2.0 * r * 3.1415926535 << endl;

	return 0;
}

Measured memory_bytes: 3804
/* ****revpro**** */
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl     '\n'
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)    
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define mii      map<ll,ll>
using namespace std;

#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define N  100005
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;  
#define ordered_set tree<double, null_type,less<double>, rb_tree_tag,tree_order_statistics_node_update> 
void solve()
{
 ll n,k;
 cin>>n>>k;
 if(n<=k)
 {
  cout<<min(n,k-n);
 } 
 else{
  n=n%k;
  cout<<min(n,k-n);
 }
}
signed main()
{
  
    /***********************************/
    unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
    mt19937_64 generator (seed);

  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS=1;
//  cin>>TESTS;
  while(TESTS--)
  {
    solve();
    
  }
  TIME
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {

	var S,s string
	var countA, countB int

	//
	fmt.Scan(&S)

	for i := 0; i < len(S); i++{
		// 000 -> 010
		// 001 -> 101
		// 010 -> 010
		// 011 -> 010
		// 100 -> 101
		// 101 -> 101
		// 110 -> 010
		// 111 -> 101
		s = S[i : i + 1]

		if i % 2 == 0{
			if s == "0" {
				countA++
			}else{
				countB++
			}
		}else{
			if s == "0" {
				countB++
			}else{
				countA++
			}
		}
	}

	if countA < countB {
		fmt.Println(countA)

	}else{
		fmt.Println(countB)

	}
}


Measured memory_bytes: 1280
#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <set>

#define rep(i,n)  for (int i = 0; i < (int)(n); i++)
#define INF 9999999999
#define PI 3.14159265359
using namespace std;

int main()
{
	int i=0,n;
	rep(i,5) {
		cin >> n;
		if (n==0){
		  	cout << i+1 << endl;
			return 0;
        }
	} 
}

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

int main(){
    int N,cnt=0;
    cin >> N;
    int a[N];
    for(int i=0;i<N;i++) cin >> a[i];
    for(int i=0;i<N;i++){
        int c=1;
        for(int j=2;j<=sqrt(a[i]);j++){
            if(a[i]%j==0) c=0;
        }
        if(c==1) cnt++;
    }
    cout << cnt << endl;
}



Measured memory_bytes: 3128
#include "bits/stdc++.h"

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#pragma GCC optimize ("-O3")

using namespace std;

// #define DEBUG_IS_VALID

#ifdef DEBUG_IS_VALID
#define DEB 1 
#else
#define DEB 0
#endif
#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

const int mod=1e9+7,INF=1<<29;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<59; 

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,M; cin >> N >> M ;
  vi a(N,1);
  vector<bool> pos(N,false);
  pos[0] = true;
  rep(mm,M){
    int x,y; cin >> x >> y ;
    x--; y--;
    pos[y] = pos[y] || pos[x];
    a[x]--; a[y]++;
    if(a[x]==0) pos[x] = false;
  }
  int ans = 0;
  rep(i,N) if(pos[i]) ans++;
  cout << ans << endl;
  return 0;
}


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

int main() {
  ll N;
  cin >> N;

  for (ll h = 1; h <= 3500; h++) {
    for (ll n = 1; n <= 3500; n++){
      if ((4*h*n-N*n-N*h) == 0) continue;
      if ((N*h*n) % (4*h*n-N*n-N*h) == 0){
        if ((N*h*n) / (4*h*n-N*n-N*h) >= 1){
          cout << h << " " << n << " " << (N*h*n) / (4*h*n-N*n-N*h) << endl;
          return 0;
        }
      }
    }
  }

  return 0;

}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<ll,ll>;

int main() {
  int h,w,m;
  cin >> h >> w >> m;
  vector<ll> hc(h),wc(w);
  vector<P> v;
  map<P,int> ma;
  ll hmax=0,wmax=0;
  rep(i,m){
      int x,y;
      cin >> x >> y;
      x--; y--;
      ma[make_pair(x,y)]=1;
      hc[x]++;wc[y]++;
      hmax=max(hmax,hc[x]);
      wmax=max(wmax,wc[y]);
  }
  vector<int> vh,vw;
  rep(i,h){
      if(hc[i]==hmax) vh.push_back(i);
  }
  rep(i,w){
      if(wc[i]==wmax) vw.push_back(i);
  }
  ll max=vh.size()*vw.size();
  if(max>m){
      cout << hmax+wmax << endl;
  }
  else{
      ll cnt=0;
      for(int x:vh)for(int y:vw){
          if(ma[make_pair(x,y)]==1) cnt++;
      }
      if(cnt==max) cout << hmax+wmax-1 << endl;
      else cout << hmax+wmax << endl;
  }
}


Measured memory_bytes: 30804
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true){
            String s = sc.next();
            if(s.equals("-")) break;
            int m = sc.nextInt();
            for(int i = 0; i < m; i ++){
                int h = sc.nextInt();
                s = s.substring(h) + s.substring(0, h);
            }
            System.out.println(s);
        }

    }
}



Measured memory_bytes: 26508
#include<iostream>
#include<string>
using namespace std;
int main() {
  string s, snew;
  cin >> s;
  for (int i = 0; i < s.size(); i = i + 2){
    snew += s[i];
  }
  //snew += '\0';
  cout << snew << endl;
  return 0;
}

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

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
//const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

signed main() {
  string s;
  cin >> s;
  int n = s.size();
  rep (i, 8) {
    string t = s.substr(0, i) + s.substr(n - (7 - i), 7 - i);
    if (t == "keyence") {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int ct_a=0,ct_b=0,ct_c=0;
	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='a')
			ct_a++;
		else if(s[i]=='b')
			ct_b++;
		else if(s[i]=='c')
			ct_c++;
	}
	if(ct_a==1 && ct_b==1 && ct_c==1)
		cout<<"Yes\n";
	else
		cout<<"No\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
    ll n,i,j,k,c=1,x=1,t;
   cin>>n;
   string s;
   while(n!=0)
   {
             t=n%26;
             n--;
             //cout<<t<<endl;
             if(t==0)
                    s+='z';
             else
             {
                       s+=char(96+t);
             }
             n/=26;
   }
   reverse(s.begin(),s.end());
   cout<<s;
}


Measured memory_bytes: 3572
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class Main {
    public static void main(String args[]) throws ParseException {
        final String input = new Scanner(System.in).nextLine();
        final SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
        final Date inputDate = sdf.parse(input);
        final Date borderDate = sdf.parse("2019/04/30");;
        if (inputDate.compareTo(borderDate) == 0) {
            System.out.println("Heisei");
        } else if (inputDate.compareTo(borderDate) == -1) {
            System.out.println("Heisei");
        } else {
            System.out.println("TBD");
        }
    }
}

Measured memory_bytes: 22868
package main

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

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func main() {
	sc := NewScanner()
	S := sc.nextRuneSlice()
	allOdd := true
	allEven := true
	for i, r := range S {
		if (i+1)%2 == 0 {
			if r == 'R' {
				allEven = false
			}
		} else {
			if r == 'L' {
				allOdd = false
			}
		}
	}
	if allOdd && allEven {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 640
N,Y = map(int, input().split())

for x in range(N+1):
  for y in range(N+1-x):
    z = N-x-y
    if 10000*x + 5000*y + 1000*z == Y:
      print(x,y,z)
      exit()
print(-1, -1, -1)

Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
template <typename T>
inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}

int main(){
    vector<ll> a(3);
    rep(i,3) cin>>a[i];
    sort(a.begin(),a.end(),greater<ll>());

    ll k;cin>>k;
    while(k--){
        a[0]*=2;
    }

    ll sum=0;
    rep(i,3){
        sum+=a[i];
    }

    cout<<sum<<endl;

    return 0;
}

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

int main(){
    string A , B , C;
    cin >> A >> B >> C;
    if (A[A.size()-1] == B[0] && B[B.size()-1] == C[0]){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}   

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

// boost
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll h, w;
  cin >> h >> w;

  if (h % 3 == 0 || w % 3 == 0) {
    cout << 0 << endl;
    return 0;
  }

  ll ans = INF;

  rep(c, 2) {
    if (h >= 3) {
      chmin(ans, w);
    }
    FOR(x, w / 3, w / 3 + 3) {
      FOR(y, h / 2, h / 2 + 2) {
        if (x > w || y > h)
          continue;

        ll a = x * h;
        ll b = (w - x) * y;
        ll c = w * h - a - b;
        ll mx = a;
        ll mn = a;
        chmax(mx, b);
        chmax(mx, c);
        chmin(mn, b);
        chmin(mn, c);
        ll v = mx - mn;
        chmin(ans, v);
      }
    }
    swap(w, h);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define endl "\n" 
using namespace std;
#define debug(x) cout<<"The value of "<<#x<<" is "<<x<<endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    cin.sync_with_stdio(0); cin.tie(0); 
    ull n;
    cin>>n;
    ull steps=0;
    ull amt=100;
    while(amt<n){
        steps++;
        amt+=amt/100;
    }
    cout<<steps<<endl;
}


Measured memory_bytes: 3652
n,m,q=map(int,input().split())
e=[]
for i in range(q):
    a,b,c,d=map(int,input().split())
    e.append([a,b,c,d])
def calc(a):
    #print(a)
    an=0
    for i in range(q):
        if a[e[i][1]-1]-a[e[i][0]-1]==e[i][2]:
            an+=e[i][3]
    return an
ans=[]
def ca(a,i,n,prev):
    if i==n:
        ans.append(calc(a))
    else:
        for j in range(prev,m+1):
            a[i]=j
            ca(a,i+1,n,j)

a=[0]*n 
ca(a,0,n,1)
print(max(ans))



Measured memory_bytes: 77340
/*******************************
 * written by Koki Riho
 * Rih0z https://github.com/Rih0z
 *******************************/

#include<iostream>
#include<map>
#include<vector>
#include<string>
#include<numeric>
#include<algorithm>

#define DEBUG false

#define FOR(i , a, b) for(size_t i = a ; i < b ; i++ )
#define REP(i,b) FOR(i , 0 , b)
#define RFOR(i,a,b) for(size_t i = a-1 ; i >= b ; i--)
#define RREP(i,a) RFOR(i,a,0)



typedef long long ll;
using namespace std;

int scanInt(void);
string scanString(void);

void scanLlArr(ll *a , int n);
void scanCharArr(char *string);

void printInt(int p);
void printLlArr(ll *a);
void printCharArr(char *string);


void perSum(ll *a , ll *sum ,int n);

/*************Global variable  **************/
int x1,y1,x2,y2,x3,y3,x4,y4 ;
char str[26];
std::map<char,int> M ;
/*******************************/

int main(){
  if (DEBUG){
    std::printf("******debug mode********\n");
  }
  cin >> x1 >> y1 >> x2 >> y2 ;
  //右下
  int difx = x2-x1;
  int dify = y2 - y1;
  int x = x2 ;
  int y = y2 ;
  REP(i,2){
    swap(difx,dify);
    difx = -difx ;
    x += difx ;
    y += dify ;
    cout << x << " " << y<< endl;
  }
  if (DEBUG){
    std::printf("******debug********\n");

    std::printf("******debug********\n");
  }
  return 0 ;
}

//各地点までの部分和を計算する
void perSum(ll *a , ll *sum ,int n){
  int i ;
  sum[0] = a[0];
  for(i = 1 ; i < n ; i++){
    sum[i] = a[i] + sum[i-1];
  }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
  ll n, k;
  cin >> n >> k;
  ll a = n%k;
  ll ans = min(a, k-a);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
	int n, h[101] = {};
	int max = 1, ans = 0, start = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &h[i]);
	}
	while (max != 0) {
		max = 0;
		for (int i = 0; i < n; i++) {
			if (max < h[i]) {
				max = h[i];
			}
		}
		for (int j = 0; j < n; j++) {
			if (h[j] == max) {
				ans++;
				if (h[j] == h[j + 1]) {
					ans--;
				}
				h[j]--;
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

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

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

    vector<double> p(n);
    vector<double> q(n);

    double max = 0;
    double tmp = 0;
    double tmp1 = 0;

    for(int i = 0; i < n; i++){
        cin >> p.at(i);
    }

    for(int i = 0; i < n; i++){
        q.at(i) = (0.5*p.at(i)*(p.at(i) + 1))/ p.at(i);
    }

    /*for(int i = 0; i < n; i++){
        cout << q.at(i) << endl;
    }*/


    int i;
    int j;

    for(int i = 0; i < k; i++){
        tmp += q.at(i); 
    }

    max = tmp;

    for(int i = 1; i <= n - k; i++){
        tmp = tmp + q.at(i + k - 1) - q.at(i - 1);

        if(tmp > max){
            max = tmp;
        }
    }
    
    /*for(i = 0; i < n - k + 1; i++){
        for(j = 0; j < k; j++){
            tmp += q.at(i + j);
        }

        if(tmp > max){
            max = tmp;
        }
        tmp = 0;
    }*/

    cout << fixed << setprecision(16) << max << endl;


}

Measured memory_bytes: 3328
n = gets.chomp.to_i
h = {}

1.upto(100) do |x|
  x.upto(100) do |y|
    y.upto(100) do |z|
      tmp = x * x + y * y + z * z + x * y + y * z + z * x

      h[tmp] ||= []
      h[tmp] << [x, y, z]
    end
  end
end

def count(arr)
  ret = 0
  arr.each do |(x, y, z)|
    if x == y && y == z
      ret += 1
    elsif x == y || y == z
      ret += 3
    else
      ret += 6
    end
  end
  ret
end

1.upto(n) do |m|
  unless h[m]
    puts 0
    next
  end

  cnt = count(h[m])
  puts cnt
end


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


vector<pair<long long,long long>> soin(long long N){
    vector<pair<long long, long long>> res;
    for (long long i = 2; i * i <= N; i++)
    {
        if(N % i != 0) continue;
        long long p = 0;
        
        while(N % i==0)
        {
            p++;
            N = N/i;
        }

        res.push_back({i,p});        
    }

    //2020=2^2*5*101,101はi*i<=N (sqrt n)に収まらない
    if(N!=1)
    {
        res.push_back({N, 1});
    }

    return res;
}

int main()
{
    long long N;
    cin >> N;
    const auto &res = soin(N);
    cout << N << ":";
    for(auto p : res)
    {
        for(int i = 1; i <= p.second;i++)
        {
            cout << " " << p.first;
        }
    }
    
    cout << endl;
}


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

int main(){
  string S;
  cin >> S;
  int before = 0;
  auto sz = S.size();
  vector<long long>s(0);
  for (int i=0;i<1<<sz-1;i++){
    bitset<9>A(i);
    //cout << A << endl;
    string tmp_s;
    auto before = 0;
    if(!A.any()){
      //cout << "KOKO" << endl;
      //cout << S << endl;
      s.push_back(stoll(S));
    }else{
      for (int j=0;j<9;j++){
        if (A.test(j)){
          tmp_s = "";
          for (int k=before;k<j+1;k++){
            tmp_s += S.at(k);
          }
          before = j+1;
          s.push_back(stoll(tmp_s));
        }
        if (j==8){
          tmp_s = "";
          for (int k=before;k<S.size();k++){
            tmp_s += S.at(k);
          }
          s.push_back(stoll(tmp_s));
        }
      }
    }
  }
  long long res=0;
  for (int i=0;i<s.size();i++){
    res += s.at(i);
  }
  cout << res << endl;
}


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

#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template <typename T> bool chkmax(T &x,T y){return x<y?x=y,true:false;}
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,true:false;}

ll readint(){
	ll x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int n;
ll a[205],b[70];
char s[205];

void add(ll x){
	for(int i=60;i>=0;i--){
		if(x&(1ll<<i)){
			if(!b[i]){
				b[i]=x;
				return;
			}
			x^=b[i];
		}
	}
}

bool ask(ll x){
	for(int i=60;i>=0;i--){
		if(x&(1ll<<i)){
			if(!b[i]) return 0;
			else x^=b[i];
		}
	}
	return 1;
}

int main(){
	int T=readint();
	while(T--){
		n=readint();
		for(int i=1;i<=n;i++) a[i]=readint();
		scanf("%s",s+1);
		for(int i=0;i<=60;i++) b[i]=0;
		int fl=0;
		for(int i=n;i>=1;i--){
			if(s[i]=='0') add(a[i]);
			else if(!ask(a[i])) fl=1;
		}
		printf("%d\n",fl);
	}
	return 0;
}

Measured memory_bytes: 3716
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int a=0,b=0,c;
		for(int i = 0;i < 3;i++){
			c=in.nextInt();
			if(i == 0) a = c;
			else{
				if(a > c){
					a = c;
				}
			}
		}
		for(int i = 0;i < 2;i++){
			c=in.nextInt();
			if(i == 0) b = c;
			else{
				if(b > c){
					b = c;
				}
			}
		}
		c = a + b - 50;
		System.out.println(c);
	}
}

Measured memory_bytes: 17164
#include <bits/stdc++.h>
 using namespace std;
 #define rep(i,N) for(int i=0;i<int(N);++i)
 using ll = long long;
 const int INF = 2147483647;
 const ll MOD = 1000000007;
//  const long long INF = 1LL << 60;

int main(){
   int x;
   cin >> x;
   int ans;
   if(x>=400&&x<=599) ans = 8;
   if(x>=600&&x<=799) ans = 7;
   if(x>=800&&x<=999) ans = 6;
   if(x>=1000&&x<=1199) ans = 5;
   if(x>=1200&&x<=1399) ans = 4;
   if(x>=1400&&x<=1599) ans = 3;
   if(x>=1600&&x<=1799) ans = 2;
   if(x>=1800&&x<=1999) ans = 1;
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 3628