akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	int N; cin>>N;
	vector<ll> A(N);
	rep(i,N)cin>>A[i];

	//possible or impossible
	if(A[0] != 0){
		cout<<-1<<endl;
		return 0;
	}
	rep(i,N-1){
		if(A[i+1]-A[i] > 1){
			cout<<-1<<endl;
			return 0;
		}
	}

	//way
	ll ans = 0;
	vector<bool> re(N,false);
	REP(i,N-1){
		if(A[i] > A[i-1])++ans;
		else ans += A[i];
	}
	cout<<ans<<endl;
	return 0;
}

// int main(){
// 	int N; cin>>N;
// 	vector<ll> A(N);
// 	rep(i,N)cin>>A[i];
// 	if(A[0] != 0){
// 		cout<<-1<<endl;
// 		return 0;
// 	}
// 	ll ans = A[N-1];
// 	vector<ll> add(N,0);
// 	add[N-1] = A[N-1];
// 	for(int i = N-2; i>=0; --i){
// 		ll need = A[i];
// 		ll max_inh = max(add[i+1]-1, 0LL);
// 		need = max(need - max_inh, 0LL);
// 		// printf("%d -> need = %lld\n", i, need);
// 		add[i] = need;
// 		ans += need;
// 	}
// 	cout<<ans<<endl;
// 	return 0;
// }

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

int main() {
	int N,n;
	cin >> N;
	n = N * 2;
	vector<int> L(n);
	for (int i = 0; i < n; i++) {
		cin >> L[i];
	}
	sort(L.begin(), L.end());
	int ans = 0;
	for (int i = 0; i < n; i = i + 2) {
		ans = ans + L[i];
	}
	cout << ans << endl;

	return 0;
}

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

int main() {
  int n,a,b;
  string s;
  cin >> n >> a >> b >> s;
  int absum = 0,bsum = 0;
  for(int i = 0;i < n;i++){
    if(s[i] == 'a'){
      if(absum < a+b){
        cout << "Yes" << endl;
        absum++;
      }
      else cout << "No" << endl;
    }
    else if(s[i] == 'b'){
      if(absum < a+b && bsum < b){
        cout << "Yes" << endl;
        absum++;
        bsum++;
      }
      else cout << "No" << endl;
    }
    else cout << "No" << endl;
  }
}


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

int main(void)
{
    int s; cin>>s;
    if(s>=1800) cout<<1;
    else if(s>=1600) cout<<2;
    else if(s>=1400) cout<<3;
    else if(s>=1200) cout<<4;
    else if(s>=1000) cout<<5;
    else if(s>=800) cout<<6;
    else if(s>=600) cout<<7;
    else cout<<8;
    return 0;
}

Measured memory_bytes: 3640
#from collections import *
#from itertools import *
#from bisect import *
from heapq import *
#import copy
#N=int(input())
#X,Y=map(int,input().split()))
#S=list(map(int,input().split()))
#S=[list(map(int,input().split())) for i in range(N)]

N=int(input())

Xsort=[]
Ysort=[]
for i in range(N):
    X,Y=map(int,input().split())
    Xsort.append([X,i])
    Ysort.append([Y,i])
Xsort=sorted(Xsort,key=lambda x:x[0])
Ysort=sorted(Ysort,key=lambda x:x[0])
Nidxlst=[[0,0] for i in range(N)]
for i in range(N):
    idx=Xsort[i][1]
    Nidxlst[idx][0]=i
    idx=Ysort[i][1]
    Nidxlst[idx][1]=i



value=0
x,y=Nidxlst[0]
ittenai=set([i for i in range(1,N)])

stack=[]
heapify(stack)
setm=set()
dic={}
def main(x,y):
    if x>0:
        a=Xsort[x-1][1]
        if a in ittenai:
            m=Xsort[x][0]-Xsort[x-1][0]
            heappush(stack,m)
            if m in setm :
                dic[m].append(a)
            else:
                setm.add(m)
                dic.update({m:[a]})
    if x<N-1:
        a=Xsort[x+1][1]
        if a in ittenai:
            m=Xsort[x+1][0]-Xsort[x][0]
            heappush(stack,m)
            if m in setm :
                dic[m].append(a)
            else:
                setm.add(m)
                dic.update({m:[a]})
    if y>0:
        a=Ysort[y-1][1]
        if a in ittenai:
            m=Ysort[y][0]-Ysort[y-1][0]
            heappush(stack,m)
            if m in setm :
                dic[m].append(a)
            else:
                setm.add(m)
                dic.update({m:[a]})
    if y<N-1:
        a=Ysort[y+1][1]
        if a in ittenai:
            m=Ysort[y+1][0]-Ysort[y][0]
            heappush(stack,m)
            if m in setm :
                dic[m].append(a)
            else:
                setm.add(m)
                dic.update({m:[a]})
main(x,y)
idle=10**9+1
value=0
while ittenai:
    m=heappop(stack)
    a=dic[m].pop()
    if a in ittenai:
        x,y=Nidxlst[a]
        main(x,y)
        ittenai.remove(a)
        value+=m

print(value)


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

int main(){
    int N, K;
    scanf("%d %d", &N, &K);

    double ans = 0;
    for(int i=0; i<N; i++){
        int j, cnt = 0;
        for(j=i+1; j<K; j*=2, cnt++);
        ans += pow(N, -1) * pow(0.5, cnt);
    }
    printf("%.13f\n", ans);
}

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

