akhauriyash/Code-Regression huggingface dataset:
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

bool dp[55][55][110];


void mainmain(){
	int n,m;
	vint a(3);
	cin>>n>>m;
	rep(i,3) cin>>a[i];
	rep(i,m){
		int a,b;
		cin>>a>>b;
		a--;
		b--;
		dp[a][b][1]=true;
	}
	reep(o,2,110){
		rep(k,n){
			rep(i,n){
				rep(j,n){
					if(dp[i][k][1]&&dp[k][j][o-1]) dp[i][j][o]=true;
					if(dp[i][k][o-1]&&dp[k][j][1]) dp[i][j][o]=true;
				}
			}
		}
	}
	vector<bool> v(n);
	v[n-1]=true;
	VV(bool) vv;
	initvv(vv,n,3);
	rep(i,3){
		rep(j,n){
			if(dp[j][n-1][a[i]]) vv[j][i]=true;
		}
	}
	bool update=true;
	int cnt=1;
	while(update){
		update=false;
		queue<int> q;
		rep(i,n){
			if(v[i]) continue;
			bool ok=true;
			rep(j,3){
				if(!vv[i][j]) ok=false;
			}
			if(ok){
				update=true;
				q.push(i);
			}
		}
		while(q.size()){
			int i=q.front();
			q.pop();
			v[i]=true;
			rep(j,3){
				rep(k,n){
					if(dp[k][i][a[j]]) vv[k][j]=true;
				}
			}
		}
		if(v[0]){
			cout<<cnt<<endl;
			return;
		}
		cnt++;
	}
	cout<<"IMPOSSIBLE"<<endl;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 3484
#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
using namespace std;
////////////// Prewritten code follows. Look down for solution. ////////////////
#define x first
#define y second
#define LEN(x) ((int)(x).size())
#define ALL(x) x.begin(), x.end()
using ll = long long;
using llu = long long unsigned;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;
using vpii = vector<pii>;

const ld EPS = 1e-9;
inline int cmp(ld x, ld y = 0, ld tol = EPS) {
	return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}

const int MOD = 1;
inline int mod(ll x, int m = MOD) {
	return (int)(((x%m) + m)%m);
}

template<typename T, typename M = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, M, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

////////////////////////// Solution starts below. //////////////////////////////

const int N = 2e5 + 10;

int n;
int a[N];
map<int, int> mp;

int main () {
	// ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.precision(10);
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		mp[i-a[i]]++;
	}

	ll ans = 0;
	for(int i = 1; i <= n; i++) {
		ans += mp[a[i]+i];
		mp[i-a[i]]--;
	}
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 21356
#include <iostream>
using namespace std;
#define MAX 2000000

int H, A[MAX+1];

void maxHeapify(int i){
  int l,r,largest,tmp;
  l = 2*i;
  r = 2*i+1;
  
  if(l <= H && A[l] > A[i]){
    largest = l;
  }
  else{
    largest = i;
  }
  if(r <= H && A[r] > A[largest]){
    largest = r;
  }
  
  if(largest != i){
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
    maxHeapify(largest);
  }
}

int main(){
  int i;
  
  cin >> H;
  for(i=1;i<=H;i++){
    cin >> A[i];
  }
  
  for(i=H/2;i>=1;i--){
    maxHeapify(i);
  }
  
  for(i=1;i<=H;i++){
    cout << " " << A[i];
  }
  cout << endl;
  
  return 0;
}



Measured memory_bytes: 5024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        int N=cin.nextInt();
        int[] P=cin.ArrayInt(N,0);
        int[] Q=new int[N];
        for(int i=0;i<N;i++)Q[i]=P[i];
        Array.Sort(Q);
        int x=0;
        for(int i=0;i<N;i++)if(Q[i]!=P[i])x++;
        if(x<=2)Console.WriteLine("YES");
        else Console.WriteLine("NO");
        
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Answer
{
    public static void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }//Answer.IntArrayAns(x);
    public static void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }

}

Measured memory_bytes: 11220
S = input()
N = len(S)
ans = [0] * N
i = 0
while i < N:
  if i == N-1:# 一番右はL固定
    ans[N-1] +=1
    break
  count = 1
  while S[i+count] == S[i]:
    count += 1
    if count == N-i:
      break
  if S[i] == 'R':
    ans[i+count-1] += (count+1)//2
    ans[i+count] += count//2
  else:
    ans[i] += (count+1)//2
    ans[i-1] += count//2
  i += count
print(*ans)

Measured memory_bytes: 10796
#include<iostream>
#include<stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
     
