akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

typedef long long ll;

int main() {
	int n, m, l; cin >> n >> m >> l;
	ll a[100][100];
	ll b[100][100];
	for (int y = 0; y < n; ++y) {
		for (int x = 0; x < m; ++x) {
			cin >> a[y][x];
		}
	}
	for (int y = 0; y < m; ++y) {
		for (int x = 0; x < l; ++x) {
			cin >> b[y][x];
		}
	}
	for (int y = 0; y < n; ++y) {
		for (int x = 0; x < l; ++x) {
			if (x) cout << " ";

			ll c = 0;
			for (int k = 0; k < m; ++k) {
				c += a[y][k] * b[k][x];
			}
			cout << c;
		}
		cout << endl;
	}
}



Measured memory_bytes: 3216
S=input()
K=int(input())

if list(S).count(S[0])==len(S):
    print(len(S)*K//2)

else:
    S_count=0
    i=0
    while i<len(S)-1:
        if S[i]==S[i+1]:
            S_count+=1
            i+=1
        i+=1

    if S[0]==S[-1]:
        a=1
        i=0
        while i<len(S)-1:
            if S[i]==S[i+1]:
                a+=1
                i+=1
            else:
                break
        b=1
        i=len(S)-1
        while i>0:
            if S[i]==S[i-1]:
                b+=1
                i+=-1
            else:
                break

        S_count*=K
        S_count-=(K-1)*(a//2 + b//2 - (a+b)//2)

    else:
        S_count*=K
    print(S_count)


Measured memory_bytes: 80432
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
typedef long long int ll;
ll N;
vector<ll>D;
ll ans;
ll M;
int main()
{
	scanf("%lld",&N);
	M=N;
	for(int i=2;i*i<=N;i++){
		if(N%i==0){
			for(int j=0;j<D.size();j++){
				if(i%D[j]==0)goto cc;
			}
			D.push_back(i);
		}
		cc:;
	}
	for(int i=0;i<D.size();i++){
		while(true){
			if(M%D[i]!=0)break;
			M/=D[i];
		}
	}
	
	if(M!=1)D.push_back(M);
	ans=N;
	for(int i=0;i<D.size();i++){
		ans*=(D[i]-1);
		ans/=D[i];
		//printf("%d\n",D[i]);
	}
	printf("%d\n",ans);
	return 0;
}

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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;

    // 処理
    // 出力
    cout << s1[0] << s2[1] << s3[2] << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9+7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,R,S,T,U,V,W,x,y,z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

template <std::int_fast64_t Modulus> class modint {
  using u64 = std::int_fast64_t;
public:
  u64 a;
  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};
typedef modint<MOD> m;
#pragma endregion

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

int main() {
  cin >> H >> N;
  int sum = 0;
  rep(i, N){
    cin >> A;
    sum += A;
  }
  if(sum < H) cout << "No";
  else cout << "Yes";
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>
using namespace std;
#define ll long long
#define MAX 15000

int main(){
  ll H, W;
  cin >> H >> W;
  vector<ll> row(W);
  vector<vector<ll>> M(H, row);

  
  vector<bool> dp2(MAX, false);
  vector<vector<bool>> dp1(W, dp2);
  vector<vector<vector<bool>>> dp(H, dp1);
  
  for(ll h=0; h<H; ++h) for(ll w=0; w<W; ++w) cin >> M[h][w];

  
  ll B;
  for(ll h=0; h<H; ++h) for(ll w=0; w<W; ++w) {
    cin >> B;
    M[h][w] = abs(M[h][w]-B);
  }

  /*
  for(ll h=0; h<H; ++h){
    for(ll w=0; w<W; ++w) cout << M[h][w] << " "; cout<<endl;
  }
  */

  dp[0][0][M[0][0]] = true;
  for(ll h=0; h<H; ++h) for(ll w=0; w<W; ++w) {
    vector<bool>& pn = dp[h][w];
    ll v = M[h][w];
      
    if(h>0){
      vector<bool>& pp = dp[h-1][w];
      for(ll i=0; i<MAX; ++i) if(pp[i]) pn[i+v] = pn[abs(i-v)] = true;
    }
    if(w>0){
      vector<bool>& pp = dp[h][w-1];
      for(ll i=0; i<MAX; ++i) if(pp[i]) pn[i+v] = pn[abs(i-v)] = true;
    }
  }

  ll ans=0;
  for(; !dp[H-1][W-1][ans]; ++ans);
    
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 14592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6+5;
const int INF = 0x3f3f3f3f;

int a[N];

int main()
{     
    string s;
    cin >> s;
    int len = s.size();
    memset(a,0,sizeof(a));
    
	for(int i = 1;i <= len;++i) a[i] = s[len-i]-'0';
    
	int ans = 0;
	for(int i = 1;a[i] || i <= len;++i){
    	a[i+1] += a[i]/10;
    	a[i] %= 10;
		
		if(a[i] < 5) ans += a[i];
    	else if(a[i] > 5) ans += 10-a[i],a[i+1]++;
    	else{
    		if(a[i+1] >= 5) ans += 5,a[i+1]++;
    		else if(a[i+1] < 5) ans += 5;
		}
	}
	printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 5252
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<cstdio>
#include<iomanip>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int INF = 1e9 + 7;
int main() {
	int N, K;
	cin >> N >> K;
	priority_queue<ll>kind[N];
	for (int i = 0; i < N; ++i) {
		int t;
		ll d;
		cin >> t >> d;
		kind[t - 1].push(d);
	}
	priority_queue<ll>best, remain;
	//best:各種類で一番おいしいやつを集めたもの
	//remain:bestの余り
	for (int i = 0; i < N; ++i) {
		if (!kind[i].empty()) {
			best.push(kind[i].top());
			kind[i].pop();
			while (!kind[i].empty()){
				remain.push(kind[i].top());
				kind[i].pop();
			}
		}
	}
	vector<ll>bsum = { 0 };
	//bestの累積和(bsum[i]=bestの先頭からi個の総和)
	while (!best.empty()) {
		bsum.push_back(bsum.back() + best.top());
		best.pop();
	}
	vector<ll>rsum = { 0 };
	//remainの累積和
	while (!remain.empty()) {
		rsum.push_back(rsum.back() + remain.top());
		remain.pop();
	}
	ll ans = 0;
	for (ll x = 1; x <= K; ++x) {
		//種類が多すぎるケース
		if (x >= bsum.size())break;
		//種類が少なすぎて余り物が足りないケース
		if (K - x >= rsum.size())continue;
		//bestからx個、remainからK-x個貪欲に選ぶ
		ans = max(ans, bsum[x] + rsum[K - x] + x * x);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8820
import heapq
import math
n,m = map(int,input().split())
lst = [int(x) * (-1) for x in input().split()]
heapq.heapify(lst)
for use_cnt in range(m):
    num = heapq.heappop(lst) * -1
    nxt_num = math.floor(num / 2)
    heapq.heappush(lst,nxt_num * -1)
print(sum(lst) * (-1))

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

#define int  long long
const int MOD = 1e9 + 7;
const int N = 1e5 + 11;
const int LOG = 25 + 1;
int dp[N][LOG];
int depth[N];
vector<int> g[N];

void dfs(int u, int v){
   dp[u][0] = v;
   for (int i = 1; i < LOG; i++)
     dp[u][i] = dp[dp[u][i - 1]][i - 1];
   for (auto it : g[u]){
	   if (it != v){
		  depth[it] = depth[u] + 1;
		  dfs(it, u);  
		 }  
	 }	
}

int lca(int u, int v){
   if (depth[v] < depth[u]) swap(u, v);
   int delta = depth[v] - depth[u];
   for (int i = 0; i < LOG; i++)
     if ((delta >> i) & 1)
       v = dp[v][i];
   if (u == v) return u;
   for (int i = LOG - 1; i >= 0; i--){
	  if (dp[u][i] != dp[v][i])
	     u = dp[u][i], v = dp[v][i];  
	 }
   return dp[u][0];	
}

void solve(){
   int n, q;
   cin >> n;
   for (int i = 0; i < n; i++){
	    int idx;
	    cin >> idx;
	    while (idx--){
		  int val;
		  cin >> val;
		  g[i].push_back(val);	
		  g[val].push_back(i);
	   } 
	}
	dfs(0, 0);
	cin >> q;
	for (int i = 0; i < q; i++){
	   int l, r;
	   cin >> l >> r;
	   int ret = lca(l, r);
	   cout << ret << endl;	
	}	
}

int32_t main(){
     ios_base::sync_with_stdio(false);
     cin.tie(nullptr);
     solve();	
}



Measured memory_bytes: 34376
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;


typedef tree<int,null_type,less<int>,rb_tree_tag,
		tree_order_statistics_node_update> indexed_set;
#define P pair<int,int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define st std::string 
#define pb push_back 
#define ll long long 
#define pq(x) std::priority_queue<x> 
#define ultapq(x) priority_queue<x,vector<x>,greater<x>> 
#define show_pq(x,n) for(int i = 0; i < n; i++){cout<<x.top(); x.pop();} 
#define itrt(yo) for(auto x:yo){std::cout<<x<<" ";} 
#define vec(x) std::vector<x> 
#define nl '\n' 
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define ALL(x) x.begin(),x.end() 
#define just int i= 0; i<n ; i++

const int MOD = 1e9+7;


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

int solve(){
    ll n; cin>>n;
    ll a[n];
    for (int i = 0; i < n; i++)
    {
        a[i] = abs( i-(n-i-1));
    }
    // for (int i = 0; i < n; i++)
    // {
    //     cout<<a[i]<<" "<<nl;
    // }
    ll b[n];
    for(just){
        cin>>b[i];
    }
    sort(a,a+n);
    sort(b,b+n);

    for (int i = 0; i < n; i++)
    {
        if (a[i]!=b[i])
        {
            cout<<0;
            return 0;
        }
    }

   
    
       
        
        
    
        ll ui = binpow(2,n/2);
        cout<<ui%MOD;
    
    return 0;
    
    
    
    
    
}

int main()
{
    IOS;
    int t=1;
    // cin>>t;

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

    

    
	

Measured memory_bytes: 1792
using System;
class ProgramD
    {
        static void Main(string[] args)
        {
            
            //入力
            string input = Console.ReadLine();
            int n = int.Parse(input);
            string[] input_a = Console.ReadLine().Split(' ');

            int[] a = new int[n];


            for(int i = 0; i<n;i++)
                a[i] = int.Parse(input_a[i]);
            
            //3桁があり得るかを見る準備
            int look = 1;

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

                if(look == a[i])
                    look++;  
                             
            }

            //答え出力
            if(look == 1)
                Console.WriteLine("-1");
            else
            {
                Console.WriteLine(n - look + 1);
            }
          
        }
    }

Measured memory_bytes: 33116
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>

int main(){
	int n=0,num[8]={0},max=0,min=0;
	int keep[8];
	int i,j,k,s,count;
	
	scanf("%d",&count);
	
	for(s=0;s<count;s++){
	
	scanf("%d",&n);
	for(i=0;i<8;i++){
		num[i]=n%10;
		n=n/10;
	}
	
	for(i=0;i<8;i++){
		for(j=0;j<8;j++){
			if(num[i]<num[j]){
				k=num[i];
				num[i]=num[j];
				num[j]=k;
			}
		}
	}
	for(i=0;i<8;i++)keep[i]=num[i];
	
	for(i=0;i<=7;i++){
		j++;
		for(j=6-i;j>=0;j--)keep[i]=(keep[i]*10);
		max+=keep[i];
	}
	
	for(i=0;i<8;i++){
		for(j=0;j<8;j++){
			if(num[i]>num[j]){
				k=num[i];
				num[i]=num[j];
				num[j]=k;
			}
		}
	}
	for(i=0;i<8;i++)keep[i]=num[i];
	
	for(i=0;i<=7;i++){
		j++;
		for(j=6-i;j>=0;j--)keep[i]=(keep[i]*10);
		min+=keep[i];
	}
	
	printf("%d\n",min-max);
	max=0;
	min=0;
	}
	
return 0;
}

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

const int maxn = 1e5 + 5;

int n;
vector<int> g[maxn];
int d[maxn], vis[maxn];

void dfs(int u, int par) {
	d[u] = par ? d[par] + 1 : 0;
	vis[u] = 1;
	for(int v : g[u]) if(!vis[v]) {
		dfs(v, u);
	}
}
int s, t;
vector<int> dia;
int get_dia(int u, int par) {
	if(u == t) {
		dia.emplace_back(u);
		return 1;
	}
	for(int v : g[u]) if(v - par) {
		if(get_dia(v, u)) {
			dia.emplace_back(u);
			return 1;
		}
	} return 0;
}

vector<int> solve() {
	vector<int> k;
	k.emplace_back(0);
	for(int i = 1; i < (int)dia.size() - 1; i++) {
		int u = dia[i];
		int cnt = 0;
		for(int v : g[u]) {
			if(v != dia[i - 1] and v != dia[i + 1]) {
				cnt++;
			}
		}
		k.emplace_back(cnt);
	}
	k.emplace_back(0);
	int c = 0;
	vector<int> ret(n);
	iota(ret.begin(), ret.end(), 1);
	for(int i : k) {
		if(i) {
			rotate(ret.begin() + c, ret.begin() + c + i, ret.begin() + c + i + 1);
		}
		c += i + 1;
	}
	return ret;
}

int main(int argc, char const *argv[])
{
	// freopen("in", "r", stdin);
	cin >> n;
	for(int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		g[u].emplace_back(v);
		g[v].emplace_back(u);
	}
	memset(vis, 0, sizeof vis);
	dfs(1, 0);
	s = 0, t = 0;
	for(int i = 1; i <= n; i++) {
		if(d[i] > d[s]) {
			s = i;
		}
	}
	memset(vis, 0, sizeof vis);
	dfs(s, 0);
	for(int i = 1; i <= n; i++) {
		if(d[i] > d[t]) {
			t = i;
		}
	}
	get_dia(s, 0);

	memset(vis, 0, sizeof vis);
	queue<int> Q;
	for(int u : dia) {
		vis[u] = 1;
		d[u] = 0;
		Q.emplace(u);
	}
	while(Q.size()) {
		int u = Q.front();
		Q.pop();
		for(int v : g[u]) if(!vis[v]) {
			vis[v] = 1;
			d[v] = d[u] + 1;
		}
	}
	for(int i = 1; i <= n; i++) {
		if(d[i] > 1) {
			cout << "-1" << endl;
			exit(0);
		}
	}
	vector<int> mn(n);
	iota(mn.begin(), mn.end(), 1);
	reverse(mn.begin(), mn.end());
	mn = min(mn, solve());
	reverse(dia.begin(), dia.end());
	mn = min(mn, solve());
	vector<int> p(n);
	for(int i = 0; i < n; i++) {
		p[mn[i] - 1] = i + 1;
	}
	for(int i : p) cout << i << ' '; cout << endl;
	return 0;
}

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

int main () {
    int n;
    cin >> n;
    if (n % 1000 == 0)
        cout << 0;
    else
        cout << (n / 1000 + 1) * 1000 - n;
}


Measured memory_bytes: 3632
/*
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
 |                                                                 |
 |   author : yash1399     Language : C ++                         | 
 |   college : MSIT                                                | 
 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |  
*/
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std;
# define ll  long long int 
# define TEST int t ; cin>>t; while(t--)
# define line cout<<endl;
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);
# define loop(i,a,b) for(long long int i=a;i<b;i++)
# define loopIn(i,a,b) for(long long int i=a;i<=b;i++)
#define MAX_SIZE 10000000
vector<bool> V(MAX_SIZE,false);
int main(){
      string s;
      cin>>s;
      ll l =s.size();
      ll ct=0;
      for(int i=0;i<l/2;i++){
          if(s[i]!=s[l-i-1]) ct++;
      }
      cout<<ct<<endl;
      
      return 0;
}

Measured memory_bytes: 1408
N = int(input())
S = str(input())
R = S[::-1]

ans = 0
for i in range(1000):
  z = str(i).zfill(3)
  right = -1
  left = -1
  if z[2] in R:
    r = R.index(z[2]) + 1
    right = N-r
  else:
    continue
  if z[0] in S:
    left = S.index(z[0]) + 1
  else:
    continue
  if z[1] in S[left:right]:
    ans += 1
print(ans)


Measured memory_bytes: 9248
N,A,B,C,D=map(int,input().split())
l,r=0,N
for i in range(N-1):
    a=A+i*C-(N-1-i)*D
    b=A+i*D-(N-1-i)*C
    if B>=a and B<=b:
        print("YES")
        exit()
print("NO")


Measured memory_bytes: 38768
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
char c[55][55];
int num[55][55];

int main()
{
	int H,W;
	cin >> H >> W;
	rep(i,H)
	{
		rep(j,W)
		{
			cin >> c[i][j];
		}
	}

	rep(i,H)
	{
		rep(j,W)
		{
			if (c[i][j] == '.')
			{
				int cnt = 0;
				for (int k = -1; k <= 1; ++k)
				{
					for (int l = -1; l <= 1; ++l)
					{
						if (k != 0 || l != 0)
						{
							if (i+k >= 0 && i+k < H && j+l >= 0 && j+l < W && c[i+k][j+l] == '#')
							{
								cnt++;
							}
						}
					}
				}
				num[i][j] = cnt;
			}
		}
	}

	rep(i,H)
	{
		rep(j,W)
		{
			if (c[i][j] == '.') cout << num[i][j];
			else cout << c[i][j];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define MAX 1000001
#define M 1000000007
#define ll long long
#define ld long double

#define left (2*i+1)
#define right (2*i+2)
#define mid ((l+r)>>1)

using namespace std;

int main() {
	ll x, y;
	cin >> x >> y;
	if (x%y==0) cout << -1;
	else cout << x;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lsb(x) (x & (-x)) 
    
using namespace std;

const int MAXN = 100;

char str[MAXN + 1];
   
int main() {
#if 0
    ifstream cin("A.in");
    ofstream cout("A.out");
#endif
    int i, n, k;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
	
	cin >> str + 1 >> k;
	n = strlen(str + 1);

	vector < pair <char, int> > arr;

	for(i = 1; i <= n; i++) {
		if(arr.empty() || str[i] != arr.back().first) {
			arr.push_back({str[i], 1});
		}
		else {
			arr.back().second++;	
		}
	}

	ll ans = 0;
	if(arr.size() == 1) {
		ans = 1LL * n * k / 2;
	}
	else if(arr[0].first == arr.back().first) {
		for(i = 1; i + 1 < arr.size(); i++) {
			ans += arr[i].second / 2;
		}
		ans = 1LL * ans * k;
		ans += 1LL * (arr[0].second + arr.back().second) / 2 * (k - 1);
		ans += arr.back().second / 2;
		ans += arr[0].second / 2;
	}
	else {
		for(auto it : arr) {
			ans += it.second / 2;
		}
		ans = 1LL * ans * k;
	}

	cout << ans;
		
	return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1000000000 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)
ll N, A, B;
vector<ll> h(100005);

bool check(ll num){
    ll a = 0;
    REP(i, N){
        ll b = h[i] - B*num;
        if(b>0){
            a += ((b+A-B-1)/(A-B));
        }
    }
    //cout << num << " " << a << " " << (a<=num) <<endl;
    return (a<=num);
}

ll binarySearch(ll start, ll end){
    if(start+1==end) return end;
    ll mid = (start+end)/2;
    if(check(mid)){
        return binarySearch(start, mid);
    }else{
        return binarySearch(mid, end);
    }
}

int main(){
    cin >> N >> A >> B;
    REP(i, N) cin >> h[i];
    cout << binarySearch(-1, 10000000005) << endl;
    return 0;
}

Measured memory_bytes: 1024
N = int(input())


# for i in range(1,N + 1):
#     # print("{}, {}, {}, {}".format(i, N // i, N % i, "OK" if N//i == N%i else ""))
#     if N//i == N%i:
#         print("{}, {}, {}".format(i, N // i, N % i))

def divisor_list(n):
    ret = set()
    i = 1
    while i * i <= n:
        if n % i == 0:
            ret.add(i)
            ret.add(n // i)
        i += 1
    return ret

ans = 0
L = divisor_list(N)
for l in L:
    oki = l-1
    if oki > 0 and N // oki == N % oki:
       ans += oki

print(ans)


Measured memory_bytes: 3828
#include <cstdio>
#include <cctype>

using namespace std;

int main() {
    char ch;
    while(1) {
        scanf("%c", &ch);
        if(isalpha(ch)){
            if( islower(ch) ) printf("%c",toupper(ch));
            else printf("%c",tolower(ch));
        } else{
            printf("%c",ch);
        }
        if( ch == '\n') break;
    }
    return 0;
}

Measured memory_bytes: 2684
// fuck ratings, i am in love with learning process

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define tez ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
int main()
{
	tez;
	ll n,x,t;
	cin>>n>>x>>t;
	if(n%x==0)
	{
		cout<<(n/x)*t<<"\n";
	}
	else
	{
		cout<<((n/x)+1)*t<<"\n";
	}
} 

Measured memory_bytes: 3648
X = int(input())
a = []

for i in range(1,32):
    for j in range(2,10):
        if i**j <= 1000:
            a.append(i**j)
a_uni = list(set(a))
b = sorted(a_uni)
    
max = 0
for i in b:
    if i <= X:
        max = i
print(max)

Measured memory_bytes: 3064
N, Y = map(int, input().split())
bflag = False
for i in range(N+1):
    for j in range(N+1):
        if i + j > N:
            break
        tmp = 10000 * i + 5000 * j + 1000 * (N-i-j)
        if tmp == Y:
            print(i, j, N-i-j)
            bflag = True
            break
    if bflag:
        break
if not bflag:
    print(-1, -1, -1)


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

using LL = long long;

#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); ++(i))
#define RFOR(i, a, b) for (int(i) = (a); (i) > (b); --(i))
#define SORT(x) sort(ALL((x)))
#define RSORT(x) sort(RALL((x)))
#define SZ(x) (int)(x).size()
#define debug(x) cerr << #x << " : " << x << '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const LL LINF = 1e18;

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

  string ans = "No";
  string S;
  cin >> S;

  if ((int)S.find("a") >= 0) {
    if ((int)S.find("b") >= 0) {
      if ((int)S.find("c") >= 0) {
        ans = "Yes";
      }
    }
  }

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
const int maxn = 1e6+7;
int n;
long long seed;
inline long long rand(long long l, long long r) {
    static long long mo=1e9+7, g=78125;
    return l+((seed*=g)%=mo)%(r-l+1);
}
long long Max[10];
long long Min[10];
int main()
{
    int t=1;
    //scanf("%d",&t);
    for(int cas=1;cas<=t;cas++)
    {
        cin >> n ;//>> seed;
        for(int i=0;i<10;i++)
            Max[i]=-1e15,Min[i]=1e15;
        long long x,y;
        for (int i = 0; i < n; i++)
        {
           cin>>x;// x = rand(-1000000000, 1000000000);
            cin>>y;//y = rand(-1000000000, 1000000000);
            Max[0]=max(Max[0],x+y);
            Max[1]=max(Max[1],-x+y);
            Max[2]=max(Max[2],x-y);
            Max[3]=max(Max[3],-x-y);
            Min[0]=min(Min[0],x+y);
            Min[1]=min(Min[1],-x+y);
            Min[2]=min(Min[2],x-y);
            Min[3]=min(Min[3],-x-y);
        }
        long long ans = 0;
        for(int i=0;i<4;i++)
            ans=max(Max[i]-Min[i],ans);
        cout<<ans<<endl;
    }
}


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

from bisect import bisect
cums = [0]
for a in A:
    cums.append(cums[-1] + a)
lmn = []
lmx = []
for i in range(2,N-1):
    j = bisect(cums, cums[i]//2)
    a1,b1 = cums[j],cums[i]-cums[j]
    a2,b2 = cums[j-1],cums[i]-cums[j-1]
    if abs(a1-b1) < abs(a2-b2):
        lmn.append(min(a1,b1))
        lmx.append(max(a1,b1))
    else:
        lmn.append(min(a2,b2))
        lmx.append(max(a2,b2))

A.reverse()
cums = [0]
for a in A:
    cums.append(cums[-1] + a)
rmn = []
rmx = []
for i in range(2,N-1):
    j = bisect(cums, cums[i]//2)
    a1,b1 = cums[j],cums[i]-cums[j]
    a2,b2 = cums[j-1],cums[i]-cums[j-1]
    if abs(a1-b1) < abs(a2-b2):
        rmn.append(min(a1,b1))
        rmx.append(max(a1,b1))
    else:
        rmn.append(min(a2,b2))
        rmx.append(max(a2,b2))
rmn.reverse()
rmx.reverse()

ans = 10**12
for ln,lx,rn,rx in zip(lmn,lmx,rmn,rmx):
    d = max(lx,rx) - min(ln,rn)
    ans = min(ans, d)
print(ans)

Measured memory_bytes: 42536
def solve():
    N,T = map(int, input().split())
    A = list(map(int, input().split()))
    max_profit = 0
    min_val = 10**9
    max_profit_pair = []
    
    for a in A:
        # print(min_val, max_profit)
        if max_profit < a-min_val:
            max_profit = a-min_val
            max_profit_pair = [(min_val,a)]
        elif max_profit == a-min_val:
            max_profit_pair.append((min_val,a))
            
        if min_val > a:
            min_val = a
            
    # print(max_profit, max_profit_pair)
    print(len(max_profit_pair))
    
solve()

Measured memory_bytes: 14244
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <string>
#include <bitset>
#include <tuple>
#include <cmath>
#include <map>

template<typename T> bool chmax( T &a, const T &b ) { if ( a <= b ) { a = b; return ( true ); } else { return ( false ); } }
template<typename T> bool chmin( T &a, const T &b ) { if ( a >= b ) { a = b; return ( true ); } else { return ( false ); } }

using namespace std;

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

using Pll  = pair<ll, ll>;
using Pull = pair<ull, ull>;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define F first
#define S second

#define rep( i, n ) for ( int i = 0; i < (int)( n ); ++i )
#define reps( i, n ) for ( int i = 1; i <= (int)( n ); ++i )
#define rrep( i, n ) for ( int i = (int)( ( n ) - 1 ); i >= 0; --i )
#define rreps( i, n ) for ( int i = (int)( ( n ) ); i > 0; --i )
#define arep( i, v ) for ( auto &&i : ( v ) )

template<typename T> T gcd( const T a, const T b ) { return ( b ? gcd( b, a % b ) : a ); }

#define ALL( c ) ( c ).begin(), ( c ).end()
#define RALL( c ) ( c ).rbegin(), ( c ).rend()
#define UNIQUE( c ) ( c ).erase( unique( ( c ).begin(), ( c ).end() ), ( c ).end() )

constexpr ll MOD = 1000000007LL;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

template<typename T = ll> class UnionFind {
public:
	UnionFind( T n ) { rep( i, n ) { par.resize( n ); siz.resize( n ); par[i] = i; siz[i] = 1; } }
	T find( T x ) { if ( x == par[x] ) return ( x ); else return( par[x] = find( par[x] ) ); }
	void unite( T x, T y ) { T xx = find( x ); T yy = find( y ); if ( xx == yy ) return;
		if ( siz[xx] <= siz[yy] ) swap( xx, yy ); par[yy] = xx; siz[xx] += siz[yy]; }
private:
	vector<T> par, siz;
};

template<typename T = ll> T power( T a, T b, T m = MOD ) {
	T res = 1;
	while ( b > 0 ) { if ( b & 1 ) res = res * a % m;
		a = a * a % m; b >>= 1; }
	return ( res );
}

/*
constexpr ll MAX = 500010;
ll fact[MAX];
ll inv[MAX];
ll inv_fact[MAX];

template<typename T> void initComb( T n, T m = MOD )
{
	fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1;
	inv[1] = 1;
	for ( int i = 2; i < n; i++ ) {
		fact[i] = ( fact[i - 1] * i ) % m;
		inv[i] = m - inv[m % i] * ( m / i ) % m;
		inv_fact[i] = inv_fact[i - 1] * inv[i] % m;
	}
}

template<typename T> T comb( T n, T r, T m = MOD )
{
	if ( n < r ) return ( 0 );
	if ( n < 0 || r < 0 ) return ( 0 );
	return ( fact[n] * ( inv_fact[r] * inv_fact[n - r] % m ) % m );
}
*/

void replace( string &s, string t, string r ) {
	string::size_type p = 0;
	while ( ( p = s.find( t, p ) ) != string::npos ) {
		s.replace( p, t.length(), r );
		p += r.length();
	}
}


int main()
{
	int A, B, C, D;
	cin >> A >> B >> C >> D;

	int e, f;
	e = min( A, B );
	f = min( C, D );

	cout << ( e + f ) << endl;

	return ( 0 );
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dp[100001];
long solve(vector<long>&height,int n,int start)
{
	if(start>=n)
	{
		return 0;
	}
	if(dp[start]!=-1)
	return dp[start];
	
	return dp[start]=min(abs(height[start+1]-height[start])+solve(height,n,start+1),abs(height[start+2]-height[start])+solve(height,n,start+2));
}
int main()
{
	memset(dp,-1,sizeof(dp));
	long n;
	cin>>n;
	vector<long> height(n+1);
	height[0]=0;
	for(long i=1;i<=n;i++)
	{
		cin>>height[i];
	 } 
	 int start=1;
	cout<<solve(height,n,start)<<endl;
		
}

Measured memory_bytes: 7424
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.conv;
import std.typecons;

void main() {
	(rs.uniq.array.length - 1).writeln;
}

// ===================================

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (isBasicType!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

int ri() {
	return readAs!int;
}

string rs() {
	return readln.chomp;
}

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

int main() {
  string w;
  cin >> w;
  int length = w.size();
  vector<int> cnt(26);
  for (int i = 0; i < length; i++) {
    cnt[w[i]-97]++;
  }
  bool can = true;
  for (int i = 0; i < 26; i++) {
    if (cnt[i] % 2 == 1) {
      can = false;
      break;
    }
  }
  if (can) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL)x=x->left;
  return x;

}

Node treeMaximum(Node x){
  while(x->right!=NIL)x=x->right;
  return x;


}

Node treeSearch(Node u, int k){
  while(u!=NIL&&k!=u->key){
    if(k<u->key)u=u->left;
    else u=u->right;
  }
  return u;
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right!=NIL)return treeMinimum(x->right);

  y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL||z->right==NIL)y=z;
  else y=treeSuccessor(z);

  if(y->left!=NIL)x=y->left;
  else x=y->right;

  if(x!=NIL)x->parent=y->parent;

  if(y->parent!=NIL)root=x;
  else if(y==y->parent->left)y->parent->left=x;
  else y->parent->right=x;

  if(y!=z)z->key=y->key;
  
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key)
      x=x->left;
    else x=x->right;
  }
  z->parent=y;

  if(y==NIL)
    root=z;
  else if(z->key<y->key)
    y->left=z;
  else
    y->right=z;
    
}

void inorder(Node u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



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

using namespace std;

#define db(x) cout << (x) << '\n';
#define all(x) x.begin(),x.end()
#define UNIQUE(x) sort(all(x)),x.resize(unique(all(x))-x.begin())
#define LB(v,x) lower_bound(all(v),x)
#define UB(v,x) upper_bound(all(v),x)
#define endl "\n"
#define F first
#define S second
#define PB push_back
#define PF push_front
#define int long long
#define double long double
#define trick int m = (l+r)>>1,lc=n<<1,rc=lc|1

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;

int dy[]={0,1,1,1,0,-1,-1,-1};
int dx[]={-1,-1,0,1,1,1,0,-1};
const int maxn = 1e5;
const int OO = 1e18;
const int mod = 1e9 + 7;
const double PI = acos(-1);

void maxself(int &a,int b)
{a=max(a,b);}
void minself(int &a,int b)
{a=min(a,b);}

vector<vi> g(maxn);


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

//	freopen("name.in","r",stdin);
//	freopen("name.out","w",stdout);

    int n,k;
    cin >> n >> k;
    vi v(n);
    for(int i=0;i<n;i++)
    cin >> v[i];

    sort(all(v));
    int sum =0 ;
    for(int i=0;i<k;i++)
        sum+=v[i];
    cout << sum;
	return 0;
}



Measured memory_bytes: 5416
from collections import Counter


def is_valid():
    if N % 2:
        return A.get(0, 0) == 1 and all(A.get(2 * i + 2, 0) == 2 for i in range(N // 2))
    else:
        return all(A.get(2 * i + 1, 0) == 2 for i in range(N // 2))


N = int(input())
A = Counter(map(int, input().split()))
MOD = 10 ** 9 + 7
print(pow(2, N // 2, MOD)) if is_valid() else print(0)


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

int main() {
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n);
    int b = a[0];

    for (int i = 1; i < n-1; i++ ) {
        if (abs(a[i] * 2 - a[n-1]) < abs(b * 2 - a[n-1])) {
            b = a[i];
        }
    }

    cout << a[n-1] << " " << b << endl;
    return 0;
}

Measured memory_bytes: 640
X, Y = map(int,input().split())

turu=X
kame=0
Flag=False
while turu>=0:
  total=4*turu+2*kame
  if total==Y:
    Flag=True
    break
  else:
    turu+=-1
    kame+=1
print("Yes" if Flag is True else "No")
  
  

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

#define pb push_back 
#define x first 
#define y second 
#define MOD 1000000007

using namespace std;
typedef long long ll;
typedef pair< int , int > PII;
const int dirx[] = {-2,-1,1,2, 1, -1};
const int diry[] = {0,1,1,0, -1, -1};
inline void debugMode() {
    #ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
    freopen("output.out", "w", stdout);
    #endif
}

int n, a[100100], b[100100], c[100100];

bool p(int x){
	for (int i = 2; i <= sqrt(x); i++)
		if (x % i == 0) return 0;
	return 1;
}

int main(){
	//	debugMode();
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 2; i <= 100005; i++){
		b[i] += b[i - 1];
		if ((i & 1) && p(i) && p((i + 1) / 2)) b[i]++;
	}
	for (int i = 1, x, y; i <= n; i++){
		cin >> x >> y;
		cout << b[y] - b[x - 1] << "\n";
	}
	return 0;
}


Measured memory_bytes: 1024
A,B,K=map(int,input().split())

if A>0:
    if A<=K:
        K=K-A
        A=0
    else:
        A=A-K
        K=0
if A<=0:
    if B>0 and B<=K:
        K=K-B
        B=0
    if B>0 and B>=K:
            B=B-K
            K=0
print(A,B)

Measured memory_bytes: 3060
#include <stdio.h>

int main(void)
{
  int n, ncopy;
  int sum = 0;
  
  scanf("%d", &n);
  ncopy = n;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  if (ncopy % sum == 0)
    printf("Yes");
  else
    printf("No");
  return 0;
}

Measured memory_bytes: 128
local n, k = io.read("*n", "*n")
local function modsub(a, b)
  if a < b then return a + k - b
  else return a - b
  end
end

local a = {}
for i = 1, n do
  a[i] = io.read("*n") % k
end
local sum = {a[1]}
for i = 2, n do
  sum[i] = (sum[i - 1] + a[i]) % k
end
for i = 1, n do
  sum[i] = modsub(sum[i], i % k)
end
local remlist, remlist_uniq = {0}, {}
remlist_uniq[0] = true
for i = 1, n do
  if not remlist_uniq[sum[i]] then
    remlist_uniq[sum[i]] = true
    table.insert(remlist, sum[i])
  end
end
local remlist_inv = {}
local remcnt = {}
for i = 1, #remlist do
  remlist_inv[remlist[i]] = i
  remcnt[i] = 0
end
remcnt[remlist_inv[0]] = 1
local ret = 0
for i = 1, n do
  if i == k then
    remcnt[remlist_inv[0]] = remcnt[remlist_inv[0]] - 1
  elseif k < i then
     remcnt[remlist_inv[sum[i - k]]] = remcnt[remlist_inv[sum[i - k]]] - 1
  end
  local reminv = remlist_inv[sum[i]]
  ret = ret + remcnt[reminv]
  remcnt[reminv] = remcnt[reminv] + 1
end
print(ret)


Measured memory_bytes: 24024
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}

using Graph = vector<vector<int>>;

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

  Graph G(N);
  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
  }

  int s, t; cin >> s >> t;
  s--; t--;

  VV dist(N, V(3, INF));
  queue<int> que;
  dist[s][0] = 0;
  que.push(s);
  while (!que.empty()) {
    int v = que.front(); que.pop();
    for (auto nv : G[v]) {
      bool updated = false;
      rep(j, 3) {
        if (chmin(dist[nv][(j+1)%3], dist[v][j] + 1)) {
          updated = true;
        }
      }
      if (updated) {
        que.push(nv);
      }
    }
  }

  if (dist[t][0] == INF) {
    cout << -1 << endl;
  }
  else {
    cout << (dist[t][0] / 3) << endl;
  }
  return 0;
}


Measured memory_bytes: 11136
N = int(input())
Alist = [int(x) for x in input().split()]
Alist.append(0)
full = 0
place = 0
for x in Alist:
    full += abs(max(place ,x) - min(place,x))
    place = x

place = 0
for i, j in zip(range(N+1),range(1,N+1)):
    if i > 0:
        place = Alist[i-1]
    through = Alist[i]
    nex = Alist[j]

    t = abs(max(place ,nex) - min(place,nex)) - (abs(max(place ,through) - min(place,through)) + abs(max(nex ,through) - min(nex,through)))
    print(full + t)

Measured memory_bytes: 14172
from collections import defaultdict
 
N, K, L = map(int, input().split())

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]
    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]
    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]
    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)
    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]

# 道路のUnionFind
uf1 = UnionFind(N)
for i in range(K):
    p, q = map(int, input().split())
    uf1.union(p - 1, q - 1)
 
# 鉄道のUnionFind
uf2 = UnionFind(N)
for i in range(L):
    r, s = map(int, input().split())
    uf2.union(r - 1, s - 1)
 
# 道路と鉄道の連結の組み合わせ（根のペアのカウント）
c = defaultdict(int)
for i in range(N):
    c[(uf1.find(i), uf2.find(i))] += 1

# 回答を出力
for i in range(N):
    print(c[(uf1.find(i), uf2.find(i))])

Measured memory_bytes: 59096
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <utility>
using namespace std;
using ll = long long int;
using pa = pair<int, int>;

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

	string A, B, C;
	cin >> A >> B >> C;

	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (A[i] == B[i]) {
			if (B[i] == C[i]) {
				continue;
			}
			else {
				ans++;
				continue;
			}
		}
		if (B[i] == C[i]) {
			ans++;
			continue;
		}
		if (A[i] == C[i]) {
			ans++;
			continue;
		}
		ans += 2;
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1234567;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-3;
int dx[4]={0,1,0,1};
int dy[4]={0,0,1,1};
int main(){
	int a,b,c;cin>>a>>b>>c;
	bool f=false;
	for(int i=a;i<=a*b*2;i+=a){
		if(i%b==c){
			f=true;
			break;
		}
	}
	if(f){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;

const int maxn=3e3+15; 
ll n,mod;
ll g[maxn][maxn],c[maxn][maxn];
ll mul(ll a,ll b,ll p)
{
    ll r=0;
    for (;b;b>>=1,a=(a+a)%p) if (b&1) r=(r+a)%p;
    return r;
}
ll qpow(ll a,ll b,ll p)
{
    ll r=1;
    for (;b;b>>=1,a=mul(a,a,p)) if (b&1) r=mul(r,a,p);
    return r;
}
int main()
{
    scanf("%lld%lld",&n,&mod);    
    for (int i=1;i<=n;i++)
    {
        c[i][0]=c[i][i]=1;
        for (int j=1;j<i;j++)
            c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
    }
    for (int i=0;i<=n;i++)
    {
        g[i][0]=1;
        for (int j=1;j<=i;j++)
            g[i][j]=(g[i-1][j-1]+g[i-1][j]*(j+1)%mod)%mod;    
    }
    ll ans=0;
    for (int i=0;i<=n;i++)
    {
        ll k=c[n][i];
        if (i&1) k=(mod-k)%mod;
        ll x=qpow(2,n-i,mod-1);
        x=qpow(2,x,mod);
        ll kind=qpow(2,n-i,mod);
        ll cnt=0,y=1;
        for (int j=0;j<=i;j++)
        {
            cnt=(cnt+(g[i][j]*y%mod))%mod;
            y=kind*y%mod;
        } 
        ans=(ans+(k*cnt%mod*x%mod))%mod;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 96240
INF = float('inf')
def bellman_ford(n, edges, s):
  min_dist = [INF] * n

  min_dist[s] = 0

  for i in range(n):
    for (start, end, cost) in edges:
      if min_dist[start] != INF and min_dist[start] + cost < min_dist[end]:
        min_dist[end] = min_dist[start] + cost
        if i == n-1 and end == n-1:
          return -INF
  
  return min_dist

N, M = map(int, input().split())

edges = []

for i in range(M):
  edge = list(map(int, input().split()))
  edge[0] -= 1
  edge[1] -= 1
  edge[2] = -edge[2]
  edges.append(edge)
min_dist = bellman_ford(N, edges, 0)

if min_dist == -INF:
  print('inf')
else:
  print(-min_dist[-1])

Measured memory_bytes: 44888
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;

typedef pair<int,pair<int,int>> triple;

triple make_triple(int a, int b, int c) {
  return make_pair(a, make_pair(b, c));
}

int main() {
  int n, m, a;
  while (cin >> n >> m >> a and n) {
    vector<triple> bars(m);
    REP(i, m) {
      int h, p, q;
      cin >> h >> p >> q;
      bars[i] = make_triple(-h, p - 1, q - 1);
    }
    
    sort(bars.begin(), bars.end());

    vector<int> candidates(n);
    REP(i, n) {
      candidates[i] = i + 1;
    }
    for (triple bar : bars) {
      pair<int,int> idxs = bar.second;
      swap(candidates[idxs.first], candidates[idxs.second]);
    }
    REP(i, n) {
      if (candidates[i] == a) {
        cout << i + 1 << endl;
        break;
      }
    }
  }
}

Measured memory_bytes: 1212
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
 
public class Main {
	InputStream is;
	PrintWriter out;
	String INPUT = "";
 
	void solve() 
	{
		int n = ni(), A = ni(), B = ni();
		out.println(Math.min(n * A,  B));
	}
 
	void run() throws Exception {
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);
 
		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if (!INPUT.isEmpty())
			tr(System.currentTimeMillis() - s + "ms");
	}
 
	public static void main(String[] args) throws Exception {
		new Main().run();
	}
 
	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;
 
	private int readByte() {
		if (lenbuf == -1)
			throw new InputMismatchException();
		if (ptrbuf >= lenbuf) {
			ptrbuf = 0;
			try {
				lenbuf = is.read(inbuf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (lenbuf <= 0)
				return -1;
		}
		return inbuf[ptrbuf++];
	}
 
	private boolean isSpaceChar(int c) {
		return !(c >= 33 && c <= 126);
	}
 
	private int skip() {
		int b;
		while ((b = readByte()) != -1 && isSpaceChar(b))
			;
		return b;
	}
 
	private double nd() {
		return Double.parseDouble(ns());
	}
 
	private float nf() {
		return Float.parseFloat(ns());
	}
 
	private char nc() {
		return (char) skip();
	}
 
	private String ns() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
 
	private char[] ns(int n) {
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while (p < n && !(isSpaceChar(b))) {
			buf[p++] = (char) b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}
 
	private char[][] nm(int n, int m) {
		char[][] map = new char[n][];
		for (int i = 0; i < n; i++)
			map[i] = ns(m);
		return map;
	}
 
	private int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
 
	private int ni() {
		int num = 0, b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}
 
		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
 
	private long nl() {
		long num = 0;
		int b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}
 
		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
 
	private static void tr(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
}

Measured memory_bytes: 21204
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

long[][] factor(long n) {
    if (n == 1) return [[1, 1]];
    long[][] res;
    if (n % 2 == 0) {
        int k = 0;
        while (n % 2 == 0) { n /= 2; k++; }
        res ~= [2, k];
    }
    for (long i = 3; i * i <= n; i += 2) {
        if (n % i != 0) continue;
        int k = 0;
        while (n % i == 0) { n /= i; k++; }
        res ~= [i, k];
    }
    if (n > 1) res ~= [n, 1];
    return res;
}

long calc(long a, long b) {
    long g = gcd(a, b);
    if (g == 1) return 1;
    return factor(g).length + 1;
}

void main() {
    long a, b; scan(a, b);
    writeln(calc(a, b));
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;


Measured memory_bytes: 256