akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <list>
#include <iomanip>
#include <string>
#include <cctype>
#include <cstdio>


using namespace std;



int main() {
    string str, order, str2;
    string substr;
    int q;
    int a, b;
    cin >> str;
    cin >> q;
    for (int i = 0; i < q; i++) {
        cin >> order >> a >> b;
        if (order == "replace") {
            cin >> str2;
            str = str.substr(0, a) + str2 + str.substr(b + 1, str.size() - a - 1);
        }
        else if (order == "reverse") {
            substr = str.substr(a, b - a + 1);
            reverse(substr.begin(), substr.end());
            str = str.substr(0, a) + substr + str.substr(b + 1, str.size() - a - 1);
        }
        else if (order == "print") {
            cout << str.substr(a, b - a + 1) << endl;
        }
    }
}


Measured memory_bytes: 3184
# -*- coding: utf-8 -*-

"""
sample = []
for i in range(100):
    for j in range(100):
        sample.append(4*i + 7*j)

print(sample)
print("---")
print(set(sample))
"""

a = int(input())

sample = [0, 4, 7, 8, 11, 12, 14, 15, 16, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200]

if a in sample:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include <cstdlib>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include <assert.h>
#include<map>
#include<set>
#include<bitset>
#include <iomanip>
#include<stack>
#include <unordered_map>
#include<cmath>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
// #define pi acos(-1)
// #include<bits/stdc++.h>
typedef long long ll;
#define INF 0x7f7f7f7f //2139062143
#define INF1 0x3f3f3f3f //1061109567
#define INF2 2147483647
#define llINF 9223372036854775807
#define pi 3.14159265358979323846264338327950254
#define pb push_back
#define ll long long
#define debug cout << "debug\n";
#define STDIN freopen("in.txt","r",stdin); freopen("out.txt","w",stdout);//************************************
#define Quick ios::sync_with_stdio(false);cin.tie(NULL);
#define scai(x) scanf("%d", &x)
#define sca2i(x, y) scanf("%d %d", &x, &y)
#define scaf(x) scanf("%lf", &x)
#define sca2f(x, y) scanf("%lf %lf", &x, &y)
#define For(m,n) for (int i = m;  i < n; i++)
#define PII pair<int,int>
#define PLL pair<long, long>
#define ft first
#define sd second
#define pb push_back


const int maxn=333333,mod=1000000009;
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))

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

double qmi(double m, int k)
{
    double res = 1;
    double t = m;
    while (k)
    {
        if (k&1) res = res * t;
        t = t * t;
        k >>= 1;
    }
    return res;
}
 int main()
 {
    // STDIN

     ll n;
     cin >> n;
    //  cout << n << endl;
    ll sum = 100;
     for (int i = 1; i <= 5000; i++)
     {
        //  cout << i << " " <<(ll)100*qmi(1.01,i) << endl;
        sum *=1.01;
         if (sum >= n)
         {
             cout << i << endl;
             return 0;
         }
     }
     
 }

Measured memory_bytes: 3620
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    double a = sc.nextDouble();
    double b = sc.nextDouble();
    double x = sc.nextDouble();
    double y = sc.nextDouble();
    double c = Math.sqrt(Math.pow(a - x, 2) + Math.pow(b - y, 2));
    System.out.println(c);
  }
}



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

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

    if (n == 0)
    {
        cout << x << endl;
        return 0;
    }

    vector<pair<int, int>> p(n);
    rep (i, n)
    {
        cin >> p[i].second;
        p[i].first = abs(p[i].second - x);
    }

    sort(p.begin(), p.end());
    if (p[0].first != 0)
    {
        cout << x << endl;
        return 0;
    }
    else
    {
        int pCnt = 1;
        for (int i = 1; i <= n; i++)
            rep (j, 2)
                if (p[pCnt].first == i)
                    pCnt++;
                else
                {
                    if (j == 1)
                    {
                        pair<int, int> ans(x - i, x + i);
                        if (p[pCnt - 1].second != ans.first)
                            cout << ans.first << endl;
                        else
                            cout << ans.second << endl;
                        return 0;
                    }
                    else
                    {
                        cout << x - i << endl;
                        return 0;
                    }
                }
    }

    return 0;
}

Measured memory_bytes: 3636
#include<cstdio>

