akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

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

  int result;
  if (a + b < c) {
    result = b + a + b + 1;
  } else {
    result = b + c;
  }

  cout << result << endl;

  return 0;
}


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define endl "\n"     
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

int32_t main()
{
     IOS;
     
     string str;
     cin>>str;
     
     int n=str.size();
     
     if(str=="keyence")
     {
          cout<<"YES";
          return 0;
     }
     
     for(int i=0;i<n;i++)
     {
          for(int j=i;j<n;j++)
          {
               string temp=str.substr(0,i);
               temp+=str.substr(j+1,(n-1)-j);
               if(temp=="keyence")
               {
                    cout<<"YES";
                    return 0;
               }
          }
     }
     cout<<"NO";
     return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
    int arr[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K;  cin >> K;
    cout << arr[K - 1] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <string>
 
int main()
{
    int n, m, a[30][30], k[30], cnt = 0, ans = 0;

    std::cin >> n >> m;
    for (int i = 0;i < n;i++){
        std::cin >> k[i];
        for(int j = 0;j < k[i];j++){
            std::cin >> a[i][j];
        }
    }

    for(int i = 1;i <= m;i++){
        for(int j = 0;j < n;j++){
            for(int o = 0;o < k[j];o++){
                if(a[j][o] == i){
                    cnt++;
                }
            }
        }
        if(cnt == n){
            ans++;
        }
        cnt = 0;
    }

    std::cout << ans;
    

    return 0;
}

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

using namespace std;

void Main() {
    int A, B;
    cin >> A >> B;

    if (A <= 8 && B <= 8) {
        cout << "Yay!" << endl;
    }
    else {
        cout << ":(" << endl;
    }
}

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


Measured memory_bytes: 3580
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
	string str1,str2;
	long long n,m,i,small,big;
	cin>>str1>>str2;
	n=str1.size();m=str2.size();
	small=n<m?n:m;
	big=n>m?n:m;
	for(i=0;i<small;i++){
		cout<<str1[i]<<str2[i];
	}
	for(i=small;i<big;i++){
		if(n>m)
		cout<<str1[i];
		else
		cout<<str2[i];
	}
	return 0;
}

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

int main(){
    int H, W;
    vector<vector<int>> ans;
    int tail[505];
    
    cin >> H >> W;
    
    for ( int y = 1; y <= H; y++ ) {
        int v, n = 0;
        for ( int x = 1; x < W; x++ ) {
            cin >> v;
            n = (v + n) % 2;
            if ( n==1 ) {
                ans.push_back( { y, x, y, x+1} );
            }
        }
        cin >> v;
        tail[y] = (v + n) % 2;
    }
    
    int n = 0;
    for ( int y = 1; y < H; y++ ) {
        n = (tail[y] + n) % 2;
        if ( n==1 ) {
            ans.push_back( { y, W, y+1, W} );
        }
    }
    
    cout << ans.size() << endl;
    for ( int i = 0; i < ans.size(); i++ ) {
        printf( "%d %d %d %d\n", ans[i][0], ans[i][1], ans[i][2], ans[i][3] );
    }
}


Measured memory_bytes: 9136
#include "stdio.h"

void load(void);
int calc(void);

int t[100001], max = 0;

int main(void){
  load();
  printf("%d", calc());
}

void load(void){
  char s[100001];
  while(max < 100000){
  	s[max] = '\0';
    max++;
  }
  scanf("%s", s);
  max = 0;
  while(1){
    if(s[max] == '\0'){
      break;
    }else if(s[max] == '0'){
      t[max] = 0;
    }else if(s[max] == '1'){
      t[max] = 1;
    }
    max++;
  }  
}

int calc(void){
  int count = 0, count_ = 0, result[2] = {0, 0};
  
  while(count_ < 2){
    while(count < max){
      if(t[count] != (count + count_) % 2){
        result[count_]++;
      }
      count++;
    }
    count = 0;
    count_++;
  }
  
  if(result[0] < result[1]){
    return result[0];
  }else{
    return result[1];
  }
}

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

using namespace std;

typedef long long i64;
typedef i64 int_t;
typedef vector<int_t> vi;
typedef vector<vi> vvi;

typedef pair<int_t, int_t> pi;

#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define sz(a) i64((a).size())
#define all(c) (c).begin(), (c).end()
#define REP(s, e, i) for(i=(s); i < (e); ++i)

i64 compute(i64 N, i64 A, i64 B, i64 C, i64 D, unordered_map<i64, i64> &sol) {  
  if(sol.find(N) == sol.end()) {
    //cout << N << endl;
    i64 ans;
    if(N % 2 == 0) {
      ans = A + compute(N / 2, A, B, C, D, sol);
    }
    else {
      ans = D + A + min(compute(N / 2, A, B, C, D, sol),
			compute(N / 2 + 1, A, B, C, D, sol));
    }

    i64 res = N % 3;
    ans = min(ans, B + min(res       * D + compute(N/3,   A, B, C, D, sol),
			   (3 - res) * D + compute(N/3+1, A, B, C, D, sol)));

    res = N % 5;
    ans = min(ans, C + min(res       * D + compute(N/5, A, B, C, D, sol),
			   (5 - res) * D + compute(N/5+1, A, B, C, D, sol)));

    if(ans / D >= N) {
      ans = D * N;
    }

    sol[N] = ans;
    //cout << N << " " << sol[N] << endl;
  }

  return sol[N];
}

int main(int argc, char *argv[]) {

  i64 T, t;
  cin >> T;
  REP(0, T, t) {
    unordered_map<i64, i64> ans;
    i64 N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    ans[0] = 0;
    ans[1] = D;
    compute(N, A, B, C, D, ans);
    cout << ans[N] << endl;
  }

  return 0;
}


Measured memory_bytes: 4360
import numpy as np
N, D = map(int, input().split())
x = []
m = 0
for _ in range(N):
    x.append(list(map(int, input().split())))
for i in range(N):
    for j in range (i):
        d = np.sqrt(sum((x[i][k]-x[j][k])**2 for k in range(D)))
        if d.is_integer():
            m += 1
print(m)

Measured memory_bytes: 12428
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=10000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 998244353
#define eps 1e-8
struct node{int l,r;ll a;}seg[200200];
bool operator<(node p,node q) {return p.r<q.r;}
int n,m;
ll mx[1600800],tag[1600800];

int read()
{
    int 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;
}

void pushdown(int id,int l,int r)
{
	if (tag[id]!=0)
	{
		tag[id<<1]+=tag[id];tag[id<<1|1]+=tag[id];
		mx[id<<1]+=tag[id];mx[id<<1|1]+=tag[id];
		tag[id]=0;
	}
}

void modify(int id,int l,int r,int ql,int qr,ll val)
{
	pushdown(id,l,r);
	if ((l>=ql) && (r<=qr))
	{
		mx[id]+=val;tag[id]+=val;
		return;
	}
	int mid=(l+r)>>1;
	if (ql<=mid) modify(id<<1,l,mid,ql,qr,val);
	if (qr>mid) modify(id<<1|1,mid+1,r,ql,qr,val);
	mx[id]=max(mx[id<<1],mx[id<<1|1]);
}

ll query(int id,int l,int r,int ql,int qr)
{
	pushdown(id,l,r);
	if ((l>=ql) && (r<=qr)) return mx[id];
	int mid=(l+r)>>1;ll ans=0;
	if (ql<=mid) ans=max(ans,query(id<<1,l,mid,ql,qr));
	if (qr>mid) ans=max(ans,query(id<<1|1,mid+1,r,ql,qr));
	return ans;
}

signed main()
{
	n=read();m=read();
	rep(i,1,m)
	{
		seg[i].l=read();seg[i].r=read();seg[i].a=read();
	}
	sort(seg+1,seg+1+m);
	int pos=1;
	rep(i,1,n)
	{
		modify(1,1,n,i,i,query(1,1,n,1,i));
		while ((pos<=m) && (seg[pos].r==i))
		{
			modify(1,1,n,seg[pos].l,seg[pos].r,seg[pos].a);
			pos++;
		}
	}
	ll ans=max(0ll,query(1,1,n,1,n));
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 24320
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _1_10_b
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            double a = double.Parse(s[0]);  //a辺
            double b = double.Parse(s[1]);  //b辺
            double c = double.Parse(s[2]);  //角度c
            double sin = Math.Sin(c * Math.PI / 180);
            double cos = Math.Cos(c * Math.PI / 180);
            double[] answer = new double[3];

            answer[1] = b * (sin);//高さ
            answer[2] = (a * b * sin) / 2;//面積
            answer[0] = a + b + Math.Sqrt(a * a + b * b - 2 * a * b * cos);//周囲

            Console.WriteLine(answer[2]);
            Console.WriteLine(answer[0]);
            Console.WriteLine(answer[1]);
        }
    }
}



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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<pair<ll, ll> > res;
    priority_queue<ll> minus;
    priority_queue<ll, vector<ll>, greater<ll> > plus;
    ll sp = 0, sm = 0;
    rep (i, n) {
        ll x;
        cin >> x;
        if (x >= 0) {
            plus.push(x);
            sp++;
        } else {
            minus.push(x); 
            sm++;
        }
    }
    while (!plus.empty() && !minus.empty()) {
        ll p = plus.top(), m = minus.top(), tmp;
        plus.pop(), minus.pop(); 
        if (sp > sm) {
            tmp = m - p;
            minus.push(tmp);
            sp--;
            res.push_back(make_pair(m, p));
        } else {
            tmp = p - m; 
            plus.push(tmp);
            sm--;
            res.push_back(make_pair(p, m));
        }
    }
    if (sp > 0) {
        while (sp != 1) {
            ll x = plus.top();
            plus.pop();
            ll y = plus.top();
            plus.pop();
            sp--;
            if (sp == 1) {
                plus.push(y - x);
                res.push_back(make_pair(y, x));
            } else {
                plus.push(x - y);
                res.push_back(make_pair(x, y));
            }
        }
        cout << plus.top() << endl;
    } else if (sm > 0) {
        while (sm != 1) {
            ll x = minus.top();
            minus.pop();
            ll y = minus.top();
            minus.pop();
            minus.push(x - y);
            sm--;
            res.push_back(make_pair(x, y));
        }
        cout << minus.top() << endl;
    }
    rep (i, res.size()) {
        cout << res[i].first << " " << res[i].second << endl; 
    }
    
    return 0;
}



