akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
using namespace std;
int main()
{
	int a, b;
	cin >> a >> b;
	string s;
	for (int i = 0; i < a; i++) {
		cin >> s;
		cout << s << endl << s << endl;
	}
	return 0;
}


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

int main()
{
    string s;
    cin>>s;
    int flag=0;

    for(int i=0;i<s.length();i++)
    {
        if(s[i]==s[i+1])
           {
                flag = 1;
                break;
           }
    }
    if(flag == 1)
        cout<<"Bad"<<endl;
    else
        cout<<"Good"<<endl;

    return 0;
}


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

using namespace std;

int funcA(int a){
	return a * 2;
}
int funcB(int k, int a){
	return k + a;
}

int main(int argc, char const *argv[]) {
	int n,k;
	std::cin >> n;
	std::cin >> k;

	int ans = 1;
	for (size_t i = 0; i < n; i++) {
		ans = min(funcA(ans), funcB(k,ans));
	}
	std::cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<typename T>
void read(T &x)
{
    char ch=getchar();
    int f=1;
    for (x=0;ch!='-'&&(ch<'0'||ch>'9');ch=getchar());
    if (ch=='-') f=-1,ch=getchar();
    for (;ch>='0'&&ch<='9';x=x*10+ch-'0',ch=getchar());
    x*=f;
}
typedef long long ll;
int n;
ll A,B,C,D,H;
ll f[500010][2]; 
int main()
{
	read(n);
	read(A),read(B),read(C),read(D);
	H=A-B;
	f[1][0]=C,f[1][1]=D;
	for (int i=2;i<=n;i++)
		f[i][0]=f[i-1][0]+C,f[i][1]=f[i-1][1]+D;
	for (int i=0;i<n;i++)
		if (f[i][0]-f[n-i-1][1]<=H && H<=f[i][1]-f[n-i-1][0])
		{
			puts("YES");
			return 0;
		}
	puts("NO");
	return 0;
}

Measured memory_bytes: 8064
#![allow(unused_imports)]
#![cfg_attr(feature = "cargo-clippy", allow(style))]
use std::cmp::{max, min};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

//{{{input!
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[macro_export]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[doc(hidden)]
#[macro_export]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[doc(hidden)]
#[macro_export]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
//}}}

fn main() {
    input! {
        n: usize,
    }
    if n % 2 == 0 {
        println!("{}", n);
    } else {
        println!("{}", 2 * n);
    }
}


Measured memory_bytes: 4352
is_prime = [1]*101010
is_prime[0] = 0
is_prime[1] = 0
max = 101010

for i in range(2,max):
    if is_prime[i]:
        j = i*2
        while j <= max-1:
            is_prime[j] = 0
            j += i

a = [0]*max
for i in range(max):
    if(i%2==0): 
        continue
    if(is_prime[i]==1 and is_prime[(i+1)//2]==1):
        a[i]=1

s = [0]*(max+1)
for i in range(max):
    s[i+1] = s[i]+a[i]


q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    r += 1
    
    print(s[r]-s[l])

Measured memory_bytes: 8020
#include<stdio.h>
#include<iostream>
#include<vector>
#include <fstream>
#include<math.h>
#include <numeric>
#include<algorithm>
#include <stdlib.h>
# include <map>

using namespace std;

int main(){
    int n ,a,b;
    cin >> n;
    if(n == 1){
        cout << "Hello World" << endl;
    }
    else{
        cin >> a >> b;
        cout << a+b << endl;
    }
}


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

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	int c[1000100] = {};
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		c[a[i]]++;
	}
	if (c[1] >= 2) {
		cout << 0 << endl;
		return 0;
	} else if (c[1] == 1) {
		cout << 1 << endl;
		return 0;
	}

	vector<vector<int>> b(n);
	for (int i = 0; i < n; i++) {
		for (int j = 2; j * j <= a[i]; j++) {
			if (a[i] % j == 0) {
				b[i].emplace_back(j);
				b[i].emplace_back(a[i] / j);
			}
		}
	}
	
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (c[a[i]] >= 2) {
			continue;
		}
		bool ok = true;
		for (auto & j : b[i]) {
			if (c[j] != 0) {
				ok = false;
				break;
			}
		}
		if (ok) {
			ans++;
		}
	}
	cout << ans << endl;

	return 0;
}

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

inline int rd() {
  int x = 0;
  char c = getchar();
  while(!isdigit(c)) c = getchar();
  while (isdigit(c)) {
    x = x * 10 + (c ^ 48);
    c = getchar();
  }
  return x;
}

int n, cnt;

