akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
template<typename T> inline void add(T& a, T b) { a += b; if (a >= MOD) a -= MOD; }

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

  // vector<int> test;
  // test.push_back(1);
  // test.push_back(2);
  // auto it = upper_bound(test.begin(), test.end(), 1);
  // if(it == test.end()) {
  //   cout << "end" << endl;
  // } else {
  //   cout << test.end() - it << endl;
  // }
  // return 0;

  int N; cin >> N;
  string S; cin >> S;

  vector<int> R;
  vector<int> G;
  vector<int> B;
  rep(i, N) {
    if(S[i] == 'R') {
      R.push_back(i);
    } else if(S[i] == 'G') {
      G.push_back(i);
    } else {
      B.push_back(i);
    }
  }
  int RN = R.size();
  int GN = G.size();
  int BN = B.size();

  if(RN == 0 || GN == 0 || BN == 0) {
    cout << 0 << endl;
    return 0;
  }

  ll ans = 0;

  const char n1[6] = { 'R', 'R', 'G', 'G', 'B', 'B' };
  const char n2[6] = { 'B', 'G', 'B', 'R', 'R', 'G' };
  const char n3[6] = { 'G', 'B', 'R', 'B', 'G', 'R' };

  rep(a, 6) {
    int rn = n1[a] == 'R' ? RN : n1[a] == 'G' ? GN : BN;
    int gn = n2[a] == 'R' ? RN : n2[a] == 'G' ? GN : BN;
    int bn = n3[a] == 'R' ? RN : n3[a] == 'G' ? GN : BN;
    vector<int> r = n1[a] == 'R' ? R : n1[a] == 'G' ? G : B;
    vector<int> g = n2[a] == 'R' ? R : n2[a] == 'G' ? G : B;
    vector<int> b = n3[a] == 'R' ? R : n3[a] == 'G' ? G : B;

    rep(i, rn) {
      rep(j, gn) {
        if(r[i] > g[j]) continue;
        auto it = upper_bound(b.begin(), b.end(), g[j]);
        if(it == b.end()) continue;
        ans += b.end() - it;
        if(binary_search(it, b.end(), g[j] + g[j] - r[i])) --ans;
      }
    }
  }

  cout << ans << endl;
}


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

int main() {
  int N;
  cin >> N;
  bool can = false;
  for (int i = 0; i <= 25; i++) {
    for (int j = 0; j < 15; j++) {
      if (4*i + 7*j == N) {
        can = true;
        break;
      }
    }
  }
  if (can) cout <<"Yes" << endl;
  else cout << "No" << endl;
}


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

const int MAX_PRIME = 1e6 + 1;

bool is_prime[MAX_PRIME];

void solve(int A, int D, int N) {
    int cnt = 0, number = A;
    while (cnt < N) {
        if (is_prime[number]) cnt++;
        number += D;
    }
    cout << number - D << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    for (int i = 2; i < MAX_PRIME; i++) {
        is_prime[i] = true;
    }
    for (int i = 2; i < MAX_PRIME; i++) {
        if (!is_prime[i]) continue;
        int not_prime = i * 2;
        while (not_prime <= MAX_PRIME) {
            is_prime[not_prime] = false;
            not_prime += i;
        }
    }
    int A, D, N;
    while (true) {
        cin >> A >> D >> N;
        if (A == 0 && D == 0 && N == 0) break;
        solve(A, D, N);
    }
    return 0;
}


Measured memory_bytes: 4024
#include <bits/stdc++.h>
using namespace std;
#include <boost/multiprecision/cpp_int.hpp>

