akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;


long long int n,cnt=0,ans=LINF,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin>>h>>w;
      if(h%3==0||w%3==0)Cout(0);
      else{
        rrep(tate,1,w){
          a=h*tate;
          b=h/2*(w-tate);
          c=h*w-a-b;
          ans=min(ans,max({a,b,c})-min({a,b,c}));
        }
        rrep(tate,1,h){
          a=w*tate;
          b=w/2*(h-tate);
          c=h*w-a-b;
          ans=min(ans,max({a,b,c})-min({a,b,c}));
        }
        rrep(tate,1,h){
          a=w*tate;
          b=((h-tate)/2)*w;
          c=h*w-a-b;
          ans=min(ans,max({a,b,c})-min({a,b,c}));
        }
        rrep(tate,1,w){
          a=h*tate;
          b=((w-tate)/2)*h;
          c=h*w-a-b;
          ans=min(ans,max({a,b,c})-min({a,b,c}));
        }
          Cout(ans);
      }
     

       
return 0;
}


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

typedef long long ll;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr << '\n'; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << " "; err(++it, args...); }

#define        optimize           ios::sync_with_stdio(0); cin.tie(0);
#define PI    acos(-1.0)
#define pb push_back
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define RESET(a, b) memset(a, b, sizeof(a))
#define pii pair <int, int>
#define gcd(a, b) __gcd(a, b)
#define min3(a, b, c) min(c, min(a, b))
#define max3(a, b, c) max(c, max(a, b))

const ll MX = 4e2 + 5;
const ll inf = 1e18L + 5;

ll ara[MX];
ll dp[MX][MX];

ll sum(int l, int r)
{
    ll ans = 0;
    for(int i = l; i <= r; i++) ans += ara[i];
    return ans;
}

int main()
{
    optimize
    int n;
    cin>>n;
    for(int i = 0; i < n; i++) cin>>ara[i];

    RESET(dp, inf);

    for(int R = 0; R < n; R++){
        for(int L = R; L >= 0; L--){
            if(L == R) dp[L][R] = 0;
            else{
                ll s = sum(L, R);
                for(int i = L; i <= R; i++){
                    dp[L][R] = min(dp[L][R], dp[L][i]+dp[i+1][R]+s);
                }
            }
        }
    }
    cout<<dp[0][n-1]<<endl;
}


Measured memory_bytes: 4952
fun main(args: Array<String>) {
    val s = readLine()!!
    val t = readLine()!!
    var ans: Int = t.length
    
    for (start in 0..s.length - t.length) {
        var diff = 0
        for (i in 0 until t.length) {
            if (t.get(i) !== s.get(start + i)) {
                diff++
            }
        }
        ans = Math.min(ans, diff)
    }

    println(ans)

}

