akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(ll i=0;i<(n);i++)
 
using namespace std;


int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n)   cin >> a[i];

    set<ll> st;
    for(auto e : a) st.insert(e);

    priority_queue<ll, vector<ll>, greater<ll>> que;
    ll minn = 1e10;
    ll maxx = 0;
    for(auto e : st){
        que.push(e);
        minn = min(minn, e);
        maxx = max(maxx, e);
    }

    if(maxx < k){
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }

    ll x = 1e10;
    bool b = true;
    while(b){
        for(auto e : st){
            if(0 < e && k <= e && e%minn == k%minn){
                x = k;
                break;
            }
            if(0 < e && 0 < e%minn)  st.insert(e%minn);
        }
        if(0 < st.count(k)){
            x = k;
            break;
        }

        b = false;
        for(auto e : st){
            if(e < minn){
                minn = e;
                b = true;
                break;
            }
        }
    }

    if(x == k)  cout << "POSSIBLE" << endl;
    else        cout << "IMPOSSIBLE" << endl;

    return 0;
}


Measured memory_bytes: 7668
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
   int N,M,X;
   cin>>N>>M>>X;
   int A[M];
   
   int ans0,ansN;
   rep(i,M){
       cin>>A[i];
       if(X<A[i]){
           ans0=i;
           ansN=M-i;
           break;
       }
   }
   int ans=min(ans0,ansN);
   cout<<ans<<endl;
    
}

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

int n;
std::pair<int, int> p[201];
std::map<std::pair<std::pair<int, int>, int>, int> l;
std::set<std::pair<std::pair<int, int>, int>> s;

typedef long long ll;
const ll mo = 998244353ll;

ll mpow(ll t, ll k, const ll &m) {
	ll ans = 1 % m;
	for(; k > 0; k >>= 1, t = t * t % m)
	if(k & 1)
		ans = ans * t % m;
	return ans;
}

ll calc(const ll &cnt) {
	return ((mpow(2ll, cnt, mo) - cnt - cnt * (cnt - 1ll) / 2ll % mo - 1ll) % mo + mo) % mo;
}

int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; ++i)
		scanf("%d%d", &p[i].first, &p[i].second);
	std::sort(p, p + n);
	for(int i = 0, dx, dy, d, c; i < n; ++i) {
		s.clear();
		for(int j = 0; j < n; ++j)
		if(i != j) {
			if(p[i].first == p[j].first) {
				c = p[i].first;
				if(s.find({{1, 0}, c}) == s.end()) {
					++l[{{1, 0}, c}];
					s.insert({{1, 0}, c});
				}
			} else if(p[i].second == p[j].second) {
				c = p[i].second;
				if(s.find({{0, 1}, c}) == s.end()) {
					++l[{{0, 1}, c}];
					s.insert({{0, 1}, c});
				}
			} else {
				dx = p[j].first - p[i].first;
				dy = p[j].second - p[i].second;
				d = std::__gcd(dx, dy);
				dx /= d;
				dy /= d;
				c = dy * p[i].first - dx * p[i].second;
				if(s.find({{dy, dx}, c}) == s.end()) {
					++l[{{dy, dx}, c}];
					s.insert({{dy, dx}, c});
				}
			}
		}
	}
	ll ans = calc(n);
	for(auto it = l.begin(); it != l.end(); ++it)
		ans = (ans - calc(it->second) + mo) % mo;
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

#define pb push_back
#define rs(x) scanf("%s",x)
#define ri(x) scanf("%d",&x)
#define rii(x,y) ri(x),ri(y)
#define ms(obj,val) memset(obj,val,sizeof(obj))
#define ms2(obj,val,sz) memset(obj,val,sizeof(obj[0])*sz)
#define FOR(i,f,t) for(int i=f;i<(int)t;i++)
#define FORR(i,f,t) for(int i=f;i>(int)t;i--)

typedef long long ll;
typedef vector<int> vi;

const int MAXN=110;

bool possible=true;
int R,C,cnt[26];
char A[MAXN][MAXN];

void f(int cc) {
	bool good = false;
	FOR(k,0,26) if(cnt[k] >= cc) {
		cnt[k] -= cc;
		good = true;
		break;
	}
	possible &= good;
}

int main() {
	rii(R,C);
	FOR(r,0,R) rs(A[r]);
	FOR(r,0,R) FOR(c,0,C) cnt[A[r][c]-'a']++;
	FOR(r,0,R/2) FOR(c,0,C/2) f(4);
	if(R % 2 == 1 && C % 2 == 1) {
		FOR(k,0,R/2+C/2) f(2);
		f(1);
	} else if(R % 2 == 1) {
		FOR(k,0,C/2) f(2);
	} else if(C % 2 == 1) {
		FOR(k,0,R/2) f(2);
	}
	printf("%s\n", possible ? "Yes" : "No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
typedef long long ll;
typedef pair<int, int> P;
const int di[4] = {1,0,-1,0};
const int dj[4] = {0,1,0,-1};


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

    map<string, int> mp;
    rep(i,n) {
        string s; cin >> s;
        mp[s]++;
    }
    int m; cin >> m;
    rep(i,m) {
        string t; cin >> t;
        mp[t]--;
    }

    int ans = -10000;
    for (auto x : mp) {
        chmax(ans, x.second);
    }
    if (ans >= 0) cout << ans << endl;
    else cout << 0 << endl;
} 

Measured memory_bytes: 3620
using System;

public class Test
{
	public static void Main()
	{
		// your code goes here
		int x, y;
		string[] line = Console.ReadLine().Split(' ');
		x = int.Parse(line[0]);
		y = int.Parse(line[1]);
		if(x%y==0)
		{
			Console.WriteLine(-1);
		}
		else
		{
			Console.WriteLine(x);
		}
	}
}

Measured memory_bytes: 11092
#include<stdio.h>
int main(void)
{
	float n,w,temp;
	int i;
	scanf("%f",&n);
	while(n>=0){
		w=128;
		temp=n;
		for(i=0;i<=11;i++){
			if(w<=n){
				n-=w;
			}
			w/=2;
		}
		if(n>0){
			printf("NA\n");
		}
		else {
		w=128;
		n=temp;
			for(i=0;i<=11;i++){
			if(w<=n){
				n-=w;
				printf("1");
			}
			else {
				printf("0");
			}
			w/=2;
			if(i==7){
				printf(".");
			}
		}
		printf("\n");
	}
	scanf("%f",&n);
	}
	return 0;
}

Measured memory_bytes: 616
import java.util.Scanner;

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

        if (N >= 10) {
            System.out.println(R);
        } else {
            int temp = 100 * (10 - N);
            System.out.println(R + temp);
        }
    }
}