namespace mp = boost::multiprecision;
const long long MOD = 1e9+7;
//const long long MOD = ;
const long long INF_LL = 1e18+3; const int INF_int = 1e9+3;
#define ll long long
#define rep(i,n) for(int i = 0;i<n;i++)
#define lrep(i,n) for(long long i = 0;i<n;i++)
#define All(a) a.begin(),a.end()
#define Debug_Output_ALL(a) for(auto itr = a.begin();itr!=a.end();itr++) cout << *itr << " ";cout << endl;
int main(){
    mp::int128_t a,b,c;
    cin >> a >> b >> c;
    mp::int128_t hoge = 4*a*b;
    mp::int128_t hoge2 = (c-a-b)*(c-a-b);
    if(hoge<hoge2 && (c-a-b)>=0){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
}


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

int main()
{

        vector<int> a;
        vector<char> o;
        vector<int> b;
        int tmp1, tmp2;
        char c;
        while (1) {

                cin >> tmp1 >> c >> tmp2;
                if (c == '?') {
                        break;
                }
                a.push_back(tmp1);
                o.push_back(c);
                b.push_back(tmp2);
        }
        int n = a.size();
        for (int i = 0; i < n; ++i) {
                if (o[i] == '+') {
                        cout << a[i] + b[i] << endl;
                }
                else if (o[i] == '-') {
                        cout << a[i] - b[i] << endl;
                }
                else if (o[i] == '*') {
                        cout << a[i] * b[i] << endl;
                }
                else {
                        cout << a[i] / b[i] << endl;
                }
        }




}



Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
long long int n,m,ans=1;
string s;

int main(){
    cin>>s;
    if(s.length()==2){cout<<s<<endl;}
    else if(s.length()==3){
        for(int i=2;i>=0;i--){
            cout<<s[i];
        }cout<<endl;
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second
#define v vector
v<v<ll> > dp(100,v<ll> (100001,-1));int n;

v<v<ll> > vec(100,v<ll> (2,-1));
ll fin(int i,int W)
{   if(i==n || W==0)
      return 0;
    if(dp[i][W]!=-1)
        return dp[i][W];
     if(vec[i][0]>W)
        return fin(i+1,W);
    return dp[i][W]=max(fin(i+1,W),fin(i+1,W-vec[i][0])+vec[i][1]);
}
int main() {
    ios_base::sync_with_stdio(false);
        cin.tie(NULL);
  int W;
  cin>>n>>W;
  for(int i=0;i<n;i++)
  {
      cin>>vec[i][0]>>vec[i][1];
  }
  cout<<fin(0,W);
}


Measured memory_bytes: 80752
#include <cstdio>
#include <iostream>

using namespace std;

int main()
{
	int n;
	int array[1024];
	int tmp;

	scanf("%d", &n);

	for (int i = 0; i < n; i++){
		scanf("%d", &array[i]);
	}

	for (int i = 0; i < n; i++){
		if (i == n - 1){
			cout << array[i] << endl;
		}
		else {
			cout << array[i] << " ";
		}
	}

	for (int i = 1; i < n; i++){
		tmp = array[i];
		int j = i - 1;
		while (j >= 0 && array[j] > tmp){
			array[j + 1] = array[j];
			j--;
		}
		array[j + 1] = tmp;

		for (int k = 0; k < n; k++){
			if (k == n - 1){
				cout << array[k] << endl;
			}
			else {
				cout << array[k] << " ";
			}
		}
	}

	return (0);
}

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

struct UnionFind{
private:
    std::vector<int> par;
    std::vector<int> size;
public:
    UnionFind(int siz){
        par=std::vector<int>(siz);
        size=std::vector<int>(siz);
        for(int i=0;i<siz;++i){
            par[i]=i;
            size[i]=1;
        }
    }

    int root(int x){
        if(par[x]==x)return x;
        else {
            par[x]=root(par[x]);
            return par[x];
        }
    }

    bool same(int x,int y){//0-indexed
        return root(x)==root(y);
    }

    void unite(int x,int y){//0-indexed
        x=root(x);
        y=root(y);
        if(x==y)return;

        if(size[x]<size[y]){
            par[x]=y;
            size[y]+=size[x];
        }
        else{
            par[y]=x;
            size[x]+=size[y];
        }
    }

    int siz(int x){
        return size[root(x)];
    }
};

using namespace std;
using ll = long long;

bool solve() {
    int n;
    cin>>n;
    if(n==0)return false;

    vector<vector<bool>> sc(30,vector<bool>(n,false));

    for(int i = 0;i < n;++i) {
        int k;
        cin>>k;
        for(int j = 0;j < k;++j) {
            int a;
            cin>>a;
            --a;
            sc[a][i]=true;
        }
    }

    vector<set<int>> dp(n);
    for(int i = 0;i < n;++i) {
        dp[i].insert(i);
    }
    for(int ans = 0;ans < 30;++ans) {
        set<int> st;
        for(int i = 0;i < n;++i) {
            if(sc[ans][i])st.insert(i);
        }
        int si=0;
        for(auto i:st) {
            for(auto j:st) {
                set<int> inters;
                set_union(dp[i].begin(),dp[i].end(),dp[j].begin(),dp[j].end(),inserter(inters,inters.begin()));
                dp[i]=inters;
                si=max(si,(int)dp[i].size());
            }
        }
        if(si>=n) {
            cout<<ans+1<<endl;
            return true;
        }
    }
    cout<<-1<<endl;
    return true;
}

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



Measured memory_bytes: 3224
package main

import (
  "fmt"
  "strconv"
)

func main() {
  var a string
  fmt.Scan(&a)

  var b string
  fmt.Scan(&b)

  var c int
  c, _ = strconv.Atoi(a+b)

  var ans bool
  for i := 1; i <= 2000; i++{  
      if i * i == c {
        ans = true
      }
    }

  if ans {
    fmt.Printf("Yes\n")
    return
  }

  fmt.Printf("No\n")
}


Measured memory_bytes: 512
def comb(n, r):
    x, y = 1, 1
    for i in range(n, n - r, -1):
        x *= i
        y *= i + r - n
    return x / y

n, p = map(int, input().split())
a = list(map(int, input().split()))
m = 0
for i in a:
    if i % 2 == 0:
        m += 1
x = 0
for i in range(1, n - m + 1, 2):
    x += comb(n - m, min(i, n - m - i))
x *= 2 ** m
print(int(x) if p == 1 else int(2 ** n - x))

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

void solve(string S) {
  ll c = 0;
  bool found;
  ll from = 0;

  while (!S.empty()) {
    found = false;

    for (int i = from; i < S.size() - 1; i++) {
      found = S.at(i) != S.at(i + 1);
      if (found) {
        S.erase(i, 2);
        if (i == 0) {
          from = 0;
        } else {
          from = i - 1;
        }
        c += 2;
        break;
      }
    }
    if (!found) break;
  }
  cout << c << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  string S;
  cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
// using System.Linq;

namespace easy_Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            // float[] ABN = Array.ConvertAll(Console.ReadLine().Split(),float.Parse);
            // int[] nx = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
            // long K = long.Parse(Console.ReadLine());
            // int[] abc = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
            // string S = Console.ReadLine();
            // int a = int.Parse(Console.ReadLine());
            // int b = int.Parse(Console.ReadLine());
            // int h = int.Parse(Console.ReadLine());
            // float N = float.Parse(Console.ReadLine());
            string c = Console.ReadLine();
            // string B = Console.ReadLine();
            // string[] B = Console.ReadLine().Split();
            // var s = (new string[] { Console.ReadLine(), Console.ReadLine(), Console.ReadLine() }).Select(float.Parse);
            // float[] a = Array.ConvertAll(Console.ReadLine().Split(),float.Parse);
            // var X = Console.ReadLine();
            // int[,] abcd = new int[NMQ[2],4];
            // int[] A = new int[NMQ[0]];
            // int[] A_num = new int[NMQ[0]];
            // for(int i = 0; i<A_num.Length;i++){
            //     A_num[i] = 0;
            // }
            string aeiou = "aeiou";
            Console.WriteLine(aeiou.Count(x=>x==c[0])!=0?"vowel":"consonant");
        }
        //最小公倍数
        static long Lcm(long a, long b)
        {
            return a/Gcd(a,b)*b;
        }

        //最大公約数
        static long Gcd(long m, long n)
        {
            if(n==0)return m;
            return Gcd(n,m%n);
        }
    }
}


Measured memory_bytes: 13268
n = int(input().rstrip())
line = input().rstrip().split(' ')

a = []
d = [0] * n
for i in range(n):
    num = int(line[i])
    a.append(num)
    d[num - 1] += 1

ans_list = [0] * n
for i in range(n):
    ans_list[i] = int(d[i] * (d[i] - 1) / 2)

total = 0
for i in range(n):
    total += ans_list[i]

for i in range(n):
    ans = total

    ans -= ans_list[a[i] - 1]
    num = d[a[i] - 1] - 1
    ans += num * (num - 1) / 2

    print(int(ans))


Measured memory_bytes: 31644
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

int main(void){
  int n, i, flag=0, v, prev;
  int *r, *min, m = 1000000000, max = 0, ans=0;

  scanf("%d",&n);
  r = malloc(sizeof(int)*n);
  min = malloc(sizeof(int)*n);

  //scanf("%d",&prev);
  
  for(i=0;i<n;i++){
    scanf("%d", &r[i]);
    if(m > r[i]){
      min[i] = r[i];
      m = r[i];
    }
    else min[i] = m;
  }
  max = r[n-1];
  ans = max-min[n-2];
  for(i=1;i<n-1;i++){
    if(r[n-1-i] > max) max = r[n-1-i];
    if(ans < max-min[n-2-i]) ans = max-min[n-2-i];
  }
  printf("%d\n",ans);

  return 0;
}


Measured memory_bytes: 3320
n = int(input())
a = [0] + list(map(int, input().split())) + [0]
s = sum([abs(a[i]-a[i-1]) for i in range(1, n+2)])
for i in range(1, n+1):
    x = abs(a[i]-a[i-1])
    y = abs(a[i+1]-a[i])
    z = abs(a[i+1]-a[i-1])
    print(s-x-y+z)

Measured memory_bytes: 14176
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#include <cstring>
#include <fstream>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int,int>
#define MA make_pair
#define LLI long long int
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define POS(i) cout<<(i?"POSSIBLE":"IMPOSSIBLE")<<endl
#define Pos(i) cout<<(i?"Possible":"Impossible")<<endl
#define co(i) cout<<i<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//

//a以上のbの倍数とaの差
LLI s(LLI a,LLI b){
    if(a) return ((a-1)/b+1)*b-a;
    else return 0;
}

int main(){
    int n; cin>>n;
    LLI a[100001],b[100001];
    FOR(i,0,n){
        cin>>a[i]>>b[i];
    }
    LLI ans=0;
    ROF(i,0,n){
        ans+=s(a[i]+ans,b[i]);
    }
    co(ans);
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;
int n,x,mn,un,i,mx,num;
int main()
{
    cin>>n;mn=n+1;
    for(i=1;i<=n;i++)
    {
        cin>>x;
        if(x<mn) mn=x,un=0;
        if(x>mx) mx=x,num=0;
        if(x==mn) un++;
        if(x==mx) num++;
    }
    if((mx==mn&&(2*mx<=n||mx==n-1))||(mx!=mn&&un<mx&&mx-mn==1&&num/2+un-1>=mn)) cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
/*******************************
Author:Morning_Glory
LANG:C++
Created Time:2019年09月01日 星期日 20时17分42秒
*******************************/
#include <cstdio>
#include <fstream>
#define ll long long
using namespace std;
ll n;
int main()
{
	scanf("%lld",&n);
	printf("%lld\n",n*(n-1)/2);
	return 0;
}


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

using namespace std;

typedef long long          ll;
typedef unsigned long long ull;
typedef vector<int>	       vi;
typedef vector<bool>       vb;
typedef map<int, int>      mii;
typedef pair<int, int>     ii;

#define INF                0x3f3f3f3f
#define INFLL              0x3f3f3f3f3f3f3f3f
#define each(x, s)         for(auto& x : s)
#define loop(x)	           for(int i = 0;i < x;i++)
#define vloop(v, x)        for(int v = 0;v < x;v++)
#define avg(l, r)          l + (r - l) / 2
#define iter(a)            a.begin(), a.end()
#define riter(a)           a.rbegin(), a.rend()
#define endl               "\n"

const ll mod = 1000000007;

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

	int l, r, d;
	cin >> l >> r >> d;
	cout << (r / d) - ((l - 1) / d) << endl;
	return 0;
}



Measured memory_bytes: 3648
#include <cstring>
#include <cstdio>
const int N=100005;
int fi[N],ne[N],fst[N],ans[N],n,tot=0;
bool f[N],g[N];
struct Edge{
	int to,nxt;
}e[N*2];
void addedge(int x,int y){
	e[++tot].to=y;e[tot].nxt=fst[x];fst[x]=tot;
	e[++tot].to=x;e[tot].nxt=fst[y];fst[y]=tot;
}
void add(int &x,int y){
	if (!y) return;
	if (x) addedge(x,y),x=0;
		else x=y;
}
int dfs(int x){
	f[x]=1;int y=0;
	for (int i=fi[x];i;i=ne[i]){
		f[x]^=1;
		add(y,dfs(i));
	}
	if (f[x]) add(y,x);
	return y;
}
void work(){
	memset(fi,0,sizeof fi);
	int rt=0;
	for (int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		if (x==-1) rt=i;
			else ne[i]=fi[x],fi[x]=i;
	}
	dfs(rt);
}
void dfs2(int x,int v){
	if (ans[x]) return;
	ans[x]=v;
	for (int i=fst[x];i;i=e[i].nxt)
		dfs2(e[i].to,-v);
}
int main(){
	scanf("%d",&n);
	work();
	memcpy(g,f,sizeof f);
	work();
	for (int i=1;i<=n;i++)
		if (f[i]!=g[i]){
			printf("IMPOSSIBLE\n");
			return 0;
		}
	for (int i=1;i<=n;i++)
		if (f[i]) dfs2(i,1);
	printf("POSSIBLE\n");
	for (int i=1;i<=n;i++) printf("%d ",ans[i]);
}

Measured memory_bytes: 6016
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

bool question(int a,int b){
    cout << "? " << a << " " << b << endl;
    char x;
    cin >> x;
    if(x=='Y'){
        return 1;
    }else{
        return 0;
    }
}


int main(){
    int a,b;
    cin >> a >> b;
    int n = a+b;
    if(a<=b){
        cout << "Impossible" << endl;
        return 0;
    }
    vector<int>tmp;
    vector<int>ans;
    tmp.PB(0);
    int t = 1;
    int cnt = 0;
    while(cnt<=b){
        if(tmp.size()==0){
            tmp.PB(t);
            t++;
            if(tmp.size()+cnt >= b+1){
                break;
            }
        }
        bool flag = question(tmp[tmp.size()-1],t);
        if(flag){
            tmp.PB(t);
            t++;
            if(tmp.size()+cnt >= b+1){
                break;
            }
        }else{
            tmp.pop_back();
            cnt++;
            t++;
        }
    }
    int s = tmp[tmp.size()-1];
    vector<bool>p(n);
    for(int i=0;i<n;i++){
        if(question(s,i)){
            p[i] = 1;
        }
    }
    cout << "! ";
    for(int i=0;i<n;i++){
        cout << p[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 724
def main():
  import math
  n,p=map(int,input().split())
  a=list(map(int,input().split()))
  x=[i for i in a if i%2==0]
  y=[i for i in a if i%2==1]
  
  def comb(n,r):
    return math.factorial(n)//(math.factorial(r)*math.factorial(n-r))
  
  xl,yl=len(x),len(y)
  ans=0
  
  for i in range(xl+1):
    for j in range(yl+1):
      if j%2==p:
        ans+=comb(yl,j)*comb(xl,i)
        
  print(ans)
if __name__=='__main__':
  main()

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct Dice
{
  int top;
  int bottom;
  int front;
  int back;
  int right;
  int left;
} dice;
void input(dice*);
void roll(dice*,char);
int compareAll(dice*,dice*);
int compare(dice*,dice*);
int main(void)
{
  int i,j;
  int n;
  dice *d;
  scanf("%d",&n);
  d=(dice*)malloc(sizeof(dice)*n);
  for(i=0;i<n;i++) input(&d[i]);
  for(i=0;i<n;i++)
    {
      for(j=i+1;j<n;j++)
        {
          if(compareAll(&d[i],&d[j])==1) break;
        }
      if(j!=n) break;
    }
  if(i==n) printf("Yes\n");
  else printf("No\n");
  return 0;
}
void input(dice *d)
{
  scanf("%d",&d->top);
  scanf("%d",&d->front);
  scanf("%d",&d->right);
  scanf("%d",&d->left);
  scanf("%d",&d->back);
  scanf("%d",&d->bottom);
}
void roll(dice *d,char c)
{
  int temp;
  switch(c)
    {
    case 'E':
      temp=d->right;
      d->right=d->top;
      d->top=d->left;
      d->left=d->bottom;
      d->bottom=temp;
      break;
    case 'N':
      temp=d->back;
      d->back=d->top;
      d->top=d->front;
      d->front=d->bottom;
      d->bottom=temp;
      break;
    case 'S':
      temp=d->front;
      d->front=d->top;
      d->top=d->back;
      d->back=d->bottom;
      d->bottom=temp;
      break;
    case 'W':
      temp=d->left;
      d->left=d->top;
      d->top=d->right;
      d->right=d->bottom;
      d->bottom=temp;
      break;
    }
}
int compareAll(dice *d1,dice *d2)
{
  int i,j;
  for(i=0;i<6;i++)
    {
      for(j=0;j<4;j++)
        {
          roll(d1,'E');
          if(compare(d1,d2)==1) return 1;
        }
      if(i%2==0)
        {
          roll(d1,'N');
          roll(d1,'N');
        }
      else if(i==1)
        {
          roll(d1,'N');
        }
      else if(i==3)
        {
          roll(d1,'E');
          roll(d1,'N');
        }
    }
  return 0;
}
int compare(dice *d1,dice *d2)
{
  if(d1->top!=d2->top) return 0;
  if(d1->bottom!=d2->bottom) return 0;
  if(d1->front!=d2->front) return 0;
  if(d1->back!=d2->back) return 0;
  if(d1->right!=d2->right) return 0;
  if(d1->left!=d2->left) return 0;
  return 1;
}


Measured memory_bytes: 2112
#include <stdio.h>
int main(void)
{
    int A, B, C;
    scanf("%d%d%d", &A, &B, &C);
    if (B/A >= C)
    {
        printf("%d\n", C);
    }else
    {
        printf("%d\n", B/A);
    }
    
}

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

const int DIM = 1e5 + 5;

int rnk[DIM], val[DIM], cst[DIM];
vector<pair<int, int>> edg[DIM];

void dfs(int x, int f, bool &ok) {
    if (rnk[x] > 1)
        val[x] *= 2;
    
    for (pair<int, int> y : edg[x]) {
        if (y.first == f)
            continue;
        
        dfs(y.first, x, ok);
        cst[y.second] = val[y.first];
        val[x] -= val[y.first];
    }
    
    ok &= (val[x] >= 0);
    if (!f) ok &= !val[x];
    
    return;
}

int main(void) {
    int n;
    cin >> n;
    
    for (int i = 1; i <= n; ++i)
        cin >> val[i];
    
    for (int i = 2; i <= n; ++i) {
        int x, y;
        cin >> x >> y;
        
        ++rnk[x]; ++rnk[y];
        edg[x].push_back(make_pair(y, i));
        edg[y].push_back(make_pair(x, i));
    }
    
    bool ok = true;
    
    if (n == 2)
        ok = (val[1] == val[2]);
    else {
        int r = 1;
        for (int i = 2; i <= n; ++i)
            if (rnk[i] > 1) r = i;
        
        dfs(r, 0, ok);
        for (int x = 1; x <= n; ++x) {
            if (rnk[x] == 1)
                continue;
            
            int s = 0, mx = 0;
            for (pair<int, int> y : edg[x]) {
                s += cst[y.second];
                mx = max(mx, cst[y.second]);
            }
            
            ok &= (mx <= s / 2);
        }
    }
    
    cout << (ok ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 13952
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	int q,i,p,f;
	char c;
	string s,t[2];
	bool flag = false;
	cin >> s;
	cin >> q;
	for(i=0; i<q; ++i){
		cin >> p; --p;
		if(p){
			cin >> f >> c; --f;
			t[f^flag].push_back(c);
		}else{
			flag = (!flag);
		}
	}
	if(flag){
		reverse(t[1].begin(),t[1].end());
		reverse(s.begin(),s.end());
		cout << t[1] << s << t[0] << endl;
	}else{
		reverse(t[0].begin(),t[0].end());
		cout << t[0] << s << t[1] << endl;
	}
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  int a[n];
  rep(i, n) cin >> a[i];
  int cnt = 0;
  rep(i, n) {
    while (a[i]%2 == 0) {
      a[i] /= 2;
      ++cnt;
    }
  }
  cout << cnt << endl;
  return 0;
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

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

int N, A;
vector<int> x;
int dp[55][55][2555]; // dp[インデックス][枚数][合計] = 総数

signed main() {
  cin >> N >> A;
  x.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> x[i];
  }

  dp[0][0][0] = 1;
  for (int idx = 0; idx < N; idx++) {
    for (int mai = 0; mai < N; mai++) {
      for (int sum = 0; sum < 2555; sum++) {
        // 選ぶ
        if (sum + x[idx] < 2555) {
          dp[idx + 1][mai + 1][sum + x[idx]] += dp[idx][mai][sum];
        }
        // 選ばない
        dp[idx + 1][mai][sum] += dp[idx][mai][sum];
      }
    }
  }

  int ans = 0;
  for (int mai = 1; mai <= N; mai++) {
    for (int sum = 1; sum < 2555; sum++) {
      if (sum == mai * A) {
        ans += dp[N][mai][sum];
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 56576
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var input = ReadLine().Split(' ');
        var num = ToInt32(input[0]);
        var yen = ToInt32(input[1]);

        for (var i = 0; i <= num; i++)
            for (var j = 0; j <= num - i; j++)
            {
                var h = num - i - j;
                var re = 10000 * i + 5000 * j + h * 1000;
                if (re == yen)
                {
                    WriteLine($"{i} {j} {h}");
                    return;
                }
            }
        WriteLine("-1 -1 -1");
    }
}


Measured memory_bytes: 13268
import java.util.Scanner;

class Main {
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		
		int sec,min,hour;
		sec = sc.nextInt();

		hour = sec / 3600;
		min = (sec%3600) / 60 ;
		sec = sec % 60;
		
		System.out.println(hour + ":" + min + ":" + sec);

		
	}
}


Measured memory_bytes: 26200
#include <stdio.h>
#include <stdlib.h>
 
char ht[1<<22];
char key[256];
 
int hash(char *str)
{
     
    int h = 1;
    while(*str) h = (h<<2) + key[*str++];
    return h;
}
 
int main()
{
    int n, i, h;
    char com[8], str[13];
    key['C']=1, key['G']=2, key['T']=3;
    scanf("%d", &n);
    for(i=0; i<n; i++) {
        scanf(" %s %s", com, str);
        h = hash(str);
        if(com[0]=='i') ht[h>>3] |= 1<<(h&7);
        else puts((ht[h>>3] & (1<<(h&7)))?"yes":"no");
    }
 
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
void solve() {
	int N, i; cin >> N >> i;
	cout << (N + 1)  - i  << endl;
	return;
}
int main() {
	solve();
	return 0;
}

Measured memory_bytes: 3640
N = int(input())
L = list(map(int,input().split()))
ans = 0
L.sort()
from bisect import bisect_left
for i in range(N):
    for j in range(i+1,N):
        #三角形の辺を2つ固定する
        t = L[i] + L[j]
        #配列のindexが返される。
        idx = bisect_left(L,t)
        #2番目に長い辺jより長い、かつ、2辺の和よりも小さい辺の数を求める。
        # t自体を含めないため、-1をしている。
        ans += max(0,idx - j -1)
print(ans)

Measured memory_bytes: 3188
sx, sy, tx, ty = map(int, input().split())
ans = ""
ans += 'R' * (tx - sx)
ans += 'U' * (ty - sy)

ans += 'L' * (tx - sx)
ans += 'D' * (ty - sy)

ans += 'D'
ans += 'R' * (tx - sx + 1)
ans += 'U' * (ty - sy + 1)
ans += 'L'

ans += 'U'
ans += 'L' * (tx - sx + 1)
ans += 'D' * (ty - sy + 1)
ans += 'R'

print(ans)

Measured memory_bytes: 9160
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		
		int[] p=new int[3];
		int[] j=new int[2];
		
		for(int i=0; i<3; i++)p[i] = sc.nextInt();
		for(int i=0; i<2; i++)j[i] = sc.nextInt();
		
		int pMin=p[0], jMin=j[0];
		for(int i=1; i<3; i++)if(p[i] < pMin)pMin = p[i];
		for(int i=1; i<2; i++)if(j[i] < jMin)jMin = j[i];
		
		System.out.println(pMin+jMin-50);
	}
}

Measured memory_bytes: 17228
#!/usr/bin/env python3
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from collections import deque
import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)



def main():

    n = int(input())


    data = [list(map(int, list(input()))) for i in range(n)]
    fordfs = [[] for i in range(n)]
    for i in range(n):
        for j in range(n):
            if data[i][j] == 1:
                fordfs[i].append(j)


    def bfs():
        V = [-1]*n
        V[0] = 0
        que = deque()
        que.append(0)
        while que:
            now = que.popleft()
            nowv = V[now]
            for ne in fordfs[now]:
                if nowv == V[ne]:
                    print(-1)
                    exit()
                elif V[ne] == -1:
                    V[ne] = (nowv+1) % 2
                    que.append(ne)


    bfs()
    # print(data)
    G = csgraph_from_dense(data)
    d = floyd_warshall(G)
    d.tolist()
    M = 0
    for i in d:
        M = max(M, max(i))
    M = int(M)
    print(M+1)
    return
if __name__ == '__main__':
    main()


Measured memory_bytes: 28736
#include <cstdio>
#include <cstring>
#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) REP(i,0,n)

int a[] = { 1, 5, 10, 50, 100, 500 };
int N[6];
int ret[666667];

int min(int x, int y) { return x < y ? x : y; }

int main()
{
	const int inf = 1000000000;
	REP(p, 1, 666667) if (!ret[p]) {
		int t = p;
		rep(i, 6) { int k=t/a[5-i]; ret[p]+=k; t-=k*a[5-i]; }
	}
	int P;
	while (scanf("%d", &P), P) {
		int s = 0;
		rep(i, 6) { scanf("%d", N+i); s += a[i] * N[i]; }

		int res = inf;
		REP(p, P, s+1) {
			int t = p;
			int pay = 0;
			rep(i, 6) { int k=min(N[5-i], t/a[5-i]); pay+=k; t-=k*a[5-i]; }
			if (!t) res = min(res, pay+ret[p-P]);
		}
		printf("%d\n", res);
	}
	return 0;
}

Measured memory_bytes: 3368
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

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

using namespace std;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

struct Puzzle{
  int field[9];
  int space;
  int turn;

  bool operator < (const Puzzle& a) const{
    rep(i, 9){
      if(a.field[i] == field[i]) continue;
      return field[i] >  a.field[i];
    }
    return false;
  }
};

bool check(Puzzle p){
  rep(i, 9){
    if(p.field[i] != i+1) return false;
  }
  return true;
}

int solve(Puzzle in){
  queue<Puzzle> q;  
  map<Puzzle, bool> mp;

  q.push(in);
  mp[in] = true;
  
  // bfs
  while(!q.empty()){
    Puzzle p = q.front(); q.pop();
    if(check(p)) return p.turn;
    int x = p.space % 3;
    int y = p.space / 3;
    rep(i, 4){
      int nx = x + dx[i];
      int ny = y + dy[i];
      if(nx < 0 || 2 < nx || ny < 0 || 2 < ny) continue;
      Puzzle tmp = p;
      swap(tmp.field[p.space], tmp.field[3 * ny + nx]);
      tmp.space = 3 * ny + nx;
      if(mp[tmp] == false){
    mp[tmp] = true;
    tmp.turn++;
    q.push(tmp);
      }
    }
  }
  return -1;
}

signed main(){
  Puzzle in;
  
  rep(i, 9){
    cin >> in.field[i];
    if(in.field[i] == 0){
      in.field[i] = 9;
      in.space = i;
    }    
  }

  in.turn = 0;
  cout << solve(in) << endl;
}

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

using namespace std;

struct vw_pair {
    int v, w;
    vw_pair(int v,int w) : v(v), w(w) {};
};

typedef pair<int, int> ii;
typedef vector <ii> vii;
typedef vector<int> vi;
typedef vector <string> vs;
typedef vector <vi> vvi;
typedef vector <vector<vw_pair>> adj_list;
typedef vector <bool> vb;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef priority_queue<int> max_heap_int;
typedef priority_queue<int, vi, greater<>> min_heap_int;

#define isOn(S, j) (S & (1<<j))
#define setBit(S, j) (S |= (1<<j))
#define clearBit(S, j) (S &= ~(1<<j))
#define toggleBit(S, j) (S ^= (1<<j))
#define lowBit(S) (S & (-S))
#define setAll(S, n) (S = (1<<n)-1)
#define modulo(S, N) ((S) & (N-1))   // returns S % N, where N is a power of 2
#define isPowerOfTwo(S) (!(S & (S-1)))
#define nearestPowerOfTwo(S) ((int)pow(2.0, (int)((log((double)S) / log(2.0)) + 0.5)))
#define turnOffLastBit(S) ((S) & (S-1))
#define turnOnLastZero(S) ((S) | (S+1))
#define turnOffLastConsecutiveBits(S) ((S) & (S+1))
#define turnOnLastConsecutiveZeroes(S) ((S) | (S-1))
#define in_range(lo, hi, x) ((x >= lo && x <= hi))

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

    int n;
    cin >> n;
    vl b(n-1);
    for (int i=0;i<(n-1);++i) cin >> b[i];
    ll s = 0;
    if (n == 2) {
        cout << 2 * b[0] << "\n";
        return 0;
    }
    for (int i=0;i<(n-1);++i) {
        if (i == 0) {
            s += (min(b[i], b[i+1]));
            s += b[i];
        }
        else {
            ll k = b[i];
            if (i+2 < n) k = min(b[i], b[i+1]);
            s += k;
        }
    }

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

Measured memory_bytes: 256
#include<map>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<stack>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
typedef long long ll;
using namespace std;
ll const MAX = 100005;

ll a[MAX];
ll b[MAX];

ll f(ll x,ll i) {
	ll v = 1;
	ll ans = 0;
	while (x > v) {
		v *= 2;
		ans++;
	}
	b[i] = (x != v);
	return ans;
}

int main() {
	ll n;
	cin >> n;
	REP(i, 1, n) {
		ll x;
		cin >> x;
		a[i] = f(x, i);
	}
	ll cur = 0;
	ll ans = 0;
	REP(i, 1, n) {
		if (a[i] <= cur) {
			cur = a[i] - b[i];
		}
		else if(a[i] > cur){
			ans += a[i] - cur;
			cur = a[i];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  long n, a, b;
  readf("%s %s %s\n", &n, &a, &b);
  auto d = b - a;
  if (d % 2) {
    writeln(min(a - 1, n - b) + 1 + (d / 2));
  } else {
    writeln(d / 2);
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
using namespace std;
 
int main(){

    string S;
    int c[3]={};

    cin >> S;

    for(int i=0;i<=3;i++){
        if(S[i]=='a'){
            c[0]+=1;
        }else if(S[i]=='b'){
            c[1]+=1;
        }else if(S[i]=='c'){
            c[2]+=1;
        }
    }

    if(c[0]==1&&c[1]==1&&c[2]==1){
        cout << "Yes"<<endl;
    }else{
        cout << "No"<<endl;
    }

    return 0;


}

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

int main()
{
  string N;
  cin >> N;
  
  int ans = 0;
  for (int i = 0; i < 4; i++)
  {
    if (N.at(i) == '2') ans++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>                                                                                                                                                                            
                                                                                                                                                                                              
int main() {                                                                                                                                                                                  
    int N;                                                                                                                                                                                    
    scanf("%d", &N);                                                                                                                                                                          
    if (N % 2 == 0) printf("%d\n", N);                                                                                                                                                        
    else printf("%d\n", 2 * N);                                                                                                                                                               
}                          

Measured memory_bytes: 128
def main():
    import numpy as np
    n,m=map(int,input().split())
    A=list(map(int,input().split()))
    A.sort()
    A=np.array(A)

    def cnt_shake(x): #握手の組であって合計パワーがx以上となる組みの数
        return n**2-np.searchsorted(A,x-A).sum()
  
    right=10**10*1
    left=-10**10-1
    while right-left>1:
        mid=(left+right)//2
        if cnt_shake(mid)<m:
            right=mid
        else:
            left=mid
    
    border=left  #border以上の握手をする
    C=n-np.searchsorted(A,border+1-A)
    B=np.cumsum(A[::-1])
    #print(border,A,B,C)

    s,cnt=0,0
    for i in range(n):
        if C[i]>0:
          cnt+=C[i]
          s+=B[C[i]-1]+A[i]*C[i]
    s+=border*(m-cnt)

    print(s)
if __name__=='__main__':
    main()


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

int main()
{
    int n,m,c;
    cin>>n>>m>>c;
    int arr[n][m],emm[m];
    ref(i,m)
    cin>>emm[i];
    ref(i,n)
    {
        ref(j,m)
        {
            cin>>arr[i][j];
        }
    }
    int count = 0,temp=  0;
    ref(i,n)
    {   
        temp = 0;
        ref(j,m)
        {
           temp += arr[i][j]*emm[j];
        }
        if(temp+c > 0)
            ++count;
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 3572
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {

			// Streamを挟まないほうが早いかテスト

			int n = Integer.parseInt(br.readLine());
			int[] S = new int[n];
			String[] tmp = br.readLine().split(" ");
			for (int i = 0; i < n; i++) {
				S[i] = Integer.parseInt(tmp[i]);
			}
			int q = Integer.parseInt(br.readLine());
			tmp = br.readLine().split(" ");
			Main m = new Main();
			int cnt = 0;
			for (int i = 0; i < q; i++) {
				int key = Integer.parseInt(tmp[i]);
				if (m.binarySearch(S, key) != -1)
					cnt++;
			}
			System.out.println(cnt);

		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	int binarySearch(int[] S, int key) {
		int left = 0;
		int right = S.length;
		while (left < right) {
			int mid = (left + right) / 2;
			if (key == S[mid]) {
				return mid;
			} else if (key < S[mid]) {
				right = mid;
			} else {
				left = mid + 1;
			}
		}
		return -1;
	}

}



Measured memory_bytes: 51716
N = int(input())
B = list(map(int,input().split()))

res = 0
for i in range(N):
    if i == 0:
        res += B[0]
    elif i == N-1:
        res += B[N-2]
    else:
        res += min(B[i-1],B[i])
print(res)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll mod = 1e9 + 7;

int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}

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

ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}

int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};


//////////////////////////////////////////////////////////////////////////////////////b,cl
int main(){
    int64_t n,k;
    cin >> n >> k;

    int64_t num = n / k;

    int64_t ans = n - num*k;

    ans = min(abs(ans-k),ans);

    cout << ans << endl;
}


Measured memory_bytes: 256
////////////////////////////////////////////    _LeMur_
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <chrono>
#include <random>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <list>
#include <map>
#include <set>

using namespace std;

const int N = 100005;
const int inf = 1000 * 1000 * 1000;
const int mod = 998244353;

int a;
string s;

int main(){
	mt19937 myrand(chrono::steady_clock::now().time_since_epoch().count());
    cin >> a >> s;
    if(a >= 3200)
        cout << s << endl;
    else
        cout << "red" << endl;
    return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
    string a, b;
    cin >> a >> b;
    int x = stoi(a + b);
    for (int i = 1; i < 1000; i++) {
        if (i*i == x) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>
#include <cstring>

using namespace std;

const int INF = 1 << 29;
typedef long long ll;
typedef pair<int,int> PI;

int W, Q;

int main(void){
	while(cin >> W >> Q, W|Q){
		int cat[100];
		int fence[100];
		memset(fence, -1, sizeof(fence));
		for(int i=0; i<Q; ++i){
			char c;
			cin >> c;
			if(c == 's'){
				int id, pos;
				bool sleep = false;
				cin >> id;
				cin >> cat[id];
				for(int j=0; j<W-cat[id]+1; ++j){
					for(int k=0; k<cat[id]; ++k){
						if(fence[j+k] != -1){
							break;
						}
						if(k == cat[id]-1){
							sleep = true;
							pos = j;
						}
					}
					if(sleep) break;
				}

				if(sleep){
					for(int j=pos; j<pos+cat[id]; ++j){
						fence[j] = id;
					}
					cout << pos << endl;
				} else {
					cout << "impossible" << endl;
				}
			}
			if(c == 'w'){
				int id;
				cin >> id;
				for(int j=0; j<W; ++j){
					if(fence[j] == id){
						fence[j] = -1;
					}
				}
			}
		}
		cout << "END" << endl;

	}

	return 0;
}

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

#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int m = 50;
const long long mod = 1e9 + 7;

void multiply(long long a[][m], long long b[][m], int d)
{
    long long c[m][m];
    for(int i=0; i<d; i++)
    {
        for(int j=0; j<d; j++)
        {
            long long sum = 0;
            for(int k=0; k<d; k++)
            {
                sum  += a[i][k]*b[k][j];
                sum %= mod;
            }
            c[i][j] = sum%mod;
        }
    }
    for(int i=0; i<d; i++)
    {
        for(int j=0; j<d; j++)
            a[i][j] = c[i][j];
    }
}

void matrixexpo(long long a[][m], int d, long long p)
{
    long long I[m][m];
    memset(I,0,sizeof(I));
    for(int i=0; i<d; i++) I[i][i] = 1;

    while(p)
    {
        if(p&1) multiply(I,a,d);
        p >>= 1;
        multiply(a,a,d);
    }
    for(int i=0; i<d; i++)
    {
        for(int j=0; j<d; j++)
            a[i][j] = I[i][j];
    }
}

int main()
{
    FASTIO
    int n; long long arr[m][m], k;
    cin >> n >> k;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
            cin >> arr[i][j];
    }
    matrixexpo(arr,n,k);
    long long sum = 0;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
        {

            sum += arr[i][j];
            sum %= mod;
        }
    }
    cout << sum << "\n";

    return 0;
}

Measured memory_bytes: 3664
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
int main() {
  long long n,ans=0;
  cin >> n;
  long long b[n-1]={};
  for(int i=0; i<n-1; i++) {
    cin >> b[i];
  }
  reverse(b,b+n-1);
  ans+=b[0];
  for(int i=0; i<n-1; i++) {
    ans+=min(b[i],b[i+1]);
  }
  cout << ans << endl; 
}


Measured memory_bytes: 256
N, K = map(int, input().split())
X = list(map(int, input().split()))

ans = float('inf')
for l in range(N - K + 1):
    r = l + K - 1

    if X[l] < 0 and X[r] <~ 0:
        ans = min(ans, abs(X[l]))
    elif X[l] >= 0 and X[r] > 0:
        ans = min(ans, X[r])
    else:
        ans = min(ans, abs(X[l]) + X[r] + min(abs(X[l]), X[r]))


print(ans)

Measured memory_bytes: 20284
from collections import Counter

class Factorize:
    def __init__(self):
        self.primes = Counter()

    def add_target(self, n):
        for i in range(2, int(n**0.5)+1):
            while n%i==0:
                self.primes[i] += 1
                n //= i
            if not n:
                break
        if n>1:
            self.primes[n] += 1
    
    def get_result(self):
        return dict(self.primes)

N, P = map(int, input().split())
fact = Factorize()
fact.add_target(P)
d = fact.get_result()
ans = 1
for i, j in d.items():
    ans *= pow(i, j//N)
print(ans)


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

using namespace std;

const int N = 300004;
int cnth[N], cntw[N], x[N], y[N];
map <int, bool> mp[N];

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int h, w, m;
    cin >> h >> w >> m;
    for (int i = 0; i < m; i++) {
        cin >> x[i] >> y[i];
        mp[x[i]][y[i]] = true;
        cnth[x[i]]++, cntw[y[i]]++;
    }
    int mxh = 0, mxw = 0;
    for (int i = 0; i < N; i++) {
        mxh = max(mxh, cnth[i]);
        mxw = max(mxw, cntw[i]);
    }
    vector <int> hall, wall;
    for (int i = 0; i < N; i++) {
        if (cnth[i] == mxh) {
            hall.push_back(i);
        }
        if (cntw[i] == mxw) {
            wall.push_back(i);
        }
    }
    int cnt = 0, mx = 0;
    for (int i = 0; i < hall.size(); i++) {
        for (int j = 0; j < wall.size(); j++) {
            cnt++;
            if (cnt > N * 2)
                break;
            mx = max(mx, mxh + mxw - mp[hall[i]][wall[j]]);
        }
        if (cnt > N * 2)
            break;
    }
    cout << mx;
}

Measured memory_bytes: 66584
n, y = gets.split(' ').map(&:to_i)

res_a = -1
res_b = -1
res_c = -1

(0..n).each{|a|
  (0..(n-a)).each{|b|
    c = n - a - b
    if 10000 * a + 5000 * b + 1000 * c == y
      res_a = a
      res_b = b
      res_c = c
    end
  }
}

puts [res_a,res_b,res_c].join(" ")

Measured memory_bytes: 1916