akhauriyash/Code-Regression huggingface dataset:
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)

    def find(self, 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 = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same_check(self, x, y):
        return self.find(x) == self.find(y)

n,m = (int(i) for i in input().split())
a = []
for i in range(m):
 tmp = list(int(i) for i in input().split())
 a.append(tmp)
ct = 0
for i in range(m):
  uf = UnionFind(n)
  for j in range(m):
    if i == j:
      nanban = j
    else:
      tmp1= a[j][0]
      tmp2= a[j][1]
      uf.union(tmp1,tmp2)
  c = a[nanban][0]
  d = a[nanban][1]
  if not uf.same_check(c,d):
   ct +=1
print(ct)



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

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

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int r, d;
    ll x;
    cin >> r >> d >> x;
    rep(i, 10) {
        x = r * x - d;
        cout << x << endl;
    }
    return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

sum=0
t=-999
for a1 in a:
    i=a1-1
    sum+=b[i]
    if t==i-1:
        sum+=c[i-1]
    t=i
print(sum)


Measured memory_bytes: 3060
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

h, w = na()
g = []
for i in range(10):
    g.append(na())

for k in range(10):
    for i in range(10):
        for j in range(10):
            g[i][j] = min(g[i][j], g[i][k] + g[k][j])

ret = 0
for i in range(h):
    row = na()
    for v in row:
       if v >= 0:
           ret += g[v][1]
print(ret)

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

#define ll long long
#define ld long double
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)

#define xx first
#define yy second
#define mp make_pair
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define pdd pair<double,double>
#define ALL(v) (v).begin(), (v).end()

const ll MOD=1e9+7; ;
const ll inf=1e10;

#define MODSET(d) if ((d) >= MOD) d %= MOD;
#define MODNEGSET(d) if ((d) < 0) d = ((d % MOD) + MOD) % MOD;
#define put(x) cout<<#x<<" = "<<x<<endl;

ll power(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a);
        n>>=1;
        a=(a*a);
    }
    return ans;
}


ll powerMod(ll a,ll n){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%MOD;
        n/=2;
        a=(a*a)%MOD;
    }
    return ans;
}

ll powerMod1(ll a,ll n,ll mod){
    ll ans=1;
    while(n){
        if(n&1)
            ans=(ans*a)%mod;
        n>>=1;
        a=(a*a)%mod;
    }
    return ans;
}

ll lcm(ll a,ll b){
    return a*(b/__gcd(a,b));
}

ll sumdigit(ll n){
    ll sum=0;
    while(n){
        sum+=n%10;
        n=n/10;
    }
    return sum;
}

ll countSetBit(ll a){
    return __builtin_popcount(a);
}
ll countBit(ll a){
    ll sum=0;
    while(a){
        sum++;
        a>>=1;
    }
    return sum;
}

ll length(ll a){
    ll ans=0;
    while(a){
        ans++;
        a=a/10;
    }
    return ans;
}

bool isVowel(char c){
	if(c=='a' or c=='e' or c=='i' or c=='o' or c=='u')
		return true;
	return false;
}


