akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <fstream>
#include <bitset>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef map<int, int> mii;
typedef map<int, string> mis;
typedef map<string, int> msi;
typedef set<int> si;
typedef set<ll> sl;
typedef map<ll, ll> mll;
typedef queue<int> qi;
typedef queue<ii> qii;
typedef vector<string> vs;
typedef pair<ll, ll> iil;
typedef vector<iil> viil;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int, ii> iii;
typedef vector<pair<pair<int,int>,int>> viii;
typedef vector<pair<pair<ll,ll>,ll>> viiil;

#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = 0 ; i < n ; i++)
#define INF 1000000000
#define MOD 1000000007;

void solve() {
    int n;
    cin >> n;
    
    double p[n];
    rep(i, n) cin >> p[i];
    double dp[n+1][n+1];
    memset(dp, 0, sizeof dp);
    dp[0][0] = 1;
    rep(i, n) {
        rep(j, n) {
            if (i+j < n) {
                dp[i + 1][j] += dp[i][j] * p[i+j];
                dp[i][j + 1] += dp[i][j] * (1 - p[i+j]);
            }
        }
    }
    double tp = 0;
    rep(i, n+1) {
        rep(j, n+1) {
            if (i+j == n && i > n/2) {
                tp += dp[i][j];
            }
        }
    }
    
    cout.precision(12);
    cout << tp << endl;
}

void querySolve() {
    int n;
    cin >> n;
    while (n--) {
        //solve();
    }
}

int main() {
    //querySolve();
    solve();

}


Measured memory_bytes: 74020
/*  -*- coding: utf-8 -*-
 *
 * f.cc: F - Enclosed Points
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;
const int MOD = 998244353;

/* typedef */

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

template <typename T, const int MAX_N>
struct BIT {
  int n;
  T bits[MAX_N + 1];
  BIT() {}

  void init(int _n) {
    n = _n;
    memset(bits, 0, sizeof(bits));
  }

  T sum(int x) {
    T s = 0;
    while (x > 0) {
      s += bits[x];
      x -= (x & -x);
    }
    return s;
  }

  void add(int x, T v) {
    while (x <= n) {
      bits[x] += v;
      x += (x & -x);
    }
  }
};

/* global variables */

int xs[MAX_N], ys[MAX_N], sxs[MAX_N], sys[MAX_N];
pii ps[MAX_N];
int e2s[MAX_N + 1], qs[MAX_N][4], bs[4];
BIT<int,MAX_N> bit;

/* subroutines */

/* main */

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

  for (int i = 0; i < n; i++) {
    scanf("%d%d", xs + i, ys + i);
    sxs[i] = xs[i], sys[i] = ys[i];
  }
  sort(sxs, sxs + n);
  sort(sys, sys + n);

  for (int i = 0; i < n; i++) {
    int px = lower_bound(sxs, sxs + n, xs[i]) - sxs;
    int py = lower_bound(sys, sys + n, ys[i]) - sys;
    ps[i] = pii(px, py);
  }
  sort(ps, ps + n);

  e2s[0] = 1;
  for (int i = 0; i < n; i++) e2s[i + 1] = e2s[i] * 2 % MOD;

  bit.init(n);
  for (int i = 0; i < n; i++) {
    int py = ps[i].second + 1;
    int q = bit.sum(py);
    qs[i][0] = q;
    qs[i][1] = i - q;
    bit.add(py, 1);
  }

  bit.init(n);
  for (int i = n - 1; i >= 0; i--) {
    int py = ps[i].second + 1;
    int q = bit.sum(py);
    qs[i][2] = q;
    qs[i][3] = n - 1 - i - q;
    bit.add(py, 1);
  }

  /*
  for (int i = 0; i < n; i++) {
    printf("%d(%d,%d)", i, ps[i].first, ps[i].second);
    for (int j = 0; j < 4; j++) printf(" %d", qs[i][j]);
    putchar('\n');
  }
  */

  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum = (sum + e2s[n - 1]) % MOD;

    for (int bits = 0; bits < 1 << 4; bits++) {
      for (int j = 0; j < 4; j++) bs[j] = ((bits >> j) & 1);
      if ((bs[0] || bs[1]) && (bs[2] || bs[3]) &&
	  (bs[0] || bs[2]) && (bs[1] || bs[3])) {
	int c = 1;
	for (int j = 0; j < 4; j++)
	  if (bs[j])
	    c = (ll)c * ((e2s[qs[i][j]] + MOD - 1) % MOD) % MOD;
	sum = (sum + c) % MOD;
      }
    }
  }

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


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

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

	if (A >= B)cout << "delicious" << endl;
	else if (B - A <= X)cout << "safe" << endl;
	else cout << "dangerous" << endl;

	return 0;
}

Measured memory_bytes: 256
N, a, b, C, D = gets.split.map(&:to_i)
S = gets.chomp.chars
ans = 'No'

if D < C
  flag = false
  (b-1).upto(D-1) do |i|
    if S[(i-1)..(i+1)].join == '...'
      flag = true
      break
    end
  end
  if !flag
    puts ans
    exit
  end
