akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#define mop 1000000007

using namespace std;
static const long long MAX = 100001;
long long p[MAX];
long long color[MAX] = {};
vector <long long> G[MAX];
long long n,m;

void bfs(long long u, long long c){
    queue<long long> Q;
    Q.push(u);
    color[u] = c;
    while(!Q.empty()){
        long long v = Q.front();
        Q.pop();
        for (long long i = 0;i<G[v].size();i++){
            if(color[G[v][i]] != 0){
                continue;
            }
            color[G[v][i]] = c;
            Q.push(G[v][i]);
        }
    }
}

void assignColor(){
    long long c = 1;
    for (long long i=1;i<=n;i++){
        if(color[i] == 0){
            bfs(i, c);
            c++;
        }
    }
}
int main() {
    


    cin >> n >> m;
    for (long long i=0;i<n;i++){
        cin >> p[i+1];
    }
    for (long long i = 0;i<m;i++){
        long long x,y;
        cin >> x >> y;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    assignColor();
    long long ans = 0;
//    for (long long i=1;i<=n;i++){
//        cout << i << " " << color[i] << endl;
//    }
    for (long long i=1;i<=n;i++){
        if(color[i] == color[p[i]]){
            ans += 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 7808
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=200010;
int n,d[maxn],ans=1,k,s[maxn],a[maxn];
struct Seg {
	int flag,tr[maxn*4];
	void build(int l,int r,int root) {
		if (l==r) {
			tr[root]=d[l];
			return;
		}
		int mid=(l+r)/2;
		build(l,mid,root*2);
		build(mid+1,r,root*2+1);
		if (flag==1) tr[root]=min(tr[root*2],tr[root*2+1]);
		if (flag==2) tr[root]=max(tr[root*2],tr[root*2+1]);
	}
	int query(int L,int R,int l,int r,int root) {
		if (L<=l&&r<=R) return tr[root];
		int mid=(l+r)/2,res;
		if (flag==1) res=n+1; else res=0;
		if (L<=mid) {
			if (flag==1) res=min(res,query(L,R,l,mid,root*2));
			else res=max(res,query(L,R,l,mid,root*2));
		}
		if (mid<R) {
			if (flag==1) res=min(res,query(L,R,mid+1,r,root*2+1));
			else res=max(res,query(L,R,mid+1,r,root*2+1));
		} return res;
	}
} mn,mx;
int main() {
	//freopen("1.txt","r",stdin);
	read(n); read(k);
	for (int i=1;i<=n;i++) read(d[i]),d[i]++;
	for (int i=1;i<=n;i++) {
		if (d[i]<d[i+1]) a[i]=1;
		s[i]=s[i-1]+a[i];
	}
	mn.flag=1; mx.flag=2;
	mn.build(1,n,1);
	mx.build(1,n,1);
	int flag=0,tmp;
	if (s[n-1]-s[n-k]==k-1) flag=1; else flag=0;
	for (int i=n-k;i>=1;i--) {
		if (s[i+k-2]-s[i-1]==k-1) tmp=1; else tmp=0;
		if (d[i]==mn.query(i,i+k,1,n,1)&&d[i+k]==mx.query(i,i+k,1,n,1));
		else if (flag&&tmp); else ans++;
		flag|=tmp;
	}
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define per(i, a, b) for (auto i = (b); i-- > (a); )
#define eb(x...) emplace_back(x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) int((x).size())
#define lb(x...) lower_bound(x)
#define ub(x...) upper_bound(x)

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T> T gcd(T a, T b) { return b != T(0) ? gcd(b, a % b) : a; }

using namespace std;

using C = complex<double>;
using vd = vector<double>;
using vi = vector<int>;
void fft(vector<C>& a) {
	int n = sz(a), L = 31 - __builtin_clz(n);
	static vector<complex<long double>> R(2, 1);
	static vector<C> rt(2, 1); // (ˆ 10% faster if double)
	for (static int k = 2; k < n; k *= 2) {
		R.resize(n); rt.resize(n);
		auto x = polar(1.0L, M_PIl / k); // M PI, lower−case L
		rep(i,k,2 * k) rt[i] = R[i] = i&1 ? R[i/2] * x : R[i/2];
	}
	vi rev(n);
	rep(i,0,n) rev[i] = (rev[i / 2] | (i & 1) << L) / 2;
	rep(i,0,n) if (i < rev[i]) swap(a[i], a[rev[i]]);
	for (int k = 1; k < n; k *= 2)
	for (int i = 0; i < n; i += 2 * k) rep(j,0,k) {
		C z = rt[j+k] * a[i+j+k]; // (25% faster if hand−rolled)
		a[i + j + k] = a[i + j] - z;
		a[i + j] += z;
	}
}
vd conv(const vd& a, const vd& b) {
	if (a.empty() || b.empty()) return {};
	vd res(sz(a) + sz(b) - 1);
	int L = 32 - __builtin_clz(sz(res)), n = 1 << L;
	vector<C> in(n), out(n);
	copy(all(a), begin(in));
	rep(i,0,sz(b)) in[i].imag(b[i]);
	fft(in);
	for (auto &x : in) x *= x;
	rep(i,0,n) out[i] = in[-i & (n - 1)] - conj(in[i]);
	fft(out);
	rep(i,0,sz(res)) res[i] = imag(out[i]) / (4 * n);
	return res;
}

const int P = 2e5 + 3, g = 2;
int lg[P];

ll bpow(ll a, int b) {
	ll res = 1;
	while (b) {
		if (b & 1) res = res * a % P;
		a = a * a % P;
		b >>= 1;
	}
	return res;
}

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

	for (int i = 0, t = 1; i < P - 1; t = t * g % P, ++i) lg[t] = i;

	vd a(P - 1, 0);
	vector<ll> t(P - 1, 0);
	int n; cin >> n;
	rep(i, 0, n) {
		int x; cin >> x;
		if (x) ++t[lg[x]];
	}
	rep(i, 0, P - 1) a[i] = t[i];
	vd c = conv(a, a);
	
	vector<ll> f(P - 1);
	rep(x, 0, P - 1) {
		if (x & 1) {
			f[x] = round(c[x] + (x != P - 2 ? c[x + P - 1] : 0));
			assert(f[x] % 2 == 0);
			f[x] /= 2;
		} else {
			f[x] = round(c[x] + c[x + P - 1]);
			f[x] -= t[x / 2] * t[x / 2] + t[(x + P - 1) / 2] * t[(x + P - 1) / 2];
			assert(f[x] % 2 == 0);
			f[x] /= 2;
			f[x] += t[x / 2] * (t[x / 2] - 1) / 2 + t[(x + P - 1) / 2] * (t[(x + P - 1) / 2] - 1) / 2;
		}
	}

	ll ans = 0;
	rep(x, 1, P) ans += f[lg[x]] * x;
	cout << ans;
}

Measured memory_bytes: 53740
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=500005;
char s[max_n];
int n,a[max_n];
int l[max_n],r[max_n];
int main(){
    scanf(" %s",s+1);
    int n=strlen(s+1)+1;
    for(int i=1;i<n;i++){
        if(s[i]=='>')l[i]=i;
        else l[i]=l[i-1];
    }
    r[n]=n;
    for(int i=n-1;i>=1;i--){
        if(s[i]=='<')r[i]=i;
        else r[i]=r[i+1];
    }
    for(int i=1;i<=n;i++){
        a[i]=max(i-1-l[i-1],r[i]-i);
    }
    ll sum=0;
    for(int i=1;i<=n;i++)sum+=a[i];
    printf("%lld\n",sum);
    return 0;
}

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

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

    vector<int> x(5, 0);
    int sum = 0;
    for (int i = 0; i < 5; i ++) cin >> x[i];
    sort(x.begin(), x.end(), [&](int a, int b)
            {int i = a%10, j = b%10;
             if (i == 0) i = 10;
             if (j == 0) j = 10;
             return i < j;
            });

    for (int i = 4; i > 0; i--)
        if (x[i] % 10)
            sum += x[i] + (10 - (x[i]%10));
        else
            sum += x[i];
    cout << sum + x[0] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
multiset<int> s;
int main() {
	int n;
	cin >> n;
	for (int i=0;i<n;i++) {
		int x;
		cin >> x;
		s.insert(x);
	}
	int m = *s.rbegin();
	for (int i=0;i<=m;i++) {
		auto it = s.find(m-i/2);
		if (it == s.end()) {
			cout << "Impossible";
			return 0;
		}
		s.erase(it);
	}
	if (!s.empty() && *s.begin() < (m+3)/2) cout << "Impossible" << endl;
	else cout << "Possible" << endl;
	return 0;
}

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

int main(){
	vector<char> a,b;
	string str1,str2;
	getline(cin,str1);
	for(int i=0; i<(int)str1.size(); i++){
		char c1=str1[i];
		a.push_back(c1);
		}
	getline(cin,str2);
	for(int i=0; i<str2.size(); i++){
		char c2=str2[i];
		b.push_back(c2);
	}
	string ans="No";
	for(int i=0; i<a.size(); i++){
		if(a[i]==b[0]){
			int k=i;
			int cnt=0;
			for(int j=0; j<b.size(); j++){
				if(a[k]!=b[j]) break;
				if(k==a.size()-1){
					k=0;
				}else{
					k++;
				}
				cnt++;
			}
			if(cnt==b.size()) ans="Yes";
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3220
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t K, A, B;
  cin >> K >> A >> B;
  const int64_t d = B - A;
  int64_t result = 0;
  if (d <= 0 || K <= A - 1) {
    result = 1 + K;
  } else {
    int64_t y = (K - A + 1) / 2L;
    int64_t x = K - 2L * y;
    // cerr << x << ", " << y << endl;
    if (y >= 0 && x >= 0) {
      result = max(1 + K, 1 + x + y * (B - A));
    } else {
      result = 1 + K;
    }
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 3616
s=str(input())
res=[0]*len(s)

nr=0
nl=0

for i in range(len(s)):
  if s[i]=="L":
    nl+=1
    if i==len(s)-1:
      res[i-nl+1]+=(nl+1)//2
      res[i-nl]+=nl//2
    if nr!=0:
      res[i]+=nr//2
      res[i-1]+=(nr+1)//2
    nr=0
  elif s[i]=="R":
    nr+=1    
    if nl!=0:
      res[i-nl]+=(nl+1)//2
      res[i-nl-1]+=nl//2
    nl=0
res=[str(x) for x in res]
print(" ".join(res))

Measured memory_bytes: 48624
n,m=map(int,input().split())
a=[[int(i) for i in input().split()] for i in range(m)]
p=list(map(int,input().split()))
ans=0
for i in range(2**n):
    s=[None]*n
    for j in range(n):
        if (i>>j)&1:
            s[j]=True
        else:
            s[j]=False
    total=0
    for y,k in enumerate(a):
        cnt=0
        for x,l in enumerate(k):
            if x==0:
                continue
            if s[l-1]==True:
                cnt+=1
        if cnt%2==p[y]:
            total+=1
    if total==m:
        ans+=1
print(ans)

Measured memory_bytes: 3064
/**
     **author : _KMS_
     **created : 28-03-2020
**/
#include<bits/stdc++.h>
using namespace std;
const long long M =2e5+10,MOD=998244353;
typedef long long ll;
int arr[M];
int dp[M];
int main() {
   
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,k;
  cin>>n>>k;
  for(int i=1;i<=n;i++)
  cin>>arr[i];
 // dp[2]=abs(arr[1]-arr[2])
for(int i=2;i<=n;++i)dp[i]=INT_MAX;
 arr[0]=arr[1];
  for(int i=2;i<=n;i++)
  {  int temp=k;
     int in=i-1;
     while(temp>0&&in>0){
    dp[i]=min(dp[in]+abs(arr[i]-arr[in]),dp[i]);
    temp--;
    in--;
  }
  }
  cout<<dp[n]<<"\n";

  return 0;
} 

Measured memory_bytes: 1024
n, m = gets.chomp.split(" ").map(&:to_i)
h = Array.new(n+1, 0)
m.times do
  a, b = gets.chomp.split(" ").map(&:to_i)
  h[a] +=1
  h[b] +=1
end
(1..(n)).each do |i|
  puts h[i]
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,mod=1e9+7,x=1,y=1,z=1;cin>>n;
  rep(i,n) {
    x=(x*10)%mod;
    y=(y*9)%mod;
    z=(z*8)%mod;
  }
  ll ans=x-2*y+z;
  while(ans<0) ans+=mod;
  print(ans);
  return 0;
}


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, u, v;
	cin >> n >> u >> v;
	u--; v--;
	vector< vector<int> > tree(n);
	for (int i = 1; i < n; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		tree[a].push_back(b);
		tree[b].push_back(a);
	}
	vector< vector<int> > depth(2, vector<int>(n));
	function<void(int, int, int, int)> dfs = [&](int u, int d, int p, int x) {
		depth[x][u] = d;
		for (int v : tree[u]) {
			if (v == p) continue;
			dfs(v, d + 1, u, x);
		}
	};
	dfs(u, 0, -1, 0);
	dfs(v, 0, -1, 1);
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (depth[0][i] < depth[1][i]) {
			ans = max(ans, depth[1][i]);
		}
	}
	cout << ans - 1 << '\n';
	return 0;
}


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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
typedef long long ll;
const int MAX_N=1e5;

int K,N;
int A[MAX_N];
int main(){
	cin>>N>>K;
	int inx;
	REP(i,N){
		cin>>A[i];
		if (A[i]==1){
			inx=i;
		}
	}
	cout<<(N-1+K-2)/(K-1)<<endl;
	return 0;
}

Measured memory_bytes: 640
import fractions
def lcm(a, b):
    return a * b // fractions.gcd(a, b)
A,B,C,D = map(int,input().split())
E = lcm(C,D)
i = (A-1)//C
j = B//C
k = (A-1)//D
l = B//D

m = (A-1)//E
n = B//E

ans = B - A + 1 - ((j-i) + (l-k) - (n-m))

print(ans)

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

#define CO const
#define IN inline
typedef long long int64;

template<class T> IN T read(){
	T x=0,w=1;char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-') w=-w;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*w;
}
template<class T> IN T read(T&x){
	return x=read<T>();
}
#define clz __builtin_clz

char str[(1<<20)+1];
int*F[1<<21],trans[1<<21][2];

int main(){
	int n=read<int>(),K=read<int>();
	F[1]=new int[1<<(n+1)];
	F[1][0]=0;
	for(int i=0;i<=n;++i){
		int p=1<<i;
		scanf("%s",str);
		for(int j=0;j<p;++j) F[1][p+j]=str[j]-'0'; // use a leading 1 to describe the length
		for(int j=0;j<p;++j) trans[p+j][1]=j;
		trans[2*p-1][0]=0; // doesn't exist
		for(int j=1;j<p;++j) trans[2*p-1-j][0]=j^((1<<(31-clz(j)))-1);
	}
	int ans=1;
	for(int i=1;i<=n;++i){
		int p=1<<i;
		for(int j=2*p-1;j>=p;--j){
			F[j]=new int[1<<(n-i+1)];
			memset(F[j],0,sizeof(int)<<(n-i+1));
			for(int k=1;k<1<<(n-i+2);++k) F[j][trans[k][j&1]]+=F[j>>1][k];
			F[j][0]=0;
			if(accumulate(F[j],F[j]+(1<<(n-i+1)),0)>=K) ans=j;
		}
	}
	for(int i=31-clz(ans)-1;i>=0;--i) printf("%d",ans>>i&1);
	puts("");
	return 0;
}


Measured memory_bytes: 247552
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        long a = Integer.parseInt(scan.next());
        long b = Integer.parseInt(scan.next());
        long c = Integer.parseInt(scan.next());
        long d = Integer.parseInt(scan.next());
        scan.close();

        long max = a * c;
        max = Math.max(max, a * d);
        max = Math.max(max, b * c);
        max = Math.max(max, b * d);

        System.out.println(max);
    }
}


Measured memory_bytes: 35568
group_1=[1,3,5,7,8,10,12]
group_2=[4,6,9,11]
group_3=[2]
groups=[group_1,group_2,group_3]

a,b=input().split()

a=int(a)
b=int(b)

for i in range(len(groups)):
  if(a in groups[i] and b in groups[i]):
    print("Yes")
    break
else:
  print("No")

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

#define int long long

const int maxn = 4e3 + 10, mod = 924844033;
int n, k, fac[maxn], inv[maxn], dp[maxn][maxn], cnt[maxn], ans, zar[maxn];
vector <int> V;

void pre() {
	fac[0] = 1;
	for (int i = 1; i < maxn; i++)
		fac[i] = (fac[i - 1] * i) % mod;
	for (int i = 0; i < maxn; i++)
		dp[i][0] = 1, dp[i][1] = i;

	zar[0] = 1;
	for (int i = 1; i < maxn; i++)
		zar[i] = -zar[i - 1];
	cnt[0] = 1;
	return;
}

int32_t main() {
	pre();
	cin >> n >> k;
	int val = n;
	for (int i = 0; i < k; i++) {
		val--;
		V.push_back(val / k);
	}
	for (int i = 2; i < maxn; i++) {
		for (int j = 2; j <= i; j++) {
			dp[i][j] = (dp[i - 1][j] + dp[i - 2][j - 1]) % mod;
		}
	}
	for (auto x : V) {
		int val = 2;
		while (val--) {
			for (int i = n; i >= 0; i--) {
				for (int j = 1; j <= min(x, i); j++) {
					cnt[i] = (cnt[i] + (cnt[i - j] * dp[x][j]) % mod) % mod;
				}
			}
		}
	}
	for (int i = 0; i <= n; i++) 
		ans = (ans + ((cnt[i] * zar[i] * fac[n - i]) % mod) + mod) % mod;
	cout << ans;
	return 0;
}

Measured memory_bytes: 81560
#include <stdio.h>
#include <string.h>
 
int main(void)
{
  char str[25] = {0};
  int cx;

  fgets(str, sizeof(str), stdin);
  cx = strlen(str);

  for (int x=cx-2; x>=0; x--) {
    putchar(str[x]);
  }
  putchar(str[cx -1]);
 
  return 0;
}

Measured memory_bytes: 2428
#include <iostream>
#include <list>

using namespace std;

int main()
{
	int	N;
	cin >> N;
	list<int> li;
	list<int>::iterator itr;
	itr = li.end();
	for (int i = 0; i < N; i++)
	{
		int	a;
		cin >> a;
		if (a == 0)
		{
			int	b;
			cin >> b;
			itr = li.insert(itr, b);
		}
		else if (a == 1)
		{
			int	b;
			cin >> b;
			if (b > 0)
			{
				for (int j = 0; j < b; j++)
					itr++;
			}
			else
			{
				for (int j = 0; j > b; j--)
					itr--;
			}
		}
		else if (a == 2)
			itr = li.erase(itr);
	}
	for (itr = li.begin(); itr != li.end(); itr++)
		cout << *itr << endl; 
}



Measured memory_bytes: 18592
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SORT(i) sort((i).begin(),(i).end())
constexpr int INF = 2000000000;
constexpr int mod = 1000000007;

int main() {
	int N, M; cin >> N >> M;
	vector<int>st(N + 1, 1);
	rep(i, M) {
		int a; cin >> a;
		st[a] = 0;
	}
	vector<ll>dp(N + 1);
	dp[0] = 1;
	rep(i, N) {
		for (int j = i + 1;j <= min(N, i + 2);++j) {
			if (st[j]) {
				dp[j] += dp[i];
				dp[j] %= mod;
			}
		}
	}
	cout << dp[N] << "\n";

	return 0;
}

Measured memory_bytes: 1408
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

void abc_160a();

void abc_161a();

void abc_162a();

void abc_163a();

void abc_164a();

int main()
{
  //abc_160a();
  //abc_161a();
  //abc_162a();
  //abc_163a();
  abc_164a();


}

void abc_160a()
{
  string S;
  cin >> S;

  if (S[2] == S[3] && S[4] == S[5]) cout << "Yes\n";
  else cout << "No\n";
}

void swap(int& a, int& b)
{
  int tmp;
  tmp = a;
  a = b;
  b = tmp;
}

void abc_161a()
{
  int x, y, z;
  cin >> x >> y >> z;

  swap(x, y);
  swap(x, z);

  cout << x << " " << y << " " << z << "\n";
}

void abc_162a()
{
  string s;
  cin >> s;
  for (char c : s)
  {
    if (c == '7')
    {
      cout << "Yes\n";
      return;
    }
  }

  cout << "No\n";
}

void abc_163a()
{
  int R;
  cin >> R;

  cout << (double)(2 * R * M_PI);
}

void abc_164a()
{
  int s, w;
  cin >> s >> w;

  if (s <= w) cout << "unsafe\n";
  else cout << "safe\n";
}


Measured memory_bytes: 3632
#ifndef _TEMPLATE_ROOT
#define _TEMPLATE_ROOT
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define repl(i, a, b) for(ll i = a; i < (b); ++i)
#define repd(i, a, b) for(int i = b; i >= (a); --i)
#define repdl(i, a, b) for(ll i = b; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool ihmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
#endif
#ifndef _TEMPLATE_IO
#define _TEMPLATE_IO

template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
#endif
#ifndef _TEMPLATE_OPT
#define _TEMPLATE_OPT
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#endif
using namespace std;

int a[500005];

struct Query {
  int l, r, id, ans;
};

// freqcnt
int freq[500005];
int distinct = 0;
void freqadd(int x) { 
//write("FA", x, freq[x], "->", freq[x]+1);
  if (!freq[x]) distinct++; freq[x]++; }
void freqrem(int x) { 
  
//write("FR", x, freq[x], "->", freq[x]-1);
  freq[x]--; if (!freq[x]) distinct--; }
Query query[500005];

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

  int n, q; read(n, q);
  rep(i, 1, n + 1) read(a[i]);
  rep(i, 0, q) read(query[i].l, query[i].r), query[i].id = i;
  
  const int BS = 2000;
  sort(query, query + q, [](const Query& a, const Query& b) {
    if (a.l / BS != b.l / BS) return a.l / BS < b.l / BS;
    else return (a.l / BS % 2 ? a.r < b.r : a.r > b.r);
    });

  // inclusive [cl, cr]
  int cl = 1, cr = 0;
  rep(i, 0, q) {
    int nl = query[i].l, nr = query[i].r;
    while (cl > nl) freqadd(a[--cl]);
    while (cr < nr) freqadd(a[++cr]);
    while (cl < nl) freqrem(a[cl++]);
    while (cr > nr) freqrem(a[cr--]);
    query[i].ans = distinct;
  }

  sort(query, query + q, [](const Query& a, const Query& b) { return a.id < b.id; });
  rep(i, 0, q) write(query[i].ans);
}



Measured memory_bytes: 15452
#include<bits/stdc++.h>
#define INF 2147483647
#define SYOU(x) setprecision(x)
#define abs(x,y) max(x,y)-min(x,y)
using namespace std;
long long i[10000000];
long long u[11111110];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=0,e=0,f=0,g=140,h=170,now=1;
  cin >>a;
  if(a==3||a==5||a==7) cout <<"YES\n";
  else cout <<"NO\n";
  return (0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    int N, K;
    cin >> N >> K;
    int ans = 1;
    for (int i = 0; i < N; i++) {
        if (ans <= K) {
            ans *= 2;
        } else {
            ans += K;
        }
    }
    cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
typedef long long int ll;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef vector<double> vecd;
typedef vector<string> vecstr;
typedef vector<char> vecchar;
typedef vector<bool> vecbool;
typedef vector<vector<bool>> vec2bool;
typedef vector<vector<int>> vec2int;
typedef vector<vector<double>> vec2d;
typedef pair<int, int> P;
////////////////////////////////////////////////
void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
int n;
struct edge {
  int to;
  int id;
};
vector<vector<edge>> tree;
vecint color;
int nc;
void dfs(int v, int pe) {
  int c = 1;  // color id
  for (auto &e : tree[v]) {
    if (e.id == pe) continue;
    if (pe != -1 && c == color[pe]) {
      c++;
    }
    color[e.id] = c;
    dfs(e.to, e.id);
    c++;
  }
}
////////////////////////////////////////////////
int main() {
  init();
  cin >> n;
  tree.resize(n);
  color.resize(n);
  REP(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    tree[a].push_back(edge{b, i});
    tree[b].push_back(edge{a, i});
  }
  nc = 0;
  int start = 0;
  REP(i, n) {
    if (nc < tree[i].size()) {
      start = i;
      nc = tree[i].size();
    }
  }
  // nc++;
  // cout << nc << endl;
  // color[start] = nc;
  dfs(start, -1);
  cout << nc << endl;
  REP(i, n - 1) { cout << color[i] << endl; }
}

Measured memory_bytes: 6912
#coding:utf-8

from collections import defaultdict

if __name__ == "__main__":
    N, K = map(int, input().split(" "))

    num = defaultdict(int)
    for i in range(N):
        a, b = map(int, input().split(" "))
        num[a] += b

    count = 0
    for key in sorted(num.keys()):
        count += num[key]

        if count >= K:
            print (key)
            break


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;

auto main() -> int
{
	int i, n; cin >> i >> n;
    
	if(i < n)
    {
    	REP(a, n)
        	cout << i;
    }
    
    else if(i >= n)
    {
    	REP(a, i)
        	cout << n;
    }
    
    cout << endl;
}


Measured memory_bytes: 384
a = [int(input()) for i in range(5)]
b = []
for i in range(5):
  if a[i] % 10 == 0:
    b.append(10)
  else:
    b.append(a[i] % 10)
b.sort()
sum = 0
for i in range(5):
  if a[i]%10 == b[0]:
    sum = sum + a[i]
    b[0] = 0
  elif a[i] % 10 == 0:
    sum = sum + a[i]
  else:
    sum = sum + (a[i]//10)*10 + 10
print(sum)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
string s;
int x,y,ans;
int main(){
    cin>>s;
    for(int i=0;i<s.size();i++)
        if (x==y){ x++; if(s[i]=='p') ans--;}    
        else{ y++; if(s[i]=='g') ans++;}        
    cout<<ans<<endl;                    
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(){
    int N,i;
    int a,b,c;

    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%d %d %d",&a,&b,&c);
        if(a*a==b*b+c*c){
            printf("YES\n");
        }else if(b*b==a*a+c*c){
            printf("YES\n");
        }else if(c*c==a*a+b*b){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }
    return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define ll long long
#define vi vector<int>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

int A,B,C;

int main(){
    cin >> A >> B >> C;

    if((A + B) >= C)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n; std::cin >> n;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int a; std::cin >> a;
        while (a > 0 && ~a & 1) {
            a >>= 1;
            ans++;
        }
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int main(void)
{
	int limit = 10000;
	int H[limit], W[limit];
	int i, j;
	for (i = 0; i < limit; i++) {
		scanf("%d %d", &H[i], &W[i]);
		if (H[i] == 0 && W[i] == 0) {
			break;
		}
	}
	for (j = 0; j < i; j++) {
		for (int h = 0; h < H[j]; h++) {
			for (int w = 0; w < W[j]; w++) {
				if (h == 0 || h == H[j] - 1 || w == 0 || w == W[j] - 1) {
					printf("#");
				} else {
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
}



Measured memory_bytes: 2036
def main():
    n, k = map(int, input().split())
    mx = (n-1)*(n-2)//2
    if mx < k:
        print(-1)
        return
    ans = []
    for i in range(n-1):
        ans.append([i+1,n])     # star graph
    add = mx - k
    edge = []
    for i in range(n-1):
        for j in range(i):
            edge.append([i+1, j+1]) # complete graph
    for i in range(add):
        ans.append(edge[i])         # add本のedgeを追加
    m = len(ans)
    print(m)
    for i in range(m):
        print(*ans[i])

main()


Measured memory_bytes: 4148
#include<stdio.h>
#include<string.h>

int main(void){
  int n;
  int i;
  int j;
  char w[101][11];

  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%s", w[i]);
    if(i>=1 && w[i][0] != w[i-1][strlen(w[i-1])-1]){
      printf("No\n");
      return 0;
    }
  }

  for (i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      if(!strcmp(w[i],w[j])){
        printf("No\n");
        return 0;
      }
    }
  }

  printf("Yes\n");
  return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int x,n;
    cin>>x>>n;
    set <int> s;
    int p;
    for (int i=0;i<n;i++){
        cin>>p;
        s.insert(p);
    }
    for (int i=0;i<101;i++){
        if(s.find(x-i)==s.end()){
            cout<<x-i<<"\n";
            break;
        }
        if(s.find(x+i)==s.end()){
            cout<<x+i<<"\n";
            break;
        }
    }
	return 0;
}

Measured memory_bytes: 3620
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Main {

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

        in.close();
    }
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

void solve() {
  int h, w;
  cin >> h >> w;
  vector<string> f(h);
  cin >> f;
  vector<vector<int>> dp = vect(h, vect(w, INF));
  dp[0][0] = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (j - 1 >= 0) {
        if (f[i][j - 1] == f[i][j])
          chmin(dp[i][j], dp[i][j - 1]);
        else
          chmin(dp[i][j], dp[i][j - 1] + 1);
      }
      if (i - 1 >= 0) {
        if (f[i][j] == f[i - 1][j])
          chmin(dp[i][j], dp[i - 1][j]);
        else
          chmin(dp[i][j], dp[i - 1][j] + 1);
      }
    }
  }
  // dmp(dp);
  int base = 0;
  if (f[0][0] == '#') base++;
  if (f[h - 1][w - 1] == '#') base++;
  cout << (dp[h - 1][w - 1] + base) / 2 << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();
  return 0;
}


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

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i,n){
        cin >> h[i];
    }
    int res = 0;
    rep(i,n){
        if(h[i] >= k) res++;
    }
    cout << res << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
int min(int n,int m){
    if(n<m) return n;
    else return m;
}
int main(void){
    int ans=10000000,i,j,a[5];
    for(i=0;i<5;i++) scanf("%d",&a[i]);
    for(i=0;i<5;i++){
        int tmp=a[i];
        for(j=0;j<5;j++){
            if(i!=j){
                if(a[j]%10==0) tmp+=a[j];
                else tmp+=a[j]+10-a[j]%10;
            }
        }
        ans = min(ans,tmp);
    }
    printf("%d",ans);
    return 0;
}


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

int main()
{
    int N, K;
    int A[1010];
    cin >> N >> K;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    sort(A, A + N);
    int sum = 0;
    for (int i = 0; i < K; i++)
    {
        sum += A[i];
    }
    cout << sum << endl;
}


Measured memory_bytes: 3640
#include <iostream>
#include <chrono>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <unordered_set>
#include <vector>
#include <queue>
#include <math.h>
#include <unordered_map>
#include <fstream>
#include <functional>
#include <map>
#include <deque>
#include <string.h>
#include <set>

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? (-a) : (a))
#define YesNo(flag) ((flag) ? "Yes\n" : "No\n")
#define YESNO(flag) ((flag) ? "YES\n" : "NO\n")

constexpr auto NMAX = (int)1e5 + 20;
constexpr auto INF_ULL = 18446744073709551615;
constexpr auto INF_INT = 2147483647;
constexpr auto PI = 3.14159265359;
constexpr auto MOD = 1000000007;

using namespace std;

typedef unsigned long long ull;

ull n;
vector<int> v;

int main()
{
	cin >> n;

	while (n) {
		int letter = n % 26;
		if (letter == 0) letter = 26;
		n /= 26;
		if (letter == 26) {
			n--;
		}
		v.push_back(letter);
	}
	for (int i = v.size() - 1; i >= 0; i--) {
		cout << (char)(v[i] + 'a' - 1);
	}
	return 0;
}

Measured memory_bytes: 3632
def make_divisors(n):
    ans=0
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            ans+=1
            if i != n // i:
                ans+=1
    return ans

n=int(input())
a=0
for i in range(1,n+1,2):
    if make_divisors(i)==8:
        a+=1
print(a)

Measured memory_bytes: 3060
#include <iostream>
#include <string>

int main(){

    std::string S;
    std::cin >>S;


    char T[2]={'L','R'};

    bool flg=true;
    int l =S.length();

    for (int i=0;i<l;i++){
        if(S[i]==T[i%2]){
            flg=false;
            break;
        }
    }

    std::cout << (flg?"Yes":"No");


    
    return 0;
}



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

int main(){
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
    long long int ans = 0;
    for(int i = n-1; i >= 0; i--){
        if((a[i]+ans)%b[i] != 0){
            ans += b[i] - (a[i]+ans)%b[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4016
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_B&lang=ja
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines


class BellmanFord:
    """
    shortest_distance(goal): startノードからgoalノードまでの最短距離
    shortest_path(goal): startノードからgoalノードまでの最短経路
    include_negative_cycle(): 負閉路の存在確認
    """
    def __init__(self, V, edges, start):
        """
        V : 頂点数
        edges: (辺の始点,辺の終点,辺のコスト)を要素とする辺のリスト
        start: 始点のノード番号
        """
        self.V = V
        self.edges = edges
        self.start = start

    def include_negative_cycle(self):
        """
        負閉路の存在確認
        Returns: True or False
        """
        d = [0] * self.V
        for i in range(self.V):
            # start, end, cost
            for s, e, c in self.edges:
                if d[e] > d[s] + c:
                    d[e] = d[s] + c
                    # V回目にも更新があるなら負の閉路が存在する
                    if i == self.V-1:
                        return True
        return False
                    
    def shortest_distance(self):
        """ 
        始点から頂点goalまでの最短距離をを返す 
        """
        d = [float('inf')] * self.V
        d[self.start] = 0

        # 最短経路での1つ前のノードを保持するリスト
        self.prev = [None] * self.V

        loop_counter = 0
        while True:
            update = False
            # start, end, cost
            for s, e, c  in self.edges:
                if d[s] != float('inf') and d[e] > d[s] + c:
                    d[e] = d[s] + c
                    self.prev[e] = s
                    update = True
            
            loop_counter += 1
            if loop_counter == self.V and update:
                d[self.start] = float('inf')
                break

            if not update:
                break
        
        return d

    def shortest_path(self, goal):
        """
        始点から頂点goalまでの最短経路をを返す 
        """
        path = []
        node = goal
        while node is not None:
            path.append(node)
            node = self.prev[node]
        return path[::-1]


def main():
    V, _, r, *edge = map(int, read().split())
    
    Edges = []
    for a, b, w in zip(*[iter(edge)]*3):
        Edges.append((a, b, w))

    bf = BellmanFord(V, Edges, r)
        
    dist = bf.shortest_distance()
    if dist[r] == float('inf'):
        print("NEGATIVE CYCLE")
    else:
        for d in dist:
            print(d if d < float('inf') else "INF")


if __name__ == "__main__":
    main()


Measured memory_bytes: 6216
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;



int main(){

    int H,W;
    int N;cin>>H>>W>>N;
    int a[N];REP(i,N)cin>>a[i];

    int color[H][W];
    fill(color[0],color[H],-1);
    bool dir=true;
    int h=0;int w=0;
    for(int j=1;j<=N;j++){
        REP(i,a[j-1]){
            color[h][w]=j;
            if(dir)w++;
            else w--;
            if(w==W){
                w=W-1;
                dir=false;
                h++;
            }
            if(w==-1){
                w=0;
                dir=true;
                h++;
            }
        }
    }

    REP(i,H){
        REP(j,W){
            cout<<color[i][j]<<" ";
        }
        cout<<endl;
    }


    return 0;
}

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

using namespace std;
using ll = long long;

const ll mod = 1000000007;

auto main (void) -> int {
  int n;
  cin >> n;

  vector<ll> a (n);
  for (auto i = 0; i < n; i++) cin >> a[i];

  ll tmp_0 = 0;
  ll tmp_1 = 0;

  for (auto i = 0; i < n; i++) {
    ll a_i = a[i] % mod;
    tmp_0  = (tmp_0 + a_i) % mod;
    tmp_1  = (tmp_1 + (a_i * a_i) % mod) % mod;
  }

  tmp_0 = (tmp_0 * tmp_0) % mod;

  ll b = tmp_0 < tmp_1 ? tmp_0 - tmp_1 + mod : tmp_0 - tmp_1;

  if (b % 2 != 0) {
    cout << (b + mod) / 2 << endl;
  } else {
    cout << b / 2 << endl;
  }

  return 0;
}


Measured memory_bytes: 4332
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<int,int>;

ll f(ll x,ll c,ll d){
    ll res =x;
    res -=x/c;
    res -=x/d;
    res+= x/lcm(c,d);
    return res;
}

vector<int> to[100005];
const ll inf =100000000;
int main(){
   ll n,k;
   cin>>n>>k;
   ll a=n/k;
   ll ans=n-k*a;
   ans=min(ans,llabs(ans-k));
   cout<<ans<<endl;
}


Measured memory_bytes: 5884
fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    loop {
        let a:u32 = sc.read();
        let b:u32 = sc.read();
        if a == 0 && b == 0 {
            break;
        }
        for i in 0..a {
            for j in 0..b {
                if i%2 == j%2 {
                    print!("#");
                }else {
                    print!(".");
                }
            }
            println!("");
        }
        println!("");
    }
    
}

use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
 
struct Scanner<'a> {
    cin: StdinLock<'a>,
}
 
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }
 
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }
 
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}


Measured memory_bytes: 5024
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            double H = cin.ReadLong;
            double log2 = Floor(Log(H,2));
            long ans = 1;
            if (H == 1)
            {
                Console.WriteLine(ans);
            }
            else
            {
                for (int i = 0; i < log2; i++)
                {
                    ans = 2 * ans + 1;
                }
                Console.WriteLine(ans);
            }
            
        }   

    }


    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        public double[] ReadDoubleArray(long N) { var ret = new double[N]; for (long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; }
    }
}


Measured memory_bytes: 13268
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
    if (a==1) {
      System.out.println("Hello World");
    } else {
      int b = sc.nextInt();
      int c = sc.nextInt();
      System.out.println(b+c);
    }
  }
}

