akhauriyash/Code-Regression huggingface dataset:
N, X = map(int, input().split())
p = 1
t = 1
pdic = {}
tdic = {}
for i in range(N):
  pdic[i] = p
  tdic[i] = t
  p = 2*p+1
  t = 2*t+3
pdic[N] = p
tdic[N] = t
ans = 0
nokori = X
state = N
count = N
while True:
  while tdic[count]+state-count>nokori:
    count -= 1
    if count<0:
      break
  if count<0:
    break
  nokori -= (tdic[count]+state-count)
  state = count
  ans += pdic[count]
  if nokori==0:
    break
  nokori -= 1
  ans += 1
  if nokori==0:
    break
print(ans)

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

using namespace std;

int main(){
  unsigned long int h,w;
  unsigned long int ans;
  cin>> h>>w;
  if(h%2==1 && w%2==1)
    ans=(h*w+1)/2;
  else
    ans=h*w/2;
  
  if(h==1 || w==1)
    ans=1;
  
  cout<<ans;
  
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace ABC162
{
    public class Solve
    {
        public static void Main(string[] args)
        {
            new ABC_C();
        }
    }
    public class ABC_A
    {
        public ABC_A()
        {
            var n = Ex.Read;
            Ex.Cw(n[0] == '7' || n[1] == '7' || n[2] == '7');
        }
    }
    public class ABC_B
    {
        public ABC_B()
        {
            // FizzBuzz列の  N  項目までに含まれる数の和
            long n = Ex.ReadLong;
            long ans = 0;

            for (int i = 0; i <= n; i++)
            {
                if (i % 3 == 0 || i % 5 == 0)
                    continue;
                ans += i;

            }
            Ex.Cw(ans);
        }
    }
    public class ABC_C
    {
        int k = Ex.ReadInt;
        long ans = 0;
        public ABC_C()
        {
            for (int i = 1; i <= k; i++)
                for (int j = 1; j <= k; j++)
                    for (int c = 1; c <= k; c++)
                    {
                        ans += Gcd(Gcd(i, j), c);
                    }
            Ex.Cw(ans);
        }

        static long Gcd(long m, long n)
        {
            if (n == 0) return m;
            return Gcd(n, m % n);
        }
    }
    public class ABC_D
    {
        public ABC_D()
        {
        }
    }
    public class ABC_E
    {
        public ABC_E()
        {
        }
    }
    public class ABC_F
    {
        public ABC_F()
        {
        }
    }
    public static class Ex
    {
        public static void Cw(object s)
        {
            Console.WriteLine(s);
        }
        public static void Cw(bool b)
        {
            if (b) Ex.Cw("Yes");
            else Ex.Cw("No");
        }

        public static string Read { get { return Console.ReadLine().Trim(); } }
        public static int ReadInt { get { return int.Parse(Read); } }
        public static long ReadLong { get { return long.Parse(Read); } }
        public static double ReadDouble { get { return double.Parse(Read); } }
        public static string[] ReadArray() { return Read.Split(' '); }
        public static int[] ReadIntArray() { return Read.Split(' ').Select(s => int.Parse(s)).ToArray(); }
        public static long[] ReadLongArray() { return Read.Split(' ').Select(s => long.Parse(s)).ToArray(); }
        public static string[] ReadArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public static int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public static long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 17672
var
	N,i,j,sz:Longint;
	A:Array[1..100,1..99]of Longint;
	ans:String;
begin
	read(N);
	if N=2 then begin
		writeln(-1);
		exit;
	end;
	if N mod 2=1 then begin
		for i:=1 to N-1 do A[N,i]:=i;
		i:=1;
		while i<=N-1 do begin
			for j:=1 to i-1 do begin
				A[i,j]:=j;
				A[i+1,j]:=j;
			end;
			A[i,i]:=i+1;
			A[i+1,i+1]:=i;
			A[i,i+1]:=i+2;
			A[i+1,i]:=i+2;
			for j:=i+2 to N-1 do begin
				A[i,j]:=j+1;
				A[i+1,j]:=j+1;
			end;
			inc(i,2);
		end;
	end else begin
		i:=1;
		while i<=N-2 do begin
			for j:=1 to i-1 do begin
				A[i,j]:=j;
				A[i+1,j]:=j;
			end;
			A[i,i]:=i+1;
			A[i+1,i+1]:=i;
			A[i,i+1]:=i+2;
			A[i+1,i]:=i+2;
			for j:=i+2 to N-1 do begin
				A[i,j]:=j+1;
				A[i+1,j]:=j+1;
			end;
			inc(i,2);
		end;
		for j:=1 to N-3 do begin
			A[N-1,j]:=j;
			A[N,j]:=j;
		end;
		A[N-1,N-2]:=N;
		A[N,N-1]:=N-1;
		A[N-1,N-1]:=N-2;
		A[N,N-2]:=N-2;
	end;
	setlength(ans,3*N*N);
	sz:=0;
	for i:=1 to N do begin
		for j:=1 to N-1 do begin
			if A[i,j]<10 then begin
				inc(sz);
				ans[sz]:=Chr(A[i,j]+48);
			end else if A[i,j]<100 then begin
				inc(sz);
				ans[sz]:=Chr(A[i,j]div 10+48);
				inc(sz);
				ans[sz]:=Chr(A[i,j]mod 10+48);
			end else begin
				inc(sz);
				ans[sz]:='1';
				inc(sz);
				ans[sz]:='0';
				inc(sz);
				ans[sz]:='0';
			end;
			inc(sz);
			ans[sz]:=#10;
		end;
	end;
	setlength(ans,sz);
	write(ans);
end.


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long 
#define mp make_pair 
#define pb push_back
#define F first 
#define S second 
#define f(i,n) for(int i=0;i<n;i++) 

using namespace std;

void test(){
	int n;
	cin>>n;
	ll a[n];
	f(i,n)cin>>a[i];
	sort(a,a+n);
	reverse(a,a+n);
	ll res = a[0];
	ll count = 1;
	for(int i=1;i<n;i++){
		if(count<(n-1)){
			ll mi = min(2LL,(n-1)-count);
			res = res + (a[i]*mi);
			count = count + mi;
		}else
			break;
	}
	cout<<res<<"\n";
}

int main(){
	int tests=1;
//	cin>>tests;
	while(tests--){
		test();
	}
}

Measured memory_bytes: 5196
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using namespace std;

int main()
{	
	int a, b, c;
	cin >> a >> b >> c;

	if((a + b) >= c){
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}



Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, K: int, a: "List[int]", b: "List[int]"):
    d = defaultdict(int)
    for ai, bi in zip(a, b):
        d[ai] += bi
    for k, v in sorted(d.items()):
        K -= v
        if K <= 0:
            print(k)
            return
    assert False


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    a = [int()] * (N)  # type: "List[int]"
    b = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, K, a, b)


if __name__ == '__main__':
    main()


Measured memory_bytes: 20840
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mp make_pair
#define pb push_back

void solve(){
    // Solve here
    int a, b, c;
    cin>>a>>b>>c;

    if(a%b==0) cout<<(a/b)*c<<endl;
    else cout<<((a/b)+1)*c<<endl;
}

int main() {

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3608
<?php

fscanf(STDIN, "%d", $n);
$H = []; $X = []; $Y = [];
for ($i = 0; $i < $n; ++$i) {
    fscanf(STDIN, "%d %d %d", $x, $y, $h);
    $X[] = $x; $Y[] = $y; $H[] = $h;
}

$ans;
for ($cx = 0; $cx <= 100; ++$cx) {
    for ($cy = 0; $cy <= 100; ++$cy) {

        // Hが0になるパターンも含んで列挙する
        $tmp = [];
        for ($i = 0; $i < $n; ++$i) {
            $tmp[] = $H[$i] + abs($X[$i] - $cx) + abs($Y[$i] - $cy);
        }
        $tmp = array_unique($tmp);

        // Hが0になっていないことを検証する
        foreach ($tmp as $hh) {
            // $hh: Hの候補
            $flg = true;
            for ($i = 0; $i < $n; ++$i) {

$tmax = max($hh - abs($X[$i] - $cx) - abs($Y[$i] - $cy), 0);

/* echo "tmax: $tmax, hh: $hh", PHP_EOL; */

                if ($tmax != $H[$i]) {
                    $flg = false;
                    break;
                }
            }
            if ($flg) {
                $ans = $hh;
/* echo "cx: $cx, cy: $cy, arr: " . implode(' ', $tmp), PHP_EOL; */
                break 3;
            }
        }

    }
}

echo sprintf("%d %d %d\n", $cx, $cy, $ans);


Measured memory_bytes: 4604
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 1000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;

signed main(void) {
    string S;
    cin >> S;
    int m = atoi(S.substr(5,2).c_str());
    int d = atoi(S.substr(8,2).c_str());
    if (m <= 3) {
        cout << "Heisei" << endl;
    } else if (m == 4) {
        if (d <= 30) {
            cout << "Heisei" << endl;
        } else {
            cout << "TBD" << endl;
        }
    } else {
        cout << "TBD" << endl;
    }
    return 0;
}

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

int main(){
  int A, B;
  cin >> A >> B;
  
  int ans = 0;
  
  if(A+B <= A-B){
    ans = A-B;
  }
  else{
    ans = A+B;
  }
  
  if(ans <= A*B){
    ans = A*B;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
def calc_h(cx,cy,xyh_item):
  res=abs(cx-xyh_item[0])+abs(cy-xyh_item[1])+xyh_item[2]
  return res

n=int(input())
xyh=[[int(x) for x in input().split()] for _ in range(n)]


#平地の情報があると結果がバグるので捨てる
xyh0=[]
xyh1=[]
for item in xyh:
  if item[2]==0:
    xyh0.append(item)
  else:
    xyh1.append(item)

xyh=xyh1
#ただしピラミッドの根元の高さ0の地点は重要なので残す（any(~)にtrueがあれば根元の可能性がある）　
for item0 in xyh0:
  if any([calc_h(item1[0],item1[1],item0)==item1[2] for item1 in xyh1]):
    xyh.append(item0)
n=len(xyh)

#全探索
anslist=[]
xyh.sort(key=lambda x:x[0],reverse=True)
for x in range(101):
  for y in range(101):
    c=0
    tmp=calc_h(x,y,xyh[0])
    for i in range(1,n):
      if tmp!=calc_h(x,y,xyh[i]):
        break
      else:
        c+=1
    #if c==n-1:
    #  print(x,y,tmp)
    anslist.append([c,x,y,tmp])


anslist.sort(key=lambda x:x[0])
print(*anslist[-1][1:])

Measured memory_bytes: 47600
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1e9;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main(){
  int n;
  cin>>n;
  vector<vector<int>> c(2,vector<int>(n));
  rep(i,2) rep(j,n) cin>>c[i][j];
  int ans=0;
  rep(i,n){
    int cnt=0;
    for(int j=0;j<=i;j++){
      cnt+=c[0][j];
    }
    for(int j=i;j<n;j++){
      cnt+=c[1][j];
    }
    ans=max(ans,cnt);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define va first
#define vb second
#define lb lower_bound
#define pb push_back
#define all(v) v.begin(),v.end()
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
using ll = long long;
using lf = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
const ll mod = 1e9 + 7;
int h, w;
char buf[1005][1005];
int dp[1005][1005];

int main(){
    fio;
    cin >> h >> w;
    for(int i = 1; i <= h; i++) cin >> buf[i] + 1;
    dp[0][1] = 1;
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            if(buf[i][j] == '#') continue;
            dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % mod;
        }
    }
    cout << dp[h][w] << '\n';
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
long long dp[1005][1005];
int main()
{
	char X[1005],Y[1005];
	int n,x,y; cin>>n;
	while(n--){
		scanf("%s%s",X,Y);
		x = strlen(X);
		y = strlen(Y);
		for(int i=0;i<=max(x,y);i++)
			dp[0][i] = dp[i][0] = 0;
		for(int i=1;i<=x;i++)
			for(int j=1;j<=y;j++)
				if(X[i-1]==Y[j-1]) dp[i][j] = dp[i-1][j-1]+1;
				else dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
		printf("%d\n",dp[x][y]);
	}
	return 0;
}



Measured memory_bytes: 11064
# coding: utf-8
# Your code here!

import sys

def input():
    return sys.stdin.readline().rstrip()

N = int(input())
a = []
tmp, head, tail = "", "", ""

for i in range(N):
    tmp = input()
    if tmp in a:
        print("No")
        exit()
    else:
        a.append(tmp)
        if i != 0:
            tail = (a[i-1])[-1]
            head = (a[i])[0]
            if tail != head:
                print("No")
                exit()
else:
    print("Yes")

Measured memory_bytes: 3064
import bisect
inf = 10**18
a,b,q = map(int,input().split())
shrine = [-inf] + list(int(input()) for _ in range(a)) + [inf]
temple = [-inf] + list(int(input()) for _ in range(b)) + [inf]

for q in range(q):
    x = int(input())
    m,n = bisect.bisect_right(shrine,x),bisect.bisect_right(temple,x)
    res = inf
    for s in [shrine[m-1],shrine[m]]:
        for t in [temple[n-1],temple[n]]:
            d1,d2 = abs(s-x)+abs(t-s),abs(t-x)+abs(s-t)
            res = min(res,d1,d2)
    print(res)

Measured memory_bytes: 14408
#include<stdio.h>
#include<string.h>
int N,M,i,j,k,P[105],r;
char S[105][9],t[9];
int main()
{
	for(;scanf("%d%d\n",&N,&M),N+M;)
	{
		for(i=r=0;i<N;i++)scanf("%s%d",S[i],P+i);
		for(i=0;i<M;i++)
		{
			scanf("%s",&t);
			for(k=0;k<N;k++)
			{
				for(j=0;S[k][j];j++)
					if(S[k][j]!='*'&&S[k][j]!=t[j])
						break;
				if(!S[k][j])
					r+=P[k];
			}
		}
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
#define int long long
#define sz(x) (int)(x.size())
using namespace std;

const int N = 2e5 + 5, inf = 1e18, mod = 1e9 + 7;


int32_t main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);  


    int n, m;
    cin >> n >> m;
    int tot = 0;
    for(int i = 0, u; i < m; i++){
        cin >> u;
        tot += u;
    }
    int ans = (n >= tot ? n - tot : -1);
    cout << ans;
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#define int long long
using namespace std;
signed main() {
	int N;
    cin>>N;
    int ans=0;

    vector<int>A(N);
    
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    for(int i=0;i<N-1;i++){
        if(A[i]>A[i+1]){
            ans+=A[i]-A[i+1];
            A[i+1]=A[i];
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4800
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

typedef long long ll;

int N;
void input()
{
    cin>>N;
}

void solve()
{
    ll ans=0;
    for(int i=1;i<=N;++i){
        if(i%3==0 || i%5==0) continue;
        ans+=i;
    }
    cout<<ans<<endl;
}

int main()
{
    cin.tie();
    ios::sync_with_stdio(false);
    input();
    solve();
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i, n) for (int i = 0; i < n; ++i)
#define debug(x) std::cout << #x << ": " << x << '\n';
#define pb push_back
#define int long long
const int N = 5e5 + 10;
int a[N], used[N], cnt[N];
std::vector<int> nxt[N], cur;
int32_t main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0); std::cout.tie(0);
	ll n, k;
	std::cin >> n >> k;

	FOR(i, n) {
		std::cin >> a[i];
		nxt[a[i]].pb(i);
	}
	ll now = 0;
	ll sz = 0;
	std::vector<std::pair<ll,ll>> s;
	s.pb({0, 0});
	while (!used[now] && now < n) {
		used[now] = 1;

		auto it = std::upper_bound(nxt[a[now]].begin(), nxt[a[now]].end(), now);
		// debug(now)
		if (it == nxt[a[now]].end()) {
			sz += (n - now) + nxt[a[now]][0] + 1;
			// debug(sz)
			now = nxt[a[now]][0] + 1;
		}
		else {
			sz += (*it - now + 1);
			now = *it + 1;
		}
		// debug(now << ' ' << sz);
		s.pb({now, sz});
		// return 0;
	}
	ll times = n * k;
	times %= s.back().second;
	// debug(times)
	// return 0;
	// debug(s.back().second)
	for (int j = s.size() - 1; j >= 0; --j) {
		if (s[j].second <= times) {
			times -= s[j].second;
			assert(times <= n);
			// debug(times)
			// debug(s[j].first << ' ' << times)
			now = s[j].first;
			// return 0;
			while (times != 0) {
				if (cnt[a[now % n]] == 0) {
					cur.pb(a[now % n]);
					cnt[a[now % n]]++;
				}
				else {
					while (cnt[a[now % n]] != 0) {
						cnt[cur.back()]--;
						cur.pop_back();
					}
				}
				times--;
				now++;
			}
			break;
		}
	}
	for (auto e : cur) {
		std::cout << e << ' ';
	}
}

Measured memory_bytes: 37616
#include <iostream>
int main(void){
	long long int dp[30];
	dp[0]=1;
	dp[1]=2;
	dp[2]=4;
	for(int i=3;i<30;i++){
		dp[i]=dp[i-1]+dp[i-2]+dp[i-3];
	}
	int n;
	while(1){
		std::cin>>n;
		if(n==0){
			break;
		}else {
			std::cout<<dp[n-1]/3650+1<<std::endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3108
import sys, math
from functools import lru_cache
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    print((N-2)*180)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9560
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	ll n; cin >> n;
	cout << n * (n - 1) / 2 << endl;
}

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

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);

	int n;
	string s;
	cin >> n >> s;

    int i = 0, ans = 0;
	while (i < n) {
		int j = i;

		while (s[i] == s[j] && j < n) {
			j++;
		}
		ans++;
		i = j;
	}

	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) {sort(all(a));a.erase(unique(all(a)),a.end());}
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
vvi g;
int main(){
    ll n;cin>>n;
    g=vvi(n);
    rep(i,n-1){
        ll a,b;cin>>a>>b;a--;b--;
        g[a].pb(b);g[b].pb(a);
    }
    ll k;cin>>k;
    vi v(n,-1);
    rep(i,k){
        ll a,b;cin>>a>>b;v[a-1]=b;
    }
    SPQ(P) pq;
    rep(i,n)if(v[i]!=-1)pq.push(P(v[i],i));
    while(!pq.empty()){
        auto t=pq.top();pq.pop();
        for(ll x:g[t.se]){
            if(v[x]==-1){
                v[x]=t.fi+1;pq.push(P(t.fi+1,x));
            }
            else if(v[x]!=t.fi+1&&v[x]!=t.fi-1)dame("No");
        }
    }
    out("Yes");
    for(ll x:v)out(x);
}

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

#define ll long long 
 
using namespace std ;
 
ll z , ans , o ;

ll mod = 1e9 + 7 ;
ll N = 1e5 + 7 ;


int main( ){

	double r ;

	cin >> r ;

	double p = 3.1415 ;

	cout << fixed << setprecision(3) << 2 * p * r << endl ; 

}	



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

#define LL long long
typedef pair<int, int> pii;

template< typename T > inline void read(T &x)
{
    static char _c;
    static bool _f;

    x = 0;
    _f = 0;
    _c = getchar();

    while(_c < '0' || '9' < _c) {if(_c == '-') _f = true; _c = getchar();}
    while('0' <= _c && _c <= '9') {x = (x << 1) + (x << 3) + (_c & 15); _c = getchar();}
    if(_f) x = -x;
}

template < typename T > inline void Min(T &x, T y) {if(y < x) x = y;}
template < typename T > inline void Max(T &x, T y) {if(x < y) x = y;}


#define lowbit(x) ((x) & -(x))
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) ((l)+(((r)-(l))>>1))
#define fi first
#define se second
#define mk make_pair
#define pb push_back

const int INF = 0x3f3f3f3f;
const int MOD = (int) 1e9 + 7;
//const int MOD = (int) 998244353;
const int maxn = (int) 2e5 + 20;
const int maxm = (int) 1e6 + 20;
const double pi = (double) acos(-1.0);
const double eps = (double) 1e-8;

inline int sig(double x) {return x < -eps ? -1 : eps < x;}
LL fp(LL a, LL n, LL m = MOD) {LL res = 1; for(; n; n >>= 1, a = a * a % m) if(n & 1) res = res * a % m; return res;}

void work()
{
    LL n;
    cin >>n;

    LL ans = 0;
    LL cnt = 1;
    while(n)
    {
        ans += cnt;
        n /= 2;
        cnt *= 2;
    }
    cout <<ans <<endl;
}

int main()
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
//    get_prime();
    int tc = 1;
//    read(tc);
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mid (tl+tr)/2
#define mod 1000000007
#define fain(arr) for(ll i=0;i<n;i++)cin>>arr[i];
#define all(x) x.begin(),x.end()
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define bugv(n1) if(DEBUG)cout<<#n1<<" is "<<n1<<'\n';
#define buga(A) cout<<#A<<" is :"<<endl ; for(auto x:A)cout<<x<<" "; cout<<endl;
#define FILE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define endl '\n'
#define ll long long 
#define pii pair<ll,ll>
#define pll pair<long long ,long long >
#define pi acos(-1)
#define sz(x) ((ll)x.size())
#define clr(x) memset(x, 0, sizeof(x))
#define init(x, a) memset(x, a, sizeof(x))
#define DEBUG true
using namespace std;

int main(){
    // FILE;
    SPEED;
    ll n,m,k;
    cin>>n>>m>>k;

    ll a[n];
    fain(a);
    ll b[m];
    rep(i,0,m)cin>>b[i];

    ll j=0;
    ll i=0;
    ll rem=k;

    for(;i<n;i++){
        if(rem-a[i]>=0){
            rem-=a[i];
        }
        else{
            break;
        }
    }

     for(;j<m;j++){
        if(rem-b[j]>=0){
            rem-=b[j];
        }
        else{
            break;
        }
    }

    ll ans = i+j;

    while(i>=0){
        i--;
        rem+=a[i];
        while(j<m){
            if(rem-b[j]>=0){
                rem-=b[j];
            }
            else{
                break;
            }
            j++;
        }

        ans=max(ans,i+j);
    }

    cout<<ans<<endl;




}


Measured memory_bytes: 6776
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b;
  cin>>a>>b;
  cout<<((a<9 && b<9) ? "Yay!" : ":(")<<'\n';
  return(0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

// フェルマーの小定理
ll mod_pow(ll n, ll p, ll mod=MOD) {
    if(p==0) return 1;
    ll res = mod_pow(n*n%mod, p/2, mod);
    if(p%2==1) res = res * n % mod;
    return res;
}
ll nCr(ll n, ll r, ll mod=MOD) {
    r = min(r, n-r);
    ll numer = 1, denom = 1;
    rep(i,r) {
        numer *= n-i;
        numer %= mod;
        denom *= i+1;
        denom %= mod;
    }
    return numer * mod_pow(denom, mod-2, mod) % mod;
}

int main() {
	int N, M, K;
	cin >> N >> M >> K;
    ll ans = 0;
    // 2点の差がxになる組み合わせは同じ行でM-x通り、2点の行の組み合わせはN*N通り
    rep(x, M) ans += (ll)x * (M-x) * N*N;
    rep(y, N) ans += (ll)y * (N-y) * M*M;
    // 2点以外(K-2)をN*M-2のマスに配置する組み合わせはnCr(N*M-2, K-2)通り
    ans %= MOD;
    ans *= nCr(N*M-2, K-2, MOD);
    ans %= MOD;

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    if (N % 2 == 1) {
        cout << 0 << endl;
        return 0;
    }
    int ans = 0;
    N /= 10;
    ans += N;
    while(N > 0) {
        ans += N / 5;
        N /= 5;
    }
    cout << ans << endl;


    return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef unordered_set<int> si;
typedef pair<int, int> pp;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)


template <typename T>
void printV(vector<T> A) {
    if (A.empty()) cerr << "EMTPY\n";
    else { 
        cerr << "\n[";
        for (int i = 0; i < A.size() -1 ; ++i) {
            cerr << A[i] << ", ";
        }
        if (A.size()) cerr << A.back() << "]\n";
    }
}


template <typename T>
void printVV(vector<vector<T>> A) {
    cerr << "\n[";
    for (auto v : A) {
        printV<T>(v);
    }
    cerr << "]\n";
}

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cerr << name << ": " << arg1 << endl;
}

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


ll sum[20];

int main(int argc, char **argv) {
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;

    if (n & 1) {
        cout << 0 << endl;
        return 0;
    }

    ll base = 5, ans = 0;
    while (n / base > 0) {
        ans += (n/base) / 2;
        base *= 5;
    }

    cout << ans << endl;

    return 0;
    
}



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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int main() {
    ios_base::sync_with_stdio(false);
    char c;
    cin >> c;
    if (c >= 'A' && c <= 'Z') {
        cout << "A" << endl;
    } else {
        cout << "a" << endl;
    }
    return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <bitset>
#include <map>
#include <math.h>
#include <utility>

using namespace std;

const double PI = acos(-1);

int main(){

    long long N, A, B;
    cin >> N >> A >> B;

    if ((B - A) % 2 == 0) {
        cout << (B - A) / 2 << endl;
    } else {
        cout << min(A + (B-A-1)/2, (N-B+1) + (B-A-1)/2) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import math

EnemyCount, slayeCount = map(int, input().split())
enemyHealths = list(map(int, input().split(" ")))
enemyHealths.sort()

if EnemyCount < slayeCount:
    slayeCount = EnemyCount

for _ in range(slayeCount):
    del enemyHealths[-1]

print(sum(enemyHealths))


Measured memory_bytes: 27300
#include<stdio.h>
#include<string.h>
int main(void){
    double g;
    while(scanf("%lf",&g)!=EOF){
        if(91<g)puts("heavy");
        else if(81<g)puts("light heavy");
        else if(75<g)puts("middle");
        else if(69<g)puts("light middle");
        else if(64<g)puts("welter");
        else if(60<g)puts("light welter");
        else if(57<g)puts("light");
        else if(54<g)puts("feather");
        else if(51<g)puts("bantam");
        else if(48<g)puts("fly");
        else puts("light fly") ;

    }

    return 0;
}

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

using namespace std;

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    string x;

    cin >> n >> x;

    for(int i=0;i<x.size();++i)
        cout << (char)((x[i]-'A'+n)%26+'A');
    cout << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

void rotate_S(int minase_inori[6]) {
	int hayami_saori = minase_inori[0];
	minase_inori[0] = minase_inori[4];
	minase_inori[4] = minase_inori[5];
	minase_inori[5] = minase_inori[1];
	minase_inori[1] = hayami_saori;
}

void rotate_NES(int kugimiya_rie[6]) {
	int kitamura_eri = kugimiya_rie[1];
	kugimiya_rie[1] = kugimiya_rie[3];
	kugimiya_rie[3] = kugimiya_rie[4];
	kugimiya_rie[4] = kugimiya_rie[2];
	kugimiya_rie[2] = kitamura_eri;
}

int check(const int asumi_kana[6], const int iguti_yuka[6]) {
	int sakura_ayane;
	int satou_satomi[6];
	for (sakura_ayane = 0; sakura_ayane < 6; sakura_ayane++) {
		satou_satomi[sakura_ayane] = iguti_yuka[sakura_ayane];
	}
	for (sakura_ayane = 0; sakura_ayane < 4; sakura_ayane++) {
		int tateno_kanako;
		for (tateno_kanako = 0; tateno_kanako < 6; tateno_kanako++) {
			if (asumi_kana[tateno_kanako] != satou_satomi[tateno_kanako]) break;
		}
		if (tateno_kanako >= 6) {
			return 1;
		}
		rotate_NES(satou_satomi);
	}
	return 0;
}

int tokui_sora(const int utida_maaya[6], const int taneda_risa[6]) {
	int igarasi_hiromi[6];
	int horie_yui;
	for (horie_yui = 0; horie_yui < 6; horie_yui++) {
		igarasi_hiromi[horie_yui] = taneda_risa[horie_yui];
	}
	if (check(utida_maaya, igarasi_hiromi)) return 1;
	for (horie_yui = 0; horie_yui < 4; horie_yui++) {
		rotate_NES(igarasi_hiromi);
		rotate_S(igarasi_hiromi);
		if (check(utida_maaya, igarasi_hiromi)) return 1;
		rotate_S(igarasi_hiromi);
		rotate_S(igarasi_hiromi);
		rotate_S(igarasi_hiromi);
	}
	rotate_S(igarasi_hiromi);
	rotate_S(igarasi_hiromi);
	return check(utida_maaya, igarasi_hiromi);
}

int main(void) {
	int mizuhasi_kaori;
	int ootani_ikue[100][6];
	int uesaka_sumire, suzaki_aya;
	if (scanf("%d", &mizuhasi_kaori) != 1) return 1;
	for (uesaka_sumire = 0; uesaka_sumire < mizuhasi_kaori; uesaka_sumire++) {
		for (suzaki_aya = 0; suzaki_aya < 6; suzaki_aya++) {
			if (scanf("%d", &ootani_ikue[uesaka_sumire][suzaki_aya]) != 1) return 1;
		}
	}
	for (uesaka_sumire = 0; uesaka_sumire < mizuhasi_kaori; uesaka_sumire++) {
		for (suzaki_aya = uesaka_sumire + 1; suzaki_aya < mizuhasi_kaori; suzaki_aya++) {
			if (tokui_sora(ootani_ikue[uesaka_sumire], ootani_ikue[suzaki_aya])) {
				puts("No");
				return 0;
			}
		}
	}
	puts("Yes");
	return 0;
}


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

#define NIL -1

typedef struct node{
  int key;
  struct node *parent;
  struct node *left;
  struct node *right;
}Node;

Node* insert(Node*, int);
Node* find(Node*, int);
Node* delete(Node*, int);
void print(Node *);
void inorderTreeWalk(Node *);
void preorderTreeWalk(Node *);

main(){
  int m, key, i;
  char string[10];
  Node *T, *node;

  T = NULL;

  scanf("%d", &m);
  for(i=0; i<m; i++){
    scanf("%s", string);
    if(strcmp(string, "insert")==0){
      scanf("%d", &key);
      T = insert(T, key);
    }
    else if(strcmp(string, "find")==0){
      scanf("%d", &key);
      if(find(T, key) == NULL) printf("no\n");
      else printf("yes\n");
    }
    else if(strcmp(string, "delete")==0){
      scanf("%d", &key);
      T = delete(T, key);
    }
    else print(T);
  }

  return 0;
}

Node* insert(Node *T, int key){
  Node *x, *y, *z;
  
  //creatNode
  z = malloc(sizeof(Node));
  z->key = key;
  z->left = NULL;
  z->right = NULL;

  y = NULL;  //x??????
  x = T;
  
  while(x != NULL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  
  if(y==NULL) T = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
  return T;
}

Node* find(Node *T, int key){
  while(T != NULL && T->key != key){
    if(key < T->key) T = T->left;
    else T = T->right;
  }
  return T;
}

Node* delete(Node *T, int key){
  Node *delNode, *x;
  Node *findNode = find(T, key);
  if(findNode == NULL) return T;  //????????????
  
  if(findNode->left == NULL || findNode->right == NULL) delNode = findNode; //??????1,0
  else {  //??????2
    delNode = findNode->right;
    while(delNode->left != NULL) delNode = delNode->left;
  }
  
  if(delNode->left != NULL) x = delNode->left;
  else x = delNode->right;

  if(x != NULL) x->parent = delNode->parent;
  if(delNode->parent == NULL) T = x;
  else if(delNode == delNode->parent->left) delNode->parent->left = x;
  else delNode->parent->right = x;

  if (delNode != findNode){
    findNode->key = delNode->key;
  }

  free(delNode);
  return T;
}

void print(Node *T){
  inorderTreeWalk(T);
  printf("\n");

  preorderTreeWalk(T);
  printf("\n");
}

void inorderTreeWalk(Node *T){
  if(T == NULL) return;

  inorderTreeWalk(T->left);
  printf(" %d", T->key);
  inorderTreeWalk(T->right);
}

void preorderTreeWalk(Node *T){
  if(T == NULL) return;
  printf(" %d", T->key);
  preorderTreeWalk(T->left);
  preorderTreeWalk(T->right);
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int n;
  cin >> n;
  ll tot = 0;
  vector<ll> a(n), x(n);
  rep(i, n) cin >> a[i];

  int x0 = 0;
  for (int i = 0; i < n; ++i) {
    if (i % 2 == 0)
      x0 += a[i];
    else
      x0 -= a[i];
  }
  x[0] = x0 / 2;
  for (int i = 0; i < n - 1; ++i) x[i + 1] = a[i] - x[i];
  for (auto xx : x) cout << 2 * xx << " ";
  cout << endl;

  return 0;
}


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

const int mod = 1000000007;

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

	int ans = 0;
	for (int c = 1; c < n; c++) {
		int trg = n - c;
		for (int i = 1; i*i <= trg; i++) {
			if (trg % i == 0) {
				if (trg/i == i) ans++;
				else ans += 2;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3632
from collections import deque

h, w = list(map(int, input().split()))

s = [list(input()) for _ in range(h)]

yo = [[0] * w for _ in range(h)]
q = deque([])
c = 0

for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            q.append((i, j))
            c += 1
        
        if s[i][j] == "#" or j == w-1:
            while len(q) > 0:
                x, y = q.pop()
                yo[x][y] = c
            c = 0



m = 0

c = 0
for j in range(w):
    for i in range(h):
        if s[i][j] == ".":
            q.append((i, j))
            c += 1

        if s[i][j] == "#" or i == h-1:
            while len(q) > 0:
                x, y = q.pop()
                m = max(m, yo[x][y] + c - 1)
            c = 0
print(m)


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

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define llrep(i,n)   for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prt_dbl(i,var) cout<<fixed<<setprecision(i)<<var<<endl;
template <typename Val,typename Number>
//use ll or int for gcd
Val gcd(Val a, Val b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
//count vector and return pair (count,vector item)
template <typename Val,typename Number>
void count_vector(vector<Val>* A,vector<pair<Number,Val>>*R){
  sort(A->begin(),A->end());
  int count = 1;
  rep(i,A->size()){
    if(i<A->size()-1){
      if(A->at(i)==A->at(i+1))count++;
      else{
        R->push_back(make_pair(count,A->at(i)));
        count = 1;
      }
    }else{
      R->push_back(make_pair(count,A->at(i)));
      count = 1;
    }
  }
}

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

int main(){
  ll N,K,ans;
  cin>>N>>K;
  ll x = N%K;
  if(x==0)ans =x;
  else {

    if(x>abs(x-K)){
      ans = abs(x-K);

    }else{
      ans = x;
    }

  }



  cout<<ans<<endl;




}


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

using namespace std;

int main(){
    string s;
    string t;
    cin>>s>>t;
    int n=s.length();
    int ans=0;
    for(int i=0;i<n;i++){
        if(s[i]!=t[i]){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main()
{
    int n,sum=0,i;
    cin>>n;
    int a[n];
    for(i=0;i<n-1;i++)
    {
        cin>>a[i];
    }
    //a[n-1]=0;
    sum+=a[0]+a[n-2];
    for(i=0;i<n-2;i++)
    {

        if(a[i]>=a[i+1])
        {
          sum+=a[i+1];
        }
        else
        {
            sum+=a[i];
        }

    }
    cout<<sum<<endl;




    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

// > 200*3
#define ROW_MAX 300
#define COL_MAX ROW_MAX
#define BUF_SIZE 1000
#define COST_MAX 0x01010101
#define VERTEXES 10

int get_int2(int *a1, int *a2) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d", a1, a2);
#else
#error
#endif
  return 0;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
#ifdef BUF_SIZE
    char line[BUF_SIZE];
    char *tmpbuf = line;
    int i;
    if(!fgets(line, BUF_SIZE, stdin)) return -1;
    for(i = 0; i < size; i++) {
        char *tmp = strtok(tmpbuf, " ");
        arr[i] = strtol(tmp, NULL, 10);
        tmpbuf = NULL;
    }
#else
#error
#endif
    return 0;
}

int main(void) {
    int graph[VERTEXES][VERTEXES];
    memset(graph, 0x01, sizeof(int)*VERTEXES*VERTEXES);
    int cnt_map[VERTEXES] = {0};
    int row, col;
    get_int2(&row, &col);
    int i, j, k;
    for(i = 0; i < VERTEXES; i++) {
        fget_array(graph[i], VERTEXES);
    }

    for(i = 0; i < row; i++) {
        static int buf[COL_MAX];
        fget_array(buf, col);
        for(j = 0; j < col; j++) {
            if(buf[j] == -1) continue;
            cnt_map[buf[j]]++;
        }
    }

    // * -> 1 (Warshall–Floyd Algorithm)
    for(k = 0; k < VERTEXES; k++) {
        for(i = 0; i < VERTEXES; i++) {
            for(j = 0; j < VERTEXES; j++) {
                int new = graph[i][k] + graph[k][j];
                if(new < graph[i][j]) {
                    graph[i][j] = new;
                }
            }
        }
    }

    int ans = 0;
    for(i = 0; i < VERTEXES; i++) {
        ans += (graph[i][1] * cnt_map[i]);
    }
    printf("%d\n", ans);

    return 0;
}

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

using namespace std;



int main() {
    ios::sync_with_stdio(false);
    
    int n, W;
    cin >> n >> W;
    
    vector<long long> D(100005, -1);
    D[0] = 0;
    
    for (int i = 0; i < n; ++i) {
        int w, v;
        cin >> w >> v;
        
        for (int j = W - w; j >= 0; --j) {
            if (D[j] != -1) {
                D[j + w] = max(D[j + w], D[j] + v);
            }
        }
    }
    
    cout << *max_element(D.begin(), D.end());
    
    return 0;
}

Measured memory_bytes: 1024
s=input()
n=len(s)
s1=s[:(n-1)//2]
s2=s[(n+1)//2:]
ans='Yes'
for s in [s,s1,s2]:
  for i in range(len(s)):
    if s[i]!=s[-1-i]:
      ans='No'
      break
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
long long n,ave;
long long a[55];
long long dp[55][55][2501];
int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>ave;
    long long sum=0;
    for(long long i=1;i<=n;++i)
    {
        dp[i][0][0]=1;
        cin>>a[i];
        sum+=a[i];
    }
    dp[0][0][0]=1;
    for(long long i=1;i<=n;i++)
    {
        for(long long j=1;j<=i;j++)
        {
            for(long long k=1;k<=sum;k++)
            {
                if(k<a[i])
                {
                     dp[i][j][k]=dp[i-1][j][k];
                }
                else
                {
                    dp[i][j][k]=dp[i-1][j][k]+dp[i-1][j-1][k-a[i]];
                }
            }
        }
    }
    long long  ans=0;
    for(long long j=1;j<=n&&j*ave<=sum;j++)
    {
            ans+=dp[n][j][j*ave];
    }
    cout << ans <<endl;
    return 0;
}


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

int main()
{
    int a, b;
    cin >> a >> b;
    if (a < b)
        cout << "a < b\n";
    else if (a > b)
        cout << "a > b\n";
    else
            cout << "a == b\n";

    return 0;
}

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

int64_t calcDiff(std::array<int64_t, 3>&& arr)
{
	std::sort(arr.begin(), arr.end());
	return arr.back() - arr.front();
}

int main()
{
	int64_t H, W;
	scanf("%lld%lld", &H, &W);
	int64_t diff{1ll << 60};
	for (int64_t i{1}; i < H - 1; i++)
	{
		int64_t left{W / 2}, other{H - i};
		diff = std::min(diff, calcDiff({i * W, left * other, (W - left) * other}));
		diff = std::min(diff, calcDiff({other * W, left * i, (W - left) * i}));
		diff = std::min(diff, calcDiff({i * W, other / 2 * W, (other - other / 2) * W}));
	}
	for (int64_t i{1}; i < W; i++)
	{
		int64_t top{H / 2}, other{W - i};
		diff = std::min(diff, calcDiff({i * H, top * other, (H - top) * other}));
		diff = std::min(diff, calcDiff({other * H, top * i, (H - top) * i}));
		diff = std::min(diff, calcDiff({i * H, other / 2 * H, (other - other / 2) * H}));
	}
	printf("%lld\n", diff);

	return 0;
}

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

int main() {
    int n, l;
    cin >> n >> l;
    vector<int> a(n);
    rep(i, n) {
        a[i] = l+i;
    }
    int s = 0;
    rep(i, n) s += a[i];
    int ans = 1e9;
    rep(i, n) {
        int t = s-a[i];
        if (abs(t-s) < abs(ans-s)) ans = t;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
uvw = [0]*(n-1)
for i in range(n-1):
    uvw[i] = list(map(int,input().split()))
V = [[] for i in range(n+1)]
for u,v,w in uvw:
    V[u].append([v,w])
    V[v].append([u,w])
from collections import deque
q = deque([])
now = 1
reach = [0]*(n+1)
reach[now] = 2
q.append(now)
while q:
    x = q.popleft()
    for L in V[x]:
        if reach[L[0]] == 0:
            q.append(L[0])
            reach[L[0]] = reach[x] + L[1]
for A in reach[1:]:
    if A%2 == 0:
        print(0)
    else:
        print(1)

Measured memory_bytes: 64428
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>


using namespace std;

int main(){
    int A,B;
    cin>>A>>B;

    int C,D,E;

    C=(A)+(B);
    D=(A)-(B);
    E=(A)*(B);


    cout<<max({C,D,E})<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int main()
{
    int n;
    cin >> n;
    ll ans = 0;
    rep(i, 1, n + 1)
        rep(j, 1, n + 1)
            rep(k, 1, n + 1) ans += gcd(i, gcd(j, k));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
N = int(input())
count = 0
a = input()
list1 = list(map(int,a.split()))

for i in range(1,N-1):
    if list1[i-1] < list1[i] < list1[i+1]:
        count +=1
    elif list1[i+1] < list1[i] < list1[i-1]:
        count +=1

print(count)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <climits>
#include <utility>
typedef long long ll;
using namespace std;

int main(void){
  int n, i, j, sum, min = INT_MAX;
  int x[100];

  cin >> n;

  for(i=0;i<n;i++){
    cin >> x[i];
  }

  for(i=0;i<100;i++){
    sum = 0;
    for(j=0;j<n;j++){
      sum += (i-x[j]) * (i-x[j]);
    }
    if(sum<min)min = sum;
  }

  cout << min << endl;
  
  return 0;
}


Measured memory_bytes: 256