Measured memory_bytes: 4720
#include <bits/stdc++.h>
#define va first
#define vb second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll mod = 998244353;
ll N, K;
ll A[4040][4040], ans[4040];

ll comb(ll N, ll K) {
	if (N<0 || K<0 || K>N) return 0;
	if (A[N][K] != 0) return A[N][K];
	if (K==0 || K==N) return 1;
	return A[N][K] = (comb(N-1, K-1) + comb(N-1, K))%mod;
}

int main() {
	cin.tie(0); ios_base::sync_with_stdio(0);
	cin >> K >> N;

	for (int i=2; i<=K+1; i++) {
		if (i&1) {
			int j = i/2;
			for (int k=0; k<=j; k++) {
				if (k%2==0) ans[i] = (ans[i] + comb(j, k)*comb(K+N-2*k-1, K-1)%mod)%mod;
				else ans[i] = (ans[i] + mod - comb(j, k)*comb(K+N-2*k-1, K-1)%mod)%mod;
			}
		}
		else {
			int j = i/2;
			for (int k=0; k<j; k++) {
				if (k%2==0) ans[i] = (ans[i] + comb(j-1, k)*comb(K+N-2*k-1, K-1)%mod)%mod;
				else ans[i] = (ans[i] + mod - comb(j-1, k)*comb(K+N-2*k-1, K-1)%mod)%mod;
			}
			for (int k=0; k<j; k++) {
				if (k%2==0) ans[i] = (ans[i] + mod - comb(j-1, k)*comb(K+N-2*k-3, K-1)%mod)%mod;
				else ans[i] = (ans[i] + comb(j-1, k)*comb(K+N-2*k-3, K-1)%mod)%mod;
			}
		}
	}

	for (int i=2; i<=K+1; i++) cout << ans[i] << '\n';
	for (int i=K+2; i<=2*K; i++) cout << ans[2*K+2-i] << '\n';
}