int a[50];
int main() {
    int n, m;

    scanf("%d%d", &n, &m);

    for (int i = 0; i < n; i++) {
        int k, x;
        scanf("%d", &k);
        for (int j = 0; j < k; j++){
            scanf("%d", &x);
            a[x-1]++;
        }
    }

    int ans = 0;
    for (int i = 0; i < m; i++) {
        if (a[i] == n) ans++;
    }

    printf("%d\n", ans);

    return 0;
}


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

int main(){
	int n,m; cin>>n>>m;
	vector<int> v(m);
	rep(i,m) cin>>v[i];
	sort(all(v));
	m--;
	vector<int> d(m);
	rep(i,m) d[i]=v[i+1]-v[i];
	sort(all(d));
	if(n>=m+1) cout<<0<<endl;
	else{
		n--;
		ll ans=accumulate(d.begin(),d.end()-n,0);
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 3912
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    import re
    pattern="^(dream|dreamer|erase|eraser)+$"
    cmp=re.compile(pattern)
    print("YES" if cmp.match(input()) else "NO")
resolve()

Measured memory_bytes: 41968
#include<stdio.h>

int main(void){
long long n,a,b;
scanf("%lld%lld%lld",&n,&a,&b);
if(n == 1 && a == b){printf("1\n");return 0;}
if(b<a || n == 1){printf("0\n");return 0;}
printf("%lld\n",((n-2)*(b-a))+1);
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

struct Triangle {
    int parent;
    vector<int> children;
};

class Tree {
    vector<vector<int>> edges;
public:
    Tree(int n) : edges(n) {}

    void edge(int i, int j) {
        edges[i].push_back(j);
        edges[j].push_back(i);
    }

    void root(int r, vector<Triangle> &leafs) {
        queue<int> vs;
        vs.push(r);
        vector<bool> check(edges.size(), false);
        check[r] = true;
        while (!vs.empty()) {
            int k = vs.front();
            Triangle triangle;
            triangle.parent = k;

            for (int i : edges[k]) {
                if (check[i]) continue;
                check[i] = true;
                triangle.children.push_back(i);
                vs.push(i);
            }
            vs.pop();
            leafs.push_back(triangle);
        }
//        reverse(leafs.begin(), leafs.end());
    }
};

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

    vector<P> es(n - 1);
    for (P &p: es) cin >> p.first >> p.second, p.first--, p.second--;


    priority_queue<ll> q;
    rep(i, n) {
        int c;
        cin >> c;
        q.push(c);
    }

    vector<Triangle> leafs;
    Tree tree(n);
    for (P &p: es)tree.edge(p.first, p.second);
    tree.root(0, leafs);

    vector<int> v(n);

    for (Triangle &t : leafs) {
        v[t.parent] = q.top();
        q.pop();
    }

    ll ans = 0;
    for (P &p:es) ans += min(v[p.first], v[p.second]);
    cout << ans << endl;
    for (ll l : v) cout << l << ' ';

}


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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a+b+c>=22){
    cout << "bust" << endl;
  }
  else cout << "win" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		int degit = 0;
		
		do {
			degit++;
			n /= k;
		} while (n > 0);
		System.out.println(degit);
		
		sc.close();
	}
}






Measured memory_bytes: 23252
# -*- coding: utf-8 -*-
from collections import Counter

n = int(input())
al = list(map(int, input().split()))

if max(al)==0:
    print("Yes")
    exit()

d = Counter(al)
keys = sorted(d.keys())
if len(keys)==2:
    if n%3==0 and keys[0]==0 and d[keys[0]]*2==d[keys[1]]:
        print("Yes")
        exit()

if len(keys)==3:
    if n%3==0 and keys[0]^keys[1]^keys[2]==0 and d[keys[0]]==d[keys[1]]==d[keys[2]]:
        print("Yes")
        exit()

print("No")

Measured memory_bytes: 60784
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI acos(-1)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}

int main(){
   ll n,m;
   cin>>n>>m;

   cout<<(1900*m+100*(n-m))*pow(2,m);
   return 0;
}


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