int main() {
  n = rd();
  int a, b;
  while (n--) {
    a = rd(); b = rd();
    if (a == b) ++cnt;
    else cnt = 0;
    if (cnt == 3) {puts("Yes"); return 0;}
  }
  puts("No");
  return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#define FAST std::ios::sync_with_stdio(false);
#define endl '\n'
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MAX_N 200005
#define Mem(a,b) memset(a,b,sizeof(a))
#define FREI freopen("in.txt","r",stdin)
#define FREO freopen("out.txt","w",stdout)
using namespace std;

int main() {
#ifdef ONLINE_JUDGE
#else
    //FREO;
#endif // ONLINE_JUDGE
//FREI;
    ll a,b,c,d,e,f;
    while(cin>>a>>b>>c>>d>>e>>f) {
        a=a*100;
        b=b*100;
        double dl=0.0;
        ll ans=0,res=0;
        for(ll i=0; i<=30; i++) {
            if(a*i>f)break;
            for(ll j=0; j<=30; j++) {
                if(a*i+b*j>f)break;
                for(ll m=0; m<=3000; m++) {
                    if(a*i+b*j+c*m>f)break;
                    for(ll n=0; n<=3000; n++) {
                        ll tmp=a*i+b*j+c*m+n*d;
                        if(tmp>f)break;
                        double tt=1.0*(c*m+n*d)/tmp;
                        //cout<<tmp<<endl;
                        if(tmp<=f&&(c*m+n*d)*100.0<=1.0*(a*i+b*j)*e&&tt>=dl) {
                            // cout<<i<<"  "<<j<<"  "<<m<<" "<<n<<endl;
                            dl=tt;
                            ans=tmp;
                            res=c*m+n*d;
                        }
                    }
                }
            }
        }
        cout<<ans<<" "<<res<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
K = int(input())
strN = [int(n) for n in str(N)]
keta_N = len(strN)

dp = [[[0] * 2 for _ in range(5)] for _ in range(keta_N+1)]
dp[0][0][0] = 1


#dp[keta][k][smaller]

for keta in range(keta_N):
    Nb = strN[keta]
    for k in range(4):
        for smaller in range(2):
            if smaller == 1:
                dp[keta + 1][k][smaller] += dp[keta][k][smaller]
                dp[keta + 1][k + 1][smaller] += dp[keta][k][smaller] * 9
            if smaller == 0:
                if Nb == 0:
                    dp[keta + 1][k][smaller] += dp[keta][k][smaller]
                if Nb == 1:
                    dp[keta + 1][k][smaller + 1] += dp[keta][k][smaller]
                    dp[keta + 1][k+1][smaller] += dp[keta][k][smaller]
                if Nb >= 2:
                    dp[keta + 1][k][smaller + 1] += dp[keta][k][smaller]
                    dp[keta + 1][k+1][smaller + 1] += dp[keta][k][smaller] * (Nb - 1)
                    dp[keta+1][k+1][smaller] += dp[keta][k][smaller]

print(dp[keta_N][K][0] + dp[keta_N][K][1])

Measured memory_bytes: 3064
a,b,c,d=map(int,input().split())
ans=0
if d-a>=0:
  d=d-a
  ans+=a
  if d-b>0:
      d-=b
      if d-c==0:
          ans-=c
      else:
          ans=ans-d
else:
    ans+=d
print(ans)    


Measured memory_bytes: 9112
#include<stdio.h>
int main(){
	int n,m;
	scanf("%d %d",&n,&m);
	int a[n][m];
	int b[m];
	
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			scanf("%d",&a[i][j]);
		}
	}
	for(int i=0;i<m;i++){
		scanf("%d",&b[i]);
	}
	int hasil[n];
	for(int i=0;i<n;i++){
		hasil[i]=0;
		for(int j=0;j<m;j++){
			hasil[i]+=(a[i][j]*b[j]);
		}
	}
	for(int i=0;i<n;i++){
		printf("%d\n",hasil[i]);
	}
	return 0;
}


Measured memory_bytes: 2768
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
const int N=2e5+10;
int main()
{
    string s;
    cin>>s;
    int a=s.length()%2,b=(s[0]==s[s.length()-1]);
    cout<<((a^b)?"First":"Second");
	return 0;
}


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

int main(){
 	string s; cin >> s;
  	for(int i = 0;i < s.size() ; ++i){
     	if(s[i] == '7'){
        	cout << "Yes" << endl;
          return 0;
        }
    }
  cout << "No" << endl;
  return 0;
  
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m,a=0,b=0;
  
  cin>>n;
  vector<string> v(n);
  for(int i=0;i<n;i++) cin>>v[i];
  cin>>m;
  vector<string> w(m);
  for(int i=0;i<m;i++) cin>>w[i];
  
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(v[i]==v[j]){
        b++;
      }
    }
    for(int j=0;j<m;j++){
      if(v[i]==w[j]){
        b--;
      }
    }
    a=max(a,b);
    b=0;
  }
  cout<<a<<endl;
  
}


Measured memory_bytes: 256
/**
* I'm sorry I was an Idiot
*/
#include<stdio.h>

int main(){
	char toRead[5];
	scanf("%s",toRead);
	int bad = 0;
	for(int i = 0; i < 3;++i){
		if(toRead[i] == toRead[i+1]){
			bad = 1;
			break;
		}
	}
	if(bad)
		puts("Bad");
	else
		puts("Good");
	return 0;
}

Measured memory_bytes: 256
n, k = list(map(int, input().split(' ')))
a = input()
acs = [0] * n
for i in range(1, n):
  acs[i] = acs[i-1] + (a[i-1: i+1] == 'AC')
print('\n'.join(map(str, [acs[e-1] - acs[s-1] for s, e in [list(map(int, input().split(' '))) for _ in range(k)]])))

Measured memory_bytes: 35424
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int n,m;
int array[305][305]={0};
int idx[305]={0};
bool judge(int border){
  for(int i=1;i<=n;i++) idx[i]=1;
  int cnt[305]={0};
  bool used[305];
  for(int i=1;i<=m;i++) used[i]=false;
  while(1){
    for(int i=0;i<=m;i++) cnt[i]=0;
    for(int i=1;i<=n;i++) cnt[array[i][idx[i]]]++;
    bool f=false;
    for(int i=1;i<=m;i++){
      if(cnt[i]>border) used[i]=true;
    }
    for(int i=1;i<=n;i++){
      while(used[array[i][idx[i]]]){
        idx[i]++;
        f=true;
        if(idx[i]>m) return false;
      }
    }
    if(!f) return true;
  }
}
int main(){
  cin>>n>>m;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      cin>>array[i][j];
    }
  }
  int lb=0,rb=n+1;
  while(rb-lb>1){
    int mid=(lb+rb)/2;
    if(judge(mid)) rb=mid;
    else lb=mid;
  }
  cout<<rb<<endl;
}


