akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int n,now;
struct V {
	int c,r;
	bool operator<(const V a)const {
		return r>a.r;
	}
} A[200005];
int main() {
	scanf("%d",&n);
	for(int i=1; i<=n; i++)
		scanf("%d %d",&A[i].c,&A[i].r);
	sort(A+1,A+n+1);
	now=A[1].r;
	for(int i=1; i<=n; i++) {
		if(now>A[i].r)now=A[i].r;
		now-=A[i].c;
	}
	if(now<0)printf("No");
	else printf("Yes");
	return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <utility>
#include <math.h>
#include <stdexcept>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string.h>
#include <cassert>
#include <string.h>
#include <tuple>

using namespace std;
#define  rep(i,n) for(int i=0;i<n;i++)
#define  rrep(i,n) for(int i=n-1;i>=0;i--)///n-1番目からn回
#define  REP(i,a,b) for(int i=a;i<=b;i++) ///a番目からb回
#define  RREP(i,a,b) for(int i=a;i<b;i--)
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pair_t;
#define MOD 1000000007

//int arr[N]
////sort(arr,arr +N)

//vector <int> hoge
////sort(hoge.begin(),hoge.end());
///*min_element(hoge.begin(),hoge.end();　最小値　　　最大値はmax_element();
///(10-(n%10))%10  10-(1桁目)取得 12->8 20->0

#define Ru(n)  ( ((n)+9)/10*10  ) //切りあげ
#define Rd(n)  ( ((n)-10)/10*10 +10 )	切り捨て


int gcd(int a,int b);
size_t length(const std::string& str) {
	return str.length();
}
bool comp(const pair_t &a, const pair_t &b) {
	return a.first < b.first;
}

int main() {

	int n,L,sum,ans=0;
	cin>>n>>L;
	sum=(L+(L+(n-1)))*n/2;
	if(L>0)
		ans=sum-L;
	else{
		if(L+n-1>0)
			ans=sum;
		else
			ans=sum-(L+n-1);
	}
	cout<<ans<<endl;
	return 0;

}


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


Measured memory_bytes: 256
import java.util.*;

class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        if(a==b){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21844
import math
n=int(input())
c=[]
s=[]
f=[]
for i in range(n-1):
    ci,si,fi=list(map(int,input().split()))
    c.append(ci)
    s.append(si)
    f.append(fi)

for start in range(n-1):
    time=0
    for i in range(start,n-1):
        time=max(s[i],math.ceil(time/f[i])*f[i])+c[i]
    print(time)
print(0)

Measured memory_bytes: 3188
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
s = 0
B = [0]
C = {0:[0]}
for i, a in enumerate(A):
    s = (s+a)%K
    n = (s-i-1)%K
    B.append(n)
    if n not in C: C[n] = []
    C[n].append(i+1)

ans = 0

for k, v in C.items():
    if len(v)<=1: continue
    ans_k = 0
    ir=0
    for il in range(0,len(v)-1):
        l = v[il]
        while(ir<len(v) and v[ir]-l<=K-1): ir+=1
        ans_k+=(ir-1)-il
    ans+=ans_k
print(ans)

Measured memory_bytes: 62116
s = input()
l = len(s)
x = 0
y = 0
if (l/2)%2==0:
  a="01"*(l//2)
  b="10"*(l//2)
else:
  a="01"*(l//2)+"0"
  b="10"*(l//2)+"1"
for i in range(l):
  if s[i]!=a[i]:
    x+=1
  if s[i]!=b[i]:
    y+=1
print(min(x,y))

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

int N, A, B, C, X;
int Y[110];

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

    while(true){
        std::cin >> N >> A >> B >> C >> X;
        if(!N){break;}

        for(int i=0;i<N;++i){
            std::cin >> Y[i];
        }

        int t = 0, idx = 0;
        while(t <= 10000){
            if(Y[idx] == X){
                ++idx;
            }

            if(idx == N){
                break;
            }

            ++t;
            X = (A * X + B) % C;
        }

        int res = t <= 10000 ? t : -1;
        std::cout << res << std::endl;
    }
}



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

int main() {
  int s, x;
  cin >> s;
  int m = s - ((s / 100 * 100) + (s % 2 * 1));
  x = s / 100 + m / 10 + s % 2;
  cout << x << endl;
}

Measured memory_bytes: 256
import Control.Monad
import Control.Applicative
import Data.List

data Dice = Dice{tp::Int, fr::Int, rt::Int, lt::Int, bk::Int, bm::Int} deriving (Show, Eq)

roll :: Dice -> Char -> Dice
roll (Dice tp fr rt lt bk bm) dir
  | dir == 'N' = Dice fr bm rt lt tp bk
  | dir == 'S' = Dice bk tp rt lt bm fr
  | dir == 'E' = Dice lt fr tp bm bk rt
  | dir == 'W' = Dice rt fr bm tp bk lt
  | otherwise = Dice tp fr rt lt bk bm

rolls :: Dice -> String -> Dice
rolls d s = foldl roll d s

initDice :: [Int] -> Dice
initDice [tp, fr, rt, lt, bk, bm] = Dice tp fr rt lt bk bm

setDice :: Dice -> Int -> Int -> Dice
setDice d t f = d2
  where
    d1 = head . filter (\x -> tp x == t) $ scanl roll d "NENEN"
    d2 = head . filter (\x -> fr x == f) $ scanl rolls d1 ["NES","NES","NES"]

main = do
  xs <- map read . words <$> getLine :: IO [Int]
  n <- readLn :: IO Int
  ys <- map (map read . words) <$> replicateM n getLine :: IO [[Int]]
  mapM_ print $ solve xs ys

solve :: [Int] -> [[Int]] -> [Int]
solve xs ys = map rt $ map (f (setDice d)) ys
  where d = initDice xs
        f g [i, j] = g i j

Measured memory_bytes: 3984
#include <stdio.h>
int main()
{
    int i, n, k;
    char a;
    char b[20];
    scanf("%d", &n);
    scanf("%s", b);
    scanf("%d", &k);
    a = b[k - 1];
    for (i = 0; i < n; i++)
    {
        if (b[i] != a)
            b[i] = '*';
    }
    printf("%s\n", b);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
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; }
ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a*b/gcd(a,b);}
ll MOD=1000000007;

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

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []
l = [0] * (10**5+1)
for i in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

for i in range(len(A)):
    l[A[i]] += 1
ans = 0
for i in range(1, len(l)):
    ans += l[i]*i
for i in range(Q):
    tmp = l[B[i]]
    tmp2 = tmp * B[i]
    l[C[i]] += tmp
    tmp3 = tmp * C[i]
    l[B[i]] = 0
    ans += tmp3 - tmp2
    print(ans)





Measured memory_bytes: 23532
while 1:
 m,f,r=map(int,input().split())
 if m==f==r==-1:break
 if m==-1 or f==-1:print('F')
 elif m+f>79:print('A')
 elif m+f>64:print('B')
 elif m+f>49:print('C')
 elif m+f>29:print('C') if r>49 else print('D')
 else:print('F')

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

int f(int d,int i){
  int s;

  s = d * i;

  return s * s;
}

int main(){
  int d, sum;

  while(scanf("%d", &d) != -1){
    sum = 0;

    for(int i = 1;d * i < 600;i++){
      sum = sum + f(d, i) * d;
    }

    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 1208
#include<iostream>
#include<cmath>
using namespace std;
int main(){
    long long a,b;cin >> a >> b;
    if(a < b){
        long long q = a;
        a = b;
        b = q;
    }
    long long x = a * b;
    long long r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    cout << x/b << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define  ll   long long int
#define  sz   200010

using namespace std;

ll r[sz];
ll g[sz];
ll b[sz];

map<char,ll>mp;

ll tani(ll a,ll bb,string s,ll xx,ll y,string sx)
{
    ll i,j,k,d,p;
    mp.clear();

    for(i=0; i<2; i++)
    {
        mp[s[i]]=1;
    }
    string x="RGB";

    p=y-xx;

    y=y+p;
ll    l=sx.length();


    for(i=0; i<3; i++)
    {
        if(mp[x[i]]==0)
        {
            if(x[i]=='R')
            {
                d=r[bb]-r[a-1];
                if(sx[y]=='R' && y<l)d--;
                break;
            }
            if(x[i]=='G')
            {
                d=g[bb]-g[a-1];
                if(sx[y]=='G' && y<l)d--;
                break;
            }
            if(x[i]=='B')
            {
                d=b[bb]-b[a-1];
                if(sx[y]=='B' && y<l)d--;
                break;
            }

        }
    }

    return d;

}
int main()
{

    ll n,i,j,x,y,z,d,k,p,l;

    string s,ss;

    cin>>n;
    cin>>s;

    l=s.length();

    x=0;
    y=0;
    z=0;

    for(i=0; i<l; i++)
    {
        if(s[i]=='R')
            x++;
        else if(s[i]=='G')
            y++;
        else
            z++;

        r[i]=x;
        g[i]=y;
        b[i]=z;
    }



    p=0;

    for(i=0; i<l; i++)
    {
        for(j=i+1; j<l-1; j++)
        {
            if(s[i]!=s[j])
            {
                ss=s[i];
                ss+=s[j];
               // cout<<ss<<endl;
                //cout<<i<<" "<<j<<endl;


                x=j+1;
                y=l-1;
                d=tani(x,y,ss,i,j,s);
                p+=d;

            }

        }
    }

    cout<<p<<endl;



    return 0;
}


Measured memory_bytes: 3688
import sys
sys.setrecursionlimit(1000000)

def neighbor(N, edges):
    neighbor_list = [[] for _ in range(N)]
    for a, b in edges:
        neighbor_list[a-1] += [b-1]
        neighbor_list[b-1] += [a-1]
        
    return neighbor_list


def paint(K, nlist, now_num, from_num, case_num):
        mod = 1000000007
        if  from_num == -1:
            can_use_color = K - 1
        else:
            can_use_color = K - 2
        
        if len(nlist[now_num]) - 1 > can_use_color:
            return 0
        
        for child in nlist[now_num]:
            if child == from_num:
                continue
            else:
                case_num *= can_use_color
                can_use_color -= 1
                case_num %= mod
        
        for child in nlist[now_num]:
            if child == from_num:
                continue
            else:
                case_num = paint(K, nlist, child, now_num, case_num)
        return case_num%mod
            

if __name__ == '__main__':
    N, K = map(int, input().split())
    edges = [None]*(N-1)
    
    for i in range(N-1):
        edges[i] = list(map(int, input().split()))
    
    nlist = neighbor(N, edges)


    print(paint(K, nlist, 0, -1, K))

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

using namespace std;

int main() {
  int n, din, sum, flag, diff;
  vector<int> v;

  cin >> n;

  sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> din;
    sum += din;
    v.push_back(din);
  }

  //cout << sum << endl;
  flag = 1;
  for (int i = 0; i < n; i++) {
    diff = sum - v[i];
    if (diff <= v[i]) {
      flag = 0;
    }
  }

  if (flag) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int K, S, z=0, ans=0;
    cin >> K >> S;
    for(int x=0; x<=K; x++){
        for(int y=0; y<=K; y++){
            z=S-(x+y);
            if(z <= K && z >= 0) ans++;
        }
    }
    cout << ans << endl;
    
}


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

int main() {
  int N, K, ans = 0;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    // robot A
    if (x <= K / 2) {
      ans += 2 * x;
    } 
    // robot B
    else {
      ans += 2 * (K - x);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
a = []
b = []
for _ in range(n):
    a.append(list(map(int, input().split())))

a.sort()
ans = 0
for _a, _m in a:
    if _m <= m:
        ans += _m * _a
        m -= _m
    else:
        ans += m * _a
        m = 0
        break

print(ans)


Measured memory_bytes: 27888
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

using namespace std;

int main(){
    int N;
    while(cin >> N){
        map<string, int> mp;
        int m = 0;
        for(int i=0;i<N;i++){
            string s; cin >> s;
            if(!mp.count(s)) mp[s] = 0;
            ++mp[s];
            m = max(m, mp[s]);
        }
        vector<string> vs;
        for(auto it : mp){
            if(it.second == m) vs.push_back(it.first);
        }
        sort(vs.begin(), vs.end());
        for(auto& s : vs) cout << s << endl;
    }
}

Measured memory_bytes: 26868
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define t(x) cerr<<#x<<":"<<x<<'\n';
#define t2(a,n) { cerr<<#a<<" = "; for(int i=0; i<n; ++i){ cerr << a[i] << ' '; } ; cerr <<'\n'; }
#define t3(a){ cerr<<#a<<" = "; for(auto i: a){ cerr<<i<<" "; } cerr<<'\n'; }



int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	map<int,int> cnt;
	int n;
	cin>>n;
	for(int i=0; i<n; ++i){
		int x; cin>>x;
		cnt[x]++;
	}
	priority_queue<pair<int,int>> pq;
	for(auto i : cnt ){
		pq.push({i.second,i.first});
	}
	while(true){
		if( pq.empty() ){ break; }
		if( pq.top().first == 1 ){ break; }
		auto get = pq.top(); pq.pop();
		if( get.first >= 3 ){ pq.push({ get.first - 3 + 1, get.second}); }
		else if( get.first == 2 ){
			auto get2 = pq.top(); pq.pop();
			if( get2.first - 1 > 0 ){ 
				pq.push({get2.first-1, get2.second});
			}
			pq.push({get.first-1, get.second});
		}
	}
	cout<<pq.size()<<endl;

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


Measured memory_bytes: 6140
#include<cstdio>
#include<stdlib.h>
#include<iostream>

using namespace std;

const int maxn = 50001;
const int maxm = 21;

int main(){
	int n,m;
	int T[50001];
	int S[maxm];
	
	cin >> n >> m;
	for(int i = 0;i < m;i++)cin >> S[i];
	
	for(int i = 0;i <= n;i++)T[i] = i;
	
	for(int j = 1;j < m;j++){
		for(int i = 1;i <= n;i++){
			if(i - S[j] < 0)continue;
			else T[i] = (T[i] > T[i - S[j]] + 1)?T[i - S[j]] + 1:T[i];
		}
//		for(int s = 1;s <= n;s++)cout << T[s] << " ";
//		cout << endl;
	}
	cout << T[n] << endl;
}


Measured memory_bytes: 3288
N,M = map(int,input().split())
H = list(map(int,input().split()))
d = {}
s = []

for _ in range(M):
    ab = list(map(int,input().split()))
    if ab[0] in d.keys():
        d[ab[0]] = max(d[ab[0]],H[ab[1]-1])
    else:
        d[ab[0]] = H[ab[1]-1]
    if ab[1] in d.keys():
        d[ab[1]] = max(d[ab[1]],H[ab[0]-1])
    else:
        d[ab[1]] = H[ab[0]-1]
    s.append(ab[0])
    s.append(ab[1])

count = 0
for i in d.keys():
    if H[i-1] > d[i]:
        count += 1

count += N - len(set(s))

print(count)

Measured memory_bytes: 30748
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef complex<double> comp;
const ll INF=1e9+7;
const ll inf=INF;
const ll MOD=998244353;
const int MAX=200010;

ll gcd(ll a,ll b){
    if(a>b){
        swap(a,b);
    }
    if(a==0)return b;
    return gcd(a,b%a);
}
ll rui(ll a,ll b,ll mod){
    ll res=1;
    ll x=a;
    while(b){
        if(b&1)res=res*x%mod;
        x=x*x%mod;
        b/=2;
    }
    return res;
}
long long extGCD(long long a,long long mod,long long &x,long long &y){
    if(mod==0){
        x=1;
        y=0;
        return a;
    }
    long long d=extGCD(mod,a%mod,y,x);
    y-=(a/mod)*x;
    return d;
}
long long invmod(long long a,long long mod){
    long long x,y;
    extGCD(a,mod,x,y);
    x%=mod;
    if(x<0)x+=mod;
    return x;
}
signed main(){
    ll n;cin>>n;
    if(n==1){
        cout<<1<<endl;
        return 0;
    }
    n=n*2LL;
    vector<pll>p(0);
    REP(i,1,sqrt(n)+1){
        if(n%i==0){
            p.pb(mp(i,n/i));
        }
    }
    ll ans=n-1;
    rep(i,p.size()){
        ll a=p[i].fi,b=p[i].se;
        if(gcd(a,b)>1)continue;
        if(a==1)continue;
        if(a>1){
            ll q=invmod(b,a);
            if(q<0)q+=a;
            ans=min(ans,b*q-1);
        }
        if(b>1){
            ll q=invmod(a,b);
            if(q<0)q+=b;
            ans=min(ans,a*q-1);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3848
#include <bits/stdc++.h>
#define st first
#define nd second

using namespace std;

void debug_out() { cerr << endl; }
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...);}

#define dbg(...) cerr << #__VA_ARGS__ << " ->", debug_out(__VA_ARGS__)
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(long long _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

const long long N = 2010;
const long long MOD = 1e9 + 7;
long long n, s[N], t[N], dp[N][N], ans, m;

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n >> m;
	for(long long i = 1; i <= n; i++) cin >> s[i];
	for(long long i = 1; i <= m; i++) cin >> t[i];

	dp[0][0] = 1;
	for(long long i = 1; i < N; i++) dp[i][0] = dp[0][i] = 1;

	for(long long i = 1; i <= n; i++)
		for(long long j = 1; j <= m; j++) {
			dp[i][j] = (s[i] == t[j]) * ( dp[i - 1][j - 1]);
			dp[i][j] += MOD + dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1];
			dp[i][j] %= MOD;
		}
		cout << dp[n][m];
}	

	

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

//#pragma GCC optimize ("Ofast")
//#pragma GCC target ("avx,avx2")

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define debug(x) cerr<<#x<<" : "<<x<<endl

typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;
const ll INF = 1e18+1;
const ll MOD = 1000000007L;
clock_t time_p=clock();
void timer(){time_p=clock()-time_p;cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";}

ll memo[51][51];


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

    ll n,k;
    cin>>n>>k;
    rep(i,n+1){
        rep(j,k+1){
            memo[i][j] = -1;
        }
    }

    cout<<n-k+1<<endl;

    timer();
    return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc158/tasks/abc158_b

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

int main()
{
    long long n, a, b;
    cin >> n >> a >> b;
    long long ans = 0;
    ans += (n / (a + b)) * a;
    ans += min(a, (n % (a + b)));

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


Measured memory_bytes: 3636
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

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

    string s;
    cin >> s;

    ll cnt = 0;
    rep(i, n-1){
        if(s[i] == s[i+1])cnt++;
    }

    cout << min(n-1, cnt+2*k) << endl;
}

Measured memory_bytes: 3752
#!/usr/bin/perl

use strict;
use warnings;

my $s = <STDIN>;
chomp $s;

my $ans = 0;
for (my $i=0; $i<length($s)/2; $i++) {
    if (substr($s, $i, 1) ne substr($s, length($s)-1-$i, 1)) {
        $ans++;
    }
}

print "$ans\n";

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }
  
};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }  
};


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  string S;
  cin >> S;
  if(S=="RRR"){
    cout << 3;
  }else{
    if(S.substr(0, 2)=="RR" or S.substr(1, 2)=="RR"){
      cout << 2;
    }else{
      if(S.find("R")!=string::npos){
        cout << 1;
      }else{
        cout << 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3624
#include "bits/stdc++.h" // {{{
using namespace std; typedef long long ll; typedef pair<int,int> pii;
#define val         const auto
#define eb          emplace_back
#define emp         emplace
#define fi          first
#define se          second
#define outl(x)     cout << (x) << '\n'
#define rep(i,n)    for(int i=0; i < (int)(n); ++i)
#define repr(i,h,l) for(int i=(h); i >= (int)(l); --i)
#define ALL(x)      begin(x), end(x)
#define TMPLT(T,U)  template<class T, class U>
#define ten(p)      ((long long)(1e##p))
#define FILL(a,v)   memset((a), (v), sizeof(a))
#ifdef  DEBUG
#define debug(...)  fprintf(stderr, __VA_ARGS__)
#define show(x)     clog << #x << " \t\t= " << (x) << '\n'
#define show2(x,y)  clog << '(' << #x << ',' << #y << ")\t\t= " << '(' << (x) << "\t, " << (y) << ")\n"
#define LN()        fputs("\n--------------------------------\n", stderr)
#else
#define debug(...)
#define show(x)
#define show2(x,y)
#define LN()
#endif
#define def(op) inline bool operator op (const T &that) const { return comp(that) op 0; }
template<class T> struct Ordered
{ virtual int comp(const T &that) const = 0; def(==); def(!=); def(<); def(<=); def(>); def(>=); };
#undef def
namespace {
  TMPLT(T,U) inline constexpr common_type_t<T,U> gcd(T x, U y)
  { return (x<y)? gcd(y,x) : (y <= 0)? x : gcd(y, x % y); }
  TMPLT(T,U) inline bool chmax(T &a, const U &b){return b>a ? a=b,1 : 0;}
  TMPLT(T,U) inline bool chmin(T &a, const U &b){return b<a ? a=b,1 : 0;}
  TMPLT(T,U) inline constexpr ll lcm(T x, U y) { return (ll)x/gcd(x,y) * y; }
  template<class Itr> string mkString(Itr begin, Itr end, const char *sp = " ") {
    static ostringstream oss; oss.str("");
    for(Itr i=begin; i != end; ++i) { if(i != begin)oss << sp; oss << *i; }
    return oss.str();
  }
  constexpr int INF = 0x3f3f3f3f; constexpr ll LINF = 0x3f3f3f3f3f3f3f3fLL;
  // }}}

constexpr int MX = ten(5) + 10;

typedef vector<int> vint;

vint getPrimeFactor(int n)
{
  int p = 2;
  vint ret;
  while(n > 1) {
    if (n % p == 0) {
      while(n % p == 0) { n /= p; ret.eb(p); }
    }
    ++p;
  }
  return ret;
}

void test()
{
  int n;
  cin >> n;
  vint rec = getPrimeFactor(n);
  outl( mkString(ALL(rec), "\n") );
}

int cnt[100];
int dp[105][80];

int slv(int idx, int mul)
{
  if (mul == 75) { return 1; }
  if (idx > 101) { return 0; }
  if (mul > 75)  { return 0; }

  int &ret = dp[idx][mul];
  if (~ret) return ret;

  ret = 0;
  for (int take = 0; take <= cnt[idx]; ++take) {
    ret += slv(idx+1, mul * (take + 1));
  }
  return ret;
}

void _main(const vector<char*> &args)
{
  int N; cin >> N;

  for (int i = 2; i <= N; ++i) {
    const vint &rec = getPrimeFactor(i);
    for (val e : rec) { ++cnt[e]; }
  }

  FILL(dp, -1);
  int ans = slv(0, 1);
  outl(ans);
}

} // {{{
signed main(signed argc, char *argv[]) {
#ifndef DEBUG
  ios::sync_with_stdio(false); cin.tie(nullptr);
#endif
  cout << fixed << setprecision(9); _main(vector<char*>(argv, argv+argc)); return 0;
} // }}}



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

int main()
{
    ll a,b,k;
    while(cin >> a >> b >> k)
    {
        ll count = 0;
        while(count < k)
        {
            if(a % 2)
            {
                a -= 1;
                a /= 2;
                b += a;
                count ++;
            }
            else
            {
                a /= 2;
                b += a;
                count ++;
            }
            if(count == k)
            break;
            if(b % 2)
            {
                b --;
                b /= 2;
                a += b;
                count ++;
            }
            else
            {
                b /= 2;
                a += b;
                count ++;
            }
        }
        cout << a << " " << b << endl;
    }
    return 0;
}


Measured memory_bytes: 256
n=int(input())
s=list(input())
r=[]
g=[]
b=[0]*n
for i in range(len(s)):
	if s[i]=="R":
		r.append(i)
	if s[i]=="G":
		g.append(i)
	if s[i]=="B":
		b[i]=1
ans=0
s=sum(b)
for i in r:
	for j in g:
		ans+=s
		if 0<=2*j-i and 2*j-i<n:
			ans-=b[2*j-i]
		if (i+j)%2==0:
			ans-=b[(i+j)//2]
		if 0<=2*i-j and 2*i-j<n:
			ans-=b[2*i-j]
print(ans)

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

int n, m;
int adj[51][51];
int reachable[51]={};
using namespace std;

void dfs(int vertex){
  if(reachable[vertex]) return;
  reachable[vertex] = 1;
  
  for(int i=1; i<=n; ++i){
    if(adj[vertex][i]){
      dfs(i);
    }
  }
}

int main(){
    
  //load adj
  cin >> n >> m;
  vector<int> a(m), b(m);
  for(int i=0; i<m; ++i){
    cin >> a[i] >> b[i];
  }
  
  int bridgeCount = 0;
  
  for(int roiEdge=0; roiEdge<m; ++roiEdge){
    //initialize reachable
    for(int i=0; i<51; ++i){
      reachable[i] = 0;
    }
    
    //initialize adj
    for(int x=0; x<51; ++x){
      for(int y=0; y<51; ++y){
        adj[x][y] = 0;
      }
    }
    for(int i=0; i<m; ++i){
      if(i != roiEdge){ //without roiEdge
        adj[a[i]][b[i]] = adj[b[i]][a[i]] = 1;
      }
    }
    
    //search
    dfs(1);
    bool allReachable = true;
    for(int i=1; i<=n; ++i){
      allReachable = reachable[i] ? allReachable : false;
    }
    if(!allReachable)bridgeCount++;
    
  }
  
  cout << bridgeCount << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll h, w, K;
    cin >> h >> w >> K;
    K--;

    vvl dp(h+1, vl(w));  // dp[i+1][j] : i行目を通過した直後にj列目にいる場合の数(i,jは0-index)
    dp[0][0] = 1;
    rep(i, h) {
        rep(j, w) {
            rep(b, 1<<(w-1)) {  // kビット目が1のとき縦棒kと縦棒k+1を結ぶ

                vl v(w);  // v[k] : 縦棒kと縦棒k+1を結ぶとき1
                rep(k, w-1) {
                    if(b & (1<<k)) {
                        v[k] = 1;
                    }
                }

                ll flag = 0;  // 2つの横棒が端点を共有するとき1
                rep(k, w-2) {
                    if(v[k] && v[k+1]) {
                        flag = 1;
                    }
                }
                if(flag) {
                    continue;
                }

                if(j > 0 && v[j-1]) {  // 縦棒j-1と縦棒jが結ばれているとき(左から右に移動する場合)
                    dp[i+1][j] += dp[i][j-1];
                }
                else if(j < w-1 && v[j]) {  // 縦棒jと縦棒j+1が結ばれているとき(右から左に移動する場合)
                    dp[i+1][j] += dp[i][j+1];
                }
                else {  // 縦棒j-1と縦棒jも、縦棒jと縦棒j+1も結ばれていないとき(横に移動しない場合)
                    dp[i+1][j] += dp[i][j];
                }
                
                dp[i+1][j] %= mod;
            }
        }
    }

    out(dp[h][K]);
    re0;
}

Measured memory_bytes: 256
//具体例をいくつか試して、「全消しがよく起きるなあ」という気持ちになるのが重要.
//s : x [xではない] xという風になると全消し発生.
//「x = a_iだったら、全消しジャンプは何マス分か？」を作って、シミュレーション。
//これでは間に合わないので、ダブリングして高速化。
//計算量 … ダブリングすればNlogK回くらいしか移動がおこなわれないはずで、各移動をlogK回で決めているから
//O(Nlog^2K)くらい？. うーん、ちょっと厳しそうだけど、ガバガバ解析だから実際は何とかなる？
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int n, K;
int a[200000];
vector<int> posList[200001];
int jumpCount[40][200000];

signed main() {
	int i, j;
	
	cin >> n >> K;
	rep(i, n) cin >> a[i];
	rep(i, n) posList[a[i]].push_back(i);
	rep(i, n) posList[a[i]].push_back(n + i);
	
	rep(i, n) {
		int iter = upper_bound(posList[a[i]].begin(), posList[a[i]].end(), i) - posList[a[i]].begin();
		jumpCount[0][i] = posList[a[i]][iter] + 1 - i;
	}
	
	rep(i, 39) {
		rep(j, n) {
			int nxt = (j + jumpCount[i][j]) % n;
			jumpCount[i + 1][j] = jumpCount[i][j] + jumpCount[i][nxt];
		}
	}

	int jCnt = 0, iter = 0;
	vector<int> ans;
	while (jCnt < n * K) {
		for (i = 39; i >= 0; i--) {
			if (jCnt + jumpCount[i][iter] <= n * K) {
				break;
			}
		}
		if (i >= 0) {
			jCnt += jumpCount[i][iter];
			iter = (iter + jumpCount[i][iter]) % n;
		}
		else {
			ans.push_back(a[iter]);
			iter = (iter + 1) % n;
			jCnt++;
		}
	}
	
	rep(i, ans.size()) {
		cout << ans[i];
		if (i + 1 < ans.size()) cout << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 78456
import sys

N = int(input())
H = list(map(int, input().split()))

for i in range(1, N):
    if H[i] + 1 == H[i-1]:
        H[i] += 1
    elif H[i] + 1 < H[i-1]:
        print("No")
        sys.exit()
    
print("Yes")

Measured memory_bytes: 14396
n = int(input())
s = input()
alpha = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
         'Q','R','S','T','U','V','W','X','Y','Z']
ans = []

for c in s:
    i = alpha.index(c)
    ans.append(alpha[(i+n)%26])

sans = ''.join(ans)
print(sans)


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

int main() {
  int N;
  cin >> N;
  int tmp = N;
  int ans = 0;
  for (int i = 0; N>0 ; i++)    
    {
      ans = ans+(N%10);
      N = N/10;
    }
  if(ans == 1) cout << 10 << endl; 
  else  cout << ans << endl;


}


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

int main(){
#define int long long
  int n; cin >> n;
  int a[n] = {};
  
  for(int i = 0; i < n; i++){
  	cin >> a[i];
  }
  
  int sum = 0;
  int running_max = a[0];
  
  for(int i = 1; i < n; i++){
    running_max = max(a[i],running_max);
    sum += (running_max - a[i]);
  }
  
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 5084
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
import pprint
sys.setrecursionlimit(10 ** 9)


INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


a, b = LI()
a -= 1; b -= 1
ans = [['.'] * 100 for _ in range(50)] + [['#'] * 100 for _ in range(50)]


flg = 0
for y in range(99, 50, -2):
    for x in range(0, 100, 2):
        if not a:
            flg = 1
            break
        ans[y][x] = '.'
        a -= 1
    if flg:
        break

flg = 0
for y in range(0, 50, 2):
    for x in range(0, 100, 2):
        if not b:
            flg = 1
            break
        ans[y][x] = '#'
        b -= 1
    if flg:
        break


print(100, 100)
for i in ans:
    print(*i, sep='')
    


Measured memory_bytes: 41328
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG

vector<int> prime(int N) {
  vector<bool> a(N, true);
  for(int i=1; i<sqrt(N); i++) {
    if(a[i]) for(int k=2; (i+1)*k-1<N; k++) a[(i+1)*k-1] = false;
  }
  vector<int> p;
  rep(i, N) if(a[i]) p.push_back(i+1);
  p.erase(p.begin());
  return p;
}

map<int,int> primefac(int N) {
  vector<int> p = prime((int)(sqrt(N))+1);
  map<int,int> ans;
  rep(i, p.size()) {
    if(N < p[i]) {
      break;
    }
    if(N%p[i] == 0) {
      int k = 0;
      while(N%p[i] == 0) {
        N /= p[i];
        k++;
      }
      ans[p[i]] = k;
    }
  }
  if(N != 1) ans[N]++;
  return ans;
}

signed main() {
  int N, P; cin >> N >> P;
  map<int,int> prime = primefac(P);
  
  int ans = 1;
  for(auto p : prime) {
    rep(i, p.second/N) ans *= p.first;
  }
  
  cout << ans << endl;

}

Measured memory_bytes: 1528
def d_string_equivalence():
    from string import ascii_lowercase
    N = int(input())
    ans = []

    def dfs(string, can_use):
        if len(string) == N:
            ans.append(string)
            return None
        for ch in ascii_lowercase[:can_use + 1]:
            if ch == ascii_lowercase[can_use]:
                # この場合だけは、新しい英小文字を加えると新しい標準形が現れる
                dfs(string + ch, can_use + 1)
            else:
                # 新しい英小文字を加えても以前現れた標準形と同型になる
                dfs(string + ch, can_use)
    dfs('', 0)  # 最初は 'a' だけ置ける
    return '\n'.join(ans)

print(d_string_equivalence())

Measured memory_bytes: 15732
#include <iostream>
#include <string>
#include <functional>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <map>

using namespace std;
using ll = long long;

int main()
{
	string s;

	cin >> s;

	if ((s.length() == 2) && (s[0] == s[1]))
	{
		cout << 1 << " " << 2 << endl;
		return 0;
	}


	for (int i = 0; i < s.length() - 2; i++)
	{
		if ((s[i] == s[i + 1]) | (s[i] == s[i + 2]))
		{
			cout << i + 1 << " " << i + 3 << endl;
			return 0;
		}
	}

	cout << -1 << " " << -1 << endl;

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
using namespace std;
int main(){
    string s;
    cin >> s;
    int l=s.size();
    long long ans=0;
    for (int i=0; i<(1<<(l-1)); i++){
        long long temp=s[0]-'0';
        long long value=0;
        for (int j=0; j<l-1; j++){
            if (i>>j &1){
                value+=temp;
                temp=s[j+1]-'0';
            }
            else {
                temp=10*temp+(s[j+1]-'0');
            }
        }
        value+=temp;
        ans+=value;
        
    }
    cout << ans <<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <set>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(void) {
  ll i, n, k, ans = 0, now;
  scanf("%lld%lld", &n, &k);
  ll a[n], sum[n + 1];
  set<ll> s;
  set<ll>::iterator it;
  for(i = 0; i < n; ++i) scanf("%lld", &a[i]), a[i] -= k;
  sum[0] = 0;
  s.insert(0);
  for(i = 0; i < n; ++i) sum[i + 1] = sum[i] + a[i], s.insert(sum[i + 1]);
  ll m = s.size(), num[m], sm = 1;
  for(it = s.begin(), i = 0; i < m; ++i, ++it) num[i] = *it;
  while(sm < m) sm <<= 1;
  ll seg[sm * 2];
  for(i = 1; i < sm * 2; ++i) seg[i] = 0;
  for(i = n; i >= 0; --i) {
    now = lower_bound(num, num + m, sum[i]) - num + sm;
    do {
      while(!(now & 1)) now >>= 1;
      ans += seg[now];
      ++now;
    } while((now & -now) != now);
    now = lower_bound(num, num + m, sum[i]) - num + sm;
    while(now) seg[now]++, now >>= 1;
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 18432
#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'
#define all(V) (V).begin(), (V).end() 
using namespace std;
typedef long long ll;

int main() {fio;
	int n, m;
	cin >> n >> m;
	vector <int> visited(n, 0), cnt(n, 1);
	visited[0] = 1;
	while(m--) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		if(visited[x]) {
			visited[y] = 1;
		}
		cnt[x]--;
		cnt[y]++;
		if(cnt[x] == 0) {
			visited[x] = 0;
		}
	}	
	cout << accumulate(all(visited), 0) << endl;
    return 0;
}

Measured memory_bytes: 3924
#include<iostream>
using namespace std;
int main(){
	int a,b,k;
	cin >> a >> b >> k;
	int cnt=0;
	for(int i=min(a,b);i>0;i--){
		if(a%i==0&&b%i==0) cnt++;
		if(cnt==k){
			cout << i <<endl;
			break;
		}
	}
	return 0;
}


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

int main(){
	unsigned long long  n,k;
	scanf("%lld %lld",&n,&k);
	while(n>k) n%=k;
	if(n==0) printf("0");
	else if(n<(k-n)) printf("%lld",n);
	else printf("%lld",k-n);
	return 0;
} 

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            var Ts = ReadIntArray();
            var M = ReadInt();
            var sum = Ts.Sum();
            LinkedList<int> rets = new LinkedList<int>();
            for (int i = 0; i < M; i++)
            {
                var PX = ReadIntArray();
                var ret = sum - Ts[PX[0] - 1] + PX[1];
                rets.AddLast(ret);
            }

            foreach (var ret in rets)
            {
                Console.WriteLine(ret);
            }
        }

        private static readonly Func<string> Read = () => Console.ReadLine();
        private static readonly Func<string[]> ReadStringArray = () => Console.ReadLine().Split();
        private static readonly Func<int> ReadInt = () => int.Parse(Console.ReadLine());
        private static readonly Func<long> ReadLong = () => long.Parse(Console.ReadLine());
        private static readonly Func<int[]> ReadIntArray = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
        private static readonly Func<long[]> ReadLongArray = () => Console.ReadLine().Split().Select(long.Parse).ToArray();
        private static readonly Action<string> Cw = str => Console.WriteLine(str);
    }
}

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

int N;
string A,B,C;
cin >> N >> A >> B >> C;

int ans = 0;

for (int i = 0; i < N; i++){
     if(A.at(i) == B.at(i) && A.at(i) == C.at(i)){
          continue;
     }
     else if(A.at(i) == B.at(i) || A.at(i) == C.at(i)){
          ans++;
     }
     else if(B.at(i) == C.at(i)){
          ans++;
     }
     else{
          ans += 2;
     }
}

cout << ans << endl;

return 0;
}

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[] a = new int[n];
        for (int i=0; i<n; i++) a[i] = sc.nextInt();

        long ans = 0;

        while (true){
            int cnt = 0;
            for (int i=0; i<n; i++){
                if (a[i]%2==0){
                    a[i] /= 2;
                    cnt++;
                }else {
                    continue;
                }
            }
            if (cnt!=n) break;
            ans++;
        }
        System.out.println(ans);
    }
}

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

using namespace std;

int n, x;
const int N = 1e5 + 7;

int main() {
    std :: ios :: sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> x >> n;
    if(n == 0) {
        cout << x << endl;
        exit(0);
    }
    vector < int > vt(n);
    for(int i = 0; i < n ; ++i) cin >> vt[i];
    sort(vt.begin(),vt.end());
    int curr = (1 << 30);
    int ans = x;
    for(int i = vt[0] - 100 ; i <= vt[vt.size() - 1] + 100 ; ++i) {
        if(!binary_search(vt.begin(),vt.end(),i)) {
            if(abs(i - x) < curr) {
                curr = abs(i - x);
                ans = i;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3664
use std::io::*;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::HashSet;
use std::cmp;
use std::f64::consts;

fn main() {
    let n: i64 = read();
    let vec: Vec<i64> = (0..n).map(|_| read()).collect();
    let mut diff_set: Vec<i64> = Vec::new();

    for (i, &e) in vec.iter().enumerate() {
        let diff = e - (i as i64 + 1);
        diff_set.push(diff);
    }

    diff_set.sort();
    let mut b: i64 = 0;
    if n % 2 == 0 {
        b = diff_set.get(n as usize/2 - 1).unwrap().clone();
    } else {
        b = diff_set.get(n as usize/2).unwrap().clone();
    }

    let mut sum = 0;
    for (i, &a) in vec.iter().enumerate() {
        sum += (a - (b+(i as i64+1))).abs();
    }
    println!("{}", sum);
}

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

// 最大公約数
fn gcd(a: i32, b: i32) -> i32 {
    match b {
        0 => a,
        _ => gcd(b, a % b)
    }
}

// 最小公倍数
fn lcm(a: i32, b: i32) -> i32 {
    a * b / gcd(a, b)
}

// 階乗
fn kaijou(n: i32)->i32 {
    if n == 1 {
        return n;
    }
    return n * kaijou(n-1);
}

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

unsigned long long gcd(unsigned long long x, unsigned long long y) {
  unsigned long long z;
  if(x>y) {
    z=y; y=x; x=z;
  }
  while(1) {
    if(y==0) return x;
    z=y; y=x%y; x=z;
  }
  return 0uLL;
}

unsigned long long lcm(unsigned long long x, unsigned long long y) {
  return x*y/gcd(x,y);
}

int main(int argc, char const *argv[])
{
  unsigned long long a,b,c,d; cin >> a >> b >> c >> d;
  unsigned long long z = lcm(c,d);
  unsigned long long ca = (a-1)/c, cb = b/c;
  unsigned long long da = (a-1)/d, db = b/d;
  unsigned long long cda = (a-1)/z, cdb = b/z;
  
  cout << (b-a+1) - ((cb+db-cdb) - (ca+da-cda)) << endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e16+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N;
    cin >> N;
    for(int i = 1; i <= 3500; i++) {
        for(int j = 1; j <= 3500; j++) {
            int X = 4*i*j;
            // X*w == N*(i*j+i*w+j*w)
            // X*w == N*i*j+(N*i+N*j)*w
            // X*w == N*i*j+(N*(i+j))*w:
            //N*i*j = X*w-(N*(i+j))*w
            //N*i*j = (X-(N*(i+j)))*w:
            int Y = N*i*j;
            if(X <= N*(i+j)) {
                continue;
            }
            if(Y%(X-(N*(i+j))) == 0) {
                cout << i << " " << j << " " << Y/(X-(N*(i+j))) << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3628