akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int x = Math.max(a, b);
        int y = Math.min(a, b);
        LOOP: while(true) {
            int r = x % y;
            x = y;
            y = r;
            if (r == 0) {
              System.out.println(x);
              break LOOP;
            }
        }
    }
}



Measured memory_bytes: 26204
import Foundation

func readWords<T>(_ f: (Substring) -> T) -> [T] {
    return readLine()!.split(separator: " ").map(f)
}

func main() {
    var hwab = readWords { Int($0)! }.makeIterator()
    let h = hwab.next()!
    let w = hwab.next()!
    let a = hwab.next()!
    let b = hwab.next()!

    var box = ("0", "1")

    for i in 1...h {
        print(String(repeating: box.0, count: w-a) + String(repeating: box.1, count: a))
        if i == b{
            box = ("1", "0")
        }
    }
}

main()

Measured memory_bytes: 13596
n = int(input())
s_list = [input().split() for i in range(n)]
s_list = sorted(["".join(sorted(s[0])) for s in s_list])
s_list.sort()

cnt = 0
p = 1
tmp = 0
while p<n:
  if s_list[p-1]==s_list[p]:
    tmp += 1
  else:
    if tmp==1:
      cnt += tmp
    elif tmp>1:
      tmp += 1
      cnt += (tmp*(tmp-1))//2
    tmp = 0
  p += 1
if tmp==1:
  cnt += tmp
elif tmp>1:
  tmp += 1
  cnt += (tmp*(tmp-1))//2
print(cnt)

Measured memory_bytes: 35820
N = int(input())
hlist = list(map(int, input().split()))
dp = [0] * N
dp[0] = 0
dp[1] = abs(hlist[0] - hlist[1])
for i in range(2, N):
    cost1 = dp[i - 1] + abs(hlist[i] - hlist[i - 1])
    cost2 = dp[i - 2] + abs(hlist[i] - hlist[i - 2])
    dp[i] = min(cost1, cost2)

print(dp[-1])


Measured memory_bytes: 13980
#include<bits/stdc++.h>
using namespace std;
const int INF=1e9+5;
int main(){
	int n,k;
	cin>>n>>k;
	vector<long long int> a(n);
	for(int i=0;i<n;i++) cin>>a[i];
	vector<long long int> dp(n,INF);
	dp[0]=0;
	for(int i=0;i<n;i++)
		for(int j=i+1;j<=i+k;j++)
			if(j<n)
				dp[j]=min(dp[j],dp[i]+abs(a[i]-a[j]));
			
	cout<<dp[n-1];
	return 0;
}


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

int main(){
  string s, t;
  cin >> s >> t;
  int count = 0;

  for (int i = 0; i < 3; i++){
    if (s[i] == t[i]){
      count += 1;
    }
  }
  cout << count << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
char G[505][505], R[505][505], B[505][505];
int main() {
	int H, W;
	scanf("%d%d", &H, &W);
	for (int i = 0; i < H; ++i) scanf("%s", G[i]);
	for (int i = 0; i < H; ++i)
		for (int j = 0; j < W; ++j) {
			if ((i % 2 == 0 && j + 1 < W) || j == 0 || G[i][j] == '#') R[i][j] = '#';
			else R[i][j] = '.';
			if ((i % 2 == 1 && j) || j == W - 1 || G[i][j] == '#') B[i][j] = '#';
			else B[i][j] = '.';
		}
	for (int i = 0; i < H; ++i) {
		R[i][W] = '\0';
		printf("%s\n", R[i]);
	}
	printf("\n");
	for (int i = 0; i < H; ++i) {
		B[i][W] = '\0';
		printf("%s\n", B[i]);
	}
}


Measured memory_bytes: 1536
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int cost[6];
int main(){
    //~ freopen("file.in", "r", stdin);
    for(int i=0;i<4;i++)
		scanf("%d",cost+i);
	ll n,ans=0;
	scanf("%lld",&n);n*=4;	
	//~ cout<<n<<endl;
	for(int i=31;i>=0;i--)
		if(n>>i&1){
			ll res=LONG_LONG_MAX;
			for(int j=0;j<4;j++)
				if(i>=j)
					umin(res,((1LL<<i)/(1<<j))*1LL*cost[j]);
			ans+=res;	
		}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256
s=input()
q=int(input())
flg=1
mae,ushiro='',''
for i in range(q):
  inp=input()
  if inp=='1':
    flg*=-1
  else:
    f,c=inp[2],inp[4]
    if f=='1'and flg==1:
      mae+=c
    elif f=='2' and flg==-1:
      mae+=c
    else:
      ushiro+=c

s=mae[::-1]+s+ushiro
if flg==-1:
  s=s[::-1]
print(s)

Measured memory_bytes: 4468
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <utility>
#include <algorithm>
#include <math.h>

using namespace std;

#define ll long long

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    cout << (C+B-A>0?C+B-A:0) << endl;
    return 0;
}


Measured memory_bytes: 256
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const [N] = input[0].map(Number);
  const A = input[1].map(Number);

  const remainingDays = N - A.reduce((acc, cur) => acc + cur);

  return remainingDays < 0 ? -1 : remainingDays;
};

console.log(main(read()));


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

using namespace std;