end
while a <= C && b <= D
  if b != D
    if S[b] == '.'
      b += 1
    elsif S[b+1] == '.'
      b += 2
    else
      break
    end
  else
    if S[a] == '.'
      a += 1
    elsif S[a+1] == '.'
      a += 2
    else
      break
    end
  end
  if a == C && b == D
    ans = 'Yes'
    break
  end
end

puts ans

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



int main() {
    const double PI=3.14159265358979323846;
	int A,B,H,M;
	cin>>A>>B>>H>>M;
  	long double D =(H*30+M*0.5)-(M*6);
  
  if(D<0){
  D=-D;
  }
  
  if(D>180){
  D=360-D;
  }
  

  long double Dp=D*PI/180;
  
 
  
  //ここまでで角度を出すやつは書けた！
  
  //ここから余弦定理に当てはめる
  long double kk =A*A+B*B-(2*A*B)*cos(Dp);//cos90は0だから5になるはずなのに
 
 //で、でたー！！！sqrt()でルートの値が出るのね
  
  cout << fixed << setprecision(20) << sqrt(kk) << endl;//そしてfixed<<setprecision()で任意の桁数が出せるのですね
  
}
  


Measured memory_bytes: 4092
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}


ll a[100009];


int main() {
	ll N, M;
	cin >> N >> M;
	set<ll> from;
	set<ll> to;
	rep(i, M) {
		ll a, b;
		cin >> a >> b;
		if (a == 1) from.insert(b);
		if (b == N)to.insert(a);
	}
	rep(i, N) {
		if (from.count(i) && to.count(i)) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;
}


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

const int COMMAX = 200000;
const int MOD = 1000000007;
vector<long long> fac, finv, inv;

void InitializeCombination(void){
    fac.push_back(1LL);
    fac.push_back(1LL);
    finv.push_back(1LL);
    finv.push_back(1LL);
    inv.push_back(0LL); //Though 0^(-1) cannot be defined, there should be some number in inv[0]
    inv.push_back(1LL);
    for (int i = 2; i < COMMAX; i++){
        fac.push_back(fac[i-1] * (long long)i % (long long)MOD);
        inv.push_back((long long)MOD - inv[MOD%i] * (long long)(MOD/i) % (long long)MOD);
        finv.push_back(finv[i-1] * inv[i] % (long long)MOD);
    }
}

long long Combination(int n, int r){
    if (n < r) return 0LL;
    if (n < 0 || r < 0) return 0LL;
    return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD;
}

int main(void){
    int N, M, K;
    cin >> N >> M >> K;

    InitializeCombination();

    long long sumCost = 0;

    for(int i=1; i<N; i++){
        sumCost += (long long)(N-i)*M*M%MOD*i%MOD;
        sumCost = sumCost % MOD;
    }
    for(int i=1; i<M; i++){
        sumCost += (long long)(M-i)*N*N%MOD*i%MOD;
        sumCost = sumCost % MOD;
    }

    sumCost = (sumCost*Combination(N*M-2, K-2))%MOD;

    cout << sumCost << endl;

    return 0;
}

Measured memory_bytes: 5204
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

s=input().rstrip()
t=input().rstrip()
strs=[]
for i in range(len(s)):
    j=len(s)-i
    ba=s[0:j]
    ba2=s[j:len(s)]
    #print(ba,end=" ")
    #print(ba2,end=" ")
    #fr="".join(list(reversed(s[j:len(s)])))
    #print(fr)
    neu=ba2+ba
    strs.append(neu)
#print(strs)
if t in strs:
    print("Yes")
else:
    print("No")
    

Measured memory_bytes: 3316
#include <iostream>

using namespace std;

bool eight_div(int n){
  int div_n = 0;
  for(int i=1; i<=n; i++)
    if(n%i == 0)
      div_n++;
  return div_n==8;
}

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

  int i;
  int count = 0;
  for(i=1; i<=N; i+=2)
    if(eight_div(i))
      count++;

  cout << count << endl;
    
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int power(long long int n){
    int p=0;
    while(n%2==0){
        p++; n/=2; 
    }    
    return p;
}

int main(){
int i, n, min;
cin>>n;
vector <long long int> v(n, 0);
for(i=0; i<n; i++) {
    cin>>v[i];
    if(i==0) min=power(v[i]);
    else if(min>power(v[i])) min=power(v[i]);
}
    cout<<min;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b
//cout << fixed << setprecision();
//priority_queue<ll, vector<ll>, greater<ll>> q;
signed main(){
	ll hp,n; cin>>hp>>n;
	vl a(n),b(n);
	rep(i,0,n)cin>>a[i]>>b[i];
	vvl dp(n+10,vl(100000,MOD));
	dp[0][0]=0;
	rep(i,0,n){
		rep(j,0,100000){
			ll k=dp[i][j];
			if(j-a[i]>=0)chmin(k,dp[i+1][j-a[i]]+b[i]);
			dp[i+1][j]=k;
		}
	}
	ll ans=MOD;
	rep(i,hp,100000)chmin(ans,dp[n][i]);
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 795844
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int str,k = 0;
  string s;
  long long r = 0,g = 0,b = 0;
  vector<int> c;
  cin >> str >> s;
  for(auto s1 : s){
    switch(s1){
      case 'R':
        r++;
        c.push_back(0);
        break;
      case 'G':
        g++;
       c.push_back(1);
        break;
      case 'B':
        b++;
        c.push_back(2);
        break;
    	}
  }
  long long ans = r* g* b;
  for(int i = 0;i< str;++i){
    for(int j = i + 1;j< str;++j){
        	if(c[i] == c[j])continue;
		k = j + (j - i);
      if(k < str){
      	if(c[j] == c[k])continue;
      	if(c[k] == c[i])continue;
          ans--;
        }
    }
      }
 
  cout << ans << endl;
return 0;
}

Measured memory_bytes: 3600
#include <iostream>

using namespace std;

int main() {
    int N;
    char arare[100];
    bool yFlag = false;

    cin >> N;
    for (int i = 0; i <N ; i++) {
        cin >> arare[i];
        if (arare[i]=='Y'){
            yFlag = true;
        }
    }
    if (yFlag){
        cout << "Four";
    }
    else{
        cout << "Three";
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifdef _LOCAL
    #define test(x) cerr << #x << "=" << x << endl
#else
    #define test(x)
#endif

typedef long long LL;

const int N = 2e5+5;

int main(){
    #ifdef _LOCAL
        freopen("data.in", "r", stdin);
    #endif
    int n;
    scanf("%d", &n);
    int ans = 0;
    for(int i = 1; i <= n; i ++){
        int x = i;
        int odd = 0;
        while(x) x /= 10, odd ++;
        if(odd & 1) ans ++;
    }
    printf("%d\n", ans);
    #ifdef _LOCAL
        fprintf(stderr, "T: %d ms\n", int(1000.0 * clock() / CLOCKS_PER_SEC));
    #endif
    return 0;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]C - 白昼夢 / Daydream
            var s = Console.ReadLine();

            s = s.Replace("eraser", "");
            s = s.Replace("erase", "");
            s = s.Replace("dreamer", "");
            s = s.Replace("dream", "");

            if (s == "")
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}

Measured memory_bytes: 13140
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin>>s;
    
    int cnt=0;
    rep(i,s.size()) if(s[i]=='o')cnt++;
    
    cout1(700+cnt*100)
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int):
    print((1000 - N )% 1000)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

vector<ll> v;

void dfs(string s){
    ll lun=stoll(s);
    if(lun<=3234566667){
        v.push_back(lun);
        rep(i,10){
            int x=s.back()-'0';
            if(abs(x-i)>1) continue;
            char c=char(i+'0');
            dfs(s+c); 
        }
    }
}

int main(){
    int k;
    cin>>k;
    dfs("1");
    dfs("2");
    dfs("3");
    dfs("4");
    dfs("5");
    dfs("6");
    dfs("7");
    dfs("8");
    dfs("9");

    

    sort(all(v));
    cout<<v[k-1]<<endl;
} 


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

#ifdef ENABLE_DEBUG
#define DEBUG(a) cerr<<#a<<"="<<endl
#define DEBUG_ARRAY(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define DEBUG(a) 
#define DEBUG_ARRAY(a,n) 
#endif
#define P(a,b) make_pair(a,b)
#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> P;
typedef pair<ll,P> PP;
typedef vector<ll> vll;

const ll INF=(1<<50);



void solve(long long N, std::vector<long long> L){
    sort(L.begin(),L.end());
    ll ans=0;
    for(long i = L.size()-2; i >= 0; i-=2)
    {
        ans+=L[i];
    }
    cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> L(2*N);
    for(int i = 0 ; i < 2*N ; i++){
        scanf("%lld",&L[i]);
    }
    solve(N, std::move(L));
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define AC ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define for0 for(i=0;i<n;i++) cin>>a[i];
#define for1 for(i=1;i<=n;i++) cin>>a[i];
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define vpp vector< pair <ll,ll> > vp;
#define sortvecp(v) sort(v.begin(), v.end(), sortbysec);
#define map1 map<ll,ll> mapy;
#define mod 998244353
#define MAXN 998244353
#define INF 1e18
using namespace std;
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.F<b.F);
}
string a,b,c;
ll dp[210][210][210];
int main(){
    //memset(dp,-1,sizeof dp);
    ll t,n,i,j,k;
    cin>>k;
    string s,s1;
    cin>>s;
    if(s.size()<=k) cout<<s;
    else{
        for(i=0;i<k;i++){
            s1+=s[i];
        }
        s1+="...";
        cout<<s1;
    }
 }


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

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

using namespace std;
using lint=long long;

int main(){
	int n; scanf("%d",&n);
	vector<int> a(n),b(n),c(n);
	rep(i,n) scanf("%d",&a[i]);
	rep(i,n) scanf("%d",&b[i]);
	rep(i,n) scanf("%d",&c[i]);

	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	sort(c.begin(),c.end());

	vector<lint> dp1(n+1),dp2(n);
	rep(i,n){
		dp1[i+1]=dp1[i]+(lower_bound(a.begin(),a.end(),b[i])-a.begin());
	}
	rep(i,n){
		dp2[i]=dp1[lower_bound(b.begin(),b.end(),c[i])-b.begin()];
	}
	cout<<accumulate(dp2.begin(),dp2.end(),0LL)<<'\n';

	return 0;
}


Measured memory_bytes: 2944
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <stdio.h>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);++i)
#define urep(i,a,n) for(ll i = (a);i>=(n);--i)
#define all(x) (x).begin(),(x).end()
#define INF 1e18
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N,M,X,Y,A,B,C,Q,K,R,W,H,P,L;
string S,T;
ll ans;
ll x[101010];
ll y[101010];
ll a[101010];
ll b[101010];
ll c[101010];
ll t[101010];
ll p[101010];
ll n[101010];
ll l[101010];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
struct Edge{
	ll to,cost;
	 Edge(ll to, ll cost) : to(to), cost(cost) {}
};
typedef vector<vector<Edge> > AdjList;
AdjList graph;
vector<ll> dist;
bool flag[100];
vector<ll> Prime{2,3,5,7,11,13,17,19,23,29,31};

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
	vector<ll> size;
    UnionFind(ll N) : par(N),size(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++) par[i] = i;
		for(ll i = 0; i < N; i++) size[i] = 1;
    }

    ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
	ll GetSize(ll x){
		return size[root(x)];
	}

    void unite(ll x, ll y) { // xとyの木を併合
        ll rx = root(x); //xの根をrx
        ll ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
		size[ry]+=size[rx];

    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};