int main(){
  //整数の時はint
  //int a,b,c;
  //文字の時はstring
  string a;
     
     
  cin>>a;
  if(a=="AAA" || a=="BBB")
    cout<<"No"<<endl;
  else
    cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 256
// Author : Chi
// created : Sunday 2020-05-31
// Sawal : https://www.codechef.com/LTIME84B/problems/TREDIFF

//header files
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

//namespaces
using    namespace __gnu_pbds;
using    namespace std;
typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > ordered_set;

//macros
#define ll 		    long long
#define ss          second
#define ff          first
#define vi          vector<int>
#define vll         vector<long long>
#define pb(x)       push_back(x)
#define TEST  	    int TesT;cin>>TesT;while(TesT--)solve();
#define TEST1       solve();
#define mod         998244353
#define r0n(i,n)    for(ll i = 0; i < n; ++i)
#define r1n(i,n)    for(ll i = 1; i <= n; ++i)
#define pdp(d,i)    fixed<<setprecision(i)<<d
#define CHI         ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define db(...)     __f(#__VA_ARGS__, __VA_ARGS__)                      //for debugging
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#define dig(n) floor(log10(n) + 1)
//LOVE ALGO
void solve(){
    long double a;
    long double b;
    cin>>a>>b;
    cout<<(ll)(a*round(b*100))/100<<"\n";
}

// Driver Code
int main(){
    CHI
    TEST1
    return 0;
}



Measured memory_bytes: 3768
m = 10**9 + 7
n = int(input())
l = list(map(int, input().split()))

f = 1
d = 0
A = 0
 
for i in range(1, n):
  d = (d*i + f) % m
  A = (A*i + (l[i]-l[i-1])*d) % m
  f = f*i % m
 
print(A)

Measured memory_bytes: 62576
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int[] p = new int[n];
    int ans = 0;

    for (int i = 0; i < n; i++) {
      p[i] = sc.nextInt();
    }

    for (int i = 0; i < (n - 2); i++) {
      if (p[i + 1] == med(p[i], p[i + 1], p[i + 2])) {
        ans++;
      }
    }

    System.out.println(ans);

  }

  // 3数の中央値を求めるメソッド
  static int med(int a, int b, int c) {
    if (a >= b) {
      if (b >= c) {
        return b;
      } else if (a <= c) {
        return a;
      } else {
        return c;
      }
    } else if (a > c) {
      return a;
    } else if (b > c) {
      return c;
    } else {
      return b;
    }
  }

}

Measured memory_bytes: 35704
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int x,y=0;
    int a=0;
    while(1){
        scanf("%d %d",&x,&y);
        if(x==0 && y==0){
            break;
        }
        if(x > y){
            a = x;
            x = y;
            y = a;
        }
        printf("%d %d\n",x,y);
    }
    return 0;
}

Measured memory_bytes: 600
#include <algorithm>
#include <iostream>
#include <iterator>
#include <set>
#include <string>

using namespace std;

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

    int ans = 0;
    for (int i = 0; i < N; ++i) {
        string l = S.substr(0, i);
        string r = S.substr(i);

        set<char> ls;
        for (char c : l) {
            ls.insert(c);
        }
        set<char> rs;
        for (char c : r) {
            rs.insert(c);
        }
        set<char> tmp;
        set_intersection(
            ls.begin(), ls.end(), rs.begin(), rs.end(),
            inserter(tmp, tmp.end()));
        ans = max(ans, (int)tmp.size());
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(c) (c).begin(), (c).end()
#define pb push_back
#define eb emplace_back
using namespace std;
const long long INF = 1LL<<60; // 仮想的な無限大の値;
using ll = long long;
using P  = pair<int, int>;
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main()
{
    string s;
    cin >> s;
    cout << s[0]<<s.size()-2 << s.back();
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  multiset<string> s;
  rep(i,n){
    string a;
    cin >> a;
    s.insert(a);
  }
  printf("%s %c %d\n","AC",'x',s.count("AC"));
  printf("%s %c %d\n","WA",'x',s.count("WA"));
  printf("%s %c %d\n","TLE",'x',s.count("TLE"));
  printf("%s %c %d","RE",'x',s.count("RE"));
}

Measured memory_bytes: 11540
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes                \
    cout << "Yes" << endl; \
    return 0;
#define No                \
    cout << "No" << endl; \
    return 0;
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template <typename T>
void print(const T &v);

int main()
{
    int N;
    cin >> N;
    vector<int> A(N + 1, 0);
    vector<int> vec(N + 1, 0);
    vector<int> ky;
    for (int i = 1; i <= N; i++)
    {
        cin >> A[i];
    }
    for (int i = i; i <= N; i++)
    {
        if (i + A[i] <= N)
        {
            vec[i + A[i]]++;
        }
        if (i > A[i])
        {
            ky.push_back(i - A[i]);
        }
    }
    ll ans = 0;
    for (int k : ky)
    {
        ans += vec[k];
    }
    cout << ans << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 5816
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define BUF_SIZE 10200

int comp(const void* a, const void* b) {
  return *(int*)a - *(int*)b;
}

int main(void) {
  char line[BUF_SIZE];
  FILE *fp = stdin;

  if(!fgets(line, BUF_SIZE, fp)) return 0;
  int num, quant;
  sscanf(line, "%d %d", &num, &quant);

  if(!fgets(line, BUF_SIZE, fp)) return 0;
  int *arr = malloc(sizeof(int)*num);
  int i;
  char* tmpbuf = line;
  for(i = 0; i < num; i++) {
    char *tmp = strtok(tmpbuf, " ");
    arr[i] = strtol(tmp, NULL, 10);
    tmpbuf = NULL;
  }
  qsort(arr, num, sizeof(int), comp);

  int sum = 0;
  for(i = 0; i < num; i++) {
    sum += arr[i];
    if(sum > quant) break;
  }
  if(sum < quant) i--;

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

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(), v.end()
#define PI 3.141592653589793238462643383279
typedef long long int ll;
typedef unsigned long long ull;
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;}
typedef pair<ll,ll> P;
const long long MOD = 1e9+7;
const ll INF = 1LL << 60;

int main(){
    int n;
    cin >> n;
    vector<int>a(n);
    int mi = INT_MAX;
    int mx = INT_MIN;
    ll cnt = 0;
    rep(i,n){
        cin >> a[i];
        chmin(mi,a[i]);
        chmax(mx,a[i]);
        cnt += a[i];
    }

    cout << mi <<" " << mx << " " << cnt << endl;





}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
 
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>
#define debug cout << "Ok" << endl;

using namespace std;

void solve(){

	return;
}
 
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);


	string s;

	cin >> s;

	cout << ( s[2]==s[3] and s[4]==s[5] ? "Yes" : "No") << endl;
	

	return 0;
}

