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

public class Main {

    Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] arr = new int[m][2];
        for (int i=0; i<m; i++) {
            arr[i][0] = sc.nextInt() - 1;
            arr[i][1] = sc.nextInt() - 1;
        }

        UnionFind uf = new UnionFind(n);
        for (int i=0; i<m; i++) {
            uf.unite1(arr[i][0], arr[i][1]);
        }

        Set<Integer> set = new HashSet<>();
        for (int i=0; i<n; i++) {
//            System.out.println(uf.parent[i]);
            set.add(uf.find(i));
        }

//        System.out.println(set);
        System.out.println(set.size() - 1);

    }

    class UnionFind {

        int[] parent, rank, size;

        void init(int n) {
            for (int i=0; i<n; i++) {
                parent[i] = i;
                rank[i] = 0;
            }
        }

        UnionFind(int n) {
            parent = new int[n];
            size = new int[n];
            for (int i=0; i<n; i++) {
                parent[i] = i;
                size[i] = 1;
            }
        }

        public int find(int x) {
            if (x==parent[x]) return x;
            return parent[x] = find(parent[x]);
        }

        //    結合して木のサイズを更新
        public void unite1(int x, int y) {
            x = find(x);
            y = find(y);
            if (x==y) return;
            if (size[x] < size[y]) {
                int tmp = x;
                x = y;
                y = tmp;
            }
            parent[y] = x;
            size[x] += size[y];
        }

        //    結合して木の深さを更新
        public void unite2(int x, int y) {
            x = find(x);
            y = find(y);
            if (x==y) return;
            if (rank[x] < rank[y]) {
                parent[x] = y;
            } else {
                parent[y] = x;
                if (rank[x]==rank[y]) rank[x]++;
            }
        }

        public boolean same(int x, int y) {
            return find(x) == find(y);
        }

        public int size(int x) {
            return size[find(x)];
        }


    }

}



Measured memory_bytes: 62220
#include <bits/stdc++.h>
using namespace std;
#define repr(i,k,n) for(int i = (k); i < (n); i++)
#define rep(i,n) repr(i,0,n)
#define ALL(a) begin(a),end(a)
const int INF = 114514810;
const int MOD = 1000000007;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N,Sn=0;
	string S;
	cin >> S;
	N=stoi(S);
	rep(i,S.size()){
		Sn+=ctoi(S[i]);
	}
	if (N%Sn==0){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
# define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(bool f) { if(f) return "True"; else return "False";}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r; 
  for (auto x: v) r += "\n" + to_string(x); return r;}
int Nerr;
template<typename A> string to_string(A *p) {return to_string(vector<A>(p, p + Nerr));}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Lu(...) [&] (auto &&u) { return __VA_ARGS__; }
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }

/************/

