akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
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 ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n,m;
  cin >> n >> m;
  vector<vector<ll>>a(n,vector<ll>(3));
  rep(i,n)rep(j,3) cin >> a[i][j];
  
  ll ans=0;
  for(int bit=0;bit<(1<<3);bit++){
    vector<ll>val(n);
    rep(i,n){
      ll res=0;
      rep(j,3){
        if(bit & (1<<j)){
          res+=a[i][j];
        }
        else{
          res-=a[i][j];
        }
      }
      val[i]=res;
    }
    sort(val.begin(),val.end(),greater<ll>());
    ll sum=0;
    rep(i,m) sum+=val[i];
    chmax(ans,sum);
  }
  cout << ans << endl;
      
        
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
 
int main() {
    int k, s;
    cin >> k >> s;
    int ans = 0;
    rep(i, k+1){
        rep(j, k+1){
            if(0 <= s-i-j && s-i-j <= k)ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
	Scanner sc;
	public void run(){
		sc = new Scanner(System.in);
		

		int m = sc.nextInt();
		for(int i = 0; i < m; i++){
			int shikin = sc.nextInt();
			int nensuu = sc.nextInt();
			int n = sc.nextInt();
			ArrayList<Integer> houhou = new ArrayList<Integer>();
			ArrayList<Double> nenri = new ArrayList<Double>();
			ArrayList<Integer> tesuu = new ArrayList<Integer>();
			for(int j = 0; j < n; j++){
				houhou.add(j, sc.nextInt());
				nenri.add(j, sc.nextDouble());
				tesuu.add(j, sc.nextInt());
			}
			calc(shikin, nensuu, n, houhou, nenri, tesuu);
		}
	}
	public void calc(int shikin, int nensuu, int n, ArrayList<Integer> houhou, ArrayList<Double> nenri, ArrayList<Integer> tesuu){
		int finalshikin = 0;
		for(int i = 0; i < n; i++){
			int h = houhou.get(i);
			int a = 0;
			if(h == 0){
				a = shikin;
				int rishi = 0;
				for(int j = 0; j < nensuu; j++){
					int b = (int) (a * nenri.get(i));
					a = a - tesuu.get(i);
					rishi = rishi + b;
				}
				a = a + rishi;
			}
			else if(h == 1){
				a = shikin;
				for(int j = 0; j < nensuu; j++){
					int b = (int) (a * nenri.get(i));
					a = a + b - tesuu.get(i);
				}
			}
			if(a >= finalshikin){
				finalshikin = a;
			}
		}
		System.out.println(finalshikin);
	}
	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 43096
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0) {
				break;
			}
			int s = scanner.nextInt();
			int g = scanner.nextInt();
			int d = scanner.nextInt();
			boolean[][] map = new boolean[d + 1][n + 1];
			for (int i = 1; i <= d; i++) {
				String line = scanner.next();
				for (int j = 1; j < n; j++) {
					if (line.charAt(j - 1) == '1') {
						map[i][j] = true;
					}
				}
			}
			boolean flag = false;
			loop:
			for (int i = 0; i <= d; i++) {
				for (int j = 1; j < n; j++) {
					if (!map[i][j - 1] && !map[i][j] && !map[i][j + 1]) {
						int x = s;
						map[i][j] = true;
						for (int k = 1; k <= d; k++) {
							if (map[k][x - 1]) {
								x--;
							} else if (map[k][x]) {
								x++;
							}
						}
						if (g == x) {
							if (i == 0) {
								System.out.println(0);
							} else {
								System.out.println(i + " " + j);
							}
							flag = true;
							break loop;
						}
						map[i][j] = false;
					}

				}
			}if(!flag){
				System.out.println(1);
			}
		}
	}
}

Measured memory_bytes: 20628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  set<int> s;
  int n;
  cin >> n;
  rep(i,n){
    int a;
    cin >> a;
    s.insert(a);
  }
  if(s.size()==n) cout << "YES" << endl;
  else cout << "NO" << endl;

  
  return 0;
    

}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++) 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
//zアルゴリズムでも解く

