akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline

n,m = map(int,input().split())

root = [[] for _ in range(n)]

for i in range(m):
    a,b = map(int, input().split())
    root[a-1].append(b-1)
    root[b-1].append(a-1)

#print(root)

count = 0
q = [0]
ans = [-1]*n

while q:
    l = q.pop(0)
    for i in root[l]:
        if ans[i] == -1:
            ans[i] = l
            q.append(i)
            count += 1
    if count  == n:
        break

if count == n:
    print("Yes")
    for i in range(1,n):
        print(ans[i]+1)

else:
    print("No")


Measured memory_bytes: 34228
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int num,n,x,p[1024],sum  = 0,minn = 156165156;
	scanf("%d%d",&n,&x);
	 for(int i = 1;i<=n;i++){
	 	scanf("%d",&p[i]);
	 	sum+=p[i];
	 	minn=minn<p[i]?minn:p[i];
	 }
	 int ans=(x-sum)/minn+n;
	 printf("%d\n",ans);
	 return 0;
}

Measured memory_bytes: 256
const Main = input => {
    input = input.split("\n");
    const n = parseInt(input[0], 10);
    input.shift();
    const s = input;

    let ac = 0;
    let wa = 0;
    let tle = 0;
    let re = 0;

    for(let i = 0; i < n; i++) {
        switch(s[i]) {
            case "AC":
                ac++;
                break;
            case "WA":
                wa++;
                break;
            case "TLE":
                tle++;
                break;
            case "RE":
                re++;
                break;
            default:
                break;
        }
    }

    console.log(`AC x ${ac}
WA x ${wa}
TLE x ${tle}
RE x ${re}`);
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

const int maxn=100;

bool vis[maxn][maxn][maxn];
int ans;
int a, b, c, maxnum;

void dfs(int a, int b, int c, int s)
{
	if (s>=ans) return;
	if (a>maxnum || b>maxnum || c>maxnum) return;
	if (vis[a][b][c]) return;
	if (a==b && a==c)
	{
		ans=s;
		return;
	}
	vis[a][b][c]=true;
	dfs(a+2, b, c, s+1);
	dfs(a, b+2, c, s+1);
	dfs(a, b, c+2, s+1);
	dfs(a+1, b+1, c, s+1);
	dfs(a+1, b, c+1, s+1);
	dfs(a, b+1, c+1, s+1);
}
int main()
{
	scanf("%d%d%d", &a, &b, &c);
	maxnum=max(a, max(b, c))+10;
	ans=0x3fffffff;
	dfs(a, b, c, 0);
	printf("%d\n", ans);
	return 0;
}

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


int main() {
  int n, a, b;
  cin >> n >> a >> b;
  int ans = b;
  if((n*a) < b) ans = n*a;
  cout << ans << endl;
  return 0;
  
}

Measured memory_bytes: 256
def hasB(A, B, M, x, y):
  has = True
  for i in range(M):
    for j in range(M):
      if A[y + i][x + j] != B[i][j]:
        has = False
  return has


N, M = list(map(lambda x: int(x), input().split(" ")))
A = []
B = []
for i in range(N):
  A.append(list(input()))
for j in range(M):
  B.append(list(input()))

has = False
for i in range(N - M + 1):
  for j in range(N - M + 1):
    if A[i][j] == B[0][0]:
      has = hasB(A, B, M, j, i)
      if has:
        break
  else:
    continue
  
  break

print("Yes") if has else print("No")

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
#define myCeil(dividend, divisor) ceil((double)(dividend) / (double)(divisor))
#define myFloor(dividend, divisor) floor((double)(dividend) / (double)(divisor))
#define calcDigits(num) floor(log10(num))+1

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl;
#define dv(name, value) cerr << (name) << " is " << (value) << endl;
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl;
#define dpa(v) cerr << "[ " << endl;REPI(itr, v) { cerr << "  [" << (*itr).first << ", " << (*itr).second << ']' << (itr != --v.end() ? "," : "") << endl; } cerr << "]" << endl;


void solve(long long r){
 cout << r * r * 3 << endl;
}

signed main(){
  long long r;
  scanf("%lld",&r);
  solve(r);
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
X = [0] * N

X[0] = sum(A) - 2 * (sum([A[i] for i in range(N) if i % 2 == 1]))

for i in range(N - 1):
    X[i + 1] = 2 * A[i] - X[i]

print(" ".join(map(str, X)))


Measured memory_bytes: 19148
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<"\n";
#define imod(a , n) (a % n + n ) % n ;
#define int long long
const double eps = 1e-9 , PI = acos(-1) ;
const int N = 1e3 + 3 , oo = 1e9 , M = 30;


int32_t main(){
   int ans , a;
   for(int x = 1 ;x < 6 ;x++){
    cin >> a ;
    if(!a)ans = x;
   }
   cout << ans ;


    return 0;
}


Measured memory_bytes: 3560
import numpy as np

N = int(input())
A = list(map(int, input().split()))

a = np.array(A)
cnt = 0
end = 0

while cnt >= 0:
    for i in a:
        if i % 2 != 0:
            print(cnt)
            end += 1
            break
    if end == 1:
        break
    a = a/2
    cnt += 1
        

Measured memory_bytes: 27064
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <numeric>
#include <functional>
#include <cmath>
#include <cassert>
#include <string>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, ll> PL;
const ll mod = 1000000007;
const ll MOD = 1000000007;
const ll INF = 1LL << 60;
#define PI (acos(-1))

ll lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}
vector<ll> divisor(ll n)
{
    vector<ll> ret;
    for (ll i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            ret.push_back(i);
            if (i * i != n)
                ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));
    return (ret);
}