Measured memory_bytes: 21972
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static final int MOD = 1000000007;
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int k = parseInt(sc.next());
		int x = parseInt(sc.next());
		sc.close();
		out.println(k*500>=x?"Yes":"No");
	}
}


Measured memory_bytes: 23764
object Main extends App {
  val n = scala.io.StdIn.readInt()
  val aInput = scala.io.StdIn.readLine()
  val aArray = aInput.split(" ").map(_.toLong).toVector

  var beforeStep = -1L
  var result = 0L

  aArray.foreach { a =>
    var updatedA = a
    if (beforeStep > 0L) {
      val sabun = beforeStep - a
      if (sabun > 0) {
        result = result + sabun
        updatedA = updatedA + sabun
      }
    }
    beforeStep = updatedA
  }
  println(result)
}

Measured memory_bytes: 86064
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin >>S;
    if(S=="MON"){
        cout <<6<<endl;
    }
    if(S=="TUE"){
        cout <<5<<endl;
    }
    if(S=="WED"){
        cout <<4<<endl;
    }
    if(S=="THU"){
        cout <<3<<endl;
    }
    if(S=="FRI"){
        cout <<2<<endl;
    }
    if(S=="SAT"){
        cout <<1<<endl;
    }
    if(S=="SUN"){
        cout <<7<<endl;
    }
}

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