Measured memory_bytes: 125696
#include<iostream>

void move(int, int);

char tiles[100][100];
bool mem[100][100];

int main()
{
  int H, W;
  while(true)
  {
    std::cin >> H >> W;
    if(!H && !W)
      break;
    for(int i = 0; i < 10000; i++)
      mem[i / 100][i % 100]  = 0;

    for(int i = 0; i < H; i++)
      std::cin >> tiles[i];

    move(0, 0);
  }
  return 0;
}

void move(int x, int y)
{
  if(mem[y][x])
  {
    std::cout << "LOOP" << std::endl;
    return;
  }

  mem[y][x] = true;

  switch(tiles[y][x])
  {
    case '<':
      move(x - 1, y);
      return;
    case '>':
      move(x + 1, y);
      return;
    case '^':
      move(x, y - 1);
      return;
    case 'v':
      move(x, y + 1);
      return;
    case '.':
      std::cout << x << " " << y << std::endl;
      return;
  }
}

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

int main()
{
  long long n;
  cin >> n;
  for(long long i=1;i<3600;i++){
    for(long long j=1;j<3600;j++){
      if(j*n+i*n-4*i*j == 0){
	continue;
      }
      if((i*j*n)%(j*n+i*n-4*i*j)==0 && -(i*j*n)/(j*n+i*n-4*i*j) > 0){
	cout << i << " " << j << " " << -(i*j*n)/(j*n+i*n-4*i*j) << endl;
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) throws FileNotFoundException {

  //  Scanner cin = new Scanner(new FileReader("input.txt"));
    Scanner cin = new Scanner(System.in);

    int x = cin.nextInt();
    int y = cin.nextInt();

    System.out.println(x + y/2);

  }

}

Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int a, b, c;

bool calc(int n, int y) {
	a = b = c = -1;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; i + j <= n; j++) {
			int k = n - (i + j);
			if (i * 10 + j * 5 + k == y) {
				a = i;
				b = j;
				c = k;
				return true;
			}
		}
	}
	return false;
}

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

	y /= 1000;
	calc(n, y);

	cout << a << " " << b << " " << c << endl;
	return 0;
}


Measured memory_bytes: 256
/************************************************************/
//
//2????????´??°a??¨b?????????????????§?????\?????????????¨??????????????????°??????
//???a??b 		??? d(??´??°)
//???a??b?????????  ??? r(??´??°)
//???a??b 		??? f(???????°???°?????°)
//
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_4_A&lang=jp
/************************************************************/

#include<stdio.h>

#define MAX 1000000000
#define MIN 1

int main()
{
	int a,b;
	
	if( scanf("%d %d", &a, &b)==2 )
	{
		if((a>=MIN) && (a<=MAX) &&
			(b>=MIN) && (b<=MAX))
		{
			printf("%d %d %.5lf\n", a/b, a%b, (double)a/(double)b);
		}
		else
		{
			/* ERROR */
			return -1;
		}
	}
	else
	{
		/* ERROR */
		return -1;
	}
	
	return 0;
}

Measured memory_bytes: 1844
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <queue>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <sstream>
#include <cassert>
#include <functional>
#include <cfloat>
#include <climits>
#include <cstring>
#include <stack>
#include <time.h>
#include <complex>
using namespace std; 
int a[101][101];
int main()
{
    int n,m;
    cin>>n;
    for(int i=1;i<=2;i++)
        {
        for(int j=1;j<=n;j++){
            cin>>a[i][j];
            a[i][j]+=max(a[i-1][j],a[i][j-1]);
        }
        }
    cout<<a[2][n];
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using Graph = vector<vector<int>>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, ans = 0;
  cin >> N;
  for (int i = 1; i <= N; i++)
    if (i % 3 != 0 && i % 5 != 0) ans += i;
  cout << ans << endl;
}