int main()
{
    fast;
    ll t;
    
    //~ cin>>t;
    t=1;
    while(t--){
			ll a,b;
			cin>>a>>b;
			cout<<lcm(a,b);
			
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 500 + 10;

int n, k;
std::vector<int> factors;
vector<int> a;

void factorize(int n){
   for (int i = 1; i*i <= n; ++i)
   {
      if(n%i)continue;
      factors.pb(i);
      if(i != n/i){
         factors.pb(n/i);
      }
   }
   sort(factors.rbegin(), factors.rend());
}


int32_t main(){_

   cin>>n>>k;
   a.resize(n);
   int sum = 0;
   for (int i = 0; i < n; ++i)
   {
      cin>>a[i];
      sum += a[i];
   }

   factorize(sum);

   int ans = 1;
   for (int tt = 0; tt <= sz(factors)-1; ++tt)
   {
      int num = factors[tt];
      vector<int> b = a;
      int sum0 = 0;
      for (int j = 0; j < n; ++j)
      {
         b[j] %= num;
         sum0 += b[j];
      }

      sort(b.begin(), b.end());
      int ops = 0;

      multiset<int> ms;
      for (int i = 0; i < n; ++i)
      {
         ms.insert(b[i]);
      }

      while(sz(ms)){
         int least = *ms.begin();
         ms.erase(ms.begin());
         if (sz(ms) == 0){
            assert(least == 0);
            break;
         }
         auto it = --ms.end();
         int maxx = *it;
         ms.erase(it);
         int mi = min(least, num - maxx);
         ops += mi;
         least -= mi;
         maxx += mi;
         least %= num;
         maxx %= num;
         if (least > 0){
            ms.insert(least);
         }
         if (maxx > 0){
            ms.insert(maxx);
         }
      }

      if(ops <= k){
         cout<<num;
         exit(0);
      }
   }

   return 0;
}


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

#include<cstdio>
#define r(i,n) for(int i=0;i<n;i++)
#define N 110

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

  vector<vector<char> > a(N, vector<char>(N));
  vector<vector<int> > s(N, vector<int>(N,0));

  r(i,n){
    r(j,m){
      cin>>a.at(i).at(j);
    }
  }



  r(i,n){
    bool flag=1;
    r(j,m){
      if(a.at(i).at(j)=='#')flag=0;
    }
    if(flag){
        r(j,m){
          s.at(i).at(j)=1;
        }
    }
  }


  r(j,m){
    bool flag=1;
    r(i,n){
      if(a.at(i).at(j)=='#')flag=0;
    }
      if(flag){
          r(i,n){
            s.at(i).at(j)=1;
          }
      }
  }

  r(i,n){
    r(j,m){
      if(s.at(i).at(j)==0)cout<<a.at(i).at(j);
    }
    cout<<endl;
  }

return 0;}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using Pair = pair<int, int>;
using Vec = vector<int>;
using Graph = vector<Vec>;

#define SEP " "

int		main(void)
{
	int n;
	cin >> n;
	Vec a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	Vec b(n);
	int lb = -1;
	int ub = min(a[0], a[n-1])+1;
	while (ub - lb > 1)
	{
		b[0] = (lb + ub) / 2;
		for (int i = 1; i < n; i++)
			b[i] = a[i - 1] - b[i - 1];
		if (b[0] + b[n-1] < a[n-1])
			lb = b[0];
		else if (b[0] + b[n-1] <= a[n-1])
			lb = b[0];
		else
			ub = b[0];
	}
	b[0] = lb;
	cout << b[0] * 2;
	for (int i = 1; i < n; i++)
		cout << SEP <<  (b[i] = a[i-1] - b[i-1]) * 2;
	cout << endl;
}



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

int n;
int x[24], y[24], r[24], c[24];

int dist(int x, int y) {
	return x * x + y * y;
}

char dp[1 << 24];

int dfs(int S) {
	if (dp[S] != -1) return dp[S];
	vector<int> ng(n);
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if ((S & (1 << i)) || (S & (1 << j))) continue;
			if (dist(x[i] - x[j], y[i] - y[j]) < (r[i] + r[j]) * (r[i] + r[j])) {
				ng[j] = 1;
			}
		}
	}
	int res = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if ((S & (1 << i)) == 0 && (S & (1 << j)) == 0 && !ng[i] && !ng[j] && c[i] == c[j]) {
				res = max(res, 2 + dfs(S | (1 << i) | (1 << j)));
			}
		}
	}
	return dp[S] = res;
}

int main()
{
	while (cin >> n, n) {
		fill(dp, dp + (1 << 24), -1);
		for (int i = 0; i < n; i++) {
			cin >> x[i] >> y[i] >> r[i] >> c[i];
		}
		cout << dfs(0) << endl;
	}
	return 0;
}

Measured memory_bytes: 19396
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i=0;i<n;i++) {
			a[i] = sc.nextInt();
		}
		
		int i=0;
		int j=0;
		int tmp = 0;
		
		long ans = 0;
		
		 while (i<=n-1) {
			if ((tmp & a[i]) == 0) {
				ans += (i-j+1);
				tmp |= a[i];
				i++;
			} else {
				tmp &= (~a[j]);
				j++;
			}
		}
		 
		 System.out.println(ans);

	}

}


Measured memory_bytes: 82324
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int INF = 1 << 20;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main()
{
    while(true){
        int n; cin >> n;
        if(n == 0){
            break;
        }
        vector<int> a(n);
        for(int i = 0; i < n; i++){
            cin >> a[i];
        }
        sort(a.begin(),a.end());
        int sum = 0;
        for(int i = 1; i < n-1; i++){
            sum += a[i];
        }
        cout << sum / (n-2) << endl;
    }
}