int func(int a,int b,int c,int k){
    if (k==0){
        if (a<b && b<c)return 1;
        else return 0;
    }
    else {
        int x=func(2*a, b, c, k-1);
        int y=func(a, 2*b, c, k-1);
        int z=func(a, b,2*c, k-1);
        if (x==1 || y==1 || z==1) return 1;
        else return 0;
    }
}
int main() {
    int a, b, c;
    int k;
    cin>>a>>b>>c;
    cin>>k;
    int res=func(a,b, c, k);

     if (res==0)cout<<"No";
     else cout<<"Yes";
    
    return 0;
    
}

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

int main() {
  int N,A[25],B[51],C[51];
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  for(int i=0;i<N;i++){
    cin >> B[i];
  }
  for(int i=0;i<N-1;i++){
    cin >> C[i];
  }
  int sum = 0;
  for(int i=0;i<N;i++){
    int a = A[i]-1;
    if(i>0){
      if(A[i] ==  A[i-1]+1){
        sum += C[a-1];
      }
    }
    sum += B[a];
  }
  cout << sum << endl;
  
  
}

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


int main() {
    int N;
    cin >> N;
    vector<int> V(N);
    rep(i,N) {
        cin >> V[i];
    }
    sort(V.begin(),V.end());
    cout << V[N - 1] - V[0] << endl;
}



Measured memory_bytes: 3612
func main(text1: String = readLine()!, text2: String = readLine()!) {
    let text2Count = text2.count
    var result = text2Count
    for text1Index in text1.indices {
        if text1[text1Index...].count < text2Count { break }
        var difference = 0
        for (character1, character2) in zip(text1[text1Index...], text2) where character1 != character2 {
            difference += 1
        }
        if result > difference {
            result = difference
        }
    }
    print(result)
}

main()

Measured memory_bytes: 7740
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mst(a,b) memset((a),(b),sizeof(a))
#define pi acos(-1)
#define pii pair<int,int>
const int INF = 0x3f3f3f3f;
const double eps = 1e-12;
const int MAXN = 1e5 + 10;
const int MAXM = 1e6 + 10;
const ll mod = 1e9 + 7;

char s[110][110];

int main()
{
#ifdef local
    freopen("data.txt","r",stdin);
//    freopen("data.txt","w",stdout);
#endif
    int a,b;
    scanf("%d%d",&a,&b);
    a--,b--;
    for(int i=1; i<=50; i++)
        for(int j=1; j<=100; j++)
            s[i][j] = '.';
    for(int i=51; i<=100; i++)
        for(int j=1; j<=100; j++)
            s[i][j] = '#';
    for(int i=1; i<=50&&b; i+=2) {
        for(int j=1; j<=100&&b; j+=2) {
            s[i][j] = '#';
            b--;
        }
    }
    for(int i=52; i<=100&&a; i+=2) {
        for(int j=1; j<=100&&a; j+=2) {
            s[i][j] = '.';
            a--;
        }
    }
    printf("100 100\n");
    for(int i=1; i<=100; i++) {
        for(int j=1; j<=100; j++)
            printf("%c",s[i][j]);
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include<string.h>
int main(void)
{
          char w[100] ;
          char s[100] = "Sunny" ;
          char c[100] = "Cloudy" ;
          char r[100] = "Rainy" ;
          scanf("%s", w) ;
          if ( strcmp(w, s)==0)
          {
                    printf("%s", c) ;
          }
          if ( strcmp(w, c)==0)
           {
                    printf("%s", r) ;
          }

          if ( strcmp(w, r)==0)
           {
                    printf("%s", s) ;
          }
}

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

#define ui unsigned int
#define ll long long
#define ul unsigned ll
#define ld long double

#define pi pair <int, int>
#define fi first
#define se second
#define mp make_pair

#define ls (p << 1)
#define rs (ls | 1)
#define md ((t[p].l + t[p].r) >> 1)

#define vi vector <int>
#define pb push_back
#define pq priority_queue

#define dbg(x) cerr << #x" = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)

#define fl(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout)

using namespace std;

namespace io {
	const int SI = 1 << 21 | 1;
	char IB[SI], *IS, *IT, OB[SI], *OS = OB, *OT = OS + SI - 1, c, ch[100];
	int f, t;
	#define gc() (IS == IT ? (IT = (IS = IB) + fread(IB, 1, SI, stdin), IS == IT ? EOF : *IS++) : *IS++)
	inline void flush() {
		fwrite(OB, 1, OS - OB, stdout), OS = OB;
	}
	inline void pc(char x) {
		*OS++ = x;
		if (OS == OT) flush();
	}

	template <class I>
	inline void rd(I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + (c & 15), c = gc());
		x *= f;
	}
	template <class I>
	inline void rd(I &x, I &y) {
		rd(x), rd(y);
	}
	template <class I>
	inline void rd(I &x, I &y, I &z) {
		rd(x), rd(y), rd(z);
	}
	template <class I>
	inline void rda(I *a, int n) {
		for (int i = 1; i <= n; i++) rd(a[i]);
	}
	inline void rdc(char &c) {
		for (c = gc(); c < 33 || c > 126; c = gc());
	}
	inline void rds(char *s, int &n) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (n = 0; c >= 33 && c <= 126; s[++n] = c, c = gc());
		s[n+1] = '\0';
	}
	inline void rds(string &s) {
		for (c = gc(); c < 33 || c > 126; c = gc());
		for (s.clear(); c >= 33 && c <= 126; s.pb(c), c = gc());
	}

	template <class I>
	inline void print(I x, char k = '\n') {
		if (!x) pc('0');
		if (x < 0) pc('-'), x = -x;
		while (x) ch[++t] = x % 10 + '0', x /= 10;
		while (t) pc(ch[t--]);
		pc(k);
	}
	template <class I>
	inline void print(I x, I y) {
		print(x, ' '), print(y);
	}
	template <class I>
	inline void print(I x, I y, I z) {
		print(x, ' '), print(y, ' '), print(z);
	}
	template <class I>
	inline void printa(I *a, int n) {
		for (int i = 1; i <= n; i++) print(a[i], " \n"[i==n]);
	}
	inline void printc(char c) {
		pc(c);
	}
	inline void prints(char *s, int n) {
		for (int i = 1; i <= n; i++) pc(s[i]);
		pc('\n');
	}
	inline void prints(string s) {
		int n = s.length();
		while (t < n) pc(s[t++]);
		pc('\n'), t = 0;
	}
	struct Flush {
		~Flush() {
			flush();
		}
	} flusher;
}
using io::rd;
using io::rda;
using io::rdc;
using io::rds;
using io::print;
using io::printa;
using io::printc;
using io::prints;