Measured memory_bytes: 640
/*
Author : Xinyuan
*/
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
#define PI acos(-1)
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef long long int  ll;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int nxt() {int x;scanf("%d", &x);return x;}


int main(){
    double a,b,h,m;
    cin >> a >> b >> h >> m;
    h+=m/60;
    double theta = abs(m*6 - h*30)*PI/(double)180;
    double c = sqrt(a*a + b* b - 2 * a * b * cos(theta));
    printf("%.15f", c);
    return 0;
}



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

const int maxN = 4010;
const int mod = 998244353;
typedef long long ll;

int C[maxN][maxN], pw[maxN];

void init(){
	int i, j;
	for(i = 0; i < maxN; ++i){
		C[i][0] = C[i][i] = 1;
		for(j = 1; j < i; ++j) C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
	}
	for(i = 1, pw[0] = 1; i < maxN; ++i)
		pw[i] = (pw[i - 1] << 1) % mod;
}

inline int Cbar(int n, int k) { if(k < 0) return 0; return C[n + k - 1][k]; }

inline ll getCount(int n, int k, int cnt){
	int j; ll res = 0;
	for(j = 0; j <= cnt; ++j){
		ll t = (C[cnt][j] * 1ll * Cbar(k - j - (cnt - j) * 2, n - j)) % mod;
		t = (t * pw[j]) % mod;
		res = (res + t) % mod;
	}
	return res;
}

int main (){
	int k, n, i, j, cnt;
	scanf("%d%d", &k, &n);
	for(init(), i = 2; i <= 2 * k; ++i){
		for(j = 1, cnt = 0; j <= k; ++j)
			if(0 < (i - j) && (i - j) <= k) ++cnt;
		if(cnt & 1)
			printf("%lld\n", (getCount(n, k - 1, cnt / 2) + 
							getCount(n - 1, k - 1, cnt / 2)) % mod);
		else printf("%lld\n", getCount(n, k, cnt / 2));
	}
	return 0;
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define line cout << __LINE__;
#define prv(a) for(auto x : a) cout << x << ' ';cout << '\n';
#define decimal_digits cout << fixed << setprecision(15);
#define sp cout << " ";

typedef unordered_map<int,int> umi;
typedef unordered_map<ll,ll> uml;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

int main(){

	string s;
	cin >> s;
	ll n = (ll)s.size();

	ll ans = 0;

	string t = "";

	string res = "";

	for(ll i = 0;i < n;i++){

		// for(ll j = i;j <= i + 2 and j < n;j++){
		// 	t += s[j];
		// }
		// if(t == "ABC"){
		// 	s[i] = 'B';
		// 	s[i + 1] = 'C';
		// 	s[i + 2] = 'A';
		// 	ans++;
		// 	i += 2;
		// 	ans += sz(r);
		// 	r += 'A';
		// }else{
		// 	r = "";
		// }
		// t = "";
		if(s[i] == 'A')
			res += 'A';
		else if(s[i] == 'B'){
			if(i < n - 1){
				if(s[i + 1] == 'C'){
					ans += sz(res);
					i++;
				}else{
					res = "";
				}
			}
		}else{
			res = "";
		}

	}
	cout << ans << '\n';
}

Measured memory_bytes: 776
using System;
using System.Linq;

class AizuOnlineJudge {
    static void Main() {
        var q = new[] { 6, 5, 4, 3, 2, 7, 6, 5, 4, 3, 2, 1 };
        var d = 0;
        var sum = 0;

        var input = Console.ReadLine()
            .ToCharArray()
            .Select((c, i) => {
                var t = c == '?' ? ((d = q[i]) & 0) : int.Parse(c.ToString()) * q[i];
                sum += t;
                return t;
            })
            .ToList();

        if (d == 1) {
            Console.WriteLine(CD(sum % 11));
        }
        else {
            var result = Enumerable.Range(0, 10)
                .Where(i => input[11] == CD(((sum - input[11]) + i * d) % 11))
                .Take(2)
                .ToList();

            Console.WriteLine(result.Count >= 2 ? "MULTIPLE" : result[0].ToString());
        }
    }

    static int CD(int v) => v <= 1 ? 0 : 11 - v;
}



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

int main()
{
   long long int n,x;
   cin>>n>>x;
   
   long long int tot=0;
   for(long long int i=0;i<n;++i)
   {
       long long int X,Y;
       cin>>X>>Y;
       
       if(((X*X)+(Y*Y))<=(x*x))
       {
           tot++;
       }
   }
   
   cout<<tot<<endl;
}

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

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rept(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(int)(n);(i)++)
#define repst(i,s,n) for(int (i)=(s);(i)<=(int)(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>=0;(i)--)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln "\n"
#define show(x) cout << #x << " = " << x ln
#define dbg(x) cout<<#x"="<<x ln

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > mat;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, k, a, cnt[200001];

int main() {
	cin >> n >> k;
	rep(i,n) {
		cin >> a;
		cnt[a]++;
	}
	sort(cnt, cnt+200001);
	int g = 0;
	rep(i,200001) {
		if (cnt[i]>0) g++;
	}
	
	int num = max(0, g-k);
	int ans = 0;
	rep(i,200001) {
		while (cnt[i]==0) i++;
		rep(j,num) {
			ans += cnt[i];
			i++;
		}
		break;
	}
	cout << ans << ln;
	
}

Measured memory_bytes: 1024
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

e=min(a)+min(b)

for _ in range(M):
    x,y,c=map(int,input().split())
    f=a[x-1]+b[y-1]-c
    e=min(e,f)

print(e)


Measured memory_bytes: 70596
a,b,c = gets.chomp.split(" ").map(&:to_i)
ans = 0
if a%2 == b%2 && b%2 != c%2
  a += 1
  b += 1
  ans += 1
elsif b%2 == c%2 && c%2 != a%2
  b += 1
  c += 1
  ans += 1
elsif c%2 == a%2 && a%2 != b%2
  c += 1
  a += 1
  ans += 1
end
m = [a,b,c].sort!
puts ans+(m[2]*2-m[1]-m[0])/2

Measured memory_bytes: 1788
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int W = scanner.nextInt();

    long[] w = new long[N];
    long[] v = new long[N];

    for (int i = 0; i < N; i++) {
      w[i] = scanner.nextInt();
      v[i] = scanner.nextInt();
    }

    long[][] vw = new long[4][N + 1];
    for (int i = 0; i < N; i++) {
      vw[(int) (w[i] - w[0])][i] = v[i];
    }
    for (int i = 0; i < 4; i++) {
      Arrays.sort(vw[i]);
      reverse(vw[i], 1, N);
      for (int j = 1; j < N + 1; j++) vw[i][j] += vw[i][j - 1];
    }

    long max = 0;
    for (int a = 0; a <= N; a++) {
      for (int b = 0; b <= N - a; b++) {
        for (int c = 0; c <= N - a - b; c++) {
          for (int d = 0; d <= N - a - b - c; d++) {
            long tw = w[0] * a + (w[0] + 1) * b + (w[0] + 2) * c + (w[0] + 3) * d;
            long tv = vw[0][a] + vw[1][b] + vw[2][c] + vw[3][d];
            if (tw > W) continue;
            max = Math.max(max, tv);
          }
        }
      }
    }
    System.out.println(max);
  }

  private static void swap(long[] a, int i, int j) {
    long tmp = a[i];
    a[i] = a[j];
    a[j] = tmp;
  }

  private static void reverse(long[] a, int i, int j) {
    if (i > j) throw new IllegalArgumentException("i must be less than j");
    while (i < j) {
      swap(a, i, j);
      i++;
      j--;
    }
  }
}


