akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
using namespace std;
const int N=2010;
struct node{int x,y;}e[N];
int n,k,ans,tot,cnt,head[N],v[N<<1],nxt[N<<1],deep[N];
inline void add(int x,int y){
    v[++tot]=y;
    nxt[tot]=head[x];
    head[x]=tot;
}inline void dfs(int x,int fx,int dep){
    deep[x]=dep;
    for(int i=head[x];i;i=nxt[i]){
        if(v[i]==fx)continue;
        dfs(v[i],x,dep+1);
}}int main(){
    scanf("%d%d",&n,&k),ans=1e9;
    for(int i=1;i<n;i++)
    	scanf("%d%d",&e[i].x,&e[i].y),add(e[i].x,e[i].y),add(e[i].y,e[i].x);
    if(k&1)
      	for(int i=1;i<n;i++){
        	cnt=0,dfs(e[i].x,e[i].y,0),dfs(e[i].y,e[i].x,0);
        	for(int j=1;j<=n;j++) if(deep[j]>(k-1)/2) cnt++;
        	if(cnt<ans) ans=cnt;} 
    else{
        for(int i=1;i<=n;i++){
	        cnt=0,dfs(i,0,0);
	      	for(int j=1;j<=n;j++) if(deep[j]>k/2) cnt++;
	      	if(cnt<ans) ans=cnt;}
    }printf("%d\n",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
 
#define INF (1<<31)//INT_MAX/2
#define MOD 1000000007
 
using ll  = long long;
using ull = unsigned long long;
 
int main(int argc, char *argv[])
{
    std::string s, t;
    std::cin >> s >> t;

    std::sort(s.begin(), s.end());
    //std::sort(t.rbegin(), t.rend());
    std::sort(t.begin(), t.end(), std::greater<int>());

    if (s < t) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No"  << std::endl;
    }

    return 0;
}

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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a < b + c)
        cout << b + c - a << endl;
    else
        cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 3572
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1e18
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define vec vector
using pint = pair<int,int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
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; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
const int mod = 1000000007;
struct mint {
    int64_t x;
    mint(int64_t x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {if ((x += a.x) >= mod) x -= mod;return *this;}
    mint& operator-=(const mint a) {if ((x += mod-a.x) >= mod) x -= mod;return *this;}
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(int64_t t) const {if (!t) return 1;mint a = pow(t>>1);a *= a;if (t&1) a *= *this;return a;}
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) {return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓


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

    ll n,x;
    cin>>n>>x;
    vll a(n);
    rep(i,n) cin>>a[i];
    rep(i,n) {a[i] = abs(x-a[i]);}
    ll ans = 0;
    rep(i,n){
        if(a[i] != 0)ans = __gcd(ans, a[i]);
    }

    cout<<ans<<endl;
    
}

Measured memory_bytes: 3952
N, K = list(map(int, input().split()))
table = [0]*N
max_W = 0
for i in range(N):
    table[i] = int(input())
    max_W = max(max_W, table[i])

left = max_W; right = 1000000000; mid = (left + right)//2;
ans = right

def is_ok(tmp_P):
    num_track = 1
    tmp_sum = 0
    for i in range(N):
        if tmp_sum + table[i] <= tmp_P:
            tmp_sum += table[i]
        else:
            num_track += 1
            tmp_sum = table[i]
            if num_track > K:
                return False
    return True

while left <= right:
    if is_ok(mid) == True:
        ans = mid
        right = mid - 1
    else:
        left = mid + 1
    mid = (left + right)//2;

print("%d"%(ans))


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

 using namespace std;

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

 #define M 2000

 bool ab[100000],ac[100000],bc[100000];

 bool match(char c1, char c2){
 return (c1 == '?' || c2 == '?' || c1 == c2);
 }

int main(void){
  
 int i,j;

 string a,b,c;
 cin >> a >> b >> c;

 int A = a.length();
 int B = b.length();
 int C = c.length();

 REP(i,A) REP(j,B) if(!match(a[i], b[j])) ab[i-j+50000] = true;
 REP(i,A) REP(j,C) if(!match(a[i], c[j])) ac[i-j+50000] = true;
 REP(i,B) REP(j,C) if(!match(b[i], c[j])) bc[i-j+50000] = true;

 int ans = 3 * M;
 for(i=-2*M;i<=2*M;i++) for(j=-2*M;j<=2*M;j++) if(!ab[i+50000] && !ac[j+50000] &&
!bc[j-i+50000]){
 int L = min(0, min(i, j));
 int R = max(A, max(B + i, C + j));
 ans = min(ans, R - L);
 }

 cout << ans << endl;

 return 0;
 }

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

using namespace std;

int main()
{
	int N,M;
	int *P,*Y;
	std::vector<int> *yd;
	cin >> N >> M;
	yd = new std::vector<int>[N];
	P = new int[M];
	Y = new int[M];

	for(int i=0;i<M;i++)
	{
		cin >> P[i] >> Y[i];
		yd[P[i]-1].push_back(Y[i]);
	}

	for(int i=0;i<N;i++)
	{
		sort(yd[i].begin(),yd[i].end());
	}

	for(int i=0;i<M;i++)
	{
		int index = P[i] - 1;
		int rank = int(lower_bound(yd[index].begin(),yd[index].end(),Y[i]) - yd[index].begin()) + 1;
		printf("%06d%06d\n",P[i],rank);
	}

	return 0;
}

Measured memory_bytes: 7808
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using Graph=vector<vector<int>>;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int mod=1000000007;
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}
int roundup(int a,int b){return	(a-1)/b+1;}
void YN(bool flg){cout<<(flg?"YES":"NO")<<endl;}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<endl;}
void yn(bool flg){cout<<(flg?"yes":"no")<<endl;}