const int N = 2e5 + 7;
int n;
char s[N];
ll ans;

int main() {
	rds(s, n);
	for (int i = 1, t = 0; i < n; i++)
		if (s[i] == 'B' && s[i+1] == 'C') ans += t, ++i;
		else if (s[i] == 'A') ++t;
		else t = 0;
	print(ans);
	return 0;
}


Measured memory_bytes: 4016
class UnionFind:
    def __init__(self,N):
        self.par =[-1 for i in range(N)]
    def find(self,x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return
        if self.par[x] > self.par[y]:
            x,y = y,x
        self.par[x] +=self.par[y]
        self.par[y] = x

    def size(self,x):
        return -self.par[self.find(x)]
    def same(self,x,y):
        return self.find(x)==self.find(y)

n,q=map(int,input().split(' '))
uf = UnionFind(n)
for i in range(q):
    com,x,y=map(int,input().split(' '))
    if com == 0:
        uf.unite(x,y)
    else:
        print(int(uf.same(x,y)))


Measured memory_bytes: 5792
#include <bits/stdc++.h>
#define MAX 100005
#define MOD 1e9
#define pb push_back
#define pairs pair<int, int>
#define vi vector<int>
#define vb vector<bool>
#define vii vector<pairs>
#define lb lower_bound
#define ub upper_bound
#define ll long long
#define endl '\n'
using namespace std;
/* ----------------------------------------------------------------------------------- */

#define FastInput ios_base::sync_with_stdio(false), cin.tie(NULL);
#define all(x) x.begin(), x.end()
#define read(x) freopen(x, "r", stdin)
#define write(x) freopen(x, "w", stdout)
#define rep(i, a, n) for (int i = a; i < n; i++)
#define REP(i, a, n) for (int i = a; i <= n; i++)
#define inputArray(a,n) rep(i, 0, n) cin >> a[i];
#define copyArray(a,temp,n) rep(i, 0, n) temp[i]=a[i];
#define printArray(a,n) rep(i, 0, n) cout << a[i] << " "; cout << endl;

/* ----------------------------------------------------------------------------------- */

#define Cases  cout << "Case " << ++Case << ": ";
#define __test int tt; int Case=0; cin >> tt; while(tt--)

#define dbgA2(A, n, m) {cout<<"--> "<<#A<<" = \n";rep(i, 0, n){rep(j, 0, n){cout<<A[i][j]<<" ";}cout<<"\n";}cout<<"\n";}
#define dbgA(A, n) {cout<<" --> "<<#A<<" = (";rep(i, 0, n)cout<<A[i]<<" ";cout<<")\n";}
#define dbg(args...) {string sss(#args);sss+=',';cout<<" --> ";debugger::call(all(sss), args);cout<<"\n";}

/* ----------------------------------------------------------------------------------- */

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }

struct debugger {
	typedef string::iterator si;
	static void call(si it, si ed) {}
	template<typename T, typename ... aT>
	static void call(si it, si ed, T a, aT... rest) {
		string b;
		for(; *it!=','; ++it)
			if(*it!=' ')
				b+=*it;
		cout << b << "=" << a << " ";
		call(++it, ed, rest...);
	}
};

/* ----------------------------------------------------------------------------------- */
int arr[105];

void solve() {
	int n;
	cin >> n;
	int arr[n];
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}

	ll ans = 0;
	for (int i = 0; i < n; i++) {
		ans ^= arr[i];
	}

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

int main() {
	solve();

	// __test {
	// 	solve();
	// }

	return 0;
}

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

const int MAX = 2000 + 1;

int dp[MAX][MAX][2];

int main()
{
	int M, N;
	string S, T;
	cin >> M >> N >> S >> T;
	int res = 0;
	for (int i = 0; i <= M; i++) {
		for (int j = 0; j <= N; j++) {
			if (i < M && S[i] == 'I') {
				dp[i + 1][j][1] = max(dp[i + 1][j][1], dp[i][j][0] + 1);
				res = max(res, dp[i + 1][j][1]);
			}
			else if (i < M && dp[i][j][1] != 0) {
				dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][1] + 1);
			}
			if (j < N && T[j] == 'I') {
				dp[i][j + 1][1] = max(dp[i][j + 1][1], dp[i][j][0] + 1);
				res = max(res, dp[i][j + 1][1]);
			}
			else if (j < N && dp[i][j][1] != 0) {
				dp[i][j + 1][0] = max(dp[i][j + 1][0], dp[i][j][1] + 1);
			}
		}
	}
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 34496
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
		using ll = long long;
		const int inf = 1e9 + 7;

		int main() {
			long long int n, ans = 1, a;
			cin >> n;
			rep(i, n) {
				cin >> a;
				if (a == 0) {
					cout << 0 << endl;
					return 0;
				}else if(a>(1000000000000000000/ans)){
					ans = -1;
				}else if (ans == -1)ans = ans;
				else {
					ans = ans * a;
				}
				if (ans > 1000000000000000000) {
					ans = -1;
				}
			}	
	cout<<ans<<endl;
}

