akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <math.h>
#define uint unsigned long long
#define ll long long
#define db double
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define ept 1e-9

using namespace std;
inline int read()
{
    int x = 0, f = 1; char ch = getchar();
    while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
    return x * f;
}
inline ll read1()
{
	ll x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}

const int N = 2e5 + 10;
pii p[N];
int n, m, ans;
int S[N << 2], T[N << 2];

inline void PushUp(int rt)
{
	S[rt] = S[ls] + S[rs];
	T[rt] = max(T[ls], S[ls] + T[rs]);
}
void Build(int rt, int l, int r)
{
	if (l == r)
	{
		S[rt] = l == 0 ? 0 : -1;
		T[rt] = 0; return;
	}
	int mid = l + r >> 1;
	Build(ls, l, mid);
	Build(rs, mid + 1, r);
	PushUp(rt);
}
void Add(int pos, int w)
{
	int rt = 1, l = 0, r = m;
	while (l < r)
	{
		int mid = l + r >> 1;
		if (pos <= mid) rt = ls, r = mid;
		else rt = rs, l = mid + 1;
	}
	T[rt] = max(0, S[rt] += w);
	while (rt >>= 1) PushUp(rt);
}

int main()
{
	n = read();
	m = read();
	rep(i, 1, n)
	{
		int x, y;
		x = read();
		y = read();
		p[i] = mp(x, m + 1 - y);
	}
	sort(p + 1, p + n + 1);
	Build(1, 0, m);
	rep(i, 1, n)
	{
		Add(p[i].Y, 1);
		ans = max(ans, T[1] - p[i].X);
	}
	printf("%d\n", max(ans, n - m));
	return 0;
}


Measured memory_bytes: 7936
#include<bits/stdc++.h>
#define int long long
#define ld long double
#define inf 0x7f7f7f7f7f7f7f7f 
#define maxn 1000010
#define ri register int
#define il inline
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define mod 998244353
#define db(x) cout << x << endl; 
#define eps 0.0001
using namespace std;
int h[maxn],v[maxn];
int s[maxn]; 
signed main()
{
	ios::sync_with_stdio(0);
	int n,m;
	cin >> n >> m;
	for(int i=1;i<=n;i++)
		cin >> h[i];
	for(int i=1;i<=m;i++)
	{
		int a,b;
		cin >> a >> b;
		if(h[a]>=h[b])
			v[b]=1;
		if(h[b]>=h[a])
			v[a] = 1;
	}
	int ans = 0;
	for(int i=1;i<=n;i++)
		if(!v[i])
			ans++;
	cout << ans;
	return 0;
}

Measured memory_bytes: 5208
#include <bits/stdc++.h>
#define MAXN 1000005
using namespace std;
inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while (ch<'0'||ch>'9'){
        if (ch=='-') f=-1;
        ch=getchar();
    }
    while (ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^'0');
        ch=getchar();
    }
    return x*f;
}
int n,k;
int temp[MAXN],pos[MAXN],P[MAXN],mino[MAXN];
void Solve(int l,int r){
	if (l==r) return ;
	int mid=(l+r)>>1;
	Solve(l,mid),Solve(mid+1,r);
	for (int i=l;i<=r;++i) temp[i]=pos[i];
	mino[mid]=temp[mid];
	for (int i=mid-1;i>=l;--i) mino[i]=min(mino[i+1],temp[i]);
	int i=l,j=mid+1;
	int p=l;
	while (i<=mid&&j<=r){
		if (mino[i]<temp[j]+k) pos[p++]=temp[i++];
		else pos[p++]=temp[j++];
	}
	while (i<=mid) pos[p++]=temp[i++];
	while (j<=r) pos[p++]=temp[j++];
}
int main(){
	n=read(),k=read();
	for (int i=1;i<=n;++i) pos[read()]=i;
	Solve(1,n);
	for (int i=1;i<=n;++i) P[pos[i]]=i;
	for (int i=1;i<=n;++i) printf("%d\n",P[i]);
}

Measured memory_bytes: 17792
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;

int main(){
	
	ll n,k; cin>>n>>k;
	vector<int> a(n);
	for(auto &i:a) cin>>i;
	ll sum{};
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			if(a.at(i)>a.at(j)) sum++;
		}
	}
	(sum *= k) %= MOD;
	sort(a.begin(),a.end());
	ll low = k*(k-1)/2%MOD;
	for(int i=0; i<n; i++){
		auto it2 = upper_bound(a.begin(),a.end(),a.at(i));
		(sum += (a.end()-it2)*low ) %= MOD;
	}
	cout << sum << endl;
	
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int N,T,s[10][2],t[10][2],i,p;
char S[51],r[10][999];
int t2m(int a[2]){return a[0]*60+a[1];}
int main()
{
	scanf("%d%d",&N,&T);
	
	for(i=0;i<N;i++)
	{
		scanf("%d:%d %s %d:%d %*s\n",&s[i][0],&s[i][1],S,&t[i][0],&t[i][1]);
		if(i>0&&t2m(s[i])-t2m(t[i-1])>=T)
			sprintf(r[p++],"%s %d",S,t2m(s[i])-t2m(t[i-1]));
	}
	printf("%d\n",p);
	for(i=0;i<p;i++)
		puts(r[i]);
	return 0;
}

Measured memory_bytes: 636
sx, sy, tx, ty = gets.chomp.split.map(&:to_i)
puts "U" * (ty - sy) + "R" * (tx - sx) + "D" * (ty - sy) + "L" * (tx - sx) +
"L" + "U" * (ty - sy + 1) + "R" * (tx - sx + 1) + "DR" + "D" * (ty - sy + 1) +
"L" * (tx - sx + 1) + "U"

Measured memory_bytes: 1916
#include<bits/stdc++.h>		
using namespace std;
stack<char> q;
string s;
int f=0;
char c[101];
int main(){
	cin>>s;
	for(int i=0; i<s.length(); i++){
		if(s[i]=='0'||s[i]=='1') q.push(s[i]);
		else {
			if(!q.empty()){
				q.pop();
			}
		}
	}
	while(!q.empty()) {
		c[++f]=q.top();
		q.pop();
	}
	for(int i=f; i>=1; i--) cout<<c[i];
	cout<<endl;
}

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

