akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int a[100000];
int main()
{
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    for(int i=1;i<=ty-sy;i++)
    {
        cout<< "U";
    }
    for(int i=1;i<=tx-sx;i++)
    {
        cout<< "R";
    }
    for(int i=1;i<=ty-sy;i++)
    {
        cout<< "D";
    }
    for(int i=1;i<=tx-sx;i++)
    {
        cout<< "L";
    }
    cout<< "L";
    for(int i=0;i<=ty-sy;i++)
    {
        cout<< "U";
    }
    cout<< "R";
    for(int i=1;i<=tx-sx;i++)
    {
        cout<< "R";
    }
    cout<< "D";
    cout<< "R";
    for(int i=0;i<=ty-sy;i++)
    {
        cout<< "D";
    }
    cout<< "L";
    for(int i=1;i<=tx-sx;i++)
    {
        cout<< "L";
    }
    cout <<"U" <<endl;  
}


Measured memory_bytes: 256
N, M = map(int, input().split())
A = set(int(input()) for i in range(M))
MOD = 10 ** 9 + 7
DP = [0] * (N + 10)
if 1 not in A:
    DP[1] = 1
if 2 not in A and 1 in A:
    DP[2] = 1
if 2 not in A and 1 not in A:
    DP[2] = 2
for i in range(3, N + 1):
    if i not in A:
        DP[i] = (DP[i - 1] + DP[i - 2]) % MOD
print(DP[N])

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

int main()
{
  vector<int> In(3, 0);
  cin >> In[0] >> In[1] >> In[2];
  sort(In.begin(), In.end());
  if (In[0] == 5 && In[1] == 5 && In[2] == 7)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n, m, L;
    cin >> n >> m >> L;    
    
    vector<vector<P>> G(n);  // 辺の重みがすべて0以上のグラフ
    rep(i, m) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;  b--;
        G[a].pb(make_pair(b, c));
        G[b].pb(make_pair(a, c));
    }

    // 拡張ダイクストラ法。計算量はO((V+E)*log(V))
    vector<vector<P>> dist(n, vector<P>(n, make_pair(INF, INF)));  // dist[sv][v] : (頂点svから頂点vへの補給回数の最小値, そのとき満タンの状態から使用した燃料量)
    rep(sv, n) {
        dist[sv][sv] = make_pair(0, 0);
        priority_queue<pair<P, ll>, vector<pair<P, ll>>, greater<pair<P, ll>>> prQ;
        prQ.push(make_pair(make_pair(0, 0), sv));  // ((補給回数kaisuu, 満タンの状態から使用した燃料量used), いまいる頂点v)
        while(!prQ.empty()) {
            auto p1 = prQ.top();
            prQ.pop();
            ll v = p1.second;
            ll kaisuu = p1.first.first;
            ll used = p1.first.second;
            if(dist[sv][v] < p1.first) {
                continue;
            }
            for(auto p2 : G[v]) {
                ll u = p2.first;
                ll cost = p2.second;
                if(cost > L) {
                    continue;
                }
                P np;
                if(used + cost > L) {
                    np = make_pair(kaisuu + 1, cost);
                }
                else {
                    np = make_pair(kaisuu, used + cost);
                }
                if(dist[sv][u] > np) {
                    dist[sv][u] = np;
                    prQ.push(make_pair(np, u));
                }
            }
        }
    }
    
    ll q;
    cin >> q;
    vl ans(q);
    rep(i, q) {
        ll sv, gv;
        cin >> sv >> gv;
        sv--;  gv--;
        if(dist[sv][gv].first == INF) {
            ans[i] = -1;
        }
        else {
            ans[i] = dist[sv][gv].first;
        }
    }

    rep(i, q) {
        out(ans[i]);
    }

    re0;
}

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

using namespace std;
using ll = long long;
using v1 = vector<int>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int partition(v1& a, int p, int r){
	int x = a.at(r);
	int i = p-1;
	rep(j, r){
		if(a.at(j) <= x){
			i++;
			int c = a.at(i);
			a.at(i) = a.at(j);
			a.at(j) = c;
		}
	}
	int c = a.at(i+1);
	a.at(i+1) = a.at(r);
	a.at(r) = c;
	return i+1;
}

int main(){
	int n;
	cin >> n;
	v1 a(n);
	rep(i, n){
		cin >> a.at(i);
	}
	int c = partition(a, 0, n-1);
	rep(i, n){
		if(i == c) cout << "[";
		cout << a.at(i);
		if(i == c) cout << "]";
		if(i == n-1){
			cout << endl;
		}else{
			cout << " ";
		}
	}
}



