akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
    #include <filesystem>
    namespace fs = std::filesystem;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
static mt19937 _g(time(nullptr));
 
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int T;
void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path __p = __FILE__;
        fs::path __input, __output;
        __input = __output = __p.parent_path();
        __input += string("/input/") + string(__p.stem()) + string(".txt");
        __output += string("/output/") + string(__p.stem()) + string(".txt");
        freopen(__input.c_str(), "r", stdin);
        freopen(__output.c_str(), "w", stdout);
    #endif
    cin >> T;
}

ll __gcd(ll a,ll b){
    if(b==0) return a;
    else return __gcd(b,a%b);
}

int solve(){
    vector<string> ans;
    for (int i = 0; i < T; i++)
    {
        ll a,b,c,d;
        cin >> a >> b >> c >> d;
        if(a<b || d<b) {ans.push_back("No"); continue;}
        else if(c>=b || b==c+1) {ans.push_back("Yes"); continue;}
        else{
            // d%=b;
            ll g=__gcd(b,d);
            a%=g;
            ll C=(a+b-g);
            DBG(C)
            if(C>c){ans.push_back("No"); continue;}
            else{ans.push_back("Yes"); continue;}
        }
    }

    for(auto a:ans) cout << a << "\n";
    return 0;
}   

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


Measured memory_bytes: 256
import math

a, b, c = [int(x) for x in input().split()]
theta = c/180*math.pi

S = a*b*math.sin(theta)/2
d = math.sqrt(a**2+b**2-2*a*b*math.cos(theta))
L =a+b+d
h = 2*S/a

print(f"{S:.6f}")
print(f"{L:.6f}")
print(f"{h:.6f}")


Measured memory_bytes: 5736
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

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

	string str;cin >> str;
	REP(i, str.size()){
		if(str[i] == '?')cout << 'D';
		else cout << str[i];
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 3784
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#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 ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

int main(void)
{
    cin.sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> Xs(N);
    REP(n, N) cin >> Xs[n];

    ll ans = 1e18;
    REP(p, 101) {
        ll sum = 0;
        for(auto x: Xs) sum += (x - p) * (x - p);
        ans = min(ans, sum);
    }
    cout << ans << endl;

    return 0;
}


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

string dp[80][80];
string field[80];
int n, m;

bool isIn(int x, int y){
    return 0 <= x && x < m && 0 <= y && y < n;
}

string nmax(string a, string b){
    if(a.size() != b.size()) return a.size() < b.size() ? b : a;
    else return a < b ? b : a;
}

int main(){
    while(cin >> n >> m, n+m){
        for(int i=0; i < m; i++) cin >> field[i];
        for(int i=0; i < 80; i++) for(int j=0; j < 80; j++) dp[i][j] = "";
        string ret;

        for(int i = m-1; 0 <= i; i--){
            for(int j = n-1; 0 <= j; j--){
                if('0' <= field[i][j] && field[i][j] <= '9'){
                    string a, b;
                    if(isIn(i+1, j)) a = dp[i+1][j];
                    if(isIn(i, j+1)) b = dp[i][j+1];
                    dp[i][j] = field[i][j] + nmax(a, b);
                }
            }
        }
        for(int i=0; i < m; i++){
            for(int j=0; j < n; j++){
                while(dp[i][j][0] == '0') dp[i][j] = dp[i][j].substr(1);
                ret = nmax(ret, dp[i][j]);
            }
        }
        cout << ret << endl;
    }
}

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

int main() {
    // 制約見て！！！デカかったらlong longにすること！
    int x;
    cin >> x;
    if(x == 2) {
        cout << x << endl;
        return 0;
    }
    while(true) {
        int sq = (int)::sqrt(x);
        for(int i = 2; i <= sq; i++) {
            if(x % i == 0) {
                break;
            }
            if(i == sq) {
                cout << x << endl;
                return 0;
            }
        }
        x++;
    }
}

Measured memory_bytes: 3644
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
def main():
    n=int(input())
    def cmb(n, r, mod):
        if ( r<0 or r>n ):
            return 0
        r = min(r, n-r)
        return g1[n] * g2[r] * g2[n-r] % mod
    mod = 10**9+7 #出力の制限
    g1 = [1, 1] # 元テーブル
    g2 = [1, 1] #逆元テーブル
    inverse = [0, 1] #逆元テーブル計算用テーブル
    for i in range( 2, n + 1 ):
        g1.append( ( g1[-1] * i ) % mod )
        inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
        g2.append( (g2[-1] * inverse[-1]) % mod )

    ki=[[] for _ in range(n)]
    for _ in range(n-1):
        a,b=map(int,input().split())
        a,b=a-1,b-1
        ki[a].append(b)
        ki[b].append(a)
    memo={} # memo[(p,v)]:p->vの部分木のサイズ、整数の書き方
    def dfs(p,v):
        if (p,v) in memo:return memo[(p,v)]
        size,pat=0,1
        tmps,tmpp=1,1
        deg=len(ki[v])
        for nv in ki[v]:
            if nv==p:continue
            si,pi=dfs(v,nv)
            size+=si
            tmps*=g2[si]
            tmps%=mod
            tmpp*=pi
            tmpp%=mod
        pat=(g1[size]*tmps*tmpp)%mod
        memo[(p,v)]=(size+1,pat)
        return (size+1,pat)
    ans=[0]*n
    def bfs(p,v,res):
        if p!=-1:memo[(v,p)]=res
        deg=len(ki[v])
        tmps,tmpp=1,1
        for i in range(deg):
            si,pi=memo[(v,ki[v][i])]
            tmps*=g2[si]
            tmpp*=pi
            tmps%=mod
            tmpp%=mod

        ans[v]=g1[n-1]*tmps*tmpp
        ans[v]%=mod

        dpl=[1]*(deg+1)
        dpr=[1]*(deg+1)
        tmp=1
        for i in range(deg):
            si,pi=memo[(v,ki[v][i])]
            tmp*=pi*g2[si]
            tmp%=mod
            dpl[i+1]=tmp
        tmp=1
        for i in range(deg-1,-1,-1):
            si,pi=memo[(v,ki[v][i])]
            tmp*=pi*g2[si]
            tmp%=mod
            dpr[i]=tmp
        for i in range(deg):
            nv=ki[v][i]
            if p==nv:continue
            bfs(v,nv,(n-memo[(v,nv)][0],(g1[n-1-memo[(v,nv)][0]]*dpl[i]*dpr[i+1])%mod))
    dfs(-1,0)
    #print(memo)
    bfs(-1,0,0)
    print(*ans,sep='\n')
    #print(memo)

if __name__=='__main__':
    main()


Measured memory_bytes: 164652
using System;
using System.Text.RegularExpressions;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using System.Numerics;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();

            if (s.Length == 2)
            {
                if (s[0] == s[1]) Console.WriteLine("1 2");
                else Console.WriteLine("-1 -1");
                return;
            }

            for (int i = 0; i < s.Length - 2; i++)
            {
                for (int c = 'a'; c <= 'z'; c++)
                {
                    var cnt = 0;
                    for (int j = 0; j < 3; j++)
                    {
                        if (s[i + j] == c) cnt++;
                    }
                    if (cnt >= 2)
                    {
                        Console.WriteLine(string.Format("{0} {1}", i + 1, i + 3));
                        return;
                    }
                }
            }

            Console.WriteLine("-1 -1");
        }
    }
}