Measured memory_bytes: 3668
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)

int cnt = 0;
// n := ???????????????????????°????????° s := ?????????????¨? now := ?????¨?????????????????°???
void dfs(int n, int s, int now){
	if(now > 9){
		//n??????????????????????¨?s
		if(n == 0 && s == 0) cnt++;
		return;
	}
	dfs(n - 1, s - now, now + 1);//??°???now???????????????
	dfs(n, s, now + 1);//??°???now??????????????????
	return;
}
int main(void){
	while(1){
		int n, s; cin >> n >> s;
		if(n == 0 && s == 0) return 0;
		cnt = 0;
		dfs(n, s, 0);
		printf("%d\n", cnt);
	}
}

Measured memory_bytes: 1144
n, m = map(int, input().split())
l = [[0,0] for i in range(n)]
for i in range(m):
    p, m = input().split()
    if l[int(p)-1][0] == 0:
        if m == 'WA':
            l[int(p)-1][1] = l[int(p)-1][1] + 1
        else:
            l[int(p)-1][0] = 1
ac = 0
wa = 0
for i in range(n):
    if l[i][0] == 1:
        ac = ac + 1
        wa = wa + l[i][1]
print(str(ac) + ' ' + str(wa))

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N), R(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
    R.at(i) = vec.at(i);
  }

  sort(R.begin(), R.end());

  for (int i = 0; i < N; i++) {
    if (vec.at(i) == R.at(N - 1)) cout << R.at(N - 2) << endl;
    else cout << R.at(N - 1) << endl;
  }
}

Measured memory_bytes: 3200
import java.io.*;
import java.util.*;

public class Main{
    static int[][] gcd=new int[201][201];

    private static int fanc1(int[] ary){
        int g=0;
        if(gcd[ary[0]][ary[1]]>0){
            g=gcd[ary[0]][ary[1]];
        }else{
            g=fanc2(ary[0],ary[1]);
        }
        if(gcd[(int)Math.max(g,ary[2])][(int)Math.min(g,ary[2])]>0){
            return gcd[(int)Math.max(g,ary[2])][(int)Math.min(g,ary[2])];
        }else{
            return fanc2((int)Math.max(g,ary[2]),(int)Math.min(g,ary[2]));
        }
    }

    private static int fanc2(int a,int b){
        if(gcd[a][b]>0)return gcd[a][b];
        if(a%b==0)return (gcd[a][b]=b);
        return (gcd[a][b]=fanc2(b,a%b));
    }

    public static void main(String[] args)throws Exception{
        Scanner sc=new Scanner(System.in);
        int k=sc.nextInt();
        long total=0;
        for(int i=1;i<=k;i++){
            for(int j=1;j<=k;j++){
                for(int l=1;l<=k;l++){
                    int[] ary={i,j,l};
                    Arrays.sort(ary);
                    total+=fanc1(ary);
                }
            }
        }
        System.out.println(total);
    }
}