Measured memory_bytes: 3636
#include <iomanip>
#include <limits>
#include <thread>
#include <utility>
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <numeric>
#include <cassert>
#include <random>
#include <chrono>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <list>
#include <functional>
#include <bitset>
#include <complex>
#include <tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double D;
typedef complex<D> P;
const ll E = 1e18 + 7;
const ll MOD = 1000000007;
#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define fill(x, y) memset(x, y, sizeof(x))
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
template <class... A>
void prints() { cout << endl; }
template <class... A>
void prints_rest() { cout << endl; }
template <class T, class... A>
void prints_rest(const T &first, const A &... rest) { cout << " " << first; prints_rest(rest...); }
template <class T, class... A>
void prints(const T &first, const A &... rest) { cout << first; prints_rest(rest...); }

template <class T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

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

    int N;
    cin >> N;
    int in;
    vector<int> A, B;
    rep(_, N+1) {
        cin >> in;
        A.push_back(in);
    }
    rep(_, N) {
        cin >> in;
        B.push_back(in);
    }

    ll ans = 0;
    rep(i, N) {
        ans += min(A[i], B[i]);
        if ( B[i] > A[i] ) {
            ans += min(A[i+1], B[i] - A[i]);
            A[i + 1] -= min(A[i + 1], B[i] - A[i]);
        }
    }

    prints(ans);

    return 0;
}



Measured memory_bytes: 1400
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"

using namespace std;
const long long int MOD = 1000000007;

long long int N;
long long int A;
long long int box;

int main() {
	cin >> N >> A;
	if (A > N)swap(A, N);
	box = N;
	while (A) {
		box %= A;
		swap(A, box);
	}
	cout << (N - box) * 3<<endl;
	return 0;
}

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

using namespace std;

typedef long long ll;

ll gcd(ll x, ll y) {
  while (y != 0) {
    ll r = x % y; x = y; y = r;
  }
  return x;
}

std::vector<std::pair<ll, int> > prime_factor(ll n) {
  std::vector<std::pair<ll, int> > ret;

  for (ll i = 2; i*i <= n; i++) {
    if (n % i != 0) { continue; }
    int exp_v = 0;
    while (n % i == 0) {
      exp_v++;
      n /= i;
    }
    ret.push_back( std::make_pair(i, exp_v) );
  }

  if (n != 1) {
    ret.push_back( std::make_pair(n, 1) );
  }

  return ret;
}