//最長共通接頭辞を求める
vector<int> Z_algorithm(const string &s){
    vector<int> ret(s.size(),0);
    int c=0;
    for(int i=1,j=0;i<s.size();i++){
        //文字列のjからiまでと0からi-jまでは一致
        if(i+ret[i-j]<j+ret[j]){
            ret[i]=ret[i-j];
        }
        else{
            //覆えずにはみ出す場合
            int k=max(0,j+ret[j]-i);
            while(i+k<s.size()&&s[k]==s[i+k])k++;
            ret[i]=k;
            j=i;
        }
    }
    ret[0]=s.size();
    return ret;
}

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

    int ans=0;
    for(int i=0;i<n-1;i++){
        string t=s.substr(i,n-i);
        auto v=Z_algorithm(t);
        int tmp=0;
        for(int j=1;j<v.size();j++){
            if(v[j]>tmp){
                //重ならないか
                if(j>=v[j]) tmp=v[j];
            }
        }
        ans=max(ans,tmp);
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

struct Job {
    uint32_t time;
    uint32_t dead_end;
};

bool compareJob(const Job& a, const Job& b)
{
    return (a.dead_end < b.dead_end);
}

/*
 No
3
2 4
2 3
1 1
 Yes
3
1 1
1 2
1 3

 Yes
3
1 1
1 2
2 4

 Yes
 3
 2 2
 2 5
 3 9

 Yes
3
2 20
2 20
3 20
*/

int main(int argc, const char * argv[]) {
    int N = 0;
    cin >> N;

    vector<Job> jobs;
    jobs.reserve(N);

    for(int i = 0; i < N; i++) {
        Job job = {0};
        cin >> job.time >> job.dead_end;
        jobs.push_back(job);
    }

    sort(jobs.begin(), jobs.end(), compareJob);

    int32_t now = 0;
    for(auto job : jobs) {
        now += job.time;
        if(job.dead_end < now) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

//20180509
//04

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

		while (scanner.hasNextLine()) {
			int n = scanner.nextInt();
			int x = scanner.nextInt();
			int count = 0;

			if(n + x == 0) {
				break;
			}

			for(int i = 1;i <= n;i++) {
				for(int j = i + 1;j <= n;j++) {
					for(int k = j + 1;k <= n;k++) {
						if(i + j + k == x) {
							count++;
						}
					}
				}
			}
			System.out.println(count);
		}
		scanner.close();
    }
}


Measured memory_bytes: 27096
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stdio.h>
#include <math.h>

//#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;

typedef pair<int, int> pii;

typedef queue<int> qi;
typedef queue<string> qs;


#define rep(i, n) for(int i=0; i<(n); ++i)
#define repp(i, a, b) for(int i = (a); i <= (b); i++)
#define Rep(i, n) for(int i=n; i >= 0; i--)

#define all(v) v.begin(), v.end()
//sort( all(v) )　などと使える

const ll INF = pow(10, 9);

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

    int a = n/1000;
    int b = n%1000 /100;
    int c = n%100 /10;
    int d = n%10;

    if(a == b && b == c){
        cout << "Yes" << endl;
    }
    else if(b == c && c == d){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]

ans = []
for i in range(H):
    for j in range(W - 1):
        if A[i][j] % 2 == 0:
            continue
        A[i][j] -= 1
        A[i][j + 1] += 1
        ans.append((i, j, i, j + 1))

for i in range(H - 1):
    if A[i][W - 1] % 2 == 0:
        continue
    A[i][W - 1] -= 1
    A[i + 1][W - 1] += 1
    ans.append((i, W - 1, i + 1, W - 1))

print(len(ans))
for v in ans:
    print(v[0] + 1, v[1] + 1, v[2] + 1, v[3] + 1)


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



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

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t
#include <math.h>

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}

int get_int3(int *a1, int *a2, int *a3) {
  scanf("%d %d %d", a1, a2, a3);
  return 0;
}

int get_int4(int *a1, int *a2, int *a3, int *a4) {
  scanf("%d %d %d %d", a1, a2, a3, a4);
  return 0;
}

int get_int5(int *a1, int *a2, int *a3, int *a4, int *a5) {
  scanf("%d %d %d %d %d", a1, a2, a3, a4, a5);
  return 0;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(int *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        scanf("%d", &arr[i]);
    }
    return 0;
}
#define NUM_MAX 2000
#define INF (1e+9)