Measured memory_bytes: 3032
#include <iostream>
using namespace std;
int main(){
	while(1){
		int w;
		cin>>w;
		if(w==-1) break;
		if(w<=10){
			cout<<4280-1150<<endl;
		}else if(w<=20&&w>=11){
			cout<<4280-1150-125*(w-10)<<endl;
		}else if(w<=30&&w>=21){
			cout<<4280-1150-125*10-140*(w-20)<<endl;
		}else if(w>=31){
			cout<<4280-1150-125*10-140*10-160*(w-30)<<endl;
		}
	}
}

Measured memory_bytes: 1160
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    token.parse().ok().unwrap()
}

fn main() {
    let a = input::<i64>();
    let b = input::<i64>();
    let c = input::<i64>();
    let d = input::<i64>();
    println!(
        "{}",
        if (a - c).abs() <= d || ((a - b).abs() <= d && (b - c).abs() <= d) {
            "Yes"
        } else {
            "No"
        }
    );
}


Measured memory_bytes: 4352
#define R(i,n) for(i=0;i<n;++i)
#define L(i,f,l) for(i=f;i<l;++i)
#define W(F) F(J,'J');F(O,'O')
#define X 1001
#define Y getchar()
#define Q(A,S) L(i,1,m){a=0;L(j,1,n){a+=I[i-1][j-1]==S;A[i][j]=A[i-1][j]+a;}}
int I[X][X],J[X][X],O[X][X];main(){int m,n,k,i,j,a,b;scanf("%d%d%d",&m,&n,&k);Y;R(i,m){R(j,n)I[i][j]=Y;Y;}n++;m++;W(Q);while(k-->0){scanf("%d%d%d%d",&a,&b,&i,&j);a--;b--;m=J[i][j]-J[i][b]-J[a][j]+J[a][b];n=O[i][j]-O[i][b]-O[a][j]+O[a][b];printf("%d %d %d\n",m,n,(i-a)*(j-b)-m-n);}}

Measured memory_bytes: 12296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll INF = 1LL << 60; //MAX 9223372036854775807

ll ans = INF;

int main()
{
ll n , m ;
cin >> n >> m ;
ll k  ;
cin >> k  ;
vector<ll> a(n);
rep(i, n){
  cin >> a[i];
}
vector<ll> b(m);
rep(i, m){
  cin >> b[i];
}
vector<ll> sum;
sum.push_back(0);
rep(i, n)
{
  sum.push_back(a[i] + sum[i]);
}
vector<ll> sum1;
sum1.push_back(0);
rep(i, m)
{
  sum1.push_back(b[i] + sum1[i]);
}
ll itr=-1,itr1=-1;
rep(i,n+1)if(sum[i]<=k)itr++;
rep(i,m+1)if(sum1[i]+sum[itr]<=k)itr1++;
ans=itr+itr1;
for(ll i=itr1+1;i<sum1.size();i++){
  while(sum1[i]+sum[itr]>k){
    itr--;
    if(itr<0)break;
  }
  if(itr>=0)ans=max(ans,i+itr);
  if(itr<0)break;
}

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

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

typedef long long ll;

const long double PI = (acos(-1));

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

  string s;
  cin >> s;

  string ans = "Yes";
  for (int i = 0; i < s.size(); i++){
    if ((i % 2 == 1 && s.at(i) == 'R') || (i % 2 == 0 && s.at(i) == 'L')){
      ans = "No";
      break;
    }
  }

  cout << ans << endl;

  return 0;
}

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