using namespace std;

typedef long long ll;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define range(i, a, b, s) for (int i = (a); i < (b); i += (s))
#define down(i, a, b, s) for (int i = (a); (b) < i; i -= (s))

// begin adjacent table (%fold)

const int maxv = 10002;
const int maxe = 20002;

struct node {
  int v;
} g[maxe];
int gindex, ghead[maxv], gnext[maxe], order[maxv];

void clear() {
  gindex = 0;
  memset(order, 0, sizeof(order));
  memset(ghead, -1, sizeof(ghead));
  memset(gnext, -1, sizeof(gnext));
}

void add_edge(int u, int v) {
  g[gindex].v = v;
  gnext[gindex] = ghead[u];
  ghead[u] = gindex++;
  order[v] += 1;
}

#define edge(e, u) for (int e = ghead[u]; e != -1; e = gnext[e])

// end adjacent table

int n, a, b, c[maxv], d[maxe];
const int inf = 0x7f7f7f7f;

int main(int argc, char const *argv[]) {
  // freopen("D.txt", "r", stdin);

  while (cin >> n) {
    clear();
    // range(i, 0, n, 1) { idx[i] = i; }
    range(i, 1, n, 1) {
      cin >> a >> b;
      a -= 1;
      b -= 1;
      add_edge(a, b);
      add_edge(b, a);
    }
    range(i, 0, n, 1) cin >> c[i];
    sort(c, c + n, less<int>());
    // cout << "c => [";
    // range(i, 0, n, 1) {
    //   if (i) cout << ", ";
    //   cout << c[i];
    // }
    // cout << "]" << endl;

    queue<int> q;
    range(u, 0, n, 1) {
      if (order[u] == 1) {
        q.push(u);
        order[u] -= 1;
      }
    }
    int cc = 0;
    memset(d, inf, sizeof(d));
    while (!q.empty()) {
      int u = q.front();
      // cout << "u => " << (u + 1) << endl;
      q.pop();
      d[u] = c[cc++];
      // order[u] -= 1;
      edge(e, u) {
        int v = g[e].v;
        order[v] -= 1;
        // cout << " " << (v) << endl;
        if (order[v] == 1) {
          q.push(v);
        }
      }
    }
    // cout << "d => [";
    int ans = 0;
    range(e, 0, (2 * (n - 1)), 2) {
      int v = min(d[g[e].v], d[g[e + 1].v]);
      ans += v;
      // cout << g[e].v << " -> " << g[e + 1].v << " " << v << endl;
    }
    cout << (ans) << endl;
    range(i, 0, n, 1) {
      if (i) cout << " ";
      cout << d[i];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1272
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const double g = 9.8;
int N, V, X, Y, xa[55], ya[55], xb[55], yb[55];
pair<double, double> calc(double x, double y) {
	// The target position is (x, y)
	double e = 1.0 * V * V * V * V - 2.0 * g * y * V * V - g * g * x * x;
	if (e < 0.0) return make_pair(-1.0, -1.0);
	double d = sqrt(e);
	double b = 1.0 * V * V - g * y;
	double al = sqrt((b - d) * 2 / (g * g));
	double ar = sqrt((b + d) * 2 / (g * g));
	return make_pair(x / V / ar, x / V / al);
}
int main() {
	cin >> N >> V >> X >> Y;
	bool flag = true;
	int lower = 1 << 30;
	for (int i = 0; i < N; ++i) {
		cin >> xa[i] >> ya[i] >> xb[i] >> yb[i];
		if (xa[i] > X) {
			--N, --i;
			continue;
		}
		if (xb[i] > X) xb[i] = X;
		if (xa[i] <= X && X <= xb[i] && ya[i] <= Y && Y <= yb[i]) {
			flag = false;
		}
		if (xa[i] <= X && X <= xb[i] && ya[i] > Y) {
			lower = min(lower, ya[i]);
		}
	}
	vector<pair<double, double> > rngs;
	vector<double> cps = { 0.0, 1.0e+99 };
	for (int i = 0; i < N; ++i) {
		pair<double, double> pa = calc(xa[i], ya[i]);
		pair<double, double> pb = calc(xb[i], yb[i]);
		pair<double, double> pc = calc(xa[i], yb[i]);
		pair<double, double> pd = calc(xb[i], ya[i]);
		vector<double> va = { pa.first, pa.second, pb.first, pb.second };
		vector<double> vb = { pc.first, pc.second, pd.first, pd.second };
		sort(va.begin(), va.end());
		sort(vb.begin(), vb.end());
		rngs.push_back(make_pair(va[0], va[1]));
		rngs.push_back(make_pair(va[2], va[3]));
		rngs.push_back(make_pair(vb[0], vb[1]));
		rngs.push_back(make_pair(vb[2], vb[3]));
		cps.insert(cps.end(), va.begin(), va.end());
		cps.insert(cps.end(), vb.begin(), vb.end());
	}
	pair<double, double> pe = calc(X, Y);
	pair<double, double> pf = calc(X, lower);
	vector<double> vc = { pe.first, pe.second, pf.first, pf.second };
	sort(vc.begin(), vc.end());
	cps.insert(cps.end(), vc.begin(), vc.end());
	sort(cps.begin(), cps.end());
	cps.erase(unique(cps.begin(), cps.end()), cps.end());
	vector<int> ps(4);
	for (int i = 0; i < 4; ++i) {
		ps[i] = lower_bound(cps.begin(), cps.end(), vc[i]) - cps.begin();
	}
	vector<bool> cant(cps.size());
	for (pair<double, double> x : rngs) {
		int l = lower_bound(cps.begin(), cps.end(), x.first) - cps.begin();
		int r = lower_bound(cps.begin(), cps.end(), x.second) - cps.begin();
		for (int i = l; i < r; ++i) {
			cant[i] = true;
		}
	}
	bool ans = false;
	for (int i = 1; i < cps.size(); ++i) {
		if (cps[i] > 0.0 && cps[i] - cps[i - 1] > 1.0e-9 && !cant[i - 1] && ((ps[0] < i && i <= ps[1]) || (ps[2] < i && i <= ps[3]))) {
			ans = true;
		}
	}
	cout << (ans && flag ? "Yes\n" : "No\n");
	return 0;
}


Measured memory_bytes: 3156
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <bitset>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007; //998244353;

template<class _T> static void get(_T& a) {
	std::cin >> a;
}
template<class _T> static void get(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void get(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}

static void D();

int main()
{
	D();
	fflush(stdout);
	return 0;
}

static void D()
{
	int N;
	get(N);

	std::vector<LLONG> ai(N);
	for (int i = 0; i < N; i++) {
		get(ai[i]);
	}

	std::vector<int> mov(N, 0);
	int buyIdx = 0, sellIdx = 0;
	int price = ai[0];
	for (int i = 1; i < N; i++) {
		if (ai[i] < ai[i - 1]) {
			if (sellIdx) {
				mov[sellIdx] = 2;
				mov[buyIdx] = 1;
				price = ai[i];
				buyIdx = i;
				sellIdx = 0;
			}
			else if (ai[i] < price) {
				buyIdx = i;
				price = ai[i];
			}
		}
		else if (ai[i] > ai[i - 1]) {
			sellIdx = i;
		}
	}
	if (sellIdx) {
		mov[sellIdx] = 2;
		mov[buyIdx] = 1;
	}
	LLONG money = 1000;
	LLONG stock = 0;
	for (int i = 0; i < N; i++) {
		if (mov[i] == 1) {
			stock = money / ai[i];
			money = money % ai[i];
		}
		else if (mov[i] == 2) {
			money += ai[i] * stock;
			stock = 0;
		}
	}
	printf("%lld\n", money);
}


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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v)                                                            \
  do {                                                                         \
    x = max(x, v);                                                             \
  } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

ll N, M;
vector<ll> a;

// 幸福度 x 以上のペアを幾つ作れるか
// O(Nlog(M))
pair<ll, vector<ll>> f(ll x) {
  vector<ll> res(N);
  ll s = 0;
  rep(i, N) {
    auto it = lower_bound(begin(a), end(a), x - a[i]);
    // cout << "*it=" << *it << endl;
    // cout << "distance=" << distance(it, end(a)) << endl;
    res[i] += distance(it, end(a));
    s += res[i];
  }
  return pair<ll, vector<ll>>(s, res);
}

signed main() {
  cin >> N >> M;
  a.resize(N);
  rep(i, N) { cin >> a[i]; }
  sort(begin(a), end(a));

  // cout << "a: ";
  // rep(i, N) { cout << a[i] << " "; }
  // cout << endl;

  // 幸福度の下限okを求める
  // O(Nlog(M)log(M))
  ll ok = 0, ng = 20000000000;
  while (ok + 1 < ng) {
    ll m = (ok + ng) / 2;
    if (f(m).first >= M) {
      ok = m;
    } else {
      ng = m;
    }
  }
  // cout << "ok=" << ok << endl;

  // cout << "b: ";
  auto m = f(ok + 1).first;
  auto b = f(ok + 1).second;
  // rep(i, N) { cout << b[i] << " "; }
  // cout << endl;

  vector<ll> psum(N + 1, 0);
  for (ll i = N - 1; i >= 0; i--) {
    psum[i] = psum[i + 1] + a[i];
  }

  // cout << "psum: ";
  // rep(i, N) { cout << psum[i] << " "; }
  // cout << endl;

  ll ans = (M - m) * ok;
  for (ll i = N - 1; i >= 0; i--) {
    ans += b[i] * a[i] + psum[N - b[i]];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3408
a,b=input().split()
list1={"1":1,"2":3,"3":1,"4":0,"5":1,"6":0,"7":1,"8":1,"9":0,"10":1,"11":0,"12":1}
c=list1[a]
d=list1[b]
if str(c)==str(d):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
int n;
const int N = 210;
const int M = 10000010;
int prime[M], not_prime[M], tot_prime;
int xi[N], A[N], B[N], totA, totB;
int V[N][N], pA[N], vA[N];
void insert(int t)
{
    if (t & 1) A[++ totA] = t;
    else B[++ totB] = t;
}
int dfs(int t)
{
    vA[t] = 1;
    for (int i = 1; i <= totB; ++ i) if (V[t][i] && !vA[pA[i]])
        if (!pA[i] || dfs(pA[i]))
            return pA[i] = t, 1;
    return 0;
}
int main()
{
    not_prime[1] = 1;
    for (int i = 2; i < M; ++ i)
    {
        if (!not_prime[i]) prime[++ tot_prime] = i;
        for (int j = 1; j <= tot_prime && i * prime[j] < M; ++ j)
        {
            not_prime[i * prime[j]] = 1;
            if (i % prime[j] == 0) break;
        }
    }
    cin >> n;
    for (int i = 1; i <= n; ++ i) cin >> xi[i];
    xi[0] = -1;
    for (int i = 1; i <= n; ++ i)
    {
        if (xi[i] - xi[i - 1] != 1) insert(xi[i]);
        if (xi[i + 1] - xi[i] != 1) insert(xi[i] + 1);
    }
    for (int a = 1; a <= totA; ++ a)
        for (int b = 1; b <= totB; ++ b)
            if (!not_prime[abs(A[a] - B[b])])
                V[a][b] = 1;
    int match = 0;
    for (int i = 1; i <= totA; ++ i)
    {
        for (int j = 1; j <= totA; ++ j) vA[j] = 0;
        if (dfs(i)) match ++;
    }
    int ans = match + (totA - match) / 2 * 2 + (totB - match) / 2 * 2 + (totA - match) % 2 * 3;
    cout << ans;
}


Measured memory_bytes: 43136
import sys 
import math
try:
	sys.stdin = open('input.txt', 'r') 
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = sys.stdin.readline
for tt in range(1):
	# r = int(input())
	n,m = map(int,input().split())
	l = list(map(int,input().split()))
	print(-1 if sum(l)>n else n-sum(l))
	

Measured memory_bytes: 68200
#include<stdio.h>
#include<string.h>

#define M 1046527
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
  else return 0;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M - 1)); }

int find(char str[]){
  long long key , i , h;
  key = getKey(str);
  for(i = 0;;i++) {
    h = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[h],str) == 0) return 1;
    else if ( strlen(H[h]) == 0 )return 0;
  }
  return 0;
}