int main() {
    int num, xscore, yscore;
    get_int3(&num, &xscore, &yscore);
    static int arr[NUM_MAX];
    fget_array(arr, num);

    static int dp[NUM_MAX+1][2];
    int last = arr[num-1];
    int i, j;
    int prev_x = INF;
    int prev_y = 0;
    for (i = num-1; i >= 0; i--) {
        int Y = (i ? arr[i-1] : yscore);
        dp[i][0] = max(abs(Y - last), prev_y);
        prev_x = min(prev_x, dp[i][0]);
        int X = (i ? arr[i-1] : xscore);
        dp[i][1] = min(abs(X - last), prev_x);
        prev_y = max(prev_y, dp[i][1]);
    }
    printf("%d\n", dp[0][0]);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const long long int MOD=1000000007LL;
int main(){
  long long int n,m;
  cin>>n>>m;
  vector<long long int> x(n);
  vector<long long int> y(m);
  for(int i=0;i<n;i++){
    cin>>x[i];
  }
  for(int i=0;i<m;i++){
    cin>>y[i];
  }
  vector<long long int> xed(n-1);
  vector<long long int> yed(m-1);
  for(int i=0;i<n-1;i++){
    xed[i]=x[i+1]-x[i];
    xed[i]%=MOD;
  }
  for(int i=0;i<m-1;i++){
    yed[i]=y[i+1]-y[i];
    yed[i]%=MOD;
  }

  long long int xside=0;
  long long int yside=0;
  for(long long int i=0;i<n-1;i++){
    xside+=((((i+1)*(n-1-i))%MOD)*xed[i])%MOD;
    xside%=MOD;
  }
  for(long long int i=0;i<m-1;i++){
    yside+=((((i+1)*(m-1-i))%MOD)*yed[i])%MOD;
    yside%=MOD;
  }
  long long int res=((yside*xside)%MOD+MOD)%MOD;
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 3328
import java.util.*;
import java.text.*;

class Main {
    public static void main(String[]args)throws Exception {
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int c = sc.nextInt();
        int [][] a = new int[r][c];
        int [] rs = new int[c];
        int [] cs = new int[r];
        int s = 0;
        for(int i = 0; i < r; i++) {
            for(int j = 0; j < c; j++) {
                a[i][j] = sc.nextInt();
                cs[i] += a[i][j];
                rs[j] += a[i][j];
                s += a[i][j];
            }
        }
        for(int i = 0; i < r; i++) {
            for(int j = 0; j < c; j++) {
                System.out.print("" + a[i][j] + " ");
            }
            System.out.println(cs[i]);
        }
        for(int j = 0; j < c; j++) {
            System.out.print("" + rs[j] + " ");
        }
        System.out.println(s);
    }
}

Measured memory_bytes: 37768
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <deque>
#include <cassert>

using namespace std;

#define print(x) cout << x << endl
#define input(x) cin >> x

typedef long long llint;

int main() {
    int n, d, a;
    input(n >> d >> a);

    vector<pair<llint, llint> > ps(n);
    for (int i = 0; i < n; i++) {
        scanf("%lld%lld", &ps[i].first, &ps[i].second);
    }
    sort(ps.begin(), ps.end());

    llint tot = 0;
    llint res = 0;
    deque<pair<llint, llint> > q;

    vector<pair<llint, llint> > bombs;

    for (auto p : ps) {
        llint x = p.first;
        llint h = p.second;

        while (!q.empty()) {
            llint bx = q.begin()->first;
            llint bh = q.begin()->second;

            if (x > bx) {
                tot -= bh;
                assert(tot >= 0);
                q.pop_front();
            } else {
                break;
            }
        }

        if (h > tot) {
            llint rem = h - tot;
            assert(rem > 0);
            llint b = (rem + a - 1) / a;
            res += b;
            tot += 1LL * b * a;
            q.push_back({x + 2LL * d, 1LL * b * a});

            bombs.push_back({x + d, b});
        }
    }
    print(res);

    /*
    for (auto bomb : bombs) {
        llint pos = bomb.first;
        llint cnt = bomb.second;

        for (auto& p : ps) {
            if (p.first >= pos - d && p.first <= pos + d) {
                p.second = max(0LL, p.second - 1LL * cnt * a);
            }
        }
    }

    for (int i = 0; i < n; i++) {
        auto p = ps[i];
        print(i << ' ' << ps[i].first << ' ' << ps[i].second);
        assert(p.second == 0);
    }
    */

    return 0;
}


Measured memory_bytes: 8944
#include<bits/stdc++.h>
using namespace std;
const int MAX=210000;
const long long MOD=998244353;

typedef long long ll;

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

ll mod_pow(ll x, ll n){ //べき乗
    ll ans=1;
    x%=MOD;
    while(n!=0){
        if(n&1) ans=ans*x%MOD;
        x=x*x%MOD;
        n=n>>1;
    }
    return ans%MOD;
}

void com_init(){ //初期化
    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;
        finv[i]=finv[i-1]*mod_pow(i,MOD-2)%MOD;//フェルマーの小定理より
    }
}

ll comb(ll n, ll k){ //nCk
    if(n<k) return 0;
    if(n<0||k<0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

int main(){
    ll N,M,K; cin >> N >> M >> K;
    com_init();
    ll ans=0;
    for(int i=0;i<=K;i++){
        ans+=((M*comb(N-1,i))%MOD*mod_pow(M-1,N-1-i))%MOD;
        ans%=MOD;
    }
    ans%=MOD;
    cout << ans << endl;
}

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

using namespace std;

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

	pair<long long, long long> p = { 1, 1 };
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		pair<long long, long long> x;
		cin >> x.first >> x.second;
		long long cnf = (p.first + x.first - 1) / x.first; 
		long long cns = (p.second + x.second - 1) / x.second; 
		long long cn = max(cnf, cns);
		p = { x.first * cn, x.second * cn };
	}
	cout << p.first + p.second << '\n';

	return 0;
}



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

using namespace std;

int const N = 1e5 + 100;
int p[N], n, m, id = 0;
vector<int> g[N];
int vis[N], col[N];

void DFS(int u){
    vis[u] = id;
    col[p[u]] = id;
    
    for(int i = 0;i < g[u].size();++i){
        int v = g[u][i];
        if(!vis[v]) DFS(v);
    }
}

int main()
{   
    scanf("%d%d", &n, &m);
    for(int i = 1;i <= n;++i) scanf("%d", &p[i]);
    
    for(int i = 0, x, y;i < m;++i){
        scanf("%d%d", &x, &y);
        g[x].push_back(y);
        g[y].push_back(x);
    }
    
    for(int i = 1;i <= n;++i){
        if(!vis[i]){
            id++;
            DFS(i);
        }
    }
    
    int ans = 0;
    for(int i = 1;i <= n;++i){
        if(vis[i] == col[i]) ans++;
    }
    
    printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 8960
///#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
///#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,popcnt,avx,avx2,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

/*
    zet:
        find_by_order(k): k-stat [k > 0]
        order_of_key(k) : {el < k}

    gp_hash_table<key, val, custom_hash>

    rope<T>:
        iterators: mutable_begin, ..
        methods  : erase, insert, substr, ..
*/

#define all(x) (x).begin(), (x).end()
#define size(x) (int)((x).size())
#define em_back emplace_back

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<typename T>
using zet = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

mt19937 eng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e5 + 4;

int n, a[N];

void solve() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    ll res = a[0] - 1;
    int last = 2;
    for (int i = 1; i < n; ++i) {
        if (a[i] == last) {
            ++last;
            continue;
        }
        if (a[i] < last) {
            continue;
        }

        int k = a[i] / last - (a[i] % last == 0) - 1;

        a[i] -= k * last;

        if (a[i] - last != last) {
            a[i] -= last;
            ++k;
        } else {
            a[i] -= last + 1;
            ++k;
        }

        res += k;
    }
    cout << res << "\n";
}

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

    int z = 1;
    /// cin >> z;

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

    return 0;
}


