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

typedef int integer;
#define int long long

using namespace std;

int m, n, t, k;

integer main() {
    ios_base::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    int x = (c - a - b);
    x *= x;
    int y = 4 * a * b;
    if (c - a - b < 0){
        cout << "No\n";
        return 0;
    }
    if (x > y){
        cout << "Yes\n";
    } else {
        cout << "No\n";

    }

}



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;
using P = pair<int,int>;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
    ll X, Y;
    cin >> X >> Y;
    ll mx3 = 2 * X - Y;
    if (mx3 < 0 || mx3 % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }
    ll m = mx3 / 3;

    ll nx3 = 2 * Y - X;
    if (nx3 < 0 || nx3 % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }
    ll n = nx3 / 3;

    combination c(m + n);
    cout << c(m + n, m) << endl;
    return 0;
}


Measured memory_bytes: 13796
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 200000000000
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()

bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}
// 入力



int main() {
    ll N;
    cin >>N;
    vector<ll> a(N);
    rep(i,N){
        cin >> a[i];
    }
    ll now =1;
    ll ans = 0;
    rep(i,N){
        if(a[i] == now){
            now++;
        }else{
            ans++;
        }
    }
    if(ans == N){
        ans = -1;
    }
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 4840
kai = input()
num = len(kai)

ans = 0

n1 = int((num-1) / 2)

for i in range(n1):
    if kai[i] != kai[-1*(i+1)]:
        ans += 1

l1 = kai[0:n1]

for i in range(len(l1)):
    if l1[i] != l1[-1*(i+1)]:
        ans += 1

l2 = kai[n1+1:]

for i in range(len(l2)):
    if l2[i] != l2[-1*(i+1)]:
        ans += 1

if ans == 0:
    print("Yes")

else:
    print("No")

Measured memory_bytes: 9056
N, K, Q = map(int, input().split())
A = [0]*N

for i in range(Q):
    x = int(input())-1
    A[x] += 1 

for i in range(N):
    if K - (Q - A[i])  >  0:
        print("Yes")
    else:
        print("No") 

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

#define sz(s) (int)(s).size()
#define re(i, n) for (int i = 1; i <= n; i ++)
#define pb push_back
#define finish(x) return cout << x << endl, 0
#define MP make_mair
#define trav(x, a) for(auto& x: a)
#define all(x) (x).begin,(x).end()
#define Sor(x) sort(all(x))
#define REV(x) reverse(all(x))
#define F first
#define S second
#define I insert
#define N 222222
#define MOD 1000000007

using namespace std;

typedef long long ll;
vector <ll> vll;
template <class T> bool umin(T& a, T b) {if(a>b){a = b; return 1;}return 0;}
template <class T> bool umax(T& a, T b) {if(a<b){a=b; return 1;}return 0;}
template <class T, class TT> bool pal(T a, TT n){int k = 0; for(int i =0; i <= n / 2; i ++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

ll powmod(ll a, ll b, ll m = MOD){ll r = 1;while(b>0){if(b&1)r=r*a%m;a=a*a%m;b>>=1;}return r;}


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5])
    	cout << "Yes";
    else
    	cout << "No";
	    
    
    
    
    
    
    
    
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n,k;
  cin>>n>>k;
  int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  int dp[n];
  dp[0]=0;
  for(int i=1;i<n;i++)
  {
    dp[i]=1000000000;
    for(int j=min(i,k);j>0;j--)
      dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
//      cout<<dp[i]<<" ";
  }
  cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024
suretu = "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"
suretu = suretu.split(",")

for i in range(len(suretu)):
    suretu[i] = int(suretu[i])

k = int(input())
if k >= 1 and k <= 32:
    #print(k)
    print(suretu[k-1])

Measured memory_bytes: 2940
#include <stdio.h>

int main()
{
	int i, N, M, Q, a[51], b[51], c[51], d[51];
	scanf("%d %d %d", &N, &M, &Q);
	for (i = 1; i <= Q; i++) scanf("%d %d %d %d", &(a[i]), &(b[i]), &(c[i]), &(d[i]));
	
	int A[12] = {}, max = 0, sum;
	for (i = 1, A[0] = 1, A[N+1] = M; i <= N; i++) A[i] = 1;
	while (1) {
		for (i = 1, sum = 0; i <= Q; i++) if (A[b[i]] - A[a[i]] == c[i]) sum += d[i];
		if (max < sum) max = sum;
		
		for (i = N; i >= 1; i--) if (A[i] < A[i+1]) break;
		if (i == 0) break;
		for (A[i++]++; i <= N; A[i++] = A[i-1]);
	}
	
	printf("%d\n", max);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1708
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=602,K=200020;
int n,m,a,b,i,j,d;
bool col[N][N];
void Col(int x){
    d=0;
    while(x%4==0)
        x/=4,d++;
    if(x&1){
        for(i=0;i<m;i++)
            for(j=0;j<m;j++)
                if((i>>d&1)^(j>>d&1))
                    col[i][j]=1;
    }
    else{
        for(i=0;i<m;i++)
            for(j=0;j<m;j++)
                if((i>>d&1))
                    col[i][j]=1;       
    }
}
int main(){
    scanf("%d%d%d",&n,&a,&b);
    m=n*2;
    n*=n;
    Col(a);Col(b);
    for(i=0;i<m;i++)
        for(j=0;j<m;j++)
            if(col[i][j]==0){
                printf("%d %d\n",i,j);
                n--;
                if(!n)return 0;
            }
}

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

bool isSquare(int x){
	int tmp = sqrt(x);
	return (tmp * tmp == x);
}

signed main(){
	int a,b,bb;
	cin >> a >> b;
	bb = b;
	while(bb){
		a *= 10;
		bb /= 10;
	}
	cout << (isSquare(a + b) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
import sys, math
from collections import defaultdict
from itertools import product
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    n = ii()
    S = [input() for i in range(n)]
    d = defaultdict(int)
    for c in S[0]:
        d[c] += 1
    for i in range(n):
        tmp = defaultdict(int)
        for c in S[i]:
            tmp[c] += 1
        for k in d.keys():
            d[k] = min(d[k], tmp[k])
    l = [k*v for k, v in d.items()]
    l = ''.join(sorted(''.join(l)))
    print(l)

if __name__ == '__main__':
    main()

Measured memory_bytes: 68292
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
int n,m;
int A[100010],B[100010];
long long dp[100010],S[100010];
bool cmp(int x,int y)
{
	return S[x]-dp[x]<S[y]-dp[y];
}
vector<int>e[100010],son[100010];
int id[100010];
bool cmp2(int x,int y)
{
	return A[x]<A[y];
}
bool book[100010];
int fa[100010];
int find(int x)
{
	return fa[x]==x?x:fa[x]=find(fa[x]);
}
int work()
{
	for(int i=1;i<=n;i++)
		id[i]=i;
	sort(id+1,id+n+1,cmp2);
	for(int j=1;j<=n;j++)
	{
		int u=id[j];
		book[u]=true;
		fa[u]=u;
		for(int i=0;i<e[u].size();i++)
		{
			int v=e[u][i];
			if(book[v])
			{
				int f=find(v);
				if(f!=u)
				{
					fa[f]=u;
					son[u].push_back(f);
				}
			}
		}
	}
	return id[n];
}
long long res1[100010],res2[100010];
void solve(int u)
{
	S[u]=B[u];
	if(!son[u].size()){
		dp[u]=A[u]+B[u];
		return ;
	}
	for(int i=0;i<son[u].size();i++)
	{
		solve(son[u][i]);
		S[u]+=S[son[u][i]];
	}
	sort(son[u].begin(),son[u].end(),cmp);
	long long nsum=0;
	for(int i=0;i<son[u].size();i++)
	{
		int v=son[u][i];
		res1[i]=max(nsum+dp[v],i>0?res1[i-1]:0);
		nsum+=S[v];
	}
	res2[son[u].size()]=0;
	for(int i=son[u].size()-1;i>=0;i--)
	{
		int v=son[u][i];
		res2[i]=max(dp[v],res2[i+1]+S[v]);
	}
	dp[u]=1e18;nsum=0;
	for(int i=0;i<son[u].size();i++)
	{
		int v=son[u][i];
		long long val=0;
		if(i>0)val=max(val,res1[i-1]);
		val=max(val,nsum+res2[i+1]);
		val=max(val,A[u]+S[u]-S[v]);
		val=max(val,S[u]-S[v]+dp[v]);
		dp[u]=min(dp[u],val);
		nsum+=S[v];
	}
	return ;
}
int main()
{
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%d %d",&A[i],&B[i]);
		A[i]=max(A[i]-B[i],0);
	}
	for(int i=1;i<=m;i++)
	{
		int u,v;
		scanf("%d %d",&u,&v);
		e[u].push_back(v);
		e[v].push_back(u);
	}
	int rt=work();
	solve(rt);
	printf("%lld\n",dp[rt]);
	return 0;
}

Measured memory_bytes: 19324
#include<stdio.h>
int main(void)
{
	int n,i;
	int a[50];
	int b,t;
	int counter=0;
	
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&b);
		if(i+1!=b && counter==0){
			t=b;
			counter=1;
		}
		else if(i+1!=b && counter==1){
			if(t!=i+1){
				printf("NO");
				return 0;
			}
		}
	}
	printf("YES");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N + 1);
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
	}

	vector<int> X(N + 1, 0);
	vector<int> res;
	for (int i = N; i; i--) {
		int cnt = 0;
		for (int j = i; j <= N; j += i) {
			cnt ^= X[j];
		}
		if (cnt != A[i]) {
			X[i] = 1;
			res.push_back(i);
		}
	}
	cout << res.size() << endl;
	for (int i = 0; i < res.size(); i++) {
		if (i > 0)cout << " ";
		cout << res[i];
	}
	cout << endl;
}