int insert(char str[]){
  long long key , i ,h;
  key = getKey(str);
for(i = 0;;i++) {
  h = (h1(key) + i * h2(key)) % M;
  if(strcmp(H[h],str) == 0) return 1;
  else if ( strlen(H[h]) == 0) {
    strcpy(H[h], str);
    return 0;
  }
}
return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';

    scanf("%d", &n);

    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);

	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}

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

int main() {
  char c;
  cin >> c;
    
	if(c=='a'||c=='i'||c=='u'||c=='e'||c=='o'){
      cout << "vowel" << endl;
    }
    else{
      cout << "consonant" << endl;
    }
}


Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Scanner;

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

		int n = sc.nextInt();
		int m = sc.nextInt();
		int k = sc.nextInt();

		HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();

		int black = 0;
		for (int i = 0; i <= n; i++) {
			for (int j = 0; j <= m; j++) {
				black = j * (n - 2 * i) + i * m;
				if (!map.containsKey(black))
					map.put(black, black);
			}
		}

		if (map.containsKey(k))
			System.out.println("Yes");
		else
			System.out.println("No");
	}

}


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

int main() {
  string a, b;
  cin >> a >> b;
  int ans = stoi(a+b);
  bool ok = false;
  for(int i = 1; i <= 1000; i++) {
    if(i*i == ans) ok = true;
  }
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3600
import Data.Functor( (<$>))
import Control.Monad( replicateM, foldM_)

main = do
    initialStr <- getLine
    q <- read <$> getLine
    operations <- replicateM q getLine
    let
	partitionizeWith a b f str
	  = let
		(left,part3) = splitAt (b+1) str
		(part1,part2) = splitAt a left
	    in
		part1 ++ f part2 ++ part3

	proc str operation
	  = let
		ops = words operation
		a = read $ ops!!1
		b = read $ ops!!2
	    in
		case ops!!0 of
		"print"	   -> let s = drop a  $ take (b+1) str
				in putStrLn s >> return str
		"reverse"  -> return $ partitionizeWith a b reverse str
		"replace"  -> return $ partitionizeWith a b (const $ ops!!3) str

    foldM_ proc initialStr operations



Measured memory_bytes: 5756
/* 
	Author: ankrypt
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
#define ff first
#define ss second
#define all(x) x.begin(), x.end() 
#define ub upper_bound
#define lb lower_bound
#define MAX_INT 5
#define fi(a, b, c, d) for(int a = b; a < c; a += d)
#define fl(a, b, c, d) for(ll a = b; a < c; a += d)
#define fei(a, b, c, d) for(int a = b; a <= c; a += d)
#define fel(a, b, c, d) for(ll a = b; a <= c; a += d)
#define quit exit(0)

ll N, M, A, B, C;
ll arr[MAX_INT], arr1[MAX_INT], temp[MAX_INT];
vector<ll> V;


int main() {
	scanf("%lld %lld %lld %lld", &A, &B, &C, &M);
	arr[0] = A;
	arr[1] = B;
	arr[2] = C;
	fi(i, 0, 3, 1) {
		if(M > 0) {
			if(M >= arr[i]) {
				V.push_back(arr[i]);
				M -= arr[i];
			}
			else {
				V.push_back(M);
				M = 0;
			}
		}
	} 
	temp[0] = 1;
	temp[1] = 0;
	temp[2] = -1;
	ll ans = 0;
	fi(i, 0, V.size(), 1) {
		ans += V[i] * temp[i];
	}
	printf("%lld\n", ans);
	
	return 0;
}
/*
	Powered by Buggy Plugin
*/




Measured memory_bytes: 3776
#include<cstdio>
#include<iostream>
using namespace std;
int main() {
  int top = 0, ans = 0, pos = 0, stack[100];
  char s[1000];
  for (int i = 0; i < 1000; ++i) {
    scanf("%c", &s[i]);
    if (s[i] == '\n') {
      s[i] = '\0'; break;
    }
  }
  while (1) {
    int cnt = 0;
    if (s[pos] >= '0'&&s[pos] <= '9') {
      int x = 1, ope = 0;
      while (s[pos] >= '0'&&s[pos] <= '9') { ++cnt; ++pos; }
      for (int i = 1; i <= cnt; ++i, x *= 10) {
	ope += (s[pos - i] - '0')*x;
      }
      stack[top++] = ope;
    }
    else if (s[pos] == '+') {
      int x1 = stack[--top], x2 = stack[--top];
      stack[top++] = x1 + x2;
      ++pos;
    }
    else if (s[pos] == '-') {
      int x1 = stack[--top], x2 = stack[--top];
      stack[top++] = x2 - x1;
      ++pos;
    }
    else {
      int x1 = stack[--top], x2 = stack[--top];
      stack[top++] = x1 * x2;
      ++pos;
    }
    if (s[pos] == '\0') break;
    ++pos;
  }
  cout << stack[0] << endl;
  return 0;
}



Measured memory_bytes: 3240
import math
def solve():
  X = int(input())

  for i in range(1,int(math.sqrt(X))+1):
    if X % i == 0:
      A = -int(X**(1/5))
      B = A - i
      while A**5-B**5>X:
        A = A+1
        B = A-i
      while A**5-B**5<=X:
        if A**5-B**5==X:
          print(A,B)
          return
        A = A + 1
        B= A - i
        
solve()

Measured memory_bytes: 9376
a, b, m = map(int, input().split())
list_a = list(map(int, input().split()))
list_b = list(map(int, input().split()))
list_m = [ list(map(int,input().split(" "))) for i in range(m)]

ans = []

ans.append(min(list_a)+min(list_b))

for i in range(m):
    k = list_m[i]
    ans.append(list_a[k[0]-1] + list_b[k[1]-1] - k[2])

print(min(ans))

Measured memory_bytes: 42408
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define for0(n) for(i=0; i<(n); i++)
#define forn1 for(i=1; i<=n; i++)


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll _,i,j,n,a,b,e,k,u,t,x=1,m,y,q,f=1,c=0,d=0,l,p,z,o,r,g,bb;
//    string ss,s;
////    cin>>_;
//    while(_--)
//    {
//        c
//
//    }
    cin>>n>>m;
    for0(m)
    {
        cin>>x;
        c+=x;
    }
    cout<<max(-1LL,n-c)<<endl;
}


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