int main() {
  ll a, b;
  cin >> a >> b;

  ll g = gcd(a, b);

  cout << prime_factor(g).size() + 1 << endl;

  return 0;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int abs(int a){
	return a>0?a:-a;
}
int main(){
	long long n, k, t;
	cin >> n >> k; 
	t = n%k;
	if( abs(t-k) > t ) cout << t << endl;
	else cout << abs(t-k) << endl;
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>
#include <queue>

using namespace std;




int main()
{
	int N, K;
	string S;

	cin >> N >> K >> S; 

	S[K-1] = S[K -1] + 'a' - 'A';
	//transform(S.begin()+K-1, S.begin() + K, S.begin() + K, tolower);

	printf("%s", S.c_str());

	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

struct SCC{
  vector< vector<int> > G; //グラフの隣接リスト
  vector< vector<int> > rG; //辺の向きを逆にしたグラフ
  vector<int> vs; //帰りがけ順の並び
  vector<bool> visited; //既に調べたか
  vector<int> cmp; //トポロジカル順序 値が等しければ強連結成分

  void init(int _V){
    int V = _V;
    G.resize(V);
    rG.resize(V);
    visited.resize(V);
    cmp.resize(V);
  }

  void dfs(int v){
    visited[v] = true;
    for(int i = 0; i < G[v].size(); i++){
      if(!visited[G[v][i]]) dfs(G[v][i]);
    }
    vs.push_back(v);
  }

  void rdfs(int v,int k){
    visited[v] = true;
    cmp[v] = k;
    for(int i = 0; i < rG[v].size(); i++){
      if(!visited[rG[v][i]]) rdfs(rG[v][i],k);
    }
  }

  int scc(int V){
    fill(visited.begin(),visited.begin()+V,false);
    for(int v = 0; v < V; v++){
      if(!visited[v]) dfs(v);
    }

    fill(visited.begin(),visited.begin()+V,false);
    int k = 0;
    for(int i = vs.size()-1; i >= 0; i--){
      if(!visited[vs[i]]) rdfs(vs[i],k++);
    }
    return k;
  }

}scc;

signed main(){

  int n,m; cin >> n >> m;
  scc.init(n);
  for(int i = 0; i < m; i++){
    int a,b; cin >> a >> b;
    a--,b--;
    scc.G[a].push_back(b);
    scc.rG[b].push_back(a);
  }
  scc.scc(n);

  for(int i = 0; i < n; i++){
    bool judge = true;
    for(int j = 0; j < n; j++){
      if(scc.cmp[i] == scc.cmp[j]){
        if(!judge) cout << " ";
        cout << j+1;
        judge = false;
      }
    }
    if(judge) cout << i+1;
    cout << endl;
  }

  return 0;
}



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

int main()
{
  string s;
  cin>>s;
  ll count=0;
  for (int i = 0; i < s.size()-1; i++)
  {
    if(s[i]=='h'&&s[i+1]=='i')
    {
      count=count+2;
    }
  }
  if(count==s.size())
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll mod=998244353;
ll mul(ll a, ll b)
{
	return ((a%mod)*(b%mod))%mod;
}
ll add(ll a, ll b)
{
	return ((a%mod)+(b%mod))%mod;
}
ll sub(ll a, ll b)
{
	return ((a%mod)-(b%mod)+mod)%mod;
}
int main() 
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n,k;
	cin>>n>>k;
	ll a[n+1];
	for(ll i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	map<ll,ll> m;
	ll i=1;
	ll j=1;
	vector<ll> v;
	while(m[i]==0)
	{
		v.push_back(i);
		m[i]=j;
		i=a[i];
		j++;
	}
	
	ll cyc=j-m[i];
	//cout<<cyc<<" ";
	if(k<v.size())
	{
		cout<<v[k];
		exit(0);
	}
	k-=v.size();
	k=k%cyc;
	k+=m[i]-1;
	cout<<v[k];
	
	
}

Measured memory_bytes: 18984
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;

const int maxn = 210000;

int n,r,c;
struct point{int x,y,i;}p[maxn]; int pn;
struct node{point x,y;}a[maxn];
bool v[maxn];

bool is(point x){return x.x==0||x.y==0||x.x==r||x.y==c;}
int sum(point x)
{
	if(x.x==0) return 2*r+c+c-x.y;
	if(x.y==0) return x.x+x.y;
	if(x.x==r) return r+x.y;
	if(x.y==c) return r+c+r-x.x;
}
inline bool cmp(const point x,const point y){return sum(x)<sum(y);}

int t[maxn],tp;

int main()
{
	scanf("%d%d%d",&r,&c,&n);
	for(int i=1;i<=n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y); point p1=(point){x,y,i};
		scanf("%d%d",&x,&y); point p2=(point){x,y,i};
		a[i]=(node){p1,p2};
		if(is(p1)&&is(p2)) v[i]=true;
	}
	for(int i=1;i<=n;i++) if(v[i]) p[++pn]=a[i].x,p[++pn]=a[i].y;
	sort(p+1,p+pn+1,cmp);
	
	for(int i=1;i<=pn;i++)
	{
		if(t[tp]==p[i].i) tp--;
		else t[++tp]=p[i].i;
	}
	if(tp) puts("NO");
	else puts("YES");
	
	return 0;
}


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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;

template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }

const int INF = 1L << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = { 0, 1, 0, -1 }, dx4 = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };

using namespace std;

vector<vector<int>> memo;

bool dfs(int left, int right, const string &S) {
    if (memo[left][right] != -1) {
        return memo[left][right] == 1;
    }

    if (left > right) {
        return true;
    }

    if (S[left] != 'm' or S[right] != 'w') {
        return false;
    }

    FOR(i, left, right) {
        if (S[i] == 'e') {
            if (dfs(left + 1, i - 1, S) and dfs(i + 1, right - 1, S)) {
                memo[left][right] = 1;
                return true;
            }
        }
    }

    memo[left][right] = 0;
    return false;
}

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

    memo.resize(510, vector<int>(510, -1));
    string S;
    cin >> S;

    if (dfs(0, S.size() - 1, S)) {
        print("Cat");
    }
    else {
        print("Rabbit");
    }

	return 0;
}


Measured memory_bytes: 3884
#include <iostream>
#include <stdio.h>
using namespace std;
const int MAXN=1000005;
int padres[MAXN],i,n,q,op,x,y;
int findSet(int i){ if (padres[i] == i) return i; else return padres[i] = findSet(padres[i]); }
bool isSameSet(int i, int j){ return (findSet(i) == findSet(j)); }
void unionSet(int i, int j){ padres[findSet(i)] = findSet(j); }
void initSet(int N){ for(int i=0; i<N; i++){ padres[i] = i;}}
int main()
{
    scanf("%d%d",&n,&q);
    initSet(n);
    for (int i=0; i<q; i++){
        scanf("%d%d%d",&op,&x,&y);
        if (op==0){
            unionSet(x,y);
        }else{
            if (isSameSet(x,y)) printf("1\n");
            else printf("0\n");
        }

    }
    return 0;
}

Measured memory_bytes: 1324
#include<bits/stdc++.h>
#define ll long long int
#define endl "\n"
#define mod 1000000007
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll>
#define FOR(i,l,r) for(int i = l; i < r; ++i)
#define MAX 800000
using namespace std;

void solve(){
	ll x,k,d;
	cin>>x>>k>>d;
	if (k >= abs(x) / d)
	{
		if (x < 0)
		{
			k -= abs(x) / d;
			x = -(abs(x) % d);
		}
		else{
			k -= abs(x) / d;
			x = (abs(x) % d);
		}
	}
	else{
		if (x < 0)
		{
			x += k*d;
		}
		else{
			x -= k*d;
		}
		k = 0;
	}
	if (x < 0)
	{
		if (k%2)
		{
			cout<<abs(x + d);
		}
		else{
			cout<<abs(x);
		}
	}
	else{
		if (k%2)
		{
			cout<<abs(x - d);
		}
		else{
			cout<<abs(x);
		}
	}
}
  