Measured memory_bytes: 3152
s = input()
n = len(s)
ss = s[:(n - 1) // 2]
sss = s[(n + 3) // 2 - 1:]
flag = True;
for i in range(len(s)//2):
    if s[i] != s[n - 1 - i]:
        flag = False
if not flag:
    print("No")
    exit()

for i in range(len(ss)//2):
    if ss[i] != ss[len(ss) - 1 - i]:
        flag = False
if not flag:
    print("No")
    exit()

for i in range(len(sss)//2):
    if sss[i] != sss[len(sss) - 1 - i]:
        flag = False
if not flag:
    print("No")
    exit()
print("Yes")


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {
  int H, W, h, w;
  cin >> H >> W >> h >> w;
  cout << (H-h)*(W-w) << endl;
  return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll q;
ll l[100005],r[100005];
ll a[100005],b[100005];
ll prime[100005];
bool is_prime[100005];
ll seive(ll n){
	ll p=0;
	for(int i=0;i<=n;i++){
		is_prime[i]=true;
	}
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<=n;i++){
		if(is_prime[i]){
			prime[p++]=i;
			for(int j=2*i;j<=n;j+=i){
				is_prime[j]=false;
			}
		}
	}
	return p;
}
int main(void){
	cin>>q;
	for(int i=0;i<q;i++){
		cin>>l[i]>>r[i];
	}
	ll k=100003;
	ll t=seive(k);
	for(int i=1;i<100002;i++){
		if(is_prime[i]&&is_prime[(i+1)/2]){
			a[i]=1;
		}
		b[i]=b[i-1]+a[i];
	}
	for(int i=0;i<q;i++){
		cout<<b[r[i]]-b[l[i]-1]<<endl;
	}
	
}


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

const double pi  = 2 * acos(0.0);
const double eps = 1e-8;

#define REP(i,a,b) for(int i=(a); i<(b);++i)
#define rep(i,n) REP(i,0,n)
#define INF (1<<29)
#define INFLL (1LL<<61)

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

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

int main(void) {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int N;
  while (cin >> N, N) {
    vector<pii> data(N);
    for (int i = 0; i < N; i++)
      cin >> data[i].second >> data[i].first;

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

    ll s = 0;
    bool ok = true;
    for (int i = 0; i < data.size(); i++) {
      s += data[i].second;
      if (s > data[i].first) {
        ok = false;
        break;
      }
    }

    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0; 
}

Measured memory_bytes: 3092
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
signed main(){
  ll n,m;
  cin >> n >> m;
  vector<pll> a(n);
  REP(i,n) cin >> a[i].first >> a[i].second;
  sort(ALL(a));
  ll ans = 0;
  ll buy = 0;
  REP(i,n){
    if(buy+a[i].second>=m){
      ans += (m-buy)*a[i].first;
      break;
    }
    ans += a[i].first*a[i].second;
    buy += a[i].second;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdio>

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

using namespace std;

typedef vector<int> vi;

void pp(vi v){
	rep(i, v.size()){
		cout << v[i] << ' ';
	}
	cout << endl;
}

int main(){
	int n, r;

	while(true){
		cin >> n >> r;

		if(!n && !r) break;

		n++;
		vi cards(n);
		rep(i, n){
			cards[i] = i;
		}

		int p, c;
		rep(i, r){
			cin >> p >> c;

			int index = n-(p-1+c);

			vi pick;
			// cardsの後ろからp-1+c番目からc個を保管
			rep(j,c){
				pick.push_back(cards[index+j]);
			}
		
			// cardsの後ろからp-1+c番目にp1番目-0をコピー
			rep(j, p-1){
				cards[index+j] = cards[index+j+c];
			}

			// 保管していたのを後ろに追加
			rep(j,c){
				cards[index+p-1+j] = pick[j];
			}

			//pp(cards);
		}
		cout << cards[n-1] << endl;
	}

	return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
 
using namespace std;
 
const int MOD=1e9+7;
const double PI=3.14159265359;

vector<int> getPrimes(int stop){
    int sieveStop=ceil(sqrt(stop));
    vector<int> psj;
    for(int i=2; i<=sieveStop; i++){
        bool isP=true;
        for(int j=2; j<i && isP; j++){
            isP=i%j;
        }
        if(isP) psj.push_back(i);
    }
    
    vector<bool> primesb(stop+1,true);
    for(int j:psj){
        for(int i=2; i*j<=stop; i++){
            primesb[i*j]=false;
        }
    }
    vector<int> ans;
    for(int i=2; i<=stop; i++){
        if(primesb[i]) ans.push_back(i);
    }
    return ans;
}

long long modpow(long long x, long long n, long long m) {
    if (n == 0) return 1%m;
    long long u = modpow(x,n/2,m);
    u = (u*u)%m;
    if (n%2 == 1) u = (u*x)%m;
    return u;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    auto p=getPrimes(100000);
    
    int n,m;
    cin>>n>>m;
    
    vector<int> factNums;
    
    for(int i:p){
        int ct=0;
        while(!(m%i)){
            ct++;
            m/=i;
        }
        if(ct) factNums.push_back(ct);
    }
    
    if(m>1){
        factNums.push_back(1);
    }
    
    vector<long long> nf(100050);
    
    nf[0]=1;
    for(int i=1; i<100050; i++){
        nf[i]=nf[i-1]*i;
        nf[i]%=MOD;
    }
    
    long long ans=1;
    
    for(int i:factNums){
        long long N=i+n-1;
        long long R=n-1;
        ans*=nf[N];
        ans%=MOD;
        
        ans*=modpow(nf[R],MOD-2,MOD);
        ans%=MOD;
        ans*=modpow(nf[N-R],MOD-2,MOD);
        ans%=MOD;
    }
    cout<<ans;
    
    return 0;
}

Measured memory_bytes: 1152
require 'matrix'

orgnums = gets.chomp.split(" ").map{|str| str.to_i}
buf = Array.new(3)
nums = orgnums
count = 0

while (!nums.find{|num| num.odd?})
	buf = ((Vector.elements(nums.rotate(1)) + Vector.elements(nums.rotate(2))) / 2).to_a
	if buf == orgnums
		puts -1
		exit
	end
	nums = buf
	count += 1
end
puts count

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


int main() {
  int64_t N,M,K;
  cin>>N>>M>>K;
  
  vector<int> A(N);
  vector<int64_t> SUMA(N+1);
  SUMA.at(0)=0;
  rep(i,N){cin >> A.at(i);SUMA.at(i+1)=SUMA.at(i)+A.at(i);}

  vector<int> B(M);
  vector<int64_t> SUMB(M+1);
  SUMB.at(0)=0;
  int jMax=0;
  rep(i,M){cin >> B.at(i);SUMB.at(i+1)=SUMB.at(i)+B.at(i);
          if(SUMB.at(i+1)<=K){jMax=i+1;}}

  int Ans=jMax;
  
  for(int i=1;i<=N;i++){
    for(int j=jMax;j>=0;j--){
      if(SUMA.at(i)+SUMB.at(j)<=K){Ans=max(Ans,i+j);jMax=j;break;}
    }
  }      
cout<<Ans<<endl;
}

Measured memory_bytes: 8012
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll k,cnt=0;
  cin >> k;
  vector<ll> v={1,2,3,4,5,6,7,8,9};
  while(v.size()<100000) {
    ll x=v[cnt]%10;
    if(x>0) {
      v.push_back(v[cnt]*10+x-1);
    }
    v.push_back(v[cnt]*10+x);
    if(x<9) {
      v.push_back(v[cnt]*10+x+1);
    }
    cnt++;
  }
  cout << v[k-1] << endl;
}

Measured memory_bytes: 1592
import sys

def ta(x, y, p):
    xc = 0
    yc = 0

    for i in p[x]:
        bc = x
        c = i
        while True:
            if c == x:
                xc += 1
                break
            elif c == y:
                yc += 1
                break
            cs = p[c]
            for j in cs:
                if j != bc:
                    bc = c
                    c = j
                    break
    if xc == yc:
        return True
    else:
        return False


d = {}
p = {}
n, m = input().strip().split(" ")
for i in range(int(n)):
    i += 1
    d[i] = 0
    p[i] = list()

for line in sys.stdin:
    x, y = line.strip().split(" ")
    x, y = int(x), int(y)
    d[x] += 1
    d[y] += 1
    p[x].append(y)
    p[y].append(x)

r = None
fc = 0
fcs = []
for x in d:
    y = d[x]
    if y % 2 != 0:
        r = False
        break
    if y >= 6:
        r = True
    if y >= 4:
        fc += 1
        fcs.append(x)

if r == None:
    if fc >= 3:
        r = True
    elif fc == 2:
        x, y = fcs
        r = ta(x, y, p)
    else:
        r = False
if r:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 35856
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner stdn = new Scanner(System.in);
		int a = 0;
		int b = 0;
		int c = 0;
		
		a = stdn.nextInt();
		b = stdn.nextInt();
		c = stdn.nextInt();
		
		if(a < b && a < c && b < c){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 26336
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[][] x = new int[n][3];

        for (int i = 0; i < n; i++) {
            x[i][0] = sc.nextInt() % (2 * k);
            x[i][1] = sc.nextInt() % (2 * k);
            String s = sc.next();
            if (s.equals("B")) {
                x[i][2] = 0;
            } else {
                x[i][2] = 1;
            }
        }

        for (int i = 0; i < n; i++) {
            if (x[i][2] == 0 && x[i][0] >= k) {
                x[i][2] = 1;
                x[i][0] -= k;
            } else if (x[i][2] == 0 && x[i][0] < k) {
                x[i][2] = 1;
                x[i][0] += k;
            }
            if (x[i][1] >= k && x[i][0] < k) {
                x[i][1] -= k;
                x[i][0] += k;
            } else if (x[i][1] >= k && x[i][0] >= k) {
                x[i][1] -= k;
                x[i][0] -= k;
            }
        }

        int[][] b = new int[2 * k + 1][k + 1];

        for (int i = 0; i < n; i++) {
            b[x[i][0] + 1][x[i][1] + 1]++;
        }
        for (int i = 1; i < 2 * k; i++) {
            b[i + 1][1] = b[i][1] + b[i + 1][1];
        }
        for (int i = 1; i < k; i++) {
            b[1][i + 1] = b[1][i] + b[1][i + 1];
        }
        for (int i = 1; i < k; i++) {
            for (int j = 1; j < 2 * k; j++) {
                b[j + 1][i + 1] = b[j][i + 1] + b[j + 1][i] + b[j + 1][i + 1] - b[j][i];
            }
        }

        int ans = 0;

        for (int i = 1; i < k * 2 + 1; i++) {
            for (int j = 1; j < k + 1; j++) {
                int tmp = culc(b, i - 1 - 2 * k, j - 1, i - k - 1, j + k - 1, k);
                tmp += culc(b, i - 1 - k, j - k - 1, i - 1, j - 1, k);
                tmp += culc(b, i - 1, j - 1, i - 1 + k, j - 1 + k, k);
                tmp += culc(b, i - 1 + k, j - k - 1, i - 1 + 2 * k, j - 1, k);
                if (tmp > ans)
                    ans = tmp;
            }
        }

        System.out.println(ans);
    }

    public static int culc(int[][] b, int x1, int y1, int x2, int y2, int k) {
        if (x1 < 0)
            x1 = 0;
        if (y1 < 0)
            y1 = 0;
        if (x2 < 0)
            x2 = 0;
        if (y2 < 0)
            y2 = 0;
        if (x1 > 2 * k)
            x1 = 2 * k;
        if (y1 > k)
            y1 = k;
        if (x2 > 2 * k)
            x2 = 2 * k;
        if (y2 > k)
            y2 = k;
        return b[x1][y1] + b[x2][y2] - b[x1][y2] - b[x2][y1];
    }
}


Measured memory_bytes: 95488
n, m = map(int, input().split())
edges = [[] for _ in range(n)]
for _ in range(m):
    s, t = map(int, input().split())
    edges[n - s].append(n - t)

dp = [0.0] * n
for i in range(1, n):
    dp[i] = sum(dp[s] + 1.0 for s in edges[i]) / len(edges[i])

ret = dp[-1]
for j in range(n - 1, 0, -1):
    if len(edges[j]) > 1:
        values = sorted(dp[s] + 1.0 for s in edges[j])
        dp[j] = (sum(values) - values[-1]) / (len(edges[j]) - 1)
        for i in range(j + 1, n):
            dp[i] = sum(dp[s] + 1.0 for s in edges[i]) / len(edges[i])
        ret = min(ret, dp[-1])

print(ret)


Measured memory_bytes: 59480
def main():
    n = int(input())
    A = list(map(int, input().split()))
    A.sort(reverse=True)
    limit = 10 ** 18
    #print(A)

    if A[-1] == 0:
        print(0)
    elif A[0] > limit:
        print(-1)
    else:
        ans = A[0]
        for i in range(1, n):
            ans *= A[i]
            if ans > limit:
                print(-1)
                exit()

        print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 21692
#include<cstdio>
#include<algorithm>
using namespace std;

const int M=5e4+5;
const int N=505;

namespace ufs{
	int fa[N];
	inline void reset(int n) {
		for(register int i=1;i<=n;i++)
			fa[i]=i;
		return;
	}
	int find(int x) {
		return (x==fa[x])?x:fa[x]=find(fa[x]);
	}
	inline bool merge(int x,int y) {
		int fx=find(x),fy=find(y);
		if(fx==fy) return false;
		return fa[fx]=fy,true;
	}
}

int n,m;
struct Edge{
	int u,v,w;
	bool operator <(const Edge &t)const{
		return w<t.w;
	}
}e[M];
int used[M];

signed main()
{
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		for(register int i=1;i<=m;i++)
			scanf("%d%d%d",&e[i].u,&e[i].v,&e[i].w);
		
		sort(e+1,e+1+m);
		ufs::reset(n);
		
		int sum=0;
		int ans1=0,ans2=0;
		
		for(register int cnt=0,i=1;cnt!=n-1&&i<=m;i++)
			if(ufs::merge(e[i].u,e[i].v))
				sum+=e[i].w,used[++cnt]=i;
		
		for(register int c=1;c<n;c++)
		{
			ufs::reset(n);
			int tmp=0,cnt=0;
			for(register int i=1;cnt!=n-1&&i<=m;i++)
				if(i!=used[c]&&ufs::merge(e[i].u,e[i].v))
					cnt++,tmp+=e[i].w;
			if(tmp!=sum||cnt!=n-1)
				ans1++,ans2+=e[used[c]].w;
		}
		
		printf("%d %d\n",ans1,ans2);

	}
}


Measured memory_bytes: 3332
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using loop = int;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(loop (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(loop (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(loop (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(loop (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    string s; cin >> s;
    int n = s.length();
    for (int i = n / 2 - 1;; --i) {
        if (s.substr(0, i) == s.substr(i, i)) {
            cout << i * 2 << "\n";
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - 48;}
char myitoc(int N) {return '0' + N;}

signed main()
{
  string S;
  cin >> S;
  int N = S.size();

  vector<vector<int>> dp(N + 1, vector<int>(4, 0));
  dp.at(0).at(0) = 1;
  for (int i = 0; i < N; i++)
  {
    string ABC = "ABC";
    for (int j = 0; j < 4; j++)
    {
      if (j != 3 && (S.at(i) == '?' || S.at(i) == ABC.at(j)))
      {
        dp.at(i + 1).at(j + 1) += dp.at(i).at(j);
        dp.at(i + 1).at(j + 1) %= MOD;
      }
      
      dp.at(i + 1).at(j) += dp.at(i).at(j) * ((S.at(i) == '?')? 3 : 1);
      dp.at(i + 1).at(j) %= MOD;
    }
  }
  
  int ans = dp.at(N).at(3);
  cout << ans << endl;
}

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

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int MOD=1e9+7;
ll INF=1e18;

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

int main(){
    int n; cin>>n;
    vector<ll> a(n);
    for(int i=0; i<n; i++) cin>>a[i];

    ll ub=0, sum=0, ans=0;
    for(int lb=0; lb<n; lb++){
        while(ub<n && (sum&a[ub])==0){
            sum+=a[ub];
            ub++;
        }

        ans+=(ub-lb);
        sum-=a[lb];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <bits/stdc++.h>
#include <cassert>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define forn(i,n)for(int i=0;i<n;i++)
#define forna(i,a,n)for(int i=a;i<n;i++)
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1e9+7
#define ff first
#define ss second
#define INF 1e18
#define MAX 200006
typedef long long ll;
using namespace std;
using namespace __gnu_pbds;

int main()
{
    IOS
    // int q;cin>>q;
    // while(q--){
        
    // }
    string s;cin>>s;
    if(s=="AAA" || s=="BBB")
        cout<<"No";
    else cout<<"Yes";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define llu unsigned long long
#define pb push_back
#define f(n) for(ll i=0;i<n;i++)
#define ina for(ll i=0;i<n;i++)cin>>a[i];
#define all(v) v.begin(),v.end()
#define YES printf("YES\n")
#define NO printf("NO\n")
#define fastio std::ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
//long long bigmod/* (a^p)%m */ ( long long a, long long p, long long m ){long long res = 1;long long x = a;while ( p ){if ( p & 1 ){res = ( res * x ) % m;}x = ( x * x ) % m;p = p >> 1;}return res;}
//ll modInverse(ll a, ll m) { ll m0 = m; ll y = 0, x = 1; if (m == 1) return 0; while (a > 1) { ll q = a / m; ll t = m; m = a % m, a = t; t = y; y = x - q * y; x = t; } if (x < 0) x += m0; return x; }
//call manipulated_seive(N) and get prime in prime vector
//const long long MAX_SIZE = 1000001; vector<long long >isprime(MAX_SIZE , true); vector<long long >prime; vector<long long >SPF(MAX_SIZE); void manipulated_seive(int N) { isprime[0] = isprime[1] = false ; for (long long int i=2; i<N ; i++) { if (isprime[i]) { prime.push_back(i); SPF[i] = i; } for (long long int j=0; j < (int)prime.size() && i*prime[j] < N && prime[j] <= SPF[i]; j++) { isprime[i*prime[j]]=false; SPF[i*prime[j]] = prime[j] ; } } }
//ll phi[5000001];bool mark[5000001];void sievephi(ll n){ll i,j;for(ll i=1;i<=n;i++) phi[i]=i;mark[1]=true;for(ll i=2;i<=n;i++)if(!mark[i]){for(ll j=i;j<=n;j+=i){mark[j]=true;phi[j]=phi[j]/i*(i-1);}}}

/*speedup
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/
// vule geli coilbi na dada cout << fixed << setprecision(6) << pi <<" "<<npi<<endl;
//Pattern? OEIS
// prime factorize?? think about 2


vector<ll>v,vv,vvv;


int main()
{
    fastio;

            ll n,x,y; cin>>n;
            for(int i=0;i<n;i++)
            {
               cin>>x>>y;
               v.pb(x+y);
               vv.pb(x-y);
               vvv.pb(y-x);
            }
            sort(all(v));
            sort(all(vv));
            sort(all(vvv));
            cout<<max(abs(v[0]- v[v.size()-1]),vvv[vvv.size()-1]+ vv[vv.size()-1])<<endl;

    return 0;
}




Measured memory_bytes: 8152
import math

def main():
    N, K = map(int, input().split())

    size = int(math.log2(K)+2)
    table = [1 / 2 ** i for i in range(size)]
    p = 0
    for i in range(1, N+1):
        point = i
        j = 0
        while point < K:
            point *= 2
            j += 1
        p += table[j]
    print(p/N)

    

main()

Measured memory_bytes: 3060
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N; cin >> N;
    vector<string> vs(N);
    vector<int> p(N), ord(N);
    iota(ord.begin(), ord.end(), 0LL);

    for(int i=0; i<N; i++) {
        cin >> vs[i] >> p[i];
    }

    sort(ord.begin(), ord.end(), [&](int x, int y) {
            if(vs[x] != vs[y]) return vs[x] < vs[y];
            return p[x] > p[y];
        });
    for(int i=0; i<N; i++) cout << ord[i] + 1 << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
P = np.array(lr())

Q = np.minimum.accumulate(P)
answer = np.count_nonzero(P == Q)
print(answer)


Measured memory_bytes: 34136
#include <iostream>
#include <stdio.h>
#include <cmath>

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

using namespace std;
typedef long long ll;

int main(){
  ll a,b,c,d,ans;
  cin >> a >> b >> c >> d;
  ans = max(a*c, max(a*d, max(b*c, b*d)));
  cout << ans << endl;
}


Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<map>

using namespace std;

const int N=2*1e5+50;

map<string,int>ma;

struct edge
{
	int time;
	string s;
}a[N];

int n,top,oi;

string sd;

bool cmp(const edge x,const edge y)
{
	if(x.time!=y.time)
	return x.time>y.time;
	return x.s<y.s;
}

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>sd;
		ma[sd]++;
		if(ma[sd]==1)
		{
			a[++top].s=sd;
		}
		
	}
	for(int i=1;i<=top;i++)
	{
		a[i].time=ma[a[i].s];
	}
	sort(a+1,a+1+top,cmp);
	oi=a[1].time;
	for(int i=1;i<=top;i++)
	{
		if(a[i].time==oi)
		cout<<a[i].s<<endl;
		
	}
	return 0;
}

Measured memory_bytes: 28288
N = int(input())
a_list = list(map(int, input().split()))
count = 0
while True:
	odd = 0
	for i in range(N):
		if a_list[i] % 2 == 0:
			a_list[i] = int(a_list[i] / 2)
			count += 1
		else:
			odd += 1
	if odd == len(a_list):
		break
print(count)

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

int main()
{
    string s,t;
    cin>>s>>t;
    string k;
    for(int i=0;i<t.size()-1;i++)k+=t[i];
    if(k==s)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3632
N = int(raw_input())
S = [list(raw_input()) for t in range(N)]
ans = 0
for n in range(N):
  t = S[n:]+S[:n]
  t_t = list(map(list, zip(*t)))
  if t == t_t:
    ans += 1
#for n in range(N):
#  isSym = True
#  for i in range(N):
#    for j in range(i,N):
#      if S[i][j] != S[j][i]:
#        isSym = False
#        break
#    if not isSym:
#      break
#  ans += 1 if isSym else 0
#  s = S.pop()
#  S.insert(0, s)
print ans*N


Measured memory_bytes: 5884
import numpy as np
n = int(input())
ab = [list(map(int, input().split())) for x in range(n)]

cnt = 0
for a, b in reversed(ab):
    diff = a - b + cnt
    if diff == -b:
        pass
    elif diff < 0:
        cnt -= diff
    else:
        diffb = diff % b
        if diffb:
            cnt += b - diffb
print(int(cnt))



Measured memory_bytes: 36328
#include<bits/stdc++.h>
 
using namespace std;
long long mod=1e9+7;
long long INF=1e7;
double EPS = 1e-12;
const long long lim = 2e5+100;
typedef long long int lld;
typedef long long ll;

#define rep(i,a,n) for(long long int i = (a); i <= (n); ++i)
#define mset(a, v) memset(a, v, sizeof(a))
#define Error(x...) { cout << "(" << #x << ")" << " = ( "; printIt(x); }
template <typename T1> void printIt(T1 t1) { cout << t1 << " )" << endl; }
template <typename T1, typename... T2>
void printIt(T1 t1, T2... t2) { cout << t1 << " , "; printIt(t2...); }
 
 
#define popcount __builtin_popcountll
 
ll powP(ll x, ll y) {
    ll ans = 1, po = x % mod;
    while(y > 0) {
        if(y & 1) ans = ans * po % mod;
        y >>= 1; po = po * po % mod;
    }
    return ans;
}


vector<ll> Ans, Adj[lim];
ll Array[lim], C[lim],dp[600][600];
pair<ll,ll> P[lim];

int main(){

    ios::sync_with_stdio(0);
    cin.tie(0);

    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output1.txt", "w", stdout);
    #endif
    
    lld T,i,p,j,l,e,r,b,c,k,m,q,a,d,w,x,y,u,v,z,t,curr,prev,sum=0,val,countA=0,indicator=0,pos,h,minA,maxA,type,n,ans=0,left,right;
    string A,B; a=b=0;  
    cin>>n>>k;
    rep(i,1,k) { cin>>x; Array[x]=1; }
    while(1) {
        val=n; indicator=0;
        while(val>0) {
            if(Array[val%10]==1) indicator=1;
            val/=10;
        }

        if(indicator==0) break;
        n++;
    }

    cout<<n<<endl;
    return 0;
}
    


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define all(x) begin(x), end(x)
#define loop(i,n) for(int i=0; i<n; i++)
#define rep(i,a,b,c) for(int i=a; i<b; i+=c)
#define brep(i,a,b,c) for(int i=a; i>b; i-=c)
#define tc(t) int t; cin>>t; while(t--)
#define sz(v) int((v).size())
#define pb push_back

int n, m, x;
vector<int> costs;
vector<vector<int>> mat;
int res = INT_MAX;

void solve (int idx, int cost, vector<int>& curr) {
    bool breakRecur = true;
    loop(i, m) {
        if (curr[i]<x) {
            breakRecur = false;
            break;
        }
    }
    if (breakRecur) {
        res = min(cost, res);
        return;
    }

    if (idx>=n) return;

    // pick idx
    loop(i, m) {
        curr[i] += mat[idx][i];
    }
    solve(idx+1, cost+costs[idx], curr);

    // do not pick idx
    loop(i, m) {
        curr[i] -= mat[idx][i];
    }
    solve(idx+1, cost, curr);
}

int32_t main() {
    IOS;
    cin>>n>>m>>x;
    costs = vector<int>(n);
    mat = vector<vector<int>>(n, vector<int>(m));
    vector<int> curr(m, 0);

    vector<int> sumOfCols(m, 0);

    loop(i, n) {
        cin>>costs[i];
        loop(j, m) {
            cin>>mat[i][j];
            sumOfCols[j] += mat[i][j];
        }
    }

    loop(i, m) {
        if (sumOfCols[i]<x) {
            cout<<-1<<endl;
            return 0;
        }
    }
    solve(0, 0, curr);

    cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint N; cin >> N;
    cout << "ABC" << N << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int main() {
    LL N, K;
    cin >> N >> K;
    if (N >= K) {
        N = N % K;
    }
    cout << min(N, K-N) << endl;
}


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

#define fr first
#define se second

using namespace std;

const long long N = 1e3 + 7;
const long long inf = 1e9 + 7;
const long long mod = 1e9 + 7;

long long x;
long long pw(long long x){
    return (x * x * x * x * x);
}
int main()
{
    ios_base::sync_with_stdio(false);

    cin >> x;
    for(long long i = -N; i <= N; i ++){
        for(long long j = -N; j <= N; j ++){
            if(pw(i) - pw(j) == x){
                cout << i << " " << j << "\n";
                return 0;
            }
        }
    }
    assert(0);
}


Measured memory_bytes: 3528
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define fop(i,m,n) for (int i=(m);i<(n);i++)
#define FOP(i,m,n) for (int i=(m)-1;i>=(n);--i)
#define test(x) cout << #x << ' ' << x << endl;
#define eb emplace_back
#define pb push_back
#define mp make_pair 
#define pii pair<int,int> 
#define X first
#define Y second

struct Seg {
	int l,r,m;
	long long sum;
	Seg* ch[2];
	Seg (int l, int r): l(l), r(r), m(l + r >> 1) {
		sum = 0;
		if (r - l != 1) {
			ch[0] = new Seg(l,m);
			ch[1] = new Seg(m,r);
			pull();
		}
	}
	void pull() {sum = max(ch[0]->sum, ch[1]->sum);}
	void set(int p, long long v) {
		if (r - l == 1) {
			sum = v;
		} else {
			if (p < m) {
				ch[0]->set(p,v); 
			} else {
				ch[1]->set(p,v);
			}
			pull();
		}
	}
	long long query(int a, int b) {
		if (a <= l and r <= b) return sum;
		long long ans = LLONG_MIN;
		if (a < m) ans = max(ans, ch[0]->query(a,b)); 
		if (m < b) ans = max(ans, ch[1]->query(a,b));
		return ans;
	}
};

int main () {
    int n;
    cin >> n;
    vector <int> h(n), v(n);
    fop (i,0,n) cin >> h[i];
    fop (i,0,n) cin >> v[i];
    Seg a(0, n);
    lli ans = 0;
    fop (i,0,n) {
        a.set(h[i] - 1, a.query(0, h[i]) + v[i]);
    }
    cout << a.query(0, n) << endl;
}

Measured memory_bytes: 20608
#include <stdio.h>
#define LL long long
#define maxn 100010
LL sum,a[maxn],cnt[maxn];
int main(){
	int i,n,q,b,c;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%lld",&a[i]),sum+=a[i],cnt[a[i]]++;
	//printf("sum=%lld\n",sum);
	scanf("%d",&q);
	while(q--){
		scanf("%d%d",&b,&c);
		//printf("cnt[%d]=%lld cnt[%d]=%lld\n",b,cnt[b],c,cnt[c]);
		sum-=cnt[b]*b;//删除旧数据
		//printf("sum=%lld\n",sum);
		sum+=cnt[b]*c;//加上新数据
		//printf("sum=%lld\n",sum);
		cnt[c]+=cnt[b],cnt[b]=0;//更新新数据数量
		printf("%lld\n",sum);
	}
	return 0;
}

Measured memory_bytes: 3224
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = b - 1;i >= a;--i)
#define p(s) cout << (s) << endl
#define p2(s,t) cout << (s) << " " << (t) << endl 
#define ALL(v) (v).begin(), (v).end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;
using namespace std;

static const ll MOD  = 1e9 + 7;
static const ll INF  = 1e18;
static const double EPS = 1e-10;

int main(){
    int N; cin >> N;
    int day = 1, cnt = 0;;
    vector<vector<int>> A(N,vector<int>(N-1));
    queue<int> Q[N];
    queue<pair<int,int>> game;

    rep(i, N) rep(j, N - 1){
        cin >> A[i][j];
        A[i][j]--;
        Q[i].push(A[i][j]);
    }
    int ttcnt = 0;

    rep(i, N){
        if(Q[Q[i].front()].front() == i){
            game.push({i, Q[i].front()});
            ttcnt++;
        }
    }
    cnt = ttcnt / 2;

    while(cnt < (N-1)*N/2){
        if(game.empty()){
            cout << -1 << endl;
            return 0;
        }
        int tcnt = 0;
        int Gsize = game.size();
        int T = 0;
        while(T < Gsize){
            auto e = game.front();game.pop();
            //cout << day << " " << e.first << " " << e.second << endl;
            T++;
            if(Q[e.first].front() != e.second) continue;
            Q[e.first].pop();
            Q[e.second].pop();

            if(!Q[e.first].empty() && Q[Q[e.first].front()].front() == e.first){
                game.push({e.first, Q[e.first].front()});
                tcnt++;
            }
            if(!Q[e.second].empty() &&Q[Q[e.second].front()].front() == e.second){
                game.push({e.second, Q[e.second].front()});
                tcnt++;
            }
        }
        //cout << cnt << endl;
        //cout << game.front().first << game.front().second << endl;
        cnt += tcnt;
        day++;
    }
    cout << day << endl;

}

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

#define fo(i,s,t) for(int i = s;  i<= t; ++ i)
const int maxn = 100050;

int n, a, b, s[maxn];
long long shit[maxn];
int t;

bool judge(int x)
{
	fo(i,1,n) shit[i] = s[i] - (long long)x*b;
	long long req = 0;
	fo(i,1,n) if(shit[i] > 0)
		req += shit[i]/(a-b) + (shit[i]%(a-b)!=0);
	if(req > x) return false;
	return true;
}

int main()
{
	scanf("%d%d%d",&n,&a,&b);
	fo(i,1,n) scanf("%d",&s[i]);
	int l, r, mid, ans;
	l = 1; r = 1000000000;
	while(l <= r)
	{
		mid = l + r >> 1;
		if(judge(mid)) r = mid - 1, ans = mid;
		else l = mid + 1;
	}	
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1408