Measured memory_bytes: 23636
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

typedef long long ll;
using namespace std;

int main() {
    ll s = 0;
    cin >> s;
    if (s <= 1000000000) {
        cout << 0 << " " << 0 << " " << 1 << " " << 0 << " " << 0 << " " << s << endl;
    }
    else {
        ll a = (ll)sqrt(s) + 1;
        if (sqrt(s) == (ll)sqrt(s)) a--;
        if (a*a-s <= 1000000000) cout << 0 << " " << 0 << " " << a << " " << 1 << " " << a*a-s << " " << a << endl;
        else {
            double buf = sqrt(a*a-s);
            for (int i=2; i<=buf; i++) {
                if ((a*a-s)%i == 0) {
                    if ((a*a-s)/i > 1000000000) continue;
                    cout << 0 << " " << 0 << " " << a << " " << i << " " << (a*a-s)/i << " " << a << endl;
                    break;
                }
            }
        }       
    }        
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
int gcd(int a,int b){if(a<b)swap(a,b);int c=a%b;while(c!=0){a=b;b=c;c=a%b;}return b;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

int main(){
  int a, b, c, d; cin >> a >> b >> c >>d;
  bool f = 1;
  while(a > 0 && c > 0){
    if(f){
      c -= b;
      f = 0;
    }else{
      a -= d;
      f = 1;
    }
  }

  if(f) puts("No");
  else puts("Yes");

  return 0;
}


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

//#include <vector>
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;
ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
//using vi = vector<int>; // intの1次元の型に vi という別名をつける
//using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
//using vs = vector<string>; // stringの1次元の型に vs という別名をつける
//using pii = pair<int, int>; // これ以降 pii という型名はpair<int, int> と同じ意味で使える
//---------------------------------------------------------------------------------------------------

vector<string> card(40);
bool isStable(vector<string> in, vector<string> out,int N){
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            for(int a=0;a<N;a++){
                for(int b=a+1;b<N;b++){
                if(in.at(i).at(1)==in.at(j).at(1)&&in.at(i)==out.at(b)&&in.at(j)==out.at(a)){
                    return false;
                    
                }
            }
            }
        }
    }
    return true;
}
void BubbleSort(vector<string> C, int N){
   
   string k;
   for(int i = 0;i<= N-1;i++){
     for(int j = N-1; j>= i+1;j--){
       if(int((C.at(j)).at(1)-int('0'))<int((C.at(j-1)).at(1)-int('0'))){
         k=C.at(j);
         C.at(j)=C.at(j-1);
         C.at(j-1)=k;
         
       }
     }
   }
   rep(i,N-1)cout<<C.at(i)<<" ";
   cout<<C.at(N-1)<<endl;
   cout<<"Stable"<<endl;
 }

void SelectionSort(vector<string> C, int N){
    string k;
   for(int i =0;i<=N-1;i++){
       int minj=i;
       for(int j=i;j<=N-1;j++){
           if(int((C.at(j)).at(1)-int('0')<int((C.at(minj)).at(1)-int('0')))){
               minj=j;
           }
       }
         k=C.at(i);
         C.at(i)=C.at(minj);
         C.at(minj)=k;
   }
   rep(i,N-1)cout<<C.at(i)<<" ";
   cout<<C.at(N-1)<<endl;
   bool ans=isStable(card,C,N);
   if(ans)cout<<"Stable"<<endl;
   else cout<<"Not stable"<<endl;
   
}


 
int main(){
   int n;
   cin>>n;
   
   rep(i,n)cin>>card.at(i);
   
   
   //cout<<int((card.at(0)).at(1)-int('0'));
   BubbleSort(card, n);
   
   SelectionSort(card,n);
   
   
   
   
   
}
  




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

using namespace std;

using int64 = long long;


int main() {
  int Q;
  cin >> Q;
  while(Q--) {
    string S, T;
    cin >> S >> T;

    if(S == T) {
      cout << 0 << endl;
      continue;
    }

    // はやすばあい
    int itti = 0;
    for(int i = 0; i < S.size(); i++) {
      if(S[i] == T[i]) {
        itti = i + 1;
      } else {
        break;
      }
    }


    int last_one = -1;
    for(int i = S.size() - 1; i >= 0; i--) {
      if(S[i] == '1') {
        last_one = i;
        break;
      }
    }

    int cost = 0;
    cost += max(0, last_one - itti);
    int last_uku = -1;
    for(int i = T.size() - 1; i >= last_uku; i--) {
      if(T[i] == '1') {
        last_uku = i;
        break;
      }
    }
    if(last_uku < itti && last_one >= itti) {
      cost += itti - last_uku;
    } else if(last_one < itti) cost += last_uku - last_one;
    else cost += last_uku - itti;
    cout << cost << endl;
  }
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
#define pb push_back

const ll MOD = 1e9 + 7;
const int N = 1e5 + 100;

vi adj[N];

pii dfs(int v, int p) {
    int w=1, b=1;
    for (int u:adj[v]) if (u!=p) {
        int w2, b2;
        tie(w2, b2) = dfs(u, v);
        w = 1ll * w * (w2+b2) % MOD;
        b = 1ll * b * w2 % MOD;
    }
    return pii(w, b);
}

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i=0; i<n-1; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    pii ans = dfs(0, 0);
    cout << (ans.first + ans.second) % MOD << '\n';
}