Measured memory_bytes: 54116
N = int(input())
A = list(map(int,input().split()))

def BubbleSort(A, N):
 flag = 0
 sw = 0
 i = 0
 while flag == 0:
  flag = 1
  for j in range(N-1, i, -1):
   if A[j] < A[j-1]:
    A[j], A[j-1] = A[j-1], A[j]
    flag = 0
    sw += 1
  i += 1
 return str(sw)

sw = BubbleSort(A, N)
print(" ".join(map(str, A)))
print(sw)

Measured memory_bytes: 7716
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define ggr getchar();getchar();return 0;
#define prique priority_queue
constexpr auto mod = 998244353;
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
//combination(Nが小さい時はこれを使う
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}

// 二項係数計算
long long COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

//繰り返し二乗法（Nが大きい時の場合のcombination)
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= (i % mod); res %= mod;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
//UnionFind
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
int dight(int n) {
	int ans = 1;
	while (n >= 10) {
		n /= 10;
		ans++;
	}
	return ans;
}
int dight_sum(int n) {
	int sum = 0;
	rep(i, 20)sum += (n % (int)pow(10, i + 1)) / (pow(10, i));
	return sum;
}
string s, t;
signed main() {
	cin >> s >> t;
	rep(i, s.size()) {
		if (s[i] != t[i]) {
			puts("No");
			ggr
		}
	}
	puts("Yes");
	ggr
}


Measured memory_bytes: 3628
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    int n;
    int[] sq;
    int ans;

    void run(){
	sq = new int[200]; // under 1024*32
	for(int i=0; i<sq.length; i++)
	    sq[i] = i*i;

	while(sc.hasNext()){
	    n = sc.nextInt();
	    if(n!=0){
		ans = 0;
		int level = sq.length-1;
		while(n < sq[level]) level--;
		int use = 0;
		solve(n, level, use);
		System.out.println(ans);
	    }
	}
    }

    void solve(int n, int level, int use){
	// hajiki kokokara
	if(level==0 || use>=4 || n<0) return;
	if(use==3 && sq[level]<n) return;
	// hajiki kokomade

	solve(n, level-1, use);

	n -= sq[level];
	use++;
	if(n==0 && use<=4){
	    ans++;
	    return;
	}

	if(n>=sq[level]) solve(n, level, use);
	else solve(n, level-1, use);
    }
}

Measured memory_bytes: 21304
S = input()

if S[0] == 'A':
    f1 = True
else:
    f1 = False

C_cnt = 0
for s in S[2:-1]:
    if s == 'C':
        C_cnt += 1
if C_cnt == 1:
    f2 = True
else:
    f2 = False

f3 = True
for s in S:
    if s == 'A' or s == 'C':
        continue
    if s != s.lower():
        f3 = False
        break

if f1 and f2 and f3:
    print('AC')
else:
    print('WA')



Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll mod= 1e9 + 7;


int main(){
  int a,b,c,k;
  cin >> a >>b >>c >>k;
  int ans=0;
  while(a>=b){
    ans++;
    b*=2;
  }
  while(b>=c){
    ans++;
    c*=2;
  }
  if(ans<=k){cout << "Yes" << endl;}else{cout << "No" << endl;}
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  int a[n];
  long dp[n+1];
  for(int i=0;i<n;i++)
    cin>>a[i];
  
  dp[0]=0;
  dp[1]=abs(a[1]-a[0]);
  for(int i=2;i<n;i++)
  {
    	long mn=LONG_MAX;
    	for(int j=max(i-k,0);j<i;j++)
        {
          	if(abs(a[i]-a[j])+dp[j]<mn)
            {
              	mn=abs(a[i]-a[j])+dp[j];
            }
        }
    	dp[i]=mn;
  }
  cout<<dp[n-1]<<endl;
}


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

long long mod = 1000000007LL;


long long cnt[200004];

int mat[405][405];
bool thonk[1004];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	
	int rows, cols; cin >> rows >> cols;
	int g[rows][cols];
	for(int r = 0;r < rows;r++){
		string s; cin >> s;
		for(int c = 0;c < cols;c++){
			g[r][c] = (s[c] == '.');
			thonk[r*cols+c] = g[r][c];
		}
	}
	
	///r*cols+c
	int n = rows*cols;
	for(int i = 0;i < n;i++){
		for(int j = 0;j < n;j++) mat[i][j] = 5002313;
		mat[i][i] = 0;
	}
	for(int r = 0;r < rows;r++){
		for(int c = 0;c < cols-1;c++){
			if(g[r][c] && g[r][c+1]){
				int a = r*cols+c;
				int b = r*cols+c+1;
				mat[a][b] = 1;
				mat[b][a] = 1;
			}
		}
	}
	
	for(int r = 0;r < rows-1;r++){
		for(int c = 0;c < cols;c++){
			if(g[r][c] && g[r+1][c]){
				int a = r*cols+c;
				int b = (r+1)*cols+c;
				mat[a][b] = 1;
				mat[b][a] = 1;
			}
		}
	}
	

	
	for(int k = 0;k < n;k++)
	for(int i = 0;i < n;i++)
	for(int j = 0;j < n;j++) mat[i][j] = min(mat[i][j],mat[i][k]+mat[k][j]);
	
	int ans = 0;
	for(int i = 0;i < n;i++){
		for(int j = 0;j < n;j++){
			if(thonk[i] && thonk[j]) ans = max(ans, mat[i][j]);
		}
	}
	
	cout << ans;
}


