akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/python3

import array
from fractions import Fraction
import functools
import itertools
import math
import os
import sys


def main():
    N, M = read_ints()
    P = [(s, v) for s, v in [read_ints() for _ in range(N)]]
    C = [read_int() for _ in range(M)]
    print(solve(N, M, P, C))


def solve(N, M, P, C):
    P.sort(key=lambda p: (-p[1], -p[0]))
    C.sort(reverse=True)
    ci = 0
    for pi in range(N):
        if ci == M:
            break
        s = P[pi][0]
        if C[ci] >= s:
            ci += 1
    return ci


###############################################################################
# AUXILIARY FUNCTIONS

DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


if __name__ == '__main__':
    main()



Measured memory_bytes: 38544
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 200200;
int n, m, k;
int dp[2 * N][4];
char s[N], t[N];
int sx, sy;

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

	scanf("%d%d%d", &m, &k, &n);
	scanf("%d%d", &sx, &sy);
	scanf(" %s %s", s, t);
	dp[2 * n][0] = 1;
	dp[2 * n][1] = m;
	dp[2 * n][2] = 1;
	dp[2 * n][3] = k;
	for (int i = 2 * n - 1; i >= 0; i--) {
		int p = i / 2;
		for (int j = 0; j < 4; j++)
			dp[i][j] = dp[i + 1][j];
		int d = -1;
		char c = ((i & 1) ? t[p] : s[p]);
		if (c == 'L')
			d = 2;
		else if (c == 'R')
			d = 3;
		else if (c == 'U')
			d = 0;
		else
			d = 1;
		if (i & 1) {
			d ^= 1;
			if (d & 1)
				dp[i][d]++;
			else
				dp[i][d]--;
		} else {
			if (d & 1)
				dp[i][d]--;
			else
				dp[i][d]++;
		}
		dp[i][0] = max(dp[i][0], 1);
		dp[i][1] = min(dp[i][1], m);
		dp[i][2] = max(dp[i][2], 1);
		dp[i][3] = min(dp[i][3], k);
		if (dp[i][0] > dp[i][1] || dp[i][2] > dp[i][3]) {
			printf("NO\n");
			return 0;
		}
	}
	if (dp[0][0] <= sx && sx <= dp[0][1] && dp[0][2] <= sy && sy <= dp[0][3]) {
		printf("YES\n");
	} else {
		printf("NO\n");
	}

	return 0;
}