Measured memory_bytes: 12672
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>

using namespace std;
//#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  int a,b;
  cin>>a>>b;
  if(a+b==15)cout<<'+'<<endl;
  else if(a*b==15)cout<<'*'<<endl;
  else cout<<'x'<<endl;
  return 0;
}


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

ans = 1
flags=[False,False]

for i in range(N-1):
  da = a[i+1] - a[i]
  if da > 0:
    flags[0] = True
  elif da < 0:
    flags[1] = True
    
  if all(flags):
    ans += 1
    flags = [False,False]
print(ans)
    

Measured memory_bytes: 20004
#include<stdio.h>
int three(int);
int main(void){
    int x,k;
    scanf("%d",&x);
    for(int i=1;i<=x;i++){
        k=three(i);
        if(i%3==0 || k==3){
            printf(" %d",i);
        }
    }
    printf("\n");
    return 0;
}
int three(int a){
    while(a>10){
        if(a%10==3){
            break;
        }
        a/=10;
    }
    return a%10;
}


Measured memory_bytes: 2144
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.nextLine();
		
		long[] map = new long[26];
		for (int i = 0; i < N; i++) {
			char S = sc.nextLine().charAt(0);
			switch(S) {
				case 'M':
				case 'A':
				case 'R':
				case 'C':
				case 'H':
					map[(int) S - 65] += 1;
					break;
				default:
					break;
			}
		}
		
		Arrays.sort(map);
		long[] march = Arrays.copyOfRange(map, 21, 26);
		
		long ans = 0;
		for (int i = 0; i < 3; i++) {
			for (int j = i + 1; j < 4; j++) {
				for (int k = j + 1; k < 5; k++) {
					ans += march[i] * march[j] * march[k];
				}
			}
		}
		
		System.out.println(ans);
	}
}

Measured memory_bytes: 94196
#include <bits/stdc++.h>
#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)
typedef long long ll;
long long MOD = 1e9 + 7;
const long long INF = 1LL << 60;
using namespace std;

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

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

int main()
{
  int n, p;
  string s;
  cin >> n >> p >> s;

  ll ans = 0;
  if (p == 2 || p == 5)
  {
    rep(i, n)
    {
      if ((s[i] - '0') % p == 0)
      {
        ans += i + 1;
      }
    }
    cout << ans << endl;
    return 0;
  }

  vector<int> d(n + 1, 0);
  int ten = 1;
  for (int i = n - 1; i >= 0; i--)
  {
    int a;
    a = (s[i] - '0') * ten % p;
    d[i] = (d[i + 1] + a) % p;
    ten *= 10;
    ten %= p;
  }

  vector<int> cnt(p, 0);

  for (int i = n; i >= 0; i--)
  {
    ans += cnt[d[i]];
    cnt[d[i]]++;
  }

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

Measured memory_bytes: 1412
#include<stdio.h>//たて a cm よこ b cm の長方形の面積と周の長さを求めるプログラム

int main(void){

	int height,length,s,around;
	
	scanf("%d%d",&height,&length);

	s=height*length;
	around=(2*height)+(2*length);

	printf("%d %d\n",s,around);
	
	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<cstdio>
#include<string.h>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cmath>
#include<algorithm>
using namespace std;
#define ll long long
// void read(__int128 &x)
// {
//     x = 0;
//     char ch;
//     int flag = 1;
//     while ((ch = getchar()))
//     {
//         if (ch == '-') flag = -1;
//         if (ch >= '0' && ch <= '9') break;
//     }
//     x = ch - '0';
//     while ((ch = getchar()) >= '0' && ch <= '9')
//     {
//         x = x * 10 + ch - '0';
//     }
//     x *= flag;
// }

// void out(__int128 x)
// {
//     if (x < 0)
//     {
//         x = -x;
//         putchar('-');
//     }
//     if (x >= 10) out(x / 10);
//     putchar(x % 10 + '0');
// }


// ll b[300005];
// int n, k;
// ll a[300005];

// int res;
// bool check(int cnt)
// {

//     for(int i = 0; i < cnt; i++)
//     {
//         a[i] = b[i];
//     }

//     int pos = cnt;
//     for(int i = cnt; i < cnt * k; i++)
//     {
//         while(b[pos] < (2 * a[i - cnt] ) && pos < n)
//         {
//             pos++;
//         }
//         if(pos >= n)
//             return 0;
//         a[i] = b[pos];
//         pos++;
//     }
//     return 1;
// }



int a, b, c, n;
const int M = 1e5 + 100;
string s[M];
char ans[M];
bool flag = 1;
void dfs(int i, int a, int b, int c)
{
    if(flag == 0)
        return ;
    if (i == n)
    {
        // cout << "Yes\n";
        printf("Yes\n");
        for (int i = 0; i < n; i++)
            //cout << ans[i] << "\n";
            printf("%c\n", ans[i] );
        flag = 0;
        return;
    }
    if (s[i] == "AB")
    {
        if (a) ans[i] = 'B', dfs(i + 1, a - 1, b + 1, c);
        if (b) ans[i] = 'A', dfs(i + 1, a + 1, b - 1, c);
    }
    if (s[i] == "BC")
    {
        if (b) ans[i] = 'C', dfs(i + 1, a, b - 1, c + 1);
        if (c) ans[i] = 'B', dfs(i + 1, a, b + 1, c - 1);
    }
    if (s[i] == "AC")
    {
        if (a) ans[i] = 'C', dfs(i + 1, a - 1, b, c + 1);
        if (c) ans[i] = 'A', dfs(i + 1, a + 1, b, c - 1);
    }
}

int main()
{


    cin >> n >> a >> b >> c;
    for (int i = 0; i < n; i++)
        cin >> s[i];
    dfs(0, a, b, c);
    if(flag)
        cout << "No";
}


Measured memory_bytes: 16212
#include<stdio.h>

int main(void){

	int i,count[26]={0};
	char word;

	while(scanf("%c",&word)!=EOF){
		if(word>='a'&&word<='z')
			count[word-'a']++;
		else if(word>='A'&&word<='Z')
			count[word-'A']++;
	}
	for(i=0;i<26;i++){
		printf("%c : %d\n",'a'+i,count[i]);
	}
	return 0;
}

Measured memory_bytes: 540
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() { cerr << "--------------" << endl; }
const int INF = 2e9;
const int MOD = 1e9 + 7;

struct Edge {
   int to, id;
};
vector<vector<Edge>> g;
vector<int> ans;

void dfs(int v, int c = -1, int p = -1) {
   int k = 1;
   rep(i, 0, g[v].size()) {
      int u = g[v][i].to, ei = g[v][i].id;
      if (u == p) continue;
      if (k == c) k++;
      ans[ei] = k;
      k++;
      dfs(u, ans[ei], v);
   }
}
int main() {
   int n;
   cin >> n;
   g.resize(n);
   ans = vector<int>(n - 1);
   rep(i, 0, n - 1) {
      int a, b;
      cin >> a >> b;
      a--, b--;
      g[a].push_back((Edge){b, i});
      g[b].push_back((Edge){a, i});
   }
   dfs(0);
   int mx = 0;
   rep(i, 0, n) chmax(mx, int(g[i].size()));
   cout << mx << endl;
   rep(i, 0, n - 1) { cout << ans[i] << endl; }
   return 0;
}

Measured memory_bytes: 8320
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)

	N, K := getInt(), getInt()

	d0 := (N + K - 1) / K
	ans := N - d0*K
	if ans < 0 {
		ans = -ans
	}
	d1 := N / K
	t := N - d1*K
	if t < 0 {
		t = -t
	}
	ans = min(ans, t)
	// ans = min(ans, N)
	// if ans > N {
	// 	ans = N
	// }
	out(ans)
}


