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

struct data {
  string s;
  int rank;
};
int n, id = 0;
vector<data> v;

int solve();
void setrank();

int main() {
  while(1) {
    cin >> n;
    if(n == 0) break;
    v.resize(n);
    for(int i = 0; i < n; ++i) cin >> v[i].s;
    setrank();
    cout << solve() << endl;
  }
  return 0;
}

int solve() {
  if(v[id].s[v[id].rank] >= '0' &&
     v[id].s[v[id].rank] <= '9')
    return v[id].s[v[id].rank] - '0';
  int ans = 0, nrank = v[id].rank;
  bool ch = v[id].s[v[id].rank] == '*';
  if(ch) ans = 1;
  ++id;
  while(v[id].rank > nrank) {
    if(ch)
      ans *= solve();
    else
      ans += solve();
    if(++id >= n) return ans;
  }
  --id;
  return ans;
}

void setrank() {
  for(int i = 0; i < n; ++i) {
    v[i].rank = 0;
    while(v[i].s[v[i].rank] == '.') ++v[i].rank;
  }
  id = 0;
}


Measured memory_bytes: 3176
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cstring>
#include <cstdio>
//#include <cmath>
#include <queue>
using namespace std;
queue <int> q1;
queue <int> q2;
char str1[100],str2[100];
int round()
{
	while(q1.front()==q2.front())
	{  q1.pop();q2.pop();
	   if(q1.empty()==true)
	     return 0;
	}
	return 1;
}
int main()
{
	int i;
	cin>>str1;
	cin>>str2;
	int len1=strlen(str1);
	for(i=0;i<len1;i++)
	  q1.push(int(str1[i]-'a'));
	for(i=0;i<len1;i++)
	{  q2.push(int(str2[i]-'a'));
	   if(q1.front()==q2.back())
	     q1.pop();
	   else
	     continue;
    }
    if(q1.empty()==true)
      printf("Yes");
    else
      if(round()==0)
        printf("Yes");
      else
        printf("No");
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>




using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const int INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
const ll mod = 1000 * 1000 * 1000 + 7;




void solve() {
    ll n, k;
    cin >> n >> k;
    if (k % 2 == 1) {
        ll x = n / k;
        cout << x * x * x << endl;

    }
    else {
        ll m = k / 2;
        ll x = n / m;
        ll x1 = x / 2;
        ll x2 = x - x1;
        cout << x1 * x1 * x1 + x2 * x2 * x2 << endl;
    }
}

//#define LOCAL

int main() {
    ios_base::sync_with_stdio(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    solve();


#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif	
    return 0;
}

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

int main(){
  int n;
  cin >>n;
  vector<int> a(n);
  rep(i,n) {
    cin >>a[i];
    a[i]--;
  }
  int now = 0;
  int ans = 0;
  while(true){
    if(now==1) {
      cout << ans << endl;
      return 0;
    }
    if(ans>=n){
      cout << -1 << endl;
      return 0;
    }
    ans++;
    now = a[now];
  }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;
#define reverse(s) reverse(s.begin(),s.end())

int main(){
    int a,b,c,x;
    cin >> a >> b >> c >> x;

    int ans = 0;
    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                int m = i*500 + j*100 + k*50;
                if(m==x)    ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

struct Plant {
  string l;
  int p, a, b, c, d, e, f, s, m;

  Plant(string l, int p, int a, int b, int c, int d, int e, int f, int s, int m) {
    this->l = l;
    this->p = p;
    this->a = a;
    this->b = b;
    this->c = c;
    this->d = d;
    this->e = e;
    this->f = f;
    this->s = s;
    this->m = m;
  }

  int time() {
    return a + b + c + d + e + (m-1) * (d + e);
  }

  int benefit() {
    return f * s * m - p;
  }
};

static bool operator< (Plant &p1, Plant &p2) {
  if(p1.benefit() * p2.time() == p2.benefit() * p1.time()) {
    return p1.l < p2.l;
  } else {
    return p1.benefit() * p2.time() > p2.benefit() * p1.time();
  }
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  while(1) {
    int n; cin >> n;
    if(n == 0) break;
    vector<Plant> plants;
    REP(i, n) {
      string l; cin >> l;
      int p, a, b, c, d, e, f, s, m; cin >> p >> a >> b >> c >> d >> e >> f >> s >> m;
      plants.pb(Plant(l, p, a, b, c, d, e, f, s, m));
    }
    sort(ALL(plants));
    REP(i, n) {
      cout << plants[i].l << endl;
    }
    cout << "#" << endl;
  }
}



Measured memory_bytes: 3168
from collections import deque
import numpy as np
H, W = map(int, input().split())
maze = [list(input()) for _ in range(H)]
w = 0
for i in range(H):
    w += maze[i].count(".")
inf = 10**9
d = np.array([[inf]*W for _ in range(H)])
d[0][0] = 0
q = deque([])
q.append([0, 0])
nx, ny = 0, 0
dx = [0, 0, -1, 1]
dy = [1, -1, 0, 0]
while len(q) > 0:
    p = q.popleft()
    if p[0] == H and p[1] == W:
        break
    for i in range(4):
        nx = p[1] + dx[i]
        ny = p[0] + dy[i]
        if nx >= 0 and ny >= 0 and nx < W and ny < H and d[ny][nx] == inf and maze[ny][nx]==".":
            q.append([ny, nx])
            d[ny][nx] = d[p[0]][p[1]] + 1
if d[H-1][W-1] == inf:
	print(-1)
else:
	print(w-(d[H-1][W-1]+1))

Measured memory_bytes: 12440
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	b=0;
	cin>>a;
	10<=a<=99;
	while(a!=0){
		b=a%10;
		a=a/10;	
		if (b==9){
			cout<<"Yes";
			a=1;
			break;
		}
	}
	if(a==0)
		cout<<"No";
	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 N = sc.nextInt();
		int[] H = new int[N];
		for (int i = 0; i < N; i++) {
			H[i] = sc.nextInt();
		}
		int count = 0;
		int max = 0;

		for (int i = 0; i < N - 1; i++) {
			if (H[i] >= H[i + 1]) {
				count++;
			} else {
				count = 0;
			}
			max = Math.max(max, count);
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 59392
N = int(input())
A = list(map(int,input().split()))
A.insert(0,0)
A.append(0)
cost = 0
for i in range(N+1):
    cost += abs(A[i+1]-A[i])
for i in range(1,N+1):
    sub = abs(A[i] - A[i+1]) + abs(A[i] - A[i-1]) - abs(A[i+1] - A[i-1])
    print(cost - sub)

Measured memory_bytes: 14048
#include<bits/stdc++.h>
using namespace std;
 
#define PI acos(-1)
#define hell 1000000007
#define HELL 998244353
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fix(n) cout << fixed << setprecision(n)
#define mset(a,n) memset(a,n,sizeof a)
#define rep(i,a,b) for (__typeof((b)) i=(a);i<(b);i++)
#define repp(i,a,b,p) for(__typeof((b)) i=(a);i<(b);i+=p)
#define ren(i,a,b) for(__typeof((a)) i=(a);i>=(b);i--)
#define renn(i,a,b,p) for(__typeof((a) i=(a);i>=(b);i-=p)
#define lbd lower_bound
#define ubd upper_bound
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(v) (v).begin(), (v).end()
#define sz(x) (ll)x.size()
#define endl "\n"
#define out(n) cout<<n<<" "
#define outl(n) cout<<n<<endl
#define line cout<<endl
#define bug(n) {outl(n);return;}
#define N 1005
ll a,b;
void solve(){
	cin>>a>>b;
	if(a>9||b>9)bug(-1);
	bug(a*b);
}
void prep(){
	
}
int main(){
    io;
    ll t=1;
    // cin>>t;
    prep();
    fix(12);
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0; i<n; i++)
#define INF (1<<20)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;

ll arr[1000010];

void Eratosthenes(int n) 
{
	rep(i, n+1)arr[i] = 1;
	for (int i = 2; i <= sqrt(n); i++) {
		if (arr[i]) {
			for (int j = 0; i*(j + 2) <= n; j++)
				arr[i*(j + 2)] = 0;
		}
	}
}

int dp[1000001];
int a[31], c[31];

int main()
{
	int n,x;
	while (cin >> n >> x, n) {

		Eratosthenes(x);

		for (int i = 0; i < n; i++) {
			cin >> a[i];
			c[i] = 1000000 / a[i];
		}

		for (int i = 0; i <= 1000000; i++)
			dp[i] = -1;

		dp[0] = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j <= x; j++) {
				if (dp[j] >= 0) {
					dp[j] = c[i];
				}
				else if (j < a[i] || dp[j - a[i]] <= 0) {
					dp[j] = -1;
				}
				else {
					dp[j] = dp[j - a[i]] - 1;
				}
			}
		}

		bool flag = false;
		for (int i = x; i >= 2; i--) {
			if (dp[i] >= 0) {
				if (arr[i]) {
					cout << i << endl;
					flag = true;
					break;
				}
			}
		}
		if(!flag)
		cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 14820
#include "bits/stdc++.h"
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
//#define INF (1LL<<59)

//verified AOJ GRL_1
#define MAX_V 100000
struct edge{int to,cost;};
vector<edge> G[MAX_V];

void dijkstra(int s, vector<int> &d){
    priority_queue< pii,vector<pii>,greater<pii> > que;
    rep(i,d.size())d[i]=INF;
    d[s]=0;
    que.push(pii(0,s));
    
    while(que.size()){
        pii p=que.top();
        que.pop();
        
        int v=p.second;
        if(d[v]<p.first)continue;
        
        rep(i,G[v].size()){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(pii(d[e.to],e.to));
            }
        }
    }
}


int main(){
    int v,e,s;
    cin>>v>>e>>s;
    rep(i,e){
        int a,b,c;
        cin>>a>>b>>c;
        G[a].pb(edge{b,c});
    }
    
    vi d(v);
    dijkstra(s,d);
    
    rep(i,v){
        if(d[i]==INF)cout<<"INF"<<endl;
        else cout<<d[i]<<endl;
    }
}

Measured memory_bytes: 13084
a,b = map(int,input().split())
dic1 = [0 for _ in range(10**3+1)]
dic2 = [0 for _ in range(10**3+1)]

for i in range(1,10**3+1):
    tax = i * 0.08
    tax2 = i * 0.1
    dic1[i] = int(tax)
    dic2[i] = int(tax2)

for i in range(10**3+1):
    if dic1[i] == a and dic2[i] == b:
        print(i)
        exit()
print(-1)

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

int main() {
	// your code goes here
	long long S,C;
	scanf("%ld %ld",&S,&C);
	long long i;
	if(S>=C/2){ //there is much S
		i=C/2;
	}
	else{
		i=S;
		C=C-S*2;
		i+=C/4;
	}
	printf("%ld",i);
	return 0;
}

Measured memory_bytes: 256
def calc(x:list, y:int):
    if x.count(y) == 0:
        return -100
    elif x.count(y) == 1:
        return -1
    elif x.count(y) == 2:
        return 1
    elif x.count(y) > 2:
        return -100

loads = []
for _ in range(3):
    loada, loadb = input().split()
    loads.append(int(loada))
    loads.append(int(loadb))

x = 0
for i in range(1,5):
    x = x + calc(loads, i)

if x == 0:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3064
#include<stdio.h>

int main(void) {
	   char str[1001];
    char end;
    int i,j,n,sum;
    int num[1001];
 
    while(1){
        for(i = 0;i < 1001;i++){
            str[i] = '0';
        }
        for(i = 0;i < 1001;i++){
            num[i] = 0;
        }
        sum = 0;
        scanf("%s",str);
        if(str[0] == '0')break;
        for(i = 0;i < 1001;i++){
            if(str[i]== 0){
                n = i;
            }
        }
        for(j = 0;j < n;j++){
            num[j] = str[j] - '0';
            sum += num[j];
        }
        printf("%d\n",sum);
    }
	return 0;
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	int n;
	string s;
	char ans;
	cin >> n >> s;
	for (int i = 0; i < s.size(); i++) {
		cout << char ((s[i] - 'A' + n) % 26 + 'A');
	}
	cout << "\n";
	return 0;
}


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

using namespace std;

struct store
{
    int id;
    int point;

    bool operator<(const store &another) const
    {
        return point < another.point;
    };

    bool operator>(const store &another) const
    {
        return point > another.point;
    };
};

struct city 
{
    string name;
    vector<store> stores;

    bool operator<(const city &another) const
    {
        return name < another.name;
    }

    bool operator>(const city &another) const
    {
        return name > another.name;
    }
};

int main()
{
    int N;
    vector<city> cities;

    cin >> N;

    string _name;
    int _point;

    for(int i=0; i<N; i++){
        cin >> _name >> _point;

        // 同じ町を検索
        bool found = false;
        for(int j=0; j<cities.size(); j++){
             if(cities[j].name.compare(_name)==0){
                cities[j].stores.push_back({i+1, _point});
                found = true;
                break;
            }
        }

        if(!found){
            city c;
            c.name = _name;
            c.stores.push_back({i+1, _point});
            cities.push_back(c);
        }
    }

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

    for(int i=0; i<cities.size(); i++){
        sort(cities[i].stores.begin(), 
        cities[i].stores.end(), greater<store>());

        for(int j=0; j<cities[i].stores.size(); j++){
            cout << cities[i].stores[j].id << endl;
        }
    }

    return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/03/05  Problem: 066_arc_b / Link: https://arc066.contest.atcoder.jp/tasks/arc066_b?lang=en  ----- */
/* ------問題------

正の整数 N が与えられます。 2 つの整数 u,v(0≦u,v≦N) であって、ある非負整数 a,b が存在して、a xor b=u、a+b=v となるようなものが何通りあるかを求めてください。 ここで、xor はビットごとの排他的論理和を表します。 なお、答えは非常に大きくなることがあるので、109+7 で割った余りを求めてください。

-----問題ここまで----- */
/* -----解説等-----

OEISさん…(A007729)

----解説ここまで---- */

LL ans = 0LL;

//LL solve(int u, int v) {
//	FOR(a, 0, 1000) {
//		FOR(b, 0, 1000) {
//			if ((a^b) == u && (a + b == v)) {
//				return 1;
//			}
//		}
//	}
//
//	return 0;
//}


LL solve(LL x ) {
	if (x < 2)return x;
	if (x % 2 == 0) {
		return solve(x / 2);
	}
	else {
		return( solve((x - 1) / 2) + solve((x + 1) / 2))%MOD;
	}
 }

LL solvesum(LL x) {
	LL ret = 0;
	FOR(i, 0, x+2) {
		ret += solve(i);
	}

	return ret;
}


map<LL, LL >memo;
map<LL, int >look;
LL solveQ(LL x) {
	if (x < 2)return (x);
	if (look[x])return memo[x];
	LL & ret = memo[x];
	ret = ( solveQ((x)/2) + solveQ((x-1) / 2)+ solveQ((x +1) / 2)) % MOD;
	look[x] = 1;
	return ret;
}


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


	//FOR(N, 1, 20) {
	//	LL ret = 0;
	//	FOR(u, 0, N + 1) {
	//		FOR(v, 0, N + 1) {
	//			ret += (solve(u, v));
	//		}
	//	}
	//	debug(ret);
	//}
	//VI test({ 1, 2, 4, 5, 8, 10, 13, 14, 18, 21, 26, 28, 33, 36, 40, 41, 46, 50, 57, 60 });
	//FOR(i, 0, 10000) {
	//	assert(solvesum(i) == solveQ(1 + i));
	//	if (i % 10 == 0)cout << i << endl;
	//	//cout<< test[i]<<", "<<solvesum(i) << ", "<<solveQ(1+i)<< endl;
	//}
	LL N; cin >> N;
	ans = solveQ(N+1);
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
//default
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
typedef pair<int, int> P_i;
typedef pair<double,double> P_d;
#define rep(i,n) for(int i=0;i<(n);++i)
#define alrep(i,j,n) for(int i=0;i<(n);++i)for(int j=i+1;j<(n);++j)
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;int ans=0;
#define answer cout << ans << endl;
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; }
const int MOD=1e9+7;
const long long INF = 1LL << 60;
int gcd(int a,int b) {return __gcd(a,b);}//if you use gcc to compile, use this

signed main(){
  int N,ans=0;
  cin >> N;
  int a[3*N];
  rep(i,3*N){
    cin >> a[i];
  }
  sort(a,a+3*N);
  rep(i,N){
    ans+=a[3*N-2-2*i];
  }
  answer
  return 0;
}


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int H, W, M;
int cntH[int(3e5+5)], cntW[int(3e5+5)];
Pii PH[int(3e5+5)], PW[int(3e5+5)];
map <Pii, bool> mp;

int main(){
  cin >> H >> W >> M;
  for (int i = 0; i < M; i++){
    int h, w; cin >> h >> w;
    cntH[h]++; cntW[w]++;
    mp[{h, w}] = true;
  }

  for (int i = 0; i <= H; i++) PH[i] = {cntH[i], i};
  sort(PH, PH + H + 1, greater<Pii>()); 
  for (int i = 0; i <= W; i++) PW[i] = {cntW[i], i};
  sort(PW, PW + W + 1, greater<Pii>());

  int h = 0, w = 0;
  while (PH[0].fi == PH[h].fi) h++;
  while (PW[0].fi == PW[w].fi) w++;

  int ans = PH[0].fi + PW[0].fi - 1;
  for (int i = 0; i < h; i++){
    for (int j = 0; j < w; j++){
      if (!mp[{PH[i].se, PW[j].se}]){
        cout << ans + 1 << endl;
        return 0;
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 29384
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  int N,M;
  cin>>N>>M;

  int ans=0;
  ans+=N*(N-1)/2;
  ans+=M*(M-1)/2;
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
#define MAX 100100
//#define NIL -1
//#define INFTY 1000000000000000000

vector<LL> parent(MAX);
vector<LL> length(MAX);
 
void init(LL n){
    for(LL i=0; i<n; i++){
        parent[i]=i;
        length[i]=1;
    }
}
 
int find(LL x){
    while(parent[x]!=x){
        x=parent[x];
    }
    return x;
}
 
bool same(LL x, LL y){
    return find(x)==find(y);
}
 
bool unite(LL x, LL y){
    x=find(x);
    y=find(y);
    if(x==y){
        return false;
    }
    if(length[x]<length[y]){
        swap(x,y);
    }
    parent[y]=x;
    length[x]+=length[y];
    return true;
}

int main(){
    LL n;
    LL m;
    cin >> n >> m;
    init(n);
    LL x;
    LL y;
    LL z;
    for(LL i=0; i<m; i++){
        cin >> x >> y >>z;
        x--;
        y--;
        unite(x,y);
    }

    set<LL> s;
    for(LL i=0; i<n; i++){
        LL tmp=find(i);
        s.insert(tmp);
    }

    cout << s.size() << endl;

    return 0;
}


Measured memory_bytes: 9576
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> penalty(n);
  vector<bool> accept(n);
  for (int i = 0; i < m; i++) {
    int k;
    cin >> k;
    string s;
    cin >> s;
    --k;
    if (s == "AC") {
      accept[k] = true;
    } else {
      if (!accept[k]) {
        ++penalty[k];
      }
    }
  }
  int ac = 0, pen = 0;
  for (int i = 0; i < n; i++) {
    if (accept[i]) {
      ++ac;
      pen += penalty[i];
    }
  }
  cout << ac << " " << pen << '\n';
  return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define TDARRAY(int,a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) {if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a, T b) {if(a>b){a=b;return 1;}return 0;}

vector<int> demical(ll n,int k,int l){
    //10進数nをk進数で表す。ただし、長さlで固定(これはbit全探索の一般化のためのものである)
    vector<int> rtn(l);
    REP(i,l){
        rtn[i]=n%k;
        n/=k;
    }
    /*while(n>0){
        rtn.push_back(n%k);
        n/=k;
    }*/
    return rtn;
}

int n;
vector<int> a(3);

int main(){
    cin >> n;
    REP(i,3){
        cin >> a[i];
    }
    vector<int> l(8,1e6);
    REP(i,n){
        cin >> l[i];
    }
    int res = INT_MAX;
    /*ll f = pow(4,8);
    REP(i,f){
        int cost = 0;
        vector<int> v(4,0);
        vector<int> k = demical(i,4,8);
        REP(j,k.size()){
            v[k[j]]+=l[j];
            if(k[j]!=3)cost+=10;
        }
        REP(j,v.size()){
            cost+=abs(v[j]-a[j]);
        }
        if(v[0]&&v[1]&&v[2]){
            chmin(res,cost);
        }
    }*/
    REP(d,4){
        REP(e,4){
            REP(f,4){
                REP(g,4){
                    REP(h,4){
                        REP(i,4){
                            REP(j,4){
                                REP(k,4){
                                    int cost = 0;
                                    vector<int> v(4);
                                    v[d]+=l[0];
                                    v[e]+=l[1];
                                    v[f]+=l[2];
                                    v[g]+=l[3];
                                    v[h]+=l[4];
                                    v[i]+=l[5];
                                    v[j]+=l[6];
                                    v[k]+=l[7];
                                    if(d!=3)cost+=10;
                                    if(e!=3)cost+=10;
                                    if(f!=3)cost+=10;
                                    if(g!=3)cost+=10;
                                    if(h!=3)cost+=10;
                                    if(i!=3)cost+=10;
                                    if(j!=3)cost+=10;
                                    if(k!=3)cost+=10;
                                    cost+=abs(v[0]-a[0]);
                                    cost+=abs(v[1]-a[1]);
                                    cost+=abs(v[2]-a[2]);
                                    if(v[0]&&v[1]&&v[2]){
                                        chmin(res,cost);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    put(res-30);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<n; i++)
#define pb push_back
#define int long long
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int N, M, Q;
int A[550][550];
int acc[550][550];

signed main() {
    cin >> N >> M >> Q;
    rep(i, M) {
        int L, R; cin >> L >> R;
        A[L-1][R-1]++;
    }
    rep(i, N) rep(j, N) acc[i+1][j+1] = acc[i+1][j]+acc[i][j+1]-acc[i][j]+A[i][j];
    while (Q--) {
        int p, q; cin >> p >> q;
        p--;
        q--;
        cout << acc[q+1][q+1]-acc[q+1][p]-acc[p][q+1]+acc[p][p] << endl;
    }
}

Measured memory_bytes: 5376
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int N, M;
  while (cin >> N >> M) {
    vector<vector<int>> G(N);
    for (int i = 0; i < M; i++) {
      int a, b;
      cin >> a >> b;
      --a;
      --b;
      G[a].push_back(b);
      G[b].push_back(a);
    }
    int Q;
    cin >> Q;
    vector<int> v(Q), d(Q), c(Q);
    for (int i = 0; i < Q; i++) {
      cin >> v[i] >> d[i] >> c[i];
      --v[i];
    }
    vector<int> color(N, 0);
    vector<vector<bool>> done(N, vector<bool>(11, false));
    function<void(int, int, int)> nul = [&](int v, int d, int c) {
      if (done[v][d]) return;
      if (d == 0) {
        color[v] = c;
        done[v][d] = true;
        return;
      }
      nul(v, d - 1, c);
      for (int u : G[v]) {
        nul(u, d - 1, c);
      }
      done[v][d] = true;
    };
    for (int q = Q - 1; q >= 0; q--) {
      nul(v[q], d[q], c[q]);
    }
    for (int v = 0; v < N; v++) {
      cout << color[v] << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 15096
N = int(input())
l = [0] * N
l = list(map(int, input().split()))
sum = 0
a = [0] * N
for i in range(N):
    sum += l[i]
x = 0
result = 1145141919810931931
for i in range(N):
    x += l[i]
    if i + 1 < N:
        result = min((result, abs(sum - 2 * x)))
print(result)


Measured memory_bytes: 26360
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    vector<int> a = {0,1999,1799,1599,1399,1199,999,799,599};
    int n;
    cin >> n;
    int ans = 8;
    for(int i=1;i<=8;i++){
        if(a[i]<n){
            ans = i-1;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define DB double
#define INF 1145141919810364364
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define rep(i,n) FOR(i,0,n)
#define MOD 1000000007
//#define MOD 998244353
#define ERR 0.00000001
#define NUM 200010

void swap(LL* a,LL* b){LL tmp=*a;*a=*b;*b=tmp;}
void YN(int a){if(a==1)printf("Yes\n");if(a==0)printf("No\n");}
LL lpow(LL a,LL n){LL ans=pow(a,n)*10;if(ans%10<5)return ans/10;return ans/10+1;}
LL dup(LL a,LL d){if(a%d==0)return a/d;else return a/d+1;}
LL GCD(LL a,LL b){LL c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int lcmpr(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return -1;if(*(LL*)a<*(LL*)b)return 1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int ccmpr(const void* a,const void* b){return *(char*)b-*(char*)a;}
int scmp(const void* a,const void* b){return strcmp((char*)a,(char*)b);}
int scmpr(const void* a,const void* b){return strcmp((char*)b,(char*)a);}
LL mod(LL a,LL m){if(a<0)return a%m+m;else return a%m;}
LL DIV(LL a,LL d){LL m=MOD,x=1,y=0,k;while(m){k=d/m;d-=k*m;swap(&m,&d);x-=k*y;swap(&x,&y);}return mod(a*mod(x,MOD),MOD);}
LL FAC(LL a){LL i,ans=1;FOR(i,1,a+1){ans*=i;if(MOD>0&&ans>MOD)ans%=MOD;}return ans;}
LL POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return ans;}
LL fact[NUM],finv[NUM],inv[NUM];
void comi(){LL i;fact[0]=fact[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fact[i]=fact[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||n<0||k<0)return 0;return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;}

int main(){
  LL H,W,i,ans=0;
  scanf("%lld%lld",&H,&W);
  if(H==1||W==1)printf("1");
  else printf("%lld\n",dup(H*W,2));
	return 0;
}


Measured memory_bytes: 128
import itertools
def main():
    N = int(input())
    d = {}
    for i in range(N):
        a = int(input())
        d[i] = []
        for _ in range(a):
            x, y = map(int, input().split())
            d[i].append((x-1,y))
    for i in range(N+1):
        for j in itertools.combinations(range(N), i):
            for k in range(N):
                a = 0
                if k not in j:
                    for x, y in d[k]:
                        if y == 0 and x not in j:
                            a += 1
                        if y == 1 and x in j:
                            a += 1
                if a > 0:
                    break
            else:
                return N - i
print(main())


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

int main() {
    int a, b, c; scanf("%d%d%d", &a, &b, &c);
    int min_num, max_num;
    min_num = min(min(a, b), c);
    max_num = max(max(a, b), c);
    printf("%d %d\n", min_num, max_num);
    return 0;
}


Measured memory_bytes: 3232
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

const int N = 1e5 + 7;

int ok = 1;

int sz[N];
vector<int> g[N];

void dfs(int cur, int p) {
	sz[cur] = 1;
	int c = 0;
	for (auto t : g[cur]) {
		if (t != p) {
			dfs(t, cur);
			c += (sz[t] & 1);
			sz[cur] += sz[t];
		}
	}
	ok &= (c < 2);
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	for (int i = 0; i + 1 < n; i++) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	dfs(0, -1);
	ok &= (sz[0] % 2 == 0);
	if (ok) {
		cout << "Second\n"; 	
	} else {
		cout << "First\n";
	}
}

Measured memory_bytes: 9052
#include <bits/stdc++.h>
using namespace std;
int main() {
    vector<int> dp(100010, 100010);
    dp.at(0) = 0;
    int N;
    cin >> N;
    for(int i = 0; i <= N; i++) {
        for(int j = 1; j <= i; j*= 6) dp.at(i) = min(dp.at(i), dp.at(i-j)+1);
        for(int j = 1; j <= i; j*= 9) dp.at(i) = min(dp.at(i), dp.at(i-j)+1);
    }
    cout << dp.at(N) << endl;
}


Measured memory_bytes: 640
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from collections import *

MOD = 1000000007
N = int(input())
nums = list(range(1,N+1))
d = defaultdict(int)
for i in range(1, N):
    ni = nums[i]
    if ni == 1:
        continue
    for j in range(i, N):
        while nums[j] % ni == 0:
            nums[j] //= ni
            d[ni] += 1
ans = 1
for v in d.values():
    ans = (ans * (v + 1)) % MOD
print(ans)
                


Measured memory_bytes: 3572
#include<stdio.h>
int main()
{
  int i,n;
  scanf("%d",&n);
  printf("%d:",n);
  while(1)
    {
      for(i=2;i<=n;i++)
	{
	  if(n%i==0)
	    {
	      n/=i;
	      printf(" %d",i);
	      break;
	    }
	  if(n<i*i) i=n-1;
	}
      if(n==1) break;
    }
  printf("\n");
  return 0;
}

Measured memory_bytes: 600
# -*- coding: utf-8 -*-
 
a = int(input())

def check(s):
    fl = True
    for i in range(2,s):
        if s % i == 0:
            fl = False
    return(fl)
    
if check(a):
    print(a)
else:
    while not(check(a)):
        a+=1
    print(a)

Measured memory_bytes: 38896
#include <stdio.h>

int	main()
{
	int	x1, y1;
	int	x2, y2;
	int	x3, y3;
	int	x4, y4;
	int	difx, dify;

	scanf("%d %d %d %d\n", &x1, &y1, &x2, &y2);
	difx = x2 - x1;
	dify = (y2 - y1) * -1;
	x3 = x2 + dify;
	y3 = y2 + difx;
	x4 = x1 + dify;
	y4 = y1 + difx;
	printf("%d %d %d %d\n", x3, y3, x4, y4);
	return (0);
}

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

inf = 2**30
dp = [inf] * (H + 1)
dp[0] = 0
for i in range(N):
    A, B = list(map(int, input().split()))
    for j in range(H + 1):
        if dp[j] != inf:
            next = min(H, j + A)
            dp[next] = min(dp[next], dp[j] + B)

print(dp[H])


Measured memory_bytes: 43996
#include <bits/stdc++.h>
using namespace std;
long long n,a[200010],ans;
int main()
{
  scanf("%lld",&n);
  for(int i=1; i<=n; i++)
    scanf("%lld",&a[i]);
  long long l=1,r=1,sumx=a[1],sum=a[1];
  for(int i=1; i<=n; i++)
  {
    while((sumx==sum)&&r<=n)
    {
      sum+=a[r+1];
      sumx^=a[r+1];
      r++;
    }
    ans+=(r-1)-l+1;
    sumx^=a[l];
    sum-=a[l];
    l++;
    if(r<l)
      r=l;
  }
  cout<<ans<<"\n";
  return 0;
}
//freopen(" .in","r",stdin);//输入
//freopen(" .out","w",stdout);//输出


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

int main(){
    int n, i, t, c = 0;
    cin >> n;
    int a[n+1];
    for(i=1; i<=n; i++){
        cin >> a[i];
    }
    t = 1;
    while(c < n){
        c++;
        t = a[t];
        if(t == 2){
            break;
        }
    }
    if(c == n){
        cout << -1;
    }else{
        cout << c;
    }
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	int n; ll k; cin >> n >> k;
	vi a(n), f(n);
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> f[i];
	sort(all(a)); sort(all(f));
	
	ll lo = -1, hi = a[n - 1] * (ll)f[n - 1], mid;
	while(lo + 1 < hi){
		mid = (lo + hi) / 2;
		ll cost = 0;
		rep(i, n){
			if(a[i] * (ll)f[n - 1 - i] > mid){
				cost += a[i] - mid / f[n - 1 - i];
			}
		}
		if(cost <= k) hi = mid;
		else lo = mid;
	}
	cout << hi << endl;
	return 0;
}

Measured memory_bytes: 1792
//F5で実行 Shift+F5で停止
//F9でブレークポイント
#include<cmath>
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
//Shift+PageUpで上部の大半を選択できる
// 1e18 = 10の18乗

int X;

void _main() {
	cin >> X;
	
	cout << (X >= 30?"Yes":"No") << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;
const double PI = acos(-1);

int main() {
    int N; cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());

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

    cout << sum << endl;
    return 0;
}

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

struct inv{
  int l,r; //closed interval
  inv(int a=0,int b=0):l(a),r(b){}
  inv operator+=(inv x){
    if(l==0 && r==0)l = x.l, r = x.r;
    else if(r+1==x.l)r = x.r;
    else l=-1,r=-1;
    return *this;
  }
  bool operator==(inv x){ return l==x.l && r==x.r; }
  bool operator!=(inv x){ return l!=x.l || r!=x.r; }
};

class SegmentTree{
  int n;
  vector<inv> node;
public:
  SegmentTree(int n_){
    n = 1;
    while(n<n_)n*=2;

    node.resize(2*n-1);
    for(int i=0;i<2*n-1;i++)node[i] = inv(0,0);
  }

  inv get(int x){
    x += n-1;
    inv res = node[x];
    while(x){
      x = (x-1)/2;
      if(node[x] != inv(0,0)){
	res += node[x];
      }
    }
    return res;
  }

  void add(int l, int r, inv x){
    add(l,r,x,0,n,0);
  }

  void add(int l, int r, inv x, int a, int b, int k){
    if(r<=a || b<=l)return;
    if(l<=a && b<=r){
      node[k] += x;
      return;
    }

    if(node[k] != inv(0,0)){
      add(a,(a+b)/2,node[k],a,(a+b)/2,2*k+1);
      add((a+b)/2,b,node[k],(a+b)/2,b,2*k+2);
    }

    add(l,r,x,a,(a+b)/2,2*k+1);
    add(l,r,x,(a+b)/2,b,2*k+2);
    node[k] = inv(0,0);
  }
};

int main(){
  int n,k,t;
  cin >> n >> k >> t;

  SegmentTree st(n);

  for(int i=0;i<t;i++){
    int l,r,x;
    cin >> l >> r >> x; l--;
    st.add(l,r,inv(x,x));
  }

  int ans = 0;
  for(int i=0;i<n;i++){
    if(st.get(i) == inv(1,k))ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 7016
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define REP(i,n) FOR(i,0,n)
using namespace std;
//bit全探索+greedy
int main(){
    int D;
    long long G;
    cin >> D >> G;
    vector<long long> p, c;
    p.resize(D);
    c.resize(D);
    REP(i,D){
        cin >> p[i] >> c[i];
    }
    long long res = 1 << 29;
    REP(bit,1<<D){
        long long sum = 0;
        long long num = 0;
        REP(i,D){
            if(bit&(1<<i)){
                sum += c[i] + p[i] * 100 * (i + 1);
                num += p[i];
            }
        }
        if(sum>=G){
            res = min(res, num);
        }else{
            for (int i = D - 1; i >= 0;i--){
                if(bit&(1<<i)){
                    continue;
                }
                REP(j,p[i]){
                    if(sum>=G){
                        break;
                    }
                    sum += 100 * (i+1);
                    num++;
                }
            }
            res = min(res,num);
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define ll long long
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()

using namespace std;

ll n,m,k,y,cnt;
string s;
vector <int> v;
pair <int, int> p[100005];


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m >> k;
    y =  k - (m - 1);
    if (y % 2 == 0){
        cout << "Borys";
    }
    else {
        cout << "Alice";
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

#define MOD 1000000007
#define INF 2000000000

int GLL(LL& x) {
    return scanf("%lld", &x);
}

int GI(int& x) {
    return scanf("%d", &x);
}

int n;

LL a, b;

vector<LL> d;

int main() {
    GI(n);

    LL absdif = 0;

    LL res = 0;
    LL minB = INF;

    FORN(i, n) {
        GLL(a);
        GLL(b);

        absdif += abs(a - b);

        res += b;
        if (a > b) minB = min(minB, b);
    }

    if (absdif == 0) {
        printf("0\n");
    }
    else {
        printf("%lld\n", res - minB);
    }

    return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())
 
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const ll MOD = (ll)1000000007;//10^9+7
const ll INF2 = (ll)100000000000000000;//10^18

ll power(ll q, ll p){
    ll a = q;
    ll ans = 1;
    while(p)
	{
		if(p&1)
			ans = (ans*a)%MOD;
		a = a*a%MOD;
		p=p>>1;
	}
    return ans;
}

ll inv(ll a){
    return power(a, MOD-2);
}
int main() {
    int h,w,a,b;
    cin>>h>>w>>a>>b;
    
    ll fac[h+w+1];
    fac[0]=1;
    REP(i,h+w){
        fac[i+1] = (fac[i]*(i+1))%MOD;
    }

    ll ans=0;


    for(int j=b;j<w;j++){
        (ans += (((((fac[h-a-1+j]*inv(fac[h-a-1]))%MOD*inv(fac[j]))%MOD * fac[w-j+a-2])%MOD*inv(fac[a-1]))%MOD*inv(fac[w-j-1]))%MOD)%=MOD;
    }

    cout<<ans<<endl;

}


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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





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






int main()
{
    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    MII mp;
    LL ans=0;
    int i,n,a[200005];
    cin >> n;
    for(i=1;i<=n;i++)
    {
        cin >> a[i];
        ++mp[i-a[i]];
    }
    for(i=1;i<=n;i++)ans+=mp[i+a[i]];
    cout << ans;
    return 0;
}


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

int main() {
  int n,k,ans = 0;
  cin >> n >> k;
  vector<int> l(n);
  for(int i = 0; i < n; i++){
    cin >> l.at(i);
  }
  sort(l.begin(),l.end());
  reverse(l.begin(),l.end());
  for(int i = 0; i < k; i++){
    ans += l.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
list = []
for i in range(N):
  line = input().split()
  line = [i + 1] + line
  list.append(line)
list.sort( key=lambda x: (x[1], -int(x[2])) )
for i in range(N - 1):
  print(list[i][0])
print(list[N-1][0], end="")


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

typedef long long ll;

const long long MOD = 1000000007;
long long modpow(long long a, long long n, long long m)
{
    long long ans = 1;
    while (n)
    {
        if (n & 1)
        {
            ans = (ans * a) % m;
        }
        a = (a * a) % m;
        n >>= 1;
    }
    return ans;
}
long long combi(long long n, long long a)
{
    long long ans = 1, ans1 = 1;
    for (long long i = n - a + 1; i <= n; i++)
    {
        ans *= i % MOD;
        ans %= MOD;
    }

    for (long long i = 2; i <= a; i++)
        ans1 = (ans1 * i) % MOD;
    ans1 = modpow(ans1, MOD - 2, MOD);
    return ((ans % MOD) * ans1) % MOD;
}
int main()
{

    int a, b, n;

    cin >> n >> a >> b;

    ll tmp = modpow(2, n, 1000000007) - combi(n, a) - combi(n, b) - 1;

    tmp %= MOD;
    if (tmp < 0)
        tmp += MOD;
    cout << tmp << endl;
    return 0;
}

Measured memory_bytes: 256