Measured memory_bytes: 3648
/* Great things never come from comfort zones,
"whatever the mind of a man can conceive and believe,it can achieve." */
 
#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define pb push_back
#define pf push_front
#define mp make_pair
#define F first
#define S second
#define all(x)     x.begin(),x.end()
#define tc   int tt; scf(tt); while(tt--)
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll mod =1e9+7;
const int N = 1e6+7;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

bool m[N]={0};


int main()
{
    
    int k;
    scf(k);

    prin(k*(k+1)/2);

    }

Measured memory_bytes: 3784
import math

a, b, x = map(int, input().split())
if a * a * b <= 2 * x:
    ans = math.degrees(math.atan((2 * (b - (x / (a * a))) / a)))
    print('{:.10f}'.format(ans))
else:
    ans = math.degrees(math.atan((a * b * b) / (2 * x)))
    print('{:.10f}'.format(ans))

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

#define MOD 1000000007
#define ll long long int
#define vi vector<int>
#define vii vector< vector<int> >
#define PI 3.1415926535897932384626433832795
#define INF 9223372036854775807LL

int arr[100005];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m;
	cin >> n >> m;
	for(int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	vii graph(n+2,vi());
	for(int i = 0; i < m; i++) {
		int x,y;
		cin >> x >> y;
		graph[x].push_back(y);
		graph[y].push_back(x);
	}
	int next = 0;
	vector<multiset<int> > trees;
	int ind = 0;
	vector<bool> was (n+2,false);
	int sizsum = 0;
	while(next != n) {
		while(next < n && was[next]) {
			next++;
		}
		if(next == n) {
			break;
		}
		trees.push_back(multiset<int>());
		stack<int> st;
		st.push(next);
		was[next] = true;
		while(!st.empty()) {
			int v = st.top();
			st.pop();
			trees[ind].insert(arr[v]);
			for(int u : graph[v]) {
				if(!was[u]) {
					was[u] = true;
					st.push(u);
				}
			}
		}
		ind++;
	}
	if(n < 2*ind-2) {
		cout << "Impossible";
		return 0;
	}
	multiset<int> curr;
	multiset<pair<int,int> > ot;
	srand(time(0));
	int rn = rand()%ind;
	rn = 0;
	for(int el : trees[rn]) {
		curr.insert(el);
	}
	for(int i = 0; i < ind; i++) {
		if(i == rn) {
			continue;
		}
		for(int el : trees[i]) {
			ot.insert({el,i});
		}
	}
	ll ans = 0;
	while(ot.size() > 0) {
		int best = (*curr.begin());
		curr.erase(curr.begin());
		auto bestot = ot.begin();
		pair<int,int> pr = *bestot;
		for(int el : trees[pr.second]) {
			curr.insert(el);
			ot.erase(ot.find({el,pr.second}));
		}
		curr.erase(curr.find(pr.first));
		while(curr.empty() && !ot.empty()) {
			curr.insert(pr.first);
			for(int el : trees[pr.second]) {
				curr.erase(curr.find(el));
				ot.insert({el,pr.second});
			}
			while(pr.second == (*bestot).second) {
				bestot++;
			}
			pr = *bestot;
			for(int el : trees[pr.second]) {
				curr.insert(el);
				ot.erase(ot.find({el,pr.second}));
			}
			curr.erase(curr.find(pr.first));
		}
		ans+= best+pr.first;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 17200
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>
#include<assert.h>
#include<random>
using namespace std;
#define int long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353 
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solve(void)
{
  int N , K;
  cin>>N>>K;
  int res = K;
  for (int i = 0; i < N - 1; i++)
  {
    res *= K -1;
  }
  cout<<res<<endl;
  
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Measured memory_bytes: 3564
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.C_Challenge
{
    class ABC_064
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            int[] array = ReadInts();
            var levelWall = new int[8]
                { 400, 800, 1200, 1600, 2000, 2400, 2800, 3200 };
            var levelCnt = new int[9];
            for (int i = 0; i < n; i++)
            {
                for(int j = 0; j <= levelWall.Length; j++)
                {
                    if (j == levelWall.Length)
                    {
                        levelCnt[levelWall.Length]++;
                    }
                    else if (array[i] < levelWall[j])
                    {
                        levelCnt[j]++;
                        break;
                    }
                }
            }

            int colorCnt = 0;
            for (int i = 0; i < levelWall.Length; i++)
            {
                if (levelCnt[i] > 0)
                {
                    colorCnt++;
                }
            }
            int min = colorCnt > 0 ? colorCnt : 1;
            int max = colorCnt + levelCnt[levelWall.Length];

            Console.WriteLine(min + " " + max);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11092
public class Main{
	public static void main(String[] a) {
		java.util.Scanner s = new java.util.Scanner(System.in);
		System.out.println((s.nextInt()+s.nextInt()*5+s.nextInt()*10+s.nextInt()*50+s.nextInt()*100+s.nextInt()*500)/1000>0?1:0);
	}
}

Measured memory_bytes: 17348
#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()
using i64 = long long;

int main(){
    int X,Y,S;
    while(cin >> X >> Y >> S, S != 0){
        int ans = -1;
        for(double p = 1; p < S; p++){
            for(double q = 1; q < S; q++){
                int P = floor(p*(100+X)/100);
                int Q = floor(q*(100+X)/100);
                if(P+Q != S) continue;
                if(P + Q > S) break;
                P = floor(p*(100+Y)/100);
                Q = floor(q*(100+Y)/100);
                ans = max(ans, P+Q);
            }
        }
        cout << ans << endl;
    } 
}


Measured memory_bytes: 3072
fn main() {
    let s: Vec<char> = read::<String>().chars().collect();
    if s[2] == s[3] && s[4] == s[5] {
        println!("{}", "Yes");
    } else {
        println!("{}", "No");
    }
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========


Measured memory_bytes: 4352
#![allow(unused_mut)]
#![allow(non_snake_case)]

#![allow(unused_imports)]
use std::collections::HashSet;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::VecDeque;
use std::cmp::{max, min};

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        w: usize,
        h: usize,
        x: usize,
        y: usize
    }
    println!("{} {}", w as f64 * h as f64 / 2 as f64,
        if 2 * x == w && 2 * y == h {
            1
        } else {
            0
        }
    )
}

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

typedef long long ll;
typedef pair< int, int > pii;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef vector< pii > vp;
typedef vector< vp > vvp;
typedef vector< string > vs;
typedef vector< double > vd;
typedef vector< vd > vvd;

template< class T1, class T2 >
int upmin( T1 &x, T2 v ){
  if( x > v ){
    x = v;
    return 1;
  }
  return 0;
}

template< class T1, class T2 >
int upmax( T1 &x, T2 v ){
  if( x < v ){
    x = v;
    return 1;
  }
  return 0;
}

const int INF = 0x3f3f3f3f;

int sx, sy, gx, gy;
int N;
vi X, Y, R;

void init(){
  cin >> sx >> sy >> gx >> gy;
  cin >> N;
  X = Y = R = vi( N );
  for( int i = 0; i < N; ++i )
    cin >> X[ i ] >> Y[ i ] >> R[ i ];
}

vd dp;

double eu_dis( double x, double y, double a, double b ){
  double dx = x - a;
  double dy = y - b;
  return sqrt( dx * dx + dy * dy );
}

void preprocess(){
  dp = vd( N );
  typedef tuple< double, int > tdi;
  priority_queue< tdi, vector< tdi >, greater< tdi > > pq;
  for( int i = 0; i < N; ++i )
    dp[ i ] = max( 0.0, eu_dis( X[ i ], Y[ i ], sx, sy ) - R[ i ] ),
    pq.emplace( dp[ i ], i );
  while( not pq.empty() ){
    double d; int u; tie( d, u ) = pq.top(); pq.pop();
    if( d != dp[ u ] ) continue;
    for( int i = 0; i < N; ++i ) if( i != u )
      if( upmin( dp[ i ], dp[ u ] + max( 0.0, eu_dis( X[ i ], Y[ i ], X[ u ], Y[ u ] ) - R[ i ] - R[ u ] ) ) )
        pq.emplace( dp[ i ], i ); 
  }
}

void solve(){
  double ans = eu_dis( gx, gy, sx, sy );
  for( int i = 0; i < N; ++i )
    upmin( ans, dp[ i ] + max( 0.0, eu_dis( X[ i ], Y[ i ], gx, gy ) - R[ i ] ) );
  cout << fixed << setprecision( 12 ) << ans << endl;
}

signed main(){
  ios::sync_with_stdio( 0 );
  init();
  preprocess();
  solve();
  return 0;
}

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define SUM(x) accumulate(ALL(x), 0)
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000
#define PI acos(-1.0)

int main()
{
  int n; cin >> n;
  ll a = 0, b = 0;
  REP(i, n) {
    ll a_, b_;
    cin >> a_ >> b_;
    if (a < a_) {
      a = a_;
      b = b_;
    }
  }

  cout << a + b << endl;
  return 0;
}


Measured memory_bytes: 256
program prob6
    implicit none
    integer(8) :: N
    integer(8), allocatable :: A(:)
    integer(8) :: M, i, cnt, tmp, ans

    read(*,*) N
    allocate(A(N))
    read(*,*) A
    call msort(A)

    tmp = A(1)
    cnt = 1
    M = 0
    ans = 1
    do i = 2, N
        if(A(i) == tmp) then
            cnt = cnt + 1
        else
            if(mod(cnt, 2) == 0) then
                M = M + 1
            end if
            cnt = 1
            tmp = A(i)
            ans = ans + 1
        end if
    end do
    if(mod(cnt, 2) == 0) then
        M = M + 1
    end if

    ans = ans - mod(M, 2)

    write(*,*) ans


    stop
contains


  !
  ! swap two arguments
  !
subroutine swap(a, b)
    implicit none
    integer(8), intent(inout) :: a, b

    integer(8) :: c

    c = a
    a = b
    b = c

  end subroutine swap

  !
  ! merge sort
  !
  recursive subroutine msort(x)
    implicit none
    integer(8), intent(inout) :: x(:)

    integer(8) :: n, mid, i, j, k
    integer(8), allocatable :: tmp(:)
    
    n = size(x)
    
    if(n == 1) then
      return
    end if

    !
    ! 前半と後半に分けてソート
    ! 1~midとmid+1~nをそれぞれソート済みにする
    !
    mid = n / 2
    call msort(x(:mid))
    call msort(x(mid+1:))

    !
    ! tmpという配列にxを一時的に保管
    ! マージソートは外部ソート
    !
    allocate(tmp(n))
    tmp = x

    ! tmpの後半部分を左右反転
    do k = n, mid+1, -1
      tmp(k) = x(mid + n - k + 1)
    end do

    ! iは前半のリストのうちまだ見ていないものの最小値
    ! jは後半のリストのうちまだ見ていないものの最小値
    ! kは見た回数の合計
    i = 1
    j = n

    do k = 1, n
      !
      ! 一番左と一番右のうち小さい方をxに入れていく
      ! ここが等号つき不等号なので、安定ソートとなる
      !
      if(tmp(i) <= tmp(j)) then
        x(k) = tmp(i)
        i = i + 1
      else
        x(k) = tmp(j)
        j = j - 1
      end if
    end do
    
    deallocate(tmp)
    return
  end subroutine msort


end program prob6

Measured memory_bytes: 4756
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int[] x = new int[n];
		int max = 0;
		int min = 100;

		for(int i = 0;i < n;i++) {
			x[i] = stdIn.nextInt();
			max = Math.max(max, x[i]);
			min = Math.min(min, x[i]);
		}


		int cost = Integer.MAX_VALUE;

		for(int i = min;i<=max;i++) {
			int ans = 0;
			for(int j = 0;j < n;j++) {
				ans = ans + ((x[j]-i)*(x[j]-i));
			}
			cost = Math.min(cost, ans);
		}

		System.out.println(cost);

	}

}


Measured memory_bytes: 22996
#include <stdio.h>


int main(){
    int a, b, c, k;
    if(scanf("%d %d %d %d", &a, &b,&c, &k)==EOF){return 0;}


    if(k <= a){printf("%d\n", k); return 0;}
    else if(a < k && k <= a+b){printf("%d\n", a); return 0;}
    else {printf("%d\n",2*a+b-k); return 0;} //a-(k-a-b)

}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    cout << s[0] << s.size() - 2 << s.back();
}


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