Measured memory_bytes: 640
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)


int main(){
    ll H, W, K;
    cin >> H >> W >> K;

    char m[H][W];
    rep(i, H){
        rep(j, W){
            cin >> m[i][j];
        }
    }

    ll black;
    ll ans = 0;
    for(int bitH = 0; bitH < (1<<H); bitH++){
        for(int bitW = 0; bitW < (1<<W); bitW++){
            black = 0;
            for(int i = 0; i < H; i++){
                for(int j = 0; j < W; j++){
                    if((bitH & (1<<i)) && (bitW & (1<<j)) && m[i][j] == '#'){
                        black++;
                    }
                }
            }
            if(black == K){
                ans++;
            }
        }
    }

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


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

void operation(vector<int>& regs){
    regs[2]--;
    int temp;
    if(regs[0]%2 == 1)
        --regs[0];
    // swap included
    temp =regs[0]/2;
    regs[0]= regs[1] + temp;
    regs[1]= temp;

}

int main(){
    int A, B, K;
    cin >> A >> B >> K;
    vector<int> regs = {A, B, K};
    
    while(regs[2] >0){
        operation(regs);
    }
    if(K%2==0)
    cout << regs[0] << ' ' <<  regs[1] << endl;
    else
    cout << regs[1] << ' ' << regs[0] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool f;
bool e[26][26];
void dfs(int x,int d){
  //cout << x << ":" << d << endl;
  if(d>26) {
    f=false;
    return;
  }
  if(!f) return;
  for(int i=0;i<26;i++){
    if(e[x][i]) dfs(i,d+1);
  }
}
int main(){
  int n;
  while(cin>>n,n){
    int i,j,k;
    vector<string> v;
    string s;
    memset(e,false,sizeof(e));
    for(i=0;i<n;i++){
      cin >> s;
      v.push_back(s);
    }
    f=true;
    for(i=0;i<n;i++){
      for(j=i+1;j<n;j++){
	if(v[i].find(v[j])==0&&v[i].size()>v[j].size()) f=false;
	int x=min(v[i].size(),v[j].size());
	for(k=0;k<x;k++){
	  if(v[i][k]==v[j][k]) continue;
	  e[v[i][k]-'a'][v[j][k]-'a']=true;
	  break;
	}
      }
    }
    for(i=0;i<26;i++){
      if(f)dfs(i,0);
    }
    if(f) cout << "yes" << endl;
    else cout << "no" << endl;
  }
  return 0;
}

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

int main() {
  int N, K, X, Y;
  cin >> N >> K >> X >> Y;
  if (K > N) {
    cout << N * X << endl;
  }
  if (K <= N) {
    cout << K * X + (N-K) * Y << endl;
  }
}

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

#define V vector
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef V<int> vi;
typedef V<ll> vll;
typedef V<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define prec(x) cout<<fixed<<setprecision(x)
#define f(i,a) for(int i = 0 ; i < a ; i++)
#define ff first
#define ss second
#define all(x) (x).begin() ,(x).end()

#define pb push_back
#define mp make_pair
#define numberofdigits(x) floor(log10(x)) + 1

ll binpow(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}

void solve()
{
	ll x , k , d;
	cin >> x >> k >> d;

	x = abs(x);

	ll div = x / d;
	if (div <= k) {
		x -= div * d;
		k -= div;
	}
	else if (x - k * d > 0)
		x -= k * d , k = 0;

	x = abs(x);

	if (k & 1)
		x -= d;


	cout << abs(x) << "\n";

}

int main() {


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


	int t = 1;
	//cin >> t;

	while (t--)
	{
		solve();
	}

	return 0;
}





Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

template <typename T, typename K> struct P {
	T a; K b;
};
typedef struct {
	vector <int> to;
	bool is_visited = false;
} node;
typedef struct {
	int to;
	int cost;
	P <int, int> change;
} edge;
int main( void ){
	int N, T; cin >> N >> T;
	vector <int> vec( T );
	rep( i, 0, T ){
		cin >> vec[ i ];
	}
	int sum = 0;
	rep( i, 0, T ){
		vec[ i ] = max( 0, vec[ i ] * 2 - N );
		sum += vec[i];
	}
	cout << max(0, sum-1) << "\n";
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int n,m;
char p[405][405];
int bel[405][405];
bool vis[405][405];
int b,w;
long long ans;
void dfs(int x,int y,int cur)
{
	if (x<=0||x>n||y<=0||y>m||vis[x][y]||bel[x][y]!=cur)
		return;
	vis[x][y]=1;
	if (p[x][y]=='#')
		b++;
	else
		w++;
	dfs(x-1,y,cur);
	dfs(x,y-1,cur);
	dfs(x+1,y,cur);
	dfs(x,y+1,cur);
}
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++)
		scanf("%s",p[i]+1);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			bel[i][j]=(p[i][j]=='.')^((i^j)&1);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
			if (!vis[i][j])
			{
				b=w=0;
				dfs(i,j,bel[i][j]);
				ans+=1ll*b*w;
			}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 13568
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
//#include <vector>

using namespace std;

#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x<y?x:y)
#define ABS(x) (x>0?x:-(x))
#define INF 1000000000

#define MOD 1000000007

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

void swap2(double* a, double* b)
{
	double tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

int gcd(int a, int b)  //最大公約数
{
	if (a < b)
		swap(&a, &b);

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

int lcm(int a, int b)
{
	return a * b / gcd(a, b);
}

long power(long x, int n) { //x^n 計算量O(logn)
	long ans = 1;
	while (n > 0) {
		if ((n & 1) == 1) {
			ans = ans * x;
		}
		x = x * x; //一周する度にx, x^2, x^4, x^8となる
		n >>= 1; //桁をずらす n = n >> 1
	}
	return ans;
}

int choose(int n, int k) {
	return k == 0 ? 1 : (long long)choose(n - 1, k - 1) * n % MOD * power(k, MOD - 2) % MOD;
}

void bubble_sort(int a[], int n)
{
	int i, j, tmp;

	for (i = 0; i < n; i++)
	{
		for (int k = 0; k < n; k++)
			printf("%d ", a[k]);

		for (j = n - 1; j > i; j--)
		{
			if (a[j - 1] > a[j])
			{
				tmp = a[j];
				a[j] = a[j - 1];
				a[j - 1] = tmp;
			}
		}
		printf("\n");
	}
}

void selection_sort(int a[], int n)
{
	int i, j, tmp, min, key;

	for (i = 0; i < n - 1; i++)
	{
		min = i;
		key = a[i];

		for (int k = 0; k < n; k++)
			printf("%d ", a[k]);

		for (j = i + 1; j < n; j++)
		{
			if (a[j] < a[min])
			{
				min = j;
				key = a[j];
			}
		}

		tmp = a[i];
		a[i] = a[min];
		a[min] = tmp;

		printf("\n");
	}

	for (int k = 0; k < n; k++)
		printf("%d ", a[k]);
}

void insertion_sort(int a[], int n)
{
	int i, j, tmp;

	for (i = 1; i < n; i++)
	{
		j = i;

		while (j >= 1 && a[j - 1] > a[j])
		{
			tmp = a[j];
			a[j] = a[j - 1];
			a[j - 1] = tmp;
			j--;
		}
	}
}

void shell_sort(int a[], int n)
{
	int h, i, j;

	for (h = 1; h < n / 9; h = h * 3 + 1)
		;

	for (; h > 0; h /= 3)
	{
		for (int k = 0; k < n; k++)
			printf("%d ", a[k]);

		for (i = h; i < n; i++)
		{
			j = i;
			while (j >= h && a[j - h] > a[j])
			{
				swap(&a[j - h], &a[j]);
				j -= h;
			}
		}
		printf("\n");
	}

	for (int k = 0; k < n; k++)
		printf("%d ", a[k]);
}

int partition(int a[], int l, int r)
{
	int i, j, pivot;

	i = l - 1;
	j = r;
	pivot = a[r];

	for (;;)
	{
		while (a[++i] < pivot)
			;
		while (i < j-- && pivot < a[j])
			;

		if (i >= j)
			break;

		swap(&a[i], &a[j]);
	}

	swap(&a[i], &a[r]);
	return i;
}

void quick_sort1(int a[], int l, int r)
{
	int v;

	if (l >= r)
		return;

	v = partition(a, l, r);

	quick_sort1(a, l, v - 1);
	quick_sort1(a, v + 1, r);
}

void quick_sort(int a[], int n)
{
	quick_sort1(a, 0, n - 1);
}

int keta(int a,int n)
{
	if (n == 1)
		return a % 10;

	for (int i = 0; i < n-1; i++)
		a /= 10;

	return a % 10;
}

int main() 
{
	int M, L, K;
	long long int A, B,N;
	int a[100000];
	char S[5];

	scanf("%lld%lld%lld", &N,&A, &B);

	printf("%lld", (N / (A + B)) * A + MIN(A,(N % (A + B))) );
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define mp(a, b) make_pair(a, b)
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = (1e9 + 7);
using namespace std;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
ll dp[100010];
ll gcd(ll x, ll y){
  return y == 0 ? x : gcd(y, x % y);
}
ll lcg(ll x, ll y){
  return x * y / gcd(x, y);
}
ll digits(ll x){
  ll length = 0;
  while (x > 0){
    x /= 10;
    length++;
  }
  return length;
  if (x == 0) return 0;
}
map<ll, ll> factor(ll n){
  map<ll, ll> ans;
  ll a = 2;
  while (n >= a * a){
    if (n % a == 0){
      ans[a]++;
      n /= a;
    }
    else a++;
  }
  ans[n]++;
  return ans;
}
template<class T> inline bool chmin(T& a, T b){
  if (a > b){
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b){
  if (a < b){
    a = b;
    return true;
  }
  return false;
}

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

  int a, b; cin >> a >> b;

  ll ans;
  //string ans;

  ans = lcg(a, b);

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

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

#ifndef ONLINE_JUDGE 
const bool DEBUG = true;
#else
const bool DEBUG = false;
#endif

// Reads a 1D vector
template <class T>
void read1d(vector<T>& arg) {
	const int l = arg.size();
	for (int i = 0; i < l; ++i) cin >> arg[i];
}

void read() {}
// Reads arbitrary values
template <class T1, class... T2>
void read(T1& var1, T2&... var2) { cin >> var1; read(var2...); }



void pln() { cout << (DEBUG ? "]\n" : "\n"); }
template <class T1, class... T2>
void pln(const T1& var1, const T2& ... var2) { cout << var1 << " "; pln(var2...); }

// Prints arbitrary values and goes to next line
template <class T1, class... T2>
constexpr void print(const T1& var1, const T2& ... var2) { cout << (DEBUG ? " [ " : ""); pln(var1, var2...); }





using ll = long long;
using ull = unsigned long long;


#define all(x) begin(x), end(x)

const bool MULTIPLE_TEST_CASES = 0;



void exec()
{
	int n;
	read(n);

	vector<ull> arr(n);
	for (int i = 0; i < n; ++i) cin >> arr[i];

	double limit = log(1e18);

	double sum = 0;
	ull x = 1;
	bool z = false;
	for (ull i : arr) {
		if (i == 0) { print(0); return; }
		sum += log(i);
		x *= i;
	}

	if (sum > limit || x > (ull)1e18) print(-1);
	else print(x);
}

















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

	if (!MULTIPLE_TEST_CASES)
		exec();
	else {
		int n;
		cin >> n;

		while (n--)
			exec();
	}

	return 0;
}

Measured memory_bytes: 4004
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;

int gcd(int a, int b) { //最大公約数
  if (b==0) return a;
  else return gcd(b, a%b);
}

int lcm(int a, int b) { //最小公倍数
  return a * b / gcd(a, b);
}


int main()
{
  ll n,a[100010],cnt[100010]={0};
  cin>>n;
  rep(i,n)cin>>a[i];

  rep(i,n){
    cnt[a[i]+1]++;
    cnt[a[i]]++;
    if(a[i]!=0)cnt[a[i]-1]++;
  }
  ll ans=0;
  rep(i,100010){
    ans=max(ans,cnt[i]);
  }

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


Measured memory_bytes: 5188
use proconio::input;
use proconio::marker::{Chars, Usize1};
use std::iter::Iterator;
use std::collections::*;
use std::cmp::*;
use itertools::Itertools;

#[allow(unused_macros)]
macro_rules! max {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      max($x,max!($($xs)+))
    };
  }
  
  #[allow(unused_macros)]
  macro_rules! min {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      min($x,min!($($xs)+))
    };
  }

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
    n: u64,
    }

    let mut sum = 0_u64;
    for i in 1..=n{
      let y = n / i ;
      sum += y * (y+1) * i / 2
    }

     println!("{}", sum);
}


Measured memory_bytes: 2180
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(void)
{
    int a,b,c;
    int max,cnt=0;
    int sa;

    scanf("%d %d %d",&a,&b,&c);
    while(a!=b||b!=c){
        if(a>b) max=a;
        else max=b;
        if(max<c)max=c;

        sa=max-a;
        sa+=max-b;
        sa+=max-c;
        if(sa==1){
            cnt+=2;
            break;
        }
        if(abs(max-a)>=2){
            cnt++;
            a+=2;
        }
        else if(abs(max-a)==1){
            if(max-b>0){
                a++;
                b++;
                cnt++;
            }
            else {
                a++;
                c++;
                cnt++;
            }
        }
        if(abs(max-b)>=2){
            cnt++;
            b+=2;
        }
        else if(abs(max-b)==1){
            if(max-a>0){
                a++;
                b++;
                cnt++;
            }
            else{
                b++;
                c++;
                cnt++;
            }
        }
        if(abs(max-c)>=2){
            cnt++;
            c+=2;
        }
        else if(abs(max-c)==1){
            if(max-a>0){
                a++;
                c++;
                cnt++;
            }
            else{
                b++;
                c++;
                cnt++;
            }
        }
    }
    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int main(){

	double diff,tmp;
	int bunshi;

	while(true){
		scanf("%lf",&diff);
		if(fabs(diff-0.0) < EPS)break;

		for(int bunbo = 1; ; bunbo++){

			bunshi = round(bunbo*M_PI);

			tmp = (double)bunshi/(double)bunbo;

			if(fabs(tmp-M_PI) < diff){
				printf("%d/%d\n",bunshi,bunbo);
				break;
			}
		}
	}
	return 0;

}

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

typedef long long int ll;
typedef vector<long long>lve;
typedef vector<pair<ll,ll> > lvp;

#define sp         ' '
#define endl       '\n'
#define F          first
#define S          second
#define pp         pop_back`
#define pb         push_back
#define mp         make_pair 
#define GCD(x,y)   __gcd(x,y)
#define lb         lower_bound
#define up         upper_bound
#define setp       setprecision
#define bs         binary_search
#define all(x)     x.begin(),x.end()
#define LCM(x,y)   ((x*y)/__gcd(x,y))
#define spc(x)     cout<<fixed<<setp(x)

const   long long  inf = 1e18;
const   long long  cs =  200005;
const   long long  mod = 1000000007;
const   double     PI =  2 * acos(0.0);
void solve()
{
    ll t,n,m,a,b,c,d,e,i,j,k,x,y,z,cnt=0,cnt1=0;
    bool flag = false;   
    
    cin>>n;
    if(n==1)
    {
        cout<<0<<endl;
        return ;
    }
    if(n==2)
    {
        cout<<1<<endl;
        return ;
    }
    x=(n*(n-1))/2;
    cout<<x<<endl;
    
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);    cout.tie(NULL);

    // freopen ("input.txt","r",stdin);
    // freopen ("output.txt","w",stdout);

    // int32_t tc;
    // cin>>tc;
    // while(tc--)
    solve();

    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
string s,st;
void digui(int w){
    if(s[w]=='e'){
        st="";
        for(int i=w;i<=w+4;i++)
            st+=s[i];
        if(st=="erase") {
            if(w+4==s.size()-1){
                cout<<"YES";
                exit(0);
            }
            if(s[w+5]=='r'){
                if(w+5==s.size()-1){
                    cout<<"YES";
                    exit(0);
                }
                digui(w+5+1);
            }
            else
                digui(w+4+1);
        }
        else
        return ;
    }
    if(s[w]=='d'){
        st="";
        for(int i=w;i<=w+4;i++)
            st+=s[i];
        if(st=="dream"){
            if(w+4==s.size()-1){
                cout<<"YES";
                exit(0);
            }
            if(s[w+5]=='e'&&s[w+6]=='r'){
                if(w+6==s.size()-1){
                    cout<<"YES";
                    exit(0);
                }
                digui(w+6+1);
                digui(w+4+1);
            }
            else
                digui(w+4+1);
        }
        else
        return;
    }
}
int main(){
    cin>>s;
    if(s[0]!='d'&&s[0]!='e'){
        cout<<"NO";
        return 0;
    }
    digui(0);
    cout<<"NO";
    return 0;
}

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

#define int long long
#define inf 1000000007LL

#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define trep(i, n) for(int i = 0; i <= (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define mfor(i, s, t) for(int i = (s); i < (t); i++)
#define tfor(i, s, t) for(int i = (s); i <= (t); i++)

class Dinic {
public:
  vector<vector<pair<int, int>>> v;
  vector<int> e;

  vector<int> k;
  vector<int> j;

  void init(int n) {
    v = vector<vector<pair<int, int>>>(n);
    e = vector<int>();
    k = vector<int>(n);
    j = vector<int>(n);
  }
  void add_edge(int a, int b, int atob, int btoa = 0) {
    v[a].push_back(make_pair(b, e.size()));
    e.push_back(atob);
    v[b].push_back(make_pair(a, e.size()));
    e.push_back(btoa);
  }
  void dyk(int s) {
    for(auto& i : k) {
      i = inf;
    }
    queue<pair<int, int>> pq;
    pq.push(make_pair(0, s));
    while(!pq.empty()) {
      int w = pq.front().first;
      int b = pq.front().second;
      pq.pop();
      if(k[b] > w) {
        k[b] = w;
        for(auto i : v[b]) {
          if(e[i.second] > 0) {
            pq.push(make_pair(w + 1, i.first));
          }
        }
      }
    }
  }
  int dfs(int s, int t, int p, int c) {
    if(p == t) {
      return c;
    }
    int all = 0;
    while(c > all && j[p] < v[p].size()) {
      if(k[v[p][j[p]].first] == k[p] + 1) {
        int r = dfs(s, t, v[p][j[p]].first, min(c - all, e[v[p][j[p]].second]));
        e[v[p][j[p]].second] -= r;
        e[v[p][j[p]].second ^ 1] += r;
        if(r < c - all) {
          j[p]++;
        }
        all += r;
      }
      else {
        j[p]++;
      }
    }
    return all;
  }
  int solve(int s, int t) {
    int all = 0;
    while(1) {
      dyk(s);
      for(auto& i : j) {
        i = 0;
      }
      int r = dfs(s, t, s, inf);
      if(r == 0) {
        return all;
      }
      all += r;
    }
  }
};

signed main() {
  int n, a, b;
  cin >> n >> a >> b;
  if(n == 1) {
    if(a == b) {
      cout << 1 << endl;
    }
    else {
      cout << 0 << endl;
    }
  }
  else if(a > b) {
    cout << 0 << endl;
  }
  else {
    int mi = a * (n - 1) + b;
    int ma = b * (n - 1) + a;
    cout << ma - mi + 1 << endl;
  }
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] accept = new int[n+1];
        int[] fail = new int[n+1];
        int ACsum = 0;
        int WAsum = 0;
        for(int i =0;i<m;i++){
            Integer p = sc.nextInt();
            String acwa = sc.next();
            if(accept[p]==1)continue;
            if(acwa.equals("AC")){
                accept[p] = 1;
                ACsum++;
                WAsum+=fail[p];
            }
            else{
                fail[p]++;
            }
        }
        System.out.println(ACsum + " " + WAsum);
        
    }
}


Measured memory_bytes: 63472
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use itertools::Itertools;
use std::process::exit;
use std::cmp::*;
use num::*;
use num::integer::Roots;

fn main() {
    input! {
    a:usize,
    b:String,
    c:usize,
    }
    let mut b=b.chars().collect_vec();
    let e=b[c-1];
    for i in 0..b.len(){
        if b[i]!=e{
            b[i]='*'
        }
    }
    let b:String=b.iter().collect();
    println!("{}",b)
}

Measured memory_bytes: 2156
def main(input = $stdin)
  n = input.gets.to_i
  series = []
  n.times do
    series << input.gets.to_i
  end
  lis = [-1]
  series.each{|a|
    if lis.last < a
      lis << a
    else
      i = -2
      while i >= -lis.size and lis[i] >= a
        i -= 1
      end
      if lis[i] < a and lis[i + 1] > a
        lis[i + 1] = a
      end
    end
  }
  puts lis.size - 1
end
main

Measured memory_bytes: 7788
/* Justin Choi */
#include <bits/stdc++.h>
using namespace std;

string FILENAME = "filename";
#define io ifstream fin(FILENAME + ".in"); ofstream fout(FILENAME + ".out")
#define fwrite(X) fout << X;
#define fwriteln(X) fout << X << endl;

#define forl(V, N) for(int V = 0; V < N; V++)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
#define rem(X) X.top(); X.pop()
#define setmin(A, B) A = min(A, B)
#define setmax(A, B) A = max(A, B)
#define graph unordered_map<int, unordered_set<int>>
#define vi vector<int>
#define pb push_back
#define ll long long

int dp[1000000];

int main() {
    int N, K;
    cin >> N >> K;
    vi A(N);
    forl(i, N) cin >> A[i];
    fill_n(dp, 1000000, -1);
    sort(A.begin(), A.end());
    forl(i, A[0]) dp[i] = 0;
    forl(i, 2*K) {
        if(dp[i] == -1) {
            dp[i] = 0;
        }
        int other = dp[i] == 0 ? 1 : 0;
        forl(j, N) {
            if(other == 1) dp[i+A[j]] = 1;
            else if(dp[i+A[j]] == -1) dp[i+A[j]] = other;
        }
    }
    if(dp[K] == 0) println("Second");
    else println("First");
}

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

using namespace std;

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '{';
    string sep;
    for (const auto &x : v)
        os << sep << x, sep = ", ";
    return os << '}';
}
template <typename T, size_t size>
ostream &operator<<(ostream &os, const array<T, size> &arr)
{
    os << '{';
    string sep;
    for (const auto &x : arr)
        os << sep << x, sep = ", ";
    return os << '}';
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T)
{
    cerr << ' ' << H;
    dbg_out(T...);
}