Measured memory_bytes: 896
// ?????±??????????????¨????¨???????
// ??¨??????????´????0??\?????§??????????´?????????§??? k ???????????£???????????´???????????¨??§????????¢?????´????????????
// ????´??????¨???????????\??????????????°(= ??´????????????????????????????????\????????????)???
// ???????????????????????§???????????????????????????????????????????????????????????????????????°??????????????§
// ???????????¢?????´???????????¨???????????????????????????????´??????°??¨?????§??????????????????( O(n + k) )???
//
// ????????????????????????????????????????????§???????????????(2000000)????????????????????´???????????????
// `int array[n]`??????????????£?¨??????????????????¨???????????????????????????????????????????????????
// `int *array = new int[n]`??????????????????????????????????????¢???????¢????????????????????????????


/* ALDS1_6_A: Counting Sort */

#include <iostream>
#include <cstdio>

const int MAX_VALUE = 10000;

void counting_sort(int n, int in[], int out[], int max) {
    int counts[max + 1];
    std::fill_n(counts, max + 1, 0);

    for (int i = 0; i < n; i++)
        counts[ in[i] ]++;

    for (int i_c = 1; i_c <= max; i_c++)
        counts[i_c] += counts[i_c - 1];

    for (int i = n - 1; 0 <= i; i--) {
        out[ counts[in[i]] - 1 ] = in[i];
        counts[ in[i] ]--;
    }
}

int main() {
    int n;
    scanf("%d", &n);

    int *in = new int[n];
    for (int i = 0; i < n; i++)
        scanf("%d", &in[i]);

    int *out = new int[n];
    counting_sort(n, in, out, MAX_VALUE);

    printf("%d", out[0]);
    for (int i = 1; i < n; i++)
        printf(" %d", out[i]);
    puts("");

    return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

const int INF = 1001001001;

int ck(int a)
{
    if (a == 1)
    {
        return 0;
    }
    for (int i = 2; i * i <= a; i++)
    {
        if (a % i == 0)
        {
            return 0;
        }
    }
    return 1;
}

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

    vector<int> su(n, 0), cum(n + 1, 0);
    rep(i, n - 1)
    {
        if (s.substr(i, 2) == "AC")
        {
            su[i + 1]++;
        }
    }
    rep(i, n) cum[i + 1] += su[i] + cum[i];
    // rep(i, n + 1)
    // {
    //     cout << cum[i] << ' ';
    // }
    // cout << endl;

    rep(i, q)
    {
        int l, r;
        cin >> l >> r;

        cout << cum[r] - cum[l] << endl;
    }

    return 0;
}

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

int main(void){
    int N;
    cin >> N;
    
    long long p[N+1];
    for(int i=1; i<=N; i++) cin >> p[i];

    long long tp=0;
    for(int i=1; i<=N; i++){
        if(p[i]==i){
            tp++;
            i++;
        }
    }

    cout << tp << endl;

    return 0;
}

Measured memory_bytes: 1024
#include"bits/stdc++.h"
using namespace std;
int main()
{
  int i,n,c=0,k,a,t;
  cin>>n>>k;
  t=n;
  vector<int> v;
  while(t--)
  {
    cin>>a;
    v.push_back(a);
  }
  sort(v.begin(),v.end());
  for(i=0;i<k;i++)
    c+=v[i];
  cout<<c;
}
  


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define set_bits(a) __builtin_popcount(a)
#define pb push_back
#define pf push_front
#define mod 1000000007
#define M 998244353
#define fi first
#define se second
#define endl '\n'
#define INF 1e18
#define PI 3.14159265358979323846
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


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

     unordered_map<ll,ll>mp;

     for(i=1;i<=k;i++)
     {
         ll p;
         cin>>p;
         while(p--)
         {
             ll a;
             cin>>a;
             mp[a]++;
         }
     }
     ll ans=0;
     for(i=1;i<=n;i++)
     {
         if(mp.find(i)==mp.end())
         {
             ans++;
         }
     }


     cout<<ans<<endl;
}