int main()
{
    int a,b;
    cin>>a>>b;
    int c=max(a,b);
    int d=min(a,b);
    if(c-2>=d){\
        cout<<c+c-1<<endl;
    }else{
        cout<<c+d;
    }

}


Measured memory_bytes: 3580
r,c=map(int,raw_input().split())
l=[]
for i in range(r):l.append(map(int,raw_input().split()))
l.append([0]*(c+1))
for i in range(c+1):
    for j in range(r):
        if i==0:l[j].append(sum(l[j]))
        l[-1][i]+=l[j][i]
for i in range(r+1):print' '.join(map(str,l[i]))


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

using namespace std;
typedef long long ll;
ll const INF = 1e18;

struct edge {
  int from, to;
  ll cost;
};

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

  vector<edge> edges;
  for (int i = 0; i < m; ++i) {
    int a, b;
    ll c;
    scanf("%d %d %lld", &a, &b, &c);
    --a; --b;
    edges.emplace_back(edge{a, b, -c});
  }

  ll d[n];
  for (int i = 0; i < n; ++i) d[i] = INF;
  d[0] = 0;
  for (int i = 0; i < n - 1; ++i) {
    for (auto e: edges) {
      if (d[e.from] == INF) continue;
      if (d[e.to] > d[e.from] + e.cost) {
	d[e.to] = d[e.from] + e.cost;
      }
    }
  }

  vector<bool> is_negative(n, false);
  for (int i = 0; i < n; ++i) {
    for (auto e: edges) {
      if (d[e.from] == INF) continue;

      if (d[e.to] > d[e.from] + e.cost) {
	d[e.to] = d[e.from] + e.cost;
	is_negative[e.to] = true;
      }

      if (is_negative[e.from]) is_negative[e.to] = true;
    }
  }
  
  if (is_negative[n - 1]) {
    printf("inf\n");
  } else {
    printf("%lld\n", -d[n - 1]);
  }
  return 0;
}



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