// #define DEBUG
#ifdef DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

int main()
{
    ios::sync_with_stdio(false);
#ifndef DEBUG
    cin.tie(nullptr);
#endif
    int64_t N;
    int X, M;
    cin >> N >> X >> M;

    vector<int> v;
    unordered_map<int, int> index;
    v.push_back(X);
    index[X] = 0;
    int cycleStart = -1, cycleLen = -1;
    int64_t cycleSum = 0;
    for (int i = 1;; i++)
    {
        int next = (1LL * v[i - 1] * v[i - 1]) % M;
        auto it = index.find(next);
        if (it == index.end())
        {
            v.push_back(next);
            index[next] = i;
        }
        else
        {
            cycleStart = index[next];
            cycleLen = i - cycleStart;
            for (int j = cycleStart; j < i; j++)
                cycleSum += v[j];
            break;
        }
    }
    dbg(v);
    int64_t sum = 0;
    for (int i = 0; i < min((int64_t)cycleStart, N); i++)
    {
        sum += v[i];
    }
    if (N >= cycleStart)
    {
        int64_t left = N - cycleStart;
        sum += (left / cycleLen) * cycleSum;
        for (int i = 0; i < left % cycleLen; i++)
        {
            sum += v[cycleStart + i];
        }
    }
    cout << sum << endl;

    return 0;
}


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