const ll MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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;
    }
}
// 二項係数計算
ll COM(ll n, ll k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll x[101],y[101],h[101];
ll solve()
{
    ll n;
    cin >> n;
    for(int i=0; i < n; i++){
        cin >> x[i] >> y[i] >> h[i];
    }

    ll CX, CY, H;
    for(int cx=0; cx < 101; cx++){
        for(int cy=0; cy < 101; cy++){
            ll H1 = -1;
            for(int i=0; i < n; i++){
                if(h[i] != 0){
                    H1 = h[i] + abs(x[i] - cx) + abs(y[i] - cy);
                    break;
                }
            }
            bool f = true;
            for (int i = 0; i < n; i++){
                ll H2 = max(H1-  abs(x[i] - cx) - abs(y[i] - cy),0LL);
                if(H2 != h[i]){
                    f = false;
                    break;
                }
            };
            
            if(f){
                cout << cx << " " << cy << " " << H1 << endl;
                return 0;
            }
        }
    }


    return 0;
}

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

    solve();
}


Measured memory_bytes: 256
N = int(input())
T,A = map(int,input().split())
H = list(map(int,input().split()))

tmp = 1000
ans = 0
for i in range(len(H)):
    tmp_ = abs(A-(T-H[i]*0.006))
    if tmp_<tmp:
        ans = i
        tmp = tmp_
print(ans+1)


Measured memory_bytes: 3060
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt(),b = sc.nextInt();
    if(a <= b){
      System.out.println(a);
    }else{
      System.out.println(a - 1);
    }
  }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;
const int mod1=998244353;