int main() {
	cin>>N>>M;
	vector<ll> tmp(M+1);
	UnionFind UF(N);
	rep(i,0,M){
		cin>>a[i]>>b[i];
		a[i]--,b[i]--;
	}
	tmp[M]=(N*N-N)/2;
	urep(i,M-1,0){
		if(!UF.same(a[i],b[i])){
			tmp[i]=tmp[i+1]-(UF.GetSize(a[i]))*(UF.GetSize(b[i]));
			UF.unite(a[i],b[i]);
		}else{
			tmp[i]=tmp[i+1];
		}
	}
	rep(i,1,M+1){
		cout<<tmp[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 7808
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

class Main {
	static class GreatestCommonDivisor {
		public void greatestcommondivisor (InputReader ir) {
			
			//２つの自然数入力
			int x = ir.nextInt();
			int y = ir.nextInt();
			
			StringBuilder sb = new StringBuilder ();		
			
			if ( x == y) sb.append(x); 
			else if (x > y) {
				int n = x % y;
				sb.append(Gcd(y,n));
			} else {
				int n = y % x;
				sb.append(Gcd(x,n));
			}
			
			System.out.println(sb);
		}
		
		//最大公約数を求める
		static int Gcd(int x, int y) {
			
			int n = Math.min(x, y);
			
			for (int i = n; i >= 1; i--) 
				if (x % i == 0 && y % i == 0) return i;
			
			return 1;
		}
		
	}
		
	static class InputReader {
		BufferedReader br;
		StringTokenizer st;
		
		public String nextString() {
			
			 while (!st.hasMoreTokens()) {
	                try {
	                    st = new StringTokenizer(br.readLine(), " ");
	                } catch (IOException e) {
	                    throw new InputMismatchException();
	                }
	            }
			return st.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(nextString());
		}
					
		public InputReader (InputStream inputStream) {
			br = new BufferedReader (new InputStreamReader (inputStream));
			st = new StringTokenizer ("");
		}
		
	}
	
	public static void main (String[] args) {
		InputStream inputStream = System.in;
		InputReader in = new InputReader (inputStream);
		GreatestCommonDivisor obj = new GreatestCommonDivisor ();
		obj.greatestcommondivisor (in);
	}
	
}



Measured memory_bytes: 24596
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}



///////////////////////////




int main() {

	ll N, K, R, S, P;
	cin >> N >> K >> R >> S >> P;
	string T;
	cin >> T;

	ll score[MAX][3] = {};
	repn(i, N) {
		if (T[i - 1] == 'r') { score[i][0] = P; }
		if (T[i - 1] == 'p') { score[i][1] = S; }
		if (T[i - 1] == 's') { score[i][2] = R; }
	}

	ll dp[MAX][3] = {};

	repn(i, N) {
		rep(j, 3) {
			if (i < K) { dp[i][j] = score[i][j]; }
			else {
				dp[i][j] = max(dp[i - K][(j + 1) % 3] + score[i][j], dp[i - K][(j + 2) % 3] + score[i][j]);
			}

			//cout << i << j << dp[i][j] << endl;
		}
		
	}

	ll ans = 0;

	for (int i = N - K + 1; i <= N; i++) {
		ans += max(dp[i][0], max(dp[i][1], dp[i][2]));
	}

	cout << ans;
		
	system("PAUSE");

}


Measured memory_bytes: 47608
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on

void main()
{
    long N, M;
    scan(N, M);
    auto X = new long[](M);
    auto Y = new long[](M);
    auto Z = new long[](M);
    foreach (i; 0 .. M)
        scan(X[i], Y[i], Z[i]);

    auto uf = UnionFind(N);
    foreach (i; 0 .. M)
        uf.unite(X[i] - 1, Y[i] - 1);
    uf.length.writeln();
}

struct UnionFind
{
    alias T = long;
    T[] rank, parent, sizes;
    long length;
    this(T n)
    {
        rank = new T[](n);
        sizes = new T[](n);
        sizes[] = 1;
        parent = iota!T(n).array();
        length = n;
    }

    T find(T x)
    {
        return (this.parent[x] == x) ? x : (this.parent[x] = this.find(this.parent[x]));
    }

    void unite(T x, T y)
    {
        T rx = this.find(x), ry = this.find(y);
        if (rx == ry)
            return;
        length--;
        this.sizes[rx] = this.sizes[ry] = this.sizes[rx] + this.sizes[ry];
        if (this.rank[rx] == this.rank[ry])
            this.parent[rx] = ry, this.rank[ry]++;
        else if (this.rank[rx] < this.rank[ry])
            this.parent[rx] = ry;
        else
            this.parent[ry] = rx;
    }

    T size(T x)
    {
        return this.sizes[this.find(x)];
    }
}


Measured memory_bytes: 15088
package main

import (
   "fmt"
)

func solution(n int, a [2][]int) int {
   out := -1 << 31
   for k := n - 1; k >= 0; k-- {
        i := 0
        sum := 0
        for j := 0; j < n; j++ {
                sum += a[i][j]
                if k == j {
                        i++
                        sum += a[i][j]
                }
        }
        out = max(out, sum)
   }
   return out
}

func max(x, y int) int {
   if x > y {
        return x
   }
   return y
}

func main() {
   var n int
   fmt.Scan(&n)
   a := [2][]int{}
   for i := range a {
        a[i] = make([]int, n)
        for j := range a[i] {
                fmt.Scan(&a[i][j])
        }
   }
   fmt.Println(solution(n, a))
}

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

using namespace std;

#define int long long
#define FR first
#define SC second
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)

typedef pair<int, int> P;

const int inf = 1LL << 55;

#define MAX_H 22
#define MAX_W 22
int grundy[MAX_H][MAX_W][MAX_H][MAX_W]; // ????????????[u,d)&[l,r)

int H, W;
char board[MAX_H][MAX_W];

int calcGrundy(int u, int l, int d, int r)
{
  int& g = grundy[u][l][d][r];
  if(~g) return g;
  if(u >= d || l >= r) return g = 0;
  set<int> V;
  for(int i = u; i < d; i++) {
    for(int j = l; j < r; j++) {
      if(board[i][j] != 'X') {
	V.insert(calcGrundy(u, l, i, j) ^ calcGrundy(u, j+1, i, r)
		 ^ calcGrundy(i+1, l, d, j) ^ calcGrundy(i+1, j+1, d, r));
      }
    }
  }
  g = 0;
  while(V.count(g)) g++;
  return g;
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  cin >> H >> W;
  rep(i, H) rep(j, W) cin >> board[i][j];
  memset(grundy, -1, sizeof(grundy));
  cout << (calcGrundy(0, 0, H, W) ? "First" : "Second") << endl;
  return 0;
}

Measured memory_bytes: 5012
#include<stdio.h>
int main(void) {
	char a[100];
	int i;
	scanf("%s", a);
	for (i = 0; i < 3; i++) {
		if (a[i] == '7') {
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}


Measured memory_bytes: 1644
#include <stdio.h>
int main(){
    int a, b, c;
    int toDel;
    scanf("%d%d%d", &a, &b, &c);
    a-=b;
    if(a<0) a*=-1;
    c-=a;
    if(c<0){
        c=0;
    }
    printf("%d\n", c);
    return 0;
}


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

namespace Geometry{
    using namespace std;
    using ld=long double;
    using Point=complex<ld>;
    const ld PI=acos(-1);
    struct Line{
        Point a,b;
    };

    struct Circle{
        Point p;
        ld r;
    };
    const ld EPS=1e-8;
    inline bool EQ(Point a,Point b){return abs(a-b)<EPS;}
    ld dot(Point a,Point b){return real(a)*real(b)+imag(a)*imag(b);}
    ld cross(Point a,Point b){return real(a)*imag(b)-imag(a)*real(b);}

    const int CCW=1;
    const int CW=-1;
    const int BAC=2;
    const int ACB=-2;
    const int ABC=0;
    int ccw(Point a,Point b,Point c){
        b-=a,c-=a;
        if(cross(b,c)>EPS) return CCW; // counter clockwise
        if(cross(b,c)<-EPS) return CW; //clockwise
        if(dot(b,c)<-EPS) return BAC; //b-a-c
        if(abs(b)<abs(c)) return ACB; //a-c-b
        return ABC; //a-b-c (abs(b)>abs(c))
    }
    ld dist_lp(Line l,Point p){
        Point x=l.b-l.a;
        Point y=p-l.a;
        return abs(cross(x,y))/abs(x);
    }
    ld dist_sp(Line l,Point p){
        if(dot(p-l.a,l.b-l.a)<EPS) return abs(p-l.a);
        if(dot(p-l.b,l.a-l.b)<EPS) return abs(p-l.b);
        return dist_lp(l,p);
    }
    bool isis_ss(Line x,Line y){
        return ccw(x.a,x.b,y.a)*ccw(x.a,x.b,y.b)<=0 && ccw(y.a,y.b,x.a)*ccw(y.a,y.b,x.b)<=0;
    }
    ld dist_ss(Line x,Line y){
        if(isis_ss(x,y)) return 0;
        ld a=min(dist_sp(x,y.a),dist_sp(x,y.b));
        ld b=min(dist_sp(y,x.a),dist_sp(y,x.b));
        return min(a,b);
    }
}

using namespace Geometry;

ld solve(int n,int m,int l){
    vector<array<Line,5>> stars(n);
    for(int i=0;i<n;i++){
        ld x,y,a,r;
        cin>>x>>y>>a>>r;
        ld theta=(a+90.)/180.*PI;
        ld delta=ld(72)/180.*PI;
        for(int j=0;j<5;j++){
            Point p0={x+r*cos(theta+j*delta),y+r*sin(theta+j*delta)};
            Point p1={x+r*cos(theta+(j+2)*delta),y+r*sin(theta+(j+2)*delta)};
            stars[i][j]=Line{p0,p1};
        }
    }
    const ld INF=1e18;
    vector<vector<ld>> dist(n,vector<ld>(n,INF));
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i==j){
                dist[i][j]=0;
                continue;
            }
            for(int ki=0;ki<5;ki++){
                for(int kj=0;kj<5;kj++){
                    dist[i][j]=min(dist[i][j],dist_ss(stars[i][ki],stars[j][kj]));
                }
            }
        }
    }
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
            }
        }
    }
    return dist[m][l];
}
int main(){
    int n,m,l;
    cout<<setprecision(10)<<fixed;
    while(cin>>n>>m>>l,n){
        m--,l--;
        cout<<solve(n,m,l)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2>
bool chmin(T1 &l, const T2 &r);
template <class T1, class T2>
bool chmax(T1 &l, const T2 &r);
#define int long long int
vector<int> cnt[26];
void solve(std::string s, std::string t)
{
  rep(i, s.size()) cnt[s[i] - 'a'].push_back(i);
  rep(i, t.size()) if (cnt[t[i] - 'a'].size() == 0)
  {
    cout << -1 << endl;
    return;
  }
  int pos = 0;
  int ans = 0;
  rep(i, t.size())
  {
    int c = t[i] - 'a';
    auto it = std::lower_bound(cnt[c].begin(), cnt[c].end(), pos);
    if (it == cnt[c].end())
    {
      it = std::lower_bound(cnt[c].begin(), cnt[c].end(), 0);
      ans++;
    }
    pos = *it + 1;
  }
  cout << pos + ans * s.size() << endl;
}

signed main()
{
  std::string s;
  std::cin >> s;
  std::string t;
  std::cin >> t;
  solve(s, t);
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2>
bool chmin(T1 &l, const T2 &r)
{
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2>
bool chmax(T1 &l, const T2 &r)
{
  return (l < r) ? (l = r, true) : false;
}


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

int main(){
    long long int n,a[5];
    cin >> n;
    for(int i=0;i<5;i++){
        cin >> a[i];
    }
    long long int min=1145141919810893;
    int minnum=0;
    for(int i=0;i<5;i++){
        if(min>a[i]){
            min=a[i];
            minnum=i;
        }
    }
    long long int tempans=n/min;
    if(n%min!=0)tempans++;
    cout << tempans+4 << endl;



    return 0;
}

Measured memory_bytes: 256
n, k = gets.chomp.split(" ").map(&:to_i)
h = gets.chomp.split(" ").map(&:to_i)
dp = Array.new(n,Float::INFINITY)
dp[0] = 0
# p dp
0.upto (n-1) do |i|
    if i - k < 0
    chmin = (h[i] - h[[i-k,0].max]).abs
    else
        chmin = (h[i] - h[i-k]).abs + dp[i-k] 
    end
    # p i - k
    # p h[i] - h[[i-k,0].max]
    # p dp
    if i >= 2
        # p [i-k,1].max
        # p i-1
        ([i-k,1].max).upto (i-1) do |j|
            #p (dp[j]+ (h[i] - h[j]).abs).abs
            chmin = [chmin,(dp[j]+ (h[i] - h[j]).abs).abs].min
        end
    end
    dp[i] = chmin
    # puts "iiiiiiiiiiii"
  
end
puts dp.pop

Measured memory_bytes: 21704
l0 = gets.split(" ").map!{|i| i.to_i}
l1 = gets.split(" ").map!{|i| i.to_i}
l2 = gets.split(" ").map!{|i| i.to_i}

b1 = l0[0]; b2 = l1[0]; b3 = l2[0]
a1 = 0; a2 = l0[1]-b1; a3 = l0[2]-b1

if (l0[0]==a1+b1) && (l0[1]==a2+b1) && (l0[2]==a3+b1) && (l1[0]==a1+b2) && (l1[1]==a2+b2) && (l1[2]==a3+b2) && (l2[0]==a1+b3) && (l2[1]==a2+b3) && (l2[2]==a3+b3) then
  puts "Yes"
else
  puts "No"
end


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

using namespace std;

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

	int X{};
	int Y{};
	cin >> X >> Y;
	cout << X + (Y / 2) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  string s;cin>>s;
  vi v(26,0);
  int n=s.size();
  rep(i,n){
    v[s[i]-'a']++;
  }
  string ans="yes";
  rep(i,26){
    if(v[i]>1)ans="no";
  }
  cout(ans);
  
  return 0;
}

Measured memory_bytes: 256
input()
card = [int(i) for i in input().split(" ")]
card.sort(reverse = True)

alice = [card[i] for i in range(len(card)) if i % 2 == 0]
bob = [card[i] for i in range(len(card)) if i % 2 == 1]

print(sum(alice) - sum(bob))

Measured memory_bytes: 3060
sx, sy, tx, ty = map(int, input().split())
dx, dy = tx-sx, ty-sy
path = 'U'*dy+'R'*dx+'D'*dy+'L'*(dx+1)+'U'*(dy+1)+'R'*(dx+1)+'D'+'R'+'D'*(dy+1)+'L'*(dx+1)+'U'

print(path)


Measured memory_bytes: 38384
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<int> vec;

void solve(){
	int n; cin >> n;
	ld ans = 0;
	rep(i, n) {
		int a; cin >> a;
		ans += (ld)1 / a;
	}
	cout << 1 / ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(6);
	//init();
	solve();
	stop
		return 0;
}


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

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    if(k < a + b)
        cout << min(k, a) << endl;
    else
        cout << -k + a + a + b << endl;
    return 0;
}


Measured memory_bytes: 3676
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <list>
#include <bitset>
#include <vector>
using namespace std;

#define I64d_OJ

//#ifdef I64d_OJ
//#define LL __int64
//#endif // I64d_OJ
#ifdef I64d_OJ
#define LL long long
#endif // I64d_OJ

typedef unsigned LL ULL;
typedef unsigned uint;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;
typedef vector<int> vi;

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

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define ls rt<<1
#define rs rt<<1|1
#define MID(a,b) (((LL)(a)+(LL)(b))>>1)
#define absx(a) ((a)<0?-(a):(a))
#define MK(a,b) make_pair(a,b)
#define PB(a) push_back(a)
#define lowbit(x) ((x)&-(x))

#define lc c[x][0]
#define rc c[x][1]

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

const double pi=(double)acos(-1.0);
const double eps=(double)1e-8;
const int INF = (int) 0x3f3f3f3f;
const int MOD = (int) 1e9+7;
const int MAXN =(int) 5e5+10;
const int MAXM = (int) 3e6+10;

///--------------------START-------------------------
LL N,K;

void work(){
    scanf("%lld%lld",&N,&K);
    if(N>K){
        N -= K*(N/K);
    }
    printf("%lld\n",min(N,K-N));
}

///--------------------END-------------------------
int main(){
#ifdef NNever
//freopen("data.in","r",stdin);
///freopen("out.txt","w",stdout);
#endif // NNever
    work();
    return 0;
}






Measured memory_bytes: 256
#include <iostream>
#define ll long long
using namespace std;

	string s;
	ll k;
	int x[100];
int main(){
	cin >>s;
  	cin >>k;
	
  	for(int i=0;i<k;i++){
    	if(s.at(i)!='1'){
        	cout <<s.at(i) <<endl;
          	return 0;
        }
    }
  
  	cout <<1 <<endl;
  
	return 0;
}

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

int main(){
  string s;cin >> s;
  int suma=0;
  if(s.at(0)==s.at(1)){
    if(s.at(2)==s.at(3) && s.at(0)!=s.at(2)){
      suma++;
    }
  }
  else if(s.at(0)==s.at(2)){
    if(s.at(1)==s.at(3) && s.at(0)!=s.at(1)){
      suma++;
    }
  }
  else if(s.at(0)==s.at(3) && s.at(0)!=s.at(1)){
    if(s.at(1)==s.at(2) && s.at(0)){
      suma++;
    }
  }
  if(suma!=0) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define BTC_RATE 380000.0

int main(){
  int n;
  cin >> n;
  
  pair<long double, string> p;
  long double answer = 0;
  
  for(int i = 0; i < n; i++){
    cin >> p.first >> p.second;
    if(p.second == "JPY")
      answer += p.first;
    else
      answer += p.first * BTC_RATE;
  }
  cout << answer << endl;

}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    long A, B;

    scanf("%ld %ld", &A, &B);

    for (int i=1; i <= B; i++) {
        if ((A * i) % B == 0) {
            printf("%ld", A * i);
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stack>
    
int main(){
    std::stack<u_int> train;
    u_int num;
    while(std::cin >> num){
        if(num == 0){
            std::cout << train.top() << std::endl;
            train.pop();
        }else{
            train.push(num);
        }
    }
    return 0;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
P a[100010];

int main() {
	int n;
	cin >> n;
	rep(i, n) {
		int population;
		cin >> population;
		a[i] = make_pair(population, i+1);
	}
	sort(a, a+n);
	rep(i, n) {
		cout << a[i].second << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1536
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := intScanner()
	a := intSliceScanner(n)
	mp := make(map[int]int)
	s := 0
	for i := 0; i < n; i++ {
		s += a[i]
		mp[a[i]]++
	}
	q := intScanner()
	for i := 0; i < q; i++ {
		b, c := intScanner(), intScanner()
		d := c - b
		s += d * mp[b]
		mp[c] += mp[b]
		delete(mp, b)
		fmt.Println(s)
	}
}


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

#define int long long

signed main(){
    string big , small;
    cin >> big >> small;
    vector <int> ind[50];
    
    for(int i = 0; i < big.length(); i++){
                     ind[big[i] - 96].push_back(i);
    }
    
    int ans = 0 , pre = -1 , cur;
    vector <int>::iterator it;
    int lim = (int)big.size();
    for(int i = 0; i < small.length(); i++){
                 it = upper_bound(ind[small[i] - 96].begin() , ind[small[i] - 96].end() , pre);
                 if(it != ind[small[i]-96].end()){
                     ans += (*it - pre);
                     pre = *it;
                     continue;
                 }
                 it = upper_bound(ind[small[i] - 96].begin() , ind[small[i] - 96].end() , -1);
                 if(it == ind[small[i] - 96].end()){
                     cout << "-1\n"; return 0;
                 }
                 ans += (lim - pre + *it);
                 pre = *it;
    }
    cout << ans << '\n';
}

Measured memory_bytes: 1724
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  int n;
  cin>>n;
  ll a[n],s[n+1];
  s[0]=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    s[i+1]=a[i]+s[i];
  }
  sort(s,s+n+1);
  ll b=s[0],c=0,d=1;
  for(int i=1;i<=n;i++){
    if(b==s[i])
      d++;
    else{
      c+=d*(d-1)/2;
      d=1;
      b=s[i];
    }
  }
  c+=d*(d-1)/2;
  cout<<c;
}
    


Measured memory_bytes: 3328
#include <iostream>
#include <queue>
#include <cstring>
using namespace std;

const int MAX = 30;
typedef pair<int,int> P;

int H,W;
int dist[MAX+1][MAX+1];
bool wall[MAX+1][MAX+1][4];
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};

int bfs(){
  queue<P> Que;
  Que.push(P(0,0));

  memset(dist,0,sizeof(dist));
  dist[0][0] = 1;
  
  while(!Que.empty()){
    P p = Que.front(); Que.pop(); 
    int y = p.first, x = p.second;

    for(int i = 0 ; i < 4 ; i++){
      int nx = x + dx[i];
      int ny = y + dy[i];
 
      if(0 <= nx && nx < W && 0 <= ny && ny < H && 
	 !wall[y][x][i] && !dist[ny][nx]){
	dist[ny][nx] = dist[y][x] + 1;
	Que.push(P(ny,nx));
      }
    }
  }

  return dist[H-1][W-1];
}

int main(){
  while(cin >> W >> H , W | H){
    memset(wall,false,sizeof(wall));

    int t;
    for(int i = 0 ; i < H ; i++){
      for(int j = 0 ; j < W - 1 ; j++){
	cin >> t;      
	wall[i][j][1] = wall[i][j+1][3] = t;
      }
      if(i < H-1){
	for(int j = 0 ; j < W ; j++){
	  cin >> t;
	  wall[i][j][2] = wall[i+1][j][0] = t;
	}
      }
    }
    
    cout << bfs() << endl;
  }

  return 0;
}

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



int main() {
    int n;
    cin >> n;
    
    vector<int> x(n);
    rep(i,n) {
        cin >> x[i];
    }
    
    int m = 1000010;
    for(int i = 1; i <= 100; i++) {
        int sum = 0;
        rep(j,n) {
            sum += abs(i-x[j]) * abs(i-x[j]);
        }
        m = min(sum,m);
    }
    
    cout << m << endl;
    
    
    return 0;
}




Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<queue>
#include<bitset>
#include<complex>
using namespace std;
template<typename __T>
inline void read(__T &x)
{
    x=0;
    int f=1;char c=getchar();
    while(!isdigit(c)){if(c=='-')	f=-1;c=getchar();}
    while(isdigit(c))	{x=x*10+c-'0';c=getchar();}
    x*=f;
}
int sb[1005];
int main()
{
	for(int i=1;i<=999;i++)
		sb[i]=sb[i-1]+i;
	int a,b;
	read(a);
	read(b);
	int gg=b-a;
	cout<<sb[gg]-b<<endl;
	return 0;
}

Measured memory_bytes: 256
x, k, d = map(int, input().split())
x = abs(x)
if x > k*d:
    print(x-k*d)
else:
    p = x//d
    c = k-p
    if p == 0 or p==1:
          for i in range(1,k+1):
            p2 = x-i*d
            c = k-i
            if p2 <= 0:
                if c%2 != 0:
                    print(abs(d+p2))
                    break
                elif c%2 == 0:
                    print(abs(p2))
                    break
    elif (c%2 == 0):
        print(abs(x-p*d))
    else:
        print(abs(d-abs(x-p*d)))

Measured memory_bytes: 9224
#include <stdio.h>

int sum(int number) {
  if(number < 10) {
    return number;
  } else {
    return number % 10 + sum(number / 10);
  }
}

int main() {
  int number_n, sum_of_number, i, bottom, top;
  long long int answer = 0;
  scanf("%d %d %d", &number_n, &bottom, &top);
  for(i = 1; i <= number_n; i++) {
    sum_of_number = sum(i);
    if(bottom <= sum_of_number && sum_of_number <= top) answer += i;
  }
  printf("%lld\n", answer);
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

int main(void)
{
char buf,*p;

scanf("%c", &buf);


  printf("%c", buf+1);
return 0;
}


Measured memory_bytes: 128