#define lli long long int
#define pb push_back
#define in insert
#define pi pair<lli, lli>
#define ps pair<double, string>
#define pib pair<pi, bool>
#define mp make_pair
#define fir first
#define sec second
#define MAXN 1001
#define MAXL 10001
#define mod 1000000007

signed main()
{
  string a, b;
  cin >> a >> b;
  bool can = true;
  for (int i = 0; i < min(a.size(), b.size()); i++)
    if (a[i] != b[i])
      can = false;
  (can) ? cout << "Yes\n" : cout << "No\n";
  return 0;
}


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

// +を入れるか-かを分岐させて再帰する関数
bool ReFunc(vector<int> vec, int place, long long left, long long right, string &answer)
{
    // 最後まで終わったら算出する。
    if (place == vec.size() - 1)
    {
        if ((left + right) == 7)
        {
            answer += "+";
            return true;
        }
        else if ((left - right) == 7)
        {
            answer += "-";
            return true;
        }
    }
    else
    {
        //(+)の場合、今考えている左辺と右辺を足して左辺を作り、次を右辺とする(例：1234)の場合、(vec, 1, 1, 2)→(vec, 2, 3, 3)
        if (ReFunc(vec, place + 1, left + right, vec.at(place + 1), answer))
        {
            answer += "+";
            return true;
        }
        //(-)の場合、今考えている左辺と右辺を減算して、、次を右辺とする(例：1234)の場合、(vec, 1, 0, 12)→(vec, 2, -1, 3)
        if (ReFunc(vec, place + 1, left - right, vec.at(place + 1), answer))
        {
            answer += "-";
            return true;
        }
    }
    return false;
}



int main()
{
    string S, answer(7, 0);
    cin >> S;
    vector<int> vec(S.size());
    for (int i = 0; i < S.size(); i++)
    {
        vec.at(i) = S.at(i) - '0';
    }

    string plusMinus;
    ReFunc(vec, 1, vec.at(0), vec.at(1), plusMinus);
    
    int temp = 0;
    answer.at(0) = S.at(0);
    for(int i = 1; i < S.size(); i++)
    {
        answer.at(++temp) = plusMinus.at(3 - i);
        answer.at(++temp) = S.at(i);
    }
    cout << answer + "=7" << endl;
}



Measured memory_bytes: 256