int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	cerr<<"Timpe elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " mps\n" ;
	return 0;
}

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

int main(){
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    vector<int> x1(n+1);
    vector<int> y1(m+1);
    for(int i = 0; i < n; i++) cin >> x1[i];
    for(int i = 0; i < m; i++) cin >> y1[i];

    string ans = "War";
    for(int z = x+1; z <= y; z++){
        bool isok = true;
        for(int i = 0; i < n; i++){
            if(x1[i] >= z) isok = false;
        }
        
        for(int i = 0; i < m; i++){
            if(y1[i] < z) isok = false;
        }

        if(isok) ans = "No War";
    }

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

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int h,w,x[300010],y[300010],i,j,r=0;
  int a[300010],b[300010],c[300010],d[300010],e[510][510];
  scanf("%d %d",&h,&w);
  for(i=0;i<h;i++){
    for(j=0;j<w;j++)scanf("%d",&e[i][j]);
  }
  for(i=r=0;i<h;i++){
    if(i%2==0){
      for(j=0;j<w-1;j++){
	if(e[i][j]%2){
	  e[a[r]=i][b[r  ]=j  ]--;
	  e[c[r]=i][d[r++]=j+1]++;
	}
      }
      if(e[i][j]%2&&h-i-1){
	e[a[r]=i  ][b[r  ]=j]--;
	e[c[r]=i+1][d[r++]=j]++;
      }
    }
    else{
      for(j=w-1;j;j--){
	if(e[i][j]%2){
	  e[a[r]=i][b[r  ]=j  ]--;
	  e[c[r]=i][d[r++]=j-1]++;
	}
      }
      if(e[i][j]%2&&h-i-1){
	e[a[r]=i  ][b[r  ]=j]--;
	e[c[r]=i+1][d[r++]=j]++;
      }
    }
  }
  printf("%d\n",r);
  for(i=0;i<r;i++)printf("%d %d %d %d\n",a[i]+1,b[i]+1,c[i]+1,d[i]+1);
  return 0;
}


Measured memory_bytes: 7424
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
ll inf = (1LL << 50);

//bool operator< (pint a, pint b) {
	//return a.second < b.second;

//}



ll gcd(ll a, ll b) {

	if (b == 0)
		return a;

	return gcd(b, a % b);


}

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

}

ll min(ll a, ll b) {
	if (a < b)
		return a;

	return b;
}




ll A[305][305];
vector<pint> Query;
pint Ipos[305 * 305];
ll cost[305 * 305];
int main() {
	ll H, W, D;
	ll L, R;
	cin >> H >> W >> D;


	rep(i, H) {
		rep(j, W) {
			cin >> A[i][j];
			Ipos[A[i][j]] = { i + 1, j + 1 };
		
		}

	}
	ll Q;
	cin >> Q;

	rep(i, Q) {
		cin >> L >> R;
		Query.push_back({L, R});

	}



	rep(i, H*W+1) {

		if (i <= D)
			cost[i] = 0;

		else {
			cost[i] = cost[(i / D - 1) * D + (i%D)] + abs(Ipos[i].first - Ipos[(i / D - 1) * D + (i%D)].first) + abs(Ipos[i].second - Ipos[(i / D - 1) * D + (i%D)].second);
		}

	}
	

	rep(i, Q) {


		cout << cost[Query[i].second] - cost[Query[i].first] << endl;
	}


	return 0;
}

Measured memory_bytes: 5616
import java.util.*;

public class Main {
	static boolean[] arr;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		arr = new boolean[10];
		for (int i = 0; i < k; i++) {
			arr[sc.nextInt()] = true;
		}
		for (int i = n; ; i++) {
			if (match(i)) {
				System.out.println(i);
				return;
			}
		}
	}
	
	static boolean match(int x) {
		while (x > 0) {
			if (arr[x % 10]) {
				return false;
			}
			x /= 10;
		}
		return true;
	}
}


Measured memory_bytes: 23380
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;

int w[10], k[10];

int main()
{
  for(int i = 0; i < 10; i++) cin >> w[i];
  for(int i = 0; i < 10; i++) cin >> k[i];
  sort(w, w + 10, greater<int>());
  sort(k, k + 10, greater<int>());
  cout << w[0] + w[1] + w[2] << " " << k[0] + k[1] + k[2] << endl;
  return 0;
}

Measured memory_bytes: 1180
import sys
input = sys.stdin.buffer.readline


h, w, n = map(int,input().split())
d = {}
for i in range(n):
    ch, cw = map(int,input().split())
    for dh in [-1,0,1]:
        for dw in [-1,0,1]:
            if 2 <= ch + dh <= h-1 and 2 <= cw + dw <= w-1:
                x = (ch + dh)*10**10 + cw + dw
                # print(ch, cw, dh, dw, x)
                if x in d:
                    d[x] += 1
                else:
                    d[x] = 1
ans = [0] * 10
ans[0]
for v in d.values():
    ans[v] += 1
ans[0] = (h-2)*(w-2) - sum(ans[1:])
for i in range(10):
    print(ans[i])


Measured memory_bytes: 233952
# https://beta.atcoder.jp/contests/abc054/tasks/abc054_b