signed main(){
	int n;cin>>n;
	vector<P> a(n);
	rep(i,n) cin>>a[i].first,a[i].second=i;
	sort(All(a));
	multiset<int> st={-1,-1,n,n};
	int ans=0;
	rep(i,n){
		int now=a[i].second,score=a[i].first;
		auto right=st.lower_bound(now),left=right;
		left--;
		int p=now-*left,q=*right-now;
		ans+=score*p*q;
		st.insert(now);
	}
	cout<<ans<<endl;
}


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

using namespace std;
    

int main(){
    int a, b, n, i;
    
    cin >> a >> b;
    
    n = 0;
    i = 1;
    
    if(b == 1){
    	cout << "0" << endl;
    }
    else if(a >= b){
        cout << "1" << endl;
    }
    else{
        while(n+a < b){
            n = n + a - 1;
            i++;
        }
            cout << i << endl;
    }
    

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define int long long
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
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;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1)*x%mod;
}

int mod_pow(int x, int y, int mood) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%mood;
		x = x * x%mood;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

int n, m;
vector<int> vec;
int cnt;
int ans = 1;

signed main() {
	cin >> n >> m;
	int k = m;
	for (int i = 2; i <= sqrt(m); i++) {
		cnt = 0;
		while (k % i == 0) {
			k /= i;
			cnt++;
		}
		if(cnt)vec.push_back(cnt);
	}
	if (k != 1)vec.push_back(1);
	for (int i = 0; i < (int)vec.size(); i++) {
		ans *= comb(vec[i] + n - 1, n - 1);
        ans %= mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
import fractions

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
  
a,b = list(map(int,input().split(" ")))
g = fractions.gcd(a,b)
if g == 1:
  print(1)
else:
  print(len(factorization(g)) + 1 )

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

int main()
{
  string str;

  while (cin >> str){
    for (int i = 0; i < str.size(); i++){
      if (str[i] == '@'){
        for (int j = 0; j < str[i + 1] - '0'; j++){
          cout << str[i + 2];
        }
        i += 2;
      }
      else {
        cout << str[i];
      }
    }
    cout << endl;
  }
}

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

int a[3];

int main() {
  	cin >> a[0] >> a[1] >> a[2];
  	sort(a, a + 3);
  	cout << ((a[0] == a[1]) ^ (a[1] == a[2])? "Yes": "No") << "\n";
}


Measured memory_bytes: 256
h, w = gets.split.map(&:to_i)
ch, cw = gets.split.map(&:to_i)
dh, dw = gets.split.map(&:to_i)

c = [?., ?#]
s = Array.new(h+3) {Array.new(w+3, c[1])}
h.times {|i| s[i+1][1,w+1] = gets.chars}

move = [[1,0], [-1,0], [0,1], [0,-1]]
warp = (-2..2).to_a.product((-2..2).to_a) - move - [[0,0]]

init = 1 << 20
d = Array.new(h+3) {Array.new(w+3, init)}
d[ch][cw] = 0
t = [[ch, cw]]

(0..).each do |k|
    break if t.empty? || d[dh][dw] < init
    u = []

    while (x,y = t.pop)
        next if d[x][y] < k

        move.each do |i,j|
            xx = x + i
            yy = y + j
            if s[xx][yy] == c[0] && d[xx][yy] > k
                d[xx][yy] = k
                t << [xx, yy]
            end
        end

        warp.each do |i,j|
            xx = x + i
            yy = y + j
            if s[xx][yy] == c[0] && d[xx][yy] > k + 1
                d[xx][yy] = k + 1
                u << [xx, yy]
            end
        end
    end

    t = u
end

p d[dh][dw] == init ? -1 : d[dh][dw]

Measured memory_bytes: 109616
n, m = map(int, input().split())
w = [1 for _ in range(n+1)]
for _ in range(m):
    w[int(input())] = 0
for i in range(2, n+1):
    if w[i] != 0:
        w[i] = w[i-2] + w[i-1]
#print(w)
print(w[-1] % 1000000007)

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

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

    pair<long long, long long> x[N];
    long long A, B;
    for (int i = 0; i < N; i++)
    {
        cin >> A >> B;
        x[i] = make_pair(A, B);
    }

    sort(x, x + N);
    long long ans = 0;
    long long idx = 0;
    while (M > 0)
    {
        if (x[idx].second < M)
        {
            ans += x[idx].first * x[idx].second;
            M -= x[idx].second;
        }
        else
        {
            ans += x[idx].first * M;
            M = 0;
        }
        idx++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using piii = pair<int, pair<int, int>>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;

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

    string S;
    cin >> S;

    ll cnt = 0, ans = 0;
    for (int i = 0; i < S.size(); ++i) {
        if (S[i] == 'W') {
            ans += i;
            ans -= cnt;
            cnt++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 720
//前置き
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>

using namespace std;

typedef  long long ll;

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))

#define PRINT(str) printf(#str "\n")
#define yOUT PRINT(Yes)
#define nOUT PRINT(No)
#define YOUT PRINT(YES)
#define NOUT PRINT(NO)

//関数定義
//最大公約数
ll gcd(ll a, ll b);

//最小公倍数
ll lcm(ll a, ll b);

int main(){
    // ========================================================
    int k, x;
    cin >> k >> x;
    if(500 * k >= x) yOUT;
    else nOUT;
}

//最大公約数
ll gcd(ll a, ll b) {  
    if (!b)  
        return a;  
    return gcd(b, a%b);  
}

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

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

int n, a;
bitset<1<<30> v;
int main()
{
	cin >> n;
	while(n--) {
		scanf ("%d", &a);
		v[a] = !v[a];
	}
	cout << v.count();
    return 0;
}


Measured memory_bytes: 123008
A=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
n=int(input())
s=str(input())
t=""
for i in range(len(s)):
  for j in range(26):
    if s[i]==A[j]:
      if j+n<=25:
        t+=A[j+n]
        break
      else:
        t+=A[j+n-26]
        break

print(t)

Measured memory_bytes: 9072
#include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i = 0 ; i < a; i ++)
#define loop(i,b,a) for(int i = b ; i < a; i ++)
const int MAX = (1e6);
bool p[MAX];
void isPrime(){
  fill(p,p + MAX,true);
  p[0] = p[1] = false;
  rep(i,MAX){
    if(p[i]){
      for(int j = i + i ; j < MAX ; j += i)
    p[j] = false;
    }
  }
} 
 
int main(void){
  isPrime();
  int n;
  while(cin>>n){
  int i = n-1;
  while(!p[i--]);
  cout<<++i<<' ';
  i = n + 1;
  while(!p[i++]);
  cout<<--i<<endl;
  }
  return 0;
}

Measured memory_bytes: 2136
#include<stdio.h>
int main(void)
{
	int a,b,c,e,f;
	scanf("%d",&a);
	int d[a];
	for(b=0; b<a; b++){
			d[b]=0;
		}
	for(b=0; b<a; b++){
			scanf("%d",&d[b]);
		}
		
	for(b=0; b<a; b++){
		c=d[b];
		e=b-1;
		while(e>=0 && d[e]>c){
			d[e+1]=d[e];
			e--;
			d[e+1]=c;
		}
		
		for(f=0; f<a; f++){
			printf("%d",d[f]);
			if(f==a-1){
				break;
			}
			printf(" ");
		}
		printf("\n");
	}

	return 0;
	
}




Measured memory_bytes: 2028
#include <stdio.h>
#include <math.h>
int n,m,a,b,x,i,j,path[5000][3],pot[100];
void connect(int from,int to){
	int i;
	for(i=0;i<m;i++){
		if(pot[i]==from){pot[i]=to;if(to==0)n--;}
	}
}
int main(void){
	while(scanf("%d",&n)!=EOF){
		if(n==0)break;
		for(i=0;i<n;i++)pot[i]=i+1;
		scanf("%d",&m);
		for(i=0;i<m;i++){
			scanf("%d,%d,%d",&a,&b,&x);
			for(j=i;j>0;j--){
				if(path[j-1][2]>x){
					path[j][2]=path[j-1][2];
					path[j][1]=path[j-1][1];
					path[j][0]=path[j-1][0];
				}else break;
			}
			path[j][2]=x;
			path[j][1]=b;
			path[j][0]=a;
		}
		x=0;m=n;
		for(i=0;n>0;i++){
			a=pot[path[i][0]];b=pot[path[i][1]];
			if(a!=b){
				if(x==0){pot[path[i][0]]=0;pot[path[i][1]]=0;n-=2;}
				else{if(a<b)connect(b,a); else connect(a,b);}
				x+=path[i][2]/100-1;
			}

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

Measured memory_bytes: 656
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m,K,P;
#define Maxn 105
int calc[Maxn][Maxn][Maxn][2],C[Maxn][Maxn],dp[Maxn][Maxn][Maxn][2];

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

int main(){
	scanf("%d%d%d%d",&n,&m,&K,&P);
	dp[1][0][0][0]=1;
	for(int i=0;i<=max(n,m);++i){
		C[i][0]=1;
		for(int j=1;j<=i;++j)C[i][j]=(C[i-1][j]+C[i-1][j-1])%P;
	}
	for(int i=1;i<=K;++i)
	   for(int j=0;j<=m;++j)
	       for(int k=0;k<=n;++k){
	       	    int tmp=(Fast_Pow(i,m-j)-Fast_Pow(i-1,m-j)+P)%P;
	       	    tmp=1ll*tmp*Fast_Pow(K-i+1,j)%P;
	       	    calc[i][j][k][0]=Fast_Pow(tmp,k);
		   } 
	for(int i=1;i<=K;++i)
	    for(int j=0;j<=n;++j)
	        for(int k=0;k<=m;++k){
	        	int tmp=(Fast_Pow(K-i+1,j)-Fast_Pow(K-i,j)+P)%P;
	        	tmp=1ll*tmp*Fast_Pow(i,n-j)%P;
				calc[i][j][k][1]=Fast_Pow(tmp,k); 
			}
	for(int t=1;t<=K;++t)
	   for(int i=0;i<=n;++i)
            for(int j=0;j<=m;++j){
            	int tmp=dp[t][i][j][0];
				for(int k=0;i+k<=n;++k)
				    dp[t][i+k][j][1]=(dp[t][i+k][j][1]+1ll*tmp*C[n-i][k]%P*calc[t][j][k][0])%P;
				tmp=dp[t][i][j][1];
				for(int k=0;k<=m-j;++k)
				    dp[t+1][i][j+k][0]=(dp[t+1][i][j+k][0]+1ll*tmp*C[m-j][k]%P*calc[t][i][k][1])%P; 
			}
	printf("%d\n",dp[K+1][n][m][0]);
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  REP(i,n) cin >> d[i];
  ll sum = 0;
  REP(i,n-1){
    for(int j = i + 1; j < n; j++){
      sum += d[i]*d[j];
    }
  }

  cout << sum << endl;
  return 0;

}



Measured memory_bytes: 3584
from heapq import heappush, heappop


def input(f):
    n, = map(int, f.readline().split())
    s = [None for _ in range(n-1)]
    t = [None for _ in range(n-1)]
    w = [None for _ in range(n-1)]
    for i in range(n-1):
        s[i], t[i], w[i] = map(int, f.readline().split())
    return n, s, t, w


def solve(n, s, t, w):
    graph = [[] for _ in range(n)]
    def add_edge(src, dst, w):
        graph[src].append((dst, w))
        graph[dst].append((src, w))
    for i in range(n-1):
        add_edge(s[i], t[i], w[i])
    
    queue = []
    def find(root):
        INF = 100000 * 1000 + 1;
        best = [INF for _ in range(n)]
        best[root] = 0
        while queue:
            _, cur_v = heappop(queue)
            for nxt_v, nxt_w in graph[cur_v]:
                dist = best[cur_v] + nxt_w
                if dist < best[nxt_v]:
                    best[nxt_v] = dist
                    heappush(queue, (dist, nxt_v))
                    
        res = (0, root)
        for i in range(n):
            if best[i] > res[0]:
                res = (best[i], i)
        return res
        
    heappush(queue, (0, 0))
    ret = find(0)
    heappush(queue, (0, ret[1]))
    res = find(ret[1])
    
    return res[0]

with open('/dev/stdin') as f:
    print(solve(*input(f)))


Measured memory_bytes: 47780
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

def cut(W,H,s):
    s %= (W+H)
    if 0 <= s <= W:
        return [s,H],[W-s,H]
    elif W <= s <= W+H:
        return [W,s-W],[W,H+W-s]

while True:
    N,W,H = inpl()
    if N == 0 and W== 0:
        break

    #         t ,  S , W , H
    cakes = [[INF,INF,INF,INF] for _ in range(N+5)]
    cakes[0] = [0,W*H,W,H]
    for t in range(N):
        p,s = inpl()
        tp,sp,wp,hp = cakes[p-1]
        c1,c2 = cut(wp,hp,s)
        cakes[p-1] = [INF,INF,INF,INF]
        cakes[N+4] = [t,c1[0]*c1[1],c1[0],c1[1]]
        cakes[N+3] = [t,c2[0]*c2[1],c2[0],c2[1]]
        cakes.sort()

    ans = []
    for t,s,w,h in cakes:
        if t == INF:
            break
        ans.append(s)
    ans.sort()
    print(' '.join(map(str,ans)))



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

using namespace std;

int main() {

	int n,m;
	cin >> n >> m;

	int l, r;
	int minr = 1000000, maxl = 0;
	for (int i = 0; i < m; i++) {
		cin >> l >> r;
		minr = min(r, minr);
		maxl = max(l, maxl);
	}

	if (minr >= maxl) {
		cout << minr - maxl + 1 << endl;
	}
	else {
		cout << "0" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
#include <memory>
using namespace std;
typedef long long LL;
//#define _USE_MATH_DEFINES

int main(void) {
	int d, n;
	cin >> d >> n;
	if (d == 0) {
		if (n == 100) {
			cout << 101 << endl;
		}
		else {
			cout << n << endl;
		}
	}
	else if (d == 1) {
		if (n == 100) {
			cout << 10100 << endl;
		}
		else {
			cout << n * 100 << endl;
		}
	}
	else if (d == 2) {
		if (n == 100) {
			cout << 1010000 << endl;
		}
		else {
			cout << 10000 * n << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
	{
	long long n ,a ,b ,sum=0 ;
	cin>>n>>a>>b ;
	sum+=a*(n/(a+b)) ;
	n%=(a+b) ;
	if(n>a)
		sum+=a ;
	else
		sum+=n ;
	cout<<sum<<endl ; 
	return 0 ;
	}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int MAX = 200100;
int BIT[MAX];
void add(int i, int n) {
  while (i < MAX) {
    BIT[i] += n;
    i += i & -i;
  }
}
int sum(int i) {
  int res = 0;
  while (i > 0) {
    res += BIT[i];
    i -= i & -i;
  }
  return res;
}
void clear() {
  for (int i = 1; i < MAX; i++)
    BIT[i] = 0;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int l = 0, r = 1e9;
  const ll all = (n+1)*n/2;
  while (r-l > 1) {
    int mid = (l+r)/2;
    vector<int> b(n), s(n+1);
    rep(i, n) b[i] = (a[i]<=mid ? 1 : -1);
    rep(i, n) s[i+1] = s[i]+b[i];
    rep(i, n+1) s[i] += n+1;
    add(s[0], 1);
    ll num = 0;
    for (int i = 1; i <= n; i++) {
      num += sum(s[i]-1);
      add(s[i], 1);
    }
    clear();
    if (num >= all/2+1)
      r = mid;
    else
      l = mid;
  }
  cout << r << endl;
  return 0;
}

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

using namespace std;

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

    int k;
    cin >> k;

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

    int quo1=a/k;
    int quo2=b/k;
    int rem=a%k;
    int c = 0;
    if(rem==0)
    {
        c=quo2-quo1+1;
    }
     else
     {
        c=quo2-quo1;
     }

    if (c>0) cout<<"OK";
    else cout<<"NG";
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    ll n;
    cin >> n;
    ll abc[n][3],tmp[n][3];
    rep(i,n){
        rep(j,3) cin >> abc[i][j];
    }
    tmp[0][0]=abc[0][0];
    tmp[0][1]=abc[0][1];
    tmp[0][2]=abc[0][2];
    for(ll i=1;i<n;i++){
        tmp[i][0]=max(abc[i][0]+tmp[i-1][1],abc[i][0]+tmp[i-1][2]);
        tmp[i][1]=max(abc[i][1]+tmp[i-1][0],abc[i][1]+tmp[i-1][2]);
        tmp[i][2]=max(abc[i][2]+tmp[i-1][0],abc[i][2]+tmp[i-1][1]);
    }
    cout << max({tmp[n-1][0],tmp[n-1][1],tmp[n-1][2]}) << endl;
    return 0;
}


Measured memory_bytes: 4992
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	string s;
	cin >> s;
	sort(s.begin(),s.end());
	cout << ((s[0]==s[1] && s[1]!=s[2] && s[2]==s[3])?"Yes":"No") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

signed main() {
  INIT;

	VAR(int, n, k);
	int ans = 1;
	REP(i, n) {
		ans = min(ans * 2, ans + k);
	}
	OUT(ans)BR;
  
  return 0;
}


Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"
#define SIZE 200009

using namespace std;
const long long MOD = (long long)1e9 + 7;

long long k;
int n, t, pos[SIZE], nxt[SIZE], pre[SIZE], a[SIZE], G, from[SIZE], m;
bool vis[SIZE];
stack<int> stk;
vector<int> ans;

void print()
{
	if (stk.empty()) return;
	int tmp = stk.top();
	stk.pop();
	print();
	cout << tmp << " ";
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> k;
	memset(pos, 0xff, sizeof(pos));
	memset(pre, 0xff, sizeof(pre));
	memset(nxt, 0xff, sizeof(nxt));
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (pos[a[i]] < 0) pos[a[i]] = i;
		if (pre[a[i]] >= 0) nxt[pre[a[i]]] = i;
		pre[a[i]] = i;
	}
	for (int i = n; i >= 0; i--) {
		if (nxt[i] < 0) from[i] = i;
		else from[i] = from[nxt[i] + 1];
	}
	for (int i = 0, PRE = n; i <= n; i++) {
		G = pos[a[PRE]] + 1;
		PRE = from[G];
		if (PRE == n) {
			t = i + 1;
			break;
		}
	}
	m = (k - 1) % t + 1;
	for (int i = 0, PRE = n; i < m; i++) {
		G = pos[a[PRE]] + 1;
		PRE = from[G];
	}
	for (int i = from[G]; i < n; i++) {
		if (!vis[a[i]]) {
			stk.push(a[i]);
			vis[a[i]] = true;
		}
		else {
			while (1) {
				int tmp = stk.top();
				stk.pop();
				vis[tmp] = false;
				if (a[i] == tmp) break;
			}
		}
	}
	print();
	//system("pause");
	return 0;
}

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

vector<int> v;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	string s; cin >> s;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == 'A') v.push_back(0);
		else if (i + 1 < s.length() && s[i] == 'B' && s[i + 1] == 'C') {
			v.push_back(1);
			i++;
		}
		else
			v.push_back(2);
	}
	long long ans = 0, c = 0;
	for (int i = 0; i < v.size(); i++) {
		if (v[i] == 2) c = 0;
		else if (v[i] == 0) c++;
		else ans += c;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 1680
object Main extends App {
	val Array(n, m) = scala.io.StdIn.readLine.split(" ").map(_.toInt)

	var ans = Set[Int]()

	for(i<-1 to m){
		ans += i
	}

	for(i<-0 until n){
		var sub = scala.io.StdIn.readLine.split(" ").map(_.toInt).tail.toSet
		ans &= sub
	}

	println(ans.size)

}

Measured memory_bytes: 26948
#include <bits/stdc++.h>
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
using namespace std;
vector<int> decToBinary(int n) 
{ 
    // array to store binary number 
    int binaryNum[32]; 
    vector<int>v(7,0);
    // counter for binary array 
    int i = 0; 
    while (n > 0) { 
  
        // storing remainder in binary array 
        binaryNum[i] = n % 2;
        v[i]=n%2;
        n = n / 2; 
        i++; 
    } 
   // reverse(v.begin(),v.end());
    return v;
} 
int main() {
    fast();
    // ll t;
    // cin>>t;
    // while(t--)			
    // {
        
    // }
    ll h,w,k;
    cin>>h>>w>>k;
    string s[h];
    for(int i=0;i<h;i++)
    cin>>s[i];
    ll cnt=0;
    for(int i=0;i<pow(2,h);i++)
    {
        vector<int>row=decToBinary(i);
        for(int j=0;j<pow(2,w);j++)
        {
            vector<int>col=decToBinary(j);
            //for(int t=0;t<col.size();t++)
            //cout<<col[t]<<" ";
            //cout<<endl;
            int temp=0;
            for(int n=0;n<h;n++)
            {
                for(int m=0;m<w;m++)
                {
                    if(row[n]==0&&col[m]==0&&s[n][m]=='#')
                    temp++;
                }
            }
            if(temp==k)
            {
                cnt++;
               // cout<<i<<" "<<j<<endl; 
            }
        }
    }
    cout<<cnt<<endl;
    
}


Measured memory_bytes: 4084
N, Y = map(int,input().split())
mi,fi,sa = 0,0,0
value = 0
num = 0
for m in range(Y//10000+1):
    for f in range((Y-m*10000)//5000+1):
        sa = (Y-m*10000-f*5000)//1000
        num = m+f+sa        
        if num == N:
            print(m,f,sa)
            exit()
print(-1,-1,-1)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include<cstdlib>
#include <cmath>
#include<stdio.h>
#include<stdlib.h>

using namespace std;
int main() {
    string s;
    cin >> s;
    int N=s.size();
    int s0[N];
    int  s1[N];
    int  s2[N];
    int c,d;
    int flag_1=0;
    int flag_2=0;
    
    
    for(int i=0;i<N;i++){
    	c=0;
    	d=0;
    	s0[i]=0;
    	
    	s0[i]=s[i] - '0';
    	//cout<<s0[i]<<endl;
    	
     	if(i%2==0){
     		s2[i]=0;
     		c=abs(s2[i]-s0[i]);
     		if(c==1){
     			flag_1 ++;
     		}
     		
     		s1[i]=1;
     		d=abs(s1[i]-s0[i]);
     		if(d==1){
     			flag_2 ++;
     		}	
     	}
     	else{
     		s2[i]=1;
     		c=abs(s2[i]-s0[i]);
     		if(c==1){
     			flag_1 ++;
     		}
     		
     		s1[i]=0;
     	    d=abs(s1[i]-s0[i]);
     		if(d==1){
     			flag_2 ++;
     	}
     }
     }
     
     if(flag_1>flag_2){
     	cout<<flag_2<<endl;
     }
     else if(flag_2>=flag_1){
     	cout<<flag_1<<endl;
     }
     
     return 0;
    }
    

Measured memory_bytes: 1664
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase

/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=998244353;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,i;cin>>n;
	vector<llint>a(n);
	for(i=0;i<n;i++){cin>>a[i];}
	SO(a);
	llint ans=a[0]%mod;
	for(i=1;i<n;i++){ans*=gcd(a[i],i);ans%=mod;}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long int
#define hell 1000000007LL
using namespace std;
ll power(ll x, ll y,ll z){ 
    if(y==0)
     return 1;
    else
    {
        ll p=power(x,y/2,z);
        ll w=(p*p)%z;
        if(y%2==0)
         return w;
        else
        return (x*w)%z;
    }}
ll gcd(ll x,ll y)
{
    if(y==0)
     return x;
    else
    return gcd(y,x%y);
}

 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    ll n;
    cin>>n;
    ll a[n],b[n];
    for(int i=0;i<n;i++)
    cin>>a[i]>>b[i];
    for(int i=0;i<=n-3;i++)
    {
        if(a[i]==b[i]&&a[i+1]==b[i+1]&&a[i+2]==b[i+2]){
        cout<<"Yes";
        exit(0);}
    }
    cout<<"No";}

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

int main() {
  int a, b;
  cin >> a >> b;
  if ((a * b * (a + b)) % 3 == 0) {
    cout << "Possible" << endl;
  }
  else {
    cout << "Impossible" << endl;
  }
}

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

using namespace std;

struct UnionFind {
    vector<int> par; 

    UnionFind(int N) : par(N) { 
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x); 
        int ry = root(y); 
        if (rx == ry) return; 
        par[rx] = ry; 
    }

    bool same(int x, int y) { 
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

    UnionFind tree(N);

    for(int i = 0; i < M; i++) {
        int  x, y;
        cin >> x >> y;
        tree.unite(x-1, y-1);
    }

    int cnt=0;
    for(int i=0;i<N;i++){
        if(!tree.same(0,i)){
            tree.unite(0, i);
            cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}

      

Measured memory_bytes: 3788
import sys
from collections import deque, Counter
sys.setrecursionlimit(1000000)
N, K, L = map(int, input().split())
pq = [list(map(int, input().split())) for _ in range(K)]
rs = [list(map(int, input().split())) for _ in range(L)]

G_r = [[] for _ in range(N+1)]
for elem in pq:
    G_r[elem[0]].append(elem[1])
    G_r[elem[1]].append(elem[0])
G_t = [[] for _ in range(N+1)]
for elem in rs:
    G_t[elem[0]].append(elem[1])
    G_t[elem[1]].append(elem[0])


field_r = [None]*(N+1)


def dfs_r(i, idx):
    q = deque()
    q.append(i)
    field_r[i] = idx
    while q:
        tmp = q.pop()
        for pos in G_r[tmp]:
            if field_r[pos] is None:
                field_r[pos] = idx
                q.append(pos)
            else:
                continue
idx = 0
for i in range(1, N+1):
    if field_r[i] is None:
        dfs_r(i, idx)
        idx += 1


field_t = [None]*(N+1)


def dfs_t(i, idx):
    q = deque()
    q.append(i)
    field_t[i] = idx
    while q:
        tmp = q.pop()
        for pos in G_t[tmp]:
            if field_t[pos] is None:
                field_t[pos] = idx
                q.append(pos)
            else:
                continue
idx = 0
for i in range(1, N+1):
    if field_t[i] is None:
        dfs_t(i, idx)
        idx += 1

m = list(zip(field_r[1:], field_t[1:]))
cnt = Counter(m)
ans = []
for elem in list(m):
    ans.append(cnt[elem])
print(' '.join(map(str, ans)))


Measured memory_bytes: 133648
#include"bits/stdc++.h"
using namespace std;
struct _ { ios_base::Init i; _() { cin.sync_with_stdio(0); cin.tie(0); } } _;

#define pii pair<int,int>
#define ff first
#define ss second
#define endll '\n'

using ll = long long int;

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

    ll sum=0;

    for(int i=1;i<=n;i++)
    {
        if(i%3==0 and i%5==0 and n%i==0) break;
        else if (i%3==0 or i%5==0) continue;
        else sum+=i;
    }

    cout<<sum;

}




Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int,int>;
using vi = std::vector<int>;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

vector<ll> prime(ll n){
    vector<ll> primes;
    vector<bool> p(n+1,true);
    p[0] = p[1] = false;
    for(ll i=2;i<=n;i++){
        if(!p[i]) continue;
        if(p[i]) primes.push_back(i);
        for(ll j=2;i*j<=n;j++) p[i*j]=false;
    }
    return primes;
}

int main(){
    auto primes = prime(55555);
    int n; cin >> n;
    vector<int> a;
    for(auto p : primes){
        if(p%5==2){
            a.emplace_back(p);
        }
    }
    rep(i,n){
        cout << a[i] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
int main(){
int N;
cin>>N;
vi a(N+1),b(N);
for(int &x:a)cin>>x;
for(int &x:b)cin>>x;
long long cnt=0;
for(int i=0;i<N;i++){
    if(a[i]<b[i]){
        cnt+=a[i];
        b[i]-=a[i];
        a[i]=0;
    if(b[i]>=a[i+1]){
           cnt+=a[i+1];
            a[i+1]=0;
    }
    else if(b[i]<a[i+1]){
            cnt+=b[i];
            a[i+1]-=b[i];
    }
    //cout<<"(1: "<<cnt<<" )"<<endl;
    }
    else if(a[i]==b[i]){
        cnt+=a[i];
        b[i]=0;
        a[i]=0;
    if(b[i]>=a[i+1]){
           cnt+=a[i+1];
            a[i+1]=0;
    }
    else if(b[i]<a[i+1]){
            cnt+=b[i];
            a[i+1]-=b[i];
    }
   // cout<<"(2: "<<cnt<<" )"<<endl;
    }
    else {
        cnt+=b[i];
        //cout<<"(3: "<<cnt<<" )"<<endl;

    }

}
cout<<fixed<<setprecision(0)<<cnt;
return 0;
}


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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] h = new int[n];
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}
		Arrays.parallelSort(h);
		int min = Integer.MAX_VALUE;
		for (int i = k-1; i < n; i++) {
			min = Math.min(min,h[i]-h[i-k+1]);
		}
		System.out.println(min);
		sc.close();
	}
}

Measured memory_bytes: 50536
INPUT = gets
tmp = INPUT.split(" ")
L = tmp[0].to_i
R = tmp[1].to_i

min = 2019
isBreak = false

for i in L..R-1
    for j in i+1..R
        result = (i*j).modulo(2019)
        min = result if result < min
        if min == 0
            isBreak = true
            break
        end
    end
    break if isBreak
end

print min

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

int main(void) {
	int num[3], ans = 0, max = 0, even = 0;
	scanf("%d %d %d", &num[0], &num[1], &num[2]);
	for (int i = 0; i < 3; i++) {
		if (num[i] % 2 == 0)even++;
	}
	if (even == 1) {
		for (int i = 0; i < 3; i++) {
			if (num[i] % 2 == 1)num[i]++;
		}
		ans++;
	}
	if (even == 2) {
		for (int i = 0; i < 3; i++) {
			if (num[i] % 2 == 0)num[i]++;
		}
		ans++;
	}
	for (int i = 0; i < 3; i++) {
		if (max < num[i])max = num[i];
	}
	for (int i = 0; i < 3; i++) {
		ans += (max - num[i]) / 2;
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 128
#!/usr/bin/env php
<?php
// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
const MOD = 2;

function genInputs() {
    while(($input = rtrim(fgets(STDIN))) !== false) {
        foreach (explode(' ', $input) as $v) {
            yield $v;
        }
    }
}
function getNext($gen) {
    $value = $gen->current();
    $gen->next();
    return $value;
}
$gen = genInputs();

$N = (int)getNext($gen);

function calc_mod_count($a) {
    static $mod_counts = [];
    if (isset($mod_counts[$a])) {
        return $mod_counts[$a];
    }
    if ($a % MOD !== 0) {
        $mod_counts[$a] = 0;
        return 0;
    }
    $ret = calc_mod_count($a / MOD) + 1;
    $mod_counts[$a] = $ret;
    return $ret;
}

for($i = 0; $i < $N; $i++) {
    $a = getNext($gen);
    $origin_counts[$i] = calc_mod_count($a);
}
echo min($origin_counts).PHP_EOL;


Measured memory_bytes: 4732
#include <iostream>
using namespace std;
 
int main() {
    int n;
    cin >> n;
    int a[n];
    for (int i=0;i<n;i++) {
        cin >> a[n-i-1];
    }
    for (int i=0;i<n;i++) {
        if (i>0) {
            cout << " ";
        }
        cout << a[i];
    }
    cout << endl;
    return 0;
}




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

typedef long long ll;
int n;
ll a[60];
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;++i)cin>>a[i];
	for(sort(a+1,a+n+1);a[n]>=n;sort(a+1,a+n+1)){for(int i=0;i<n;++i)a[i]+=a[n]/n;a[n]%=n;}
	cout<<a[0]<<'\n';
	return 0;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, A, B = MAP()
h = [INT() for _ in range(N)]

ng = 0
ok = ceil(max(h)/B)

def is_ok(x):
    h_copy = h[:]
    for i in range(N):
        h_copy[i] -= B*x
    cnt = 0
    for i in range(N):
        cnt += max(0, ceil(h_copy[i]/(A-B)))
    return cnt <= x


while ng+1 != ok:
    m = (ok+ng)//2
    if is_ok(m):
        ok = m
    else:
        ng = m
print(ok)


Measured memory_bytes: 13128
/*---------------------------------

 @Author:   Dicer
 @DateTime: 2019-05-15 19:53:54

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
inline ll qpow(ll a,ll b,ll mod){ll res=1;while(b){if(b&1)res = (res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int MAXN = 2e5 + 7;

int a[233];
int main(int argc, char const *argv[])
{
	int n, m, c;
	cin >> m >> n >> c;
	for(int i = 1; i <= n; ++i)	cin >> a[i];
	int cnt = 0;
	for(int i = 1; i <= m; ++i){
		int res = c, x;
		for(int j = 1; j <= n; ++j){
			cin >> x;
			res += a[j]*x;
		}
		// cout << res << endl;
		if(res > 0)	cnt++;
	}
	cout << cnt << endl;
	return 0;
}

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

bool is_palin(string s){
    string t(s.rbegin(),s.rend());
    return s == t;
}

int main(){
    string s;
    cin >> s;
    int n = s.size();
    if (is_palin(s) && is_palin(s.substr(0,(n-1)/2)) && is_palin(s.substr((n+1)/2))) cout << "Yes" <<endl;
    else cout << "No" << endl;
    return 0;
}

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

const int MAX_N = 402;
int N;
int a[MAX_N];
ll dp[MAX_N][MAX_N];
ll psum[MAX_N];

ll go(int le, int ri)
{
	if(le > ri) return 0;
	if(le == ri) return a[le];
	ll& res = dp[le][ri];
	if(res != -1) return res;
	res = 1e15;
	for(int k=le+1;k<=ri;++k){
		res = min(res, go(le,k-1)+go(k,ri));
	}
	res += psum[ri+1]-psum[le];
	return res;
}

void solve()
{
	psum[0]=0;
	for(int i=1;i<=N;++i) psum[i]=psum[i-1]+a[i-1];
	memset(dp, -1, sizeof(dp));
	ll ans = go(0, N-1);
	cout << ans-psum[N] << '\n';
}

int main()
{
	cin >> N;
	for(int i=0;i<N;++i) cin >> a[i];
	solve();
	return 0;
}

Measured memory_bytes: 1536