Measured memory_bytes: 3100
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#define N 210
#define M 10000010
using namespace std;
struct edge{int x, y, next;}a[40010];
int T, n, l, p[M], flag[M], w[N], x, l1, l2, a1[N], a2[N], F[N], match[N], P[N], k, ans, ss;
map<int, int>mp;
map<int, int>::iterator it;
inline void prev(){
	l=0; memset(flag, 0, sizeof(flag)); flag[1]=1;
	for(int i=2; i<=10000000; i++){
		if(!flag[i])p[++l]=i;
		for(int j=1; j<=l&&i*p[j]<=10000000; j++){
			flag[i*p[j]]=1; if(i%p[j]==0)break;
		}
	}
}
inline int ABS(int x){return x>0?x:-x;}
inline void add(int x, int y){a[++l].x=x; a[l].y=y; a[l].next=P[x]; P[x]=l;}
inline int dfs(int x){
	for(int i=P[x]; i; i=a[i].next)if(F[a[i].y]<ss){
		F[a[i].y]=ss; if(!match[a[i].y]||dfs(match[a[i].y])){match[a[i].y]=x; return 1;}
	}
	return 0;
}
int main(){
	prev();
	T=1;
	for(int owo=1; owo<=T; owo++){
		scanf("%d", &n); l1=l2=0; mp.clear();
		for(int i=1; i<=n; i++){scanf("%d", &x); mp[x]^=1; mp[x+1]^=1;}
		for(it=mp.begin(); it!=mp.end(); it++)if(it->second){
			x=it->first;
			if(x&1)a1[++l1]=x; else a2[++l2]=x;
		}
		l=0; memset(P, 0, sizeof(P));
		for(int i=1; i<=l1; i++)
			for(int j=1; j<=l2; j++)if(!flag[ABS(a1[i]-a2[j])])add(i, j);
		k=ss=0; memset(F, 0, sizeof(F)); memset(match, 0, sizeof(match));
		for(int i=1; i<=l1; i++){ss++; k+=dfs(i);}
		ans=k+((l1-k)/2+(l2-k)/2)*2+((l1-k)%2)*3;
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 43392
N = int(input())
A = list(map(int, input().split()))
ans = 0
"""
A[i] + A[j] = j - i
<=> A[i] + i = j - A[j]
"""
L_i = [A[i] + i for i in range(N)]
L_j = [j - A[j] for j in range(N)]
# L_j[x] < x <= 2 * (10**5)
ans_lis = [0] * (2*(10**5))
for x in L_i:
    if x < 2*(10**5):
        ans_lis[x-1] += 1
for y in L_j:
    if y > 0:
        ans += ans_lis[y-1]
print(ans)

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

int main() {
	int N;
	cin >> N;
	int CMAX = 100 / 4;
	int DMAX = 100 / 7;
	for (int i = 0; i <= CMAX; i++)
	{
		for (int j = 0; j <= DMAX; j++)
		{
			if (i * 4 + j * 7 == N) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int mod=1e9+7;
struct Matrix{
	int a[3][3];
	void clear(int flag=0){
		memset(a,0,sizeof(a));
		if(flag) REP(i,0,2) a[i][i]=1;
	}
	Matrix operator *(const Matrix &rhs) const{
		Matrix B;
		REP(i,0,2) REP(j,0,2){
			ll res=0;
			REP(k,0,2) res+=(ll)a[i][k]*rhs.a[k][j];
			B.a[i][j]=res%mod;
		}
		return B;
	}
	Matrix operator ^(const int rhs) const{
		Matrix x=(*this),res;
		res.clear(1);
		int y=rhs;
		while(y){
			if(y&1) res=res*x;
			x=x*x;
			y>>=1;
		}
		return res;
	}
};
Matrix Ans,T0,T1;
int main(){
	int n=read(),m=read();
	int lst=0;
	REP(i,0,2) REP(j,0,2) T0.a[i][j]=1;
	T0.a[0][1]=T0.a[2][1]=T0.a[2][2]=2;
	T0.a[1][0]=0;
	T1=T0;
	T1.a[2][0]=T1.a[2][1]=0;
	T1.a[2][2]=1;
	Ans.clear();
	Ans.a[0][0]=1;
	REP(i,1,m){
		int x=read();
		Ans=Ans*(T0^(x-lst));
		Ans=Ans*T1;
		lst=x+1;
	}
	Ans=Ans*(T0^(n-lst));
	printf("%d\n",Ans.a[0][2]);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(register int i = a; i <= b; i++)
#define per(i, a, b) for(register int i = a; i >= b; i--)
typedef long long LL;
const LL mod = 1e9 + 7;
const int N = 3e5 + 5;

int n, a[N];
LL ans;

int main() {
	cin>>n;
	rep(i, 1, n) {
		cin>>a[i];
		if(a[i] >= a[i - 1]) continue;
		ans += a[i - 1] - a[i];
		a[i] = a[i - 1];
	}
	cout<<ans<<endl;
}

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

#define fr(i,n) _back
#define pb	push_back
#define eb	emplace_back
#define mk	make_pair
#define fi	first
#define se	second
#define endl	'\n'

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);

const int T = 1e3 + 3;
vector<int> g[T];
int sob[T][T];
int cor[T][T];
int pai[T][T];
int dist[T][T];
int n,m;
int ori;

void dfs(int u) {
    cor[ori][u] = 1;

    for(int v : g[u]) {
        if(!cor[ori][v]) {
            pai[ori][v] = u;
            dist[ori][v] = dist[ori][u] +1;
            dfs(v);
        }

        else if(v == ori and cor[ori][v] == 1)
            if(dist[ori][u] < sob[ori][u])
                sob[ori][u] = dist[ori][u];
    }

    cor[ori][u] = 2;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    memset(sob, INF, sizeof sob);

    for(int i = 0; i < m; i++) {
        int a,b;cin >> a >> b;
        g[a].pb(b);
    }

    for(int i = 1; i <= n; i++) ori = i, dfs(i);

    int a = 0, b = 0;
    int best = INF;

    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            if(sob[i][j] != INF) {
                if(sob[i][j] < best) {
                    best = sob[i][j];
                    a = i;
                    b = j;
                }
            }
        }
    }

    if(!a) { cout << -1 << endl; return 0; }
    vector<int> ans;
    while(a != b) { ans.pb(b); b = pai[a][b]; }
    ans.pb(a);
    cout << ans.size() << endl;
    for(auto x : ans) cout << x << endl;

    return 0;
}


Measured memory_bytes: 16128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int i = (s);i <= (e);i++)

int n;
int l,r;
int main()
{
    cin >> n;
    i64 res = 0;
    rep(i,1,n)
    {
        cin >> l >> r;
        res += r - l + 1;
    }
    cout << res << endl;
}

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

int main() {
	int N, Y;
	cin >> N >> Y;
	for (int x = 0; x <= N; x++) {
		for (int y = 0; y <= N - x; y++) {
			int z = N - x - y;
			if (z < 0) {
				continue;
			}
			if (10000 * x + 5000 * y + 1000 * z == Y) {
				cout << x << " " << y << " " << z << endl;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1\n";
	return 0;
}

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

typedef long long ll;
const int MAXN = 100010;

int n;
ll ans, a[MAXN], b[MAXN];

inline int read() {
	int x = 0, f = 1;
	char ch = getchar();
	for(; !isdigit(ch); ch = getchar()) if(ch=='-') f=-1;
	for(; isdigit(ch); ch = getchar()) x = (x*10)+(ch^48);
	return x * f;
}

int main() {

	int i;

	n = read();
	for(i = 1; i <= n; i++) a[i] = read(), b[i] = read();

	for(i = n; i >= 1; i--) {
		a[i] += ans;
		ll p = a[i] == 0 ? 0 : (a[i]-1)/b[i]+1;
		ans += b[i]*p-a[i];
	}

	printf("%lld\n", ans);
	return 0;
}


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

using ll = long long;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SIZE(a) ((int)(a).size())

const int N = 200005;

const int mod = 1000*1000*1000 + 7;

int n;
pair<int,int> a[N];
int lf[N], rt[N];
int seg[N];
int f[N];

inline void add(int &x, int y) {
	x += y;
	if (x >= mod) x -= mod;
}

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

	cin >> n;
	REP(i, n) cin >> a[i].first >> a[i].second;
	REP(i, n+2) seg[i] = -1;
	sort(a, a + n);

	vector<pair<int,int>> b(n);
	REP(i, n) b[i] = {a[i].second, i};
	sort(b.begin(), b.end());

	int mx = -1;
	REP(i, n) {
		mx = max(mx, b[i].second);
		rt[b[i].second] = mx+1;
	}
	int mn = n;
	for (int i = n-1; i >= 0; --i) {
		mn = min(mn, b[i].second);
		lf[b[i].second] = mn+1;
	}

	REP(i, n) {
		seg[rt[i]] = max(seg[rt[i]], lf[i]);
	}

	int sum = 1;
	f[0] = 1;

	mx = -1;
	int j = 0;

	for (int i = 1; i <= n+1; ++i) {
		mx = max(mx, seg[i-1]);
		while (j < mx) {
			add(sum, mod-f[j]);
			++j;
		}
		add(f[i], sum);
		add(sum, sum);
	}

	cout << f[n+1] << '\n';

	return 0;
}

Measured memory_bytes: 6528
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define ALL(v) v.begin(), v.end()
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
	int N; cin >> N;
	vector<int> P(N), Q(N), A(N);
	rep(i, N) cin >> P[i];
	rep(i, N) cin >> Q[i];
	rep(i, N) A[i] = i+1;

	vector<vector<int>> B;
	do {
		B.push_back(A);
	} while( next_permutation(ALL(A)) );


	ll p, q;
	ll b = B.size();
	rep(i, b) {
		if (P == B[i]) p = i;
		if (Q == B[i]) q = i;
	}

	cout << ((p>q) ? p-q: q-p) << endl;

}

Measured memory_bytes: 3256
n = gets.to_i

h = Hash.new(-1)
h[0] = 3
gets.split.each{|e| h[e.to_i] += 1}

h.delete_if{|k,v| v == 0}
h = h.sort_by{|k,v| -k}
puts h[0][1] >= 3 ? h[0][0] ** 2 : h[0][0] * h[1][0]

Measured memory_bytes: 14212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); i++)

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);