int n,k;
ll ans=4000000000000000000;
vector<pair<ll,ll>> a;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> k;
	a.resize(n);
	rep(i,n) cin >> a.at(i).first >> a.at(i).second;
	sort(a.begin(),a.end());
	ll ans=4000000000000000000;
	if(k==2){
		rep(i,n){
			rep(j,n){
				if(i==j) continue;
				ans=min(ans,abs(a.at(i).first-a.at(j).first)*abs(a.at(i).second-a.at(j).second));
			}
		}
	}
	else if(k==3){
		rep(i,n){
			rep(j,n){
				if(i==j) continue;
				rep(l,n){
					if(i==l || j==l) continue;
					ans=min(ans,abs(max(a.at(i).first,max(a.at(j).first,a.at(l).first))-min(a.at(i).first,min(a.at(j).first,a.at(l).first)))*abs(max(a.at(i).second,max(a.at(j).second,a.at(l).second))-min(a.at(i).second,min(a.at(j).second,a.at(l).second))));
				}
			}
		}
	}
	else{
		rep(i,n){
			for(int j=i+1;j<n;++j){
				for(int l=j+1;l<n;++l){
					for(int m=l+1;m<n;++m){
						ll maxx=max(a.at(i).first,max(a.at(j).first,max(a.at(l).first,a.at(m).first)));
						ll minx=min(a.at(i).first,min(a.at(j).first,min(a.at(l).first,a.at(m).first)));
						ll maxy=max(a.at(i).second,max(a.at(j).second,max(a.at(l).second,a.at(m).second)));
						ll miny=min(a.at(i).second,min(a.at(j).second,min(a.at(l).second,a.at(m).second)));
						int cnt=0;
						rep(o,n){
							if(a.at(o).first>=minx && a.at(o).first<=maxx && a.at(o).second>=miny && a.at(o).second<=maxy) cnt++;
						}
						if(cnt>=k) ans=min(ans,(maxx-minx)*(maxy-miny));
					}
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0;i<(ll)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;
const ll INF = 1e9;
int main(){
    fast_io
    
    int n;
    cin>>n;
    vector<int> t(n+1), x(n+1), y(n+1);
    t[0]=0;
    x[0]=0;
    y[0]=0;
    for(int i=1;i<=n;i++) cin>>t[i]>>x[i]>>y[i];

    for(int i=0;i<n;i++){
        int dt=t[i+1]-t[i];
        int dx=abs(x[i+1]-x[i]);
        int dy=abs(y[i+1]-y[i]);

        if(dt<dx+dy){
            cout<<"No"<<endl;
            return 0;
        }
        if(dt%2!=(dx+dy)%2){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;

int main(){
	int n,m;
	cin >> n >> m;
	
	vector<pair<int,int> > v(n);
	
	for(int i=0;i<n;++i){
		int a,b;
		cin >> a >> b;
		pair<int,int> p = pair<int,int>(a,b);
		v[i] = p;
	}
	sort(v.begin(),v.end());
	
	unsigned long long int res = 0;
	priority_queue<long long int> pq;
	int c = 0;
	//cout << "--"<<endl;
	for(int i=1;i<=m;++i){
		while(c < n && v[c].first <= i){
			pq.push(v[c].second);
			//cout << "insert " << c << " " <<v[c].first << " " << v[c].second <<endl;
			c++;
		}
		if(!pq.empty() ){
			int a =pq.top();pq.pop();
			res += a;
			//cout << i << " " << a << " " << endl;
		}
	}
	
	cout << res << endl;
	
	return 0;
}



Measured memory_bytes: 2168
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	var H, N int
	x := 0

	fmt.Scanf("%d %d", &H, &N)

	for i := 0; i < N; i++ {
		x += nextInt()
	}

	if H <= x {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int n,k,ans,p;
int o[12][6]=
{
    {4,2,0,9,7},
    {1,10,8,6,4},
    {9,7,5,3,1},
    {6,4,2,0,9},
    {3,1,10,8,6},
    {0,9,7,5,3},
    {8,6,4,2,0},
    {5,3,1,10,8},
    {2,0,9,7,5},
    {10,8,6,4,2},
    {7,5,3,1,10}
};
int main()
{
    cin>>n>>k;
	n-=2;
    p=n%11;
	n/=11;
    ans=n*5;
    for(int i=0;i<p;i++)
    {
		for(int j=0;j<5;j++)
		{
			if(o[i][j]==k)
			{
				ans++;
			}
		}
	}
     cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;


int main()
{
	int N;
	int A[2][100];
	cin >> N;
	for (int i = 0; i < 2; i++)
		for (int j = 0; j < N; j++)
			cin >> A[i][j];

	int A1Sum[100];
	int A2Sum[100];
	A1Sum[0] = A[0][0];
	A2Sum[0] = A[1][0];
	for (int i = 1; i < N; i++) {
		A1Sum[i] = A1Sum[i - 1] + A[0][i];
		A2Sum[i] = A2Sum[i - 1] + A[1][i];
	}

	int maxv = 0;
	for (int i = 0; i < N; i++) {
		maxv = max(maxv, A1Sum[i] + (A2Sum[N - 1] - (i==0 ? 0 : A2Sum[i-1])));
	}
	cout << maxv << endl;

    return 0;
}


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

using namespace std;

int main() {
  int X, Y;
  cin >> X >> Y;
  for (int i = 0; i <= X; i++) {
    int j = X - i;
    int legs = 2 * i + 4 * j;
    if (legs == Y) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
using namespace std;

int n;
ll k;
vector<ll>a,f;
bool C(ll mid){
    ll cnt=0;
    rep(i,n){
        if(a[i]*f[i]>mid){
            cnt+=(a[i]*f[i]-mid+f[i]-1)/f[i];//切り上げを忘れない
        }
    }
    return cnt<=k;
}

void solve(){
    cin>>n>>k;
    a.resize(n);f.resize(n);
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>f[i];
    sort(begin(a),end(a));
    sort(f.rbegin(),f.rend());
    //最大の積を二分探索で決め打ち
    ll lb=-1,ub=1e12,mid;
    while(ub-lb>1){
        mid=(lb+ub)/2;
        if(C(mid))ub=mid;
        else lb=mid;
    }
    cout<<ub<<"\n";
}
 
signed main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
	cout<<fixed<<setprecision(15);
	solve();
	return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define M 1000000007
int main(){
  int n;
  cin>>n;
  vector<double> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  double c=(a[0]+a[1])/2.0;
  for(int i=2;i<n;i++){
    c=(c+a[i])/2.0;
  }
  cout<<fixed<<setprecision(10)<<c;
}

Measured memory_bytes: 256
def runlen(a):
    n = len(a)
    result = []
    count = 1
    for i in range(n):
        if i == n - 1 or a[i] != a[i + 1]:
            result.append((count, a[i]))
            count = 1
        else:
            count += 1
    return result

def f(s):
    rl = runlen(s)
    result = ""
    for (count, c) in rl:
        result += str(count)
        result += c
    return result

def apply(f, n, x):
    for _ in range(n):
        x = f(x)
    return x

while True:
    n = int(input())
    if n == 0:
        break
    s = input().strip()
    print(apply(f, n, s))


Measured memory_bytes: 6956
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int N,D,X,tmp;
	cin >> N >> D >> X;
	int ans = 0;
	for (int i = 0;i <N;i++){
		cin >> tmp;
		int x = 0;
		while(x +1 <=D){
			x += tmp;
			ans++;
		}
	}
	ans += X;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(ReadLine());
            var a = int.Parse(ReadLine());

            n = n % 500;
            WriteLine(n <= a ? "Yes" : "No");
        }
    }
}



Measured memory_bytes: 13140
#include<bits/stdc++.h>
 
using namespace std;
int main()
 
{
int a,b,c;
cin >> a >> b >> c;
      int ans;
 
      if(a == b&& b  == c){
            ans =1;
      }else if((a == b && b != c)||(b == c && c != a) || ( a == c && c != b)){
            ans = 2;
      }else{
            ans = 3;
      }
      cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(){
    char a[1000][1001] = {0};
    int b[1000] = {0};
    for(int i = 0; i < 1000; i++){
        for(int j = 0; j < 1001; j++){
            scanf("%c", &a[i][j]);
            if(a[i][j] == '\n') break;
            b[i] += a[i][j] - '0';
        }
        if(a[i][0] == '0') break;
    }
    for(int i = 0; i < 1000; i++){
        if(b[i] == 0) break;
        cout << b[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 4152
def main():
    N = int(input())
    A1 = list(map(int, input().split()))
    A2 = list(map(int, input().split()))
    A1sum = [0] * (N+1)
    A2sum = [0] * (N+1)
    for i in range(N):
        A1sum[i+1] = A1sum[i] + A1[i]
        A2sum[i+1] = A2sum[i] + A2[i]
    ans = 0
    for i in range(N):
        ans = max(ans, A1sum[i+1] + A2sum[N] - A2sum[i])
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
def main():
    N, M, X = (int(i) for i in input().split())
    a = [int(i) for i in input().split()]
    route = [None for i in range(N+1)]
    route = []
    for i in range(N+1):
        if (i == 0) or (i == N) or (i == X):
            ret = False
        elif i in a:
            ret = True
        else:
            ret = None
        route.append(ret)
    min_0 = route[:X].count(True)
    min_N = route[X:].count(True)
    print(min(min_0, min_N))

if __name__ == '__main__':
    main()

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

int main() {
  int n, val;
  scanf("%d", &n);
  int count = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &val);
    // cout << val << endl;
    while (val % 2 == 0) {
      val /= 2;
      count++;
    }
  }

  printf("%d\n", count);

  return EXIT_SUCCESS;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(int i = 1; i <= (int)(n); i++)
const long long INF = 1LL << 60;
const double PI=3.14159265358979323846;

struct Node{
    int key;
    Node *parent,*left,*right;
};
Node *root,*NIL;

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

    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

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

void inorder(Node *u){
    if(u == NIL) return;
    inorder(u->left);
    cout << " " << u->key;
    inorder(u->right);
}

void preorder(Node *u){
    if(u == NIL)return;
    cout << " " << u->key;
    preorder(u->left);
    preorder(u->right);
}

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

Node *getminimum(Node *u){
    while(u->left != NIL){
        u=u->left;
    }
    return u;
}

Node *nextnodepoint(Node *u){
    if(u->right != NIL){
        return getminimum(u->right);
    }
    else{
        Node *y;
        y = u->parent;
        while(y != NIL && u==y->right){
            u=y;
            y=y->parent;
        }
        return y;
    }
}

void Delete(int k){
    Node *u,*x,*y;
    u=find(root,k);

        if(u->left == NIL && u->right == NIL){
            y=u;
            x=y->right;
        }
        
        else if(u->left != NIL && u->right != NIL){
            y=nextnodepoint(u);
            x=y->right;
        }
        else{
            y=u;
            if(u->left == NIL)
                x=u->right;
            else
                x=u->left;
        }
        if(x != NIL){
            x->parent = y->parent;
        }


        if(y == root){
            root=x;
        }
        else if(y->key < y->parent->key)
            y->parent->left = x;
        else
            y->parent->right = x;

        if(y != u)
            u->key = y->key;

        free(y);


}
int main() 
{
    int n,x;
    string com;
    cin >> n;
    rep(i,n){
        cin >> com;
        if(com == "insert"){
            cin >> x;
            insert(x);
        }
        else if(com=="delete"){
            cin >> x;
            Delete(x);
        }
        else if(com == "find"){
            cin >> x;
            if(find(root,x)!=NIL)
                cout << "yes" << endl;
                else
                    cout << "no" << endl;
        }
        else if(com == "print"){
            inorder(root);
            cout << endl;
            preorder(root);
            cout << endl;
        }
    }

}


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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int n;cin>>n&&n;){
		vi ds(n);
		rep(i,n) cin>>ds[i];
		int m; cin>>m;
		vi ts(m);
		rep(i,m) cin>>ts[i];

		map<int,int> f;
		rep(i,n) f[ds[i]]++;
		bool ok=true;
		rep(i,m){
			ok&=f[ts[i]]>0;
			f[ts[i]]--;
		}
		cout<<(ok?"YES":"NO")<<endl;
	}
}


Measured memory_bytes: 11264
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner scanner = new Scanner(System.in);
	//char配列に入れる[a][a][b][b]
    char[] array = scanner.next().toCharArray();
	
    //被りカウンター
    int count = 0;

    for(int i = 0; i < array.length; i++) {
      for(int l = 0; l < array.length; l++) {
        //同じ場所を評価しない
        if(i == l) {
          continue;
        }
        //被りがあれば１代入
        count += array[i] == array[l] ? 1 : 0;
      }
    }
    System.out.println(count == 4 ? "Yes" : "No");

    scanner.close();
  }
}

Measured memory_bytes: 21716
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <string>
using namespace std;

class ARegistration {
public:
	void solve(std::istream& in, std::ostream& out) {
        string a, b;
        in >> a >> b;
        b.pop_back();
        if (a == b) {
            out << "Yes" << endl;
        } else {
            out << "No" << endl;
        }
    }
};


int main() {
	ARegistration solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>

using namespace std;


int main()
{
    int s, w;
    cin >> s >> w;

    if (w >= s)
    {
        cout << "unsafe" << endl;
    }
    else
    { 
        cout << "safe" << endl;
    }
    return 0;
}


Measured memory_bytes: 3636
A = input()
B = input()

ans = {"1","2","3"}
ans = set(ans)

ans.remove(A)
ans.remove(B)
a = 0

if "1" in ans:
    print("1")
else:
    a = 1
if "2" in ans:
    print("2")
else:
    a = 1
if "3" in ans:
    print("3")
else:
    a = 1

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

int main(){
        int n, num[101] = {0}, max = 0;
        while(cin >> n){
                num[n]++;
                if(max < num[n]) max = num[n];
        }
        for(int i = 0; i <= 101; i++){
                if(num[i] == max) cout << i << endl;
        }
}

Measured memory_bytes: 1160
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

typedef pair<int, int> P;

int n;
vector<P> ax, ay;
vector<pair<int,P> > es;

struct UnionFindTree{
    int par[100000], rank[100000];

    void init(int k){
        for(int i=0;i<k;i++){
            par[i]=i;
            rank[i]=1;
        }
    }
    int find(int a){
        if(par[a] == a)return a;
        else{
            par[a] = find(par[a]);
            return par[a];
        }
    }
    bool same(int a, int b){
        return find(a) == find(b);
    }
    void unite(int a, int b){
        a = find(a);
        b = find(b);
        if(a == b)return;
        if(rank[a]<rank[b]){
            par[a] = b;
        }
        else{
            par[b] = a;
            rank[a]++;
        }
    }
};

int kruskal(){
    UnionFindTree g;
    g.init(n);
    int res = 0;
    for(int i=0;i<es.size();i++){
        int cost = es[i].first, u = es[i].second.first, v = es[i].second.second;
        if(g.same(u,v))continue;
        res += cost;
        g.unite(u,v);
    }
    return res;
}

int main(){
    cin >> n;
    for(int i=0;i<n;i++){
        int x,y;
        cin >> x >> y;
        ax.push_back({x,i});
        ay.push_back({y,i}); 
    }
    sort(ax.begin(),ax.end());
    sort(ay.begin(),ay.end());
    for(int i=0;i<n-1;i++){
        es.push_back({abs(ax[i+1].first-ax[i].first), {ax[i].second,ax[i+1].second}});
        es.push_back({abs(ay[i+1].first-ay[i].first), {ay[i].second,ay[i+1].second}});
    }
    sort(es.begin(),es.end());

    cout << kruskal() << endl;

    return 0;
    /*
    最小全域木の問題
    辺の数を減らすためx,yでそれぞれソートして近いもの同士をつなげる
    あとはクラスカル法で使う辺を決定
    */
}

Measured memory_bytes: 7016
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;

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

static const int MAX = 10000;
static const int INFTY = (1 << 20);

int n;
vector<pair<int, int>> adj[MAX];
int dist[MAX];

void dijkstra(int s) {
	priority_queue<pair<int, int>> PQ;
	int color[MAX];
	
	REP(i, n) {
		color[i] = 0;
	}

	dist[s] = 0;
	PQ.push(make_pair(0, s));
	color[s] = 1;

	while (!PQ.empty()) {
		pair<int, int> f = PQ.top(); PQ.pop();
		int u = f.second;
		color[u] = 2;

		//????°???????????????????????????????????????§???????????°??????
		if (dist[u] < f.first*(-1)) continue;

		REP(j, adj[u].size()) {
			int v = adj[u][j].first;
			if (color[v] == 2) continue;
			if (dist[v] > dist[u] + adj[u][j].second) {
				dist[v] = dist[u] + adj[u][j].second;
				PQ.push(make_pair(dist[v] * (-1), v));
				color[v] = 1;
			}
		}
	}

}

int main() {
	int k, u, v, c;
	cin >> n;
	REP(i, n) {
		cin >> u >> k;
		REP(j, k) {
			cin >> v >> c;
			adj[u].push_back(make_pair(v, c));
		}
	}

	REP(i, n) dist[i] = INFTY;

	dijkstra(0);

	REP(i, n) {
		cout << i << " " << (dist[i] == INFTY ? -1 : dist[i]) << endl;
	}

	return 0;
}

Measured memory_bytes: 8008
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
//#define mod 998244353ll
#define flagcount __builtin_popcount
#define flag(x) (1ll << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1ll << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return -1;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
template <typename T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b; // aをbで更新
        return true;
    }
    return false;
}
template <typename T>
bool chmin(T &a, const T &b)
{
    if (a > b)
    {
        a = b; // aをbで更新
        return true;
    }
    return false;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));
//dp[x][y][z]:x番目までみてy枚選択して合計がzになる場合の数
ll dp[55][55][2505];
int main()
{
    cout << fixed << setprecision(30);
    ll N, A;
    cin >> N >> A;
    vector<ll> x(N);
    loop(i, N) cin >> x[i];
    dp[0][0][0] = 1;
    for (ll i = 0; i < N; i++)
    {
        for (ll j = 0; j < N; j++)
        {
            for (ll k = 0; k < 2503; k++)
            {
                //i番目のものを選ぶ
                dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
                //i番目のものを選ばない
                dp[i + 1][j][k] += dp[i][j][k];
            }
        }
    }
    ll ans = 0;
    for (ll i = 1; i <= N; i++)
        ans += dp[N][i][i * A];
    putout(ans);
    return 0;
}


Measured memory_bytes: 53636
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int N, x, y ;
  	cin >> N ;
  	x = N - N % 10 ;
  	y = N - N / 1000 * 1000 ;
  
  	if (x % 111 == 0 || y % 111 == 0) {
      cout << "Yes" ;
    }
  else {
    cout << "No" ;
  }
  
}


Measured memory_bytes: 3640
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;

int main() {
	LL P;
	LL N;
	cin >> N >> P;
	LL ret=1;
	for(LL i=2;i*i<=P;i++){
		int e=0;
		while(P%i==0){
			P/=i;
			e++;
			if(e%N==0){
				ret*=i;
			}
		}
	}
	if (N==1){
		ret*=P;
	}
	cout << ret << endl;


	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
long flag[200000];

int main(void){
  long N,M;
  long a,b;
  scanf("%ld%ld",&N,&M);



  for(int i = 0;i < M;i++) flag[i] = 0;
  for(int i = 0;i < M;i++){
    scanf("%ld%ld",&a,&b);
    if(a == 1) flag[b-1]++;
    if(b == N) flag[a-1]++;
  }

  for(int i = 0;i < M;i++){
    if(flag[i] == 2){
      printf("POSSIBLE\n");
      return 0;
    }
  }
  printf("IMPOSSIBLE\n");

  return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int main () {
  int n, k;
  cin >> n >> k;

  vector <int> h(n);
  int ans;

  ans = 0;
  for (int i = 0; i < n; i++){
    cin >> h.at(i);
  }

  for (int i = 0; i < n; i++){
    if ( h.at(i) >= k){
      ans++;
    }
  }

  
  cout << ans << endl;
  
}


Measured memory_bytes: 640
h,w,k=map(int,input().split())
ori=[]
for i in range(h):
  a=str(input())
  #a=a+"."
  ori.append(a)
#ori.append("........")
#print(ori)
t=[]
y=[]
for i in range(h):
  t.append(ori[i].count("#"))
#print(t)
total=sum(t)
#print(total)
for j in range(w):
  now=0
  for i in range(h):
    noww=str(ori[i])
    #print(j,i,noww[j])
    if noww[j]=="#":
      now+=1
  y.append(now)

  
#print(t,y)

import itertools

ans=0
check=0
listate = [i for i in range(h)]
lisyoko = [i for i in range(w)]
for n in range(1,len(listate)+1):
    for tat in itertools.combinations(listate, n):
      tate=list(tat)
      for n in range(1,len(lisyoko)+1):
        for yok in itertools.combinations(lisyoko, n):
          yoko=list(yok)

          now=total
          #print(tate,yoko)
          for j in yok:
            now-=y[j]
          for i in tate:
            now-=t[i]
            noww=str(ori[i])
            for j in yok:
              if noww[j]=="#":
                now+=1
          check+=1
          if now==k:
            ans+=1
            #print(tate,yoko)
            
for n in range(1,len(listate)+1):
    for tat in itertools.combinations(listate, n):
      tate=list(tat)
      now=total
      for i in tate:
        now-=t[i]
      check+=1
      if now==k:
        ans+=1
        #print(tate)

for n in range(1,len(lisyoko)+1):
  for yok in itertools.combinations(lisyoko, n):
    yoko=list(yok)
    now=total
    for i in yoko:
      now-=y[i]
    check+=1
    if now==k:
      ans+=1
      #print(yoko)
if total==k:
  ans+=1
print(ans)
              
              
          
          
  


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

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


Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main(void) {
	int n;
	cin >> n;
	map<pair<int, int>, int> mp;
	for (int i = 1; i <= n; ++i) {
		pair<int, int> tmp;
		string s = to_string(i);
		tmp.first = s[0];
		tmp.second = s[s.size() - 1];
		++mp[tmp];
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		pair<int, int> tmp;
		string s = to_string(i);
		tmp.second = s[0];
		tmp.first = s[s.size() - 1];
		ans += mp[tmp];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int cost = 0;
        if (a > b)
            cost += b;
        else
            cost += a;
        if (c > d)
            cost += d;
        else
            cost += c;
        System.out.println(cost);
    }
}

Measured memory_bytes: 23764
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.Math;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder st = new StringBuilder();
        
        String[] ary = new String[2];
        int[] num = new int[2];
        
        while(true){
            ary = br.readLine().split(" ");
            //ary = inputStr.split(" ");
            num[0] = Integer.parseInt(ary[0]);
            num[1] = Integer.parseInt(ary[1]);
            
            if(num[0] == 0 && num[1] == 0){
                break;
            }
            
            System.out.println(Math.min(num[0], num[1]) + " " + Math.max(num[0], num[1]));
        }
        
    }
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++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;

    }
}

LL comb(int n, int k) {
    if( n < k ) return 0;
    if( n < 0 || k < 0 ) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int n, m;
    cin >> n >> m;
    bool bloke[SIZE] = {};
    
    while( m-- ) {
        int a;
        cin >> a;
        bloke[a] = true;

    }

    LL dp[SIZE];
    dp[0] = 1;
    for( int i = 1; i <= n; ++i ) {
        if( bloke[i] ) {
            dp[i] = 0;

        } else {
            if( i - 2 >= 0 ) {
                dp[i] += dp[i - 2];

            }
            dp[i] += dp[i - 1];
            dp[i] %= MOD;

        }
    }
    cout << dp[n] << endl;

    return 0;
}



Measured memory_bytes: 1280
#include <stdio.h>

int main() {
	int l , a, b, c, d, aa, bb, result = 1;
	scanf("%d %d %d %d %d", &l, &a, &b, &c, &d);
	aa = a / c;
	if( a % c != 0 ) aa++;
	bb = b / d;
	if( b % d != 0 ) bb++;
	if( aa < bb ) aa = bb;
	if( l - aa > 1 ) result = l - aa;
	printf("%d\n", result);
	return 0;
}

Measured memory_bytes: 596
def factorial(n, mod=10**9+7):
    a = 1
    for i in range(1,n+1):
        a = a * i % mod
    return a

N, M = map(int, input().split())
MOD = 10**9 + 7
if N < M:
  N, M = M, N

if N > M + 1:
  ans = 0
elif N == M + 1:
  ans = (factorial(N) * factorial(M)) % MOD
else:
  ans = (2 * factorial(N) ** 2) % MOD

print(ans)

Measured memory_bytes: 9204
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PI 				acos(-1)
#define mp				make_pair
#define pb				push_back
#define all(a)			(a).begin(), (a).end()
#define sz(a)			a.size()
#define srt(a)			sort(all(a))
#define mem(a, h)		memset(a, (h), sizeof(a))
#define f 				first
#define s 				second
#define MOD1			998244353
#define fore(i, b, e)	for(int i = b; i < e; i++)
#define forg(i, b, e, m)	for(int i = b; i < e; i+=m)
int in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
using namespace __gnu_pbds;

typedef long long 		ll;
typedef unsigned long long 		ull;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//find_by_order kth largest  order_of_key <
const int tam = 100010;
const int MOD = 1e9+7;
const double EPS = 1e-9;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	//freopen("qwe.txt", "r", stdin);
	//freopen("asd.txt", "w", stdout);
	int n, q;
	cin>>n>>q;
	vector<int> in[n], out[n];
	int a, b;
	int res = 0;
	fore(i, 0, q)
	{
		cin>>a>>b;
		in[a-1].pb(i);
		out[b-1].pb(i);
	}
	set<int> st;
	fore(i, 0, n)
	{
		fore(j, 0, out[i].size())
		{
			if(st.count(out[i][j]))
			{
				st.clear();
				res++;
				break;
			}
		}
		fore(j, 0, in[i].size())
			st.insert(in[i][j]);
	}
	cout<<res<<'\n';
	return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS2

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

int main(void){
    long n, h;
    scanf("%ld %ld", &n, &h);
    vector<long> a(n), b(n);
    for(long i=0; i<n; i++){
        scanf("%ld %ld", &a[i], &b[i]);
    }
    sort(a.begin(), a.end(), greater<long>());
    sort(b.begin(), b.end(), greater<long>());
    const long am = a[0];
    long ib=0;
    for(long n=1; ; n++){
        if(b[ib]>am){
            h-=b[ib];
            ib++;
        }else{
            n+=(h+am-1)/am - 1;
            h -= (h+am-1)/am*am;
        }
        if(h<=0){
            printf("%ld", n);
            return 0;
        }
    }
}


Measured memory_bytes: 1792
import java.util.*;

class Main{
    public static void main(String[] args){
        int A, B, C, D = 0;
        Scanner sc = new Scanner(System.in);

        A = sc.nextInt();
        B = sc.nextInt();
        C = sc.nextInt();
        D = sc.nextInt();
        
        if(A+B-C-D>0){
            System.out.println("Left");
        }else if(A+B-C-D==0){
            System.out.println("Balanced");
        }else{
            System.out.println("Right");
        }
    }
}

Measured memory_bytes: 22996
<?php
$n=trim(fgets(STDIN));
$p=explode(" ",trim(fgets(STDIN)));
$i=1;
$ans=1;
$min=$p[0];
while($i<$n){
  if($p[$i]<$min){
    ++$ans;
    $min=$p[$i];
  }
  ++$i;
}
echo $ans;

Measured memory_bytes: 18932
// In the name of ALLAH
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n ;
    cin >> n ;
    ll val = 100, cnt = 0 ;
    while( val < n )
    {
        val += val/100 ;
        cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3596
/*Bismillahir Rahmanir Rahim
->>Code by Ashraful Islam Paran
->>CUET,CSE
*/
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef unsigned long long ull;
typedef vector<int> vi;
const int MX=2e5+5;
#define f(i,x,n) for(int i=x;i<n;i++)
#define pb push_back
#define endl "\n"
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    int a[n],d[MX];
    ll s{0};
    f(i,0,n)
    {
        cin>>a[i];
        s+=a[i];
        d[a[i]]++;
    }
    //cout<<s<<endl;
    int q,b,c;

    cin>>q;
    while(q--)
    {
        //s=0;
        int h{0};
        cin>>b>>c;

        h=d[b];
        d[b]=0;
        d[c]+=h;
        s+=h*(c-b);
        //cout<<h<<" "<<c<<" "<<b<<endl;

        cout<<s<<endl;
    }


    return 0;
}



Measured memory_bytes: 4364
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

lint gcd(lint a, lint b) { return b ? gcd(b, a%b) : a; }

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	lint t1, t2, a1, a2, b1, b2;
	cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;

	if (a1 < b1) {
		swap(a1, b1);
		swap(a2, b2);
	}

	lint sub = t1 * b1 + t2 * b2 - t1 * a1 - t2 * a2;
	if (sub == 0) {
		cout << "infinity" << "\n";
		return 0;
	}

	if (sub < 0) {
		cout << "0" << "\n";
		return 0;
	}

	lint A = t1 * (a1 - b1);
	lint ans = A / sub * 2 + (A % sub != 0);

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <chrono>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long double> vld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pldll;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<ld> vld;
#define newl '\n'
const ll M = 1e9 + 7;
const ll N = 1e2;
const ll INF = LONG_MAX;
#define REP(i, a, b) for (int i = a; i < b; i++)
#define LOG_TWO_N 10
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);

ll gcd(ll a,ll b)
{
    if(a==0)
    {
        return b;
    }
    else
    {
        return gcd(b%a,a);   
    }
}
ll lcm(ll a,ll b)
{
    return a*b/gcd(a,b);
}
int f(char c)
{
    return (int)c-96;
}

template <class T>
void print(vector<T> &vec, int inc = 0, bool lb = true)
{
    for (auto v : vec)
        cout << v + inc << " ";
    if (lb)
        cout << newl;
}

void solve(ll t)
{
    ll x, k, d; cin >> x >> k >> d;
    x = abs(x);
    if(k <= x/d) {
        cout << x-k*d;
    } else {
        k -= x/d;
        if(k%2) {
            cout << abs((x%d)-d);
        } else {
            cout << x%d;
        }
    }
}

int main()
{
    fast;

    ll t = 1;
    //cin >> t;
    while (t--)
    {
        solve(t);
    }

    return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;i++)
ll n,m,a;
void solve()
{
    vector<vector<int> > in(n,vector<int>(m));
    int I=0,J=0;
    rep(i,0,a)
    {
        int t;cin>>t;
        while(t)
        {
            in[I][J]=i+1;
            if(I%2==0)
            {
                J++;
                if(J==m)
                {
                    J--;
                    I++;
                }
            }
            else
            {
                J--;
                if(J==-1)
                {
                    J++;
                    I++;
                }
            }
            t--;
            
        }
    }
    rep(i,0,n)
    {
        rep(j,0,m)
        {
            if(j)cout<<' ';
            cout<<in[i][j];
        }
        cout<<endl;
    }
}
main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin>>n>>m;
    cin>>a;
    ;
    solve();

    return 0;
}

Measured memory_bytes: 384