signed main()
{
	ios_base::sync_with_stdio(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{   
		int n;
		cin >> n;
		vector<int> a(n+1);
		int sum = 0;
		rep(i,0,n+1){
			cin >> a[i];
			sum += a[i];
		}
		if(n == 0){
			if(a[0] != 1){
				cout << -1 << endl;
			}
			else cout << 1 << endl;
			r0;
		}
		vector<int> v(n+1);
		v[0] = 1;
		rep(i,1,n+1){
			if(v[i-1] * 2 <= 1e9) v[i] = v[i-1] * 2;
			else v[i] = 1e9;
		}
		int ans = 0;
		vector<int> cum(n+1);
		rep(i,0,n+1){
			if(i) cum[i] = sum;
			sum -= a[i];
		}
		cum[0] = 1;
		int free = (a[0]!=1);
		rep(i,0,n+1){
			if(a[i] > free*2){
				cout << -1 << endl;
				r0;
			}
			cum[i] = min(cum[i], 2*free);
			free = max(0ll, cum[i] - a[i]);
		}
		ans = 0;
		rep(i,0,n+1) ans += cum[i];
		cout << ans;
	}
}

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


vector<int> vis;

vector<vector<int> > g;

void dfs(int node,int curr,vector<int> &h)
{
	h[node]=curr;
	vis[node]=1;
	for(auto v:g[node])
	{
		if(!vis[v])
			dfs(v,curr+1,h);
	}
}


int main()
{
	ios_base::sync_with_stdio(false);
	
	int n,a,b;
	cin>>n>>a>>b;
	
	vis.resize(n+1);
	g.resize(n+1);
	
	for(int i=0;i<n-1;i++)
	{
		int u,v;
		cin>>u>>v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	
	vector<int> da(n+1,0);
	vector<int> db(n+1,0);
	
	dfs(a,0,da);
	fill(vis.begin(),vis.end(),0);
	dfs(b,0,db);
	
	int ans=0;
	
	for(int i=0;i<n+1;i++)
	{
		if(da[i]<db[i])
			ans = max(ans,db[i]);
	}
	cout<<ans-1;
	
}

Measured memory_bytes: 10752
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using llvec=vector<ll>;
using llmat=vector<vector<ll>>;
#define PI 3.141592653589793
#define llmattp(name,a,b,num) name(a,vector<ll>(b,num))
#define INTINF 1<<30
#define LLINF 1LL<<60
#define ABS(x) ( (x)>0 ? (x) : -(x) )

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;
}

ll gcd(ll a, ll b) { //最大公約数
	if(a==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

ll factorial(ll x) { //階乗
	ll f=1;
	for(ll i=2; i<x; i++) {
		f*=i;
	}
	return f;
}

ll nPr(ll n, ll r) {
	ll result=1;
	for(ll i=r+1; i<=n; i++) result*=i;
	return result;
}

ll nCr(ll n, ll r) {
	if (n == r) { return 1; }
	if (r > n) { return 0; }

	if (r > n / 2) { r = n - r; }

	if (n == 0) { return 0; }
	if (r == 0) { return 1; }
	if (r == 1) { return n; }

	double result = 1;
	for (double i = 1; i <= r; i++) {
		result *= (n - i + 1) / i;
	}

	return (ll)result;
}

bool IsPrime(ll num) { //素数判定
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (ll i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

ll GreaterBinarySearch(ll *array, ll key, ll max, ll min) {
	if(array[max]<array[min]) {
		return NULL;
	} else {
		ll mid = max + (min-max)/2;
		if(array[mid]<key) {
			return GreaterBinarySearch(array,key,max,mid-1);
		} if(array[mid]>key) {
			return GreaterBinarySearch(array,key,mid+1,min);
		} else {
			return mid;
		}
	}
}

int DigitNum(ll n) { //桁数
	int digit=0;
	ll wari=1LL;
	while(n/wari) {
		digit++;
		wari*=10;
	}
	return digit;
}

void PrimeFact(ll x) { // 素因数分解 出力部を適切に書き換え
	int i=2;
	while(x%2&&i*i<=x) {
		cout<<2<<endl;
		x/=2;
	}
	i++;
	while(i*i<=x) {
		if(x%i) {
			i+=2;
			continue;
		}
		cout<<i<<endl;
		x/=i;
	}
}

bool Palind(string s) { //回文判定
	return s == string(s.rbegin(), s.rend());
}

string stcut[4][4]={
	{"AA","AB","AX","AY"},
	{"BA","BB","BX","BY"},
	{"XA","XB","XX","XY"},
	{"YA","YB","YX","YY"}
};

int main() {
	string S; cin>>S;
	if(S.at(2)==S.at(3)&&S.at(4)==S.at(5))
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}


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

int main() {
int N=0;
  
  cin>>N;
  vector<int> A(N);
  vector<int> B(N);
  
  A.at(0)=0;
for(int i=1;i<N;i++){
  cin>>A.at(i);
}
  
  for(int i=1;i<N;i++){
    int j=A.at(i)-1;
    B.at(j)++;
  }
    
    for(int i=0;i<N;i++){
      cout<<B.at(i)<<endl;
    }
    
      
  
}


Measured memory_bytes: 4840
#include <map>
#include <set>
#include <list>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <bitset>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
bool a[805][805],v[805][805];
int b[805][805];
queue<pair<int,int> > q;
int main ( ) {
	int n,m,k,i,j,sx,sy,ans=2147483647;
	scanf("%d%d%d",&n,&m,&k);
	for (i=1;i<=n;i++) {
		string c;
		cin>>c;
		for (j=1;j<=m;j++) {
			if (c[j-1]=='S') sx=i,sy=j,a[i][j]=true;
			else if (c[j-1]=='#') a[i][j]=false;
			else a[i][j]=true;
			b[i][j]=2147483647;
		}
	}
	int x=sx,y=sy;
	q.push(make_pair(x,y));b[x][y]=0;
	while (!q.empty()) {
		pair<int,int> t=q.front();q.pop();
		x=t.first;y=t.second;
		if (v[x][y] || !a[x][y]) continue;
		if (x>n || y>m || x<1 || y<1) continue;
		v[x][y]=true;
		if (a[x+1][y]) b[x+1][y]=min(b[x+1][y],b[x][y]+1),q.push(make_pair(x+1,y));
		if (a[x-1][y]) b[x-1][y]=min(b[x-1][y],b[x][y]+1),q.push(make_pair(x-1,y));
		if (a[x][y+1]) b[x][y+1]=min(b[x][y+1],b[x][y]+1),q.push(make_pair(x,y+1));
		if (a[x][y-1]) b[x][y-1]=min(b[x][y-1],b[x][y]+1),q.push(make_pair(x,y-1));
	}
	for (i=1;i<=n;i++) {
		for (j=1;j<=m;j++) {
			if (!a[i][j]) continue;
			if (b[i][j]==2147483647) continue;
			int tt=b[i][j];
			if (b[i][j]<k) tt=k;
			int w=min(min(i-1,j-1),min(n-i,m-j));
			tt+=w;
			tt=(tt-1)/k+1;
			if (tt<ans) ans=tt;
		}
	}
	printf("%d\n",ans);
	return 0;
}
/*
Sample Input 1
3 3 3
#.#
#S.
###
Sample Output 1
1

Sample Input 2
3 3 3
###
#S#
###
Sample Output 2
2

Sample Input 3
7 7 2
#######
#######
##...##
###S###
##.#.##
###.###
#######
Sample Output 3
2
*/

Measured memory_bytes: 4096
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

k=int(input())
ans=0
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            ans+=gcd(a,b,c)
print(ans)


Measured memory_bytes: 70008
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort(reverse=True)

V = [-1, 2, 5, 5, 4, 5, 6, 3, 7, 6]

dp = [-1e10] * (N + 1)
dp[0] = 0

for i in range(1, N + 1):
    # i 本で表せる最大の桁数を dp に求める
    l = [dp[i - V[j]] + 1 for j in A if i - V[j] >= 0]
    if l:
        dp[i] = max(l)
# 各桁の最大値を求めていく
n = N
while n > 0:
    for j in A:
        if n - V[j] < 0: continue
        if dp[n] == dp[n - V[j]] + 1:
            print(j, end='')
            n = n - V[j]
            break
print()


Measured memory_bytes: 4204
#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define ll long long
  #define int long long
  #define double long double
  #define max(a,b) (a>b?a:b)
  #define min(a,b) (a<b?a:b)
  #define mp make_pair
  #define pb push_back
  #define inf INT_MAX
  #define f first
  #define s second
  #define all(v) v.begin(), v.end()
  #define mod INT_MAX 
  int32_t main()
  { 
    /*#ifndef ONLINE_JUDGE
       freopen("in.txt","r",stdin);
       freopen("out.txt","w",stdout);
    #endif*/
    
    IOS
    int x;
    cin>>x;
    //cout<<x/100.00<<endl;
    double t=log10(x/100.00) ;
    //cout<<t<<endl;
    t/= log10(1.01);
    //cout<<t<<endl;
    int amt=100,cnt=0;
    while(amt<x)
    {
      amt=amt*1.01;
      //cout<<amt<<" ";
      cnt++;
      amt=floor(amt);
    }
    int ans=(int)(round(t));
    cout<<cnt;
    return 0;
  }
    

Measured memory_bytes: 3692
#include <bits/stdc++.h>
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define TRAV(i, a) for(auto & i : (a))
#define SZ(x) ((int)(x).size())
#define PR std::pair
#define MP std::make_pair
#define X first
#define Y second
typedef long long ll;
typedef std::pair<int, int> PII;
typedef std::vector<int> VI;

const int MOD = 1000000007;

int dp[5005][5005];
int fact[5005];

int modpow(int a, int e){
	int ret = 1;
	while(e > 0){
		if(e&1) ret = (1ll*a*ret)%MOD;
		a = (1ll*a*a)%MOD;
		e>>=1;
	}
	return ret;
}

int tick;
VI vis;
std::vector<VI> g;

int medu;

void dfs(int v){
	vis[v] = tick;
	TRAV(ch, g[v]){
		if(vis[ch] == tick){
			medu++;
		}else if(vis[ch] == 0){
			dfs(ch);
		}
	}
}

int szdfs(int v){
	int ret = 1;
	TRAV(ch, g[v]) ret += szdfs(ch);
	return ret;
}

int main(){
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(0);
	int n;
	std::cin >> n;
	g.resize(n);
	VI next(n);
	FOR(i, n){
		std::cin >> next[i];
		if(next[i] != -1){
			next[i]--;
			g[next[i]].push_back(i);
		}
	}

	vis.resize(n);
	tick = 1;
	FOR(i, n) if(vis[i] == 0 && next[i] != -1) dfs(i), tick++;

	std::cerr << "meduzki: " << medu << std::endl;

	VI size(n);
	VI A;
	FOR(i, n) if(next[i] == -1) size[i] = szdfs(i), A.push_back(size[i]);

	int ans = (1ll*medu*modpow(n-1, SZ(A)))%MOD;

	std::cerr << "base ans: " << ans << std::endl;

	fact[0] = 1;
	REP(i, 1, 5005) fact[i] = (1ll*fact[i-1]*i)%MOD;


	dp[0][0] = 1;
	REP(i, 1, SZ(A)+1){
		dp[i][0] = 1;
		REP(j, 1, SZ(A)+1){
			int zemna = (1ll*dp[i-1][j-1]*A[i-1])%MOD;

			int domn = modpow(n-1, SZ(A)-j);
			if(j == 1){
				int cur = (1ll*(zemna-1)*domn)%MOD;
				if(cur < 0) cur += MOD;
				ans = (ans+cur)%MOD;
			}else{
				int cur = 1ll*zemna*fact[j-1]%MOD;
				cur = (1ll*cur*domn)%MOD;
				ans = (ans + cur)%MOD;
			}

			dp[i][j] = (zemna + dp[i-1][j])%MOD;
		}
	}

	std::cerr << "spojne: " << ans << std::endl;
	std::cerr << "ways: " << modpow(n-1, SZ(A)) << std::endl;
	ll all = 1ll*modpow(n-1, SZ(A))*n%MOD;
	std::cout << (all-ans+MOD)%MOD << std::endl;

	return 0;
}

Measured memory_bytes: 101588
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>

using namespace std;
typedef long long ll;
#define pl pair<ll,ll>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); itr++)
#define dbg(x) cout << #x"="<< (x) << endl
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a) 
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second

int main(){
	int n,k;
  cin>>n>>k;
  vector<int> a(n+1);

  int temp;
  rep(i,n){
    cin>>temp;
    a[temp]--;
  }
  sort(all(a));

  int ans=0;
  rep(i,k){
    ans-=a[i];
  }
  cout<<n-ans<<endl;

    return 0;
}

Measured memory_bytes: 1152
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int r;
  cin >> r;
  cout << r * r << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    static final int SUM_LIMIT = 2500;

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

        int N = sc.nextInt();
        int A = sc.nextInt();
        int[] x = new int[N];
        for (int i = 0; i < x.length; ++i) {
            x[i] = sc.nextInt();
        }

        System.out.println(solve(x, A));

        sc.close();
    }

    static long solve(int[] x, int A) {
        long[][] wayNums = new long[x.length + 1][SUM_LIMIT + 1];
        wayNums[0][0] = 1;
        for (int xi : x) {
            long[][] nextWayNums = new long[x.length + 1][SUM_LIMIT + 1];
            for (int i = 0; i <= x.length; ++i) {
                for (int j = 0; j <= SUM_LIMIT; ++j) {
                    nextWayNums[i][j] = wayNums[i][j];

                    if (i != 0 && j >= xi) {
                        nextWayNums[i][j] += wayNums[i - 1][j - xi];
                    }
                }
            }

            wayNums = nextWayNums;
        }

        long[][] wayNums_ = wayNums;
        return IntStream.rangeClosed(1, x.length).mapToLong(i -> wayNums_[i][A * i]).sum();
    }
}

Measured memory_bytes: 52176
using System;
using System.Linq;
using System.Text;
using CompLib.Util;
using System.Threading;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        int k = sc.NextInt();
        var sb = new StringBuilder();
        for (int i = 0; i < k; i++)
        {
            sb.Append("ACL");
        }

        Console.WriteLine(sb);
    }

    public static void Main(string[] args) => new Program().Solve();
    // public static void Main(string[] args) => new Thread(new Program().Solve, 1 << 27).Start();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public string ReadLine()
        {
            _index = _line.Length;
            return Console.ReadLine();
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 27492
#include <bits/stdc++.h>
using namespace std;
#define int long long
int MOD = (int)1e9 + 7;
int INF = (int)2e18;
// Comment out below and program paste
// #include "UnionFind.h"
// #include "power.h"


signed main() {
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i] >> B[i];
    }
    int answer = 0, temp = 0;
    for (int i = N - 1; i >= 0; --i) {
        int t = B[i] - ((A[i] + temp) % B[i]);
        if (t != B[i]) {
            answer += t;
            temp += t;
        }
    }
    cout << answer << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--)