Measured memory_bytes: 3632
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

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

    int a, b;
    cin >> a >> b;
    int res =a - 2*b;
    cout << max(res,0);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <string>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

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

	vector<int> peaks;
	for (int i = 1; i < n; ++i) {
		peaks.push_back(value[i] - value[i - 1]);
	}

	long long money = 1000, stocks = 0;
	for (int i = 0; i < n - 1; ++i) {
		if (peaks[i] > 0) {
			stocks = money / value[i];
			money %= value[i];
			money += value[i + 1] * stocks;
		}
	}

	cout << money << "\n";

	return 0;

}

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

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

using namespace std;

int main() {
  int N, K; cin >> N >> K;
  set<int> st;
  rep(i, K) { int x; cin >> x; st.insert(x); }
  for (int n = N; ; n++) {
    string s = std::to_string(n);
    int sz = s.size();
    bool flag = 1;
    rep(i, sz) {
      if (st.count(s[i] - '0')) { flag = 0; break; }
    }
    if (flag) {
      cout << n << "\n";
      exit(0);
    }
  }
}


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

using namespace std;
typedef long long ll;

int H, W;
ll cost[10][10];
ll d[10][10];
int in[200][200];
const ll INF = 1145141919810893;

int main() {
	cin >> H >> W;
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++)cin >> cost[i][j];
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++)cin >> in[i][j];
	}

	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			if (i == j)d[i][j] = 0;
			else d[i][j] = cost[i][j];
		}
	}
	for (int k = 0; k < 10; k++) {
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				if (d[i][j] > d[i][k] + d[k][j])d[i][j] = d[i][k] + d[k][j];
			}
		}
	}
	ll ans = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (in[i][j] != -1) {
				ans += d[in[i][j]][1];
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <fstream>
#include<vector>
#include<utility>
#include<algorithm>
#include<limits.h>


using namespace std;


int main()
{
	int n, k;

	cin >> n >> k;

	vector<int> h(n);

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

	sort(h.begin(), h.end());


	int wk;
	int ans = INT_MAX;
	for (int i = 0; i < n - k + 1; i++) {
		wk = h[i + k - 1] - h[i];

		if (wk < ans)ans = wk;



	}

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



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int N=5e5+7;
struct node{int l,r,sum;}t[N*40];
int n,cnt,a[N],rt[N];
map<int,int>pos;
void update(int l,int r,int &now,int pre,int k,int v)
{
	t[++cnt]=t[pre],t[cnt].sum+=v,now=cnt;
	if(l==r)return;
	int mid=l+r>>1;
	if(k<=mid)update(l,mid,t[cnt].l,t[pre].l,k,v);
	else update(mid+1,r,t[cnt].r,t[pre].r,k,v);
}
int query(int l,int r,int rt,int k)
{
	if(l>=k)return t[rt].sum;
	int mid=l+r>>1;
	if(k<=mid)return query(l,mid,t[rt].l,k)+t[t[rt].r].sum;
	return query(mid+1,r,t[rt].r,k);
}
int main()
{
	int q,tmp,l,r;
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(!pos.count(a[i]))update(1,n,rt[i],rt[i-1],i,1);
		else update(1,n,tmp,rt[i-1],pos[a[i]],-1),update(1,n,rt[i],tmp,i,1);
		pos[a[i]]=i;
	}
	while(q--)scanf("%d%d",&l,&r),printf("%d\n",query(1,n,rt[r],l));
}

Measured memory_bytes: 241224
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<utility>
#include<cmath>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<cstring>
#include<iterator>
#include<bitset>
#include<assert.h>
using namespace std;
 
struct edge {int /*from,*/to,cost;};
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
typedef vector<edge> VE;
static const int MOD = 1000000007;
static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define ALL(x) (x).begin(),(x).end()
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define MAX(a,b,c) max((a),max((b),(c)))
#define MIN(a,b,c) min((a),min((b),(c)))
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
//#define int ll

signed main(){
    string s;
    cin >> s;
    REP(i,4) cout << s[i];
    printf(" ");
    FOR(i,4,12) cout << s[i];
    puts("");
    return 0;
}

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

int main() {
  int W, H, N;
  cin >> W >> H >> N;

  int x[N], y[N], a[N];
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i] >> a[i];
  }

  vector<vector<int>> tiles(H, vector<int>(W, 1));

  for (int i = 0; i < N; i++) {
    if (a[i] == 1) {
      for (int k = 0; k < H; k++) {
        for (int l = 0; l < x[i]; l++) {
          tiles.at(k).at(l) = 0;
        }
      }
    }
    else if (a[i] == 2) {
      for (int k = 0; k < H; k++) {
        for (int l = W - 1; l >= x[i]; l--) {
          tiles.at(k).at(l) = 0;
        }
      }
    }
    else if (a[i] == 3) {
      for (int k = 0; k < y[i]; k++) {
        for (int l = 0; l < W; l++) {
          tiles.at(k).at(l) = 0;
        }
      }
    }
    else if (a[i] == 4) {
      for (int k = H - 1; k >= y[i]; k--) {
        for (int l = 0; l < W; l++) {
          tiles.at(k).at(l) = 0;
        }
      }
    }
  }

  int area = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (tiles.at(i).at(j)) area++;
    }
  }

  cout << area << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[1005], b[1005];