def solve():
    n, m = map(int, input().split())
    img = []
    tmp = []

    for _ in range(n):
        img.append(input())

    for _ in range(m):
        tmp.append(input())

    loops = n - m + 1
    for loop in range(loops):
        for row in range(loops):
            match = True
            for col in range(m):
                if img[col+loop][row:row+m] != tmp[col]:
                    match = False
            if match:
                print('Yes')
                return
    print('No')


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(long long x, long long y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(long long x, long long y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int N, K; cin >> N >> K;
    vector<int>l(N);
    rep(i, N)cin >> l[i];
    sort(l.begin(), l.end());
    reverse(l.begin(),l.end());
    int ans = 0;
    rep(i, K)ans += l[i];
    cout << ans << endl;
}

Measured memory_bytes: 3580
#!/usr/bin/env python3
import sys
input = sys.stdin.buffer.readline

def inn(func=int):
    return list(map(func,input().split()))

def ins():
    return input().split()

an,bn,m = inn()
a = inn()
b = inn()

m_a = min(a)
m_b = min(b)
min_n = min(a)+min(b)

coupon = {}
for i in range(m):
    xi,yi,ci = inn()
    xi = xi-1
    yi = yi-1
    sum_vou = a[xi]+b[yi]-ci
    if sum_vou < min_n:
        min_n = sum_vou

print(min_n)


'''
for i in range(m):
    xi,yi,ci = inn()
    xi = xi-1
    yi = yi-1
    if not (xi,yi) in coupon.keys():
        coupon[(xi,yi)] = ci
    else:
        if coupon[(xi,yi)] < ci:
            coupon[(xi,yi)] = ci
'''

Measured memory_bytes: 16252
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'YES' : 'NO') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n=gi
a=gsmi
puts_yesno a.uniq.size==n

Measured memory_bytes: 32404
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

void dfs(const vvi &to, vi &id, int u, int val) {
    id[u] = val;
    for (int v: to[u]) {
        if (id[v] < 0) dfs(to, id, v, val);
    }
};

int main() {
    int n, m, s, t, q, u, v;
    cin >> n >> m;
    vvi to(n);
    for (int i=0; i<m; ++i) {
        cin >> s >> t;
        to[s].push_back(t);
        to[t].push_back(s);
    }
    vi id(n, -1);
    for (int i=0; i<n; ++i) {
        if (id[i] < 0) dfs(to, id, i, i);
    }
    cin >> q;
    for (int i=0; i<q; ++i) {
        cin >> u >> v;
        cout << (id[u] == id[v] ? "yes" : "no") << endl;
    }
    return 0;
}


Measured memory_bytes: 13392
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>

using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
 
template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
  
inline int updiv(int a,int b){ return (a + b - 1) / b; }
 
constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
constexpr int dy[] = {0,-1,0,1,1,-1,-1,1};

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

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

	int n;
	cin >> n;

	int res = 0;

	for(auto [p, k] : prime_factor(n)){
		for(int i = 1; i <= 100; ++i){
			if(k >= i){
				++res;
				k -= i;
			}else{
				break;
			}
		}
	}

	cout << res << '\n';

	return 0;
}