Measured memory_bytes: 3972
#include <iostream>
#include <string>
using namespace std;
int main(void){
  string s,t;
  cin >> s >> t;
  
  if(s[0] == t[2] && s[1] == t[1] && s[2] == t[0])
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	string n;
  	cin >> n;
  	if(n.at(0) == '7' || n.at(1) == '7' || n.at(2) == '7') cout << "Yes" << endl;
  	else cout << "No" << endl;
 }

Measured memory_bytes: 3624
#include<cstdio>
struct UF{
  int u[100001],cl[100001];
  void init(int x){
    for(int i=0;i<x;i++){
      u[i] = i;
      cl[i] = 0;
    }
  }
  void unite(int x,int y){
    x = find(x);
    y = find(y);
    if(club(x) == 0) cl[x] = club(y);
    if(club(y) == 0) cl[y] = club(x);
    if(x > y) u[x] = y;
    if(y > x) u[y] = x; 
  }
  int find(int x){
    if(x != u[x]) u[x] = find(u[x]);
    return u[x];
  }
  int club(int x){
    return cl[find(x)];
  }
  void in(int x,int y){
    cl[find(x)] = y;
  }
};
int main(){
  int n,m,k,a,b,c,fl=0;
  UF uf;
  scanf("%d %d %d",&n,&m,&k);
  uf.init(n);
  for(int i=1;i<=k;i++){
    scanf("%d %d %d",&a,&b,&c);
    if(a == 1 && fl == 0){
      if(uf.club(b)!=0 && uf.club(c)!=0 && uf.club(b)!=uf.club(c)) fl = i;
      else uf.unite(b,c);
    }
    if(a == 2 && fl == 0){
      if(uf.club(b) != 0 && uf.club(b) != c) fl = i;
      else uf.in(b,c);
    } 
  }
  printf("%d\n",fl);
  return 0;
}

Measured memory_bytes: 3544
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>
#include <atcoder/all>

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

#pragma GCC target ("avx2")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define repeat(i, n, m) for(int i = n; i < (m); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

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

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr ll mod = 998244353;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;
using namespace atcoder;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

template<typename T>
inline T chmin(T& a, const T& b) {
	if (a > b)a = b;
	return a;
}

template<typename T>
inline T chmax(T& a, const T& b) {
	if (a < b)a = b;
	return a;
}


/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int n, q;
	scanf("%d %d", &n, &q);
	dsu d(n);
	for (int i = 0; i < q; i++) {
		int t, u, v;
		scanf("%d %d %d", &t, &u, &v);
		if (t == 0) {
			d.merge(u, v);
		}
		else {
			if (d.same(u, v)) {
				printf("1\n");
			}
			else {
				printf("0\n");
			}
		}
	}

	Please AC;
}