int x,y,z;
long long sum;

int main() {
	cin >> x;
	for (int a = 1; a <= x; a++) {
		if (a%3 != 0 && a%5 != 0) sum += a;
	}
	cout << sum << "\n";
}

Measured memory_bytes: 3624
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int dp[200000],ch[200000],a,n,ans=1,b,MOD=1000000007;
vector<int> v;
int main(void){
    cin>>n;
    
    cin>>a;
    v.push_back(a);
    for(int i=1;i<n;i++){
        cin>>b;
        if(a!=b){
            v.push_back(b);
        }
        a=b;
    }
    n=v.size();
    
    memset(ch,-1,sizeof(ch));
    for(int i=0;i<n;i++){
        a=v[i];
        a--;
        if(ch[a]==-1)ch[a]=i;
        else{
            ans+=dp[ch[a]]+1;
            ans%=MOD;
            dp[i]=dp[ch[a]]+1;
            ch[a]=i;
        }
        if(i!=0)dp[i]+=dp[i-1];
        dp[i]%=MOD;
        //cout<<ans<<" "<<dp[i]<<endl;
    }
    cout<<ans<<endl;
}


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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, __VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

#define MOD 1000000007
#define INF 1000000000
#define MAX_N 200
#define MAX_V MAX_N

int d[MAX_V][MAX_V];    // d[u][v] は辺 e=(u,v) のコスト(存在しない場合は INF、ただし d[i][i]=0 とする)
int V;                  // 頂点数
int H, W;

int main()
{
    V = 100;
    // 初期化
    REP(i, V) { REP(j, V) { d[i][j] = (i==j) ? 0 : INF; }}

    cin >> H >> W;
    REP(i, 10) {
        REP(j, 10) {
            int tmp;
            cin >> tmp;
            d[i][j] = tmp;
        }
    }

    // ワーシャルフロイド
    REP(k, V) {
        REP(i, V) {
            REP(j, V) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    int ans = 0;
    REP(i, H) {
        REP(j, W) {
            int wall;
            cin >> wall;
            if(wall == -1 || wall == 1) { continue; }
            ans += d[wall][1];
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 384