Measured memory_bytes: 3668
/*
ID: amagica1
TASK: ariprog
LANG: C++
*/
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define NINF -INF
#define mp make_pair
#define boost() cin.tie(0); cin.sync_with_stdio(0)
#define For(i, a, b) for(int i=a; i<b; i++)
#define FOR(i, a, b) for(int i=a; i<=b; i++)
#define Rev(i, a, b) for(int i=a; i>b; i--)
#define REV(i, a, b) for(int i=a; i>=b; i--)
typedef long long ll;
typedef long double ld;
typedef int64_t l;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
const ll MOD = 1e9 + 7;
const int MAXN = 100005;
ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}
int N; bool honest[16]; vector<pii> people[16];
int check(int x) {
    int cnt=0; memset(honest, false, sizeof(honest));
    for(int i=0; i<16; i++) {
        if((x >> i) & 1) {
            honest[i]=true;
            cnt++;
        }
    }
   /* for(int i=0; i<N; i++) {
        printf("%d ", honest[i]);
    }
    printf("\n");*/
    for(int i=1; i<=N; i++) {
        for(pii v : people[i]) {
            //printf("%d %d %d %d\n", i-1, honest[i-1], v.first-1, v.second);
            if(honest[i-1] && honest[v.first-1] != v.second) {
                //printf("%d %d %d %d\n", i-1, honest[i-1], honest[v.first-1], v.second);
                return 0;
            }
        }
    }
    //printf("cnt %d\n", cnt);
    return cnt;
}
int main() {
    //-----------FILE------------//
    // freopen("ariprog.in", "r", stdin);
    // freopen("ariprog.out", "w", stdout);
    //----------------------------//
    cin >> N;
    for(int i=1; i<=N; i++) {
        int t; cin>>t;
        for(int j=1, u, v; j <= t; j++) {
            cin >> u >> v;
            if(v == 1) people[i].push_back({u, 1});
            else people[i].push_back({u, 0});
        }
    }
    int ans=0;
    for(int i=0; i<(1<<N); i++)
        ans = max(check(i), ans);
    printf("%d\n", ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
typedef long long int ll;
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main()
{
    string s;
    cin>>s;
    int a=0,b=0;
    for(int i=0;i<s.length();i++){
        if(s[i]=='0'){
            a++;
        }else{
            b++;
        }
    }
    cout<<2*min(a,b)<<endl;
    return 0;
}

Measured memory_bytes: 512
n=int(input())
hl=list(map(int,input().split()))
dp=[0,abs(hl[0]-hl[1])]
for i in range(2,n):
    dp.append(min(abs(hl[i]-hl[i-2])+dp[i-2],abs(hl[i]-hl[i-1])+dp[i-1]))
print(dp[-1])

Measured memory_bytes: 13928
n = int(input())
a = list(map(int, input().split()))
a.sort()
aMax = a[-1]
ans = 0
dp = [1] * (aMax+1)

for i in range(n-1):
    p = a[i]
    if dp[p] == 1:
        for j in range(aMax//p+1):
            dp[p*j] = 0
        if a[i] != a[i+1]:
            ans += 1
if dp[aMax] == 1:
    ans += 1
print(ans)

Measured memory_bytes: 32164
#include <bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;

bool sortinrev(const pair<int,int> &a,  const pair<int,int> &b) { 
       return (a.first > b.first); 
}
   	
int main() {
	long long int n, m, sum = 0, count;

	cin >> n >> m;

	long long int a[n], b[m], c[m];
	vector<pair<long long int, long long int>> v;

	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	sort(a, a+n);

	for (int i = 0; i < m; i++)
	{
		cin >> b[i] >> c[i];
		v.push_back( make_pair(c[i],b[i]) );
	}

	sort(v.begin(), v.end(), sortinrev);
	long long int it = 0;
	for (int i = 0; i < m; i++)
	{
		count = 0;
		while (a[it] <= v[i].first && count < v[i].second)
		{
			a[it] = v[i].first;
			count++;
			it++;
		}
	}

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

	cout << sum;

	return 0;
}



Measured memory_bytes: 7416
n=int(input())
from collections import defaultdict
def factorization(n):
    arr = defaultdict(int)
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr[i]+=cnt

    if temp!=1:
        arr[temp]=1

    if arr==[]:
        arr[n]=1

    return arr
l=factorization(n)
ans=0
for v in l.values():
    i=1
    while i<=v:
        ans+=1
        v-=i
        i+=1
print(ans)


Measured memory_bytes: 66156
fun main() {
    val (n, l) = nextIntList()
    println((0 until n).map {
        next()
    }.sorted().joinToString(separator = ""))
}

// # Utils
// ## Input
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map(String::toInt)
fun nextLongList() = next().split(" ").map(String::toLong)
fun nextDoubleList() = next().split(" ").map(String::toDouble)

// ## Array
inline fun <reified T> sizedArray(size: Int, default: T) = Array(size) { default }
inline fun <reified T> sized2DArray(row: Int, column: Int, default: T) = Array(row) { Array(column) { default } }

// ## mod^-1
//    [NOTE] CANNOT use this for 0, mod, 2mod, 3mod ...(return wrong value)
fun modinv(num: Long, mod: Long): Long {
    var a = num
    var b = mod
    var u = 1L
    var v = 0L
    while (b > 0) {
        val t = a.div(b)
        a -= t * b
        a = b.also { b = a } // swap a and b
        u -= t * v
        u = v.also { v = u } // swap u and v
    }
    u %= mod
    if (u < 0) u += mod
    return u
}

fun gcd(x: Int, y: Int): Int {
    fun innerGcd(x: Int, y: Int): Int {
        return if (x % y == 0) y else innerGcd(y, x % y)
    }
    return if (x >= y) innerGcd(x, y) else innerGcd(y, x)
}

fun gcd(x: Long, y: Long): Long {
    fun innerGcd(x: Long, y: Long): Long {
        return if (x % y == 0L) y else innerGcd(y, x % y)
    }
    return if (x >= y) innerGcd(x, y) else innerGcd(y, x)
}

// classes
class UnionFindTree(val size: Int) {
    private val r = sizedArray(size, -1)
    fun root(x: Int): Int {
        if (r[x] < 0) return x
        return root(r[x])
    }

    fun unite(x: Int, y: Int) {
        var rx = root(x)
        var ry = root(y)
        if (rx == ry) return
        if (r[rx] > r[ry]) {
            rx = ry.also { ry = rx }
        }
        r[rx] += r[ry]
        r[ry] = rx
    }

    fun size(x: Int) = -r[root(x)]

    override fun toString(): String {
        return r.joinToString(separator = ", ")
    }
}

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

using namespace std;

int main() {
	string a, b;
	cin >> a;
	cin >> b;
	int sa = a.size();
	int sb = b.size();
	if (sa > sb) {
		printf("GREATER\n");
	} else {
		if (sa < sb) {
			printf("LESS\n");
		} else {
			int i;
			for (i = 0; i < sa; i++) {
				if (a[i] > b[i]) {
					printf("GREATER\n");
					break;
				}
				if (a[i] < b[i]) {
					printf("LESS\n");
					break;
				}
			}
			if (i == sa) {
				printf("EQUAL");
			}
		}
	}
	return 0;
}


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

ll n;
vll G[10];

ll ans=0;
void dfs(ll v, vector<bool> visited){
  visited[v]=true;
  for(auto nv: G[v]){
    if(visited[nv]) continue;
    dfs(nv,visited);
  }
  rep(i,n){
    if(!visited[i]) return;
  }
  ans++;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll m; cin>>n>>m;
  rep(i,m){
    ll a,b; cin>>a>>b; a--,b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  
  vector<bool> visited(10);
  dfs(0,visited);
  
  cout<<ans<<endl;
  
}

Measured memory_bytes: 256