Measured memory_bytes: 4092
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;

int main(){
    ll H;
    cin >> H;
    ll ans = 0, exp = 1;
    while(H > 0){
        H /= 2;
        ans += exp;
        exp *= 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys

class LowLinks:
    def __init__(self, edges, v, root=0):
        self.edges = edges
        self.root = root
        self.ord = [None] * v
        self.low = [None] * v
        self.cnt = 0
        self.bridges = []
        self.articulations = set()
        self.par = [None] * v

    def build(self):
        self.search(self.root)

    def search(self, x):
        self.ord[x] = self.cnt
        self.low[x] = self.cnt
        self.cnt += 1
        dim = 0
        for to in self.edges[x]:
            if to == self.par[x]:continue
            if self.ord[to] != None:
                self.low[x] = min(self.low[x], self.ord[to])
            else:
                self.par[to] = x
                self.search(to)
                dim += 1
                self.low[x] = min(self.low[x], self.low[to])

                if x != self.root and self.ord[x] <= self.low[to]:
                    self.articulations.add(x)

            if x == self.root and dim > 1:
                self.articulations.add(x)

            if self.ord[x] < self.low[to]:
                self.bridges.append((x, to))


sys.setrecursionlimit(1000000)
v, e = map(int, input().split())
edges = [[] for _ in range(v)]
for _ in range(e):
    s, t = map(int, input().split())
    edges[s].append(t)
    edges[t].append(s)

lowlinks = LowLinks(edges, v)
lowlinks.build()
if lowlinks.bridges:
    bridges = sorted(lowlinks.bridges, key=lambda x: (min(x), max(x)))
    for bridge in bridges:
        print(min(bridge), max(bridge))


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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define F first
#define S second
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif




int main(void) 
{


	int n; 
	scanf("%d", &n); 
	vector<int> v; 
	for (int i=0, x; i<n; i++) 
	{
		scanf("%d", &x); 
		v.eb(x); 
	}
	sort(v.begin(), v.end()); 
	bool flag = true; 
	for (int i=1; i<n; i++) 
	{
		if(v[i] == v[i-1]) 
		{
			flag = false; 
			break;
		}
	}

	if (flag) puts("YES");
	else puts("NO");



 
 
 
	return false;   
}













Measured memory_bytes: 1400
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

ll l[100010];
ll r[100010];

int main(){
  ll n;
  cin >> n;
  ll a[n];
  rep(i,n)cin >> a[i];
  l[0]=a[0];
  r[n-1]=a[n-1];
  for(int i=0;i+1<n;i++){
    l[i+1]=__gcd(l[i],a[i+1]);
  }
  for(int i=n-1;i>=1;i--){
    r[i-1]=__gcd(r[i],a[i-1]);
  }
  ll ans=max(r[1],l[n-2]);
  for(int i=1;i+1<n;i++){
    ans=max(ans,__gcd(r[i+1],l[i-1]));
  }
/*
rep(i,n){
    cout << "i:" << i << ' ' << "l[i]:" << l[i] << ' ' << "r[i]:" << r[i] << endl;
  }
*/  
  cout << ans << endl;
return 0;}

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

const int N = 3005;
int dp[N][N], transactions[N][N], sizeS, sizeT;
char s[N], t[N];

int lis(int i, int j) {
  if (i >= sizeS || j >= sizeT) return 0;
  if (dp[i][j] != -1) return dp[i][j];

  if (s[i] == t[j])
    return dp[i][j] = lis(i+1, j+1) + 1;

  int a = lis(i+1, j);
  int b = lis(i, j+1);
  if (a > b) transactions[i][j] = 1;
  else transactions[i][j] = -1;
  return dp[i][j] = std::max(a, b);
}

int32_t main() {
  scanf("%s%s", s, t);
  sizeS = strlen(s);
  sizeT = strlen(t);

  memset(dp, -1, sizeof dp);
  int ans = lis(0, 0);

  for (int i = 0, j = 0, cnt = 0; cnt < ans;) {
    if (s[i] == t[j]) {
      putchar(s[i]);
      i++, j++, cnt++;
    } else if (transactions[i][j] == 1) {
      i++;
    } else {
      j++;
    }
  }
  puts("");

  return 0;
}


Measured memory_bytes: 71168
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<cstring>
#include<math.h>
#include<string>
#include<vector>
#include<map>
#include<numeric>
#include<set>
#include<unordered_map>
using namespace std;
typedef long long ll;
int main()
{
    int n,a,b;
    cin>>n>>a>>b;
    cout<<min(b,a*n)<<endl;
}


Measured memory_bytes: 256
import sys
N,K=map(int,input().split())
if K%2==1:
    s=N//K
    print(s**3)
    sys.exit()
k=K//2
s=N//k
num=0
if s%2==0:
    print((s**3)//4)
    sys.exit()
t=((s//2+1)**2)*(s//2+1)
u=((s//2)**2)*(s//2)
print(t+u)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn=1e5+5;
int n;
char s[maxn];
int vis[maxn];
int check()
{
    for(int i=1;i<=n;i++)
    {
        int l=i-1;
        int r=i+1;
        if(l==0) l=n;
        if(r==n+1)r=1;
        if(vis[i]==1)
        {
            if(s[i]=='o'&&vis[l]!=vis[r])
                return 0;
            if(s[i]=='x'&&vis[l]==vis[r])
                return 0;
        }
        if(vis[i]==2)
        {
            if(s[i]=='o'&&vis[l]==vis[r])
                return 0;
            if(s[i]=='x'&&vis[l]!=vis[r])
                return 0;
        }
    }
    return 1;
}
void init()
{
    for(int i=2;i<n;i++)
    {
        if(vis[i]==1)
        {
            if(s[i]=='o') vis[i+1]=vis[i-1];
            else vis[i+1]=(vis[i-1]==1?2:1);
        }
        if(vis[i]==2)
        {
            if(s[i]=='o')vis[i+1]=(vis[i-1]==1?2:1);
            else vis[i+1]=vis[i-1];
        }
    }
}
int main()
{
    scanf("%d",&n);
    scanf("%s",s+1);
    vis[1]=vis[2]=1;
    init();
    if(check())
    {
        for(int i=1;i<=n;i++)
        {
            printf("%c",vis[i]==1?'S':'W');
        }
            printf("\n");
            return 0;
    }
    vis[1]=vis[2]=2;
    init();
    if(check())
    {
        for(int i=1;i<=n;i++)
        {
            printf("%c",vis[i]==1?'S':'W');
        }
        printf("\n");
        return 0;
    }
    vis[1]=1;
    vis[2]=2;
    init();
    if(check())
    {
        for(int i=1;i<=n;i++)
        {
            printf("%c",vis[i]==1?'S':'W');
        }
        printf("\n");
        return 0;
    }
    vis[1]=2;
    vis[2]=1;
    init();
    if(check())
    {
        for(int i=1;i<=n;i++)
        {
            printf("%c",vis[i]==1?'S':'W');
        }
        printf("\n");
        return 0;
    }
    printf("-1\n");
    return 0;
}


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

#define null               ""
#define endl               '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fr, to)    for (int i = fr; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int nsz = 100, mod = 1e9 + 7;
int n, dp[nsz + 5][5][5][5][5], ans;

// 0: #
// 1: A
// 2: C
// 3: G
// 4: T

bool inline chk1(int a, int b, int c) {
    if ((a == 1 && b == 2 && c == 3) ||
        (a == 2 && b == 1 && c == 3) ||
        (a == 1 && b == 3 && c == 2))  return 0;
    return 1;
}

bool inline chk2(int a, int b, int c, int d) {
    if ((a == 1 && b == 2 && d == 3) ||
        (a == 1 && c == 2 && d == 3))  return 0;
    return 1;
}

bool inline chk(int a, int b, int c, int d) {
    return chk1(a, b, c) && chk1(b, c, d) && chk2(a, b, c, d);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n;
    dp[0][0][0][0][0] = 1;
    cont (i, n) {
        cont (a, 4) {
            if (i <= 1) {
                if (i == 1) {
                    dp[1][0][0][0][a] = 1;
                }
                continue;
            }
            cont (b, 4) {
                if (i <= 2) {
                    if (i == 2) {
                        dp[2][0][0][a][b] = 1;
                    }
                    continue;
                }
                cont (c, 4) {
                    if (i <= 3) {
                        if (i == 3 && chk1(a, b, c)) {
                            dp[3][0][a][b][c] = 1;
                        }
                        continue;
                    }
                    cont (d, 4) {
                        if (i <= 4) {
                            if (i == 4 && chk(a, b, c, d)) {
                                dp[4][a][b][c][d] = 1;
                            }
                            continue;
                        }
                        if (chk(a, b, c, d)) {
                            cont (p, 4) {
                                if (chk(p, a, b, c)) {
                                    dp[i][a][b][c][d] += dp[i - 1][p][a][b][c];
                                    dp[i][a][b][c][d] %= mod;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    loop (a, 5) {
        loop (b, 5) {
            loop (c, 5) {
                loop (d, 5) {
                    ans += dp[n][a][b][c][d];
                    ans %= mod;
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
N,K = map(int,input().split())
d = {}
for n in range(N):
	a,b = map(int,input().split())
	if a in d:
		d[a] += b
	else:
		d[a] = b 
d2 = list(d)
d2.sort()
cnt = 0
for i in d2:
	cnt += d[i]
	if cnt >= K:
		print(i)
		break

Measured memory_bytes: 10588
import std.stdio,std.string,std.conv;

int main()
{
	string s;
	while((s = readln.chomp).length != 0)
	{
		string[] _s = s.split(" ");
		int a = _s[0].to!int;
		int b = _s[1].to!int;
		int c = _s[2].to!int;

		int count = 0;
		bool flag[11];
		foreach(i;1..11) flag[i] = true;

		flag[a] = false;
		flag[b] = false;
		flag[c] = false;

		foreach(i;1..11)
		{
			if(flag[i] == true && a+b+i <= 20)
			{
				count++;
			}
		}

		if(count/7.0 >= 0.5)
		{
			writeln("YES");
		}
		else
		{
			writeln("NO");
		}
	}
	return 0;
}

Measured memory_bytes: 1072
#include <bits/stdc++.h>
typedef long long int lld;
typedef unsigned long long int llu;
#define INF (lld)(9223372036854775807)
#define IINF (int)(2147483647)

using namespace std;
int main(void) {
  lld n, k, h, m;
  cin >> n >> k;
  vector<lld> c(n), p(k, 0);
  for (lld i = 0; i < n; i++) {
    cin >> h;
    if (i == 0) {
      c[0] = 0;
    } else {
      m = INF;
      for (lld j = 1; j <= k; j++) {
        if (i - j < 0) {
          break;
        }
        m = min(abs(p[(i - j) % k] - h) + c[i - j], m);
      }
      c[i] = m;
    }
    p[i % k] = h;
  }

  cout << c[n - 1] << "\n";
}

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

int main() {
  string s;
  cin >> s;
  string check="ACGT";

  int cnt=0;
  int max=-1;
  for(int i=0;i<s.size();i++){
    int flg=0;
    for(int j=0;j<4;j++){
      if(check.at(j) == s.at(i))flg=1;
    }
    if(flg==1){
      cnt++;
      if(i==s.size()-1 && max<cnt)max=cnt;
    }else {
      if(max<cnt)max=cnt;
      cnt=0;
    }
  }
  cout << max << endl;
  return 0;
}

Measured memory_bytes: 3600
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))

mod = 10 ** 9 + 7
dp = [[0] * (M + 1) for _ in range(N + 1)]

for i in range(N + 1):
	for j in range(M + 1):
		if i == 0 or j == 0:
			dp[i][j] = 1
		elif S[i - 1] == T[j - 1]:
			dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod
		else:
			dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]) % mod
			
print(dp[N][M])

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/


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


    pair<bool, ll> isok[n+1];
    rep(i,n+1) isok[i] = make_pair(false, -1);
    int c = 1;
    isok[c] = make_pair(true, c+1);
    while(c*(c+1)/2 <= n){
        isok[c*(c+1)/2] = make_pair(true, c+1);
        c++;
    }

    if(isok[n].first){
        cout << "Yes" << endl;
        int k = isok[n].second;
        cout << k << endl;

        int res[c][c-1];
        rep(i,c) rep(j,c-1) res[i][j] = 0;

        int cross = 0;
        int i = 0;
        int cnt = 1;
        while(cnt <= n){
            res[cross+i+1][cross] = cnt;
            res[cross][cross+i] = cnt;
            cnt++;
            if(cross+i+1 == c-1){
                cross++;
                i = 0;
            }else{
                i++;
            }
        }

        rep(i,c){
            cout << c-1 << " ";
            rep(j,c-1){
                cout << res[i][j];
                if(j != c-2) cout << " ";
            }cout << endl;
        }

    }else{
        cout << "No" << endl;
    }

}

Measured memory_bytes: 5912
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

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

  int h, w, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  for (auto &x: s) cin >> x;

  vector<bool> berryExists(h);
  vector<vector<int> > berryNum(h);
  vector<vector<int> > group(h, vector<int>(w));
  int m = 1;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') {
        berryExists[i] = true;
        berryNum[i].push_back(m);
        group[i][j] = m;
        m++;
      }
    }
  }

  for (int i = 0; i < h; i++) {
    if (berryExists[i]) {
      int p = 0;
      int j = 0;
      while (p < berryNum[i].size()) {
        if (group[i][j] > 0) {
          p++;
        }
        else {
          group[i][j] = berryNum[i][p];
        }
        j++;
      }
      while (j < w) {
        group[i][j] = group[i][j-1];
        j++;
      }
    }
  }

  for (int i = 1; i < h; i++) {
    if (!berryExists[i] && berryExists[i-1]) {
      for (int j = 0; j < w; j++) {
        group[i][j] = group[i-1][j];
      }
      berryExists[i] = true;
    }
  }

  for (int i = h-2; i >= 0; i--) {
    if (!berryExists[i] && berryExists[i+1]) {
      for (int j = 0; j < w; j++) {
        group[i][j] = group[i+1][j];
      }
      berryExists[i] = true;
    }
  }

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cout << group[i][j];
      if (j < w-1) cout << " ";
      else cout << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 1920
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
using namespace std;
int n,m,i,j,a[5][100005],b[100005],rev0,rev1;
struct bit
{
	int a[100005];
	int lowbit(int x)
	{
		return x&-x;
	}
	void add(int x,int y)
	{
		x=n-x+1;
		int i;
		for(i=x;i<=n;i+=lowbit(i)){
			a[i]+=-y;
		}
	}
	int query(int x)
	{
		x=n-x+1;
		int i,s=0;
		for(i=x;i;i-=lowbit(i)){
			s+=a[i];
		}
		return s;
	}
}c0,c1;
void gugu()
{
	puts("No");
	exit(0);
}
int main()
{
	scanf("%d",&n);
	fz1(i,3){
		fz1(j,n){
			scanf("%d",&a[i][j]);
		}
	}
	fz1(i,n){
		int t=(a[1][i]+2)/3;
		if(min(min(a[1][i],a[2][i]),a[3][i])!=t*3-2) gugu();
		if(max(max(a[1][i],a[2][i]),a[3][i])!=t*3) gugu();
		if(a[1][i]<a[2][i]&&a[2][i]<a[3][i]){
			b[i]=t;
		}
		else if(a[1][i]>a[2][i]&&a[2][i]>a[3][i]){
			b[i]=-t;
		}
		else gugu();
	}
	for(i=1;i<=n;i+=2){
		if(b[i]<0){
			b[i]=-b[i];
			rev1^=1;
		}
		if(b[i]%2==0) gugu();
	}
	for(i=2;i<=n;i+=2){
		if(b[i]<0){
			b[i]=-b[i];
			rev0^=1;
		}
		if(b[i]%2==1) gugu();
	}
	for(i=1;i<=n;i+=2){
		if(c0.query(b[i])&1) rev0^=1;
		c0.add(b[i],1);
	}
	for(i=2;i<=n;i+=2){
		if(c1.query(b[i])&1) rev1^=1;
		c1.add(b[i],1);
	}
	if(rev0||rev1) gugu();
	puts("Yes");
	return 0;
}

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

int main(void)
{
    int A, B;
    cin >> A >> B;

    int sum = 1, counter = 0;
    while (sum < B)
    {
        sum--;
        sum += A;
        counter++;
        // printf("sum = %d, counter = %d\n", sum, counter);
    }
    cout << counter << endl;
    return (0);
}

Measured memory_bytes: 256
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion


void Main();
void solve(long long A, long long B);

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main(){
    ll A, B;
    cin >> A >> B;
    B--;A--;

    ll C = B/A;
    if(B%A!=0){
        C++;
    }
    cout << C << el;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <random>
#include <fstream>
#include <time.h>
#define int long long
#define debug(x) cerr << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1000000007;
const ll LINF = 1e18;
const double EPS = 1e-9;


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

  int n,m,c;
  cin>>n>>m>>c;
  int b[m];
  rep(i,m) cin>>b[i];
  int a[n][m];
  rep(i,n) {
    rep(j,m) cin>>a[i][j];
  }
  int ans = 0;
  rep(i,n) {
    int sum = 0;
    rep(j,m) {
      sum += a[i][j] * b[j];
    }
    sum += c;
    if(sum > 0) {
      ans++;
    }
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
 
def main():
	n = list(map(int, input().split()))
	x = abs(n[0] - n[2])
	y = abs(n[1] - n[3])
	if n[0] < n[2]:
		if n[1] < n[3]:
			print(n[2]-y,n[3]+x,n[0]-y,n[1]+x)
		else:
			print(n[2]+y,n[3]+x,n[0]+y,n[1]+x)
	else:
		if n[1] > n[3]:
			print(n[2]+y,n[3]-x,n[0]+y,n[1]-x)
		else:
			print(n[2]-y,n[3]-x,n[0]-y,n[1]-x)


if __name__ == '__main__':
	main()

Measured memory_bytes: 3064
#include <algorithm>
#include <cstring>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
const int inf = 1 << 30;
const int INF = INT_MAX;

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k, h[100010];
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> h[i];
  }
  sort(h, h + n);
  int m = INT_MAX;
  for (int i = 0; i + k <= n; ++i) {
    int diff = h[i + k - 1] - h[i];
    m = min(m, diff);
  }
  cout << m << endl;
  return 0;
}

Measured memory_bytes: 640