int main() {
  int  N, A, B, X;
  
  cin >> N >> A >> B;
  
  if ( N * A < B ) {
    X = N * A;
  }
  else {
    X = B;
  }
  
  cout << X << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;

map<ll, ll> prime;

void prime_fuctor(ll N)
{
    for (ll i = 2; i * i <= N; i++) {
        while (N % i == 0) {
            prime[i]++;
            N /= i;
        }
    }
    if (N != 1) prime[N]++;
}

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

    prime_fuctor(P);
    ll ans = 1;
    for (auto itr = prime.begin(); itr != prime.end(); itr++) {
        if (itr->second >= N) {
            ll cnt = (itr->second / N);
            ll cal = 1;
            while (cnt) {
                cal *= itr->first;
                cnt--;
            }
            ans *= cal;
        }
    }

    // if (N == 1) ans = P;

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

Measured memory_bytes: 256
///-----Bismillahir Rahmanir Rahim-----///

#include<bits/stdc++.h>
using namespace std;

///---FAST I/O---///
#define Boost() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

///---DATA TYPE---///
typedef long long ll;
typedef long long int lli;
///vector
typedef vector<int> vi;
typedef vector<ll> vl;
///pair
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;

///---LOOP---///
#define rep0(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)

///---I/O---///
#define sf scanf
#define pf printf

///---OTHERS---///
#define pb push_back
#define all(c)		c.begin(),c.end()
#define MK make_pair
#define F first
#define S second
#define endl '\n'


///---INITIALIZATION---//
#define mem(a,b) memset(a, b, sizeof(a) )

///---CALCULATE---///
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

///---BIT OPERATION---///
inline bool checkBit(ll n, int i)
{
    return n&(1LL<<i);
}
inline ll setBit(ll n, int i)
{
    return n|(1LL<<i);;
}
inline ll resetBit(ll n, int i)
{
    return n&(~(1LL<<i));
}

///------String/Char Related Functions-----///
string makeintString(int x)
{
    stringstream ss;
    ss << x;
    string str = ss.str();
    ///cout<<str<<endl;
    return str;
}
string makellString(ll x)
{
    stringstream ss;
    ss << x;
    string str = ss.str();
    ///cout<<str<<endl;
    return str;
}
char cpp(char c)
{
    return static_cast<char>(c + 1);
}

///---CONSTANT---///
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

int main()
{
    Boost();

    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int a[n+5];
        int xr=0;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
            xr=xr^a[i];
        }
        for(int i=0;i<n;i++)
        {
            int tmp=xr^a[i];
            cout<<tmp<<" ";
        }

    }
    return 0;
}



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

