akhauriyash/Code-Regression huggingface dataset:
#C
import math
A, B = list(map(int, input().split()))
ans1min = A/0.08
ans1max = (A+1)/0.08
ans2min = B/0.1
ans2max = (B+1)/0.1

#print(ans1min)
#print(ans2min)
if ans1min >= ans2min and ans1min < ans2max:
    print(math.ceil(ans1min))
elif ans1min <= ans2min and ans2min < ans1max:
    print(math.ceil(ans2min))
else:
    print('-1')


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

int main() {
  int n,m;
  cin >> n >> m;
  vector<int> h = vector<int>(n);
  for(int i=0; i<n; i++){
    cin >> h[i];
  }
  
  vector<bool> ab = vector<bool>(n,true);
  int a,b;
  for(int i=0; i<m; i++){
    cin >> a >> b;
    if(h[a-1] > h[b-1]) ab[b-1] = false;
    else if(h[a-1] < h[b-1]) ab[a-1] = false;
    else{
      ab[a-1] =false;
      ab[b-1] = false;
    }
  }
  int ans = 0;
  for(int i=0; i<n; i++){
    if(ab[i]) ans++;
  }
  cout << ans << endl;
}
  

Measured memory_bytes: 3788
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)






int main() {
    ll n;
    cin >> n;
    vector<ll> h(n);
    REP(i, n){
        cin >> h[i];
    }
    vector<ll> dp(n, INF);
    dp[0] = 0;
    REP(i, n - 1){
        if(i < n - 2){
            dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
            dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
        }
        else{
            dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
        }
    }
    cout << dp[n - 1] << endl;
}


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

using namespace std;

using ll =  long long int;

#define int  long long int
#define mod  1000000007

ll mod_pow(ll a,ll b,ll m)
{
    ll res = 1;
    while(b)
    {
        if(b&1)
        {
            res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n;
    
    cin >> n;
    
    vector<pair<int,int>> a(n);
    
    int m1 = 0;
    int m2 = 1e10;
    int m3 = -1e10;
    int m4 = 1e10;
    
    for(int i = 0; i < n; ++i) {
    	cin >> a[i].first >> a[i].second;
    	
    	int x = a[i].first;
    	int y = a[i].second;
    	
    	m1 = max(m1 , x+y);
    	m2 = min(m2 , x+y);
    	m3 = max(m3 , x-y);
    	m4 = min(m4 , x-y);
    }
    
    cout << max({abs(m1 - m2) , abs(m3 - m4)});
    
  
    return 0;
}


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

using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };

#define ARRAY_MAX 100005

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;



//約数の列挙
vector<ll> divisor(ll n) {
	vector<ll> res;
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			res.push_back(i);
			if (i != n / i) {
				res.push_back(n / i);
			}
		}
	}
	return res;
}

int main() {


	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	for (int i = 1; i <= 1e5; i++)
	{
		vector<ll> vec = divisor(i);
		if (vec.size() == n)
		{
			cout << i << endl;
			return 0;
		}
		vec.shrink_to_fit();
	}

	return 0;
}


Measured memory_bytes: 3204
#include<iostream>
#include<cstdio>
#include<vector>
#include<set>
#include<algorithm>
#include<unordered_map>
#include<queue>
#include<map>
using namespace std;

int N, M;
typedef pair<int, int> vert;
struct pair_hash{
    size_t operator() (const pair<int, int> &p) const{
        return p.first ^ p.second;
    }
};


int main(){
    cin >> N >> M;
    int p, q, c;
    map<vert, vector<pair<vert, int> >> edges;
    map<vert, int> d;
    for(int i = 1; i <= N; i++){
        d[make_pair(i, -1)] = 100000000;
    }
    for(int m = 0; m < M; m++){
        scanf("%d %d %d", &p, &q, &c);
        edges[make_pair(p, c)].push_back(make_pair(make_pair(q, c), 0));
        edges[make_pair(q, c)].push_back(make_pair(make_pair(p, c), 0));
        edges[make_pair(p, -1)].push_back(make_pair(make_pair(p, c), 1));
        edges[make_pair(q, -1)].push_back(make_pair(make_pair(q, c), 1));
        edges[make_pair(p, c)].push_back(make_pair(make_pair(p, -1), 0));
        edges[make_pair(q, c)].push_back(make_pair(make_pair(q, -1), 0));
        d[make_pair(p, c)] = d[make_pair(q, c)] = 100000000;
    }

    priority_queue<pair<int, vert> > PQ;
    map<vert, bool> visited;
    d[make_pair(1, -1)] = 0;
    PQ.push(make_pair(0 * (-1), make_pair(1, -1)));

    while(!PQ.empty()){
        pair<int, vert> now_data = PQ.top(); PQ.pop();
        vert now = now_data.second;
        visited[now] = true;

        if(d[now] < now_data.first * (-1)){
            continue;
        }

        for(vector<pair<vert, int> >::iterator itr = edges[now].begin(); itr != edges[now].end(); itr++){
            vert next = (*itr).first;
            if(visited[next]){
                continue;
            }
            if(d[next] > d[now] + (*itr).second){
                d[next] = d[now] + (*itr).second;
                PQ.push(make_pair(d[next]*(-1), next));
            }
            
        }
    }

    int ans = d[make_pair(N, -1)];
    if(ans == 100000000){
        cout << "-1" << endl;
    }else{
        cout << ans << endl;
    }
}