int main(){
  int N, M; cin >> N >> M;
  vector<pair<int,int>> A(N);
  int AC=0;
  int WA=0;
  if(M==0){
    cout << AC << " " << WA << endl;
    return 0;
  }
  for(int i=0;i<M;i++){
    int p; string S; cin >> p >> S;
    if(A[p-1].first==0 && S=="AC"){
      AC++;
      WA+=A[p-1].second;
      A[p-1].first=1;
    }
    if(A[p-1].first==0 && S=="WA"){
      A[p-1].second++;
    }
  }
  cout << AC << " " << WA << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
/*---------------------DEBUGGING--------------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
//#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M  1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 10000000000000
#define N 200005
#define vi vector<int>
#define all(v) v.begin(),v.end()
#define endl "\n"
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int n,a,b;
   cin>>n>>a>>b;
   cout<<min(n*a,b)<<endl;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using u128 = __uint128_t;

#define int long long
#define idxSet tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define atIdx find_by_order
#define idxOf order_of_key
#define MOD 1000000007
#define MAX 200005
#define endl '\n'

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int dp[MAX];

void solve() {
    int n , k;
    cin>>n>>k;
    bool data[10] = {false};
    for (int i = 0; i < k; ++i) {
        int v; cin>>v;
        data[v] = true;
    }
    vi d;
    while(n != 0){
        d.push_back(n % 10);
        n/= 10;
    }
    reverse(d.begin() , d.end());
    int ith = -1;
    for(int i = 0 ; i < 10 ;i++){
        if(!data[i]){
            ith = i;
            break;
        }
    }
    int idx = d.size();
    for(int i = 0 ; i <  d.size() ; i++){
        if(data[d[i]]){
            idx = i + 1;
            break;
        }
    }
    int carry = 0;
    for(int i = idx - 1; i >= 0 ;i--){
        int v = d[i] + carry;
        for(int j = v ; j < 10 ; j++){
            if(!data[j]){
                for(int ii = 0 ; ii < i  ; ii++){
                    cout<<d[i];
                }
                cout<<j;
                for(int ii = idx ; ii < d.size() ; ii++){
                    cout<<ith;
                }
                cout<<endl;
                return;
            }
        }
        carry = 1;
        idx--;
    }
    for(int i = 1 ; i < 10 ; i++){
        if(!data[i]){
            cout<<i;
            break;
        }
    }
    for(int i = 0 ; i< d.size() ; i++){
        cout<<ith;
    }
    cout<<endl;
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin>>t;
    while (t--)
        solve();
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> ws(n);
  for (auto &w : ws) {
    cin >> w;
  }
  
  int ans = (1 << 30);
  
  for (int i = 0; i < n - 1; i++) {
    int s1 = 0, s2 = 0;
    for (int j = 0; j <= i; j++) {
      s1 += ws[j];
    }
    for (int j = i + 1; j < n; j++) {
      s2 += ws[j];
    }
    ans = min(ans, abs(s1 - s2));
  }
  
  cout << ans << endl;
  
  return 0;
}


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

    using namespace std;

    void __print(int x) {cerr << x;}
    void __print(long x) {cerr << x;}
    void __print(long long x) {cerr << x;}
    void __print(unsigned x) {cerr << x;}
    void __print(unsigned long x) {cerr << x;}
    void __print(unsigned long long x) {cerr << x;}
    void __print(float x) {cerr << x;}
    void __print(double x) {cerr << x;}
    void __print(long double x) {cerr << x;}
    void __print(char x) {cerr << '\'' << x << '\'';}
    void __print(const char *x) {cerr << '\"' << x << '\"';}
    void __print(const string &x) {cerr << '\"' << x << '\"';}
    void __print(bool x) {cerr << (x ? "true" : "false");}

    template<typename T, typename V>
    void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
    template<typename T>
    void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
    void _print() {cerr << "]\n";}
    template <typename T, typename... V>
    void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
    #ifndef ONLINE_JUDGE
    #define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
    #else
    #define debug(x...)
    #endif
    const long long INF  = 1e18;
    int md = 998244353;

    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int n,k;
        cin>>n>>k;
        vector<int>dp(n+3);
        vector<int>pre(n+3);
        vector<int>l(k);
        vector<int>r(k);
        for(int i=0;i<k;i++)
        {
            cin>>l[i];
            cin>>r[i];
        }
        dp[1]=1;
        pre[1] = 1;
        for(int i=2;i<=n;i++)
        {
            for(int j=0;j<k;j++)
            {
                if(l[j]>=i)
                    continue;
                int left = l[j];
                int right = min(i-1,r[j]);
                int val = (pre[i-left] - pre[i-right-1] + md )%md;
                dp[i] = (dp[i] + val)%md;
            }
            pre[i] = (pre[i-1]%md + dp[i]%md)%md;
        }
        cout<<dp[n];
        return 0;
        
    }
    //https://www.youtube.com/watch?v=ZQqccia8bVo

Measured memory_bytes: 4748
import math
lst = [1 for i in range(1000001)]
prime = [0, 0]
lst[0] = lst[1] = 0
cnt = 0
for i in range(2,1000001):
    if lst[i] == 1:
        cnt += 1
        for j in range(i*2,1000001,i):
            lst[j] = 0
    prime.append(cnt)
                
while(True):
    try:
        print(prime[int(input())])
    except:
        break


Measured memory_bytes: 23808
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(){
	int a,b,c,k; scanf("%d%d%d%d", &a, &b, &c, &k);
	printf("%d\n", min(k, a) - max(0, k-a-b));
}


Measured memory_bytes: 3812
#include <stdio.h>
#define N 100

int G[N+1][N+1], size[N+1], d[N+1], f[N+1], n, t;

void init(){
  int i;
  for(i=0;i<=N;i++){
    d[i] = 0;
    f[i] = 0;
  }
  t = 1;
}

void dfs(int p){
  int i;
  d[p] = t;
  for(i=1;i<=size[p];i++){
    if(!d[G[p][i]]){
      t++;
      dfs(G[p][i]);
    }
  }
  f[p] = ++t;
}

main(){
  int i, j, u, v;
  init();
  scanf("%d", &n);
  for(i=0;i<n;i++){
    scanf("%d", &u);
    scanf("%d", &size[u]);
    for(j=1;j<=size[u];j++) scanf("%d", &G[u][j]);
  }
  for(i=1;i<=n;i++) if(!d[i]) dfs(i), t++;
  for(i=1;i<=n;i++) printf("%d %d %d\n", i, d[i], f[i]);
  return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<string> vs;

typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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;}

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n;
	cin >> n;
	ll a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	cout << a[n-1] << endl;
	return 0;
}

Measured memory_bytes: 256
import bisect
N=int(input())
A=list(map(int,input().split()))
if N==2:
  print(max(A),min(A))
else:
  B=sorted(A)
  a=B[-1]
  B=B[:N-1]
  b=bisect.bisect_left(B,a/2)
  c=abs(a/2-B[b])
  d=abs(a/2-B[b-1])
  if c>d:
    bb=B[b-1]
  else:
    bb=B[b]  
  print(a,bb)

Measured memory_bytes: 14428
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define DEBUG(x)           cout << '>' << #x << ':' << x << endl;
#define forn(i,n)          for(int i=0;i<(int)n;++i)
#define for1(i,n)          for(int i=1;i<=(int)n;++i)
#define forr(i,n)          for(int i=(int)n-1;i>=0;--i)
#define forre(i,a,b)       for(int i=(int)b;i>=(int)a;--i)
#define fore(i,a,b)        for(int i=(int)a;i<=(int)b;++i)
#define input(arr,n)       for(int i=0;i<n;i++)cin>>arr[i]
#define output(arr,n)      for(int i=0;i<n;i++)cout<<arr[i]<<" "
#define for_each(arr)      for(auto& it:arr)cout<<it<<" "
#define ff                 first
#define ss                 second
#define PI                 acos(-1.0)
#define all(a)             a.begin(),a.end()
#define rall(a)            a.rbegin(),a.rend()
#define Unique(a)          sort(all(a)),a.erase(unique(all(a)),a.end())
#define pb(x)              push_back(x)
#define eb(x)              emplace_back(x) 
#define ppb(x)             pop_back(x)
#define pf(x)              push_front(x)
#define ppf(x)             pop_front(x)
#define in(x,y)            insert({x,y})
#define Sort(a)            sort(a.begin(),a.end())
#define mem(arr,a)         memset(arr,a,sizeof arr)
#define ins(a)             insert(a)
#define max2(a,b)          max(a,b)
#define max3(a,b,c)        max(a,max(b,c))
#define max4(a,b,c,d)      max(a,max3(b,c,d))
#define min2(a,b)          min(a,b)
#define min3(a,b,c)        min(a,min(b,c))
#define min4(a,b,c,d)      min(a,min3(b,c,d))
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<char> vc;
typedef vector<double> vd;
/*inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void Set(int & n, int b) { n |= two(b); }
inline void Reset(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }*/
/*int fx1[]={+1,-1,+0,+0};
int fy1[]={+0,+0,+1,-1};
int fx2={+0,+0,+1,-1,-1,+1,-1,+1};
int fy2={-1,+1,+0,+0,+1,+1,-1,-1};
*/

ll a,b,c,n,ans,cn1,cn2,cn3,t;
string s,s1,s2;


int main()
{
    FIO;
   /* #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    cin>>n;
    map<int,int>mp;
    //vector<int>v(n+1);
    for(int i=1;i<=n;i++){
    	cin>>a;
    	mp[a]=i;
    }
    for(auto it:mp)cout<<it.second<<" ";//<<endl;

    

    
   	
    #ifdef ONLINE_JUDGE
    cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
    #endif
   return 0;
}
 


Measured memory_bytes: 5504
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int dp[1005][10005];
int main(){
      int w,n,v1,w1,solve,solve_,count = 0;
      do{
            cin >> w;
            if(!w)break;
            cin >> n;

            count++;
            solve =solve_=  -1;
            for(int i = 0;i<1005;i++)for(int j = 0;j<10005;j++)dp[i][j] = -1;
            dp[0][0] = 0;
            for(int i =0 ;i< n;i++)
            {
                  scanf("%d,%d",&v1,&w1);
                  for(int j = 0;j<=w;j++)
                  {
                        if(dp[i][j]!=-1)
                        {
                              dp[i+1][j] = max(dp[i+1][j],dp[i][j]);
                              dp[i+1][j+w1] = max(dp[i][j]+v1,dp[i+1][j+w1]);
                        }
                  }
            }
            for(int i = 0;i<=w;i++){
                  if(dp[n][i]>solve){
                        solve = dp[n][i];
                        solve_ = i;
                  }
            }
            cout << "Case "<<count << ':'<<endl<< solve<<endl<<solve_<<endl;



      }while(1);
}

Measured memory_bytes: 40520
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ARedOrNot solver = new ARedOrNot();
        solver.solve(1, in, out);
        out.close();
    }

    static class ARedOrNot {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            String x = in.next();
            if (n < 3200) out.println("red");
            else out.println(x);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 21460
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 1000000007;

long long div(long long a, long long b, long long c) { return b / c - (a - 1) / c; }

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}
long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}
void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)

int main() {
    string a, b;
    cin >> a >> b;
    if (a.size() > b.size()) {
        cout << "GREATER" << endl;
        return 0;
    }
    if (b.size() > a.size()) {
        cout << "LESS" << endl;
        return 0;
    }
    REP(i, a.size()) {
        if (a[i] > b[i]) {
            cout << "GREATER" << endl;
            return 0;
        }
        if (a[i] < b[i]) {
            cout << "LESS" << endl;
            return 0;
        }
    }
    cout << "EQUAL" << endl;
}

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


template <typename T>
T gcd( T a, T b )
{
    if( b == 0 ) return a;
    else return gcd( b, a % b );
}

// 最小公倍数
template <typename T>
T lcd( T a, T b ) { return a * b / gcd<T>( a, b ); }


int main()
{
    long long A, B, C, D;
    cin >> A >> B >> C >> D;

    // A~B の間に含まれる倍数の数
    long long c_muptiple = B/C-(A-1)/C;
    long long d_muptiple = B/D-(A-1)/D;
    long long lcd_cd = lcd<long long>(C, D);
    long long cd_muptiple = B/lcd_cd-(A-1)/lcd_cd;

    //cout << c_muptiple << " " << d_muptiple << " " << cd_muptiple << endl;
    cout << (B-A+1) - (c_muptiple+d_muptiple-cd_muptiple) << endl;
    
    return 0;
}

Measured memory_bytes: 256
import heapq
N,M = map(int,input().split())
A = list(map(lambda x:int(x)*(-1),input().split()))
heapq.heapify(A)
for _ in range(M):
    a = heapq.heappop(A)
    a /= 2
    heapq.heappush(A,a)
s = 0
for i in A:
    i = int(i*(-1))
    s += i
print(s)

Measured memory_bytes: 14180
s = input()
t = input()

ans = len(t)

for i in range(len(s)-len(t)+1):
    #print(i)
    t_ans = 0
    for j in range(len(t)):
        if s[i+j] != t[j]:
            t_ans += 1
    ans = min(t_ans,ans)
    
print(ans)

Measured memory_bytes: 72868
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#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 <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
int n,m,v,i;
ll ans , cnt=0;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n;
  string s;
  cin>>s;
  repl(i,1,s.size()){
    string a,b;
    cnt = 0;
    a = s.substr(0,i);
    b = s.substr(i,s.size()-i);
    std::map<ll,ll> x,y;
    rep(i,a.size()) x[a[i]]++;
    rep(i,b.size()){
      if(x[b[i]] >= 1) {
        cnt++;
        x[b[i]] = 0;
      }
    }
    maxch(ans,cnt);
    // cout<<a<<" "<<b<<endl;
  }
  cout<<ans<<endl;

}

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


Measured memory_bytes: 256
# AtCoder Beginner Contest 088B

n = gets.to_i
array = gets.split.map(&:to_i)
array = array.sort{ |a,b| b<=>a }

alice = 0;	bob= 0;	

array.length.times do |i|
	if i % 2 == 0 then	alice += array[i]
	else			bob += array[i]
	end
end

puts alice - bob

Measured memory_bytes: 1788
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define Decimal fixed << setprecision(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}
constexpr int INF = 1100000000;
constexpr long long LLINF = 1100000000000000000LL;
constexpr long long MOD = 1000000007;

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


int main()
{
  ll N;
  cin >> N;
  vector<P> v;
  REP(i, N) {
    ll A, B;
    cin >> A >> B;
    v.PB(MP(B, A));
  }
  sort(ALL(v));

  ll sum = 0;
  REP(i, N) {
    sum += v[i].SE;
    if (sum > v[i].FI) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 6384
from collections import deque
N, M, K = map(int, input().split())
A = [[] for i in range(N)]
B = [[] for i in range(N)]
for i in range(M):
  a, b = map(lambda x:int(x)-1, input().split())
  A[a].append(b)
  A[b].append(a)
for i in range(K):
  a, b = map(lambda x:int(x)-1, input().split())
  B[a].append(b)
  B[b].append(a)
P = [-1 for i in range(N)]
Q = []
k = -1
for i in range(N):
  if P[i] == -1:
    q = 1
    k += 1
    P[i] = k
    d = deque([i])
    while len(d):
      s = d.pop()
      for t in A[s]:
        if P[t] == -1:
          P[t] = k
          q += 1
          d.append(t)
    Q.append(q)
for i in range(N):
  ans = Q[P[i]] - len(A[i]) - 1
  for j in B[i]:
    if P[i] == P[j]:
      ans -= 1
  print(ans)

Measured memory_bytes: 110748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
	ll n, k, q;
  	cin>>n>>k>>q;
  	vector<ll> v(n, k-q);
  	for (ll i=0; i<q; i++){
      ll p;
      cin>>p;
      p--;
      v[p]++;
    }
  	for (ll i=0; i<n; i++){
      if (v[i]>0) cout<<"Yes\n";
      else cout<<"No\n";
    }
}

Measured memory_bytes: 1408
'use strict'

const main = input => {
	const args = input.split('\n').map(arg => arg.split(' '))
	const n = parseInt(args[0][0], 10)
	let flg = false

	for (let i = 0; i <= Math.floor(n / 4); i++) {
		for (let j = 0; j <= Math.floor(n / 7); j++) {
			if (4 * i + 7 * j === n) flg = true
		}
	}

	if (flg) console.log('Yes')
	else console.log('No')
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7500
#include <bits/stdc++.h>
#define PII pair<int, int>
#define LL long long
#define double long double
using namespace std;
const int MAXN = 205;
 
struct Vector {
	int x, y;
	LL cross(const Vector &v) const {
		return (LL) x * v.y - (LL) y * v.x;
	}
	bool operator < (const Vector &v) const {
		return atan2(x, y) < atan2(v.x, v.y);
//		int id1 = y > 0 || (y == 0 && x >= 0) ? 1 : 2;
//		int id2 = v.y > 0 || (v.y == 0 && v.x >= 0) ? 1 : 2;
//		if (id1 != id2) return id1 < id2;
//		return cross(v) > 0;
	}
};
 
int N;
LL sumx[MAXN], sumy[MAXN];
Vector vec[MAXN];
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
 
	cin >> N;
	for (int i = 1; i <= N; i++) {
		int x, y;
		cin >> x >> y;
		vec[i] = {x, y};
	}
	sort(vec + 1, vec + 1 + N);
	for (int i = 1; i <= 2 * N; i++) {
		sumx[i] = sumx[i - 1] + vec[i].x;
		sumy[i] = sumy[i - 1] + vec[i].y;
		if (i <= N) {
			vec[i + N] = vec[i];
		}
	}
	
	LL ans = 0;
	for (int i = 1; i <= N; i++) {
		for (int j = i; j - i + 1 <= N; j++) {
			LL vx = sumx[j] - sumx[i - 1];
			LL vy = sumy[j] - sumy[i - 1];
			ans = max(ans, vx * vx + vy * vy);
		}
	}
	
	cout << fixed << setprecision(18) << sqrt(ans) << '\n';
 
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const ll mod = 1000000007;
ll A, B, C, Sx, Sy;
ll ans;
ll inv[10000100];
ll FactorialInv[10000100];
ll Factorial[10000100];
ll beki(ll a, ll b){
    if(b == 0){
        return 1;
    }
    ll ans = beki(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}
void init_combination(){
    const int MAX = 10000002;
    Factorial[0] = 1;
    inv[0] = 1;
    for(int i = 1; i <= MAX; i++){
        Factorial[i] = Factorial[i - 1] * i % mod;
    }
    FactorialInv[MAX] = beki(Factorial[MAX], mod - 2);
    for(ll i = MAX - 1; i >= 0; i--) {
        FactorialInv[i] = FactorialInv[i+1] * (i+1) % mod;
    }
    for(int i = 1; i <= MAX; i++) {
        inv[i] = FactorialInv[i] * Factorial[i-1] % mod;
    }
}
ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    if(a < b) return 0;
    ll ans = Factorial[a] * FactorialInv[b] % mod;
    ans = ans * FactorialInv[a - b] % mod;
    return ans;
}


void solve() {
    ans = 0;
    for(ll overx = A; overx <= 1e6; overx++) {
        ll overy = Sy - Sx + overx;
        if(overy < B) continue;
        ll now = 1;
        ll tmp = overx - A;
        now *= combination(A - 1 + tmp, tmp);
        tmp = overy - B;
        now *= combination(B - 1 + tmp, tmp);
        now %= mod;
        ll rest = Sx - overx;
        if(rest < 0) continue;
        now *= combination(A + B + C - 1 + rest, rest);
        now %= mod;
        now *= combination(A + B + C, A);
        now %= mod;
        now *= combination(B + C, B);
        now %= mod;
        ans += now;
        ans %= mod;
    }
    cout << ans << endl;
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    init_combination();
    while(cin >> A >> B >> C >> Sx >> Sy) {
        if(A==0 and B==0 and C==0) break;
        solve();
    }
    return 0;
}


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

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

    }


Measured memory_bytes: 256
n=int(input())
w=list(map(int,input().split()))
i,d=0,sum(w)
while(True):
  a=sum(w[:i])
  b=sum(w)-a
  c=abs(b-a)
  if c>d:
    break
  else:
    d=c
    i+=1
print(d)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pp pair<ll,ll>
typedef tree<pp,null_type,less<pp>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define rep(i,a,b) for( ll i = a ; i < b ; i+=1 )
#define sz(v) (ll)(v.size())
#define hell (ll)1000000007
#define slld(x) scanf("%lld",&x)
ll t = 1,tt;
const ll nax=2e18;
void solve(){
	ll n,k;
	cin>>n>>k;
	cout<<min(n%k,k-(n%k));
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	//cin>>t;
    while(t--){
        solve();
    }
    return 0 ;
}


Measured memory_bytes: 256
import collections

n,q=map(int,input().split())
cnt=[0]*(n+1)
g=[[] for _ in range(n+1)]
for _ in range(n-1): #木グラフの隣接リストを作成
 a,b=map(int,input().split())
 g[a].append(b)
 g[b].append(a)
for _ in range(q): #各頂点についてcount[v]を計算
 v,val=map(int,input().split())
 cnt[v]+=val
q=collections.deque()
q.append(1) #DFSのスタックによる実装、まずスタックに始点1を積む
checked=[0]*(n+1) #各頂点を見たかどうかのフラグを持っておく
while q:
 v=q.pop()
 checked[v]=1 #頂点を見たかどうかのフラグを更新する
 for u in g[v]:
   if checked[u]==1: #vの子ノードuについて、まだ見ていない頂点であればcount[u]をcount[u]+=count[v]として更新する
     continue
   cnt[u]+=cnt[v]
   q.append(u) #スタックに子ノードuを積む
print(*cnt[1:]) #各頂点のcountが答えとなる

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

//C++14 (GCC 5.4.1)

#define LLINF (1LL<<60)
typedef long long ll;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)

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

template<typename T> inline T divrup(T a, T b) { if (a % b) return a/b+1; else return a/b;}
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)

int main() {
    ios::sync_with_stdio(false);//stdoutとcoutの同期解除
    cin.tie(nullptr);//cinとcoutの同期解除
    
    int N,p;
    cin >>N;

    vector<int> pos(N+1);
    rep(i,N){
        cin >> p;
        pos[p]=i+1;
    }
    //-----------------------------------
    ll ans=0;
    std::multiset<int> se{0,0,N+1,N+1};
    se.insert(pos[N]);//大きい数のある場所から見ていく

    for(int i=N-1;i>0;i--){
        auto it=se.lower_bound(pos[i]);
        it--;it--;
        int w=*it;it++;
        int x=*it;it++;
        int y=*it;it++;
        int z=*it;
        ans+=(ll)i*(x-w)*(y-pos[i]);// w<L<=x<i<=R<y <z
        ans+=(ll)i*(z-y)*(pos[i]-x);// w< x<=L<i<y<=R<z
        se.insert(pos[i]);
    }

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

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

class Program
{
  static void Main(string[] args)
  {
    var p = Console.ReadLine();
    int count = 0;
    for (int i = 0; i < 4; i++) {
      if (p[i] == '+')count++;
      if (p[i] == '-')count--;
    }
    Console.WriteLine(count);
  }

}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define N 40010
using namespace std;
int a[2];
int main(){
	string s;
	cin>>s;
	a[s[0]-'A']++;
	a[s[1]-'A']++;
	a[s[2]-'A']++;
	if(a[0]==0||a[1]==0){
		cout<<"No"<<endl;
	}else{
		cout<<"Yes"<<endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pi pair<int,int>
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define sz(x) ((int)x.size())
#define ln(x) ((int)x.length())
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define dbg(x) cout<<#x<<": "<<x<<endl
#define clr(x,v) memset(x, v, sizeof(x))
#define dblout(x) cout << setprecision(x) << fixed;
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
const int MAXN = 1e6 + 5;

void cp()
{
    string s;
    cin >> s;
    if(s.back() == 's')
        s += "es";
    else
        s += "s";
    cout << s << endl;
}

int main()
{
    FASTIO;
    int t;
    t = 1;
    // cin >> t;
    while(t--)
    {
        cp();
    }
    return 0;
}

Measured memory_bytes: 3664
#include <vector>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <map>
#include <set>
#include <string>
#include <cassert>

#define INFLL 2000000000000000000
#define INF 2000000000
#define MOD 1000000007
#define PI acos(-1.0)

using namespace std;

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

int main() {
	//freopen("maxrand1.in", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ll arr[50];
	ll n;
	cin >> n;
	for (int i = 0; i < n; i++) cin >> arr[i];
	ll ans = 0;
	while (true) {
		ll sum = 0;
		for (int i = 0; i < n; i++) {
			sum += arr[i];
			if (sum > 10000000000000000)
				break;
		}		
		if (sum <= n * (n - 1)) break;
		ll step = n * (1 - n) + sum;
		ll old = step;
		ans += step;
		for (int i = 0; i < n; i++) {
			ll tmp = step;
			ll l = 0, r = step;
			while (l <= r) {
				ll mid = (l + r) / 2;
				if (arr[i] - mid * n + old - mid >= 0) {
					tmp = mid;
					l = mid + 1;
				} else r = mid - 1;
			}
			arr[i] = arr[i] - tmp * n + old - tmp;
			step -= tmp;
		}
	}
	while (true) {
		ll toAdd = 0;
		for (int i = 0; i < n; i++) toAdd += arr[i] / n;
		if (toAdd == 0)
			break;
		ans += toAdd;
		for (int i = 0; i < n; i++) {
			arr[i] = arr[i] % n + toAdd - arr[i] / n;
		}
	}
	cout << ans << endl;
	return 0;
}


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

template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}

signed main(){
  int x;cin>>x;
  int now=0;
  for(int i=1;i;i++){
    now+=i;
    if(now>=x)fin(i);
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int N; cin>>N;
	int a,b; cin>>a>>b;
	ll ans = 0;
	rp(i,1,N+1){
		ll s = 0;
		int n = i;
		while(n){
			s += n % 10;
			n /= 10;
		}
		if(a<=s && s<=b){
			ans += i;
		}
	}
	ote(ans);
}


Measured memory_bytes: 256
a,b = map(str, input().split())
c = int(a+b)

def bisearch(f, n):
    l = 0
    r = n
    fl = f(l)
    fr = f(r)
    while l <= r:
        m = (l + r) // 2
        fm = f(m)
        #print l,m,r,fl,fm,fr,n
        if fm == n:
            return m
        elif fm > n:
            r = m - 1
            fr = f(r)
        else:
            l = m + 1
            fl = f(l)

def try_square_root(n2):
    return bisearch(lambda n:n*n, n2)
 
if try_square_root(c)==None:
  print('No')
else:
  print('Yes')

Measured memory_bytes: 38256