Measured memory_bytes: 35972
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector
;
#define vvec(s) vector<vector
> ;
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(),s.end()
void vout(vector<int> v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    lli n,k;
    cin>>n>>k;
    vector<pii> rec;
    rep(i,n){
        lli a,b;
        cin>>a>>b;
        rec.push_back(pii(a,b));
    }
    sort(all(rec));
    lli ans,cnt=0;
    rep(i,rec.size()){
        cnt+=rec[i].second;
        if(cnt>=k){
            ans=rec[i].first;
            break;
        }
    }
    out(ans);
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
#define ll long long
#define f   first
#define s   second
#define pb          push_back
#define mod         1000000007
#define hell        998244353
#define inf         1000000000000000000LL
using namespace std;
ll n,k,m;
//ll dp[15][1005];
vector<ll> v;
void solve()
{   ll X,Y,Z;
    cin>>k;
    queue<ll> q;
    if(k<=10) cout<<k;
    else
    {
        ll cnt=9;
        for(ll i=1;i<=9;i++)
            {q.push((i));v.pb((i));}
        while(1)
        {
            ll x=q.front();
            q.pop();
            if(cnt>100005) break;
                ll y=(x%10);
                if(y==0)
                {
                    v.pb(x*10);
                    v.pb(x*10+1);
                    q.push(x*10);
                    q.push(x*10+1);
                    cnt+=2;
                }
                else if(y==9)
                {
                    v.pb(x*10+8);
                    v.pb(x*10+9);
                    q.push(x*10+8);
                    q.push(x*10+9);
                    cnt+=2;
                }
                else
                {
                    v.pb(x*10+(y-1));
                    v.pb(x*10+y);
                    v.pb(x*10+(y+1));
                    q.push(x*10+(y-1));
                    q.push(x*10+y);
                    q.push(x*10+y+1);
                    cnt+=3;
                }
        }
        cout<<v[k-1];

    }
    
}

int main()
{   //seive();
    ll t=1;
    //cin>>t;
    while(t--)
        solve();

}

Measured memory_bytes: 1620
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

ll N;
ll A[20];
ll x[20][20];
ll y[20][20];

int main(){

    ll N;
    cin >> N;
    rep(i, N){
        cin >> A[i];
        rep(j, A[i]){
            cin >> x[i][j] >> y[i][j];
            x[i][j]--;
        }
    }
    ll ans = 0;
    rep(i, 1 << N){
        ll flg = 1;
        rep(j, N)if(i & (1 << j))rep(k, A[j]){
            if((0 != (i & (1 << x[j][k]))) != y[j][k]){
                flg = 0;
            }
        }
        if(flg)chmax(ans, (ll)__builtin_popcount(i));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
/*
  Contest 089
  B - Hina Arare
  Rakesh Kumar --> 18/09/2020
 */

#include <bits/stdc++.h>

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

    int n = 0;
    std::cin >> n;
    std::set<char> maala;
    while (n--) {
        char c;
        std::cin >> c;
        maala.insert(c);
    }
    std::cout << (maala.size() == 3 ? "Three" : "Four") << std::endl;

    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ull = uint64_t;
using ll = int64_t;
using ld = long double;

const int N = 200228;

int a[N];

map<int, int> m;

int main() {
#ifdef BZ
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cout.setf(ios::fixed); cout.precision(20);
    int n;
    cin >> n;
    int v = (1 << 29);

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

    int ans = 0;

    while (m.size()) {
        int x = m.rbegin()->first;

        while (x < v) {
            v /= 2;
        }

        if (x == v) {
            if (m.rbegin()->second > 2) {
                m.rbegin()->second -= 2;
                ++ans;
            } else {
                ans += m.rbegin()->second - 1;
                m.erase(x);
            }

            continue;
        }

        int d = v * 2 - x;
        auto it = m.find(d);

        if (it == m.end()) {
            m.erase(x);
        } else {
            ++ans;
            if (--m[d] == 0) {
                m.erase(d);
            }

            if (--m[x] == 0) {
                m.erase(x);
            }
        }
    }

    cout << ans << "\n";
}



Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
int dp[3300][3300];
signed main(){
    string s,t;cin >> s >> t;
    int n = s.size(),m = t.size();
    rep(i,n)rep(j,m){
        if(s[i] == t[j]){
            dp[i+1][j+1] = dp[i][j]+1;
        }
        else{
            dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1]);
        }
    }
    //cout << dp[n][m];
    string ans = "";
    int j = m-1,i = n-1;
    while(j >=0 && i >=0){
        if(dp[i+1][j+1] == dp[i][j+1])i--;
        else if(dp[i+1][j+1] == dp[i+1][j])j--;
        else {
            ans = s[i] + ans;
            i--;j--;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 78208
n, k, q = gets.chomp.split(" ").map(&:to_i)
arr = Array.new(n+1,0)
q.times do |i|
    a = gets.chomp.to_i
    arr[a] += 1
end
arr.shift
arr.each do |i|
    if k + i - q> 0
        puts "Yes"
    else
        puts "No"
    end
end

Measured memory_bytes: 14972
from sys import stdin
import numpy as np
def main():
    #入力
    readline=stdin.readline
    x1,y1,x2,y2=map(int,readline().split())
    
    p1=np.array([x1,y1])
    p2=np.array([x2,y2])
    R1=np.array([[0,-1],[1,0]])
    R2=np.array([[0,1],[-1,0]])
    p3=np.dot(R2,(p1-p2))+p2
    p4=np.dot(R1,(p2-p1))+p1
    print(p3[0],p3[1],p4[0],p4[1])

if __name__=="__main__":
    main()

Measured memory_bytes: 14416
N, K = map(int, input().split())
H = list(map(int, input().split()))

dp = [10 ** 9] * N
dp[0] = 0

for i in range(1, N):
	for j in range(min(i, K) + 1):
		dp[i] = min(dp[i], dp[i - j] + abs(H[i] - H[i - j]))
print(dp[-1])

Measured memory_bytes: 84720
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define N 1000005
using namespace std;

int n, m, x, l, r, ans;
pair < int , pair < int , int > > a[N];
set < int > s;

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%d %d",&n ,&m);
	for(int i = 1; i <= m; i++){
		scanf("%d %d",&l ,&r);
		a[++x] = mp(l, mp(1, i));
		a[++x] = mp(r, mp(0, i) );
	}
	sort(a + 1, a + x + 1);
	for(int i = 1; i <= x; i++){
		if(a[i].nd.st == 1){
			s.insert(a[i].nd.nd);
		}else{
			if(s.count(a[i].nd.nd)){
				// cout << a[i].st;
				ans++;
				s.clear();
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 5888
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,avx2,fma,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(0),cin.tie(0), cout.tie(0)
typedef long long ll;


ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

//#######################################

int main(){
  boost;

  
  int n;
  cin>>n;
  long a[n],b[n],c[n];

  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
  }
 
  long dp[n][3];
  dp[0][0]=a[0];
  dp[0][1]=b[0];
  dp[0][2]=c[0];

  for(int i=1;i<n;i++){
    dp[i][0]=max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
		dp[i][1]=max(dp[i-1][0]+b[i],dp[i-1][2]+b[i]);
		dp[i][2]=max(dp[i-1][0]+c[i],dp[i-1][1]+c[i]); 
     }
     	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;


}



Measured memory_bytes: 8304
A=[]
fp =0
bp =0
n=int(raw_input())
while n: 
    cmd = raw_input()
    if cmd[0] == 'i':
        A.append(int(cmd[7:]))
        fp += 1
    elif cmd[6] == ' ':
        try:
            i = A[::-1].index(int(cmd[7:]))
            if i!=-1:
                del A[-i-1]
                fp -=1
        except:
            pass
    elif cmd[6] == 'F':
        A.pop()
        fp -=1
    elif cmd[6] == 'L':
        bp +=1
    n -=1
 
for k in A[bp:fp+1][::-1]:
    print int(k),

Measured memory_bytes: 42200
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<bool> vb;
#define MOD 1000000007

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

	/*dp[i] is true if the frist player wins if their
		are i stones remaining.*/

	for (int i = 0; i <= k; ++i) {
		for (auto e : a) {
			if (i >= e and !dp[i-e])
				dp[i] = true;
		}
	}
	puts(dp[k] ? "First" : "Second");
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define mod 998244353
#define SYOU(x) fixed<<setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
using pii=pair<int, int > ;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  lol n,m,k;
  string s,w;
  lol a,b,c,x,y;
  cin >>n;
  string ans="No";
  if(n%10==7) ans="Yes";
  n/=10;
  if(n%10==7) ans="Yes";
  n/=10;
  if(n==7) ans="Yes";
  cout <<ans<<'\n';
  return (0);
}


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

using namespace std;

#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
const double PI = 3.14159265358979323846;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

int X, Y, Z, K;
int A[1100], B[1100], C[1100];

signed main() {
    cin >> X >> Y >> Z >> K;
    for (int i = 0; i < X; i++)cin >> A[i];
    for (int i = 0; i < Y; i++)cin >> B[i];
    for (int i = 0; i < Z; i++)cin >> C[i];
    vint vec;
    for (int i = 0; i < X; i++)for (int j = 0; j < Y; j++)vec.push_back(A[i] + B[j]);
    sort(vec.begin(), vec.end()), reverse(vec.begin(), vec.end());
    vint vec2;
    for (int i = 0; i < min(K, (int) vec.size()); i++)for (int j = 0; j < Z; j++)vec2.push_back(vec[i] + C[j]);
    sort(vec2.begin(), vec2.end()), reverse(vec2.begin(), vec2.end());
    for (int i = 0; i < K; i++)cout << vec2[i] << endl;
}


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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

template <typename T>
inline void chkmax(T &x, T y) { if (x < y) x = y; }

template <typename T>
inline void chkmin(T &x, T y) { if (x > y) x = y; }

inline int read() {
  #define nc getchar()
  int x = 0;
  char c = nc;
  while (c < 48) c = nc;
  while (c > 47) x = x * 10 + (c ^ 48), c = nc;
  return x;
  #undef nc
}

typedef long long ll;
typedef pair <int, int> pii;
const int maxn = 2010;
int n;
pii A[maxn];

ll dp[2][maxn];

int getdis(int x) {
  return max(x, n - x + 1);
}

int get(int x, int y) {
  return x < y ? y - x : x - y;
}

int main() {
  cin >> n;
  rep(i, 1, n) A[i] = pii(read(), i);
  sort(A + 1, A + n + 1, [] (pii P, pii Q) {
    return P.first == Q.first ? getdis(P.second) > getdis(Q.second) : P.first > Q.first;
  });
  int sel = 1;
  rep(i, 1, n) {
    rep(j, 0, i) {
      dp[sel][j] = 0;
      if (j < i) chkmax(dp[sel][j], dp[sel ^ 1][j] + 1ll * A[i].first * get(n - (i - j) + 1, A[i].second));
      if (j) chkmax(dp[sel][j], dp[sel ^ 1][j - 1] + 1ll * A[i].first * get(j, A[i].second));
    }
    sel ^= 1;
  }
  ll res = 0;
  rep(i, 0, n) chkmax(res, dp[sel ^ 1][i]);
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3684
/*
Sharif Hasan - CSE, PUST
Feb 22, 2020 12: 35 PM 
*/
#include<bits/stdc++.h>
#define br cout<<"\n"

/*STL definations*/
#define pb push_back

#define FOR(i,n) for(i=0;i<n;i++)
#define FROM(a,i,n) for(i=a;i<n;i++)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

/*Main function*/
int main()
{
double a,b;
cin>>a>>b;
cout<<floor(log(a)/log(b))+1;br;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SUM(x) accumulate(rng(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

//const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb(2000005);
// comb(n,k)ならcomb(n+k+5)とかにしておく

mint f(int n, int k) {
  if (n < 0) return 0;
  mint res = comb(n,k);
  // nPk = nCk * k!
  //res *= comb.fact[k]; // <- nPk求めたいときは必要
  return res;
}
// f(n,k).x で nCk か nPk が計算される

int main () {
  int x, y;
  cin >> x >> y;

  if ((x+y)%3 != 0) {
    cout << 0 << endl;
    return 0;
  }
  int n = (-x+2*y)/3;
  int m = (2*x-y)/3;
  if (n < 0 || m < 0) {
    cout << 0 << endl;
    return 0;
  }
  cout << f(n+m,n).x << endl;
  return 0;
}

Measured memory_bytes: 31488
#include <bits/stdc++.h>
using namespace std;
//解説AC
int main() {
  int n; cin >>n;
  vector<int>a(n),b(n);
  for(int i=0;i<n;i++)cin>>a[i];
  int count=0;
  int x=n;
  while(x>0){
    for(int i=x-1;i>=0;i--){
      //cout<<i<<" "<<a[i]<<endl;
      if(a[i]==i+1){
        b[count]=a[i];
        count++;
        a.erase(a.begin()+i);
        break;
      }
    }
    if(count==n)break;
    x--;
  }
  if(count!=n){
    cout<<-1<<endl;
    return 0;
  }
  for(int i=count-1;i>=0;i--){
    cout<<b[i]<<endl;
  }
  return 0;
}


Measured memory_bytes: 3616
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
    
n, m = map(int, input().split())
uf = UnionFind(n)
for i in range(m):
    a, b = map(int, input().split())
    uf.union(a - 1, b - 1)
print(uf.group_count() - 1)

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

int main() {
  int a, b;
  cin >> a >> b;
  if (b < 0 && (b-a+1)%2 == 1) cout << "Negative";
  else if (a <= 0 && b >= 0) cout << "Zero";
  else cout << "Positive";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

const int MAX = 5e5;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
  if(n >= MAX){
    ll tmp = 1;
    rep(i,k){
      tmp *= (n-i);
      tmp %= MOD;
    }
    return tmp*finv[k]%MOD;
  }

  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

int main(){
  ll n, a, b; cin >> n >> a >> b;
  ll ans = POW(2LL, n) - 1;
  COMinit();
  ans -= COM(n, a) + COM(n, b);
  ans %= MOD;

  while(ans < 0){
    ans += MOD;
  }

  cout << ans << endl;
}


Measured memory_bytes: 11904
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
lint power(lint x, lint n, lint mod) {
  lint ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= mod;
    (x *= x) %= mod;
    n >>= 1;
  }
  return ret;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int N;
  cin >> N;
  vector<lint> C(N);
  REP(i, N) cin >> C[i];
  sort(ALL(C));
  lint ans = 0;
  REP(i, N) {
    ans = (ans + (N+1-i)*power(2LL, N-1-i, MOD)% MOD * power(2LL, MOD-2, MOD) % MOD * C[i] % MOD * power(2LL, i, MOD) % MOD )  % MOD;
  }
  cout << (ans * power(2LL, N, MOD) % MOD) << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

void bubbleSort(int A[], int N) {
	bool flag = true;
	int cnt = 0;
	//i:??????????????¨?????????????????????????????????
	for (int i = 0; flag; i++) { 
		flag = false;
		for (int j = N - 1; j >= i + 1; j--) {
			if (A[j] < A[j - 1]) {
				swap(A[j], A[j - 1]);
				flag = 1;
				cnt++;
			}
		}
	}

	for (int i = 0; i < N; i++) {
		cout << A[i];
		if (i != N - 1)cout << " ";
	}
	cout << endl;
	cout << cnt << endl;
}

int main() {
	int N; cin >> N;
	int A[100];
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	bubbleSort(A, N);

	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int n,a[200005],r,l,k,b[200005];
int main()
{
//	freopen("push.in","r",stdin);
//	freopen("push.out","w",stdout);
	scanf(" %d",&n);
	for(int i=1;i<=n;i++)
		scanf(" %d",&a[i]);
	if(n==1)
	{
		printf("%d\n",a[1]);
		return 0;
	}
	double aw=n;
	aw=aw/2;
	r=ceil(aw)+1;
	l=r-1;
	if(n%2==1)
		k=0;
	else
		k=-1;
	for(int i=r;i<=n;i++)
		b[i]=a[k+=2];
	k=n+2;
	for(int i=1;i<=l;i++)
		b[i]=a[k-=2];
	for(int i=1;i<=n;i++)
	{
		if(i!=n)
			printf("%d ",b[i]);
		else
			printf("%d",b[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
#define ll long long
int main (){
    int n;
    cin >> n;
    cout << (int)pow((int)sqrt((double)n),2) << endl;
    return 0;
}



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

using namespace std;

int main()
{
    int n;
    cin >> n;
    string a, b, c;
    for (int i = 0; i < n; i++)
    {
        int num;
        cin >> num;
        a += num + '0';
    }
    for (int i = 0; i < n; i++)
    {
        int num;
        cin >> num;
        b += num + '0';
    }
    c = a;
    sort(begin(c), end(c));
    int cntA = -1, cntB = -1, now = 0;
    do
    {
        if (c == a)
        {
            cntA = now;
        }
        if (c == b)
        {
            cntB = now;
        }
        if (~cntA && ~cntB)
        {
            cout << abs(cntA - cntB) << "\n";
            return 0;
        }
        now++;
    } while (next_permutation(begin(c), end(c)));
}

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

using namespace std;

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

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

  vector<int> dp(N+1);
  dp[0] = 1;

  int cur = 0;
  for (int i = 1; i <= N; i++) {
    if (cur < M && i == a[cur]) {
      dp[i] = 0;
      cur++;
    } else {
      dp[i] = (i > 1 ? (dp[i-1] + dp[i-2]) : dp[i-1]) % 1000000007;
    }
  }

  cout << dp[N] << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long
int ll[200007],ff[200007];
const int mod = 1e9 + 7;

int qpow(int a,int b){
  int ret=1;
  while(b){
    if(b&1) ret=(ret*a)%mod;
    a=(a*a)%mod;
    b>>=1;
  }
  return ret;
}


int cc(int n,int m){
  return (ff[n]*ll[m])%mod*ll[n-m]%mod;
}

int count_ways(int a,int b,int c,int d){
  int tot=(c-a)+(d-b);
  int down=(c-a);
  int ret=cc(tot,down);
  return ret;
}
main()
{
	
	int n,m,a,b;
	cin>>n>>m>>a>>b;
	ff[0]=1; ll[0]=1;
    for(int i=1;i<=m+n+2;i++)
	{
    ff[i]=i*ff[i-1]%mod;
    ll[i]=qpow(ff[i],mod-2);
    }
	int tot=count_ways(1,1,n,m);
    for(int i=1;i<=b;i++)
	{
        int tmp=count_ways(1,1,n-a,i)*count_ways(n-a+1,i,n,m)%mod;
        tot=(tot-tmp+mod)%mod;
    }
    cout<<tot<<endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <string>
#include <map>
#define rep(i,N) for(int i=0; i<N;i++)
using namespace std;

int main(){
    int X,frag,it;
    cin >> X;
    if(X==2){
        it=2;
        cout << it <<endl;return 0;
    }else if(X==3){
        it=3;
        cout << it <<endl;return 0;
    }else if(X==4){
        it=5;
        cout << it <<endl;return 0;
    }else{
        it=X;
        while(frag!=-1){
            rep(i,int(it/2)){
                if(it%(i+2)==0){
//                    cout << i+2<< " "<<it <<endl;
                    frag=0;
                    break;
                }else{
                    frag=-1;
                }
            }
            it+=1;
        }
    }
    cout << it-1 <<endl;

    return 0;
}

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

using namespace std;

//#define FILE_IO

typedef long long LL;

int N, M;
LL p[5005];
LL mrs[5005][5005];
int b[5005][205];
int v[5005], st[5005], dr[5005];
stack <int> stv;

int add(int x11, int x22, int y11, int y22, int val)
{
    mrs[x11][y11] += val;
    mrs[x11][y22 + 1] -= val;
    mrs[x22 + 1][y11] -= val;
    mrs[x22 + 1][y22 + 1] += val;
}

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    scanf("%d%d", &N, &M);
    for(int i = 2; i <= N; i++)
    {
        scanf("%d", &p[i]);
        p[i] += p[i - 1];
    }
    for(int i = 1; i <= N; i++)
        for(int j = 1; j <= M; j++)
            scanf("%d", &b[i][j]);

    for(int i = 1; i <= M; i++)
    {
        for(int j = 1; j <= N; j++)
            v[j] = b[j][i];

        while(!stv.empty()) stv.pop();
        for(int j = 1; j <= N; j++)
        {
            while(!stv.empty() && v[stv.top()] <= v[j])
                stv.pop();

            if(stv.empty()) st[j] = 1;
            else    st[j] = stv.top() + 1;

            stv.push(j);
        }

        while(!stv.empty()) stv.pop();
        for(int j = N; j >= 1; j--)
        {
            while(!stv.empty() && v[stv.top()] < v[j])
                stv.pop();

            if(stv.empty()) dr[j] = N;
            else    dr[j] = stv.top() - 1;

            stv.push(j);
        }

        for(int j = 1; j <= N; j++)
            add(st[j], j, j, dr[j], v[j]);
    }

    for(int i = 1; i <= N; i++)
        for(int j = 1; j <= N; j++)
            mrs[i][j] += mrs[i][j - 1] + mrs[i - 1][j] - mrs[i - 1][j - 1];

    LL ans = 0;
    for(int st = 1; st <= N; st++)
        for(int dr = st; dr <= N; dr++)
            ans = max(ans, mrs[st][dr] - p[dr] + p[st]);
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 199936
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
signed main(){
    ll n;cin>>n;
    ll ans=0;
    REP(i,1,sqrt(n)+1){
        ll a=i,b=n/i;
        if(n%i==0&&b-1>a)ans+=b-1;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3684
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
using pii = pair<int,int>;

int main() {
	int n,m,b,c,j=0;
	scanf("%d %d",&n,&m);
	vector<int> a(n);
    vector<pii> d(m);
	for(int i=0; i<n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=0; i<m;i++){
		scanf("%d %d",&b, &c);
		d[i].first = b;
        d[i].second = c;
	}
	sort(a.begin(), a.end());
	sort(d.begin(), d.end(),[](pii x,pii y){
        return x.second > y.second;
    });
    for(int i=0;i<m&&j<n;i++){
        for(int k=0;k<d[i].first;k++){
            if(d[i].second>a[j]){
                a[j] = d[i].second;
                j++;
                if(j==n) break;
            }else{
                j=n;
                break;
            }
        }
    }
        
	long long ans = accumulate(a.begin(), a.end(), 0LL);
	printf("%lld\n", ans);
	return 0;
}


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

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

  int ans = 0;
  for (int ya = 1; ya <= 122; ++ya) {
    long long x = 1;
    for (int i = 0; i < n; ++i)
      x *= ya;
    if (x > m)
      break;

    int y = 0;
    while (x) {
      y += x % 10;
      x /= 10;
    }

    if (y + a == ya)
      ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1000000007;
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)

int main(void){
    int n;
    cin>>n;
    vector<int> A(n);
    rep(i,n) cin>>A[i];
    int ans=0;
    rep(i,n){
        int a=A[i];
        while(a%2==0){
            a/=2;
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<numeric>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(){ 
	string s;
	cin>>s;
	if(s[0]=='9'||s[1]=='9'){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
const int maxn = 1e5+3;
LL a[maxn*3], l[maxn], r[maxn];
priority_queue<LL, vector<LL>, greater<LL> >q;
priority_queue<LL>p;
int main()
{
    LL sum = 0, sum2=0, ans;
    int n, m;
    scanf("%d",&n);
    for(int i=1; i<=3*n; ++i)
    {
        scanf("%lld",&a[i]);
        if(i<=n) sum += a[i], q.push(a[i]);
        else if(i>2*n) sum2 += a[i], p.push(a[i]);
    }
    l[n] = sum;
    r[2*n+1] = sum2;
    for(int i=n+1; i<=2*n; ++i)
    {
        if(q.top() < a[i])
        {
            sum = sum - q.top() + a[i];
            q.pop();
            q.push(a[i]);
        }
        l[i] = sum;
    }
    r[2*n] = sum2;
    for(int i=2*n-1; i>=n; --i)
    {
        if(p.top() > a[i+1])
        {
            sum2 = sum2 - p.top() + a[i+1];
            p.pop();
            p.push(a[i+1]);
        }
        r[i] = sum2;
    }
    ans = l[n]-r[n];
    for(int i=n+1; i<=2*n; ++i)
        ans = max(ans, l[i]-r[i]);
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 5108
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
q = int(input())
ans = sum(a)
con = Counter(a)
for _ in range(q):
    b, c = map(int, input().split())
    u=con[b]
    ans -= b * u
    con[c]+=con[b]
    con[b]=0
    ans += c * u
    print(ans)

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


int main(){
    int n; cin >> n;
    vector<string> arr(n);
    rep(i,n) cin >> arr[i];
    int flag = 0;
    for(int i = 0; i < n - 1; i++){
        if(arr[i][arr[i].size()-1] != arr[i+1][0]){
            cout << "No" << endl;
            flag++;
            break;
        }
    }
    sort(arr.begin(), arr.end());
    for(int i = 0; i < n - 1; i++){
        if(arr[i] == arr[i+1]){
            cout << "No" << endl;
            flag++;
            break;
        }
    }
    if(flag == 0){
        cout << "Yes" << endl;
    }
}

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

#define task "B"
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define db1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define db2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define db3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, n) { cerr << #A << " = "; rep(_, 1, n) cerr << A[_] << ' '; cerr << '\n'; }
#define SZ(x) ((int)(x).size())
#define pb push_back
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ackjalscjaowjico
#define prev ajcsoua0wucckjsl
#define y1 alkscj9u20cjeijc
#define left lajcljascjljl
#define right aucouasocjolkjl
#define y0 u9cqu3jioajc

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;

typedef pair<int,int> ii;
typedef pair<ii,int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;

int main()
{
	//freopen(task".in","r",stdin);
	//freopen(task".out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	string s;
	cin >> s;
	rep(i, 0, SZ(s) - 1) cout << 'x';
}


Measured memory_bytes: 256
#include <stdio.h>
int main() 
{
	int a[250],i,n;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		
	}
	for(i=1;i<=n;i++)
	{
	printf("node %d: key = %d, ",i,a[i]);
	if(i/2>0) printf("parent key = %d, ",a[i/2]);
	if(i*2<=n) printf("left key = %d, ",a[i*2]);
	if(i*2+1<=n) printf("right key = %d, ",a[i*2+1]);
	printf("\n");
    }
	return 0;
}



Measured memory_bytes: 2032
#include <bits/stdc++.h>
using namespace std;
signed main()
{
  int a,b,c=1,d;
  cin>>a>>b;
  d=a;
  for(int i=1;i<=d;i++){
    if(a>b){
    a-=b;
    a+=b-1;
    c++;
    }
  }
  cout<<c<<"\n";
}


Measured memory_bytes: 256
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

N, K = map(int, input().split())
h = list(map(int, input().split()))
print(sum(1 if h[i] >= K else 0 for i in range(N)))


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

int main () {
int A1 , A2 , A3 ; cin >> A1 >> A2 >> A3 ;
int ans = max ({ A1 , A2 , A3 }) - min ({ A1 , A2 , A3 });
cout << ans << endl ;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#include<iterator>
#include<vector>
#include<algorithm>


#define v vector
#define ll long long 
#define vpll vector<pair<long long,long long> > 
#define F first
#define S second
#define mp make_pair
#define ld long double
#define pb push_back
#define pii pair<int,int>
#define pci pair<char,int>
#define un unsigned

#define mod 1000000007
#define MAXN 100000
using namespace std; 


int main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    set<string> ss;
    map<string,v<pii> > m;
    for(int i = 1 ; i <= n ; i++)
    {
        string s;
        int temp;
        cin>>s>>temp;
        ss.insert(s);
        m[s].pb(mp(temp,i));
    }
    std::set<string>::iterator it = ss.begin();
    while(it != ss.end())
    {
        sort(m[*it].rbegin(),m[*it].rend());
        for(int j = 0 ; j < m[*it].size() ; j++)
        {
            cout<<m[*it][j].S<<endl;
        }
        it++;
    }
    return 0;
} 



Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<set>
#include<tuple>
using namespace std;
#define INF 11000000000
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> p;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)


int main(){
    string s,ans="CODEFESTIVAL2016";
    cin>>s;
    int count=0;
    for(int i=0;i<(int)ans.size();i++){
        if(s[i]!=ans[i]) count++;
    }
    cout<<count<<endl;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long ll;
const int maxn=5e5+5;
int t[maxn<<2];
void update(int x,int nv,int l,int r,int num){
	if(l==r){
		t[num]=nv;
		return;
	}
	int mid=(l+r)>>1;
	if(x<=mid) update(x,nv,l,mid,num<<1);
	else update(x,nv,mid+1,r,num<<1|1);
	t[num]=max(t[num<<1],t[num<<1|1]);
}
int query(int x,int y,int l,int r,int num){
	if(l>y||r<x) return 0;
	if(l>=x&&r<=y) return t[num];
	int mid=(l+r)>>1;
	return max(query(x,y,l,mid,num<<1),query(x,y,mid+1,r,num<<1|1));
}
int n,k,ans;
int main(){
	cin>>n>>k;
	for(int i=1,x;i<=n;i++){
		cin>>x;
		int p=query(max(0,x-k),x+k,0,maxn-1,1);
		ans=max(ans,1+p);
		update(x,1+p,0,maxn-1,1);
	}
	cout<<ans;
}

Measured memory_bytes: 6116
n,m,x = [int(i) for i in input().split()]
il = []
for _ in range(n):
  il.append([int(i) for i in input().split()])
  
c_min = 10**10
ok = False
  
for i in range(2**n):
  s = bin(i)[2:].zfill(n)
  sum_a = [0] * (m+1)
  for j in range(n):
    if s[j] == '1':
      l = il[j]
      for k in range(m+1):
        sum_a[k] += l[k]
  if min(sum_a[1:]) >= x:
    ok = True
    c_min = min(c_min, sum_a[0])
      
if ok:
  print(c_min)
else:
  print(-1)
      
    

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

class U {
public:
  int n;
  vector<int> p, s;

  U(int _) {
    n = _;
    p.resize(n);
    s.resize(n);
    for (int i = 0; i < n; i++) {
      p[i] = i;
      s[i] = 1;
    }
  }

  bool connect(int a, int b) {
    int ap, bp;
    for (ap = p[a]; ap != p[ap]; ap = p[ap]);
    for (bp = p[b]; bp != p[bp]; bp = p[bp]);
    if (ap == bp)
      return true;
    int mi = min(ap, bp), ma = max(ap, bp);
    p[ma] = mi;
    s[mi] += s[ma];
    s[ma] = 0;
    for (int pp = a; pp != mi;) {
      int next = p[pp];
      p[pp] = mi;
      pp = next;
    }
    for (int pp = b; pp != mi;) {
      int next = p[pp];
      p[pp] = mi;
      pp = next;
    }
    return false;
  }

  int q(int a) {
    int ap;
    for (ap = a; ap != p[ap]; ap = p[ap]);
    return s[ap];
  }

  int parent(int a) {
    int ap;
    for (ap = a; ap != p[ap]; ap = p[ap]);
    return p[ap];
  }

  bool query(int a, int b) { return parent(a) == parent(b); }
};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, k, l;
  cin >> n >> k >> l;
  U u1(n), u2(n);
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    u1.connect(a, b);
  }
  for (int i = 0; i < l; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    u2.connect(a, b);
  }

  map<pair<int, int>, int> mp;
  for (int i = 0; i < n; i++) {
    mp[make_pair(u1.parent(i), u2.parent(i))]++;
  }
  vector<int> ans(n);
  for (int i = 0; i < n; i++) {
    ans[i] = mp[make_pair(u1.parent(i), u2.parent(i))];
  }

  cout << ans[0];
  for (int i = 1; i < n; i++) cout << " " << ans[i];
  cout << endl;
  return 0;
}


Measured memory_bytes: 16000
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rt register int
#define l putchar('\n')
#define ll long long
#define r read()
#define p 998244353
using namespace std;
inline ll read(){
    ll x = 0; char zf = 1; char ch = getchar();
    while (ch != '-' && !isdigit(ch)) ch = getchar();
    if (ch == '-') zf = -1, ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return x * zf;
}
void write(ll y){if(y<0)putchar('-'),y=-y;if(y>9)write(y/10);putchar(y%10+48);}
void writeln(const ll y){write(y);putchar('\n');}
int i,j,k,m,n,x,y,z,cnt,sum;
int a[1010],b[1010],tot[1010];
int main(){
	n=r;
	for(rt i=1;i<=n;i++)a[i]=r;
	for(rt i=1;i<=n;i++){
		int sl=0;
		for(rt j=1;j<=n;j++)if(a[j]!=-1){
			sl++;tot[j]=sl; 
		}
		bool fla=1;
		for(rt j=n;j>=1;j--)if(a[j]!=-1&&a[j]==tot[j]){
			b[i]=a[j];a[j]=-1;fla=0;break;
		}
		if(fla) {
			puts("-1");
			return 0;
		}
	}
	for(rt i=n;i>=1;i--)writeln(b[i]);
    return 0;
}








Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pii pair<int,int>
#define eb emplace_back
#define MOD 1000000007
#define int long long
using namespace std;
#define s second
#define f first

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    int i;
    for(i=1;i<1e5;i++)
        if( abs(a*i-c)%b == 0 )
            break;
    i==1e5? cout << "NO" : cout << "YES";
}

Measured memory_bytes: 3648