using namespace std;

int N;
int BIT[100005];
vector<int> cmp;
int arr[100005];
int dp[100005];

int getidx(int n){
    return lower_bound(cmp.begin(), cmp.end(), n) - cmp.begin() + 1;
}

void upd(int n, int v){
    n = getidx(-n);
    for(int i = n; i<=N; i+=i&-i){
        BIT[i] = max(BIT[i], v);
    }
}

int query(int n){
    int s = 0;
    n = getidx(-n);
    for(int i = n; i>0; i-=i&-i){
        s = max(BIT[i], s);
    }
    return s;
}

int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> N;
    for(int i =1 ; i<=N; i++){
        cin >> arr[i];
        cmp.push_back(-arr[i]);
    }
    sort(cmp.begin(), cmp.end());
    //reverse(cmp.begin(), cmp.end());
    int ans = 0;
    for(int i = 1; i<=N; i++){
        dp[i] = query(arr[i]) + 1;
        upd(arr[i], dp[i]);
        ans = max(ans, dp[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
  ll n ;
  cin >> n;
  
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  
  ll ans = 0;
  int maxNum = 0;
  
  for(int i = 0; i < n; i++){
    maxNum = max(maxNum, a[i]);
    int x = maxNum;
    ans += maxNum - a[i];
  }
  cout << ans << endl;
} 

Measured memory_bytes: 3972
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, a[200009], b[200009], cnt[3], ans[200009], pp[200009];
vector<int> vec[200009];

void fun(int from, int cur, int v)
{
	pp[cur] = v;
	for (int i = 0; i < (int)vec[cur].size(); i++) {
		if (vec[cur][i] != from) {
			fun(cur, vec[cur][i], 1 - v);
		}
	}
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		cin >> a[i] >> b[i];
		vec[a[i]].pb(b[i]);
		vec[b[i]].pb(a[i]);
	}
	fun(0, 1, 1);
	int cnt2 = (n + 1) / 3;
	int cnt1 = (n + 2) / 3;
	int cur0 = 3, cur1 = 1, cur2 = 2;
	bool flag = true;
	for (int i = 1; i <= n; i++) {
		if (pp[i]) {
			if (cnt1) {
				ans[i] = cur1;
				cur1 += 3;
				cnt1--;
			}
			else {
				ans[i] = cur0;
				cur0 += 3;
			}
		}
		else {
			if (cnt2) {
				ans[i] = cur2;
				cur2 += 3;
				cnt2--;
			}
			else {
				ans[i] = cur0;
				cur0 += 3;
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		if (ans[i] > n) flag = false;
	}
	if (!flag) {
		int cnt2 = (n + 1) / 3;
		int cnt1 = (n + 2) / 3;
		int cur0 = 3, cur1 = 1, cur2 = 2;
		for (int i = 1; i <= n; i++) {
			if (!pp[i]) {
				if (cnt1) {
					ans[i] = cur1;
					cur1 += 3;
					cnt1--;
				}
				else {
					ans[i] = cur0;
					cur0 += 3;
				}
			}
			else {
				if (cnt2) {
					ans[i] = cur2;
					cur2 += 3;
					cnt2--;
				}
				else {
					ans[i] = cur0;
					cur0 += 3;
				}
			}
		}
	}
	flag = true;
	for (int i = 1; i <= n; i++) {
		if (ans[i] > n) flag = false;
	}
	if (!flag) {
		int c0 = 0, c1 = 0;
		for (int i = 1; i <= n; i++) {
			if (pp[i]) c1++;
			else c0++;
		}
		bool ok = true;
		int cnt2 = (n + 1) / 3;
		int cnt1 = (n + 2) / 3;
		int cur0 = 3, cur1 = 1, cur2 = 2;
		if (c1 > c0) ok = false;
		for (int i = 1; i <= n; i++) {
			if (ok) {
				if (pp[i]) {
					ans[i] = cur0;
					cur0 += 3;
				}
				else {
					if (cur1 <= n) {
						ans[i] = cur1;
						cur1 += 3;
					}
					else if (cur2 <= n) {
						ans[i] = cur2;
						cur2 += 3;
					}
					else {
						ans[i] = cur0;
						cur0 += 3;
					}
				}
			}
			else {
				if (!pp[i]) {
					ans[i] = cur0;
					cur0 += 3;
				}
				else {
					if (cur1 <= n) {
						ans[i] = cur1;
						cur1 += 3;
					}
					else if (cur2 <= n) {
						ans[i] = cur2;
						cur2 += 3;
					}
					else {
						ans[i] = cur0;
						cur0 += 3;
					}
				}
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		cout << ans[i] << " ";
	}
	cout << E;
	//system("pause");
	return 0;
}

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

typedef long long       ll;
typedef vector<int>     vi;
typedef pair<int,int>   pi;
typedef map<int,int>    mi;

#define F               first
#define S               second
#define pb              push_back
#define mp              make_pair
#define M               1000000007
#define SQ(a)           (a)*(a)
#define rep(i,a,b)      for(int i=a; i<b; i++)

void solve(){
   string s;
    cin >> s ;

    int n = s.size()-1;
    if(s[n]=='s') s+="es";
    else s+='s';
   cout << s << endl;
}
int main(){
    //int t; cin >> t; while(t--)
    solve();

    return 0;
}





Measured memory_bytes: 3632
#include<iostream>
using namespace std;
 
int main(){
 
    int N;
    cin >> N;
    if(N/100==7) {
      cout<<"Yes"<<endl;
      return 0;
    }
    if((N/10)%10==7) {
      cout<<"Yes"<<endl;
      return 0;
    }
  if(N%10==7) {
      cout<<"Yes"<<endl;
      return 0;
    }
  
  else{
    cout<<"No"<<endl;
    return 0;
  }
}

Measured memory_bytes: 3044
#include "bits/stdc++.h"
#include <random>
#define REP(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < ll(n); ++i)
#define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
struct Q {
  ll l, r, c, index;
  bool operator<(const Q &rhs) const {
    if (l == rhs.l)
      return r < rhs.r;
    return l < rhs.l;
  }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n, m;
  cin >> n >> m;
  vector<Q> v(m);
  REP(i, m) {
    ll l, r, c;
    cin >> l >> r >> c;
    l--;
    r--;
    v[i] = Q{l, r, c, i};
  }
  sort(ALL(v));
  vector<vector<Q>> cand(n);
  REP(i, m) cand[v[i].l].push_back(v[i]);
  vector<ll> d(n, INF * INF);
  vector<int> valid(m, 1);
  d[0] = 0;

  priority_queue<pll, vector<pll>, greater<>> q1, q2;
  for (auto q : cand[0]) {
    q1.push({q.c, q.index});
    q2.push({q.r, q.index});
  }
  FOR(i, 1, n) {
    while (!q2.empty() && q2.top().first < i) {
      valid[q2.top().second] = 0;
      q2.pop();
    }
    while (!q1.empty() && valid[q1.top().second] == 0) {
      q1.pop();
    }
    if (q1.empty()) {
      cout << -1 << endl;
      return 0;
    }
    d[i] = q1.top().first;
    for (auto q : cand[i]) {
      q1.push({q.c + d[i], q.index});
      q2.push({q.r, q.index});
    }
  }
  cout << d[n - 1] << endl;
}


Measured memory_bytes: 13596
#include<iostream>
using namespace std;
int main(){
  int n,a[1234567],b[1234567],tong;
  cin>>n;
  tong =0;
  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i];
    tong+=b[i]-a[i]+1;
  }
  cout<<tong;
  return 0;
}

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

int main(){
    int a,b,c,k,max;
    scanf("%d %d %d %d",&a,&b,&c,&k);

    max = a;
    if(b>max)
        max = b;
    else if(c>max)
        max = c;
    
    if(max==a)
        max = (pow(2,k)*a) + b + c;
    else if (max==b)
        max = ((1<<k)*b) + a + c;
    else if (max==c)
        max = ((1<<k)*c) + a + b;

    printf("%d\n",max);
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]

ans = "No"

for i in range(N - M + 1):
    for j in range(N - M + 1):
        c = 0
        for x in range(M):
            for y in range(M):
                if A[x + i][y + j] == B[x][y]:
                    c += 1
        if c == M ** 2:
            ans = "Yes"
            break

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin >> s;
	int l = s.length();
	for (int i(1); i < l - 1; i++)
	{
		s = s.substr(0, s.length() - 1);
		if (s.substr(0, s.length() / 2) == s.substr(s.length() / 2, s.length()))
		{
			cout << l - i;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int mincost(int *arr,int n,int* memo){
	if(n<=1) return 0;
	if(n==2) return abs(arr[0]-arr[1]);
	if(memo[n]!=-1) return memo[n]; 
	int ans1=mincost(arr+1,n-1,memo);
	int ans2=mincost(arr+2,n-2,memo);
	int ans=min(abs(arr[0]-arr[1])+ans1,abs(arr[0]-arr[2])+ans2);
	memo[n]=ans;
	return ans;
}

int main(){
	int n;
	cin>>n;
	int * arr=new int[n];
	for(int i=0;i<n;i++) cin>>arr[i];
	int * memo=new int [n+1];
	for(int i=0;i<=n;i++) memo[i]=-1;
	int ans=mincost(arr,n,memo);
	cout<<ans<<endl;
return 0;
}

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

int main() {
  int N,i,sum,a,b;
  cin>> N;
  sum=0,a=0,b=N;
  for (i==0; ; i++){
    a=b%10,b/=10;
    sum+=a;
    if (b==0)
      break;
  }
  if (N%sum==0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <bits/stdc++.h>

#include<unordered_set>

using namespace std;

#define dprint(Exp,...) if(Exp){fprintf(stderr, __VA_ARGS__);}
#define printe(...) fprintf(stderr, __VA_ARGS__);
#define PrtExp(_Exp)  cerr<< #_Exp <<" = "<< (_Exp)
#define PrtExpN(_Exp)  cerr<< #_Exp <<" = "<< (_Exp) <<"\n"

#define SINT(n) scanf("%d",&n)
#define SINT2(n,m) scanf("%d %d",&n,&m)
#define SINT3(n,m,o) scanf("%d %d %d",&n,&m,&o)
#define SINT4(n,m,o,p) scanf("%d %d %d %d",&n,&m,&o,&p)
#define SINT5(n,m,o,p,q) scanf("%d %d %d %d %d",&n,&m,&o,&p,&q)
#define SLL(n) scanf("%lld",&n)
#define SLL2(n,m) scanf("%lld %lld",&n,&m)
#define SLL3(n,m,o) scanf("%lld %lld %lld",&n,&m,&o)
#define SST(s) scanf("%s",s)
#define SCH(c) scanf("%c",&c)

#define GC() getchar()

#define PINT(n) printf("%d",(int)(n))
#define PINT2(n,m) printf("%d %d",(int)(n),(int)(m))
#define PINT3(n,m,l) printf("%d %d %d",(int)(n),(int)(m),(int)(l))
#define PLL(n) printf("%lld",(long long)(n))
#define PST(s) printf("%s",(s))
#define PCH(s) printf("%c",(s))

#define PINTN(n) printf("%d\n",(int)(n))
#define PINT2N(n,m) printf("%d %d\n",(int)(n),(int)(m))
#define PINT3N(n,m,l) printf("%d %d %d\n",(int)(n),(int)(m),(int)(l))
#define PLLN(n) printf("%lld\n",(long long)(n))
#define PSTN(s) printf("%s\n",(s))
#define PCHN(s) printf("%c\n",(s))

#define PSP() printf(" ")
#define PN() printf("\n")

#define PC(c) putchar(c)
#define CSP (' ')
#define SN ("\n")

#define rep(i,a) for(int i=0;i<a;i++)
#define reP(i,a) for(int i=0;i<=a;i++)
#define Rep(i,a) for(int i=a-1;i>=0;i--)
#define ReP(i,a) for(int i=a;i>=0;i--)

#define rEp(i,a) for(i=0;i<a;i++)
#define rEP(i,a) for(i=0;i<=a;i++)
#define REp(i,a) for(i=a-1;i>=0;i--)
#define REP(i,a) for(i=a;i>=0;i--)

#define repft(i,a,b) for(int i=a;i<b;i++)
#define repfT(i,a,b) for(int i=a;i<=b;i++)
#define Repft(i,a,b) for(int i=a-1;i>=b;i--)
#define RepfT(i,a,b) for(int i=a;i>=b;i--)

#define foreach(a,it) for(auto it = a.begin(); it != a.end(); ++it)

#define FILL(a,v) fill(begin(a),end(a), v)
#define FILL0(a) memset(a,0,sizeof(a))
#define FILL1(a) memset(a,-1,sizeof(a))

typedef long long ll;

typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll>   Pll;


const int INF = 1000000009;
const ll INFLL = 0x1f1f1f1f1f1f1f1fLL;//2,242,545,357,980,376,863

template <class A, class B> inline ostream& operator<<(ostream& st, const pair<A, B>& P) { return st << "(" << P.first << "," << P.second << ")"; };
template <class A, class B> inline pair<A, B> operator+(const pair<A, B>& P, const pair<A, B>& Q) { return pair<A, B>(P.first + Q.first, P.second + Q.second); };
template <class A, class B> inline pair<A, B> operator-(const pair<A, B>& P, const pair<A, B>& Q) { return pair<A, B>(P.first - Q.first, P.second - Q.second); };

#define fs  first	
#define sc  second



int main() {
	string s;
	int n;
	cin >> s >> n;
	for (int i = 0; i < s.length(); i += n) {
		cout << s[i];
	}
	cout << endl;


	return 0;
}

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

using namespace std;
int v[1005],w[1005],d[20005];
int main()
{
    int n,m,ans=1000000000;
    cin >> m >> n;
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&v[i],&w[i]);
    }
    for(int i=0;i<=20000;i++)
    {
        d[i]=1000000000;
    }
    d[0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=v[i];j<=20000;j++)
        {
            d[j]=min(d[j],d[j-v[i]]+w[i]);
        }
    }
    for(int i=m;i<=20000;i++)
    {
        ans=min(ans,d[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
 
int main() {
  int A, B, j = 0, l = 0, k= 0, f = 0;
  cin >> A >> B;
  j = 1;
 
  // ここにプログラムを追記
    rep(i ,A) {
        if (j < B) {
         j = j + j;
        }
      	else{
         j = j + B;
        }
  	}
    	cout << j;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
 

int  A(int x){
    if(x>=0)return x;
    else return -x;
}

ll inv(ll x) {
	ll res = 1;
	ll k = N - 2;
	ll y = x%N;
	while (k) {
		if (k & 1)res = (res*y) % N;
		y = (y%N)*(y%N) % N;
		k /= 2;
	}
	return res;
}

bool m[2010];

int main(void){
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=1;i<(1<<n);i++){
        int sum = 0;
        for(int j=0;j<n;j++){
            if(i & (1<<j)){
                sum+=a[j];
            }
        }
        m[sum]=true;
    }
    int q;
    cin>>q;
    for(int i=0;i<q;i++){
        int x;
        cin>>x;
        if(m[x]){
            cout<<"yes"<<endl;
        }
        else cout<<"no"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
long long n,i,a[222222],ans;
int main(){
	scanf("%d",&n);
	for (i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	a[0]=-1;
	for (i=1;i<=n;i++){
		if (a[i]>a[i-1]+1){
			puts("-1");
			return 0;
		}
	}
	for (i=1;i<n;i++) if (a[i]==a[i+1]-1) ans++; else ans+=a[i+1];
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,t,e;
	cin >> n;
	int ans = 1;
	cin >> t;
	for(int i = 1;i < n;++i){
		cin >> e;
		if(e <= t) {
			ans += 1;
			t = e;
	} 
		}
		cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define N 1000000

int main(){
  int n,q,C=0;
  int S[N],T[N];
  int i,j,key;

  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&S[i]);

  scanf("%d",&q);
  for(i=0;i<q;i++)
    scanf("%d",&T[i]);

  for(i=0;i<q;i++){
    key=T[i];
    j=0;
    while(j<n){
      for(j=0;j<n;j++){
	if(key == S[j]){
	  C++;
	  j=n;
	  break;
	}
      }
    }
  }
  printf("%d\n",C);
  return 0;
}

Measured memory_bytes: 2692
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  string::const_iterator it=s.begin();
  string::const_reverse_iterator rit=s.rbegin();
  int c=0;
  for(int i=0;i<s.size()/2;i++,++it,++rit) {
    if(*it!=*rit) c++;
  }
  cout << c << endl;
  return 0;
}

Measured memory_bytes: 256
from sys import exit, stdin
N, x = [int(_) for _ in stdin.readline().rstrip().split()]
A = [int(_) for _ in stdin.readline().rstrip().split()]

ans = 0
for i in range(N-1):
    two_total = A[i]+A[i+1]
    if two_total > x:
        A[i+1] = max(0, A[i+1]+x-two_total)
        ans += two_total-x

print(ans)

Measured memory_bytes: 14596
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;




int main(){
  int x;
  while(cin >> x){
    vector<bool> dp(x+1000);
    dp[0] = true;

    FORE(i,0,x){
      REPE(j,5){
        dp[i + 100 + j] = dp[i + 100 + j] or dp[i];
      }
    }

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

  return 0;
}


Measured memory_bytes: 256
import collections
n=int(input())
b=list("abcdefghij")


def func(l, a):
    if n == a:
        for ans in l:
            print(ans)
        return
    newl=[]
    for tmp in l:
        c=collections.Counter(list(tmp))
        for i in range(len(c)+1):
            newl.append(tmp + b[i])
    func(newl, a+1)

func(['a'], 1)


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

int main() {
    int N;
    string S; cin >> N >> S;
    int x = 0, mx = 0;
    for (int i = 0; i < N; i++) {
        if (S.at(i) == 'I') x++;
        else x--;
        mx = max(mx, x);
    }
    cout << mx << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<iostream>

using namespace std;


int main ()
{
    int n , tmp [1001];
    int d,x ;
    while (scanf ("%d",&n)!=EOF)
    {
         int ans =0;
        scanf ("%d%d",&d,&x) ;
        for (int i=0;i<n;i++)
            scanf ("%d",&tmp[i]);
        ans += x;
        for (int i=0;i<n;i++)
        {
            ans ++ ;
            ans += (d-1) /tmp[i]  ;
            //cout<<ans <<endl ;
        }
        printf ("%d\n",ans );

    }


    return 0;
}


Measured memory_bytes: 256
import sys
N = int(sys.stdin.readline())
R = {}
for i in xrange(N):
  s, p = sys.stdin.readline().strip().split()
  if s in R:
    R[s] += [(int(p), i+1)]
  else:
    R[s] = [(int(p), i+1)]
for k,V in sorted(R.items()):
  for v in sorted(V, reverse=True):
    print v[1]

Measured memory_bytes: 2568
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
struct edge {
    ll to,cost;
};

/*
const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_MAX; i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
        finv[i] = finv[i-1]*inv[i]%MOD;
    }
}
long long COM(int n,int k){
    if(n < k || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
*/

int main(){
    ll N; cin >> N;
    cout << N*(N-1)/2 << endl;
}

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

int n;

int main(void) {

    cin >> n;
    int m[n + 1][n + 1] = {};
    int p[n + 1] = {}; // p[i - 1] x p[i]の行列を表す

    for (int i = 0; i < n; ++i) {
        cin >> p[i] >> p[i + 1];
    }

    // 範囲が1の場合は計算しないので0
    for (int i = 1; i <= n; ++i) {
        m[i][i] = 0;
    }

    // l    : 対象とする行列の個数
    // i    : スタート地点
    // j    : ゴール地点
    // k    : 括弧を切るポイント
    for (int l = 2; l <= n; ++l) {
        for (int i = 1; i <= n - l + 1; ++i) {
            int j = i + l - 1;
            m[i][j] = INT32_MAX;
            for (int k = i; k <= j - 1; ++k) {
                m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
            }
        }
    }

    // for (int i = 1; i <= n; ++i) {
    //     for (int j = i + 1; j <= n; ++j) {
    //         m[i][j] = INT32_MAX;
    //         for (int k = i; k < j; ++k) {
    //             // i ~ k, (k + 1) ~ jの行列計算
    //             // それまでの計算回数 + 新しい計算回数
    //             // それまでの計算回数はm[i][k] + m[k + 1][n]
    //             // 新しい計算回数は左の行 * 中間の列 * 右の列
    //             m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
    //         }
    //     }

    // }

    cout << m[1][n] << endl;

    return 0;
}


Measured memory_bytes: 3124
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdlib>

using namespace std;

int main(){
  string S;
  cin >> S;
  int count=0;
  for(int i=0;i<3;i++){
    if(S.at(i)=='1')  count++;
  }
  cout << count << endl;

  return 0;
}


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

using namespace std;

typedef long long ll;

const int MAXN=510;

int n,m,q;
int f[MAXN][MAXN];

int main()
{
    scanf("%d%d%d",&n,&m,&q);
    for(int i=1,l,r;i<=m;i++)
    {
        scanf("%d%d",&l,&r);
        f[l][r]++;
    }
    for(int len=2;len<=n;len++)
        for(int i=1;i+len-1<=n;i++)
        {
            f[i][i+len-1]+=f[i][i+len-2]+f[i+1][i+len-1]-f[i+1][i+len-2];
        }
    for(int i=1,l,r;i<=q;i++) scanf("%d%d",&l,&r),printf("%d\n",f[l][r]);
}

Measured memory_bytes: 1920
n = int(input())
a = list(map(str,input().split()))

frn = ["" for i in range((n+1)//2)]
bck = ["" for i in range(n//2)]

for i in range(n):
    if i%2 == 0:
        frn[i//2] = a[i]
    else:
        bck[i//2] = a[i]

if n%2 == 0:
    print(" ".join(bck[::-1]+frn))
else:
    print(" ".join(frn[::-1]+bck))


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

int main(){
  int def,l,r,t,ans=2019;cin>>l>>r;
  def=(r-l)%2020;l%=2019;r=l+def;
  
  for(int i=l;i<=r-1;i++){
    for(int j=i+1;j<=r;j++){
      ans=min(ans,(i*j)%2019);
    }
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second

using namespace std;
int main()
{
	std::ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	string s;
	cin>>s;
	int c = 0;
	int k=0;
	while(k<n){
		c = s[k] == 'R' ? c+1 : c;
		k++;
	}
	if(c == n)	cout<<0<<endl;
	else{
		int count = 0;
		for(int i=0,j = n-1;i<j;){
			if(s[i] == 'W' && s[j] == 'R'){
				swap(s[i++], s[j--]);
				count++;
			}
			else if(s[i] == 'W' && s[j]!='R')	j--;
			else if(s[i] != 'W' && s[j]=='R')	i++;
			else if(s[i] != 'W' && s[j]!='R')	i++,j--;
		}
		for(int i=1;i<n;i++){
			if(s[i-1] == 'W' && s[i] == 'R'){
				s[i-1] = 'R';	count++;
			}
		}
		cout<<count<<endl;
	}

}


Measured memory_bytes: 3768
require 'prime'
require 'set'
require 'tsort'
include Math
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end


n = gif

a = gi
a.sort!
puts a.last-a.first

Measured memory_bytes: 2300
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if ((a == 1 || a == 9 || a == 7 || a == 4) && (b == 1 || b == 9 || b == 7 || b == 4) && (c == 1 || c == 9 || c == 7 || c == 4) && (d == 1 || d == 9 || d == 7 || d == 4) && a + b + c + d == 21) { cout << "YES" << endl; }
	else { cout << "NO" << endl; }
}

Measured memory_bytes: 256