#define rrep1(i,n) for(int i=(int)(n);1<=i;i--)

#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define endl "\n"

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

typedef long long lint;

using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	lint n,k;
	cin>>n>>k;
	cout<<min(n%k,abs((n%k)-k))<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;

int main() {
	int a, p;
	cin >> a >> p;
	p += a * 3;
	int py;
	py = p / 2;
	cout << py << endl;
	return 0;
}

Measured memory_bytes: 256
//https://atcoder.jp/contests/s8pc-3/tasks/s8pc_3_b
//B - 石落としゲーム
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
const ll LINF = 0x1fffffffffffffff;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}
int main() {
#if LOCAL&01
  std::ifstream in("./test/sample-3.in");
  //std::ifstream in("./input.txt");
  std::cin.rdbuf(in.rdbuf());
#else
  cin.tie(0);
  ios::sync_with_stdio(false);
#endif
  ll H,W,K; cin>>H>>W>>K;
  using Mat = vector<vector<ll>>;
  vector<vector<ll>> chw(H,vector<ll>(W));
  vector<string> chw_str(H);
  REP(i,H){
    cin>>chw_str[i];
    const auto& s=chw_str[i];
    FOR(x,0,s.size()){
      ll v=s.at(x)-'0';
      chw[i][x]=v;
    }
  }

  auto kesu_line = [&](vector<ll>& ln)->ll{
    ll result=0;
    for(ll x=0;x<W;++x){
      ll sc=ln[x];
      if(sc==0)continue;
      ll num=1;
      while(true){
        ll cx=x+num;
        if(cx>=W)break;
        if(sc==ln[cx]) ++num;
        else {
          break;
        }
      }
      if(num>=K){
        FOR(i,x,x+num){
          result += ln[i];
          ln[i]=0;
        }
      }
    }
    return result;
  };
  auto kesu = [&](Mat& mat)->ll{
    ll result=0;
    FOR(y,0,H){
      result += kesu_line(mat.at(y));
    }
    return result;
  };
  auto otosu_line = [&](Mat& mat, ll ix){
    for(ll y=H-1;y>=1;--y){
      if(mat[y][ix]==0){
        for(ll ty=y-1;ty>=0;--ty){
          if (mat[ty][ix]!=0){
            swap(mat[y][ix],mat[ty][ix]);
            break;
          }
        }
      }
    }
  };
  auto otosu = [&](Mat& mat){
    FOR(x,0,W){
      otosu_line(mat, x);
    }
  };

  //一番した調べればいいだけではないな...
  ll ans=0;
  //ll del_y=H-1;
  FOR(del_y,0,H)
  FOR(del_x,0,W){
    auto wk=chw; //copy
    wk[del_y][del_x]=0;
    otosu_line(wk,del_x);

    ll rate=1;
    ll score=0;
    do{
      ll r = kesu(wk);
      dump(rate,r,wk);
      if(r==0)break;
      score += (r * rate);
      rate *= 2;
      otosu(wk);
    }while(true);
    chmax(ans,score);
  }
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			A();
		}
		public static void A()
		{
			Scanner cin = new Scanner();
			int n = cin.Int();
			int a = cin.Int();
			int b = cin.Int();
			int c = cin.Int();
			int d = cin.Int();
			string s = cin.Next();

			if (d > c) {
				// a b c d
				int cnt = 0;
				for (int i = a; i <= c; ++i) {
					if (s[i - 1] == '#') {
						if (cnt == 1) {
							Console.WriteLine("No");
							return;
						} else {
							cnt = 1;
						}
					} else {
						cnt = 0;
					}
				}

				cnt = 0;
				for (int i = b; i <= d; ++i) {
					if (s[i - 1] == '#') {
						if (cnt == 1) {
							Console.WriteLine("No");
							return;
						} else {
							cnt = 1;
						}
					} else {
						cnt = 0;
					}
				}

				Console.WriteLine("Yes");
			} else {
				// a b d c
				int cnt = 0;
				for (int i = a; i <= c; ++i) {
					if (s[i - 1] == '#') {
						if (cnt == 1) {
							Console.WriteLine("No");
							return;
						} else {
							cnt = 1;
						}
					} else {
						cnt = 0;
					}
				}

				int maxCnt = 0;
				cnt = 0;

				for (int i = b - 1; i <= d + 1; ++i) {
					if (s[i - 1] == '#') {
						maxCnt = Math.Max(maxCnt, cnt);
						cnt = 0;
					} else {
						cnt += 1;
					}
				}

				maxCnt = Math.Max(maxCnt, cnt);
				if (maxCnt >= 3) {
					Console.WriteLine("Yes");
				} else {
					Console.WriteLine("No");
				}
			}
		}
	}

	public 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 Int()
		{
			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] = Int() + add;
			}
			return Array;
		}

		public long Long()
		{
			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] = Long() + add;
			}
			return Array;
		}

		public double Double()
		{
			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] = Double() + add;
			}
			return Array;
		}
	}
}