int N,W;
int v[1000],w[1000];
int main(){

    cin>>N>>W;
    for(int i=1;i<=N;i++){
        cin>>v[i]>>w[i];
    }

    vector<vector<int> > dp(N+1,vector<int>(W+1,0));

    for(int i=0;i<N;i++){
        for(int j=0;j<=W;j++){
            dp[i+1][j]=dp[i][j];
            if(j-w[i+1]>=0){
                dp[i+1][j]=max(dp[i+1][j],dp[i][j-w[i+1]]+v[i+1]);
            }
        }
    }

    cout<<dp[N][W]<<endl;
}


Measured memory_bytes: 6836
def main():
    s=list(input())
    alpha=[chr(i) for i in range(97, 97+26)]
    if s==list("zyxwvutsrqponmlkjihgfedcba"):
        print(-1)
        return
    if len(s)!=26:
        for i in range(26):
            a=alpha[i]
            if a not in s:
                s.append(a)
                print(''.join(s))
                return
    else:

        tank=[s[25]]
        for i in range(25):
            if ord(s[24-i])>ord(s[25-i]):
                tank.append(s[24-i])
            else:
                point=s[24-i]
                tank.append(s[24-i])
                tank.sort()
                for j in range(len(tank)):
                    if tank[j]==point:
                        head=tank.pop(j+1)
                        break
                s=s[:24-i]
                s.append(head)
                print(''.join(s))
                return                




if __name__ == "__main__":
    main()

Measured memory_bytes: 38384
s = input()
q = int(input())
arr = [list(input().split()) for i in range(q)]
mae1 = 0
mae = []
ato = []
for i in arr:
    if i[0] == '1':
        mae1 = 0 if mae1 == 1 else 1
    else:
        if mae1 == 0:
            if i[1] == '1':
                mae.append(i[2])
            else:
                ato.append(i[2])
        else:
            if i[1] == '1':
                ato.append(i[2])
            else:
                mae.append(i[2])
mae = ''.join(mae)
ato = ''.join(ato)
ans = mae[::-1] + s + ato
if mae1 == 1:
    ans = ans[::-1]
print(ans)


Measured memory_bytes: 31628
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int64_t n, k;
  cin >> n >> k;
  
  int64_t d=n%k;
  
  if(k-d < d){
    cout << k-d << endl;
  }
  else{
    cout << d << endl;
  }
}


Measured memory_bytes: 3632
#include "bits/stdc++.h"
#define LF '\n'
#define ALL(x) x.begin(), x.end()
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;
template<class Itr> void dump(Itr begin, Itr end) { for (;begin != end; ++begin) clog << *begin << LF; }

signed main()
{
  cin.tie(nullptr), ios::sync_with_stdio(false);

  int a, b;
  char c;
  cin >> a >> c >> b;
  if (c == '-') b = -b;

  cout << a+b << endl;

  return 0;
}



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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  int A;
  vec.at(0) = 0;
  for (int i = 1; i < N; i++) {
    cin >> A;
    vec.at(i) = A;
  }
  sort(vec.begin(), vec.end());
  int counter;
  int start = 0;
  for (int i = 0; i < N; i++) {
    counter = 0;
    for (int j = start; j < N; j++) {
      if (vec.at(j) == i+1)
        counter++;
      if (vec.at(j) > i+1)
        break;
    }
    cout << counter << endl;
    start += counter;
  }
}


Measured memory_bytes: 4024
#![allow(non_snake_case,unused_imports,dead_code)]
use std::io::Read;
use std::cmp::max;
use std::cmp::min;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::BinaryHeap;
use std::cmp::Ordering;

use proconio::input;
use proconio::marker::{Chars,Usize1,Isize1};