int main() {
	string s;
	cin >> s;
	if (s == "MON") {
		cout << 6;
	}
	else if(s=="TUE"){
		cout << 5;
	}
	else if (s == "WED") {
		cout << 4;
	}
	else if (s == "THU") {
		cout << 3;
	}
	else if (s == "FRI") {
		cout << 2;
	}
	else if (s == "SAT") {
		cout << 1;
	}
	else if (s == "SUN") {
		cout << 7;
	}
	
}

Measured memory_bytes: 3520
a = input()
p = int(a[0:2])
q = int(a[2:4])
if p == 0:
    if q == 0 or q > 12:
        print("NA")
    else:
        print("YYMM")
elif q == 0:
    if p == 0 or p > 12:
        print("NA")
    else:
        print("MMYY")
else:
    if p > 12 and q > 12:
        print("NA")
    elif p <= 12 and q <= 12:
        print("AMBIGUOUS")
    elif p <= 12 and q > 12:
        print("MMYY")
    elif q <= 12 and p > 12:
        print("YYMM")

Measured memory_bytes: 3064
class UnionFind:
    """
    素集合データ構造: 要素を素集合（互いに重ならない集合）に分割して管理するデータ構造
        Union: 2つの集合を1つに併合する
        Find: ある要素がどの集合に属しているかを判定する
    """

    def __init__(self, n):
        self.n = n
        # 各要素の親要素の番号を格納するリスト
        # 要素が根（ルート）の場合は[-そのグループの要素数]を格納する
        self.parents = [-1] * n

    def find(self, x):
        """
        要素xが属するグループの根を返す
        """
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        """
        要素xが属するグループと要素yが属するグループとを併合する
        """
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

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

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

    def size(self, x):
        """
        要素xが属するグループのサイズ（要素数）を返す
        """
        return -self.parents[self.find(x)]

    def same(self, x, y):
        """
        要素x, yが同じグループに属するかどうかを返す
        """
        return self.find(x) == self.find(y)

    def members(self, x):
        """
        要素xが属するグループに属する要素をリストで返す
        """
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        """
        すべての根の要素をリストで返す
        """
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        """
        グループの数を返す
        """
        return len(self.roots())

    def all_group_members(self):
        """
        {ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す
        """
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        """
        print()での表示用
        """
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


n, m, k = map(int, input().split())

uf = UnionFind(n)
friend = [set() for _ in range(n)]
block = [set() for _ in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    friend[a].add(b)
    friend[b].add(a)
    uf.union(a, b)

for i in range(k):
    c, d = map(int, input().split())
    c -= 1
    d -= 1
    if uf.same(c,d):
        block[c].add(d)
        block[d].add(c)

for i in range(n):
    print(uf.size(i) - len(friend[i]) - len(block[i]) - 1, end=' ')


Measured memory_bytes: 130284
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;int stage[n+1][4],cost[n+1][4];
  for(int i=1;i<=n;i++)
  {
    cin>>stage[i][1]>>stage[i][2]>>stage[i][3];
  }
   for(int i=1;i<n;i++)
   for(int j=1;j<4;j++)
    cost[i][j]=-1;
  cost[n][1]=stage[n][1];
  cost[n][2]=stage[n][2];
  cost[n][3]=stage[n][3];
  for(int i=n-1;i>0;i--)
   {
       for(int j=1;j<4;j++)
        for(int k=1;k<4;k++)
         {
             if(j==k)
             continue;
             cost[i][j]=max(cost[i][j],stage[i][j]+cost[i+1][k]);
         }
   }int max=0;
   for(int i=1;i<4;i++)
     if(max<cost[1][i])
      max=cost[1][i];
      cout<<max<<endl;
}

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

#define pow(n) (n)*(n)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

using namespace std;

/* function */
//  - none - 


/* code */
int main (void) 
{

  /* Variable_Proclamation */
  int64_t a, b;    // input
  int64_t x;    // input
  int ans;  // output

  int i, j, k;    // subscript
  int64_t count;
  int comp; // comparison

  int64_t to_a, to_b;


  /* Input, Array_Proclamation */
  cin >> a >> b;
  cin >> x;


  /* Initialize */
  ans = 0;
  count = 0;



  /* Calculation */
  to_a = a/x;
  to_b = b/x;

  count = to_b - to_a;
  if(a%x == 0)
  {
    count += 1;
  }

  // for(i=a; i<=b; i++)
  // {
  //   if(i%x == 0)
  //   {
  //     count++;
  //   }
  // }
  

  /* Output */
  cout << count << endl;


  return 0;

}


/* entity */
//  - none -




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S,T;
  cin >> S >> T;
  
  long long len_S,len_T;

  len_S = S.length();
  len_T = T.length();
  
  long count_tmp = 0;
  long count = 0;

  for (long i = 0; i < len_S - len_T + 1; i++) {
    for (long j = 0; j < len_T; j++) {
        if(S[i+j] == T[j]){
           count += 1;
        }        
       }
    count_tmp = max(count_tmp,count);
    count = 0;
  }
      
cout << len_T - count_tmp <<endl; 

}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int t;
ll n,arr[10005],x,k,d;