Measured memory_bytes: 21972
n = int(input())
lst = [[-1 for _ in range(n)] for __ in range(n)]
for i in range(n):
    ai = int(input())
    for j in range(ai):
        hito, which = map(int, input().split())
        lst[i][hito-1] = which

ans = 0
muri = 0
for i in range(2**n):
    kumi = list(format(i, '0'+str(n)+'b'))
    temp = 0
    muri = 0
    for j in range(n):
        if muri == 1:
            break
        elif kumi[j] == '1':
            for k in range(n):
                if (lst[k][j] == 0 and kumi[k] == '1') or (lst[j][k] == 1 and kumi[k] == '0'):
                    muri = 1
                    break
            if muri == 0:
                temp += 1
    if muri == 0:
        ans = max(ans, temp)

print(ans)

Measured memory_bytes: 44380
#include<iostream>

using namespace std;

int main(){
  int i1,i2,i3,i4,i5,i6,i7,i8,i9,i10;
  int N,M,Q;
  int sum=0;
  int summax=0;
  int a[Q],b[Q],c[Q],d[Q];
  
  cin >> N >> M >> Q;
  for(int k=0;k<Q;k++){
    cin >> a[k] >> b[k] >> c[k] >> d[k];
  }
  
  for(i1=1;i1<=M;i1++){
  for(i2=i1;i2<=M;i2++){
  for(i3=i2;i3<=M;i3++){
  for(i4=i3;i4<=M;i4++){
  for(i5=i4;i5<=M;i5++){
  for(i6=i5;i6<=M;i6++){
  for(i7=i6;i7<=M;i7++){
  for(i8=i7;i8<=M;i8++){
  for(i9=i8;i9<=M;i9++){
  for(i10=i9;i10<=M;i10++){
  sum=0;
  int A[]={i1,i2,i3,i4,i5,i6,i7,i8,i9,i10};
  for(int k=0;k<Q;k++){
    if(A[b[k]-1]-A[a[k]-1]==c[k]){
      //cout << a[k] << " " << b[k] << " " << c[k] << " " << d[k] << ":";
      //cout << A[0] << A[1] << A[2] << A[3] << A[4] << endl;
      sum+=d[k];
    }
  }
  summax=max(sum,summax);
  }}}}}}}}}}
  cout << summax << endl;
  return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
using namespace std;
using P = pair<int, int>;
typedef long long ll;

int main() {
  int k;
  cin >> k;
  if(k % 2 == 0){
    cout << -1 << endl;
    return 0;
  }
  if(k % 5 == 0){
    cout << -1 << endl;
    return 0;
  }
  if(k == 7){
    cout << 1 << endl;
    return 0;
  }
  int ans = 1;
  ll kakeru = 1;
  rep(i, k){
    ll num = 7 * kakeru;
    if(num % k == 0){
      cout << ans << endl;
      return 0;
    }
    kakeru *= 10;
    kakeru += 1;
    kakeru %= k;
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

int b[202020];

void divisor(ll n){
    for(ll i=1; i*i <= n; i++){
        if(n % i == 0){
            b[i]++;
            if(i != n / i) b[n / i]++;
        }
    }
    b[n] %= 2;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> a(N+1);
    REP(i,N) cin >> a[i+1];
    int cnt = 0;
    vector<int> ans;
    for(int i=N;i>0;i--){
        b[i] %= 2;
        if(a[i] == b[i]) continue;
        else{
            divisor(i);
            cnt++;
            ans.push_back(i);
        }
    }
    reverse(ans.begin(),ans.end());
    if(a[1] != b[1]){
        cout << -1 << endl;
        return 0;
    }
    cout << cnt << endl;
    REP(i,cnt) cout << ans[i] << " ";
    cout << endl;
}


Measured memory_bytes: 3832
using System;
class main
{
    static void Main(string[] args)
    {
        string s;
        while ((s = Console.ReadLine()) != null)
        {
            double x1, y1, x2, y2, x3, y3, px, py, abc, abp, pbc, apc;
            string[] a = s.Split(' ');
            x1 = double.Parse(a[0]);
            y1 = double.Parse(a[1]);
            x2 = double.Parse(a[2]);
            y2 = double.Parse(a[3]);
            x3 = double.Parse(a[4]);
            y3 = double.Parse(a[5]);
            px = double.Parse(a[6]);
            py = double.Parse(a[7]);
            abc = Math.Abs(((x1 * (y2 - y3)) + (x2 * (y3 - y1)) + (x3 * (y1 - y2))) * 0.5);
            abp = Math.Abs(((x1 * (y2 - py)) + (x2 * (py - y1)) + (px * (y1 - y2))) * 0.5);
            pbc = Math.Abs(((px * (y2 - y3)) + (x2 * (y3 - py)) + (x3 * (py - y2))) * 0.5);
            apc = Math.Abs(((x1 * (py - y3)) + (px * (y3 - y1)) + (x3 * (y1 - py))) * 0.5);
            if ((abp + pbc + apc) - abc < 0.001)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");
        }
    }
}

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

int main(){
  int N, X, Y;
  cin >> N >> X >>Y;
  int k=1;
  long long ans = 0;
  map<int, int> x;
  for(int i=1; i<=N-1; i++){
    for(int j=i+1; j<=N; j++){
      long long minway = min(abs(j-i),min(abs(X-i)+1+abs(j-Y),abs(Y-i)+1+abs(j-X)));
      if(x.count(minway)){
        x.at(minway)+=1;
      }
      if(!x.count(minway)){
        x.emplace(minway, 1);
      }
    }
  }
  for(int i=1; i<=N-1; i++){
    if(x.count(i))cout << x.at(i) << endl;
    else cout << 0 << endl;
  }
  return 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#define int  long long int
	#define pb push_back
	#define fe first
	#define lb lower_bound 
	#define ub upper_bound
	#define pii pair<pair<int,int>,pair<int,int> >
	#define se second
	#define endl "\n"
	#define pi pair<int, int>
	#define mi          map<int,int>
	#define mii         map<pi,int>
	#define vi vector<int> 
	#define vvi vector<vi>
	#define bs   binary_search
	#define rep(i,a,b) for(int i=a;i<b;i++)
	#define rep1(i,a,b) for(int i=a;i<=b;i++)	
	#define all(c) (c).begin(),(c).end()
	#define sz(x)       (int)x.size() 
	#define PI 3.14159265358979323846
	
	 const int N =1e5;
	
	 int mod= 1e9+7;
	 int dx[4]={0,0,+1,-1};
	 int dy[4]={+1,-1,0,0};  
	 
	 
	int po(int a, int b) {
		a %= mod;
		int res = 1;
		while (b > 0) {
			if (b & 1)
				res = (res * a) % mod;
			a =(a*a) % mod;
			b >>= 1;
		}
		 return res;	
	   }

	
	 void solve(){
		int k,n;
		cin>>k>>n;
	    vi v(n,0);
	    rep(i,0,n) cin>>v[i];
	    int mx=v[0]+k-v[n-1];
	    rep(i,1,n) {
			   mx=max(mx,abs(v[i]-v[i-1]));
			} 
			cout<<k-mx<<endl;		 
	 }
	
int32_t main() {
	cool;
	int t=1;
	//cin>>t;
	while(t--)
	   solve();
	   
	   
	   return 0;	   
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
int x1,x2,x3,x4,y1,y2,y3,y4;
  cin >> x1 >> y1 >> x2 >> y2;
  x3 = x2 -(y2-y1);
  y3 = y2 +  x2 - x1;
  x4 = x3 - (x2- x1);
  y4 = y3 - (y2 - y1);
  cout << x3 <<" "<< y3<<" "<< x4 <<" "<< y4 << endl;
}

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

int main(void)
{
	int n, m, a, b;
	cin >> n;
	vector<int> A;
	rep(i, n)
	{
	    cin >> a;
		A.push_back(a);
	}
	cin >> m;
	vector<int> B;
	rep(i, m)
	{
	    cin >> b;
		B.push_back(b);
	}

    if (includes(A.begin(), A.end(), B.begin(), B.end()))
    {
        cout << 1 << endl;
    }
    else
    {
        cout << 0 << endl;
    }
}


Measured memory_bytes: 5240
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Linq.Enumerable;

class Program
{
    static void Main()
    {
        var N = int.Parse(ReadLine());

        var cnt = Repeat(int.MaxValue, 100_001).ToArray();

        var units = new[] { 1 }
            .Concat(Range(1, 6).Select(i => (int)Math.Pow(6, i)))
            .Concat(Range(1, 5).Select(i => (int)Math.Pow(9, i)))
            .Where(x => x < cnt.Length).OrderBy(x => x).ToArray();

        var q = new Queue<(int v, int c)>(units.Select(x => (x, 1)));

        foreach (var (v, c) in q)
            cnt[v] = c;

        while(0 < q.Count)
        {
            var (v, c) = q.Dequeue();
            var nextC = c + 1;

            foreach (var nextV in units.Select(x => v + x).Where(x => x < cnt.Length))
            {
                if (cnt[nextV] == int.MaxValue)
                {
                    cnt[nextV] = nextC;
                    q.Enqueue((nextV, nextC));
                }
            }
        }

        WriteLine(cnt[N]);
    }
}

static class ArrayDeconstructExtensions
{
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2) => (i1, i2) = (a[0], a[1]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3) => (i1, i2, i3) = (a[0], a[1], a[2]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4) => (i1, i2, i3, i4) = (a[0], a[1], a[2], a[3]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4, out T i5) => (i1, i2, i3, i4, i5) = (a[0], a[1], a[2], a[3], a[4]);
}


Measured memory_bytes: 48352
#include <bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second
#define resz resize
 
#define sz(x) ll((x).size())
#define all(x) (x).begin(), (x).end()
 
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define F0R(i, a) for (ll i = 0; i < (a); i++)
#define FORR(i, a, b) for (ll i = a; i >= (b); i--)
#define F0RR(i, a) for (ll i = a; i >= 0; i--)
#define trav(a, x) for (auto& a : x)

using ll = long long;
using vi = vector<ll>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
 
using pii = pair<ll, ll>;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
 
using vpii = vector<pii>;
using vvpii = vector<vpii>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
using vpdd = vector<pdd>;
using vvpdd = vector<vpdd>;
 
ll gcd(ll a,ll b)
{
    if(b==0)return a;
    else return gcd(b,a%b);
}
ll po(ll a,ll b)
{
    ll ans = 1;
    while(b--)
        ans*=a;
    return ans;
}
ll pom(ll a,ll b,ll mod)
{
    if(b==0)return 1;
    ll k = pom(a,b/2,mod);
    if(b%2==0)return (k*k)%mod;
    else return ((k*k)*mod*a)%mod;
}
 
ll sqdist(ll a,ll b,ll c,ll d)
{
    return (a-c)*(a-c)+(b-d)*(b-d);
}


ll arr[100005];
void solve()
{
     ll n,m;
     cin>>n>>m;
     FOR(i,0,n)cin>>arr[i];
     ll p = arr[0];
     FOR(i,1,n)
     {
        ll g = gcd(p,arr[i]);
        p = (p*arr[i])/g;
     }
     m*=2;
     FOR(i,0,n)
     {
        //cout<<p<<' '<<arr[i]<<endl;
        if((p/arr[i])%2==0){cout<<0;return;}
     }

     //cout<<p<<' '<<m<<endl;
     ll ans = m/p;
     if(ans%2==0)cout<<ans/2;
     else cout<<ans/2+1;
}

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

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    // ll t;
    //cout<<"Y"<<endl;
    //cin>>t;
    //while(t--)
        solve();
}

Measured memory_bytes: 1024
# import math
# import bisect
# import heapq
# from collections import deque
# import numpy as np

# k,x = map(int, input().split())
n = int(input())
s = input()
# a = list(map(int,input().split()))
count = 0
for i in range(n-2):
    # print(s[i:i+3])
    if s[i:i+3] == 'ABC':
        count += 1

print(count)

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#define _PI (3.141592653589793)
int main()
{
	int A, B, H, M;
	std::cin >> A >> B >> H >> M;
	const double m = H * 60 + M;
	const double degA = (m / (12 * 60))*360;
	const double degB = (m / (1 * 60))*360;
	const double yA = A * sin(degA / 180 * _PI);
	const double xA = A * cos(degA / 180 * _PI);
	const double yB = B * sin(degB / 180 * _PI);
	const double xB = B * cos(degB / 180 * _PI);

	std::cout << std::fixed << std::setprecision(15) << sqrt(pow(xA - xB, 2) + pow(yA - yB, 2)) << std::endl;

	return 0;
}

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

using namespace std;

int main() {
    string s;
    cin >> s;

    int n = s.length();
    vector<int> ans(n);
    for (int i = 0; i < n; ++i) {
        int t = 0;
        while (s[i] == 'R') {
            t++;
            i++;
        }
        ans[i - 1] += t - t / 2;
        ans[i] += t / 2;
    }

    reverse(s.begin(), s.end());
    reverse(ans.begin(), ans.end());
    for (int i = 0; i < s.length(); ++i) {
        int t = 0;
        while (s[i] == 'L') {
            t++;
            i++;
        }
        ans[i - 1] += t - t / 2;
        ans[i] += t / 2;
    }

    reverse(ans.begin(), ans.end());
    for (int i = 0; i < n; ++i) {
        cout << ans[i] << ((i == n - 1) ? "\n" : " ");
    }
    return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    string S; cin >> S;
    ll max_cnt = 0, cnt = 0;
    set<char> st{'A', 'T', 'G', 'C'};
    rep(i, S.size()){
        if (st.find(S[i]) != st.end()){
            cnt++;
        } else {
            if (cnt > max_cnt){max_cnt = cnt;}
            cnt = 0;
        }
    }
    if (cnt > max_cnt){max_cnt = cnt;}
    cout << max_cnt << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll //9223372036854775807
#define pi acos(-1.0)
#define ms(a,b) memset(a,b,sizeof(a))
#define nl "\n"
#define FAST_IO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
typedef long long ll;
const int mod = 998244353;
ll qpow(ll x, ll y){ll s=1;while(y){if(y&1)s=s*x%mod;x=x*x%mod;y>>=1;}return s;}
//ll qpow(ll a, ll b){ll s=1;while(b>0){if(b%2==1)s=s*a;a=a*a;b=b>>1;}return s;
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();return x*f;}
ll inve(ll x){return x==1?1:(mod-mod/x)*inve(mod%x)%mod;}

const int N = 1e6+5;

string s, str="keyence";

int main()
{

    cin>>s;

    if(s.substr(s.length()-7) == str)
        return puts("YES"),0;

    for(int i=0;i<s.length()-7;i++)
        if(s.substr(i,i+7)==str)
            return puts("YES"),0;


    for(int i=1;i<=6;i++)
    {
        string ss=s.substr(0,i)+s.substr(s.length()-7+i);
        if(ss==str) return puts("YES"),0;
    }

    puts("NO");

    return 0;
}


Measured memory_bytes: 256
from itertools import groupby
S = input()
K = int(input())
a1 = 0
for v, g in groupby(S):
    n = len(list(g))
    a1 += n // 2

if n == len(S):
    print(n * K // 2)
    exit()

a2 = 0
for v, g in groupby(S+S):
    n = len(list(g))
    a2 += n // 2

print(a1 + (a2-a1)*(K-1))


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

ll A;
string B;

int main(){
  cin >> A >> B;
  B.erase(B.begin()+1);
  ll ans = (A * stoi(B) / 100);
  cout << ans << endl;
}


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

int main()
{
  ll K, N;
  cin >> K >> N;
  ll M = 0;
  ll before = 0;
  ll first;
  ll m = 0;
  for (ll i = 0; i < N; ++i)
  {
    ll a;
    cin >> a;
    if (i == 0)
    {
      first = a;
      before = a;
      continue;
    }
    if (a - before > m)
    {
      m = a - before;
    }
    // cout << a - before << endl;
    before = a;
  }
  // cout << K - (before - first) << endl;
  m = max(m, K - (before - first));
  cout << K - m << endl;
}


Measured memory_bytes: 256
// https://beta.atcoder.jp/contests/abc106

#define SUBMIT

#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>
#include <unordered_map>
#include <map>

using namespace std;
using ui64 = unsigned long long;
using i64 = long long;

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

    int ans = 0;
    for (int i = 1; i <= N; ++i) {
        if (i % 2 == 0) continue;

        int count = 0;
        for (int j = 1; j <= i; ++j) {
            if (i % j == 0) count++;
        }

        if (count == 8) ans++;
    }

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


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

#define F first
#define S second
typedef double db;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll gcd(ll x,ll y){
return y? gcd(y,x%y):x;
}

int main(){
  ll n,k,ans,mx,mn;
  cin>>n>>k;
  n%=k;
  cout<<min(n,abs(n-k))<<endl;
return 0;
}



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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var abk = ReadLongs();
            //高橋
            var takahashi = abk[0];
            //青木
            var aoki = abk[1];
            var K = abk[2];

            var ansA = Max(takahashi - K, 0);
            var nokori = Max(K - takahashi, 0);
            var ansB = aoki - nokori;

            WriteLine(Max(ansA,0) + " " + Max(ansB,0));
        }

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13140
class Abc81:
    def __init__(self):
        self.N = int(input())

    def resolve(self):
        for i in range(1,10):
            temp_ans = self.N/i
            if temp_ans  < 10 and temp_ans.is_integer():
                ans = 'Yes'
                break
            else:
                ans = 'No'
        print(ans)        
            

resolver = Abc81()
resolver.resolve()

Measured memory_bytes: 2940
s = input()
n = len(s)
a = 0
b = 0
for i in range(n):
    if i % 2 == 0:
        if s[i] == '0':
            a += 1
        else:
            b += 1
    else:
        if s[i] == '0':
            b += 1
        else:
            a += 1
print(min(a, b))


Measured memory_bytes: 39920
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin>>n;
    int t=0,x=0,y=0;
    for(int i=0;i<n;i++){
        int nt,nx,ny;
        cin>>nt>>nx>>ny;
        int d=abs(nt-t)-abs(nx-x)-abs(ny-y);
        if(d<0||d%2==1){cout<<"No"<<endl;return 0;}
        t=nt,x=nx,y=ny;
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
# 63


n = int(input())
dp = [[int(x) for x in input().split()] for y in range(n)]
del_l = []
ans = 0

# for i in range(n):
#     for j in range(i+1,n):
#         ans += dp[i][j]

for i in range(n-1):
    for j in range(i+1,n):
        for k in range(n):
            if k in (i,j):
                continue
            if dp[i][j] > dp[i][k] + dp[k][j]:
                print("-1")
                exit()
            elif dp[i][j] == dp[i][k] + dp[k][j]:
                break
        else:
            ans += dp[i][j]

print(ans)



Measured memory_bytes: 75312
#!python3

# input
D, N = list(map(int, input().split()))


def main():
    if N == 100:
        ans = 100 ** (D + 1) + 100 ** D
    else:
        ans = str(N) + "00" * D
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if (s.charAt(0)==s.charAt(1) && s.charAt(1)==s.charAt(2)) {
            System.out.print("No");
        } else {
            System.out.print("Yes");
        }
    }
}


Measured memory_bytes: 35768
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	ll N;
	cin >> N;

	ll kazu[30];
	kazu[0] = 0;
	int k = 0;
	while (1) {
		kazu[k + 1] = kazu[k] * 26 + 26;
		ce(kazu[k + 1]);
		if (kazu[k + 1] > 1e16) break;
		k++;
	}



	while (k >= 0) {
		if (N > kazu[k]) break;
		k--;
	}
	ce(k);

	N -= kazu[k] + 1;

	char kotae[30];
	rep(i, k + 1) {
		kotae[i] = 'a' + N % 26;
		N /= 26;
	}
	for (int i = k; i >= 0; i--) {
		cout << kotae[i];
	}
	cout << endl;



	Would you please return 0;
}