fn comp_f64(a: &f64, b: &f64) -> Ordering {
    if a < b {
        return Ordering::Less;
    } else if a > b {
        return Ordering::Greater;
    }
    Ordering::Equal
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut buf_it = buf.split_whitespace();
    
    let N = buf_it.next().unwrap().parse::<usize>().unwrap();
    let M = buf_it.next().unwrap().parse::<usize>().unwrap();

    let mut K = vec![0;N];
    let mut L = vec![Vec::new();N];

    for i in 0..N{
        K[i] = buf_it.next().unwrap().parse::<usize>().unwrap();
        for _ in 0..K[i]{
            let l = buf_it.next().unwrap().parse::<usize>().unwrap()-1;
            L[i].push(l);
        }
    }

    let mut U = UnionFind::new(N+M);
    for i in 0..N{
        for j in 0..K[i]{
            U.merge(i,L[i][j]+N);
        }
    }
    let p = U.get_parent(0);
    for i in 1..N{
        if U.get_parent(i)!=p{
            println!("NO");
            return;
        }
    }
    println!("YES");
}


struct UnionFind{
        P: Vec<usize>,
    }
    
    impl UnionFind {
        fn new(n:usize) -> UnionFind{
            UnionFind {P:(0..n).collect()}
        }
        fn get_parent(&mut self,n:usize) -> usize{
            if self.P[n] == n{ return n;}
            let p = self.P[n];
            self.P[n] = self.get_parent(p);
            self.P[n]
        }
        fn is_united(&mut self,x:usize,y:usize) -> bool{
            self.get_parent(x)==self.get_parent(y)
        }
        fn merge(&mut self,x:usize,y:usize){
            if self.is_united(x,y) {return;}
            let i = self.get_parent(x);
            let j = self.get_parent(y);
            self.P[j] = i;
        }
    }

Measured memory_bytes: 13724
import java.util.Scanner;
class Main{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
int a=scan.nextInt();
int[][] c=new int[4][14];
for(int x=0;x<4;x++){
for(int y=1;y<14;y++){
c[x][y]=0;
}
}
for(int b=0;b<a;b++){
String d=scan.next();
int e=scan.nextInt();
if("S".equals(d))
c[0][e]=1;
if("H".equals(d))
c[1][e]=1;
if("C".equals(d))
c[2][e]=1;
if("D".equals(d))
c[3][e]=1;
}
for(int x=0;x<4;x++){
for(int y=1;y<14;y++){
if(c[x][y]==0){
if(x==0)
System.out.print("S ");
if(x==1)
System.out.print("H ");
if(x==2)
System.out.print("C ");
if(x==3)
System.out.print("D ");
System.out.println(y);

}
}
}
}
}

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

int main() {
  string s, t; cin >> s >> t;
 
  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());
  
  if(s<t) cout << "Yes" << endl;
  else cout << "No" << endl;
  
    return 0;
}

Measured memory_bytes: 256
#include "iostream"
using namespace std;

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

	cin>>n;
	if(n<1200){
		cout<<"ABC";
	}
	else if(n<2800){
		cout<<"ARC";
	}
	else{
		cout<<"AGC";
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>
#include <queue>

using namespace std;

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

int main(){
    string s;
    cin >> s;
    pair<int, int> ans = {-1, -1};
    for(int i = 1; i < s.size(); i ++){
        if(s[i - 1] == s[i]){
            ans = {i - 1 + 1, i + 1};
            break;
        }
        if(i >= 2 && s[i - 2] == s[i]){
            ans = {i - 2 + 1, i + 1};
            break;
        }
    }

    cout << ans.first << " " << ans.second << endl;
    return 0;
}


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


int main(){
    int n, l; cin >> n >> l; 
    vector<string> s(n); rep(i,n) cin >> s[i];
    sort(s.begin(), s.end());
    string ans = ""; rep(i,n) ans = ans + s[i];
    cout << ans << endl;
}

Measured memory_bytes: 256
s, t = input(), input()
ls, lt = len(s), len(t)

table = [[0] * (lt+1) for i in range(ls+1)]
for ss in range(ls):
    for st in range(lt):
        table[ss+1][st+1] = table[ss][st] + 1 if s[ss] == t[st] else max(table[ss+1][st], table[ss][st+1] )

ans = ""
ss, st = ls, lt
while ss * st != 0:
    if table[ss][st] == table[ss-1][st]:
        ss -= 1
    elif table[ss][st] == table[ss][st-1]:
        st -= 1

    else:
        ss -= 1
        st -= 1
        ans = s[ss] + ans

print(ans)

Measured memory_bytes: 113244
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
int main(void){
    ll N , H , W ;
    cin >> N >> H >> W ;
    ll A[N] , B[N] ;
    for(ll i = 0 ; i < N ; i++){
        cin >> A[i] >> B[i] ;
    }
    ll cnt = 0 ;
    for(ll i = 0 ; i < N ; i++){
        if(H <= A[i] && W <= B[i]){
            cnt++ ;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3620
n, k = map(int, input().split())
p = list(map(int, input().split()))
l = []

num = 0
for j in range(k):
    num += p[j]
l.append(num)

for i in range(n-k):
    l.append(l[i]-p[i]+p[i+k])

print((max(l)+k)/2)

Measured memory_bytes: 32008
using System;

class NREasy
{
	static public void Main(string[] args)
	{
		int W,a,b;
		string[] vals = Console.ReadLine().Split(' ');
		W = int.Parse(vals[0]);
		a = int.Parse(vals[1]);
		b = int.Parse(vals[2]);

		int aR = a + W;
		int bR = b + W;

		if(aR >= b && a <= bR)
		{
			Console.WriteLine(0);
		}
		else if(aR < b)
		{
			Console.WriteLine(b-aR);
		}
		else
		{
			Console.WriteLine(a-bR);
		}

	}
}


Measured memory_bytes: 11092