typedef long long ll;
#define int         ll
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<pii> vpii;
typedef vector<long long> vll;
typedef vector<vll> vlll;

const int           mod = 1e9 + 7;
#define pb          push_back
#define test        int t; cin >> t; while(t--)
#define debug1(x)    cout << '>' << #x << ':' << x << "\n";
#define endl        '\n'
#define off         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define max(a,b)   (a>b?a:b)
#define min(a,b)   (a<b?a:b)


template <typename Arg1>
void pr(Arg1&& arg1) {cout << arg1 << endl;}
template <typename Arg1, typename... Args>
void pr(Arg1&& arg1, Args&&... args)
{
  cout << arg1 << " ";
  pr(args...);
}

template <typename Arg1> void rd(Arg1& arg1) {cin >> arg1;}
template <typename Arg1, typename... Args>
void rd(Arg1& arg1, Args&... args)
{
  cin >> arg1;
  rd(args...);
}


template <typename T1, typename T2>
ostream& operator<< (ostream& out, const pair<T1, T2>& p) {
  out << p.first << " " << p.second;
  return out;
}

template <typename T>
ostream& operator<< (ostream& out, const vector<T>& v) {
  for (T i : v) {
    out << i<<" ";
  }
  return out;
}
#define debug(...) deb(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void deb(const char* name, Arg1&& arg1) {cout << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void deb(const char* names, Arg1&& arg1, Args&&... args)
{
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " = " << arg1;
  deb(comma, args...);
}





int32_t main() {

  off;
    
  int n;
  cin>>n;
  cout<<n*n*n;
  return 0;
}

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

#define FastRead  ios_base::sync_with_stdio(0);cin.tie(0);
#define endl      "\n"
#define pi        acos(-1.0)

typedef long long ll;
typedef long long unsigned llu;


int main()
{
    FastRead

    ll n,m;

    cin>>n>>m;

    cout<<((n*(n-1))/2)+((m*(m-1))/2);
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i<b; i++)
#define rep(i, n) FOR(i, 0, n)
#define rFOR(i, a, b) for(int i = a;i >= b; i--)
#define rrep(i, a) rFOR(i, a, 0)
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<char> vc;
typedef vector<vc> vvc;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ld PI = acos(-1);
const ll INF = 1e18;
struct edge{ll to, cost;};