Measured memory_bytes: 6912
m,k = map(int,input().split())
if k == 0:
    l = [i // 2 for i in range(2 ** (m + 1))]
    print(*l)
    exit()

if m == 0:
    if k == 0:
        print(0, 0)
    else:
        print(-1)
    exit()

if m == 1:
    if k == 0:
        print(0, 0, 1, 1)
    else:
        print(-1)
    exit()

if not 0 <= k < 2 ** m:
    print(-1)
    exit()

l = [0]
for i in range(2 ** (m - 1) - 1):
    l.append(2 ** (m - 1) - i)
for i in range(2 ** (m - 1)):
    l.append(i + 1)
for i in range(2 ** m):
    if i == 0:
        l.append(0)
    elif i == 2 ** (m - 1):
        l.append(l[i])
    else:
        l.append(l[i] + 2 ** (m - 1) - 1)

if k == 1:
    print(*l)
    exit()

for i in range(len(l)):
    if l[i] == 1:
        l[i] = k
    elif l[i] == k:
        l[i] = 1
print(*l)

Measured memory_bytes: 66800
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
typedef vector<vector<int>> Graph;
const int inf = 1e9;
const int mod = 1e9 + 7;

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

    int N;
    cin >> N;
    V v(2 * N);
    rep(i, 2 * N) cin >> v[i];
    sort(all(v));
    int sm = 0;
    rep(i, 2 * N) {
        if (i % 2 == 0) sm += v[i];
    }
    cout << sm << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
#define all(x) (x).begin(), (x).end()

ll d;

ll divs[3] = {2, 3, 5};
ll costs[3];

unordered_map<ll, ll> memo;

ll Solve(ll n) {
  if (memo.find(n) != memo.end()) return memo[n];
  ll ret = LLONG_MAX;
  if (n == 1) {
    ret = min(ret, d);
    return memo[1] = ret;
  }

  for (int i = 0; i < 3; i++) {
    ll div = divs[i];
    ll lower = n / div;
    if (lower) {
      ll addcost = costs[i] + d * (n % div);
      if (n - lower < 1e9 + 100) addcost = min(addcost, d * (n - lower));
      ret = min(ret, Solve(lower) + addcost);
    }
    if (n % div) {
      ll addcost = costs[i] + d * (div - (n % div));
      if (n - (lower + 1) < 1e9 + 100)
        addcost = min(addcost, d * (n - (lower + 1)));
      ret = min(ret, Solve(lower + 1) + addcost);
    }
  }

  return memo[n] = ret;
}

int main() {
  int T;
  cin >> T;
  while (T--) {
    ll n;
    scanf("%lld", &n);
    scanf("%lld%lld%lld%lld", &costs[0], &costs[1], &costs[2], &d);
    memo.clear();

    cout << Solve(n) << endl;
  }

  return 0;
}

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

bool check753(ll a)
{
  vector<int> chk(10, 0);
  while ( a > 0) {
    ll p = a % 10;
    chk[p] = 1;
    a /= 10;
  }
  return (chk[3] == 1 && chk[5] == 1 && chk[7] == 1);
}

ll next753(ll a)
{
  string s;
  s = to_string(a);
  reverse(s.begin(), s.end());
  bool loop = false;
  rep(i, s.size()) {
    loop = false;
    switch(s[i]) {
    case '3':
      s[i] = '5';
      break;
    case '5':
      s[i] = '7';
      break;
    case '7':
      s[i] = '3';
      loop = true;
    }
    if(!loop) break;
  }
  if(loop) s.push_back('3');
  reverse(s.begin(), s.end());
  return stoll(s);
}

void solve()
{
  ll N; cin >> N;
  ll ans = 0;
  ll v = 333;
  while(v <= N) {
    if(check753(v)) {
      ans ++;
      cerr << v << " ";
    }
    v = next753(v);
  }
  
  cout << ans << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 3708
s = input()

if len(s) % 2 == 0: # 偶数
    if s[0] == s[-1]: # 奇数
        print("First")
    else: # 偶数
        print("Second")
else: # 奇数
    if s[0] == s[-1]: # 奇数 
        print("Second")
    else: # 偶数
        print("First")

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

typedef long long ll;

const int MAX_N = 2e5 + 10;
int n, m, ans, len;
int Arr[MAX_N];
int Brr[MAX_N];
int Fen[MAX_N];

void upd (int tmp, int val) {
	for (; tmp < MAX_N; tmp += tmp & -tmp)
		Fen[tmp] += val;
}

int get (int tmp) {
	int cnt = 0;
	int pointer = 0;
	for (int i = 20; ~i; i--)
		if ((pointer | (1 << i)) < MAX_N && cnt + Fen[pointer | (1 << i)] < tmp) {
			pointer |= (1 << i);
			cnt += Fen[pointer];
		}

	return pointer + 1;
}

int Map (int d) {
	return lower_bound(Brr, Brr + len, d) - Brr + 1;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> Arr[i];
		Brr[i] = Arr[i];
	}
	
	sort(Brr, Brr + n);
	len = unique(Brr, Brr + n) - Brr;

	for (int i = 0; i < n; i++)
		upd(Map(Arr[i]), +1);

	for (int i = 0; i < n; i++) {
		upd(Map(Arr[i]), -1);
		cout << Brr[get(n / 2) - 1] << "\n";

		upd(Map(Arr[i]), +1);
	}
	return 0;
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define setbits __builtin_popcount 
#define big 1e9+7;
using namespace std;
ll n,k,m,flag,mod;
ll height[100005],dp[100005];
string s;
int main()
{
	IOS;
	cin>>n;
	for (int i = 0; i < n; ++i)
		cin>>height[i];
	dp[1] = abs(height[1] - height[0]);
	for (int i = 2; i < n; ++i)
		dp[i] = min(dp[i-1]+abs(height[i-1]-height[i]),dp[i-2]+abs(height[i]-height[i-2]));
	cout<<dp[n-1];
    return 0;
}

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

#define pb         push_back

const int INF = 100000000;

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

int main(void) {
	int n;
	while(cin >> n, n){
		int left = 0;
		int right = 0;
		int up = 0;
		int down = 0;
		vector< pair<int, int> > sq;
		sq.pb(make_pair(0,0));

		for(int i=0; i<n-1; i++){
			int num;
			int dir;
			cin >> num >> dir;
			
			int y = sq[num].first + dy[dir];
			int x = sq[num].second + dx[dir];
			left = min(x, left);
			right = max(x, right);
			up = max(y, up);
			down = min(y, down);
			//printf("%d %d %d %d\n", left, right, up, down);
			sq.pb(make_pair(y, x));
		}

		cout << right + 1 - left << " " << up + 1 - down << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1204
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;


void solve() {
    int N, M;
    cin >> N >> M;
    
    string S;
    cin >> S;
    each(c, S)c -= 'A';
    vector<vi> deg(2, vi(N)), G(N);

    rep(i, M) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        deg[S[v]][u]++;
        deg[S[u]][v]++;
        G[u].push_back(v);
        G[v].push_back(u);
    }

    queue<int> Q;
    rep(i, N)if (!deg[0][i] || !deg[1][i]) {
        Q.push(i);
    }

    int cnt = N;
    while (!Q.empty()) {
        int u = Q.front();
        Q.pop();
        each(v, G[u]) {
            if (deg[S[u]][v]-- == 1 && deg[1-S[u]][v] > 0) {
                Q.push(v);
            }
        }
        cnt--;
    }
    cout << (cnt > 0 ? "Yes" : "No") << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}

Measured memory_bytes: 12132
#include <stdio.h>

int main(void)
{
	char mass[8][8];
	int i, j;
	
	while (scanf("%s", mass[0]) != EOF){
		for (i = 1; i < 8; i++){
			scanf("%s", mass[i]);
		}
		
		for (i = 0; i < 8; i++){
			for (j = 0; j < 8; j++){
				if (mass[i][j] == '1' && mass[i][j + 1] == '1'){
					if (mass[i + 1][j] == '1' && mass[i + 1][j + 1] == '1'){
						printf("A\n");
					}
					else if (mass[i][j + 2] == '1' && mass[i][j + 3] == '1'){
						printf("C\n");
					}
					else if (mass[i + 1][j + 1] == '1' && mass[i + 1][j + 2] == '1'){
						printf("E\n");
					}
					else if (mass[i + 1][j - 1] == '1' && mass[i + 1][j] == '1'){
						printf("G\n");
					}
				}
				else if (mass[i][j] == '1' && mass[i + 1][j] == '1'){
					if (mass[i + 2][j] == '1' && mass[i + 3][j] == '1'){
						printf("B\n");
					}
					else if (mass[i + 1][j - 1] == '1' && mass[i + 2][j - 1] == '1'){
						printf("D\n");
					}
					else if (mass[i + 1][j + 1] == '1' && mass[i + 2][j + 1] == '1'){
						printf("F\n");
					}
				}
			}
		}
	}
	return (0);
}

Measured memory_bytes: 524
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define FOR(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)


int main(){
	ll N,K;
	cin >> N >> K;
	string S;
	cin >> S;
	
	int score = 0;
	int cnt = 1;
	FOR(i, N-1) {
		if (S[i] == S[i + 1]) {
			cnt += 1;
		}else {
			if (cnt >= 2) {
				score += (cnt-1);
			}
			cnt = 1;
		}
	}
	if (cnt >= 2) {
		score += (cnt - 1);
	}

	int ans = min(N - 1, score + 2 * K);
	cout << ans << endl;

}

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

#define ll long long
#define rep(A,B,C) for(A=B;A<C;++A)
#define repd(A,B,C) for(A=(ll)C-1;A>=B;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>
template<typename T>
void mxin(T& a,T b){if(a<b)a = b;}
template<typename T>
void mnin(T& a,T b){if(a>b)a = b;}
using namespace std;

/////////////////////////////////////////////////////
#define MOD 998244353


ll A, B, C, D;
ll dp[3030][3030];
ll i, j, k;

int main(){
    scanf("%lld%lld%lld%lld", &A, &B, &C, &D);

    dp[A][B] = 1;
    rep(i,A,C+1){
        rep(j,B,D+1){
            (dp[i + 1][j] += dp[i][j] * j) %= MOD;
            (dp[i][j + 1] += dp[i][j] * i) %= MOD;
            (dp[i + 1][j + 1] += MOD - dp[i][j] * i * j % MOD) %= MOD;
        }
    }
    printf("%lld\n", dp[C][D]);
    return 0;
}

Measured memory_bytes: 74772
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<int(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define show(x) cout<< #x << " = " << x << endl
using namespace std;

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

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

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

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const int N_MAX=100010;

int main(){
	int n;
	cin>>n;
	int dp[n+1];
	REP(i,n+1)dp[i]=INF;
	dp[0]=0;
	for(int i=0;i<=n;i++){
		if(i+1<=n)
			dp[i+1]=min(dp[i+1],dp[i]+1);
		for(int j=1;j<n;j++){
			int k=int(pow(6,j));
			if(i+k<=n){
				dp[i+k]=min(dp[i+k],dp[i]+1);
			}else break;
		}
		for(int j=1;j<n;j++){
			int k=int(pow(9,j));
			if(i+k<=n){
				dp[i+k]=min(dp[i+k],dp[i]+1);
			}else break;
		}
	}
	cout<<dp[n]<<endl;
	return 0;
}


Measured memory_bytes: 768
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s,d[100000],f,g,h,j,i;
	while(1){
		scanf("%d",&a);
			if(a==-1) break;
		s=4;
		while(1){
			if(a<s) break;
			s*=4;
		}
		s/=4;
		i=0;
		while(1){
			if(s==1) break; 
			d[i]=a/s;
			a=a%s;
			s/=4;
			i++;
		}
		d[i]=a;
		for(j=0;j<=i;j++)
			printf("%d",d[j]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 2576
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>
#include <memory.h>

using namespace std;

typedef long long ll;

const ll MAXV = 1e5;
ll V;
// firstに頂点、secondにコストとした隣接リスト
vector<pair<ll, ll> > graph[MAXV];
ll used[MAXV]; // 頂点がTに含まれているかどうか

// 最小全域木のコストを返す
ll prim(){
  ll res = 0;
  // firstにmincost、secondにid
  priority_queue<pair<ll, ll>, vector<pair<ll, ll> >, greater<pair<ll, ll> > > PQ;
  PQ.push(make_pair(0, 0));
  while(!PQ.empty()){
    pair<ll, ll> p = PQ.top(); PQ.pop();
    ll v = p.second;
    if(used[v] == true) continue;
    used[v] = true;
    res += p.first;
    for(int i=0;i<graph[v].size();i++){
      ll to = graph[v][i].first;
      ll cost = graph[v][i].second;
      if(!used[to]) PQ.push(make_pair(cost, to));
    }
  }
  return res;
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cin >> V;
  // X.firstはx座標, X.secondはid
  vector<pair<int, int> > X, Y;
  for(int i=0;i<V;i++){
    int tx, ty; cin >> tx >> ty;
    X.push_back(make_pair(tx, i));
    Y.push_back(make_pair(ty, i));
  }
  sort(X.begin(), X.end());
  sort(Y.begin(), Y.end());
  for(int i=0;i<V-1;i++){
    ll costX = X[i+1].first - X[i].first;
    ll costY = Y[i+1].first - Y[i].first;
    graph[X[i].second].push_back(make_pair(X[i+1].second, costX));
    graph[X[i+1].second].push_back(make_pair(X[i].second, costX));
    graph[Y[i].second].push_back(make_pair(Y[i+1].second, costY));
    graph[Y[i+1].second].push_back(make_pair(Y[i].second, costY));
  }
  cout << prim() << endl;
}

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

int main() {
  int N,A,B;
  cin>>N;
  A=0;
  B=0;
  vector<int> a(N);
  for(int i=0;i<N;i++){cin>>a.at(i);}
  for(int i=0;i<N;i++){
    int max=0;
    int num=0;
    for(int j=0;j<N;j++){
      if (a.at(j)>max){max=a.at(j);num=j;}
    }
    a.at(num)=0;
    if(i%2==0){
      A+=max;
    }
    if(i%2==1){
      B+=max;
    }
  }
  cout<<A-B<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
int main() {
 int N, R;
 scanf("%d %d", &N, &R);
 int ret;
 if (N >= 10) {
  ret = R;
 } else {
  ret = R + (100 * (10 - N));
 }
 printf("%d\n", ret);
 return 0;
}

Measured memory_bytes: 128
let n = Int(readLine()!)!

let b = readLine()!.characters.split{$0 == " "}.map{ Int(String($0))! }

var ret = b[0]

for i in 0..<n-2 {
  ret += min(b[i], b[i + 1])
}

ret += b[n - 2]

print(ret)

Measured memory_bytes: 4080
#include <iostream>
#include <vector>

int main(){
	int n;
	std::vector< int > r, c;
	std::vector< std::vector< int > > dp;
	
	std::cin >> n;
	r.resize(n);
	c.resize(n);
	dp.resize(n);
	
	for(int i=0; i<n; ++i){
		std::cin  >> r[i] >> c[i];
		dp[i].resize(n);
		dp[i][i] = 0;
	}
	
	for(int m=1; m<n; ++m){
		for(int i=0; i<n; ++i){
			int j = m + i;
			if(j>=n)break;
			
			int min = -1;
			for(int k=i; k<j; ++k){
				int t = dp[i][k] + dp[k+1][j] + r[i] * c[k] * c[j];
				
				if(min == -1 || min > t){
					min = t;
				}
			}
			dp[i][j] = min;
		}
	}
	
	std::cout << dp[0][n-1] << std::endl;
	
	return 0;
}

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

vector<vector<int>> a(0, vector<int>(0));
vector<vector<int>> b(0, vector<int>(0));
int f(){
  int k = a.size();
  int l = a.at(0).size();
  rep(i, k) a.at(i).push_back(l+1);
  rep(i, k){//2
    rep(j, l+1){//3
      b.push_back({});
      rep(m, l+1) b.at(i*(l+1)+j).push_back(a.at(i).at((m+j)%(l+1)));
    }
  }
  while(a.size() != 0){
    a.pop_back();
  }
  rep(i, b.size()) a.push_back(b.at(i));
  while(b.size() != 0){
    b.pop_back();
  }
  return 0;
}

int main(){
	int n;
	cin >> n;
    vector<int> ns0(n);
    vector<int> ns1(n);
    rep(i, n) cin >> ns0.at(i);
    rep(i, n) cin >> ns1.at(i);
    a.push_back({1});
    rep(i, n-1) f();
    sort(a.begin(), a.end());
    int c, d;
    int f0 = 0;
    int f1 = 0;
    rep(i, a.size()){
      f0 = 0;
      f1 = 0;
      rep(j, n){
        if(a.at(i).at(j) != ns0.at(j)) f0 = 1;
        if(a.at(i).at(j) != ns1.at(j)) f1 = 1;
      }
      if(f0 == 0) c = i+1;
      if(f1 == 0) d = i+1;
    }
    cout << abs(c-d) << endl;
}

Measured memory_bytes: 6384
#include <iostream>
#include <vector>
using namespace std;
int main()
{
  int N;
  cin >> N;
  vector <int> k(N+1);
  for (int i = 0; i < N; i++) cin >> k[i];
  
	k[N] = 0; // stopper

	int ans = 0;
	int stpos = 0;
	int pos = stpos;
	while (stpos < N) {
		if ((pos==stpos) && (k[stpos]==0)) {
			stpos++;
			pos = stpos;
			continue;
		}

		if (k[pos]==0) {
			ans++;
			pos = stpos;
			continue;
		}

		k[pos++]--;
	}

	cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    vi a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    ll k; cin >> k; k--;
    cout << a[k] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool comp(int a, int b) 
{ 
    return (a < b); 
} 
int main(){
  int dp[100001][3]={0}, n, a[100001][3], k;
  cin>>n;
  for(int i=0;i<n;i++){
  	for(int j=0;j<3;j++)
    	cin>>a[i][j];
  }
  dp[0][0]=a[0][0];
  dp[0][1]=a[0][1];
  dp[0][2]=a[0][2];
  for(int i=1;i<n;i++){
  	dp[i][0]=max({dp[i][0],dp[i-1][1]+a[i][0],dp[i-1][2]+a[i][0]},comp);
  	dp[i][1]=max({dp[i][1],dp[i-1][0]+a[i][1],dp[i-1][2]+a[i][1]},comp);
  	dp[i][2]=max({dp[i][2],dp[i-1][1]+a[i][2],dp[i-1][0]+a[i][2]},comp);
  }
  cout<<std::max({dp[n-1][0],dp[n-1][1],dp[n-1][2]},comp)<<"\n";
}
  


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

int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  if((a==b && b!=c)||(a==c && b!=c) || (c==b && a!=b))
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}

Measured memory_bytes: 256
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var one = nextIntArray();
  var N = one[0];
  var M = one[1];
  var list = new Array(N);
  for(var i = 0; i < N; i++){
    list[i] = {
      child : new Set(),
      parent : new Set(),
      from : null,
    };
  }
  for(var i = 0; i < N - 1 + M; i++){
    var tmp = nextIntArray();
    list[tmp[0] - 1].child.add(tmp[1] - 1);
    list[tmp[1] - 1].parent.add(tmp[0] - 1);
  }
  for(var i = 0; i < N; i++){
    if(list[i].parent.size == 0){
      topologicalSort(i);
      break;
    }
  }
  var output = new Array(N);
  for(var i = 0; i < N; i++){
    output[i] = list[i].from;
    if(output[i] == null){
      output[i] = 0;
    }
  }
  myout(myconv(output,9));
  
  function topologicalSort(index){
    var ok = [];
    var queue = [index];    
    while(queue.length > 0){
      var parent = queue.shift();
      ok.push(parent);
      var child = Array.from(list[parent].child);
      for(var i = 0; i < child.length; i++){
        list[parent].child.delete(child[i]);
        list[child[i]].parent.delete(parent);
        if(list[child[i]].parent.size == 0){
          list[child[i]].from = parent + 1;
          queue.push(child[i]);
        }
      }
    }
    //myerr(ok);
    //myerr(list);
  }
}


Measured memory_bytes: 112268
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

N, A , B = LI()

print(min(N*A, B))


Measured memory_bytes: 67052
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount
           
#define rep(i, n) for (int i = 0; i < n; ++i)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


int main()
{
    int n;
    static int new_ok[100010];
    scanf("%d", &n);
    rep (i, n)
    {
	int a, b;
	scanf("%d%d", &a, &b);
	if (a > n + 1)
	    continue;
	if (b > n + 1)
	    b = n + 1;
	++new_ok[b];
	--new_ok[a - 1];
    }
    ++new_ok[n + 1];

    int res = -3, ok = 0;
    for (int i = n + 1; i > 0; --i)
    {
	ok += new_ok[i];
	if (ok >= i)
	{
	    res = i - 1;
	    break;
	}
    }
    printf("%d\n", res);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;

struct Point{
  int time;
  int x, y;
};

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

   int t, x, y;
   Point p;
   p.time = p.x = p.y = 0;
   int del = 0, dif = 0;
   bool flag = true;
   for(int i = 0; i < n; i++){
     cin >> t >> x >> y;
     del = t - p.time;
     dif = abs(p.x - x) + abs(p.y - y);
     if(del < dif || (del - dif) % 2 == 1){
      flag = false; 
     }else{
        p.time = t;
        p.x = x;
        p.y = y;
     }
   }

  if(flag){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#ABC132B
n = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(1,n-1):
    if p[i-1] < p[i] < p[i + 1] or p[i + 1] < p[i] < p[i-1]:
        count = count + 1
    else:
        pass

print(count)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <bitset>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repm(i, a, n) for (int i = a; i >= n; i--)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vs vector<string>
#define vii vector<vector<int>>
#define vll vector<ll>
#define vllll vector<vector<ll>>
#define vd vector<double>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())
#define reverse_v(a) reverse(a.begin(), a.end())
#define fi first
#define se second

void print(bool c)
{
    (c) ? (cout << "Yes" << endl) : (cout << "No" << endl);
}

void Print(bool c)
{
    (c) ? (cout << "YES" << endl) : (cout << "NO" << endl);
}

//最小公倍数
template <typename T>
T gcd(T a, T b)
{
    while (1)
    {
        if (a < b)
            swap(a, b);
        if (b == 0)
            break;
        a %= b;
    }
    return a;
}

//最大公約数
template <typename T>
T lcm(T a, T b)
{
    return a * b / gcd(a, b);
}
//セカンドキー->ファーストキーの順ソート
bool cmp(const pii &a, const pii &b)
{
    if (a.second != b.second)
        return a.second < b.second;
    return a.first < b.first;
}

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

int eve(int x)
{
    if (x % 400 == 0)
        return 1;
    if (x % 100 == 0)
        return 0;
    if (x % 4 == 0)
        return 1;
    return 0;
}

int main(void)
{
    ll n, k, p[3];
    string t, hand, rsp = "rsp";
    cin >> n >> k >> p[0] >> p[1] >> p[2] >> t;
    ll ans = 0;
    rep(i, 0, n)
    {
        rep(j, 0, 3)
        {
            if (t[i] == rsp[j])
            {
                if (i - k >= 0 && hand[i - k] == rsp[(j + 2) % 3])
                {
                    hand += 'f';
                    continue;
                }
                hand += rsp[(j + 2) % 3];
                ans += p[(j + 2) % 3];
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int maxn = 100005;
typedef long long ll;
vector<int> v[maxn*2];
vector<int> cnt;
bool visited[maxn*2];

void dfs(int x)
{
     if (visited[x]) return;
    visited[x] = true;
    cnt[x/maxn]++;
    for(auto u: v[x]) dfs(u);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        int x,y;
        cin >> x >> y;
        y += maxn;
        v[x].push_back(y);
        v[y].push_back(x);
    }

    ll ans = 0;
    for(int i = 0; i < 2*maxn; i++){
        if(visited[i]) continue;
        cnt = vector<int> (2);
        dfs(i);
        ans += (ll) cnt[0] * cnt[1];
    }
    ans -= n;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 10240
#include <bits/stdc++.h>
using namespace std;
int main () {
  int W, H, N;
  cin >> W >> H >> N;
  int l = 0, r = W, u = H, d = 0;
  int x, y, a;
  for(int i = 0; i < N; i++) {
    cin >> x >> y >> a;
    if(a == 1) l = max(x, l);
    else if(a == 2) r = min(x, r);
    else if(a == 3) d = max(y, d);
    else if(a == 4) u = min(y, u);
  }
  cout << max((r - l), 0) * max((u - d), 0)<< endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <string>
#include <queue>

using namespace std;

static const int N = 3;
static const int N2 = 9;

class Puzzle {
public:
    int piece[N2];
    int space;
    string path;

    Puzzle() {}

    Puzzle(int space, string path) : space(space), path(path) {}

    bool operator<(const Puzzle &p) const {
        for(int i = 0; i < N2; i++)
        {
            if(piece[i] == p.piece[i])
                continue;
            return piece[i] < p.piece[i];
        }
        return false;
    }
};

static const int dx[4] = {-1, 0, 1, 0};
static const int dy[4] = {0, -1, 0, 1};
static const char dir[4] = {'u', 'l', 'd', 'r'};

bool isTarget(Puzzle p)
{
    for (int i = 0; i < N2; i++)
        if (p.piece[i] != (i + 1)) // 不正解
            return false;

    return true;
}

string bfs(Puzzle start)
{
    queue<Puzzle> Q;
    map<Puzzle, bool> is_visit;
    Puzzle u, v;
    start.path = "";
    Q.push(start);
    is_visit[start] = true;

    while (!Q.empty())
    {
        u = Q.front();
        Q.pop();

        if (isTarget(u))
            return u.path;

        int sx = u.space / N; // 空きマスのx座標
        int sy = u.space % N; // 空きマスのy座標
        for (int direct = 0; direct < 4; direct++)
        {
            int tx = sx + dx[direct]; // 遷移先の空きマスのx座標
            int ty = sy + dy[direct]; // 遷移先の空きマスのy座標
            if (tx < 0 || tx >= N || ty < 0 || ty >= N)
                continue; // 枠外にでたら無視
            v = u;
            swap(v.piece[u.space], v.piece[tx * N + ty]); // ピースを移動
            v.space = tx * N + ty;
            if(!is_visit[v])
            {
                is_visit[v] = true;
                v.path += dir[direct];
                Q.push(v);
            }
        }
    }

    return "unsolvable";
}

int main()
{
    Puzzle input;

    for(int i = 0; i < N2; i++)
    {
        cin >> input.piece[i];
        if(input.piece[i] == 0)
        {
            input.piece[i] = N2;
            input.space = i;
        }
    }

    string answer = bfs(input);
    cout << answer.size() << endl;
}


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

#define ll long long

int main(){
    ll h,w,n;
    cin >> h >> w >> n;
    h = max(h,w);
    if( n % h == 0)
        cout<< n/h;
    else
    {
        cout<< n/h + 1;
    }


    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 REP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define MP(a,b) make_pair(a,b)
typedef long long LL;
typedef pair<int, int> PI;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
const LL MOD = 1000000007LL;
int main() {
	string S;
	cin >> S;
	int cnt = 0;
	rep(i, S.size()) {
		if (S[i] == 'p') cnt++;
	}
	cout << S.size() / 2 - cnt << endl;
}

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

using namespace std;
#define ll long long
#define ld long double
#define INF 0x3f3f3f3f
const int N=2e5 + 5;
const ll mod = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    string s1, s2;
    cin >> s1 >> s2;
    if(s1 == s2.substr(0, s1.length()) && s2.length() == s1.length() + 1) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

typedef long long ll;
const int maxn=1e5+10;
int n,m,s,t;
ll diss[maxn],dist[maxn],ans[maxn];
int ebeg[maxn],eto[maxn<<1],enxt[maxn<<1],ecnt,ew[maxn<<1],eww[maxn<<1];
bool inq[maxn];

void ae(int u,int v,int a,int b){
	++ecnt;
	enxt[ecnt]=ebeg[u];
	ebeg[u]=ecnt;
	eto[ecnt]=v;
	ew[ecnt]=a;
	eww[ecnt]=b;
}

int main(){
	cin>>n>>m>>s>>t;
	for(int i=0,u,v,a,b;i<m;++i){
		cin>>u>>v>>a>>b;
		ae(u,v,a,b);ae(v,u,a,b);
	}
	{
		queue<int> q;
		memset(diss,100,sizeof(diss));
		diss[s]=0;
		q.push(s);
		inq[s]=true;
		while(!q.empty()){
			int pos=q.front();q.pop();
			for(int i=ebeg[pos],v;i;i=enxt[i])
				if(diss[v=eto[i]]>diss[pos]+ew[i]){
					diss[v]=diss[pos]+ew[i];
					if(!inq[v]){
						inq[v]=true;
						q.push(v);
					}
				}
			inq[pos]=false;
		}
		memset(dist,100,sizeof(dist));
		dist[t]=0;
		q.push(t);
		inq[t]=true;
		while(!q.empty()){
			int pos=q.front();q.pop();
			for(int i=ebeg[pos],v;i;i=enxt[i])
				if(dist[v=eto[i]]>dist[pos]+eww[i]){
					dist[v]=dist[pos]+eww[i];
					if(!inq[v]){
						inq[v]=true;
						q.push(v);
					}
				}
			inq[pos]=false;
		}
	}
	for(int i=1;i<=n;++i)
		ans[i]=(ll)1e15-diss[i]-dist[i];
	for(int i=n-1;i;--i)
		ans[i]=max(ans[i],ans[i+1]);
	for(int i=1;i<=n;++i)
		cout<<ans[i]<<endl;
	return 0;
}

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

int main() {
    int N, l , r;
    int sum = 0;
    cin >> N;

    for (int i = 0; i < N; i++) {
        cin >> l >> r;
        sum += r - l + 1;
    }
    cout << sum << endl;

}


Measured memory_bytes: 3580
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.container;
import std.datetime;

void main()
{
	while (1) {
		auto str = readln.chomp;
		if (str == "#") break;
		int i = str.length.to!int-1;
		long a, b = 1;
		
		while (i > 0) {
			a *= 2;
			b *= 2;
			if (str[i] == 'h') {
				a -= 90;
				a = max(0, a);
				i -= 5;
			} else {
				a += 90;
				a = min(90*b/2, a);
				i -= 4;
			}
		}
		
		if (b != 2) {
			b /= 4;
			a /= 2;
		} else {
			b /= 2;
		}
		if (b == 1) a.writeln;
		else writeln(a, "/", b);
	}
}

Measured memory_bytes: 1180
<?php
 sscanf(fgets(STDIN), "%d %d", $N, $D);
 $ans = 0;
 $psec = 0;
 foreach(preg_split("/ /", fgets(STDIN)) as $value){
  $value = intval($value);
  $sub = $value - $psec;
  if($sub > 0 && $sub < $D){
    $ans -= $D - $sub;
  }
  $ans += $D;
  $psec = $value;
 }
 echo $ans;
?>

Measured memory_bytes: 40948
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        Integer[] L = new Integer[N];
        for (int i = 0; i < N; i++) {
            L[i] = scanner.nextInt();
        }
        long ans = 0;
        Arrays.sort(L, Collections.reverseOrder());
        for (int j = 0; j < N - 2; j++) {
            for (int i = j + 1; i < N - 1; i++) {
                if (L[j] >= L[i] + L[i+1]) {
                    break;
                }
                for(int k = i + 1; k < N; k++) {
                    if (L[j] < L[i] + L[k]) {
                        ans++;
                    }else{
                        break;
                    }
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 27888
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using Debug;
//using static System.Globalization.CultureInfo;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
        Solve();
        //WriteLine(Solve());
    }
    static void Solve()
    {
        var nq = Input.ar;
        Func<long,long,long> func = (long val1, long val2) => Min(val1, val2);
        var seg = new SegmentTree<long>(nq[0],(1L<<31)-1,func);
        var res = new List<long>();
        while (nq[1]-- > 0)
        {
            var qu = Input.ar;
            if (qu[0] == 0)
                seg.Update(qu[1], qu[2]);
            else res.Add(seg.query(qu[1], qu[2] + 1));
        }
        WriteLine(string.Join("\n", res));
    }
}

public class Input
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public static char[][] gred(int h) 
        => Enumerable.Repeat(0, h).Select(v => read.ToCharArray()).ToArray();
    public static int[][] ar2D(int num)
        => Enumerable.Repeat(0, num).Select(v => ar).ToArray();
    public static long[][] arL2D(int num)
        => Enumerable.Repeat(0, num).Select(v => arL).ToArray();
    public const long Inf = (long)1e18;
    public const double eps = 1e-6;
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}

class SegmentTree<T>
{
    private List<T> item;
    private int _num;
    private Func<T, T, T> _func;
    private Func<T, T> updateFunc;
    private T _inf;

    public int Parent(int index)
        => (index + 1) / 2 - 1;
    public int Left(int index)
        => 2 * index + 1;
    public int Right(int index)
        => 2 * (index + 1);

    public SegmentTree(int num, T inf, Func<T, T, T> func, Func<T, T> updateFunc=null)
    {
        _func = func;
        _num = 1;
        _inf = inf;
        this.updateFunc = updateFunc ?? ((T value) => value);
        while (_num < num)
            _num *= 2;
        item = new List<T>(2 * _num - 1);
        for (var i = 0; i < 2 * _num - 1; i++)
            item.Add(inf);
    }
    public void Update(int index, T value)
    {
        index += _num - 1;
        item[index] = updateFunc(value);
        while (Parent(index) >= 0)
        {
            index = Parent(index);
            item[index] = _func(item[Left(index)], item[Right(index)]);
        }
    }
    public T query(int left, int right)
        => query(left, right, 0, 0, _num);
    private T query(int left, int right, int k, int l, int r)
    {
        if (r <= left || right <= l) return _inf;
        if (left <= l && r <= right) return item[k];
        else
            return _func(query(left, right, Left(k), l, (l + r) / 2), query(left, right, Right(k), (l + r) / 2, r));
    }
}



Measured memory_bytes: 23684
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
using namespace std;
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const ll INF64 = 3e18;
const double INFD = 1e30;
const double EPS = 1e-10;
const double PI = acos(-1);
const int MOD = 317847191;
template <typename T>
inline T read() {
    T X = 0, w = 0;
    char ch = 0;
    while (!isdigit(ch)) {
        w |= ch == '-';
        ch = getchar();
    }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
    return w ? -X : X;
}
const int MAXN = 200005;
const int MAXV = 10000005;
int n, m, k;
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};
int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1};
int CASE = 1;
ll arr[MAXN];
ll b[MAXN];
char S[MAXN];
char T[MAXN];
int main() {
#ifdef LOCALLL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    ll k;
    scanf("%d%d%lld", &n, &m, &k);
    for (int i = 1; i <= n; i++) {
        arr[i] = arr[i - 1] + read<int>();
    }
    for (int i = 1; i <= m; i++) {
        b[i] = b[i - 1] + read<int>();
    }
    int ans = 0;
    for (int i = 0; i <= n; i++) {
        auto p = upper_bound(b + 1, b + m + 1, k - arr[i]);
        if (k - arr[i] < 0) break;
        --p;
        int s = (p - b);
        ans = max(ans, i + s);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 6952
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;

const int maxn=2e5+10;
int ans;
char s[maxn];

int main(){
	ios::sync_with_stdio(false);
	cin>>s;
	ans=strlen(s);
	for(int i=0,scnt=0;s[i];++i)
		if(s[i]=='S')
			++scnt;
		else if(scnt)
			--scnt,ans-=2;
	cout<<ans<<endl;
	return 0;
}

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

typedef vector<int> v;
typedef v::iterator vi;
int c = 0;

void mm(vi l, vi m, vi r)
{
	v L(m - l);
	copy(l, m, L.begin());
	vi cp = L.begin();

	for (vi i = l; i != r; i++)
		if (cp == L.end())
			break;
		else if (m == r) {
			copy(cp, L.end(), i);
			break;
		} else if(*cp <= *m)
			*i = *cp, cp++;
		else
			*i = *m, m++;
}

void ms(vi l, vi r)
{
	if (l + 1 < r) {
		int d = r - l;
		vi m = l + d / 2;
		c += d;
		ms(l, m);
		ms(m, r);
		mm(l, m, r);
	}
}

int main()
{
	int n;
	scanf("%d", &n);
	v S(n);
	for (int &x :S)
		scanf("%d", &x);

	ms(S.begin(), S.end());

	for (int &x: S)
		printf("%s%d", &x == &S[0] ? "": " ", x);
	puts("");
	printf("%d\n", c);
}



Measured memory_bytes: 5688
#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);
}

string s;

vector<pair<char, int>> fwd, bwd;

int main() {
    cin >> s;

    int n = s.size();

    FORN(i, n) bwd.PB(MP(s[i], i));

    fwd = bwd;
    reverse(fwd.begin(), fwd.end());

    int res = 0;

    while (!fwd.empty() && !bwd.empty() && fwd.back().SS < bwd.back().SS) {
        if (fwd.back().FF == bwd.back().FF) {
            fwd.pop_back();
            bwd.pop_back();
        }
        else if (fwd.back().FF == 'x') {
            fwd.pop_back();
            res++;
        }
        else if (bwd.back().FF == 'x') {
            bwd.pop_back();
            res++;
        }
        else {
            printf("-1\n");
            return 0;
        }
    }

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

    return 0;
}

Measured memory_bytes: 2164
# -*- coding:utf-8 -*-

def solve():
    N = int(input())
    S = input()

    Rnum = [0 for _ in range(N)]  # Rnum[i] := i以降の右側に何個Rがあるか？（i含む）
    Gnum = [0 for _ in range(N)]
    Bnum = [0 for _ in range(N)]

    if S[N-1] == "R":
        Rnum[N-1] = 1
    elif S[N-1] == "G":
        Gnum[N-1] = 1
    else:
        Bnum[N-1] = 1
    for i in range(N-2, -1, -1):
        if S[i] == "R":
            Rnum[i] = Rnum[i+1] + 1
            Gnum[i] = Gnum[i+1]
            Bnum[i] = Bnum[i+1]
        elif S[i] == "G":
            Rnum[i] = Rnum[i+1]
            Gnum[i] = Gnum[i+1] + 1
            Bnum[i] = Bnum[i+1]
        else:
            Rnum[i] = Rnum[i+1]
            Gnum[i] = Gnum[i+1]
            Bnum[i] = Bnum[i+1] + 1

    ans = 0
    for i in range(N-2):
        for j in range(i+1, N-1):
            if S[i]=="R" and S[j]=="G":
                ans += Bnum[j+1]
                if j+(j-i)<N:
                    if S[j+(j-i)] == "B":
                        ans -= 1
            elif S[i]=="R" and S[j]=="B":
                ans += Gnum[j+1]
                if j+(j-i)<N:
                    if S[j+(j-i)] == "G":
                        ans -= 1
            elif S[i]=="G" and S[j]=="R":
                ans += Bnum[j+1]
                if j+(j-i)<N:
                    if S[j+(j-i)] == "B":
                        ans -= 1
            elif S[i]=="G" and S[j]=="B":
                ans += Rnum[j+1]
                if j+(j-i)<N:
                    if S[j+(j-i)] == "R":
                        ans -= 1
            elif S[i]=="B" and S[j]=="R":
                ans += Gnum[j+1]
                if j+(j-i)<N:
                    if S[j+(j-i)] == "G":
                        ans -= 1
            elif S[i]=="B" and S[j]=="G":
                ans += Rnum[j+1]
                if j+(j-i)<N:
                    if S[j+(j-i)] == "R":
                        ans -= 1

    print(ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 69120
# -*- coding: utf-8 -*-
"""
Cumulative Sum - The Maximum Number of Customers
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_5_A&lang=jp

"""
import sys


def solve(events):
    ans, customer = 0, 0
    for _, e in events:
        customer += e
        ans = max(ans, customer)
    return ans


def main(args):
    N, T = map(int, input().split())
    events = []
    for _ in range(N):
        l, r = map(int, input().split())
        events.append((l, 1))
        events.append((r, -1))
    ans = solve(sorted(events))
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])



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

typedef long long ll;

void lc(ll a,ll b)
{
	ll m=a,n=b,c;  
    while(b!=0)  
    { 
    	c=a%b; 
		a=b; 
		b=c;
	} 
	printf("%lld %lld\n",a,m/a*n);
}
int main (void)
{
	ll a,b;
	while(scanf("%lld%ulld",&a,&b)!=EOF)
	    lc(a,b);
	return 0;
}
 


Measured memory_bytes: 3180