int main() {

 int n;
 cin>>n;

 ll sum = 0;
 for(int i = 1;i<=n;i++){
    if( i%3!=0 && i%5!=0){
      sum+=i;
    }
 }

 cout<<sum<<"\n";


  
  return 0;
}


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

using namespace std;

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

#define faster ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define read freopen("in.txt", "r", stdin)
#define write freopen("out.txt", "w", stdout)
#define mem(x, n) memset(x, n, sizeof(x))
#define all(x) x.begin(), x.end()
#define endl "\n"

int main() {
	faster;

	ll n, m, t, in, tot = 0, time = 0;
	cin >> n >> m >> t;

	vector<ll> a(n + 1), b(m + 1);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < m; i++) {
		cin >> b[i];
	}
	int i, j;
	for (i = 0; i < n; i++) {
		if (a[i] + time <= t) {
			time += a[i];
			tot++;
		} else {
			break;
		}
	}
	i--;

	ll temp = tot;

	for (j = 0; j < m; j++) {
		time += b[j];
		temp++;
		while (i >= 0 && time > t) {
			time -= a[i];
			i--;
			temp--;
		}

		if (time <= t) {
			tot = max(tot, temp);
		} else {
			break;
		}
	}

	cout << tot << endl;
	return 0;
}

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

int main()
{
  int n,k;
  cin>>n>>k;
  int arr[n];
  for(int i=0;i<n;i++)
    cin>>arr[i];
  
  int dp[n];;
  dp[0]=0;
  dp[1]=abs(arr[1]-arr[0]);
  for(int i=2;i<n;i++)
  {
    dp[i]=INT_MAX;
  	for(int s=1;s<=k && i-s>=0;s++)
    dp[i]=min(dp[i],dp[i-s]+abs(arr[i]-arr[i-s]));
}
  cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1152
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#pragma comment(linker, "/STACK:400000000")

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(it=X.begin();it!=X.end();it++)
#define iss istringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sst stringstream
#define sz size()
#define vc vector
typedef vc<int> vi;
typedef vc<ll> vl;
typedef vc<string> vs;

#define MAXN (1<<17)

ll bit[MAXN+1],n=MAXN;

void init(){
	fill(bit,bit+n+1,0);
}

ll sum(ll i){
	ll s=0;
	while(i){
		s+=bit[i];
		i-=i&-i;
	}
	return s;
}

void add(int i,ll x){
	while(i<=n){
		bit[i]+=x;
		i+=i&-i;
	}
}

int A,B,P,a[100010],N;
string s[100010];

bool comp(int a,int b){
	return s[a-A]<s[b-A];
}

int main(){
	while(cin>>A>>B>>P && A){
		init();
		N=B-A+1;
		rep2(i,A,B+1){
			a[i-A]=i;
			sst ss;
			ss<<i;
			s[i-A]=ss.str();
		}
		sort(a,a+N,comp);
		ll ans=0;
		rep(i,N){
			ll res=(1+sum(a[i]-A+1))%P;
			ans=(ans+res)%P;
			add(a[i]-A+1,res);
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 8124
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[] for _ in range(num)]
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

from collections import deque

N,K = II()
p = III()
x = [(p0+1)/2 for p0 in p]

d = deque(x[:K])
ans = sum(d)
now = sum(d)
for i in range(K,N):
    now = now-x[i-K]+x[i]
    if now>ans:
        ans = now

print(ans)

Measured memory_bytes: 77636
#include<bits/stdc++.h>
#include<vector>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define rep(i,N) for(int i=0;i<N;i++)

using namespace std;

int main(void){
   int N,M,p=0,m=0,ans=0;
   cin>>N;
   V<string> s(N);
   rep(i,N)cin>>s[i];
   cin>>M;
   V<string> t(M);
   rep(i,M)cin>>t[i];
   rep(i,N){
       p=1,m=0;
       for(int j=i+1;j<N;j++){
           if(s[i]==s[j]){
               p++;
           }
       }
       rep(j,M){
           if(s[i]==t[j]){
               m++;
           }
       }
       ans=max(ans,p-m);
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    long count = 0;
    long[] H = new long[n];
    for (int i = 0; i < n; i++) {
      H[i] = sc.nextLong();
    }
    Arrays.sort(H);
    if (n <= k) {
      count = 0;
    } else {
      for (int i = n - 1 - k; i >= 0; i--) {
        count += H[i];
      }
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 89868
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    string s; cin >> s;
    sort(all(s));

    if(s == "abc") cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<bitset>
using namespace std;
int main() {
    long long p, q;
    cin >> p >> q;
    bitset<32> a(p), b(q);
    cout << (a&b) << endl;
    cout << (a|b) << endl;
    cout << (a^b) << endl;
    return 0;
}


Measured memory_bytes: 3148
def bSort(a):
    for i in range(len(a)):
        for j in range(len(a)-1, i, -1):
            if a[j] > a[j-1]:
                a[j], a[j-1] = a[j-1], a[j]

    return a



n = int(input())

p = list(map(int, input().split()))

d = [0]*3
c = [0]*3
count = 0

for i in range(n-2):
    for j in range(3):
        d[j] = p[i+j]
        c = d[:]
    d = bSort(d)
    
    if c[1] == d[1]:
        count += 1
print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define Mod 1000000007
#define ll long long
#define dd double
#define pb push_back
#define ff first
#define ss second
#define Mp make_pair
#define INF 999999999999999999
#define NN (ll)(1e6+5)
int mod(string s,int a) 
{ 
    int ans=0; 
    for (int i=0;i<s.length();i++) 
         ans=(ans*10+(int)s[i]-'0')%a; 
    return ans; 
}
ll min(ll x,ll y){if(x<y) return x;return y;}
ll max(ll x,ll y){if(x>y) return x;return y;}
ll power(ll x,unsigned ll y) 
{ 
    if (y==0) 
        return 1; 
    else if (y%2==0) 
        return power(x,y/2)*power(x,y/2); 
    else
        return x*power(x,y/2)*power(x,y/2); 
}
ll hcf(ll a,ll b) 
{ 
    if(b==0) 
        return a; 
    return hcf(b,a%b);  
}
int main()
{
   fio;
   /*#ifndef ONLINE_JUDGE 
    	freopen("input.txt", "r", stdin); 
    	freopen("output.txt", "w", stdout); 
    	freopen("error.txt", "w", stderr); 
   #endif*/
   ll TT=1;
   //cin>>TT;
   while(TT--)
   {    
       ll s,w;
       cin>>s>>w;
       cout<<(s>w?"safe\n":"unsafe\n");
   }
}

Measured memory_bytes: 3688
#include <stdio.h>
#include <math.h>

int main(void)
{
	double a, b, C, c,S,rad,L,h;
	#define PI 3.141592653589793

	c = 0;

	scanf("%lf %lf %lf", &a, &b, &C);

	//面積を求める
	rad = (C * PI) / 180.0;
	S =  (a * b * sin(rad))/2.0;


	//週の長さを求める
	c = (a * a) + (b * b) - (2 * b*a*cos(rad));  
	c = sqrt(c);
	L = a + b + c;

	//高さhをもとめる

	h = (2 * S) / a;

	//全体の結果画面出力
	printf("%8f\n%8f\n%8f\n", S,L,h);
}


Measured memory_bytes: 2116
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL,LL> PLL;//
typedef std::pair<int,int> PII;//
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int N;
	cin >> N;
	vector<LL> A(N),B(N),C(N);
	for(int i=0;i<N;++i)cin>>A[i];
	for(int i=0;i<N;++i)cin>>B[i];
	for(int i=0;i<N;++i)cin>>C[i];
	
	sort(A.begin(),A.end());
	sort(B.begin(),B.end());
	sort(C.begin(),C.end());
	int sizeA,sizeB,sizeC;
	sizeA = A.size();
	sizeB = B.size();
	sizeC = C.size();
	vector<LL> v(N);
	
	int pos = 0;
	for(int i=0;i<sizeB;++i){
		v[i] = pos;
		if( i ){
			v[i] += v[i-1];
		}
		while( pos < sizeA && A[pos] < B[i] ){
			v[i] += 1;
			++pos;
		}
	}
	LL ans = 0;
	pos = 0;
	for(int i=0;i<sizeC;++i){
		while( pos < sizeB && B[pos] < C[i] ){
			++pos;
		}
		int ter = pos - 1 ;
		if( ter >= 0 && B[ter] < C[i] ){
			ans += v[ter];
		}
	}
	cout << ans << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()

Measured memory_bytes: 3456
import java.util.*;

class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int n = sc.nextInt();
                while(n != 0){ 
                        int max = sc.nextInt();
                        int sum = max;
                        for(int i = 1; i < n; i++){
                                int a = sc.nextInt();
                                sum = Math.max(sum+a, a); 
                                max = Math.max(sum, max);
                        }   
                        System.out.println(max);
                        n = sc.nextInt();
                }   
                sc.close();
        }   
}

Measured memory_bytes: 12000
N, X, M = list(map(int, input().split()))

A = X
sum_A = A
A_list = [X]
for i in range(1, N):
    A = A ** 2 % M

    if (A in A_list):
        start = A_list.index(A)
        loop = A_list[start:]
        sum_A += sum(loop)*((N-i)//len(loop)) + sum(loop[:(N-i) % len(loop)])
        break
    else:
        A_list.append(A)
    sum_A += A

    if (A == 0):
        break

print(sum_A)


Measured memory_bytes: 68692
//Today, I will prepare and someday my chance will come. ~A.lincoln
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define int long long int
#define vi vector<int>
#define pp pair<int,int>
#define se set<int>
#define pb push_back
#define ump unordered_map<int,int>
#define maxx INT_MAX
#define minn INT_MIN
#define endl "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
int32_t main()
{
    FAST
    int n; cin>>n;
    ump freq;
    for(int i=0;i<n;i++)
    {
        int temp; cin>>temp;
        freq[temp]++;
    }

    int count=0;
    for(auto it:freq)
    {
        if(it.second<it.first)
            count+=it.second;
        if(it.second>it.first)
            count+=(it.second-it.first);
        else count+=0;
    }
    cout<<count<<endl;
}



Measured memory_bytes: 7308
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<numeric>
#include<algorithm>
#include<tuple>
#include<cmath>

typedef unsigned long long ll;

ll DENOM = 1000000000LL + 7LL;
using namespace std;

int main(){
    char a;
    cin >> a;
    if (a - 'A' < 26){
        a = 'A';
    }else{
        a = 'a';
    }
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 3052
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main{
	static final Scanner s=new Scanner(System.in);
	static int getInt(){
		return Integer.parseInt(s.next());
	}
	public static void main(String[] __){
		int n=getInt(),m=getInt(),dp[]=IntStream.rangeClosed(0,n).toArray();
		for(int l=0;l<m;l++){
			int c=getInt();
			for(int i=0;i+c<=n;i++){
				dp[i+c]=Math.min(dp[i+c],dp[i]+1);
			}
		}
		System.out.println(dp[n]);
	}
}

Measured memory_bytes: 32320
// #1140935 Solution for 0515: School Road by ryogo 
#include<iostream>
using namespace std;
int dp[20][20];
int main(){
	int a, b;
	int i, j;
	while(cin>>a>>b){
		if(a == 0 && b == 0) { break; }
		int n;
		cin>>n;
		for(i=1;i<=16;i++)for(j=1;j<=16;j++){dp[i][j]=0;}
		for(i=1;i<=n ;i++){
			int x,y;
			cin>>x>>y; dp[y][x]=-1;
		}
		dp[1][1]=1;
		for(i=1;i<=b;i++){
			for(j=1;j<=a;j++){
				if(i==1 && j==1)continue;
				if(dp[i][j]!=-1){
					dp[i][j]=dp[i][j-1]+dp[i-1][j];
				}
				else dp[i][j]=0;
			}
		}
 
		cout<<dp[b][a]<<endl;
	}
}


Measured memory_bytes: 3080
#include<stdio.h>

int selectionSort(int A[], int N){
    int i,j,t,sw=0,minj;
    for(i=0; i<N-1; i++){
        minj = i;
        for(j=i; j<N; j++){
            if(A[j] < A[minj]) minj=j;
        }
        t=A[i]; A[i]=A[minj]; A[minj]=t;
        if( i != minj)  sw++;
    }
    return sw;
}

int main(){
    int A[100],N, i, sw;
    
    scanf("%d",&N );
    for(i=0; i<N; i++) scanf("%d",&A[i]);
    
    sw = selectionSort(A, N);
    
    for(i=0; i<N; i++){
        if(i>0) printf(" ");
        printf("%d",A[i]);
        
    }
    printf("\n");
    printf("%d\n", sw);
    
    return 0;
}



Measured memory_bytes: 2720
#include<ctime>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath> 
#include<cstring> 
#include<cassert>
#include<string>
#include<sstream>
#include<fstream>
#include<deque>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<set>
#include<bitset>
#include<iomanip>
#include<utility>
#include<functional>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cwchar>
#include<cwctype>
#include<exception>
#include<locale>
#include<numeric>
#include<new>
#include<stdexcept>
#include<limits>
using namespace std;

#define ll long long
#define INF 1e9
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
#define pii pair<int,int>
#define sz(s) s.size()
#define all(s) (s.begin(),s.end())
inline void Fail(){
	printf("Yes");
	exit(0);
}

const int maxn=1005;
int n,m,k;

int main(){
	scanf("%d%d%d",&n,&m,&k);
	REP(i,n){
		int cur=0;
		cur+=m*i;
		if(cur==k)Fail();
		REP(j,m){
			cur-=i;
			cur+=n-i;
			if(cur==k)Fail();
		}
	}
	printf("No");
	return 0;
}

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

using namespace std;

int main () {
	#ifdef wll
//	freopen ("testdata.in", "r", stdin);
	#endif
	int n, k;
	scanf ("%d%d", &n, &k);
	if (k == 1) {
		printf ("0\n");
		return 0;
	}
	printf ("%d\n", n - k);
	return 0;
}
















Measured memory_bytes: 256
loop do

  n = gets.to_i
  if n == 0 then break end

  dimp = 0
  dimn = 0
  tmp = ''

  optr = Array.new(n + 1, '?')
  opnd = Array.new(n + 1).map{Array.new}

  for i in 0 .. n - 1
    
    keynext = gets.chomp.chars
    
    dimn = keynext.count('.')
    tmp  = keynext[-1]

    #p optr, opnd

    if dimn < dimp
 
      opcnt = dimp - dimn

      while opcnt > 0

        tmpresult = opnd[dimp].shift

        while opnd[dimp].size > 0

          if optr[dimp - 1] == '+'
            tmpresult = tmpresult + opnd[dimp].shift
          elsif optr[dimp - 1] == '*'
            tmpresult = tmpresult * opnd[dimp].shift
          end

          #p tmpresult
        end
        opcnt -= 1
        dimp -= 1

        opnd[dimp] << tmpresult
        #p optr, opnd
      end
    end
    dimp = dimn

    if tmp == '+' || tmp == '*'
      optr[dimn] = tmp
    else
      opnd[dimn].push(tmp.to_i)
    end
  end

  while dimp > 0

    tmpresult = opnd[dimp].shift

    while opnd[dimp].size > 0

      if optr[dimp - 1] == '+'
        tmpresult = tmpresult + opnd[dimp].shift
      elsif optr[dimp - 1] == '*'
        tmpresult = tmpresult * opnd[dimp].shift
      end
    end

    #p optr, opnd

    dimp -= 1
    opnd[dimp] << tmpresult
  end
  puts opnd[dimp]
end





Measured memory_bytes: 6876
#include "bits/stdc++.h"
using namespace std;

int main() {
	int N, A, B;
	static long long H[100000], MAX = 0;
	cin >> N >> A >> B;
	for (int i = 0; i < N; i++) {
		cin >> H[i];
		MAX = max(MAX, H[i]);
	}
	long long L = 0, R = MAX / B + 1;
	while (R - L > 0) {
		long long count = 0, mid = (L + R) / 2;
		for (int i = 0; i < N; i++) {
			int h = H[i];
			h = max((long long)0, h - B * mid);
			if (h % (B - A) == 0) count += h / (A - B);
			else count += h / (A - B) + 1;
		}
		if (count <= mid) R = mid;
		else L = mid + 1;
	}
	cout << L;
}

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

int main()
{
  string s;
  cin >> s;
  int ans = 0;
  for(int i= 0; i < 4; i++){
      if(s[i] == '+'){
          ans ++;
      }else if(s[i] == '-'){
          ans --;
      }
  }
  cout << ans << endl;
  
}


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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



int n, k, d[101], a[101][101];
int c[101];
void solve(){
	cin >> n >> k;
	for(int i = 0; i < k; i++){
		cin >> d[i];
		for(int j = 0; j < d[i]; j++){
			cin >> a[i][j];
			c[a[i][j]]++;
		}
	}
	
	int cnt = 0;
	for(int i = 1; i <= n; i++){
		if(c[i] == 0) cnt++;
	}
	cout << cnt << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 3684
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    int Q = sc.nextInt();
    int[] ints = new int[N];
    for (int i = 0; i < Q; i++) {
      ints[sc.nextInt() - 1]++;
    }
    for (int i = 0; i < N; i++) {
      System.out.println((K - Q + ints[i] > 0) ? "Yes" : "No");
    }
  }
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    int ma = 0;
    long long ans = 0;
    for(int i = 0; i < n; i++) {
        ma = max(ma, a[i]);
        ans += ma - a[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4044
#include <bits/stdc++.h>
using namespace std;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<int> 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};
  int k;
  cin >> k;
  cout << a[k-1] << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;

int main(int argc, char *argv[])
{
    string input;
    getline(cin, input);
    for (int i = 0; i < input.size(); i++)
    {
        if (islower(input[i]))
        {
            input[i] = toupper(input[i]);
        }
        else
        {
            input[i] = tolower(input[i]);
        }
    }

    cout << input << endl;

    return 0;
}


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

int main(){
  
  int x,p=0,min=0;
  
  for(int i = 0;i<5;i++){
    cin >> x;
    p+=x/10;
    if(x%10 != 0) {
      p+=1;
      if(10-x%10>min) min = 10-x%10;
    }
  }
  cout << p*10-min <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (1E9+7)
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int d = max(a, max(b, c));
	int sum = (d - a) + (d - b) + (d - c);
	int ans = (sum % 2 == 0 ? sum / 2 : (sum + 3) / 2);
	cout << ans << endl;
}


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

#define x first
#define y second
#define ndl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)x.size()
#define bit __builtin_popcount
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;
using namespace __gnu_pbds;

template<typename T> using indexed_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<int, ull> piu;
typedef vector<vector<int>> matrix;

const ll INF = 1e18 + 123;
const ld EPS = 1e-9;
const int inf = 1e9 + 123;
const int MOD = 1e9 + 7;
const int N = 5e5 + 123;
const int M = 1e6 + 123;
const double pi = 3.141592653;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};

void solve(){
    int n;
    cin >> n;
    cout <<fixed<<setprecision(2) << 2*pi*n;
}

int main(){
    #ifdef KAZAKH
        //freopen("input.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; i++){
        //cout << "case #" << i << ": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  const int N = 100005;



int fun(int a,int b)
{
  return a*a*a*a*a - b*b*b*b*b;
}

int32_t main()
{


    IOS

    int x;
    cin >> x;


    for(int i = 1; i*i <= x; i++)
    {
      if(x%i == 0)
      {
        for(int j = -200; j <= 200; j++)
        {
          int a = j + i;
          int b = j;
          if(fun(a,b) == x)
          {
            cout << a << " " << b;
            return 0;
          }
         }
      }

    }

    
    return 0;
}



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

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

  int ans = 0;

  for(int i=0;i<n-2;i++) {
    string sub = s.substr(i, 3);
    if(sub == "ABC") ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxn 100005
#define mod 1000000009
#define ll long long
using namespace std;

typedef pair<int, int> P;

int a, b;

int main()
{
    cin >> a >> b;
    b--;
    a--;
    cout << (int)ceil(1.0 * b / a);
    return 0;
}

Measured memory_bytes: 256
#![allow(clippy::needless_range_loop)]
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;
use proconio::input;
use proconio::marker::*;
use std::collections::BTreeSet;
use std::ops::Bound::*;

fn main() {
    input! {
        n: usize,
        q: [(usize, usize)],
    }
    let m = n - 2;
    let mut xs: BTreeSet<(usize, usize)> = BTreeSet::new();
    let mut ys: BTreeSet<(usize, usize)> = BTreeSet::new();
    let mut ans = m * m;

    for &(k, c) in &q {
        let c = c - 2;
        if k == 1 {
            if let Some(&(_, y)) = xs.range((Included((c, 0)), Unbounded)).next() {
                ans -= y;
                ys.insert((y, c));
            } else {
                ans -= m;
                ys.insert((m, c));
            }
        } else if let Some(&(_, x)) = ys.range((Included((c, 0)), Unbounded)).next() {
            ans -= x;
            xs.insert((x, c));
        } else {
            ans -= m;
            xs.insert((m, c));
        }
    }

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


Measured memory_bytes: 17652
#include<stdio.h>
int main(void)
{
	int n,ball[10],b[10],c[10],i,n0;
	scanf("%d",&n);
	for(n0=0;n0<n;n0++){
		int p=0,o=0,j=0;
		for(i=0;i<10;i++){
			scanf("%d",&ball[i]);
		}
		b[0]=ball[0];
		c[0]=0;
		for(i=1;i<10;i++){
			if(b[p]<ball[i]){
				p++;
				b[p]=ball[i];
			}
			else if(c[o-1]<ball[i]&&o>=1||c[o]<ball[i]&&o==0){
				c[o]=ball[i];
				o++;
			}
			else{
				j=1;
				c[o]=ball[i];
				o++;
			}
		}
		if(j==0){
			printf("YES\n");
		}
		else{
			printf("NO\n");
		}
	}
	return 0;
}

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

int main() {
  int n;
  std::cin >> n;
  std::vector<int> mochi(n, 0);
  for (int i = 0; i < n; i++) std::cin >> mochi.at(i);
  std::sort(mochi.begin(), mochi.end());
  mochi.erase(std::unique(mochi.begin(), mochi.end()), mochi.end());
  std::cout << mochi.size() << std::endl;
  return 0;
}

Measured memory_bytes: 256
from heapq import heappush, heappop
 
N, M = map(int, input().split())
 
goods = list(map(int, input().split()))
goods_heap = []
 
for i in range(N):
    heappush(goods_heap, -goods[i])
 
for _ in range(M):
    heappush(goods_heap, -(-heappop(goods_heap)//2))
    
sum = -sum(goods_heap)
 
print(sum)

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

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int W = Integer.parseInt(scan.next());
        int H = Integer.parseInt(scan.next());
        int N = Integer.parseInt(scan.next());

        int[] xs = new int[N];
        int[] ys = new int[N];
        int[] as = new int[N];


        for(int n=0;n<N;n++){
            xs[n] = Integer.parseInt(scan.next());
            ys[n] = Integer.parseInt(scan.next());
            as[n] = Integer.parseInt(scan.next());
        }

        scan.close();

        int[] impoint = new int[4];

        impoint[0] = 0;
        impoint[1] = W;
        impoint[2] = 0;
        impoint[3] = H;

        for(int i=0;i<N;i++){
            switch (as[i]){
                case 1: //left
                    if(xs[i] > impoint[0]){
                        impoint[0] = xs[i];
                    }
                    break;
                case 2://right
                    if(xs[i] < impoint[1]){
                        impoint[1] = xs[i];
                    }
                    break;
                case 3://down
                    if(ys[i] > impoint[2]){
                        impoint[2] = ys[i];
                    }
                    break;
                case 4://up
                    if(ys[i] < impoint[3]){
                        impoint[3] = ys[i];
                    }
                    break;
            }
        }
        System.out.println(Math.max(impoint[1] - impoint[0] , 0) * Math.max(impoint[3] - impoint[2],0));

    }
}


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

#define int long long

signed main() {
    int a, b;
    cin >> a >> b;
    int ans = 0;
    for(int i=a; i<=b; ++i) {
        string s = to_string(i);
        string t = s;
        reverse(t.begin(), t.end());
        if(s==t) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main{

	static Scanner sc = new Scanner(System.in);
	
	static int n, current = 0;
	static int stack[] = new int[10];
	
	public static void main(String[] args) {
		
		while(read()){
			solve();
		}

	}
	
	public static boolean read(){
		if(!sc.hasNext()) return false;
		
		n = sc.nextInt();
		
		return true;
	}
	
	public static void solve(){
		if(n == 0){
			current--;
			System.out.println(stack[current]);
			stack[current] = 0;
			return;
		}
		
		stack[current] = n;
		current++;
	}

}

Measured memory_bytes: 11000
#include <cstdio>
#include <cstdlib>
 
#define siz 10000000
 
char buf[siz], *bit = buf;
 
inline int nextInt(void) {
    register int ret = 0;
    register int neg = false;
 
    for (; *bit < '0'; ++bit)
        if (*bit == '-')neg ^= true;
 
    for (; *bit >= '0'; ++bit)
        ret = ret * 10 + *bit - '0';
 
    return neg ? -ret : ret;
}
 
int n, m;
 
int pre[100005];
 
inline int ask(int p) {
    int ret = 0;
    for (; p; p -= p&-p)
        ret += pre[p];
    return ret;
}
 
inline void add(int p, int k) {
    for (; p <= n; p += p&-p)
        pre[p] += k;
}
 
signed main(void) {
    fread(buf, 1, siz, stdin);
 
    n = nextInt();
    m = nextInt();
 
    for (int i = 1; i <= m; ++i) {
        int c = nextInt();
        if (c)  // get(i)
            printf("%d\n", ask(nextInt()));
        else    // add(s, t, x)
        {
            int x = nextInt();
            int y = nextInt();
            int k = nextInt();
            add(x, k); add(y + 1, -k);
        }
    }
 
    //system("pause");
}


Measured memory_bytes: 4332
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define forn(i,a,b) for(int i =a;i<b;i++)
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(false);
using namespace std;

//for debugging 
/*
g++ -D_GLIBCXX_ASSERTIONS -DDEBUG -ggdb3 -std=c++14 
*/
int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
#else
#define dbg(x)
#endif
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
	os<<"[";
	for(auto& x:v){os<<x<<", ";}
	return os<<"]";
}
template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
	return os<<"{"<<p.first<<", "<<p.second<<"}";
}
// debugging ends here

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;


void solve(){
	int n,x,t;
	cin >> n >> x >> t;
	cout << (n+x-1)/x*t << endl;
}

int main(){
	fast;
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif

	// int t;cin >> t;while(t--)
		solve();
}


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

int main()
{
  int tmp,A,B,C,K,res=0;
  scanf("%d %d %d",&A,&B,&C);
  scanf("%d",&K);
  if(A < B){
    tmp = A;
    A = B;
    B = tmp;
  }
  if(A < C){
    tmp = C;
    C = A;
    A = tmp;
  }
  for(int i=0;i<K;i++)
     A *= 2;
  printf("%d\n", A+B+C);
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#define ll long long
using namespace std;
int main(){
    int n,k;
    string s;
    cin>>n>>k>>s;
    int hp=0;
    for(int i=0;i<n-1;i++){
        if(s[i+1]==s[i]) hp++;
        
    }    
    
    cout<<min(2*k+hp,n-1)<<endl;
    return 0;
}

Measured memory_bytes: 512
L=[]
L.append(2)
L.append(1)

def luca(N,cnt):
  L.append(L[-2]+L[-1])
  if N==cnt:
    print(L[-1])
  else:
    cnt+=1
    luca(N,cnt)
N = int(input())

if N<=1:
  print(L[N])
else:
  N-=2
  cnt=0
  luca(N,cnt)

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

using namespace std;

int main(){
#ifdef LOCAL
	freopen("input", "r", stdin);
#endif

	int a, b, c, d;

	scanf("%d %d %d %d", &a, &b, &c, &d);

	int turns_win = ceil((double)c/(double)b);
	int turns_lose = ceil((double)a/(double)d);

	if (turns_win <= turns_lose){
		printf("Yes\n");
	} else {
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 3620
let prime_factors n =
  let rec doit i x acc =
    if i*i > n then begin
      if x <> 1 then x :: acc
      else acc
    end else begin
      if x mod i = 0 then begin
        let new_x = ref (x / i) in
        while !new_x mod i = 0 do
          new_x := !new_x / i
        done;
        doit (i + 1) !new_x (i :: acc)
      end else
        doit (i + 1) x acc
    end in
  doit 2 n []

let phi_func n =
  int_of_float
    (List.fold_left
      (fun acc x -> acc *. (1. -. 1. /. (float x)))
      (float n)
      (prime_factors n))

let () =
  let n = read_int () in
  Printf.printf "%d\n" (phi_func n)

Measured memory_bytes: 2356
#include <stdio.h>

int main(int argc, const char * argv[])
{
    int i, j, k, datasets, max;
    int side[3];
    int num[2];
    int a, b, c;
    
    scanf("%d", &datasets);
    if (datasets > 1000) {
        exit(0);
    }

    for (i = 0; i < datasets; i++) {
        scanf("%d %d %d", &side[0], &side[1], &side[2]);
        if ((1 > side[0] && side[0] > 1000) || (1 > side[1] && side[1] > 1000) || (1 > side[2] && side[2] > 1000)) {
            exit(0);
        }
        
        for (j = 1, max = 0; j < 3; j++) {
            if(side[max] < side[j]) {
                max = j;
            }
        }
        
        k = 0;
        for (j = 0; j < 3; j++) {
            if(side[j] != side[max]) {
                num[k++] = j;
            }
        }

        c = side[max] * side[max];
        a = side[num[0]] * side[num[0]];
        b = side[num[1]] * side[num[1]];
        
        if (c == (a + b)) {
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    }

    return 0;
}

Measured memory_bytes: 580