template <typename T>
bool chmax(T &a, const T &b) {
    if (a < b) {
      a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmin(T &a, const T &b) {
    if (a > b) {
      a = b;
      return true;
    }
    return false;
}

//組み合わせを線形で
//参考:https://drken1215.hatenablog.com/entry/2018/06/08/210000

const int MXN = 3000001;//変更可
ll fac[MXN], inv[MXN], finv[MXN];

void COMinit(int M){
    fac[0] = fac[1] = 1;
    inv[1] = 1;
    finv[0] = finv[1] = 1;
    for(int i = 2; i < MXN; i++){
        fac[i] = fac[i-1] * i % M;
        inv[i] = M - M / i * inv[M%i] % M;
        finv[i] = finv[i-1] * inv[i] % M;
    }
}

ll COMBI(int N,int K,int M){
    if(N < K){
        return 0;
    }
    if(N < 0||K < 0){
        return 0;
    }
    return fac[N] * finv[N-K] % M * finv[K] % M;
}

ll PERMU(int N,int K,int M){
    if(N < K){
        return 0;
    }
    if(N < 0||K < 0){
        return 0;
    }
    return fac[N] * finv[N-K] % M;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    COMinit(MOD2);
    int N, K;
    cin >> N >> K;
    ll ans = 0;
    rep(i, K + 1){
        if((K - i) % 2 == 0){
            //cout << i << endl;
            ans += COMBI(N, i, MOD2) * COMBI(N - 1 + (3 * K - i) / 2, N - 1, MOD2) % MOD2;
            //cout << ans << endl;
        }
    }
    FOR(i, 2 * K + 1, 3 * K + 1){
        ans -= N * COMBI(3 * K - i + N - 2, N - 2, MOD2);
        ans %= MOD2;
        //cout << ans << endl;
    }
    cout << (ans % MOD2 + MOD2) % MOD2 << endl;
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/

Measured memory_bytes: 73952
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    // insert code here...
    string InputStr;
    cin>>InputStr;
    for(int i=0;i<(int)InputStr.size();i++){
        char ch = InputStr[i];
        if((i+1)%2==0&&(ch=='L'||ch=='U'||ch=='D')){
        }
        else if((i+1)%2!=0&&(ch=='R'||ch=='U'||ch=='D')){
        }else{
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Text;

namespace Aizu {
    public class OnlineJudge {
        static void Main() {
            var capacity = 8;
            var size = 0;
            var array = new int[capacity];
            var output = new StringBuilder();

            for (var i = int.Parse(Console.ReadLine()); i > 0; --i) {
                var query = Console.ReadLine().Split().Select(int.Parse).ToArray();
                switch (query[0]) {
                    case 0:
                        if (size == capacity) {
                            var oldArray = array;
                            array = new int[capacity <<= 1];
                            Array.Copy(oldArray, array, oldArray.Length);
                        }
                        array[size++] = query[1];
                        break;
                    case 1:
                        output.AppendLine(array[query[1]].ToString());
                        break;
                    case 2:
                        --size;
                        break;
                }

            }

            Console.Write(output.ToString());
        }
    }
}



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

struct YOKO_LINE {
  int height;
  int left;
  int right;
};

bool compare(const YOKO_LINE& left, const YOKO_LINE& right) {
    return left.height > right.height;
}

int main() {
  int n, m, a;
  while(1) {
    cin >> n >> m >> a;
    if(n+m+a == 0) return 0;

    YOKO_LINE yoko[m+1];
    YOKO_LINE temp;
    temp.height = -1;
    temp.left = -1;
    temp.right = -1;
    yoko[m] = temp;
    for(int i = 0; i < m; i++) {
      cin >> yoko[i].height >> yoko[i].left >> yoko[i].right;
    }
    sort(yoko, yoko + m, compare);

    for(int i = 0; i < m; i++) {
      if(yoko[i].left == a) {
        a = yoko[i].right;
        while(yoko[i].height == yoko[i+1].height) i++;
      }else if(yoko[i].right == a) {
        a = yoko[i].left;
        while(yoko[i].height == yoko[i+1].height) i++;
      }
    }
    cout << a << endl;
  }
}



Measured memory_bytes: 3112
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const ll MOD = 1e9 + 7;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")



int main() {
    string s; cin >> s;
    ll ans = 0;
    ll count = 0;
    ll pos = 0;

    for(int i = s.length()-1; i >= 1; i --){
        if(s[i-1] == 'B' && s[i] == 'C'){
            s[i-1] = 'D';
            s.erase(s.begin()+i);
        }
    }

    rep(i,s.length()){
        if(s[i] == 'A') count ++;
        else if(s[i] == 'D'){
            ans += count;
        }else{
            count = 0;
        }
    }

    cout << ans;


}

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

bool	CMP1(vector<int> A, vector<int> B) {
	if (A.at(1)==B.at(1))
		return (A.at(0)<=B.at(0));
	return (A.at(1)<=B.at(1));
}

int	main() {
	const long MOD=1000000007;
	int N;
	cin >>N;
	vector<vector<int>> C(N, vector<int> (3, 0));
	for (int i=0; i<N; i++) {
		C.at(i).at(0)=i;
		cin >>C.at(i).at(1);
	}
	sort(C.begin(), C.end(), CMP1);
	C.at(0).at(2)=-1;
	for (int i=1; i<N; i++) {
		if(C.at(i).at(1)==C.at(i-1).at(1))
			C.at(i).at(2)=C.at(i-1).at(0);
		else
			C.at(i).at(2)=-1;
	}
	sort(C.begin(), C.end());
	vector<long> S0(N, 0);
	S0.at(0)=1;
	for (int i=1; i<N; i++) {
		if (-1==C.at(i).at(2)) {
			S0.at(i)=S0.at(i-1);
		} else if (i-1==C.at(i).at(2)) {
			S0.at(i)=S0.at(i-1);
		} else {
			S0.at(i)=S0.at(i-1)+S0.at(C.at(i).at(2));
			S0.at(i) %=MOD;
		}
	}
	cout <<S0.at(N-1) <<endl;
	return 0;
}


Measured memory_bytes: 13184
#include<stdio.h>

int main(void) {
  int d,n,ans=1;
  scanf("%d %d",&d,&n);
  for(int i = 0; i < d; i++) {
    ans *= 100;
  }
  if(n < 100) {
    printf("%d",ans*n);
  }else{
    printf("%d",ans*101);
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
	string a, b, c;
	cin >> a;
	cin >> b;
	cin >> c;
	int num = 'A' - 'a';
	printf("%c%c%c\n", a[0] + num, b[0] + num, c[0] + num);

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>


const int MAX_N = 8;
int N;
int A, B, C;
int L[MAX_N];

int calc(int bit, int length) {
    int num = 0;
    int ltmp = 0;
    for (int i = 0; i < N; i++) {
        if (((bit >> i) & 1) == 1) {
            ltmp += L[i];
            num++;
        }
    }
    return abs(ltmp - length) + (num - 1) * 10;
}

int main(int argc, char **argv) {
    std::cin >> N >> A >> B >> C;
    for (int i = 0; i < N; i++) {
        std::cin >> L[i];
    }

    int BIT_MAX = (1 << N);
    int ret = 4000;

    for (int bitA = 1; bitA < BIT_MAX; bitA++) {
        for (int bitB = 1; bitB < BIT_MAX; bitB++) {
            for (int bitC = 1; bitC < BIT_MAX; bitC++) {
                if ((bitA + bitB + bitC) == (bitA ^ bitB ^ bitC)) {
                    int tmp = calc(bitA, A) + calc(bitB, B) + calc(bitC, C);
                    ret = std::min(ret, tmp);
                }
            }
        }
    }

    std::cout << ret << std::endl;
    
    return 0;

}

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

int main()
{
  int N, M;
  vector<int>num(205);
  int query;
  
  cin >> N >> M;
  Rep(i,2 * N)num[i] = i + 1;
  
  while(M--) {
    cin >> query;
    vector<int> t;
    if(query == 0) {
      Rep(i,N) {
	t.push_back(num[i]);
	t.push_back(num[N + i]);
      }
    }else {
      for(int i = query; i < 2 * N; i++) {
	t.push_back(num[i]);
      }
      Rep(i,query) {
	t.push_back(num[i]);
      }
    }
    num = t;
  }

  Rep(i,2 * N) {
    cout << num[i] << endl;
  }
  return 0;
}
	

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

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define mod 1000000007
#define endl "\n"
#define all(a) (a).begin(),(a).end()
#define lp(i,a,b) for(i=a;i<b;i++)
#define lpr(i,a,b) for(i=a;i>=b;i--)
#define F first
#define S second
#define pb push_back
#define mp make_pair

typedef long long int ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;

int main(){

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

  fast;
  int i,j,q,n,k,x,m,a,b,tc;
  cin>>n>>k>>x;
  tc=n;
  n=k;
  k=tc;

  tc=x;
  x=n;
  n=tc;
  cout<<n<<" "<<k<<" "<<x<<endl;

  
  return 0;
}  


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

//region Template
#include "ext/pb_ds/assoc_container.hpp"
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const int MOD = 1000000007;

using namespace std;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_multiset;

#define finish(x) cout << x; exit(0);
#define fastIO cin.tie(0); cin.sync_with_stdio(false);

void setIn(string s) { freopen(s.c_str(), "r", stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }

//const string USCAO_TAG = "mountains";
void usaco(const string& USACO_TAG) { setIn(USACO_TAG + ".in"); setOut(USACO_TAG + ".out"); }
void print() {}
template<typename T, typename... Args>
void print(T firstArg, Args... args) {
	#ifdef LOCAL
	cout << firstArg << "\t";
	print(args...);
	#endif
}
//endregion

/* Notes:
 * Farah </3
 */

const int MAXN = 3e2 + 6;
const ll INF = 2e18;

set<pair<int, int>> rs[MAXN];

ll dp[MAXN][MAXN][MAXN];

void add(ll &x, ll y)
{
	x += y;
	if(x >= MOD) x -= MOD;
}

int main() {
	#ifdef LOCAL
	setIn("in.txt");
	setOut("out.txt");
	#endif

	int n, m;
	cin >> n >> m;

	for(int i = 0; i < m; i++){
		int l, r, x;
		cin >> l >> r >> x;

		rs[r].insert({l, x});
	}


	ll ans = 0;

	dp[0][0][0] = 1;

	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= n; j++){
			for(int k = 0; k <= n; k++){
				int idx = max(i, max(j, k));
				int cnt = 0;

				for(auto x : rs[idx]){
					cnt = 0;
					if(i >= x.first && i != 0) cnt++;
					if(j >= x.first && j != 0) cnt++;
					if(k >= x.first && k != 0) cnt++;

					if(cnt != x.second){
						dp[i][j][k] = 0;
						//print(i, j, k, '\n');
					}

				}

				add(dp[idx + 1][j][k], dp[i][j][k]);
				add(dp[i][idx + 1][k], dp[i][j][k]);
				add(dp[i][j][idx + 1], dp[i][j][k]);
			}
		}
	}

	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= n; j++){
			add(ans, dp[i][n][j]);
			add(ans, dp[i][j][n]);
			add(ans, dp[n][i][j]);
		}
	}
	cout << ans << endl;
}


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

using namespace std;

#define sp(x) cout<<setprecision(x);
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define lint long long
#define FOR(i,a,b) for(lint i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define yes "Yes"
#define no "No"
#define divs 1000000007
#define dive 1000000009

typedef pair<int, int> P;

lint ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
	lint n, d; cin>>n>>d;
	vector<vector<lint> > v(n);
	REP(i,n){
		REP(j,d){
			lint in; cin>>in;
			v[i].push_back(in);
		}
	}
	int cnt = 0;
	int now = 0;
	REP(i,n-1){
		FOR(j,i+1,n){
			REP(k,d){
				now += abs(v[i][k]-v[j][k])*abs(v[i][k]-v[j][k]);
			}
			if((int)sqrt(now)*(int)sqrt(now)==now) cnt++;
			now = 0;
		}
	}
	cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a,b,c,count=3;
  cin >> a >> b >> c;
  if(a == b && a==c){
    cout << "1" << endl;
  } else{
    if(a == b){
      count--;
    }
    if(a == c){
      count--;
    }
    if(b==c){
      count--;
    }
    cout << count << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
ma = lambda : map(int,input().split())
ni = lambda : int(input())
import collections
n = ni()
x = list(ma())
x2 = sorted(x)
me1 = x2[n//2]
me2 = x2[n//2-1]
for nu in x:
    if nu<me1:
        print(me1)
    else:
        print(me2)


Measured memory_bytes: 25476
import Data.List
import Data.Char

main = interact $ unlines . map (show . how_many_island) . read' . lines
 where
  read' ("0 0":_) = []
  read' (wh:xs) = cs : read' xs'
   where
    [w,h] = map read (words wh)
    (is,xs') = splitAt h xs
    cs = map fst (filter ((=='1') . snd) atlas)
    atlas = zip [(x,y)| x<-[0..h-1], y<-[0..w-1]] (filter isDigit (concat is))

how_many_island [] = 0
how_many_island cs = 1 + how_many_island (explore cs)

explore [] = []
explore (c:cs) = advance [c] [] cs

advance ok ng []
 | any (`neighbor_of` ng) ok = advance ok [] ng
 | otherwise = ng
advance ok ng (c:cs)
 | c `neighbor_of` ok = advance (c:ok) ng cs
 | otherwise = advance ok (c:ng) cs

neighbor_of (x,y) cs = (not.null) (intersect neighbor cs)
 where neighbor = [(x',y') | x'<-[x-1..x+1], y'<-[y-1..y+1], (x',y') /= (x,y)]

Measured memory_bytes: 5440
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define x first
#define y second
#define pb push_back
#define pf push_front
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;
typedef pair<int, int> pi;
int dp[100005];
// dp[i]
// i日目
// の報酬?
void solve()
{
	int n, m;
	cin >> n >> m;

	priority_queue<pi> pq;
	priority_queue<pi, vector<pi>, greater<pi>> pless;
	rep(i, n)
	{
		int a, b;
		cin >> a >> b;
		pless.push(make_pair(a, b));
	}
	int ans = 0;
	FOR(i, 1, m + 1)
	{
		while (pless.top().first <= i&& pless.size()>0)
		{
			pi tp=pless.top();
			swap(tp.first,tp.second);
			pq.push(tp);
			pless.pop();
		}
		if (pq.size() > 0)
		{
			ans += pq.top().first;
			//cout<<pq.top().first<<" "<<pq.top().second<<endl;
			pq.pop();
		}
		//cout<<ans<<endl;
	}
	cout << ans << endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
}


Measured memory_bytes: 2548
main :: IO ()
main = do
  [x, y] <- map (read :: String -> Int) . words <$> getLine
  putStrLn $ solve x y


solve :: Int -> Int -> String
solve x y = if getGroup x == getGroup y
            then "Yes"
            else "No"
  where
    group1 = [1, 3, 5, 7, 8, 10, 12]
    group2 = [4, 6, 9, 11]
    group3 = [2]
    getGroup :: Int -> Int
    getGroup x
      | elem x group1 = 1
      | elem x group2 = 2
      | elem x group3 = 3
      | otherwise = 0


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

#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mod 1000000007
int val=0,ans=INT_MIN;
void dfs(int node,vector<vector<int>> &adj,vector<bool> &visited)
{
    visited[node]=true;
    val++;
    for(auto u:adj[node])
        if(!visited[u])
            dfs(u,adj,visited);
}
int main(){
	fast;
    int n,m;
    cin>>n>>m;
    vector<vector<int>> adj(n+1);
    vector<bool> visited(n+1,false);
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    for(int i=1;i<=n;i++)
    {
        val=0;
        if(!visited[i])
           dfs(i,adj,visited);
        ans=max(ans,val);
    }
    cout<<ans;
	return 0;
}


Measured memory_bytes: 23460
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 10;

char s[maxn];
int main()
{
    scanf("%s",s);
    int len=strlen(s);
    int t=s[len-1]-'0';
    if( t==2||t==5||t==4||t==7||t==9 ) printf("hon\n");
    else if( t==0||t==1||t==6||t==8 ) printf("pon\n");
    else if( t==3 ) printf("bon\n");
    return 0;
}


Measured memory_bytes: 3120
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_C
// Getting Started - Prime Numbers

#define SUBMIT

#include <utility>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <limits>
#include <numeric>
#include <set>
#include <cmath>

using namespace std;
using i64 = long long;

bool is_prime(int x) {
    if (x <= 1) return false;
    if (x <= 3) return true;
    if (x % 2 == 0 || x % 3 == 0) return false;

    for (int i = 5; i * i <= x; i+= 6) {
        if (x % i == 0 || x % (i + 2) == 0) return false;
    }

    return true;
}

int main() {
    int n;
    cin >> n;
    int x;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        cin >> x;
        if (is_prime(x)) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

// 日付クラス.
struct Date{
	int y, m, d;
	// コンストラクタで初期化
	Date(int y_, int m_, int d_){
		y = y_;
		m = m_;
		d = d_;
	}
	// 日付を1日進める. 1日進めて 1000年1月1日になるときだけ false を返す.
	bool inc(){
		if( m % 2 == 1 || y%3 == 0 ){ // 1ヶ月が20日あるとき
			if( d == 20 ){
				d = 1;
				if( m == 10 ){
					y++;
					m = 1;
				}else{
					m++;
				}
			}else{
				d++;
			}
		}else{ // 1ヶ月が19日あるとき
			if( d == 19 ){
				d = 1;
				if( m == 10 ){
					y++;
					m = 1;
				}else{
					m++;
				}
			}else{
				d++;
			}
		}
		return !( y == 1000 && m == 1 && d == 1 );
	}
};

int main(){
	int n;
	cin >> n;
	for(int i=0 ; i < n ; i++ ){
		int y , m , d;
		cin >> y >> m >> d;
		
		Date t(y,m,d);
		int ans = 1;
		while( t.inc() ) ans++;
		
		cout << ans << endl;
	}
}

Measured memory_bytes: 864
import numpy as np
import math
s = list(map(int, input().split()))
n = s[0]
m = s[1]
x = s[2]
book = []

for i in range(n):
    s = list(map(int, input().split()))
    book.append(s)
book=np.array(book)
ans=math.inf

for i in range(1<<n):

    skill = [0]*(m+1)
    for j in range(n):
        if i>>j & 1:
            for k,l in enumerate(book[j]):
                skill[k]+=l

    ok=True
    for j in range(1,m+1):
        if skill[j]<x :
            ok=False
            break
    if ok:
        ans=min(ans,skill[0])
if ans==math.inf:
    ans=-1
print(ans)

Measured memory_bytes: 27200
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, total;
  cin >> N;
  total = 0;
  for (int i = 0; i < N; i++)
  {
    int l, r;
    cin >> l >> r;
    r = r - l + 1;
    total += r;
  }
  cout << total << endl;
}

Measured memory_bytes: 3612
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

int main() {
    ll N;
    cin >> N;
    ll L[N];
    REP(i, 0, N) {
        cin >> L[i];
    }
    sort(L, L + N);
    ll sum = 0;
    REP(i, 0, N - 1) {
        sum += L[i];
    }
    if (sum > L[N - 1]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    int ans = 0;
    cin >> N >> K;
    REP(i,N){
        int h;
        cin >> h;
        if(h >= K) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ull  unsigned long long
#define ll long long int
#define ull unsigned long long 
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(),v.rend() //reverse
#define vl vector< long long>v(n);
#define mii unordered_map<ll,ll>
double pi = 2*acos(0.0);
//ll power(ll a,ll b){ ll res=1;while(b){if(b&1)res=res*a;b=b/2; a=(a*a); }return res;}

 int main()
 {
       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
       ll tst;
       tst=1;
       //cin>>tst;
    
       while(tst--)
       {
          ll n;
          cin>>n;ull sum=0;
          vl(n);long long int count[100011]={0};
          for(int i=0;i<n;i++)
          {
                          cin>>v[i];
                          sum+=v[i];
                          count[v[i]]++;
          }
          unsigned long long q;
          cin>>q;
          while(q--)
          {
             ll a,b;
             cin>>a>>b;
             sum-=count[a]*a;
             sum+=count[a]*b;
             count[b]+=count[a];
             count[a]=0;
             cout<<sum<<endl;
          }
        
        }
 }

Measured memory_bytes: 4760
#include<iostream>
using namespace std;
#define N 3

int c[N][N];


bool check(int ta,int tb) {
	int a[N];
	int b[N];
	a[0] = ta;
	b[0] = tb;

	a[1] = c[1][0] - b[0];
	a[2] = c[2][0] - b[0];
	b[1] = c[0][1] - a[0];
	b[2] = c[0][2] - a[0];

	if (a[1] < 0 || a[2] < 0 || b[1] < 0 || b[2] < 0) {
		return false;
	}
	else if (a[1] + b[1] == c[1][1] && a[2] + b[1] == c[2][1] && a[1] + b[2] == c[1][2] && a[2] + b[2] == c[2][2]) {
		return true;
	}
	else {
		return false;
	}



}


int main() {
	for (int i = 0; i<N; i++) {
		for (int j = 0; j<N; j++) {
			cin>>c[i][j];
		}
	}

	for (int k = 0; k <= c[0][0]; k++) {
		int tmpa = k;
		int tmpb = c[0][0] - k;
		if (check(tmpa, tmpb)) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (a * b % 2 == 0) {
            System.out.println("Even");
        } else {
            System.out.println("Odd");
        }
    }
}


Measured memory_bytes: 20820
import java.io.*;
import java.util.*;
import java.math.*;

 
 public class Main	{
   static class Pair implements Comparable<Pair>{
   int a;
   int b;
   public Pair(int x,int y){a=x;b=y;}
   public Pair(){}
   public int compareTo(Pair p){
	 return p.a - a;
   }



 }
static class TrieNode{
  TrieNode[]child;
  int w;
  boolean term;
  TrieNode(){
    child = new TrieNode[26];  
  }
}
  public static int gcd(int a,int b)
  {
    if(a<b)

      return gcd(b,a);
    if(b==0)
      return a;
    return gcd(b,a%b);
    
  }
  //static long ans = 0;
  static long mod = (long)(1e9+7);///998244353;
   
    public static void main(String[] args) throws Exception {
       new Thread(null, null, "Anshum Gupta", 99999999) {
            public void run() {
                try {
                    solve();
                } catch(Exception e) {
                    e.printStackTrace();
                    System.exit(1);
                }
            }
        }.start();
    }

static long pow(long x,long y){
    if(y == 0)return 1;
    if(y==1)return x;
    long a = pow(x,y/2);
    a = (a*a)%mod;
    if(y%2==0){
        return a;
    }
    return (a*x)%mod;
}

static long mxx;
static int mxN = (int)(1e6+5);
static long[]fact,inv_fact;
static long my_inv(long a) {
	return pow(a,mod-2);
}
static long bin(int a,int b) {
	if(b>a)return 0;
    return ((fact[a]*inv_fact[a-b])%mod * inv_fact[b])%mod;
}
static String str;
static int n,k;

 public static void solve() throws Exception {
   // solve the problem here
   MyScanner s = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out), true);
        int tc = 1;//s.nextInt();
        mxx = (long)(1e18+5);
       
        while(tc-->0){
        	long a = s.nextLong();
        	long b = s.nextLong();
        	a%=b;
    //    	if(a<0)a+=b;
        	out.println(Math.min(a, Math.abs(a-b)));
        }
        
           
        out.flush();
}
 
     
 
 
 
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
 
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
 
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
 
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt() { return Integer.parseInt(next()); }
        long nextLong() { return Long.parseLong(next()); }
        double nextDouble() { return Double.parseDouble(next()); }
         
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    //--------------------------------------------------------
}


Measured memory_bytes: 32944
using System;
using System.Linq;

class Procon {
  public Procon () { }
  static void Main (string[] agrs) {
    new Procon ().Do ();
  }

  Scanner cin;

  public void Do () {
    cin = new Scanner ();
    int H = cin.nextInt ();
    int W = cin.nextInt ();
    int[, ] c = new int[10, 10];

    for (int i = 0; i < 10; i++) {
      for (int j = 0; j < 10; j++) {
        c[i, j] = cin.nextInt ();
      }
    }

    int[, ] A = new int[H, W];
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        A[i, j] = cin.nextInt ();
      }
    }

    int[] DP = new int[10];
    for (int i = 0; i < 10; i++) {
      DP[i] = c[i, 1];
    }

    for (int j = 0; j < 10; j++) {
      for (int i = 0; i < 10; i++) {
        for (int k = 0; k < 10; k++) {
          int tmp = c[i, k] + DP[k];
          if (tmp < DP[i]) {
            DP[i] = tmp;
          }
        }
      }
    }

    int ret = 0;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (A[i, j] == -1) {
          continue;
        }
        ret += DP[A[i, j]];
      }
    }
    Console.WriteLine (ret);
  }
}

class Scanner {
  string[] s;
  int i;
  int max_i;

  public Scanner () {
    s = new string[0];
    max_i = 0;
    i = 0;
  }

  public string nextString () {
    if (i >= s.Length) {
      s = Console.ReadLine ().Split (' ');
      max_i = s.Length;
      i = 0;
      if (max_i == 0) {
        return "";
      }
      return s[i++];
    } else {
      return s[i++];
    }
  }

  public int nextInt () {
    return int.Parse (nextString ());
  }

  public long nextLong () {
    return long.Parse (nextString ());
  }

  public double nextDouble () {
    return double.Parse (nextString ());
  }

  public string[] arrayString () {
    return Console.ReadLine ().Split (' ');
  }

  public int[] arrayInt () {
    string[] str = Console.ReadLine ().Split (' ');
    int[] array = new int[str.Length];
    for (int i = 0; i < str.Length; i++) {
      array[i] = int.Parse (str[i]);
    }
    return array;
  }

  public long[] arrayLong () {
    string[] str = Console.ReadLine ().Split (' ');
    long[] array = new long[str.Length];
    for (int i = 0; i < str.Length; i++) {
      array[i] = long.Parse (str[i]);
    }
    return array;
  }

  public double[] arrayDouble () {
    string[] str = Console.ReadLine ().Split (' ');
    double[] array = new double[str.Length];
    for (int i = 0; i < str.Length; i++) {
      array[i] = double.Parse (str[i]);
    }
    return array;
  }
}

Measured memory_bytes: 13228
def fib(n):
    global Fib
    if n <= 1:
        return 1
    elif Fib[n] != -1:
        return Fib[n]
    else:
        return fib(n-1) + fib(n-2)

def fib_eff(n):
    global Fib
    Fib[0] = 1
    Fib[1] = 1
    for i in range(2, n+1):
        Fib[i] = Fib[i-1] + Fib[i-2]

n = int(input())
Fib = [-1] * 45
fib_eff(n)
print(Fib[n])


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

const int M = 3e5 + 10;
long long cnt[M];
int op[M];

int main()
{
	memset(cnt, 0, sizeof(cnt));
	int n, m;
	long long totl = 0;
	scanf("%d%d", &n, &m);
	for(int i=0; i<n; ++i)
		scanf("%d", op + i);
	for(int i=1; i<n; ++i) {
		int l = op[i-1], r = op[i];
		if(l > r) r += m;
		totl += r - l;
		if(r - l > 1) {
			++cnt[l+2];
			 cnt[r+1]-=(r-(l+2) +1)+1;
			 cnt[r+2]+=(r-(l+2)+1);
		}
	}
	for(int i=1; i<=2*m; ++i) {
		cnt[i] += cnt[i-1];
	}
	for(int i=1; i<=2*m; ++i) {
		cnt[i] += cnt[i-1];
	}
	long long ans = -1;
	for(int i=1; i<=m; ++i) {
		ans = max(cnt[i] + cnt[i+m], ans);
	}
	cout<<totl - ans<<endl;
	return 0;
}


Measured memory_bytes: 2944
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};



int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n;
    cin>>n;
    vector<int> a(n);
        rep(i,n) cin>>a.at(i);
    sort(all(a));
    int x=a[n-1];
    int sum=0;
    rep(i,n-1) sum +=a[i];
    x<sum?Yes:No;
}

Measured memory_bytes: 256