int main()
{
    cin>>x>>k>>d;
    x=abs(x);
    ll e = x/d;
    if(e>k){
        cout<<x-(k*d)<<endl;
    }
    else{
        x%=d;
        k-=e;

        if(k%2!=0 && k!=0){
            ll a=abs(d+x);
            ll b=abs(x-d);
            cout<<min(a,b)<<endl;
        }
        else cout<<x<<endl;

    }
    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<utility>
#include<vector>

//nCrをMODで割ったあまりを返す
long long combination_mod(long long n, long long r, long long mod, long long f_max)
{
	//例外処理
	/*if (n < r || n < 0 || r < 0)
	{
		throw - 1;
	}*/

	//階乗をmodで割ったあまりを計算する
	static std::vector<long long>factorial_mod(f_max);
	if (factorial_mod[0] != 1)
	{
		factorial_mod[0] = 1;
		for (long long i = 1; i < f_max; i++)
		{
			factorial_mod[i] = factorial_mod[i - 1] * i % mod;
		}
	}

	long long numerator = factorial_mod[n];
	long long denominator = factorial_mod[r] * factorial_mod[n - r] % mod;//積はMODを超えているかもしれないからもう一回剰余算する

	/*
	nCr ＝ n!/(n-r)!/r!
		≡ (n! % p)*((n-r)! r! % p)^(p-2) (mod p) (但しpは素数)

	証明:

	*/

	//割り切れる場合は普通に返す
	if (numerator % denominator == 0)
	{
		return numerator / denominator;
	}
	//割り切れない時
	else
	{
		long long index = mod - 2, power = 1;
		while (index > 0)
		{
			if (index & 1)
			{
				power *= denominator;
				power %= mod;
			}
			denominator *= denominator;
			denominator %= mod;
			index >>= 1;
		}
		return numerator * power % mod;
	}
}

signed main()
{
	const long long mod = 998244353;
	const long long f_max = 333333;

	long long n, a, b, k;
	std::cin >> n >> a >> b >> k;
	std::vector<std::pair<long, long>>pairs;
	pairs.reserve(n);
	for (long long x = 0; x <= n; x++)
	{
		if ((k - a * x) % b == 0)
		{
			long long y = (k - a * x) / b;
			if (0 <= y && y <= n)
			{
				pairs.push_back(std::make_pair(x, y));
			}
		}
	}
	long long ans = 0;
	for (auto i : pairs)
	{
		ans += combination_mod(n, i.first, mod, f_max) * combination_mod(n, i.second, mod, f_max) % mod;
		ans %= mod;
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007
using vi=vector<int>;

vector<int> init_spf(int n){
    vector<int> spf(n+1);
    for (int i = 0; i < n+1; i++){
        spf[i]=i;
    }
    for (int i = 2; i*i<=n; i++){
        if(spf[i]==i){
            for (int j = i*i; j <= n; j+=i){
                if(spf[j]==j)spf[j]=i;
            }
        }
    }
    return spf;
}
void factorization(int x,const vector<int> &spf,map<int,int> &lcm_factors){
    int same_factor=0;
    int prev_factor=2;
    while (x!=1){
        if(prev_factor==spf[x])same_factor++;
        else same_factor=1;
        lcm_factors[spf[x]]=max(lcm_factors[spf[x]],same_factor);
        prev_factor=spf[x];
        x/=spf[x];
    }
}
ll mod_pow(ll x, ll p){
	ll res=1;
	ll n=x;
	while(p>0){
		if(p&1==1)res=(res*n)%MOD;
		n=(n*n)%MOD;
		p=(p>>1);
	}
	return res;
}

ll modinv(ll a, int b){// a/b mod MOD
    ll res=1;
    int n=MOD-2;
    ll x=b;
    while(n>0){
        if(n&1==1){
            res*=x;
            res%=MOD;
        }
        x*=x;
        x%=MOD;
        n>>=1;
    }
    res*=a;
    res%=MOD;
    return res;
}

int main(){
    int N; cin>>N;
    auto spf=init_spf(1000000);
    vi A(N);
    map<int,int> lcm_factors;
    for (int i = 0; i < N; i++){
        cin>>A[i];
        factorization(A[i],spf,lcm_factors);
    }
    ll lcm=1;
    for(auto P:lcm_factors){
        ll p=P.first;
        ll n=P.second;
        lcm*=mod_pow(p,n);
        lcm%=MOD;
    }
    ll ans=0;
    for (int i = 0; i < N; i++){
        ans+=modinv(lcm,A[i]);
        ans%=MOD;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 7640
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]

dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD = 1000000007
INF = float("inf")

sys.setrecursionlimit(1000000)

def main():

    S = input()
    if S[-1] == "s":
        print(S+"es")
    else:
        print(S+"s")

if __name__ == '__main__':
    main()

Measured memory_bytes: 72480
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

long long int INF = 1e18;
using namespace std;

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

long long int LCM(long long int a, long long int b){
	long long int dummy1, dummy2, dummy;
	dummy1 = max(a, b);
	dummy2 = min(a, b);
	while(true){
		dummy = dummy1 % dummy2;
		dummy1 = dummy2;
		dummy2 = dummy;
		if(dummy == 0){
			break;
		}
	}
	return (a / dummy1) * (b / dummy1) * dummy1;
}

long long int GCD(long long int a, long long int b){
	long long int dummy1, dummy2, dummy;
	dummy1 = max(a, b);
	dummy2 = min(a, b);
	while(true){
		dummy = dummy1 % dummy2;
		dummy1 = dummy2;
		dummy2 = dummy;
		if(dummy == 0){
			break;
		}
	}
	return dummy1;
}

int main(){
	
	long long int x, y;
	cin >> x >> y;
	
	cout << GCD(x, y) << endl;
	
	return 0;
}


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

int main(){
  int a,b,c,d,n,count = 0;
  
  while(scanf("%d",&n)!=EOF){
  
  for(a=0;a<10;a++){
    for(b=0;b<10;b++){
      for(c=0;c<10;c++){
	for(d=0;d<10;d++){
	  if((a+b+c+d)==n)count++;
	}
      }
    }
  }
  
  cout << count << endl;
  count =0;
  }
  return 0;
}

Measured memory_bytes: 1208
// AOJ
// ALDS1_11_A Graph
// https://onlinejudge.u-aizu.ac.jp/problems/ALDS1_11_A
#include <bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
#define rep(i, n) for(int i = 0; i < (n); i++)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_h(const vector<T>& c, int n=INT_MAX)
{ rep(i, min(n, (int)c.size())) cout << c[i] << (i==c.size()-1?"\n":" "); }

int main() {
    int n; cin >> n;
    vvi g(n, vi(n, 0));
    rep(i, n) {
        int u, k; cin >> u >> k; u--;
        rep(j, k) {
            int v; cin >> v; v--;
            g[u][v] = 1;
        }
    }

    rep(i, n) cout_h(g[i]);
}



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

int main(){
  int N;
  cin >> N;
  
  vector<pair<pair<string, int>, int>> res(N);
  for(int i = 0; i < N; i++){
    string city;int score;
    cin >> city >> score;
    score *= (-1);
    
    res.at(i) = make_pair(make_pair(city, score), i + 1);
  }
  
  sort(res.begin(), res.end());
  
  for(int i = 0; i < N; i++){
    cout << res.at(i).second << endl;
  }
}


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

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

  int ans;
  for (int i = 6; i >= 0; --i) {
    if ((N >> i) & 1) {
      ans = 1 << i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() 
{
    int N,W;
    cin>>N>>W;
    int wt[N+1],val[N+1];
    for(int i=0;i<N;i++)
    {
        cin>>wt[i]>>val[i];
    }
    long long  dp[N+1][W+1];
    for(int i=0;i<=N;i++)
    {
        for(int w=0;w<=W;w++)
        {
            if(i==0 || w==0)
                dp[i][w]=0;
            else if(wt[i-1]<=w) 
            {  
               dp[i][w]=val[i-1]+dp[i-1][w-wt[i-1]];
               dp[i][w]=max(dp[i][w],dp[i-1][w]);
            }
            else
              dp[i][w]=dp[i-1][w];   
        }
    }
    cout<<dp[N][W];
    return 0;

  
}


Measured memory_bytes: 79104
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <cmath>
#define PI 3.14159265358979
using namespace std;

int main(){
	double a,b,c;
	cin >> a >> b >> c;
	double rad = c * PI / 180.0;
	double s = a * b / 2 * sin(rad);
	double l = a + b + sqrt(a * a + b * b -2 * a * b * cos(rad));
	double h = 2 * s / a;
	printf("%lf\n",s);
	printf("%lf\n",l);
	printf("%lf\n",h);
	return 0;
}

Measured memory_bytes: 3628
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>

using namespace std;

typedef long long ll;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,q;
    char s[200010],t[200010],d[200010];
    cin>>n>>q;
    s[0]='_';
    for(int i=1;i<=n;i++) cin>>s[i];
    s[n+1]='_';
    for(int i=0;i<q;i++) cin>>t[i]>>d[i];
    
    int l=0,r=n+1;
    for(int i=q-1;i>=0;i--){
        if(t[i]==s[l]&&d[i]=='R') l--;
        else if(t[i]==s[l+1]&&d[i]=='L') l++;
        if(t[i]==s[r]&&d[i]=='L') r++;
        else if(t[i]==s[r-1]&&d[i]=='R') r--;
    }
    
    cout<<r-l-1<<endl;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  int n;
  cin>>n;
  vector<string> s(n);
  int BA[3];
  int len;
  int ans=0;
  BA[0]=BA[1]=BA[2]=0;
  
  REP(i,n){
    cin>>s[i];
    len = s[i].size();
    REP(j,len-1){
      if(s[i][j]=='A' && s[i][j+1]=='B'){
        ans++;
      }
    }
    if(s[i][0]=='B'){
      BA[0]++;
    }
    if(s[i][len-1]=='A'){
      BA[1]++;
    }
    if(s[i][0]=='B' && s[i][len-1]=='A'){
      BA[2]++;
    }
  }
  
  int a,b,c;
  b = BA[0]-BA[2];
  a = BA[1]-BA[2];
  c = BA[2];
  int d;
  if(a==0 && b==0){
    d = max(0,c-1);
  }else{
    d = min(a,b)+c;
  }
  ans += d;
  cout<<ans<<endl;
  return 0;
}


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

int main() {
    int64_t A, B, K;
    cin >> A >> B >> K;
    int64_t a_sub = min(A, K);
    A -= a_sub;
    K -= a_sub;
    cout << A << " " << max(B - K, (int64_t)0) << endl;
}

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

using namespace std;

int main() {
    int n, c, ans = 1e9;
    cin >> n >> c;
    vector< vector<int> > d(c + 1, vector<int>(c + 1)), v(3, vector<int>(c + 1));
    for (int i = 1; i <= c; ++i) for (int j = 1; j <= c; ++j) cin >> d.at(i).at(j);

    for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) {
        int temp;
        cin >> temp;
        ++v.at((i + j) % 3).at(temp);
    }

    vector<int> i(3);
    for (i.at(0) = 1; i.at(0) <= c; ++i.at(0)) {
        for (i.at(1) = 1; i.at(1) <= c; ++i.at(1)) {
            if (i.at(0) == i.at(1)) continue;
            for (i.at(2) = 1; i.at(2) <= c; ++i.at(2)) {
                if (i.at(0) == i.at(2) || i.at(1) == i.at(2)) continue;
                int num = 0;
                for (int j = 0; j < 3; ++j) for (int k = 1; k <= c; ++k) {
                    num += v.at(j).at(k) * d.at(k).at(i.at(j));
                }
                ans = min(ans, num);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
ll n,m,p,q,A[33],B[33],a,b,C[33];
int main(void){
    while(1){
        cin>>n>>m>>p>>q;
        //cout<<n<<" "<<m<<" "<<p<<" "<<q<<" "<<endl;
        if(n==0&&m==0&&p==0&&q==0){
            return 0;
        }
        for(int i=0;i<33;i++){
            A[i]=1,B[i]=1;
        }
        for(int i=0;i<p;i++){
            cin>>a>>b;
            //cout<<a<<b<<"W"<<p<<q<<endl;
            if(a==1){
                if(n-b<b){
                    b=min(b,n-b);
                    n-=b;
                    for(int j=0;j<b;j++){
                        A[b+j+1]+=A[b-j];
                    }
                    for(int j=0;j<n;j++){
                        C[j+1]=A[n+b-j];
                    }
                    for(int j=1;j<=n;j++){
                        A[j]=C[j];
                    }
                }
                else{
                    b=min(b,n-b);
                    n-=b;
                    for(int j=0;j<b;j++){
                        A[n-j]+=A[n+j+1];
                    }
                }
            }
            if(a==2){
                if(m-b<b){
                    b=min(b,m-b);
                    m-=b;
                    for(int j=0;j<b;j++){
                        B[b+j+1]+=B[b-j];
                    }
                    for(int j=0;j<m;j++){
                        C[j+1]=B[m+b-j];
                    }
                    for(int j=1;j<=m;j++){
                        B[j]=C[j];
                    }
                }
                else{
                    b=min(b,m-b);
                    m-=b;
                    for(int j=0;j<b;j++){
                        B[m-j]+=B[m+j+1];
                    }
                }
            }
        }/*
        if(p==3){
            for(int i=0;i<=n;i++)cout<<A[i];
            cout<<endl;
            for(int j=0;j<=m;j++)cout<<B[j];
            cout<<endl;
        }*/
        for(int i=0;i<q;i++){
            cin>>a>>b;
            cout<<A[n-a]*B[m-b]<<endl;
        }
    }
}



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

typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> ii;
#define ll long long

#define sz(a) int((a).size())
#define len(a) int((a).length())
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define newl '\n'

int main(){
  int n; cin >> n;
  int h[n]; for(int i=0;i<n;++i) cin >> h[i];

  int dp[n]; dp[0]=0; dp[1]=abs(h[1]-h[0]);

  for(int i=2;i<n;++i){
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
  }
  cout << dp[n-1] << newl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

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

    int h, w;
    cin >> h >> w;
    vector< string > field(h);
    rep (i, h) cin >> field[i];

    queue< pair<int, int> > q;
    vector< vs32 > d(h, vs32(w, 1e9));
    rep (i, h)
    {
        rep (j, w)
        {
            if (field[i][j] == '#')
            {
                q.push(pair<int, int>{i, j});
            }
        }
    }

    int ans = -1;
    int dy[] = {-1, 0, 1, 0};
    int dx[] = {0, -1, 0, 1};
    while (!q.empty())
    {
        ++ans;
        int s = q.size();
        rep (j, s)
        {
            pair<int, int> p = q.front(); q.pop();
            int y = p.first;
            int x = p.second;
            rep (i, 4)
            {
                int ny = y + dy[i];
                int nx = x + dx[i];
                if (IN(0, h, ny) && IN(0, w, nx) && field[ny][nx] != '#')
                {
                    q.push(pair<int, int>{ny, nx});
                    field[ny][nx] = '#';
                }
            }
        }
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 13456
function main(arg) {
	arg = arg.trim().split('\n');
	var t = arg[1],
        s = arg[0],
        mac = [],
        out = 0;
  	for (var i = 0; i < 3; i ++) {
    	mac.push(t[i] == s[i] ? true : false);
      	if (mac[i] === true) {
        	out++;
        }
    }
  console.log(out)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <iostream>
#include <algorithm>
#include <climits>

using namespace std;

int A[3][200];

int main(){
    int N;
    int x, y;
    int ans = INT_MIN;
    
    cin >> N;
    for(int i = 0; i < 2; i++){
        for(int j = 0; j < N; j++){
            cin >> A[i][j];
        }
    }
    
    for(int i = 0 ; i < N; i++){
        int sum = A[0][0];
        
        for(int j = 0; j < N - 1; j++){
            if(j >= i){
                sum += A[1][j];
            }
            else{
                sum += A[0][j + 1];
            }
        }
        sum += A[1][N - 1];
        
        ans = max(ans, sum);
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

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


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = INT32_MAX / 3;
const ll MOD = 1e9 + 7;

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


/******************************************************************************************/


int main() {

	int n;
	cin >> n;
	vector<int> a;
	a.push_back(0);

	ll sum = 0;

	for (int i = 0; i < n; i++)
	{
		int c;
		cin >> c;
		a.push_back(c);
	}

	a.push_back(0);

	n += 2;

	for (int i = 0; i <= n - 2; i++)
	{
		sum += abs(a[(i + 1) % n] - a[i]);
	}

	for (int i = 1; i <= n - 2; i++)
	{
		cout << sum - abs(a[(i + 1) % n] - a[i]) - abs(a[i] - a[(i + n - 1) % n]) + abs(a[(i + 1) % n] - a[(i + n - 1) % n]) << endl;
	}


	return 0;
}


Measured memory_bytes: 1784
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] D = new int[N];
		for (int i = 0; i < N - 1; ++i) {
			D[i + 1] = D[i] + sc.nextInt();
		}
		long ans = 0;
		int pos = 0;
		for (int i = 0; i < M; ++i) {
			int m = sc.nextInt();
			ans += D[m > 0 ? pos + m : pos] - D[m > 0 ? pos : pos + m];
			pos += m;
		}
		System.out.println(ans % 100000);
	}

}

Measured memory_bytes: 13000
#pragma GCC optimize("O2")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<limits.h>
#include<ctime>
#define N 100001
typedef long long ll;
const int inf=0x3fffffff;
const int maxn=2017;
using namespace std;
inline int read()
{
    int f=1,x=0;char ch=getchar();
    while(ch>'9'|ch<'0')
    {
        if(ch=='-')
        f=-1;
        ch=getchar();
    }
    while(ch<='9'&&ch>='0')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return f*x;
}
int sum=1,ans=0;
int a[N]; 
int main()
{
	int n=read();
	for(int i=1;i<=n;i++)
	{
		a[i]=read();
		if(a[i]%2==0)
		sum*=2;
	} 
	cout<<pow((double)3,n)-sum; 
}

Measured memory_bytes: 256
#include<stdio.h>

void swap(int *a,int *b)
{
	int c;
	c=*a;
	*a=*b;
	*b=c;
}

int main()
{
	int num[5];
	int i,j;
	scanf("%d %d %d %d %d",&num[0],&num[1],&num[2],&num[3],&num[4]);
	for(i=0;i<4;i++)
	{
		for(j=i+1;j>0;j--)
		{
			if(num[j]>num[j-1]){swap(num+j,num+j-1);}
		}
	}
	for(i=0;i<5;i++)
	{
		printf("%d",num[i]);
		if(i<4){putchar(' ');}
	}
	putchar('\n');
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main(){
    int a,b;
    0 <= a <= 100;
    2 <= b <= 1000;

    scanf("%d %d", &a, &b);
    if(!(b % 2 == 0)){
        return 0;
    }

    if(13 <= a){
        printf("%d", b);
    }else if(6 <= a){
        b = b / 2;
        printf("%d", b);        
    }else{
        b = 0 % b;
        printf("%d", b);
    }
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

int main() {
    int a, b;
    cin >> a >> b;
    if (a > 2 * b) {
        cout << a - 2 * b << endl;
    } else {
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int K,A,B,i;
    cin>>K>>A>>B;
    for(i=A;i<=B;i++)
    {
        if(i%K==0)
        {
            cout<<"OK";
            return 0;
        }

    }
    cout<<"NG";
    return 0;
}


Measured memory_bytes: 3580
#include <stdio.h>
#include <iostream>
#include <cassert>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <deque>

#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define irep(i,a,b) for(int i=(a);i>=(b);i--)
#define debug(x) do { cerr << #x << ": " << x << endl; } while(0)

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

ll total = 0;

void dfs(string & s, int pos, ll acc, ll num, int N) {
  // debug(num);
  // debug(pos);
  if (pos >= N) {
    acc += num;
    total += acc;
  } else {
    // append
    ll nn = num*10 + (s[pos]-'0');
    dfs(s, pos+1, acc, nn, N);

    // stop here add +  if only num > 0 
    if (num > 0) {
      // debug(pos);
      acc += num;
      dfs(s, pos+1, acc, s[pos]-'0', N);
    }
  }

}


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


  string S;
  cin >> S;

  dfs(S, 0, 0, 0, S.size() );

  cout << total << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int a[20];
int k[20];

int main()
{
int i;
int m,p;
int j;
int c;
c=0;

for(i=1;i<=10;i++)
{
scanf("%d", &a[i]);
}
m=a[1];
p=a[1];
for(i=2;i<=10;i++)
{
if(m>=a[i]) m=a[i];
if(p<=a[i]) p=a[i];
}
for(i=p;i>=m;i--)
{
for(j=1;j<=10;j++)
{
if(i==a[j])
{
k[c]=i;
c++;
}
}

}
for(i=0;i<=2;i++)
printf("%d\n", k[i]);
return 0;
}

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

const int Nmax=200010;

int main() {
	char s[100];
	int N;
	cin >> N;
	for(int i=0;i < N;i++){
		cin >> s[i];
	}
	map<char, int> mp;
	int cnt=0,mac=0;
	for(int k=1;k < N-1;k++){//区切るところ
		map<char, int> mp;
    	cnt=0;
		for(int i=0;i < k;i++){
			for(int j = k;j < N;j++){
				if(mp[s[i]] != -1){
					if(s[i]==s[j]){
						cnt++;
						mp[s[i]] = -1;
					}
				}
			}

		}
      	mac = max(mac,cnt);
    }
		cout << mac << endl;
	return 0;
}

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

int n, p;
string s;

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

  if (p == 2 || p == 5)
  {
    long long int ans = 0;
    for (int i = 0; i < n; i++)
    {
      if ((s[i] - '0') % p == 0)
      {
        ans += i + 1;
      }
    }
    cout << ans << endl;
  }
  else
  {
    // u[i]: s[n-i-1]~s[n-1]を繋いでできるintをpで割った余り
    vector<int> u(n);
    u[0] = (s[n - 1] - '0') % p;
    int x = 10 % p;
    for (int i = 1; i < n; i++)
    {
      u[i] = (u[i - 1] + (s[n - i - 1] - '0') * x) % p;
      x = x * 10 % p;
    }

    // v[i]: u[0]~u[n-1]のうち、pで割った余りがiであるものの個数
    vector<long long int> v(p, 0);
    for (int i = 0; i < n; i++)
    {
      v[u[i]]++;
    }

    // cout << "---u---" << endl;
    // for (int i = 0; i < n; i++)
    // {
    //   cout << u[i] << endl;
    // }

    // cout << "---v---" << endl;
    // for (int i = 0; i < p; i++)
    // {
    //   cout << v[i] << endl;
    // }

    long long int ans = 0;
    ans += v[0];
    for (int i = 0; i < p; i++)
    {
      ans += v[i] * (v[i] - 1) / 2;
    }

    cout << ans << endl;
  }
}


Measured memory_bytes: 1412
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i,n) for(ll i=0;i<(int)(n);i++)
#define REP(i,m,n) for(ll i=m;i<(int)(n);i++)
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; }
typedef long long ll;
typedef pair<ll,ll> pint;
const long long INF = 1LL<<60;
const ll MOD = 1000000007;
ll gcd(ll a,ll b){
    if(b==0){
        return a;
    }
    else{
        return gcd(b,a%b);
    }
}
const int MAX_V = 100000;
int n;
vector<ll> d(MAX_V);
vector<ll> dl(MAX_V);
struct edge {int to,cost;};
vector<edge> G[MAX_V];
typedef pair<int,int> P;
void dijkstra(int s){
    priority_queue<P,vector<P>,greater<P>> que;
    fill(d.begin(),d.end(),INF);
    d[s]=0;
    que.push(P(0,s));
    while(! que.empty()){
        P p = que.top();que.pop();
        int v = p.second;
        if(d[v]<p.first) continue;
        for (int i =0;i<G[v].size();i++){
            edge e = G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
                dl[e.to]=v;
            }
        }
    }
}
int main(){
    ll m;cin>>n>>m;
    rep(i,m){
        int a,b;cin>>a>>b;
        edge e1;
        e1.to =b-1;
        e1.cost=1;
        edge e2;
        e2.to = a-1;
        e2.cost = 1;
        G[a-1].push_back(e1);
        G[b-1].push_back(e2);
    }
    dijkstra(0);
  cout<<"Yes"<<endl;
    REP(i,1,n){
        cout<<dl[i]+1<<endl;
    }
}


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

int n,m;
int a[11];
int ans;
vector<tuple<int,int,int,int>> sco;

void dfs(int i,int pv)
{
    if(i==n)
    {
        int tmp=0;
        for(auto [l,r,c,d]:sco)
        {
            if(a[r]-a[l]==c) tmp+=d;
        }
        if(tmp>ans) ans=tmp;
        return;
    }
    for(int j=pv; j<m; ++j)
    {
        a[i]=j;
        dfs(i+1,j);
    }
}

main()
{
    cin>>n>>m;
    int Q; cin>>Q;
    sco.resize(Q);
    for(int i=0; i<Q; ++i)
    {
        int a,b,c,d; cin>>a>>b>>c>>d; --a; --b;
        sco[i]=tie(a,b,c,d);
    }
    dfs(0,0);
    cout << ans << "\n";
}

Measured memory_bytes: 3580
#include <iostream>
using namespace std;
int main(){
	bool a[30]={0};
	int temp;
	for(int i=0;i<28;i++){
		cin >> temp ;
		a[temp-1]=true;
	};
	for(int i=0;i<30;i++){
		if(a[i]==false) cout << i+1 << '\n' ;
	};
}

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

int main(){
	int p1, p2, p3, j1, j2;
	cin >> p1 >> p2 >> p3 >> j1 >> j2;
	int ans = min( p1 , min(p2,p3) ) + min(j1,j2) - 50;
	cout << ans << endl;
}

Measured memory_bytes: 0
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define pi pair<int,int> 
#define pii pair<pi,int>
#define ull unsigned long long
#define vi vector<int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll fastexp(ll x,ll a){
    ll res = 1;
    while(a>0){
        if(a&1){
            res = (res*x)%mod;
        }
        a=a>>1;
        x=(x*x)%mod;
    }
    return res;
}
ll inverse(ll n){
    return fastexp(n,mod-2);
}
template <typename T>
void add(T &a, T b){
	a += b;
	if(a >= mod)a -= mod;
}
template <typename T>
void sub(T &a, T b){
	a -= b;
	if(a < 0)a += mod;
}
template <typename T>
void mul(T &a, T b){
	a *= b;
	if(a >= mod)a %= mod;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n,m;
	cin>>n>>m;
	vi h(n+1);
	vi v[n+1];
	rep(i,n){
		cin>>h[i+1];
	}	
	rep(i,m){
		int x,y;
		cin>>x>>y;
		v[x].pb(y);
		v[y].pb(x);
	}
	int c = 0;
	repa(i,1,n+1){
		int f = 1;
		for(auto x:v[i]){
			if(h[x] >= h[i]){
				f = 0;
			}
		}
		if(f){
			c++;
		}
	}
	cout<<c;
	return 0;
}

Measured memory_bytes: 8780
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int foo(string& s, string& t) {
	int S = s.length(), T = t.length();
	for (int l = min(S, T); l >= 0; l--)
		if (s.substr(S - l) == t.substr(0, l))
			return T - l;
}

bool bar(string& s, string& t) {
	int S = s.length(), T = t.length();
	for (int i = 0; i + T <= S; i++)
		if (s.substr(i, T) == t)
			return true;
	return false;
}

int main() {
	for (;;) {
		int n; cin >> n;
		if (n == 0) break;
		vector<string> s(n);
		for (int i = 0; i < n; i++)
			cin >> s[i];
		vector<bool> b(n, true);
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				if (j != i && b[j] && bar(s[j], s[i]))
					b[i] = false;
		vector<string> _s;
		for (int i = 0; i < n; i++)
			if (b[i])
				_s.push_back(s[i]);
		s = _s;
		n = s.size();
		vector< vector<int> > a(n, vector<int>(n));
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				a[i][j] = foo(s[i], s[j]);
		vector< vector<int> > dp(1 << n, vector<int>(n, INT_MAX));
		for (int S = 1; S < (1 << n); S++)
			for (int i = 0; i < n; i++) {
				if (S & (1 << i)); else continue;
				int T = S - (1 << i);
				if (T == 0) {
					dp[S][i] = s[i].length();
					continue;
				}
				for (int j = 0; j < n; j++) {
					if (T & (1 << j)); else continue;
					dp[S][i] = min(dp[S][i], dp[T][j] + a[j][i]);
				}
			}
		int mini = INT_MAX;
		for (int i = 0; i < n; i++)
			mini = min(mini, dp[(1 << n) - 1][i]);
		cout << mini << endl;
	}
}

Measured memory_bytes: 2584
#include<bits/stdc++.h>
using namespace std;
stack<char>m;
string a;
int main()
{
    cin>>a;
    int n=a.size();
    for (int i=0;i<n;i++)
      m.push(a[i]);
    bool j=1;
    for(int i=0;i<n;i++)
	{
        char top=m.top();
        if (top=='b')
		  top='d';
        else if (top=='d')
		  top='b';
        else if (top=='p')
		  top='q';
        else if (top=='q')
		  top='p';
        if (top==a[i])
		{
            j=1;
            m.pop();
        }
        else
		{
            j=0;
            break;
        }
    }
    if(j==0)
      cout<<"No"<<endl;
    else
      cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define st first
#define nd second

using ll = long long ;
using namespace std;
using pii = pair<int,int>;
const int mod = 1e9 + 7;
int  add(ll a, ll b){
	a += b;
	a %= mod;
	if(a < 0) a += mod;
	return a;
}
int main(){
	int n, k;
	scanf("%d %d", &n, &k);
	int ans = 0;
	ll ma = 0, mi = 0;
	for(int i = 0; i < k - 1; i++){
		mi += i, ma += n - i ;
	}
	for(int i =k - 1; i<= n; i++){
		mi += i, ma += n - i ;
		ans = add(1LL * ans, add(ma+ 1, -mi));
	}
	printf("%d", ans);
	


}

Measured memory_bytes: 3840
import sys
# from math import sqrt, gcd, ceil, log
# from bisect import bisect
from collections import defaultdict, Counter
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))

# sys.setrecursionlimit(10**6)



def solve():
	n = int(input()); arr = read()
	cum = arr[0]
	for i in arr[1:]:cum ^= i
	for i in range(n):arr[i] = arr[i]^cum
	print(*arr)

		

if __name__ == "__main__":
	solve()

Measured memory_bytes: 31752
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  string S;
  cin >> S;

  if (S == "zyxwvutsrqponmlkjihgfedcba") {
    cout << -1 << '\n';
    return 0;
  }

  map<char, int> m;
  for (char c : S) {
    m[c]++;
  }

  for (char c = 'a'; c <= 'z'; c++) {
    if (m[c] == 0) {
      cout << S << c << endl;
      return 0;
    }
  }

  string T = S;
  next_permutation(all(T));

  rep(i, len(S)) {
    cout << T[i];
    if (S[i] != T[i]) {
      cout << '\n';
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <stdio.h>
typedef long long ll;

ll abs(ll a) {
  return a > 0 ? a : -a;
}

int main(void) {
  ll i, n, ans = 1e9;
  scanf("%lld", &n);
  ll w[n], sum[n];
  for(i = 0; i < n; ++i) scanf("%lld", &w[i]);
  sum[0] = w[0];
  for(i = 1; i < n; ++i) sum[i] = sum[i - 1] + w[i];
  for(i = 1; i < n; ++i)
    if(abs(2 * sum[i - 1] - sum[n - 1]) < ans) 
      ans = abs(2 * sum[i - 1] - sum[n - 1]);
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 256