Measured memory_bytes: 5108
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String[] str = in.nextLine().split(" ",0);
		int num1 = Integer.parseInt(str[0]);
		int num2 = Integer.parseInt(str[1]);
		int num3 = Integer.parseInt(str[2]);

		if(num3 >= num1 && num3 <= num2){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 23764
#include "bits/stdc++.h"
using namespace std;
int main()
{
    char a;
    bool b = false;
    for (int i = 0; i < 2; i++)
    {
        scanf("%c", &a);
        if (a == '9')
        {
            b = true;
            break;
        }
    }
    if (b)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
}


Measured memory_bytes: 256
H, W = map(int, input().split())
A = 0 

if H == 1 or W == 1:
  print('1')

elif H % 2 == 1:
  if W % 2 == 1:
    A += (H // 2 + 1) * (W // 2 + 1)
    A += (H // 2) * (W // 2)
    print(int(A))
    
  else:
    A += (H // 2 + 1) * (W // 2)
    A += (H // 2) * (W // 2)
    print(int(A))
      
else:
  A += (H / 2) * W
  print(int(A))
  


Measured memory_bytes: 3064
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")


def ok(a, i, j, l, o):
    if a > min(i, j, l):
        return 0
    i -= a
    j -= a
    l -= a
    return 6 * a + (i // 2) * 4 + (j // 2) * 4 + (l // 2) * 4 + o * 2


def main():
    i, o, t, j, l, s, z = map(int, input().split())

    low, high, ans = -1, int(1e14) - 1, 0
    while high - low > 1:
        middle = (low + high) // 2
        if ok(middle, i, j, l, o) > ans:
            ans = ok(middle, i, j, l, o)
            low = middle
        else:
            high = middle

    print(ans // 2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
n=int(input())
S=input()
C=[0]*n
C[0]=S[1:].count('E')
ans=C[0]
for i in range(n-1):
    C[i+1]=C[i]
    if S[i]=='W':
        C[i+1]+=1
    if S[i+1]=='E':
        C[i+1]-=1
    ans=min(ans,C[i+1])
print(ans)

Measured memory_bytes: 15436
#include <bits/stdc++.h>
 
#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;
 
/* DSU 
int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}
void make_set(int v) {
    parent[v] = v;
    rank[v] = 0;
}
void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (rank[a] < rank[b])
            swap(a, b);
        parent[b] = a;
        if (rank[a] == rank[b])
            rank[a]++;
    }
}
*/ 
ll power(ll base, ll exp) 
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}
 
ll mod(ll a, ll b) {return (a % b + b) % b;}
 
ll powerm(ll base,ll exp,ll mod) 
{ll ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
 
using namespace std;

int main()
{
	fast;
	ll n; cin>>n;
	ll sum = 0; unordered_map<ll,ll>mp;
	for(ll i = 0; i < n; i++)
	{
		ll x; cin>>x; sum += x;
		mp[x]++;
	}
	ll q;
	cin>>q;
	while(q--)
	{
		ll a,b; cin>>a>>b;
		if(!mp.count(a))
		{
			cout << sum << endl;
			continue;
		}
		ll ct = mp[a];
		mp.erase(a);
		if(mp.count(b)) mp[b] += ct;
		else mp[b] = ct;
		ll diff = (b*ct) - (ct * a);
		sum += diff;
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 6660
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n,x,ans=0;
	cin >> n >> x;
	long long a[n];
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	for(int i=0;i<n-1;i++){
		if(a[i]+a[i+1]>x){
			ans+=(a[i]+a[i+1]-x);
			a[i+1]-=(a[i]+a[i+1]-x);
			if(a[i+1]<0){
				a[i+1]=0;
			}
		}
	}
  	cout << ans << endl;
  	return 0;
}


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

int main() {
	using namespace std;
	ios_base::sync_with_stdio(false), cin.tie(nullptr);
	int N; cin >> N;
	struct constraint {
		bool z;
		uint64_t v;
	};
	vector<constraint> rows(N);
	vector<constraint> cols(N);
	for (int i = 0; i < N; i++) cin >> rows[i].z;
	for (int j = 0; j < N; j++) cin >> cols[j].z;

	for (int i = 0; i < N; i++) cin >> rows[i].v;
	for (int j = 0; j < N; j++) cin >> cols[j].v;

	auto id = [](bool z) -> uint64_t { return z ? uint64_t(0) : ~uint64_t(0); };
	auto op = [](bool z, uint64_t a, uint64_t b) -> uint64_t { return z ? (a | b) : (a & b); };

	uint64_t row_accum[2] = {id(0), id(1)};
	for (int i = 0; i < N; i++) {
		for (int z = 0; z < 2; z++) {
			row_accum[z] = op(z, row_accum[z], rows[i].v);
		}
	}
	uint64_t col_accum[2] = {id(0), id(1)};
	for (int j = 0; j < N; j++) {
		for (int z = 0; z < 2; z++) {
			col_accum[z] = op(z, col_accum[z], cols[j].v);
		}
	}

	vector<bool> row_parity(N);
	{
		bool cur_parity[2] = {true, true};
		for (int i = 0; i < N; i++) {
			row_parity[i] = (cur_parity[rows[i].z] ^= 1);
		}
	}
	vector<bool> col_parity(N);
	{
		bool cur_parity[2] = {true, true};
		for (int j = 0; j < N; j++) {
			col_parity[j] = (cur_parity[cols[j].z] ^= 1);
		}
	}

	auto get_cell = [&](int i, int j) -> uint64_t {
		const auto& [rz, rv] = constraint(rows[i]);
		const auto& [cz, cv] = constraint(cols[j]);
		if (rz == cz) {
			return op(!rz, rv, cv);
		} else {
			if (row_parity[i] ^ col_parity[j]) {
				return op(!cz, cv, op(!rz, ~row_accum[cz], rv));
			} else {
				return op(!rz, rv, op(!cz, ~col_accum[rz], cv));
			}
		}
	};

	vector<vector<uint64_t>> ans(N, vector<uint64_t>(N));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			ans[i][j] = get_cell(i, j);
		}
	}

	for (int i = 0; i < N; i++) {
		uint64_t v = id(rows[i].z);
		for (int j = 0; j < N; j++) {
			v = op(rows[i].z, v, ans[i][j]);
		}
		if (v != rows[i].v) {
			cout << -1 << '\n';
			exit(0);
		}
	}
	for (int j = 0; j < N; j++) {
		uint64_t v = id(cols[j].z);
		for (int i = 0; i < N; i++) {
			v = op(cols[j].z, v, ans[i][j]);
		}
		if (v != cols[j].v) {
			cout << -1 << '\n';
			exit(0);
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			cout << ans[i][j] << " \n"[j+1==N];
		}
	}

	return 0;
}


Measured memory_bytes: 7608
from collections import Counter
import sys

sys.setrecursionlimit(10**6)


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


class SegmentTree:
    def __init__(self, array, operator, identity_element):
        _len = len(array)
        self.__op = operator
        self.__size = 1 << (_len - 1).bit_length()
        self.__tree = [identity_element] * self.__size + \
            array + [identity_element] * (self.__size - _len)
        self.__ie = identity_element

        for i in range(self.__size - 1, 0, -1):
            self.__tree[i] = operator(
                self.__tree[i * 2], self.__tree[i * 2 + 1])

    def update(self, i, v):
        i += self.__size
        self.__tree[i] = v
        while i:
            i //= 2
            self.__tree[i] = self.__op(
                self.__tree[i * 2], self.__tree[i * 2 + 1])

    def query(self, l, r):
        l += self.__size
        r += self.__size
        ret = self.__ie
        while l < r:
            if l & 1:
                ret = self.__op(ret, self.__tree[l])
                l += 1
            if r & 1:
                r -= 1
                ret = self.__op(ret, self.__tree[r])
            l //= 2
            r //= 2
        return ret

st = SegmentTree([0]*2*(10**5), max, 0)

for _, a, i in sorted(zip(H, A, range(N))):
    st.update(i, st.query(0, i) + a)

print(st.query(0, N))


Measured memory_bytes: 121808
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner input = new Scanner(System.in);
		int n = input.nextInt();
		int[] num = new int[n];
		int[] numSorted = new int[n];
		int count = 0;
		
		for(int i =0;i<n;i++) {
			num[i] = input.nextInt();
		}
		
		for(int i =0;i<n;i++) {
			numSorted[i]= num[i];
		}
		Arrays.sort(numSorted);
		for(int i =0;i<n;i++) {
			if(num[i]!=numSorted[i]) {count++;}
			
		}
		if(count==0||count==2)
		System.out.println("YES");
		else {
			System.out.println("NO");
		}
			
			
		
		}

	}




Measured memory_bytes: 27128
def gcd(a,b):
	if b < 1: return a
	a,b = b,a % b
	return gcd(a,b)
ss = input().split()
while ss:
	a,b = map(int,ss)
	g = gcd(a,b)
	l = int(a*b/g)
	print(g,l)
	try: ss = input().split()
	except EOFError: break


Measured memory_bytes: 7584
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rrep(i,n) for(int i=(int)(n)-1; i>=0; i--)
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin(); it!=(c).end(); it++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define pr(a) cout << (a) << endl
#define PR(a,b) cout << (a) << " " << (b) << endl
#define F first
#define S second
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000001;
const ll MAXL=1000000000000000001LL;
const ll mod=1000000007;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int main() {
  int n,m;
  while(cin >> n >> m && (n||m)) {
    queue<int> que;
    for(int i=1; i<=n; i++) que.push(i);
    string s;
    for(int i=1; i<=m; i++) {
      cin >> s;
      if(que.size()>1) {
	int x=que.front();
	que.pop();
	if(i%15==0) {
	  if(s!="FizzBuzz") continue;
	} else if(i%3==0) {
	  if(s!="Fizz") continue;
	} else if(i%5==0) {
	  if(s!="Buzz") continue;
	} else {
	  if(!isdigit(s[0])) continue;
	  stringstream ss;
	  ss << s;
	  int k;
	  ss >> k;
	  if(k!=i) continue;
	}
	que.push(x);
      }
    }
    vector<int> ans;
    while(!que.empty()) {
      ans.pb(que.front());
      que.pop();
    }
    sort(all(ans));
    rep(i,ans.size()) {
      if(i) cout << " ";
      cout << ans[i];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 1264
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import lru_cache, reduce
from math import gcd
from operator import add, itemgetter, mul, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353





s = sys.stdin.buffer.readline().decode().rstrip()
a = s[-1]
if a in '24579':
    print('hon')
elif a in '0168':
    print('pon')
else:
    print('bon')


Measured memory_bytes: 27144
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct node{
  int key;
  struct node *prev;
  struct node *next;
}Node, *NodePointer;
 
 
 
NodePointer nil;
 
void init(){
  nil = malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}
 
void insert(int key){
  
  NodePointer x = malloc(sizeof(Node));

  x->key = key;
  x->next = nil->next;

  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}



NodePointer listSearch(int key){
  NodePointer s;
  s = nil->next;

  while(s != nil && s->key != key){
    s = s->next;
  }
  
  return s;
}
 
void deleteNode(NodePointer d){
  if(d == nil)return;
 
  d->prev->next = d->next;
  d->next->prev = d->prev;
  free(d);
}
 
void deleteKey(int key){
  deleteNode(listSearch(key));
}
void deleteFirst(){
  deleteNode(nil->next);
}
 
void deleteLast(){
  deleteNode(nil->prev);
}
 
void printlist(){
  NodePointer p = nil->next;
  while(1){
    if(p == nil)break;
    printf("%d",p->key);
    if(p->next != nil){
      printf(" ");
    }
    p = p->next;
  }
  printf("\n");
}
 
int main(){
  int n, key,i;
  char com[11];
 
  scanf("%d",&n);
 
  init();
  for(i=0;i<n;i++){
    scanf("%s%d",com,&key);
 
    if(com[0] == 'i'){
      insert(key);
    }
    else if(com[0] == 'd'){
      if(com[6] == 'F'){
        deleteFirst();
      }
      else if(com[6] == 'L'){
        deleteLast();
      }
      else{
        deleteKey(key);
      }
    }
 
  }
   printlist();
  return 0;
}



Measured memory_bytes: 33024
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }

    let mut ans = 0;
    let mut pre = a[0];
    for t in a {
        if t < pre {
            ans += pre - t;
        } else {
            pre = t;
        }
    }

    println!("{}", ans);
}


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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;

int main(){
    int N, M;
    cin >> N >> M;
    vector<pii> ids(M);
    for(int i=0; i<M; i++){
        int a, b;
        cin >> a >> b;
        ids[i]={b, a};
    }
    sort(all(ids));
    int ans=0, cur=-1;
    for(int i=0; i<M; i++){
        if(cur <= ids[i].second){
            cur=ids[i].first;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4060
#include <iostream>

using namespace std;

int main()
{
    bool cS[13], cH[13], cC[13], cD[13];
    for(int i = 0; i < 13; i++)
    {
        cS[i]=false;
        cH[i]=false;
        cC[i]=false;
        cD[i]=false;
    }
    int a, b;
    string t;
    cin>>a;
    while(a--)
    {
        cin>>t>>b;
        if(t=="S")
            cS[b-1] = true;
        if(t=="H")
            cH[b-1] = true;
        if(t=="C")
            cC[b-1] = true;
        if(t=="D")
            cD[b-1] = true;
    }
    for(int i = 0; i < 13; i++)
    {
        if(cS[i] == false)
            cout<<"S "<<i + 1<<endl;
    }
    for(int i = 0; i < 13; i++)
    {
        if(cH[i] == false)
            cout<<"H "<<i + 1<<endl;
    }
    for(int i = 0; i < 13; i++)
    {
        if(cC[i] == false)
            cout<<"C "<<i + 1<<endl;
    }
    for(int i = 0; i < 13; i++)
    {
        if(cD[i] == false)
            cout<<"D "<<i + 1<<endl;
    }
    return 0;
}



Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) (a).begin(),(a).end()
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,n) for(ll (i)=(n)-1;(i)>=0;i--)
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;
int main(){
    int a1,a2,a3;
    cin>>a1>>a2>>a3;
    if(a1+a2+a3 >= 22)cout<<"bust"<<endl;
    else cout<<"win"<<endl;
}

Measured memory_bytes: 256
import collections
s = str(input())

c = list(collections.Counter(s).values())
c.sort(reverse=True)

#print(c)
if len(c) <= 2:
    if c[0] >= 2:
        print('NO')
    else:
        print('YES')

else:
    if abs(c[0]-c[1]) >= 2 or abs(c[1]-c[2]) >= 2 or abs(c[2]-c[0]) >= 2:
        print('NO')
    else:
        print('YES')



Measured memory_bytes: 3444
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 1005
using namespace std;
typedef tuple<int,int,int> T;
int n,m,dx[4]={-1,1,0,0},dy[4]={0,0,1,-1};
char in[M][M];
bool vis[M][M];
queue<T> q;
int main()
{
    while (~scanf("%d %d",&n,&m)) {
        REP(i,1,n) scanf("%s", in[i]+1);
        REP(i,1,n) REP(j,1,m) if(in[i][j]=='#') {
            q.push(make_tuple(i,j,0));
            vis[i][j] = true;
        }

        int ans = 0;
        int x,y,z;
        while (!q.empty()) {
            tie(x,y,z) = q.front();
            q.pop();
            ans = max(ans, z);

            for (int k=0; k<4; k++) {
                int nx = x+dx[k];
                int ny = y+dy[k];
                if (nx>=1 && nx<=n && ny>=1 && ny<=m && !vis[nx][ny]) {
                    q.push(make_tuple(nx, ny, z+1));
                    vis[nx][ny] = true;
                }
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}




Measured memory_bytes: 14352
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


int main() {
  string s;
  cin >> s;
  string ans = "";
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'B') {
      if (ans.size() == 0) continue;
      ans = ans.substr(0, ans.size() - 1);
    } else {
      ans += s[i];
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

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

    cout << max({A * 10 + B + C, B * 10 + A + C, C * 10 + A + B}) << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

final class Main {

    private static final String[] keys = {"A", "B", "C"};

    private Main() {
    }

    public static void main(final String[] argv) throws IOException {
        final BufferedReader inputReader =
                new BufferedReader(new InputStreamReader(System.in));
        boolean[] cups = new boolean[3];
        Arrays.fill(cups, false);
        cups[0] = true;
        while (true) {
            String input = inputReader.readLine();
            if (input == null) {
                break;
            }
            String[] temp = input.split(",");
            swap(cups, getIndex(temp[0]), getIndex(temp[1]));
        }
        for (int i = 0; i < cups.length; i++) {
            if (cups[i]) {
                System.out.println(keys[i]);
                break;
            }
        }
    }

    private static void swap(boolean[] cups, int indexA, int indexB) {
        boolean temp = cups[indexA];
        cups[indexA] = cups[indexB];
        cups[indexB] = temp;
    }

    private static int getIndex(String key) {
        for (int i = 0; i < keys.length; i++) {
            if (key.equals(keys[i])) {
                return i;
            }
        }
        return -1;
    }
}

Measured memory_bytes: 9340
from collections import defaultdict
import sys
input = sys.stdin.readline

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

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

        if x == y:
            return

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

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

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

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

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

def main():
    N, K, L = map(int, input().split())
    road = UnionFind(N)
    train = UnionFind(N)
    for _ in range(K):
        p, q = map(int, input().split())
        p -= 1
        q -= 1
        road.union(p,q)
    for _ in range(L):
        r, s = map(int, input().split())
        r -= 1
        s -= 1
        train.union(r,s)

    d = defaultdict(int)
    for i in range(N):
        a = road.find(i)
        b = train.find(i)
        d[(a,b)] += 1

    ans = [0] * N

    for i in range(N):
        a = road.find(i)
        b = train.find(i)
        ans[i] = d[(a,b)]
    print(*ans)




if __name__ == "__main__":
    main()

Measured memory_bytes: 106332
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int turn = Integer.parseInt(br.readLine());
        int tarou = 0; int hanako = 0;
        for(int i = 0; i < turn; i++){
            String[] card = br.readLine().split(" ");
            if(card[0].compareToIgnoreCase(card[1]) == 0){
                tarou++; hanako++;
            }else if(card[0].compareToIgnoreCase(card[1]) > 0){
                tarou += 3;
            }else{
                hanako += 3;
            }
        }
        System.out.println(tarou+" "+hanako);
    }
}

Measured memory_bytes: 25464
#include<bits/stdc++.h>
using namespace std;
const int N=1<<18;

int n,a[N],b[4];
pair<int,int> p[N];

void ins(int x,int y) {
	b[0]=p[x].first; b[1]=p[x].second;
	b[2]=p[y].first; b[3]=p[x].second;
	sort(b,b+4);
	p[x].first=b[3]; p[x].second=b[2];
}

int main() {
	scanf("%d",&n);
	for (int i=0;i<(1<<n);i++) scanf("%d",&a[i]);
	for (int i=0;i<(1<<n);i++) p[i].first=a[i];
	for (int i=0;i<n;i++) {
		for (int j=0;j<(1<<n);j++) {
			if (!((1<<i)&j)) ins((1<<i)|j,j);
		}
	}
	int ans=0;
	for (int i=1;i<(1<<n);i++) {
		ans=max(ans,p[i].first+p[i].second);
		printf("%d\n",ans);
	}
	return 0;
}


Measured memory_bytes: 6144
#include <stdio.h>

int main(){
  int densen[5];
  for(int i=0; i<5; i++){
    scanf("%d", &densen[i]);
  }
  int k;
  scanf("%d", &k);
  
  //全探索
  int hasConnection = 0; //0でAllOK、1で通信できない
  for(int i=0; i<5; i++){
    for(int j=0; j<5; j++){
      if((densen[i] - densen[j]) > k) hasConnection = 1;
    }
  }

  if(hasConnection == 1){
    printf(":(");
  }else{
    printf("Yay!");
  }
  
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define rrep(i, a, b) for (int i = (a); i < (b); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using tl = tuple<ll, ll, ll>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n, m, k;
    cin>>n>>m>>k;
    vl as(n), bs(m);
    cin>>as>>bs;

    vl ss(n + 1), ts(m + 1);
    rep(i, n) ss[i + 1] += ss[i] + as[i];
    rep(i, m) ts[i + 1] += ts[i] + bs[i];

    int ans = 0;
    rep(i, n + 1) {
        if (ss[i] > k) break;
        auto it = upper_bound(rng(ts), k - ss[i]);
        int d = it - ts.begin();
        chmax(ans, i + d - 1);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 9532
#include <iostream>
#include <math.h>
#include <strings.h>
#include <queue>
#include <algorithm>
using namespace std;
 
int main()
{
    long long N,S;
    cin >>N;
    S=0;
    long long i;
    for(i=1;i<=N;i++){
        if(i%3!=0 and i%5!=0){
            S=S+i;
        }
    }
 
    cout<<S;
 
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

int N;
int bottom[200001];

bool top(int x){
    for(int i=1;i<N;i++){
        if((bottom[N-1+i]>=x)==(bottom[N-1+i-1]>=x)) return bottom[N-1+i]>=x;
        if((bottom[N-1-i]>=x)==(bottom[N-1-i+1]>=x)) return bottom[N-1-i]>=x;
    }
    return (bottom[0]>=x);
}

int main(){
    cin >> N;
    for(int i=0;i<2*N-1;i++){
        cin >> bottom[i];
    }
    int l=1,r=2*N;
    while(r-l>1){
        int m=(l+r)/2;
        if(top(m)) l=m;
        else r=m;
    }
    cout << l << endl;
    
    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
    string s, t;cin>>s>>t;
    reverse(all(s));
    reverse(all(t));
    string ans = "UNRESTORABLE";
    int l = s.size() - t.size();
    rep(i,0,l){
        int cnt = 0;
        rep(j,0,t.size()-1){
            if(s[i+j]!=t[j] && s[i+j] != '?')break;
            
            if(j==t.size()-1){
                ans = s.substr(0,i)+t+s.substr(i+t.size());
                reverse(all(ans));
                rep(k,0,ans.size()-1){
                    if(ans[k]=='?')ans[k]='a';
                }
                cout<<ans<<endl;
                return 0;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main() {
    string num;
    cin >> num;

    ll patern1 = 0;
    ll patern2 = 0;

    char even = '0';
    char odd = '1';
    if (num[0] == '1') {
        even  = '1';
        odd = '0';
    }

    // パターン１最初を動かさないパターン
    for (ll i = 0; i < num.size(); i++) {
        if (i % 2 == 0) {
            if (num[i] == even) ++patern1;
        } else {
            if (num[i] == odd) ++patern1;
        }
    }

    // パターン２最初を動かすパターン
    for (ll i = 0; i < num.size(); i++) {
        if (i % 2 == 0) {
            if (num[i] != even) ++patern2;
        } else {
            if (num[i] != odd) ++patern2;
        }
    }

    ll res = min(patern1, patern2);

    cout << res << endl;
}


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

int main(){
  int A, B, C, ans;
  cin >> A >> B >> C;
  
  ans = C - (A - B);
  if(ans < 0){
    cout << 0 << endl;
  }else{
    cout << C - (A - B) << endl;
  }
  
  return 0;
}

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

int main(){
int N;
  cin>>N;
  vector<pair<string, int>>S(N),c(N);
  for(int i=0; i<N; i++){
   cin>>S[i].first>>S[i].second;
    c[i].first=S[i].first;
    c[i].second=S[i].second;
  }
  

  sort(S.begin(), S.end());
  for(int i=0; i<N; i++){
   for(int j=0; j<N; j++){
    if(S[i].first==S[j].first){
     if(S[i].second>S[j].second){swap(S[i],S[j]);}
    }
   }
  }
  
  for(int i=0; i<N; i++){
   for(int j=0; j<N; j++){
    if(S[i].first==c[j].first && S[i].second==c[j].second){cout<<j+1<<endl;}
   }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")  // disable
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define lll __int128
#define lp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define vec(v, type, sz) vector<type> v(sz)
#define in(v) \
    for (auto &i : v) cin >> i
#define all(v) v.begin(), v.end()
#define prv(v)                         \
    for (auto i : v) cout << i << " "; \
    cout << "\n"
#define MOD 1000000007
#define INF 1000000000
#define INFL 1000000000000000000ll
#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define vi vector<int>
#define vl vector<ll>
#define vii(v, n, m, val) vector<vector<int>> v(n, vector<int>(m, val))
#define viii(v, i, j, k, val)        \
    vector<vector<vector<int>>> v(i, \
                                  vector<vector<int>>(j, vector<int>(k, val)))
#define pii pair<int, int>
#define pb push_back
#define file_io                       \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define testcases \
    int tcc;      \
    cin >> tcc;   \
    for (int tc = 1; tc <= tcc; tc++)
//-----------------------------------------
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while (!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
               __attribute__((unused)) int idx,
               __attribute__((unused)) int LINE_NUM) {
    cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if (idx > 0)
        cerr << ", ";
    else
        cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss;
    ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef LOAFNOB
#define debug(...) \
    debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif
//----------------------------------------------

int main() {
    fast_io;
    unordered_set<string> st;
    int n; cin>>n; while(n--){
    	string s; cin>>s;
    	st.insert(s);
    }
    cout<<st.size();
}

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

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> a(n);
  vector<pair<int, int>> b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i].first;
    b[i].second = i;
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  for (int i = 0; i < a.size(); i++) {
    if (a[i].first > b[i].first) {
      cout << "No";
      return 0;
    }
  }
  for (int i = 0; i < a.size() - 1; i++) {
    if (a[i+1].first <= b[i].first) {
      cout << "Yes";
      return 0;
    }
  }
  vector<int> p(n);
  for (int i = 0; i < n; i++) {
    p[a[i].second] = b[i].second;
  }
  int cur = p[0];
  int len = 1;
  while (cur != 0) {
    len++;
    cur = p[cur];
  }
  if (len < n) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}

Measured memory_bytes: 2176
#include <iostream>
#include <algorithm>

int main() {
  int x, y;
  while (true) {
    std::cin >> x >> y;
    if (!x && !y) break;
    if (y < x) {
      std::swap(x, y);
    }
    std::cout << x << " " << y << std::endl;
  }
}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;

template<typename T>
static inline void chmin(T & ref, const T  value) {
	if (ref > value) ref = value;
}

template<typename T>
static inline void chmax(T & ref, const T value) {
	if (ref < value) ref = value;
}

struct UnionFind {
public:
	vector <ll> par; // 
	vector <ll> siz; // 

	UnionFind() {}

	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}

	ll root(ll x) {
		while (par[x] != x) {
			x = par[x] = par[par[x]];
		}
		return x;
	}

	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}

	bool issame(ll x, ll y) {
		return root(x) == root(y);
	}

	ll size(ll x) {
		return siz[root(x)];
	}
};

int main() {
	int a, b;
	cin >> a >> b;
	set<P> black, white;
	for (int y = 0; y < 100; y+=2) {
		for (int x = 0; x < 50; x+=2) {
			if (a <= 1) break;
			white.insert(P(x, y));
			a--;
		}
	}
	for (int y = 0; y < 100; y += 2) {
		for (int x = 51; x < 100; x += 2) {
			if (b <= 1) break;
			black.insert(P(x, y));
			b--;
		}
	}
	cout << 100 << " " << 100 << endl;
	for (int y = 0; y < 100; y++) {
		for (int x = 0; x < 100; x++) {
			if (x < 50) {
				if (white.count(P(x, y))) {
					cout << '.';
				}
				else {
					cout << '#';
				}
			}
			else {
				if (black.count(P(x, y))) {
					cout << '#';
				}
				else {
					cout << '.';
				}
			}
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3704
import java.util.*;

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

        int n = sc.nextInt();
        int[] a;
        a = new int[100];
        int j=0;
        for(j=0;j<n;j++){
            a[j] = sc.nextInt();
        }

        for(int i=n-1;i>=0;i--){
            System.out.print(a[i]);
            if(i!=0)    System.out.print(" ");
        }
        System.out.println();
        sc.close();
    }
}


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

int main()
{
    int a,b,c;
    ll k;
    cin>>a>>b>>c>>k;
    if(k%2==0)cout<<a-b<<endl;
    else cout<<b-a<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

const int m = 2019;

int main() {
  string s; cin >> s;
  int n=s.size();
  reverse(s.begin(), s.end());
  int x=1, tot=0;
  vector<int> cnt(m, 0);
  cnt[tot]++;
  REP(i,n) {
    tot += (s[i]-'0')*x;
    x = x*10%m;
    tot%=m;
    cnt[tot]++;
  }

  ll ans=0;
  REP(i,m) ans += cnt[i] * (cnt[i]-1) / 2;
  COUT(ans);
  return 0;
}

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

int main(){
    ll L,R,d,res;
    cin>>L>>R>>d;
    res=R/d-(L-1)/d;
    cout<<(ll)res;
    return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

typedef struct{
  char name[11];
  int time;
}DATA;



int main(){

  DATA *queue;
  int n,q,i,sumT=0,head=0,tail=0;

  scanf("%d%d",&n,&q);

  queue=(DATA *)malloc(sizeof(DATA)*(n+1));

  for(i=0;i<n;i++)scanf("%s%d",queue[i].name,&queue[i].time);

  tail=n;

  for(head=0;head!=tail;head++){
    if(head==n+1)head=0;
    if(q>=queue[head].time){
      sumT+=queue[head].time;
      printf("%s %d\n",queue[head].name,sumT);
    }else{
      sumT+=q;
      if(tail==n+1)tail=0;
      strcpy(queue[tail].name,queue[head].name);
      queue[tail].time=queue[head].time-q;
      tail++;
    }
  }

  free(queue);

  return 0;

}

Measured memory_bytes: 1152
from bisect import bisect_left
n=int(input())
a=list(map(int,input().split()))
a.sort()

ans=0
# print(a)
for i in range(1,n-1):
    for j in range(0,i):
        k=bisect_left(a,a[i]+a[j])-i-1
        # print(f"i{i} j{j} bisect{bisect_left(a,a[i]+a[j])}")
        ans=ans+k
print(ans)


Measured memory_bytes: 3188