Measured memory_bytes: 12384
#include <algorithm>
#include <iostream>
#include <limits>
#include <vector>

using ::std::cin;
using ::std::cout;
using ::std::endl;
using ::std::string;
using ::std::vector;

using LL = long long;

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

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

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

  LL subSum = 0;
  for (int i = 1; i <= n - 2; i += 2) {
    subSum += 2 * ds[i];
  }

  // cout << sum << " " << subSum << endl;

  vector<LL> xs(n);
  xs[0] = sum - subSum;
  for (int i = 1; i < n; i++) {
    xs[i] = (ds[i - 1] - xs[i - 1] / 2) * 2;
  }

  // for (int i = 0; i < n; i++) {
  //   if (i > 0) cout << " ";
  //   cout << xs[i];
  // }
  // cout << endl;
  string output;
  for (int i = 0; i < n; i++) {
    if (i > 0) output.append(" ");
    output.append(std::to_string(xs[i]));
  }
  cout << output << endl;
  return 0;
}

Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
using LP=pair<ll,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=998244353;

ll modpower(ll n,ll p){
    if(p==0){return 1;}
    if(p%2==1){return n*modpower(n,(p-1)/2)%MOD*modpower(n,(p-1)/2)%MOD;}
    else{return modpower(n,p/2)*modpower(n,p/2)%MOD;}
}