Measured memory_bytes: 122932
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string n;
  cin>>n;
  
  int nlen=n.size();
  int nsum=0;
  for(int i=0; i<nlen; i++){
    int ni=n.at(i)-'0';
    nsum += ni;
  }
  
  if(nsum%9==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3712
s = input()
if len(s)==1:
  print(1)
  exit()
ans = len(s)
tori = float("inf")
for i in range(1,len(s)):
  a = s[i]
  b = s[i-1]
  if a != b:
    tori = max(i,len(s)-i)
  ans = min(tori,ans)
print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>



using namespace std;


static const int N = 100;

int main(){
    

    int n,p[N+1],m[N+1][N+1];
    cin >> n;
    for (int i=1;i<=n;i++){
        cin >> p[i-1] >> p[i];
    }
    for (int i=1;i<=n;i++){
        m[i][i] = 0;
    }
    for (int l = 2;l<=n;l++){
        for (int i = 1;i<=n-l+1;i++){
            int j = i+l-1;
            m[i][j] = (1<<21);
            for (int k= i;k<j;k++){
                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;
}


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

int main(){
	long long n,m;
	cin>>n>>m;
	long long a[m],b[m],c[n];
	for(long long i=0;i<m;i++) cin>>a[i]>>b[i];
	for(long long i=0;i<n;i++) c[i]=0;
	for(long long i=0;i<m;i++){
		if(a[i]==1) c[b[i]-1]+=1;
		if(b[i]==n) c[a[i]-1]+=1;
	}
	sort(c,c+m);
	cout<<((c[m-1]==2)?"POSSIBLE":"IMPOSSIBLE");
	return 0;
}


Measured memory_bytes: 4992
// Vicfred
// https://atcoder.jp/contests/abc168/tasks/abc168_c
#include <ios>
#include <iostream>
#include <cmath>
#include <math.h>
#include <iomanip>

using namespace std;

int main() {
    cout << fixed << showpoint;
    cout << setprecision(23);

    long double a, b, h, m;

    cin >> a >> b >> h >> m;

    long double x = M_PI/6;
    long double y = M_PI/30;
    long double z = x/60;
    long double C = abs(x*h + z*m - y*m);

    cout << sqrt(a*a+b*b-2.0L*a*b*cos(C)) << endl;

    return 0;
}



Measured memory_bytes: 4088
#!/usr/bin/env python3

import sys
# import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    n, m = mi()
    a = lmi()
    total = sum(a)
    num = len(list(filter(lambda x: x >= total / (4 * m), a)))
    print('Yes') if m <= num else print('No')

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
# AOJ 0519: Worst Reporter
# Python3 2018.6.20 bal4u

# トポロジーソート V:総ノード数, to[][]:隣接リスト
def topological_sort(V, to):
	cnt = [0]*V
	for i in range(V):
		for j in to[i]: cnt[j] += 1
	Q = []
	for i in range(V):
	   if cnt[i] == 0: Q.append(i)
	f = 0
	while len(Q) > 0:
		f |= len(Q) > 1
		i = Q[0]
		del Q[0]
		print(i+1)  # ノードの表示
		for k in to[i]:
			cnt[k] -= 1
			if cnt[k] == 0:	Q.append(k)
	return f	

n = int(input())
to = [[] for i in range(n)]
m = int(input())
for i in range(m):
	a, b = list(map(int, input().split()))
	to[a-1].append(b-1)
print(1 if topological_sort(n, to) else 0)



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

int main()
{
    int N, K;
    cin >> N >> K;
    int res = 0;
    int x;
    for (int i = 0; i < N; i++)
    {
        cin >> x;
        res += min(x, (K - x)) * 2;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <ctype.h>
#include <algorithm>
#include <cmath>
#include <vector>

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define square(x) (x) * (x)

const int INF = 1e9;

using namespace std;

int main() {
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;
    if(x - r < 0 || x + r > w || y - r < 0 || y + r > h)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("No");}else{puts("Yes");}
#define MAX_N 200005

int main() {
    string s;
    cin >> s;
    if(s == "AAA" || s == "BBB")yn;
    return 0;
}
 
 


Measured memory_bytes: 256
import cmath


r, c, n = map(int, input().split())
lis = []


for i in range(n):
    x1, y1, x2, y2 = map(int, input().split())
    if (0 < x1 < r and 0 < y1 < c) or (0 < x2 < r and 0 < y2 < c):
        continue
    else:
        lis.append((i, x1 - r / 2 + (y1 - c / 2) * 1j))
        lis.append((i, x2 - r / 2 + (y2 - c / 2) * 1j))


lis.sort(key=lambda x: cmath.phase(x[1]))
stack = []


for i in lis:
    if stack == [] or stack[-1] != i[0]:
        stack.append(i[0])
    else:
        stack.pop()

        
if stack == []:
    print("YES")
else:
    print("NO")

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

using namespace std;

using int64 = long long;

int Max(const vector<int>& xs) {
  int value = INT32_MIN;
  for (int x : xs) value = max(x, value);
  return value;
}

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

  int n;
  cin >> n;
  vector<vector<int>> value_table(n, vector<int>(3));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> value_table[i][j];
    }
  }

  vector<vector<int>> dp(n, vector<int>(3));
  for (int j = 0; j < 3; j++) dp[0][j] = value_table[0][j];

  for (int i = 1; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      for (int pj = 0; pj < 3; pj++) {
        if (pj == j) continue;
        dp[i][j] = max(dp[i][j], dp[i - 1][pj] + value_table[i][j]);
      }
    }
  }

  int ans = Max(dp[n - 1]);
  cout << ans << endl;
}


Measured memory_bytes: 11264
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	int n;
	cin >> n;
	int d[100];
	for(int i = 0; i < n; i++){
		cin >> d[i];
	}
	long long int ans = 0;
	for(int i = 0; i < n; i++){
		for(int j = i + 1; j < n; j++){
			ans += d[i] * d[j];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
X = list(map(int, input().split()))
X.sort()
p_min = X[0]
p_max = X[-1]
ans = float('inf')
for p in range(p_min, p_max+1):
    now = 0
    for i in range(N):
        now += (X[i] - p) ** 2
    ans = min(ans, now)
print(ans)

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

signed main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
	
  	int3(a, b, c);
  	cout << (a + b) * c / 2 << endl;
  
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

int main(){
  int n,a,b; cin >> n >> a >> b;
  vector<ll> x(n);
  rep(i,n) cin >> x[i];
  
  ll cost = 0;
  for(ll i = 1; i<n;i++){
    if((x[i] - x[i-1])*a > b) cost += b;
    else cost += (x[i] - x[i-1])*a;
  }
  
  cout << cost << endl;
  
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
    string a,b;
    char c[1001],d[1001];
    gets(c);
    gets(d);
    a=c;
    b=d;
    for(int i=0;i<a.size()-1;i++)
        for(int j=i+1;j<a.size();j++)
            if(a[i]>a[j])
                swap(a[i],a[j]);
    for(int i=0;i<b.size()-1;i++)
        for(int j=i+1;j<b.size();j++)
            if(b[i]<b[j])
                swap(b[i],b[j]);
    if(a<b)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include<bits/stdc++.h>
#define lli long long int
int main(){
  lli n,sum=0,x;
  cin>>n;
  vector<lli>p(n+1);
  for(lli i=1;i<=n;i++){
    cin>>p[i];
    if(p[i]-1==sum)
      sum++;
  }
  //lli k=-1;
  //cout<<(sum>0)?(sum):k;
  if(sum>0)
    cout<<n-sum;
  else
    cout<<"-1";
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main() {
  int q;
  int c, a, n;
  
  cin >> q;
  while(q--) {
	int ans = 0;
	cin >> c >> a >> n;
	
	for(;c > 0;) {
	  if(n > 0 && a > 0) ans ++, n--, a--, c--;
	  else if(a > 0 && c > 1)	ans ++, a--, c-=2;
	  else if(c > 2) c-=3, ans++;
	  else c = 0;
	}
	cout << ans << endl;
  }
  
  return 0;
}

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

struct UnionFind{
    vector<int> par;

    UnionFind(int n): par(n){
        for(int i=0; i<n; i++){
            par[i] = i;
        }
    }

    int root(int x){
        if(par[x] == x) return x;
        else return par[x] = root(par[x]);
    }

    void unite(int x, int y){
        int rx = root(x), ry = root(y);
        if(rx != ry) par[ry] = rx;
    }

    bool same(int x, int y){
        return root(x) == root(y);
    }
};

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int n, q;
    cin >> n >> q;
    UnionFind uf(n);

    vector<int> ans;
    for(int i=0; i<q; i++){
        int c, x, y;
        cin >> c >> x >> y;
        if(c == 0) uf.unite(x,y);
        else ans.push_back(uf.same(x, y));
    }

    for(auto v: ans){
        cout << v << endl;
    }

    return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
#define DATA 3

int main(){
    int a, b, c;
    int i, n;
    int data[DATA];
    int tmp=0;


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

    data[0] = a;
    data[1] = b;
    data[2] = c;

    for(i=0; i<DATA; i++){
      for(n=i+1; n<DATA; n++){
        if(data[i] > data[n]){
            tmp = data[i];
            data[i] = data[n];
            data[n] = tmp;
        }
      }
    }

    printf("%d %d %d\n", data[0], data[1], data[2]);
    return 0;
}



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

int main(){
int N;
cin >> N;
int a[N];
for(int i = 0; i < N; i++){
cin >> a[i];
}

int min= a[0]; 
int max= a[0];
long long sum= a[0];

for(int i = 1; i < N; i++){
 sum += a[i];
 if(a[i] < min) min = a[i];
 if(a[i] > max) max = a[i];
}

cout << min << " " << max << " " << sum << endl;
}


Measured memory_bytes: 3092
#include <iostream>
#include <string>
#include <map>

int main()
{
  int N;
  std::cin>>N;
  
  std::map<std::string,int> t;
  for(int i=0;i!=N;i++)
  {
    std::string S;
    std::cin>>S;
    t[S]++;
  }
  
  std::cout<<"AC x "<<t["AC"]<<"\n"
    <<"WA x "<<t["WA"]<<"\n"
    <<"TLE x "<<t["TLE"]<<"\n"
    <<"RE x "<<t["RE"]<<std::endl;
  
  return 0;
}

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

def main():

    A, B, C, K = map(int, input().split())

    ans = 0

    if K <= A:
        ans = K

    else:
        if K <= A + B:
            ans = A

        else:
            ans = A + (-1 * (K - A - B))

    print(ans)


if __name__ == "__main__":
    main()

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

typedef long long ll;

const ll MOD = 10007;

int c (char s) {
    if (s == 'J') return 1;
    if (s == 'O') return 2;
    return 4;
}

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

    vector<vector<ll> > dp(n + 1, vector<ll>(1 << 3, 0));

    for (int i = 0; i < 1 << 3; i++) {
        if ((i & (1 | c(str[0]))) == (1 | c(str[0]))) {
            dp[0][i] = 1;
        }
    }

    for (int i = 1; i < n; i++) {
        int now = c(str[i]);
        for (int j = 1; j < 1 << 3; j++) {
            for (int k = 1; k < 1 << 3; k++) {
                if (dp[i-1][j] && (j & k) && (k & now)) {
                    dp[i][k] += dp[i-1][j];
                    dp[i][k] %= MOD;
                }
            }
        }
    }

    ll res = 0;
    for (int i = 1; i < 1 << 3; i++) {
        res = (res + dp[n-1][i]) % MOD;
    }

    cout << res << endl;
}

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

using namespace std;
#define sqr(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))
#define GCD(a, b) __gcd(a, b)
#define LCM(a, b) ((a)*(b)/GCD(a,b))
#define MP make_pair
#define n1 first
#define n2 second
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define SI set<int>
#define SL set<ll>
#define MS multiset
#define MSI multiset<int>
#define MSLL multiset<ll>
#define PB push_back
#define PF push_front
#define VI vector<int>
#define VPI vector<pair<int,int>>
#define VLL vector<ll>
#define SZ(x) ((int)x.size())

typedef long long ll;

typedef unsigned long long ull;
typedef long double ld;
typedef double db;
const int INF = 1e9;
const int MOD = 1000000007;
const int N = 202055;
const int M = 1211;

void solve() {
    int a,b;
    cin >> a >> b;

    set <int> s;
    s.insert(a);
    s.insert(b);

    for (int i = 1; i <= 3; i++){
        if (!s.count(i)) cout << i;
    }

}

int main() {
    ios_base::sync_with_stdio(false);
#ifdef dxz05
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else

#endif

    int T = 1;
    //cin >> T;

    while (T--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 256
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
#define min(x,y) (x < y ? x : y)
#define max(x,y) (x < y ? y : x)
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << "(" << p.first << ", " << p.second << ")"; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

void solve() {
  ll n; cin >> n;
  vector<double> p(n); cin >> p;
  vector<vector<double>> dp(n+1, vector<double>(n+1, 0));
  dp[0][0] = 1;
  rep(i, n) rep(j, n+1) {
    dp[i+1][j+1] += dp[i][j] * p[i];
    dp[i+1][j] += dp[i][j] * (1-p[i]);
  }
  double ans = 0;
  rep(f, n+1) {
    ll b = n - f;
    if (f > b) {
      ans += dp[n][f];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 72448
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;const int N=2*1e5+10;
int w[N];int d[N];int cnt[20];int res;int n;int st;bool book[N];int sxr[N]; 
int main()
{
    scanf("%d",&n);
    for(int i=1,u,v,va;i<n;i++){scanf("%d%d%d",&u,&v,&va);w[u]^=va;w[v]^=va;}
    for(int i=0;i<n;i++){cnt[w[i]]++;}
    for(int i=1;i<=15;i++)res+=cnt[i]/2,st|=(cnt[i]&1)<<(i-1);	
    for(int i=1;i<(1<<15);i++)d[i]=d[i>>1]+(i&1);
    for(int i=1;i<(1<<15);i++)d[i]-=1;
    for(int i=1;i<(1<<15);i++)
        for(int j=0;j<15;j++)if((i>>j)&1)sxr[i]^=(j+1);
    for(int i=1;i<(1<<15);i++) 
    {
        if(sxr[i]!=0)continue;
        for(int k=(i-1)&i;k;k=(k-1)&i)
            if(sxr[k]==0)d[i]=min(d[i],d[k]+d[i^k]);
    }printf("%d",res+d[st]);return 0;
}

Measured memory_bytes: 2376
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
        int totalCaseCount = inpt[0];
        int caseMCount = inpt[1];

        long mul = (long)Math.Pow(2, caseMCount);
        long ans = mul * (1900 * caseMCount + (totalCaseCount - caseMCount) * 100);
        Console.WriteLine(ans);

    }

    public class Reader
    {
        private static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"





100 5




";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}


Measured memory_bytes: 13396
#include<iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
int n;
string str="abcdefghijklmnopqrstuvwxyz";
string S[55],ans="";
int al[55][30]={};
int main(){
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>S[i];
		for(int j=0;j<S[i].size();++j){
			al[i][S[i][j]-'a']++;
		}
	}
	for(int i=0;i<26;++i){
		int k=10000;
		for(int j=0;j<n;++j){
			k=min(al[j][i],k);
		}
		for(int j=0;j<k;++j){
			ans+=str[i];
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val l = readLine()!!.map(Char::toString).map(String::toInt)

    fun Char.toSign(): String {
        return if (this == '1') {
            "+"
        } else {
            "-"
        }
    }
    for (b in (0..7).map { Integer.toBinaryString(it) }.map { it.padStart(3, '0') }) {
        var sum = l[0]
        if (b[2] == '1') {
            sum += l[1]
        } else {
            sum -= l[1]
        }

        if (b[1] == '1') {
            sum += l[2]
        } else {
            sum -= l[2]
        }
        if (b[0] == '1') {
            sum += l[3]
        } else {
            sum -= l[3]
        }

        if (sum == 7) {
            println("${l[0]}${b[2].toSign()}${l[1]}${b[1].toSign()}${l[2]}${b[0].toSign()}${l[3]}=7")
            return
        }
    }
}



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

typedef long long ll;
typedef unsigned long long int ull;
#define endl "\n"
#define pb push_back
#define sq(a) (a)*(a)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugv(v) cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;
#define MOD 1000000007
#define PI 3.141592653589793238
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll exp(ll x,ll n,ll mod)
{
    ll result=1;
    while(n)
    {
        if(n & 1)
            result=(result * x)%mod;
        x=(x*x)%mod;
        n=n>>1;
    }
    return result;
}



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

    int n,m,k;
    cin>>n>>m>>k;
    ll a[n+1],b[m+1];
    ll sa[n+1],sb[m+1];
    sa[0]=sb[0]=0;
    a[0]=b[0]=0;

    for(int i=1;i<=n;i++)
    {
    	cin>>a[i];
    	sa[i]=sa[i-1]+a[i];
    }

    for(int i=1;i<=m;i++)
    {
    	cin>>b[i];
    	sb[i]=sb[i-1]+b[i];
    }

    
    
    int ans=0;

    // int l=0,r=0;
    // while((l<n)||(r<m))
    // {
    // 	ll temp=min(a[l],b[r]);

    // 	if(a[l]>b[r])
    // 		r++;
    // 	else
    // 		l++;
    // 	if((tot+temp)<=k)
    // 	{
    // 		ans++;
    // 		tot+=temp;
    // 	}
    // 	else
    // 		break;
    // }

    // for(int i=0;i<=min(k,n);i++)
    // {
    // 	tot+=a[i];
    // 	ll temp=tot,curr=i;

    // 	for(int j=1;j<=min(k-i,m);j++)
    // 	{
    // 		if((temp+b[j])<=k)
    // 		{
    // 			temp+=b[j];
    // 			curr++;
    // 		}
    // 		else
    // 			break;
    // 	}

    // 	if(temp<=k)
    // 		ans=max(ans,curr);
    // }

    int r=0;
    for(int i=n;i>=0;i--)
    {
   		while((r<=m)&&(sa[i]+sb[r]<=k))
   			r++;
   		
   		if(r)
   			r--;

   		if(sa[i]+sb[r]<=k)
   			ans=max(ans,i+r);
    }

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

Measured memory_bytes: 9796
import copy

def check(s, t, k):
	for i in range(len(t)):
		if s[i+k] != t[i] and s[i+k] != '?':
			return False
	return True

def construct(s, t, k):
	ans = copy.deepcopy(s)
	for i in range(len(t)):
		ans[i+k] = t[i]
	for i in range(len(s)):
		if ans[i] == '?':
			ans[i] = 'a'
	return "".join(ans)

def resolve():
	s = list(input())
	t = list(input())
	ans = []
	if len(s) < len(t):
		print('UNRESTORABLE')
		return
	for i in range(len(s) - len(t) + 1):
		if check(s, t, i):
			ans.append(construct(s, t, i))
	if len(ans) >= 1:
		print(min(ans))
	else:
		print('UNRESTORABLE')
resolve()

Measured memory_bytes: 40816
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
typedef long long ll;
////////////////////////////////////////////////////////////

int main(){
	int tmp;
	while( cin >> tmp ){
		int a[4],b[4];
		a[0] = tmp;
		rep(i,1,4) cin >> a[i];
		rep(i,0,4) cin >> b[i];
		map<int,bool> mp;
		rep(i,0,4) mp[a[i]] = 1;
		
		int h=0,br=0;
		rep(i,0,4){
			if( a[i] == b[i] ) h++;
			else if(mp[b[i]]) br++;
		}

		cout << h << " "<< br << endl;
	}
	ret 0;
}


Measured memory_bytes: 3056
n=int(input())
A=[]
for i in range(n):
    A.append(list(input().split()))

ans=0
for i in range(n):
    if A[i][1]=="BTC" :
        ans+=380000*float(A[i][0])
    else :
        ans+=float(A[i][0])

print(ans)


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


int main()
{
	int n;
	cin >> n;
	int h[n];
	for (int i = 0; i < n; i++)
		cin >> h[i];
	int ans[n];
	ans[0] = 0;
	ans[1] = abs(h[1]-h[0]);
	for (int i = 2; i < n; i++) {
		ans[i] = min(ans[i-1] + abs(h[i]-h[i-1]), ans[i-2] + abs(h[i]-h[i-2]));
	}
	cout << ans[n-1];
}






Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb push_back
#define mp make_pair
#define nt _ll128
#define ld long double
long double PI =3.14159265358979323846;
using ll = long long;



const ll modo=1e9+7;
const ll inf=1e17;
const ll ms=(1e5)+5;


ll ar[ms];
ll br[ms];

ll peil(int a,int b)
{
    if(0>=a)return 0;
    if(a%2)return a/2+1;
    return a/2;
}

int main()
{
    idfc;

   ll a=0;
   int i;
   int n;
   cin>>n;

   for(i=1;i<=n;i++)cin>>ar[i];
   for(i=1;i<=n;i++)cin>>br[i];


   ll p;
   for(i=1;i<=n;i++)
   {
       p=peil(br[i]-ar[i],2);
       ar[i]+=(p*2);
       a+=p;
   }
   //cout<<a<<"\n";
   for(i=1;i<=n;i++)
   {
      // cout<<ar[i]<<" "<<br[i]<<"\n";
       p=ar[i]-br[i];
       if(a>=p)
       {
           a-=p;
       }
       else {
           cout<<"No";return 0;
       }
   }
   cout<<"Yes";


    return 0;
}

Measured memory_bytes: 3816
import java.awt.geom.*;
import java.io.*;
import java.math.*;
import java.text.*; 
import java.util.*;
import java.util.regex.*;

/*
			  br = new BufferedReader(new FileReader("input.txt"));
			  pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
			  br = new BufferedReader(new InputStreamReader(System.in));
			  pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
 */

public class Main {
	private static BufferedReader br;
	private static StringTokenizer st;
	private static PrintWriter pw;

	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		//int qq = 1;
		int qq = Integer.MAX_VALUE;
		//int qq = readInt();
		for(int casenum = 1; casenum <= qq; casenum++) {
			int n = readInt();
			int m = readInt();
			int[] x = new int[n];
			int[] y = new int[n];
			for(int i = 0; i < n; i++) {
				x[i] = readInt();
				y[i] = readInt();
			}
			int[] xx = new int[m];
			int[] yy = new int[m];
			for(int i = 0; i < m; i++) {
				xx[i] = readInt();
				yy[i] = readInt();
			}
			for(int i = 0; i < n; i++) {
				int best = 0;
				for(int a = 1; a < m; a++) {
					int bestDist = Math.abs(x[i] - xx[best]) + Math.abs(y[i] - yy[best]);
					int aDist = Math.abs(x[i] - xx[a]) + Math.abs(y[i] - yy[a]);
					if(aDist < bestDist) {
						best = a;
					}
				}
				pw.println(best+1);
			}
		}
		exitImmediately();
	}

	private static void exitImmediately() {
		pw.close();
		System.exit(0);
	}

	private static long readLong() throws IOException {
		return Long.parseLong(readToken());
	}

	private static double readDouble() throws IOException {
		return Double.parseDouble(readToken());
	}

	private static int readInt() throws IOException {
		return Integer.parseInt(readToken());
	}

	private static String readLine() throws IOException  {
		String s = br.readLine();
		if(s == null) {
			exitImmediately();
		}
		st = null;
		return s;
	}

	private static String readToken() throws IOException  {
		while(st == null || !st.hasMoreTokens())  {
			st = new StringTokenizer(readLine().trim());
		}
		return st.nextToken();
	}
}

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

int main(){
  int N;
  cin >> N;
  vector<int>A(N);
  int ans=0;
  int count=0;
  for(int i=0;i<N;i++){
    cin >> A[i];
    if(i==0){
      ans++;
      count=A[i];
      continue;
    }
    count=min(count,A[i]);
    if(count==A[i]){
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3992
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>
#include <functional>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long long llong;
typedef long double ld;

using namespace std;

#ifndef LOCAL
#define cerr _cer
struct _cert
{
    template <typename T> _cert& operator << (T) { return *this; }
};
_cert _cer;
#endif

template <typename T> void dprint(T begin, T end) {
    for (auto i = begin; i != end; i++) {
        cerr << (*i) << " ";
    }
    cerr << "\n";
}

int main() {
    int n;
    ll t;
    cin >> n >> t;
    ll ans = 0;
    ll lst = -t;
    for (int i = 0; i < n; ++i) {
        ll nw;
        cin >> nw;
        ans += min(t, nw - lst);
        lst = nw;
    }
    cout << ans << "\n";
    return 0;
}




Measured memory_bytes: 256
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));
  $l = explode(" ", trim(fgets(STDIN)));

  //$l = range(1, 2000);

  $ans = 0;

  //echo count($l);
  rsort($l);

  for ($i=0; $i<$n-2; $i++) {
    for ($j=$i+1; $j<$n-1; $j++) {
      $p = $l[$i] - $l[$j];
      // 全件NG
      if($l[$j+1] <= $p){
        continue;
      }
      // 全件OK
      if($l[$n-1] > $p){
        $ans += $n-$j-1;
        continue;
      }
      // 探索
      $a = $j+1;
      $b = $n-1;
      while(($b-$a) > 1){
        $x = intdiv($b-$a, 2)+$a;
        if($l[$x] <= $p) $b = $x;
        else $a = $x;
      }
      $ans += $a-$j;
    }
  }
echo $ans;

Measured memory_bytes: 4604
N, Q = [int(i) for i in input().split()]
S = input()
t = [0] * (N + 1)

for i in range(N):
  t[i + 1] = t[i] + (1 if S[i:i + 2] == 'AC' else 0)

for i in range(Q):
  l, r = map(int, input().split())
  print(t[r-1] - t[l-1])

Measured memory_bytes: 9412
#include <stdio.h>
#define WHITE  0
#define GRAY   1
#define BLACK  2
#define NIL   -1
#define N    150

typedef struct{
  int id;
  int k;
  int v[N];
}DATA;

void bfs(int,int,int);
void enqueue(int);
int dequeue(void);
  
int count=0;
int d[N],color[N],G[N][N],Q[N];
DATA data[N];

int main() {

  int i,j,n;
  
  scanf("%d",&n);
  for(i = 1; i <= n; i++) {
    scanf("%d%d",&data[i].id,&data[i].k);
    if(data[i].k == 0 ) data[i].v[1] = 0;
    
    for(j = 1; j <= data[i].k; j++) {
      scanf("%d",&data[i].v[j]);
      if(data[i].v[j] == data[i].v[data[i].k]) data[i].v[(data[i].k)+1] = NIL;
    }
  }
  
  for(i = 1; i <= n; i++) {
    for(j = 1; j <= n; j++) {
      G[i][data[i].v[j]] = 1;   
    }
  }

  bfs(1,data[1].id,n);

  for(i = 1; i <= n; i++) {
    printf("%d %d\n",data[i].id,d[i]);
  }

  return 0;
}

void bfs(int s,int u,int V)
{
  int i,x;
  for(i = u; i <= V; i++) {
    color[i] = WHITE;
    d[i] = NIL;
  }
  color[s] = GRAY;
  d[s] = 0;
  enqueue(s);
  
  while(count != 0) {
    x = dequeue();
    for(i = u; i <= V; i++) {
      if(G[x][i] == 1 && color[i] == WHITE) {
	color[i] = GRAY;
	d[i] = d[x]+1;
	enqueue(i);

      }
    }
    color[x] = BLACK;
  }
}

void enqueue(int a)
{
  Q[count] = a;
  count++;
}

int dequeue(void)
{
  int head,i;
  head = Q[0];
  for(i = 0; i < count; i++) {
    Q[i] = Q[i+1];
  }
  count--;
  return head;
}



Measured memory_bytes: 2028
#include<stdio.h>

int main ()
{
   int n,a,b,tr;
   scanf("%d %d %d",&n,&a,&b);
   tr=n*a;

   if(tr<b){
    printf("%d",tr);
   }
   if(tr>b){
    printf("%d",b);
   }
   if(tr==b)
   {
       printf("%d",tr);
   }


    return 0;
}

Measured memory_bytes: 128
def main():
    h, _ = map(int, input().split())
    coord = [''] * (h * 2 + 1)
    for y in range(1, h + 1):
        coord[y] = input()

    for y in range(h, 0, -1):
        coord[y * 2] = coord[y]
        coord[y * 2 - 1] = coord[y]

    for row in coord[1:]:
        print(row)


if __name__ == '__main__':
    main()


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

typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int n; cin >> n;
    vector<int> s(n); cin >> s;
    int q; cin >> q;
    vector<int> t(q); cin >> t;
    sort(all(t));
    
    int ans = 0;

    rep(i, q) {
        int l, r, c;
        l = 0, r = n;
        while (l != r) {
            c = l + (r - l)/2;
            if (s[c] == t[i]) {
                ans++;
                break;
            } else if (s[c] < t[i]) {
                l = c+1;
            } else {
                r = c;
            }
        }
    }

    cout << ans << endl;
}



Measured memory_bytes: 3340
#include <iostream>
#include <cmath>
// #include <algorithm>
using namespace std;

int main(){
    int a, b,c;
    cin >>  a >> b >> c;
    int k; cin >> k;
    int MAX = max(a,b);
    MAX = max(MAX,c);
    
    cout << a+b+c+ MAX * (pow(2, k)-1) << endl;
}

Measured memory_bytes: 512
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
long long a,b,c,k;
long long d,e,f;
int main()
{
	cin>>a>>b>>c>>k;
	if (k&1)
	{
		printf("%lld\n",b-a);
	}
	else
	{
		printf("%lld\n",a-b);
	}
    return 0;
}

Measured memory_bytes: 256
aa = input().strip().split()
n = int(aa[0])
k = int(aa[1])
x = [int(s) for s in input().strip().split()]
r = -1

for i in range(n - k + 1):
    if 0 <= x[i] and (r == -1 or x[i + k - 1] < r):
        r = x[i + k - 1]

    if x[i] < 0 and (r == -1 or x[i + k - 1] - 2 * x[i] < r):
        r = x[i + k - 1] - 2 * x[i]

    if 0 <= x[i + k - 1] and (r == -1 or 2 * x[i + k - 1] - x[i] < r):
        r = 2 * x[i + k - 1] - x[i]

    if x[i + k - 1] < 0 and (r == -1 or -x[i] < r):
        r = - x[i]

print(r)


Measured memory_bytes: 14252
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> v1(1, 0), v2(n + 1, 0);
    for (int i = 0; i < n; i++) {
        int t;
        cin >> t;
        v1.push_back(t);
    }
    for (int i = 0; i < k; i++) {
        vector<int> c1(n + 1, 0), c2(n + 1, 0);
        for (int j = 1; j <= n; j++) {
            c1[max(1, j - v1[j])]++;
            c2[min(n, j + v1[j])]++;
        }
        bool flag = true;
        int c = 0;
        v2 = vector<int>(n + 1, 0);
        for (int j = 1; j <= n; j++) {
            c += c1[j];
            v2[j] = c;
            c -= c2[j];
            if (v2[j] != n) flag = false;
        }
        v1 = v2;
        if (flag) break;
    }
    for (int i = 1; i <= n; i++) {
        cout << v1[i] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 7200
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N; cin>>N;
  vector<long long>A(N-1,0), B(N-1,0), C(N,0);
  long long a=1, z=1e9+7;
  for(int i=1; i<N; i++){
    a*=i, a%=z, A[i-1]=a;
  }
  a=1;
  for(int i=N-1; i>0; i--){
    a*=i, a%=z, B[(N-1)-i]=a;
  }
  for(int i=0; i<N; i++){
    cin>>a;
    C[i]=a;
  }
  long long ans=0;
  for(int i=0; i<N-1; i++){
    if(i==0) ans+=((C[N-1]-C[i])*B[N-3-i])%z, ans%=z;
    else if(i==N-2) ans+=((C[N-1]-C[i])*A[i-1])%z, ans%=z;
    else ans+=((C[N-1]-C[i])*((A[i-1]*B[N-3-i])%z))%z, ans%=z;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
using namespace std;
int main()
{
  int N, K;
  cin >> N >> K;
  vector<int> x(N);
  for (int i = 0; i < N; i++)
    cin >> x[i];
  int ans = 0;
  for (int i = 0; i < N; i++)
  {
    ans += 2 * min(x[i], K - x[i]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
S = input()
chars = []
for i in range(len(S)):
    chars.append(S[i])
if chars.count(chars[0]) == 2:
    for i in range(len(S)):
        if chars.count(chars[i]) != 2:
            print("No")
            break
    else:
        print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
// #define STOPIT
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

void debug_impl() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
    #define debug(...)\
    do {\
        cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        cerr << std::noboolalpha;\
    } while (false)
#else
    #define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr>
istream& operator>> (istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr >
ostream& operator<< (ostream& os, Container const& v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}
int main()
{
    int n;
    string s;
    cin >> n >> s;
    vector<int> colors(n);
    rep(i, 0, n)
    {
        if (s[i] == 'R')
            colors[i] = 0;
        else if (s[i] == 'G')
            colors[i] = 1;
        else if (s[i] == 'B')
            colors[i] = 2;
    }

    vector<vector<int>> kcsum(3, vector<int>(n+1, 0));
    rep(i, 0, n)
    {
        kcsum[0][i+1] = kcsum[0][i];
        kcsum[1][i+1] = kcsum[1][i];
        kcsum[2][i+1] = kcsum[2][i];
        ++kcsum[colors[i]][i+1];
    }

    ll cnt = 0;
    rep(i, 0, n-2)
        rep(j, i+1, n-1)
        if (colors[i]!=colors[j])
        {
            int tgt;
            rep(c, 0, 3)
            {
                if (colors[i]!=c and colors[j]!=c)
                {
                    tgt = c;
                    break;
                }
            }

            cnt += kcsum[tgt][n]-kcsum[tgt][j+1];

            // invalid
            int pos = 2*j-i;
            if (pos<n and colors[pos] == tgt)
                --cnt;
        }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    char x;
    cin >> x;
    if(x == 'A') cout << "T" << endl;
    if(x == 'C') cout << "G" << endl;
    if(x == 'G') cout << "C" << endl;
    if(x == 'T') cout << "A" << endl;

    return 0;
}

Measured memory_bytes: 3688