int h, n;
int dp[1005][20005];
int main()
{
	ios::sync_with_stdio(false);
	cout.tie(0);
	cin.tie(0);
	cin >> h >> n;
	memset(dp, 0x3f, sizeof(dp));
	for (int i = 1; i <= n; i ++)
		dp[i][0] = 0;
	for (int i = 1; i <= n; i ++)
	{
		cin >> a[i] >> b[i];
		for (int j = 1; j <= h + 10000; j++)
			if (j - a[i] >= 0)
				dp[i][j] = min(dp[i - 1][j], dp[i][j - a[i]] + b[i]);
			else dp[i][j] = dp[i - 1][j];
	}
	int ans = 0x3f3f3f3f;
	for (int i = h; i <= h + 10000; i++)
		ans = min(ans, dp[n][i]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 78848
#include <stdio.h>

int main(void) {
    int n,k,i,j,temp;
    int sum = 0;
 
    scanf("%d%d",&n,&k);
 
    int l[n];
    
    for(i=0;i<n;i++) {
        scanf("%d",&l[i]);
    }

    for(i=0;i<n-1;i++) {
	for(j=n-1;j>i;j--) {
	    if(l[j-1] > l[j]) {
                temp = l[j];
		l[j] = l[j-1];
		l[j-1] = temp;
	    }
        }
    }
   
    for(i=n-1;i>n-k-1;i--) {
	sum = sum + l[i];
    }
    printf("%d",sum);
}

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

int main()
{
	int N = 0;
	std::cin >> N;

	std::vector<int> H(N);
	for (int i = 0; i < N; ++i)
	{
		std::cin >> H.at(i);
	}

	int answer = 0;
	int up = 0;
	for (int i = 0; i < N - 1; ++i)
	{
		if (H.at(i) >= H.at(i + 1))
		{
			up++;
			if (answer < up)
			{
				answer = up;
			}
		}
		else
		{
			up = 0;
		}
	}

	std::cout << answer << "\n";

	return 0;
}

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

#define fastInput ios_base::sync_with_stdio(false), cin.tie(NULL);
#define all(x) x.begin(), x.end()
#define scan(a) scanf("%d", &a)
#define scanll(a) scanf("%lld", &a)
#define scanD(a) scanf("%lf", &a)
#define print(a) printf("%d\n", a)
#define printll(a) printf("%lld\n", a)
#define printD(a) printf("%lf\n", a)
#define printTwo(a) printf("%.2lf\n", a);
#define read(x) freopen(x, "r", stdin)
#define write(x) freopen(x, "w", stdout)
#define rep(i, a, n) for (int i = a; i < n; i++)
#define REP(i, a, n) for (int i = a; i <= n; i++)
#define inputArray(a,n) rep(i, 0, n) cin >> a[i];
#define copyArray(a,temp,n) rep(i, 0, n) temp[i]=a[i];
#define printArray(a,n) rep(i, 0, n) cout << a[i] << " "; cout << endl;

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

#define Cases  cout << "Case " << ++Case << ": ";
#define __test int tt; int Case=0; cin >> tt; while(tt--)
#define showTime cerr << "time = " << (clock() / CLOCKS_PER_SEC) << " sec" << '\n';

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

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

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

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

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


void solve() {
	ll n, k;
	scanll(n);
	scanll(k);
	n %= k;
	if (n > k - n)
		printll(k - n);
	else
		printll(n);
}

int main() {
#ifdef Niloy
	read("input.txt");
	write("output.txt");
#endif

	solve();

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

	showTime;
	return 0;
}




Measured memory_bytes: 3816
#include <bits/stdc++.h>
#define F first
#define S second
#define T second.first
#define C second.second
using namespace std;
typedef long long ll;
typedef pair<ll, double> pii;
typedef pair<int,pair<double,int>> piii;

const int N= 1e5+5, L = 14, OO = 0x3f3f3f3f;
const ll M=10 ;
const double ESP = 1e-8;


int main(){
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    ll q,h,s,d;
    double n;
    cin>>q>>h>>s>>d>>n;
    piii A[4];
    A[0] = {d,{2.0, d}};
    A[1] = {s*2,{1.0,s}};
    A[2] = {h*4,{0.5,h}};
    A[3] = {q*8,{0.25,q}};
    sort(A, A+4);
    ll ans = 0;
    for(int i=0; i<4; i++){
       if(n<=0.0)
            break;
       if(A[i].T == 2.0){
            ll x = (n/2);
            ans += x*A[i].C;
            n -= x *2;
       }
       else if( A[i].T == 1.0){
            ans+= (ll)(n)*A[i].C;
            break;
       }
       else if( A[i].T == 0.5){
            ans += (ll)(n/0.5)*A[i].C;
            break;
       }
       else if( A[i].T == 0.25){
            ans+= (ll)(n/0.25)*A[i].C;
            break;
       }
    }
    cout<<ans;
}
/*
*/


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

int main(){
    
    size_t n;
    std::cin >> n;

    std::vector<std::pair<size_t, bool>> a(n);

    for(auto&& e : a){
        size_t in;
        std::cin >> in;
        e = {in - 1, false};
    }

    size_t i = 0, cnt = 1;

    while(true){
        if(a.at(i).second == true){
            std::cout << -1 << std::endl;
            return 0;
        }

        if(a.at(i).first + 1 == 2){
            std::cout << cnt << std::endl;
            return 0;
        }

        a.at(i).second = true;
        i = a.at(i).first;
        cnt++;
    }
    
    return 0;
}


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

int main() {
  vector<long long> v(3);
  for (auto &e : v) cin >> e;
  sort(v.begin(), v.end());
  
  for (auto e : v) {
    if (e % 2 == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  
  cout << v[0] * v[1] << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll INF = 1e18;
# define rep(i, n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define all(x) (x).begin(), (x).end()

ll N;

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

    cin >> N;
    vector<ll> P(N);
    vector<ll> Q(N);
    vector<ll> P1(N);
    vector<ll> Q1(N);

    rep(i, N) {
        cin >> P[i];
    }
    rep(i, N) {
        cin >> Q[i];
    }

    P1 = P;
    Q1 = Q;

    sort(all(P1));
    sort(all(Q1));

    ll a = 0;
    ll cnt = 0;
    do {
        cnt++;
        if (P==P1) {
            a = cnt;
            break;
        }
    } while(next_permutation(all(P1)));

    ll b = 0;
    cnt = 0;
    do {
        cnt++;
        if (Q==Q1) {
            b = cnt;
            break;
        }
    } while(next_permutation(all(Q1)));

    cout << abs(b-a) << endl;
    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define RRep(i, r, n) for (ll i = n - 1; i <= r; i--)
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define int long long
#define pb push_back
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
const int MOD = (1000000007);
//const int MOD = (998244353);
//const int INF = (1 << 30)-1;
const int INF = (1LL << 60)-1;
const double EPS = (1 >> 30);

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

//using Graph = vector<vector<pair<int, int>>>;
using Graph = vector<vector<int>>;

int dfs(const Graph &G,int v,vector<bool> &seen,vector<int> &cost){
    seen[v] = true;
    for(auto next_v : G[v]){
        if(seen[next_v]) continue;
        cost[next_v]+=cost[v];
        dfs(G,next_v,seen,cost);
    }
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    int n,q;
    cin>>n>>q;
    Graph G(n);
    vector<int> cost(n);
    vector<bool> seen(n,false);
    int a,b;
    rep(i,n-1){
        cin>>a>>b;
        a--;b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    int p,x;
    rep(i,q){
        cin>>p>>x;
        p--;
        cost[p]+=x;
    }

    seen[0]=true;
    dfs(G,0,seen,cost);

    rep(i,n){
        cout<<cost[i]<<endl;
    }

    
}

Measured memory_bytes: 180608
a,b=map(int,input().split())
aa=a
bb=b
x=0
y=0
while aa>0 and bb>0:
	if aa>bb:
		aa-=1
		x+=1
	else:
		bb-=1
		y+=1
	aa-=1
	bb-=1
if aa!=0 or bb!=0:
	print(0)
	exit()
mod=10**9+7
fac=[1]
for i in range(max(a,b)):
	fac.append(fac[i]*(i+1)%mod)
x+=y
r=pow(fac[y]*fac[x-y]%mod,mod-2,mod)
print(fac[x]*r%mod)


Measured memory_bytes: 42668
#include <stdio.h>
int main() {
	int baris, kolom, n;
	scanf("%d",&baris);
	scanf("%d",&kolom);
	scanf("%d",&n);
	
	int max;
	baris > kolom ? max = baris : max = kolom;
	
	n % max == 0 ? printf("%d",n/max) : printf("%d",(n/max)+1);
	return 0;
}

Measured memory_bytes: 1728