int main() {
    int A,B,C,D;
    cin>>A>>B>>C>>D;
    if(A==C){
        cout<<modpower(A,D-B)<<endl;
        return 0;
    }
    if(B==D){
        cout<<modpower(B,C-A)<<endl;
        return 0;
    }
    vector<vector<vector<ll>>> dp(C+5,vector<vector<ll>>(D+5,vector<ll>(5)));
    dp[A][B][0]=1;
    for(int i=A+1;i<=C;i++){
        dp[i][B][0]=modpower(B,i-A);
    }
    for(int i=B+1;i<=D;i++){
        dp[A][i][1]=modpower(A,i-B);
    }
    for(int i=A;i<C;i++)for(int j=B;j<D;j++){
        dp[i+1][j+1][0]+=dp[i][j+1][0];
        dp[i+1][j+1][0]%=MOD;
        dp[i+1][j+1][0]+=dp[i][j+1][1];
        dp[i+1][j+1][0]%=MOD;
        dp[i+1][j+1][0]+=dp[i][j+1][2];
        dp[i+1][j+1][0]%=MOD;
        dp[i+1][j+1][0]+=dp[i][j+1][3];
        dp[i+1][j+1][0]%=MOD;
        dp[i+1][j+1][0]+=dp[i][j+1][4];
        dp[i+1][j+1][0]%=MOD;

        dp[i+1][j+1][1]+=dp[i+1][j][0];
        dp[i+1][j+1][1]%=MOD;
        dp[i+1][j+1][1]+=dp[i+1][j][1];
        dp[i+1][j+1][1]%=MOD;
        dp[i+1][j+1][1]+=dp[i+1][j][2];
        dp[i+1][j+1][1]%=MOD;
        dp[i+1][j+1][1]+=dp[i+1][j][3];
        dp[i+1][j+1][1]%=MOD;
        dp[i+1][j+1][1]+=dp[i+1][j][4];
        dp[i+1][j+1][1]%=MOD;

        dp[i+1][j+1][2]+=dp[i][j][0]*i*j;
        dp[i+1][j+1][2]%=MOD;
        dp[i+1][j+1][2]+=dp[i][j][1]*i*j;
        dp[i+1][j+1][2]%=MOD;
        dp[i+1][j+1][2]+=dp[i][j][2]*i*j;
        dp[i+1][j+1][2]%=MOD;
        dp[i+1][j+1][2]+=dp[i][j][3]*i*j;
        dp[i+1][j+1][2]%=MOD;
        dp[i+1][j+1][2]+=dp[i][j][4]*i*j;
        dp[i+1][j+1][2]%=MOD;

        dp[i+1][j+1][3]+=dp[i][j+1][0]*j;
        dp[i+1][j+1][3]%=MOD;
        dp[i+1][j+1][3]+=dp[i][j+1][3]*j;
        dp[i+1][j+1][3]%=MOD;

        dp[i+1][j+1][4]+=dp[i+1][j][1]*i;
        dp[i+1][j+1][4]%=MOD;
        dp[i+1][j+1][4]+=dp[i+1][j][4]*i;
        dp[i+1][j+1][4]%=MOD;
    }
    ll ans=0;
    rep(i,5){
        ans+=dp[C][D][i];
        ans%=MOD;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 638184
#include<bits/stdc++.h>
using namespace std;
#define llong long long
int n;
int po[1010][2];
bool check(int x){return (x%2+2)%2;}
int m;
llong w[55];
int sym;
int gx,gy;
void solve(llong x,llong y,int cur)
{
	if(cur>m)return;
	llong dx=abs(x-gx),dy=abs(y-gy);
//	cout<<"cur: "<<cur<<" x: "<<x<<" y: "<<y<<" dx: "<<dx<<" dy: "<<dy<<endl;
	if(dx>=dy)
	{
		if(gx>=x)
		{
			putchar('R');
			solve(x+w[cur],y,cur+1);
			return;
		}
		else
		{
			putchar('L');
			solve(x-w[cur],y,cur+1);
			return;
		}
	}
	else
	{
		if(y<=gy)
		{
			putchar('U');
			solve(x,y+w[cur],cur+1);
			return;
		}
		else
		{
			putchar('D');
			solve(x,y-w[cur],cur+1);
			return;
		}
	}
}
int main()
{
	scanf("%d",&n);
	int ma=0;
	for(int i=1;i<=n;++i)
	{
		scanf("%d%d",&po[i][0],&po[i][1]);
		if(check(po[i][0]+po[i][1])!=check(po[1][0]+po[1][1]))
			puts("-1"),exit(0);
		ma=max(ma,abs(po[i][0]+po[i][1]));
	}
	sym=check(po[1][0]+po[1][1]);
	m=1;
	w[m]=1;
	while((1ll<<(m-1))<ma) m++;
	for(int i=1;i<=m;++i)w[i]=(1ll<<(m-i));
	if(!sym)m++,w[m]=1;
	printf("%d\n",m);
	for(int i=1;i<=m;++i)printf("%lld ",w[i]);puts("");
	for(int i=1;i<=n;++i)
		gx=po[i][0],gy=po[i][1],solve(0,0,1),puts("");
	return 0;
}


Measured memory_bytes: 256
#include <cassert>
#include <iostream>
using namespace std;
const int M = 998244353;

int main() {
    int A, B, C, D; cin >> A >> B >> C >> D;
    long long dp[C+1][D+1];
    dp[A][B] = 1;
    for (int h = A+1; h <= C; h++) dp[h][B] = B * dp[h-1][B] % M;
    for (int w = B+1; w <= D; w++) dp[A][w] = A * dp[A][w-1] % M;
    for (int h = A + 1; h <= C; h++)
        for (int w = B + 1; w <= D; w++)
            dp[h][w] = (h * dp[h][w-1] + w * dp[h-1][w] - (h - 1) * (w - 1) * dp[h-1][w-1]) % M;

    cout << (dp[C][D] % M + M) % M << endl;
}


Measured memory_bytes: 73928
import java.util.Scanner;

public class Main
{

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

		int n = Integer.parseInt(sc.next());

		long[] value = new long[n];

		for (int i = 0; i < n; i++) {
			value[i] = Long.parseLong(sc.next());
		}

		boolean minuscount = false;
		long max = 0;

		for (int i = 0; i < n; i++) {
			if (value[i] < 0) minuscount = !minuscount;
		}

		for (int i = 0; i < n; i++) {
			max += Math.abs(value[i]);
		}

		if (minuscount) {
			long min = Math.abs(value[0]);

			for (int i = 0; i < n; i++) {
				if (min > Math.abs(value[i])) {
					min = Math.abs(value[i]);
				}
			}

			max -= min * 2L;
		}

		System.out.println(max);


		sc.close();
	}

}


Measured memory_bytes: 47900
import sys
input = lambda : sys.stdin.readline().rstrip()
mod = 10**9 + 7

s = input()

from collections import Counter

c = Counter(s)

A = c["a"]
B = c["b"]
C = c["c"]

if len(c.keys()) == 1:
    if len(s) > 1:
        print("NO")
    else:
        print("YES")
    sys.exit()

if len(c.keys()) == 2:
    if A + B + C == 2:
        print("YES")
    else:
        print("NO")
    sys.exit()

A -= min(c.values())
B -= min(c.values())
C -= min(c.values())

if A >= 2 or B >= 2 or C >= 2:
    print("NO")
else:
    print("YES")

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

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

    int N;
    cin >> N;

    vector<int> A(N, 0);
    int x;
    rep(i, N-1) {
        cin >> x;
        A[x-1]++;
    }

    rep(i, N) {
        cout << A[i] << endl;
    }
}

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

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

  string ans;

  rep(i, s.size()) {
    int a = (int)s[i] + (n%26);
    if(a > 90) {
      int b = a - 26;
      ans.push_back((char)b);
    } else {
      ans.push_back((char)a);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {

	var a, b int

	fmt.Scan(&a, &b)

	if 1 > a || 9 < a {
		fmt.Println(-1)
		return
	}
	if 1 > b || 9 < b {
		fmt.Println(-1)
		return
	}

	fmt.Println(a*b)

}


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

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)

using namespace std;
using ll = long long;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  	
  	ll w_i,v_i,n,w;
  	cin>>n>>w;

  	vector<ll> dp(w+1,0);
  	rep(i,n)
  	{
  		cin>>w_i>>v_i;
  		for(ll j = w,k=w-w_i;j>=w_i,k>=0;j--,k--)
  		{
  			dp[j] = max(dp[j],dp[k] + v_i);
  		}
  	}
  	ll max = -1;
	/*rep(i,w+1)
	{
		if(dp[i] > max)
				max = dp[i];
	} */	
	cout<<dp[w];
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod = 1e9+7;

void solve() {
	string s;
	cin>>s;
	int n = s.size();
	if(s[n-1] != 's') {
		s += 's';
	}
	else s += "es";
	cout<<s;
}

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 3640
#include<iostream> 
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
int a,b,c;
int main()
{
	a=read(),b=read(),c=read();
	cout<<b+min(c,a+b+1);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define maxn 510
using namespace std;
const double eps=1e-10;
int n; 
struct P{
    double x,y;
}a[maxn];
double dist(P p1,P p2)
{
    return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}
P o;
double r;
void cir(P p1,P p2,P p3)//求外接圆
{
    double a=2*(p2.x-p1.x),b=2*(p2.y-p1.y);
    double c=p2.x*p2.x+p2.y*p2.y-p1.x*p1.x-p1.y*p1.y;
    double d=2*(p3.x-p1.x),e=2*(p3.y-p1.y);
    double f=p3.x*p3.x+p3.y*p3.y-p1.x*p1.x-p1.y*p1.y;
    o.x=(b*f-e*c)/(b*d-e*a);
    o.y=(d*c-a*f)/(b*d-e*a);
    r=dist(o,p1);
}
int main()
{
    cin>>n;
        for(int i=1;i<=n;i++)   scanf("%lf%lf",&a[i].x,&a[i].y);
        o=a[1];
        r=0;
        for(int i=2;i<=n;i++)
        {
            if(dist(o,a[i])>r+eps)
            {
                o=a[i];r=0;
                for(int j=1;j<=i-1;j++)
                {
                    if(dist(o,a[j])>r+eps)
                    {
                        o.x=(a[i].x+a[j].x)/(double)2;
                        o.y=(a[i].y+a[j].y)/(double)2;
                        r=dist(o,a[i]);
                        for(int k=1;k<=j-1;k++)
                        {
                            if(dist(o,a[k])>r+eps)  cir(a[i],a[j],a[k]);
                        }
                    }
                }
            }
        }
        printf("%.7lf\n",r);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    ll a, b;
    cin >> a >> b;
    if (llabs(a-b) % 2 != 0) {
        cout << "IMPOSSIBLE" << endl;
    } else {
        cout << (a+b) / 2 << endl;
    }
    return 0;
}



Measured memory_bytes: 764
#include <iostream>
#include <algorithm>
using namespace std;
int n,m;
int x,y;
int r[100001],all[100001];
int ans;
int main(){
    cin>>n>>m;
    r[1]=1;
    for(int i=1;i<=n;i++)all[i]=1;
    for(int i=0;i<m;i++){
        cin>>x>>y;
        r[y]=max(r[x],r[y]);
        all[x]--; all[y]++;
        r[x]=min(r[x],all[x]);
    }
    for(int i=1;i<=n;i++)ans+=r[i];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
class RollingHash():
    def __init__(self, s):
        self.length = len(s)
        self.base1 = 1009
        self.base2 = 1007
        self.mod1 = 10**9 + 7
        self.mod2 = 10**9 + 9
        self.hash1 = [0] * (self.length + 1)
        self.hash2 = [0] * (self.length + 1)
        self.pow1 = [1] * (self.length + 1)
        self.pow2 = [1] * (self.length + 1)

        for i in range(self.length):
            self.hash1[i+1] = (self.hash1[i] + ord(s[i])) * self.base1 % self.mod1
            self.hash2[i+1] = (self.hash2[i] + ord(s[i])) * self.base2 % self.mod2
            self.pow1[i+1] = self.pow1[i] * self.base1 % self.mod1
            self.pow2[i+1] = self.pow2[i] * self.base2 % self.mod2
        
    def get(self, l, r):
        t1 = self.hash1[r] - self.hash1[l] * self.pow1[r-l] % self.mod1
        t1 = (t1 + self.mod1) % self.mod1
        t2 = self.hash2[r] - self.hash2[l] * self.pow2[r-l] % self.mod2
        t2 = (t2 + self.mod2) % self.mod2
        return (t1, t2)

class FastRollingHash():
    def __init__(self, s):
        self.length = len(s)
        self.base = 1009
        self.mod = (1 << 61) - 1
        self.hash = [0] * (self.length + 1)
        self.pow = [1] * (self.length + 1)

        for i in range(self.length):
            self.hash[i+1] = (self.hash[i] + ord(s[i])) * self.base % self.mod
            self.pow[i+1] = self.pow[i] * self.base % self.mod

    def get(self, l, r):
        t = self.hash[r] - self.hash[l] * self.pow[r-l] % self.mod
        t = (t + self.mod) % self.mod
        return t

n = int(input())
s = input()
RH = FastRollingHash(s)

def check(l):
    place = {}
    for i in range(n - l + 1):
        hs = RH.get(i, i + l)
        if hs in place:
            if i - place[hs] >= l:
                return True
        else:
            place[hs] = i
    return False

l = 0; r = n // 2 + 1
while r - l > 1:
    m = (l + r) // 2
    if check(m):
        l = m
    else:
        r = m

print(l)

Measured memory_bytes: 46428
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll,ll> P;

/*
*/

template<int MOD>
struct ModInt {
	static const int Mod = MOD;
	unsigned x;
	ModInt() : x(0) { }
	ModInt(signed sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	ModInt(signed long long sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	int get() const { return (int)x; }

	ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
	ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }

	ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
	ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
	ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
	ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }

	ModInt inverse() const {
		signed a = x, b = MOD, u = 1, v = 0;
		while (b) {
			signed t = a / b;
			a -= t * b; std::swap(a, b);
			u -= t * v; std::swap(u, v);
		}
		if (u < 0) u += Mod;
		ModInt res; res.x = (unsigned)u;
		return res;
	}
};
typedef ModInt<1000000007> mint;

ll n,k;
mint dp[100010],ru[100010],ans;
vector<P> a;

void init(){
	cin>>n>>k;
	for(ll i=1;i*i<=n;i++){
		a.push_back({i,0});
		a.push_back({n/i,0});
	}
	a.push_back({0,0});  // padding
	sort(a.begin(), a.end());
	a.erase(unique(a.begin(), a.end()), a.end());
	reg(i,1,a.size()-2) {
		int l = n/a[i+1].first;
		int r = n/a[i].first;
		a[i].second = r-l;
	}
	a.back().second = 1;
	// rep(i,a.size())cerr<<a[i].first<<" "<<a[i].second<<endl;
	dp[1]=1;
}

int main(void){
	init();
	rep(i,k){
		ru[0]=0;
		reg(i,1,a.size()-1)ru[i]=ru[i-1]+dp[i];
		reg(i,1,a.size()-1)dp[i]=ru[a.size()-i]*a[a.size()-i].second;
	}
	reg(i,1,a.size()-1)ans+=dp[i];
	cout<<ans.get()<<endl;
	return 0;
}

Measured memory_bytes: 2168
#include<bits/stdc++.h>
#include<string>
#define pii pair<int,int>
#define fr(j,n) for(int j=0;j<n;j++)
#define f(n) for(int i=0;i<n;i++)
#define rt return 0;
#define sc second
#define fi first
#define i(n) int n;cin>>n;
#define pb(i) push_back(i);
#define rt return 0;
#define sz(v) v.size()
#define allv v.begin(),v.end()
#define ff(i,in,fi) for(int i=in;i<fi;i++)
//#define df int n;cin>>n;int a[n];fr(n){cin>>a[i];}5 8 7 14 55 19 9 2
using namespace std;
#define trav(a, x) for(auto& a : x)
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl
#define invect(data,n,commands) for(int xxx = 0;xxx<n;xxx++){int tmp;cin>>tmp;data.pb(tmp);commands}
#define ll long long int
#define p(s) cout<<#s<<":"<<s<<'\n';
#define here(n) cout<<"here"<<n<<endl;
#define ios         ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

int main()
{
	ios;
	int a,b;
	cin>>a>>b;
	int sum=0,num=0;
	if(b==1)
	{
		cout<<0;
		rt;
	}
	while(sum<b)
	{
		if(sum+a>=b)
			{cout<<num+1;rt;}
		num++;
		sum+=a-1;
	}
	cout<<num;
}

Measured memory_bytes: 256
int main(int argc ,const char *argv[])
{
    int m,f,r;
    for(int i=0;i<50;i++){
        scanf("%d %d %d",&m,&f,&r);
        if(m==-1&&f==m&&r==m){
            break;
        }else if(m==-1||f==-1){
            putchar('F');
        }else if(m+f>=80){
            putchar('A');
        }else if(m+f>=65){
            putchar('B');
        }else if(m+f>=50){
            putchar('C');
        }else if(m+f>=30){
            if(r>=50){
                putchar('C');
            }else{
                putchar('D');
            }
        }else{
            putchar('F');
        }
        putchar('\n');
    }
    return 0;
}


Measured memory_bytes: 2064
#include <bits/stdc++.h>
using namespace std;
# define LL long long


int main(){
    int n,m,x_;
    scanf("%d%d%d",&n,&m,&x_);
    int g[n][m+1];
    for(int x=0;x<n;x++){
        for (int y=0;y<m+1;y++){
            scanf("%d",&g[x][y]);
        }
    }
    int cost=10000000,pres=0;
    
    int arr[m+1]={0};
    for (int i=1;i<(1<<n);i++){
        for(int x=0;x<n;x++){
            if ((i>>x)&1) {
                pres+=g[x][0];
                for (int y=1;y<m+1;y++){
                    arr[y]+=g[x][y];
                }
            }
        }
        int ans=1;
        for (int y=1;y<m+1;y++){
            ans=(ans & (arr[y]>=x_));
            arr[y]=0;
        }
        if (ans) cost=min(cost,pres);
        pres=0;
    }
    if (cost==10000000) printf("-1");
    else printf("%d",cost);
}

Measured memory_bytes: 3796
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

int main() {
    int N,M;
    cin >> N >> M;
    cout << (N * (N - 1)) / 2 + (M * (M - 1)) / 2 << endl;
}

Measured memory_bytes: 256
//
//  main.cpp
//  HW9
//
//  Created by xuechen on 2020/1/3.
//  Copyright © 2020 xuechen. All rights reserved.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;

int main(){
    int n;
    string s;
    cin >> n;
    cin >> s;
    int count = 0;
//    if(s) cout << "yes";
    while(s != "" && s.find("ABC") != string::npos){
        int idx = s.find("ABC") + 3;
        count ++;
        s = s.substr(idx);
      }
    
    cout << count << endl;
    
    
    return 0;
}


Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;

int dy[4] = {-1, 0, +1, 0};
int dx[4] = {0, +1, 0, -1};

const long long INF = 1LL << 60;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

int main(void){
	int n, k;
	cin >> n >> k;

	vector<int> h(n);

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

	ll dp[100100];
	for(int i = 0; i < 100100; i++){
		dp[i] = INF;
	}

	dp[0] = 0;

	for(int i = 0; i < n; i++){
		for(int j = 1; j <= k; j++){
			dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
		}
	}

	cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1408