Measured memory_bytes: 3640
// D - Integer Cards

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const int MOD = 1e9 + 7;

struct Exchange {
	int B;
	int C;
};

Exchange exc[100000];
int A[100000];

int main() {
	int N, M;
	cin >> N >> M;

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

	sort(A, A+N);

	for (int i=0; i<M; i++) {
		cin >> exc[i].B >> exc[i].C;
	}

	sort(exc, exc+M, [](const Exchange &a, const Exchange &b) {
		return a.C > b.C;
	});

	int i=0;
	int j=0;
	while (i < N && j < M) {
		for (int k=0; k<exc[j].B && i < N && A[i] < exc[j].C; k++) {
			A[i] = exc[j].C;
			i++;
		}
		j++;
	}

	ll ans = 0;
	for (int i=0; i<N; i++) {
		ans += A[i];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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



template <typename T>
class dijkstra
{
private:
    using P = pair<T, T>;
    struct edge{
        long long to;
        T cost;
    };
    long long vertex;   // 頂点数
    vector<vector<edge>> list;  //隣接リスト
    vector<T> distance;    // 距離
public:
    dijkstra(long long n, T infinity = 1e16);  // nは頂点の数、infinityは初期化に使う値
    void add_edge(long long v1, long long v2, T cost);    // 頂点v1から頂点v2に辺を張る
    void run(long long s);        // sは開始地点。
    T get_distance(long long v);    // 頂点vへの距離を返す
};

template <typename T>
dijkstra<T>::dijkstra(long long n, T infinity){
    vertex = n;
    list.resize(n);
    distance = vector<T>(vertex, infinity);
}

template <typename T>
void dijkstra<T>::add_edge(long long v1, long long v2, T cost){
    list[v1].push_back({ v2, cost });
}

template <typename T>
void dijkstra<T>::run(long long s){
    priority_queue<P, vector<P>, greater<P>> que;
 
    distance[s] = 0;    // 開始点の距離は0
    que.push(P(0, s));
    
    while(!que.empty()){
        P p = que.top(); que.pop();
        T v = p.second;
        if(distance[v] < p.first) continue;
        for(auto e : list[v]){
            if(distance[e.to] > distance[v] + e.cost){
                distance[e.to] = distance[v] + e.cost;
                que.push(P(distance[e.to], e.to));
            }
        }
    }
}

template <typename T>
T dijkstra<T>::get_distance(long long v){
    return distance[v];
}



int main() {
    ll n;
    cin >> n;
    
    dijkstra<ll> dik(n);
    REP(i, n - 1){
        ll a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        dik.add_edge(a, b, c);
        dik.add_edge(b, a, c);
    }
    
    ll q, k;
    cin >> q >> k;
    k--;
    dik.run(k);
    REP(i, q){
        ll x, y;
        cin >> x >> y;
        x--; y--;
        printf("%lld\n", dik.get_distance(x) + dik.get_distance(y));
    }
}

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

int main(){
  cout << fixed << setprecision(10);

  int N; cin >> N;
  vector<double> dp(N+1,0);
  dp[0] = 1;

  double ans = 0;

  for (int i=0; i<N; i++){
    double p; cin >> p;
    double a = dp[0];
    dp[0] *= 1 - p;
    for (int j=1; j<=i+1; j++){
      double b = dp[j];
      dp[j] = a * p + b * (1 - p);
      a = b;

      if (j > N / 2){
        ans += dp[j];
        dp[j] = 0;
        break;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << fixed;
    string s;
    for (int i = 0; i < 4; ++i) {
        char c;
        cin >> c;
        s += c;
    }
    sort(s.begin(), s.end());
    string t = "1974";
    sort(t.begin(), t.end());

    if (s == t) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}



Measured memory_bytes: 256
import java.io.*;

class Main {

  public static void main(String[] args) throws Exception {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    try {

      String inputL1 = br.readLine();
      String[] inputNum = inputL1.split(" ");

      int n = Integer.parseInt(inputNum[0]);
      int m = Integer.parseInt(inputNum[1]);

      String inputL2 = br.readLine();
      String[] strArray = inputL2.split(" ", 0);

      int[] num = new int[n];
      for (int i = 0; i < n; i++) {
        num[i] = Integer.parseInt(strArray[i]);
      }

      for (int i = 0; i < n; i++) {
        for (int j = 0; j < n - (i+1); j++) {
          if (num[j] < num[j+1]) {
            int tmp = num[j];
            num[j] = num[j+1];
            num[j+1] = tmp;
          }
        }
      }

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

      System.out.println(ans);

    } catch(Exception e) {
      System.err.println("hoge");
    }
  }

}

Measured memory_bytes: 21204