akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0); 
	int N; cin >> N; 
	string S[1000010] = {}; 
	for(int i = 0; i < N; i++) cin >> S[i]; 
	vector<pair<int, int>> type1, type2, type3, type4; 
	for(int i = 0; i < N; i++){
		int sum = 0; int mn = 0;
		for(int j = 0; j < S[i].size(); j++){
			if(S[i].at(j) == '(') sum ++; 
			else sum --; 
			mn = min(sum, mn); 
		}
		if(mn == 0) type1.emplace_back(make_pair(mn, sum)); 
		else if(sum >= 0) type2.emplace_back(make_pair(mn, sum)); 
		else if(mn < sum) type3.emplace_back(make_pair(mn, sum)); 
		else type4.emplace_back(make_pair(mn, sum)); 
	}
	sort(type2.begin(), type2.end()); 
	reverse(type2.begin(), type2.end()); 
	sort(type3.begin(), type3.end()); 
	int now = 0; 
	bool ok = true; 
	for(auto p : type1) now += p.second; 
	for(auto p : type2){
		if(now + p.first < 0) ok = false;  
		now += p.second; 
	}
	for(auto p : type3){
		if(now + p.first < 0) ok = false;  
		now += p.second; 
	}
	for(auto p : type4){
		now += p.second; 
	}
	if(now != 0) ok = false; 
	cout << (ok ? "Yes" : "No") << endl; 
}

Measured memory_bytes: 42484
S = input()
C = len(S)
M = S.replace("A","")
A = "AKIHABARA"
B = A.replace("A","")
P = 0

for i in range (C-1):
	if S[i] == "A":
		if S[i+1] == "A":
			P=100
	if S[i] == "K":
		if S[i+1] != "I":
			P=200
	if S[i] == "I":
		if S[i+1] != "H":
			P=200
if B==M and P<=4:
	print("YES")
else:
	print("NO")

Measured memory_bytes: 3064
gets;a=[1,1];$<.each{|s| b=s.split.map(&:to_i); c=b.zip(a).map{|v|(v[1]/v[0])+(v[1]%v[0]>0?1:0)}.max; a=b.map{|v|c*v};};p a[0]+a[1]

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

using namespace std;

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

    vector<int> dest(N+1, 0);
    for(int i=1; i<N+1; i++)cin >> dest.at(i);

    vector<int> l(0);
    int now=1;
    l.push_back(now);
    int loop_start=0;
    bool isKmin = false;
    vector<bool> isVisit(200001, false);
    
    while(true){
        if(K < l.size()){
            isKmin = true;
            break;
        }
        now = dest.at(now);

        if(isVisit.at(now)){
            auto f = find(l.begin(), l.end(), now);
            loop_start = f - l.begin();
            break;
        }
        isVisit.at(now) = true;
        l.push_back(now);
    }
    // cout << "list : ";
    // for(int ele : l)cout << ele << " ";
    // cout << endl;

    int index = (K-l.size()) % (l.size()-loop_start) + loop_start;
    // cout << "K-size: " << K-l.size() << "\tsize - ls: " << l.size()-loop_start << endl;
    if(isKmin)cout << l.at(K);
    else cout << l.at(index);
}

Measured memory_bytes: 5044
#include <stdio.h>
#include <iostream>
#include <queue>
#include <cstdio>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string.h>
#include <limits.h>
#include <map>
#include <string>
#include <bitset>
#include <vector>
using namespace std;
int main() {
    double r;
    cin>>r;
    cout<<2*r*3.1415926<<endl;
    return 0;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001


bool check(string str) {
    if (str == "ABC") return true;

    string s = "";
    set<char> st;
    rep(i, str.size()) {
        if (i < str.size() - 2 && str.substr(i, 3) == "ABC") {
            s += "X";
            i += 2;
        } else {
            s += str[i];
            st.insert(str[i]);
        }
    }
    if (st.size() != 2) return false;
    rep(i, 3) {
        if (st.count((char)('A' + i))) continue;
        rep(j, s.size()) if (s[j] == 'X') s[j] = (char)('A' + i);
    }
    return check(s);
}

int main(){
    cin.sync_with_stdio(false);
    string s;
    cin >> s;

    bool ok = false;
    if (s.size() % 2) {
        ok = check(s);
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 22056
from collections import defaultdict as dict

s = input()
n = len(s)
p = 2019
a = []
for x in s:
    a.append(int(x))

x = 0
mem = dict(int)
mem[0] = 1
ans = 0
a.reverse()
d = 1
for y in a:
    x += d * y
    x %= p
    d = (d * 10) % p
    ans += mem[x]
    mem[x] += 1

print(ans)

Measured memory_bytes: 75540
#include <stdio.h>
int INF = 1 << 20;

int min(int x, int y) { if (x < y) return x; else return y; }

int dp[21][50001];
int main() {
	int n, m;
	int deno[20];
	scanf("%d %d\n", &n, &m);
	for (int i = 0; i < m; i ++) {
		scanf("%d", &deno[i]);
	}
	dp[0][0] = 0;
	for (int k = 1; k <= n; k ++) {
		dp[0][k] = INF;
	}
	for (int i = 1; i <= m; i ++) {
		int d = deno[i - 1];
		for (int k = 0; k <= n; k ++) {
			if (k - d >= 0) {
				dp[i][k] = min(dp[i - 1][k], dp[i][k - d] + 1);
			} else {
				dp[i][k] = dp[i - 1][k];
			}
		}
	}
	printf("%d\n", dp[m][n]);
	return 0;
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

pll S[100005];

int main()
{
    ll N, M;
    cin >> N >> M;
    REP(i, N)
    {
        cin >> S[i].first >> S[i].second;
    }
    sort(S, S + N, [](pll a, pll b) { return a.first < b.first; });

    ll sum = 0;
    REP(i, N)
    {
        if (M <= 0)
            break;
        sum += std::min(S[i].second, M) * S[i].first;
        M -= S[i].second;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF=(ll)1e9;
const ll MOD=(ll)1e9+7;
const ll MAX=510000;
vector<int> dx={1,0,-1,0,1,-1,1,-1},dy={0,1,0,-1,1,-1,-1,1};
template<class T> inline bool chmax(T& a, T b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
    ll H,W,ans;
    cin>>H>>W;
    if(H%3==0||W%3==0){
        cout<<"0"<<endl;
        return 0;
    }
    ans=min(H,W);
    for(ll i=1;i<H;i++){
        ll a,b,c,M,m;
        a=W/2*i;
        b=(W-W/2)*i;
        c=W*(H-i);
        M=max(a,max(b,c));
        m=min(a,min(b,c));
        ans=min(ans,M-m);
    }
    for(ll i=1;i<W;i++){
        ll a,b,c,M,m;
        a=H/2*i;
        b=(H-H/2)*i;
        c=H*(W-i);
        M=max(a,max(b,c));
        m=min(a,min(b,c));
        ans=min(ans,M-m);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
/* KUPC
 * team : pokaikoDrkenPrime
 * written by MMNMM(pokaiko)
 */

#include<bits/stdc++.h>

int main(){
    using namespace std;
    string S;
    cin >> S;
    constexpr unsigned long seed_f = 1215, seed_s = 259, seed_t = 1333333333, sz = 100, bt = 30;
    const auto& ruiseki_string = [](string& s) -> string {
        string t(s.begin(), s.end());
        partial_sum(t.begin(), t.end(), s.begin(), [](char a, char b){return '0' ^ a ^ b;});
        return s;
    };
    if(S == "Alice"){
        vector<string> a(sz);
        string s;
        for(auto& i : a){
            cin >> i;
            shuffle(i.begin(), i.end(), mt19937{seed_f});
            ruiseki_string(i);
            shuffle(i.begin(), i.end(), mt19937{seed_s});
            ruiseki_string(i);
            shuffle(i.begin(), i.end(), mt19937{seed_t});
            s += string{i.cbegin(), i.cbegin() + bt};
        }
        cout << s << endl;
    }
    if(S == "Bob"){
        vector<string> b(sz);
        string s;
        for(auto& i : b){
            cin >> i;
            shuffle(i.begin(), i.end(), mt19937{seed_f});
            ruiseki_string(i);
            shuffle(i.begin(), i.end(), mt19937{seed_s});
            ruiseki_string(i);
            shuffle(i.begin(), i.end(), mt19937{seed_t});
            s += string{i.cbegin(), i.cbegin() + bt};
        }
        cout << s << endl;
    }
    if(S == "Charlie"){
        string X, Y;
        cin >> X >> Y;
        vector<string> c(sz);
        for(auto& i : c){
            cin >> i;
            shuffle(i.begin(), i.end(), mt19937{seed_f});
            ruiseki_string(i);
            shuffle(i.begin(), i.end(), mt19937{seed_s});
            ruiseki_string(i);
            shuffle(i.begin(), i.end(), mt19937{seed_t});
            string tmp{i.begin(), i.begin() + bt};
            i = tmp;
        }
        vector<string> a(sz), b(sz);
        for(unsigned long i{0}; i < sz; ++i)a[i] = string{X.begin() + i * bt, X.begin() + (i + 1) * bt};
        for(unsigned long i{0}; i < sz; ++i)b[i] = string{Y.begin() + i * bt, Y.begin() + (i + 1) * bt};
        for(const auto& i : c){
            bitset<bt> C{i};
            [&]{for(unsigned long j{0}; j < sz; ++j){
                bitset<bt> A{a[j]};
                for(unsigned long k{0}; k < sz; ++k){
                    bitset<bt> B{b[k]};
                    if((A ^ B) == C){
                        cout << j + 1 << " " << k + 1 << endl;
                        return;
                    }
                }
            }}();
        }
    }
    return 0;
}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, k, p[N], ps[N], good[N], lnk[N];
set<int> st;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> k;
	for (int i = 0; i < n; i++) cin >> p[i];
	ps[0] = 0;
	for (int i = 1; i < n; i++) ps[i] = ps[i - 1] + (p[i] > p[i - 1] ? 1 : 0);
	int ans = 0;
	for (int i = 0; i < n - k + 1; i++) {
		if (ps[i + k - 1] - ps[i] == k - 1) good[i] = 1, ans = 1;
		else good[i] = 0;
	}
	for (int i = 0; i < k - 1; i++) st.insert(p[i]);
	for (int i = 0; i < n - k; i++) {
		st.erase(p[i]);
		st.insert(p[i + k - 1]);
		if (!good[i] && !good[i + 1] && *st.begin() > p[i] && *st.rbegin() < p[i + k]) lnk[i] = 1;
	}
	for (int i = 0; i < n - k + 1; i++) if (!good[i]) {
		int j = i;
		while (j < n - k && !good[j + 1] && lnk[j]) j++;
		ans++;
		i = j;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11264
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,x = inpl()
a = inpl()
a.sort()
for i in range(n):
    if a[i] <= x:
        x -= a[i]
    else:
        print(i)
        break
else:
    if x == 0:
        print(n)
    else:
        print(n-1)

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n;
	cin>>n;
	set<int> st;
	for(int i = 0; i < n; i++){
		int x; cin>>x;
		if(st.find(x) != st.end()){
			st.erase(x);
		}else{
			st.insert(x);
		}
	}
	cout<<st.size()<<endl;


	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin>>S;
  for(int i=0;i<(S.size()-1)/2;i++){
    if(S[i]!=S[(S.size()-1)/2-i-1]){
      cout<<"No"<<endl;
      return 0;
    }
  }
  for(int i=(S.size()+3)/2-1;i<S.size();i++){
    if(S[i]!=S[S.size()-i-1]){
      cout<<"No"<<endl;
      return 0;
    }
  }
  string a=S.substr(0,(S.size()-1)/2);
  string b=S.substr((S.size()+3)/2-1,S.size()-1);
  if(a==b){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)
n = int(input())
result = num2alpha(n)
print(result.lower())

Measured memory_bytes: 9152
#include<bits/stdc++.h>
#define cs const
using namespace std;
cs int N = 1e6 + 50;
cs int Mod = 998244353;
int add(int a, int b){ return a + b >= Mod ? a + b - Mod : a + b; }
int mul(int a, int b){ return 1ll * a * b % Mod; }
int dec(int a, int b){ return a - b < 0 ? a - b + Mod : a - b; }
void Add(int &a, int b){ a = add(a,b); }
void Mul(int &a, int b){ a = mul(a,b); }
void Dec(int &a, int b){ a = dec(a,b); }
int ksm(int a, int b){ int as=1; for(;b;b>>=1,Mul(a,a)) if(b&1) Mul(as,a); return as; }
int n, k, fc[N], ifc[N];
int C(int n, int m){ if(n<0||m<0||n<m) return 0; return mul(fc[n],mul(ifc[n-m],ifc[m])); }
void fc_init(int n){
	fc[0]=fc[1]=ifc[0]=ifc[1]=1;
	for(int i=2; i<=n; i++) fc[i]=mul(fc[i-1],i);
	ifc[n]=ksm(fc[n],Mod-2);
	for(int i=n-1; i>=2; i--) ifc[i]=mul(ifc[i+1],i+1);
}
int main(){
	#ifdef FSYolanda
	freopen("1.in","r",stdin);
	#endif
	scanf("%d%d",&n,&k);
	fc_init(k); int as = 0;
	for(int i=n,j; i<=k; i++){
		j=k-i; if(i<j) continue;
		int t=i-n+1; Add(as,dec(C(k-(i==j),i),C(k-(i==j),i+t)));
	} cout<<as; return 0;
}

Measured memory_bytes: 6272
#include <iostream>
#include <string>
using namespace std;
int main(void){
	string a;
	cin >> a;
	if(a[0] == a[1] && a[1] == a[2]){
		cout << "Yes" << endl;
		return 0;
	}
	else if(a[1] == a[2] && a[2] == a[3]){
		cout << "Yes" << endl;
		return 0;
	}
	else{
		cout << "No" << endl;
		return 0;
	}
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  long long int N,D;
  cin >> N >>D;
  long long int X[N];
  long long int Y[N];
  long long int count=0;
  for(int i=0; i<N; i++){
    cin>> X[i] >> Y[i];
  }
  for(int i=0;i<N; i++){
    if(X[i]*X[i]+Y[i]*Y[i] <= D*D){
      count++;
    }
  }
  cout<< count << endl;
}

Measured memory_bytes: 6708
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int h = sc.nextInt();
    int m = sc.nextInt();
    sc.close();

    double hd = (60 * h + m) * 0.5;
    double md = m * 6;

    double r = 0.000000000;
    if(hd < md) {
      r = md - hd;
      if(r > 180) {
        r = 360 - r;
      }
      double ans = Math.sqrt(a * a + b * b - 2 * a * b * Math.cos(r * Math.PI/180));
      System.out.println(ans);
    }else if(hd > md) {
      r = hd - md;
      if(r > 180) {
        r = 360 - r;
      }
      double ans = Math.sqrt(a * a + b * b - 2 * a * b * Math.cos(r * Math.PI/180));
      System.out.println(ans);
    }else {
      System.out.println(Math.abs(a-b));
    }
  }

}


Measured memory_bytes: 35884
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(ll i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (ll i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};

vector<int> to[200005];

int main(){
    ll n;
    cin >> n;
    ll ans = 0;
    rep(i, n) {
        ans += (i+1)*(n-i);
    }
    rep(i, n-1) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        to[u].push_back(v);
        to[v].push_back(u);
        if (u>v) swap(u, v);
        ans -= (u+1)*(n-v);

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


Measured memory_bytes: 14984
#include <bits/stdc++.h>
using namespace std;
 
/*** Template Begins ***/
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
 
// Debug //
 
#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;

/*** Template Ends ***/

void solve(){
    float d,t,s;
    cin>>d>>t>>s;
    bool f=(d/s<=t);
    if(f)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
 
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3732
x = int(input())
s = [pow(i, 5) for i in range(1000)]
for i in range(1000):
    for j in range(2000):
        if j % 2 == 0:
            if s[i] - s[j // 2] == x:
                print(i, j // 2)
                exit()
        else:
            if s[i] + s[j // 2] == x:
                print(i, -(j // 2))
                exit()

Measured memory_bytes: 65920
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;

int main()
{
    string s;
    cin>>s;
    size_t sz = s.size();
    int inc = 0, dec = 0, sump = 0, sumg = 0;
    for (int i=0; i < sz; i++)
    {
        if (s[i] == 'g')
            if (sump + 1 <= sumg)
            {
                inc++;
                sump++;
            }
            else
                sumg++;
        if (s[i]=='p')
        {
            if (sump >= sumg)
            {
                dec++;
                sumg++;
            }
            else 
                sump++;
        }
    }
    cout << inc - dec << endl;
    return 0;
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Abc170D
    {
        public static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).OrderBy(i => i).ToArray();

            var max = a.Last();
            var divisible = new bool[max + 1];
            var exist = new bool[max + 1];

            foreach (var x in a)
            {
                if (exist[x])
                    divisible[x] = true;
                else
                    exist[x] = true;

                int y = x * 2;
                while (y <= max)
                {
                    divisible[y] = true;
                    y += x;
                }
            }

            int count = 0;
            for (int i = 0; i <= max; i++)
                if (exist[i] && !divisible[i])
                    count++;

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 48056
H, W, K = gets.chomp.split(" ").map(&:to_i)
C = []
H.times do
    C << gets.chomp.split("")
end

hp = []
H.times do |h|
    hp << (0..H-1).to_a.combination(h+1).to_a
end

wp = []
W.times do |w|
    wp << (0..W-1).to_a.combination(w+1).to_a
end

hp.flatten!(1)
wp.flatten!(1)
hp << []
wp << []

def nuri(c, hh, ww)
    (0..c.size-1).each do |y|
        (0..c[y].size-1).each do |x|
            if hh.include?(y) || ww.include?(x) then
                c[y][x] = "."
            end
        end
    end
    c
end

def cnt(c)
    cnt = 0
     (0..c.size-1).each do |y|
        (0..c[y].size-1).each do |x|
            cnt += 1 if (c[y][x] == "#")
        end
    end
    cnt
end

result = 0
hp.each do |hh|
    wp.each do |ww|
        c = nuri(Marshal.load(Marshal.dump(C.clone)), hh, ww)
        result += 1 if cnt(c) == K
    end
end

puts result

Measured memory_bytes: 14284
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define F first
# define S second
# define pb push_back
# define ub upper_bound
# define lb lower_bound
# define all(x) x.begin(), x.end()
# define pqueue priority_queue
# define mset multiset
# define umap unordered_map
# define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
# define rep(i,n) for(int i=0;i<n;++i)
# define forn(i,n) for(int i=1;i<=n;++i)
# define lr(i,l,r) for(int i=l;(l>r?i>=r:i<=r);(l>r?--i:++i))

using namespace std;

template<class T> void umin(T &a,T b){a=min(a,b);}
template<class T> void umax(T &a,T b){a=max(a,b);}

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

const int dx[]={1,0,-1,0,-1,-1,1,1},dy[]={0,1,0,-1,-1,1,-1,1}; 
const int mod = 1e9+7;
const ll N = 2e5+5;

int n,q,ans[N],cnt[N];
vector<int>g[N];

void dfs(int x,int p){
	ans[x]+=ans[p];
	for(auto i:g[x]){
		if(i^p){
			dfs(i,x);
		}
	}
}

void solve(){
	cin>>n>>q;
	rep(i,n-1){
		int u,v;
		cin>>u>>v;
		g[u].pb(v);
		g[v].pb(u);
	}
	while(q--){
		int a,b;
		cin>>a>>b;
		cnt[a]+=b;
	}
	for(int i=1;i<=n;++i)ans[i]=cnt[i];
	dfs(1,0);
	for(int i=1;i<=n;++i)cout<<ans[i]<<' ';

}

int main(){
	Speed();
	int T=1; 
	//cin>>T;	
	while(T--)
		solve();
	return 0;
}

Measured memory_bytes: 25464
#include <iostream>
#include <string>

using namespace std;

int main()
{
  string S;
  cin >> S;
  bool x = true;
  for(int i = 0; i < S.size() && x ; i++){
    for(int j = 0; j < S.size(); j++){
      if(S.at(i) == S.at(j) && i != j){
        x = false;
        break;
      }
    }
  }
  if(x){
    cout << "yes";
  }else{
    cout << "no";
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


int main(){cout<<fixed<<setprecision(10);
		 int m1,d1,m2,d2;
           cin>>m1>>d1>>m2>>d2;
           cout<<!(m1==m2)<<endl;
}



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

int main() {
	int n; cin >> n;
	vector<int> a(n);
	for(auto&e:a) cin >> e;
	long long ans=0;
	for(int i=0;i<n;++i) {
		if(i&&a[i-1]&&a[i]) ++ans,--a[i];
		ans+=a[i]/2;
		a[i]=a[i]&1;
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 768
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int H = sc.nextInt();
		int M = sc.nextInt();

		int Bangle = 6 * M;
		double Aangle = H * 30 + 0.5 * M;
		double X = Aangle - Bangle;
		if (X < 0) {
			X = Bangle - Aangle;
		}
		if (X > 180) {
			X = 360 - X;
		}

		System.out.println(Math.sqrt(A * A + B * B - 2 * A * B * Math.cos(Math.PI * X / 180)));
	}
}

Measured memory_bytes: 35948
#include<iostream>
using namespace std;
int main()
{
  string s = "IMPOSSIBLE";
  int i, N, M, a, b, array;
  cin >> N >> M;
  int arr1[N], arr2[N];
  for(i = 0; i < N; i++){
    arr1[i] = 0;
    arr2[i] = 0;
  }
  while(cin >> a >> b){
    if(a == 1){
      if(arr2[b]==1){
        s = "POSSIBLE";
      }
      else{
        arr1[b]=1;
      }
    }
    else if(b == N){
      if(arr1[a] == 1){
        s = "POSSIBLE";
      }
      else{
        arr2[a] = 1;
      }
    }
  }
  cout << s;
  return 0;
}


Measured memory_bytes: 1792
// #include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define exf(x)	 for(auto&& tmp : x) { cout << tmp << endl; }	// 拡張for
#define PI 3.14159265358979323846264338327950288
#define testP	 cout << "------------------ test ------------------" << endl;	// 動作確認テスト
#define testX(x) cout << "testout : " << x << endl;	// テストアウト
const int MOD{ int(1e9 + 7) };	// = 1000000007
const int inf{ 2100000000 };	// = 2100000000 (MAX:2147483647)
typedef long long ll;
using namespace std;

// ------------------ ベクター表示 ------------------ //
void printVec(vector<int>& vec) {
	cout << "";
	for (auto it = vec.begin(); it != vec.end(); it++) cout << *it << " ";
	cout << endl;
}

// ------------------ ベクター合計 ------------------ //
int sumVec(vector<int> v) {
	int sum = 0;
	for (size_t i = 0; i < v.size(); i++) sum += v[i];
	return sum;
}

// -------------------------------------------------- //
// ------------------ ここから本編 ------------------ //
// -------------------------------------------------- //

int main(void) {

	char x;
	cin >> x;
	if ('a' <= x && x <= 'z') cout << 'a' << endl;
	else cout << "A" << endl;

	return 0;
}


Measured memory_bytes: 3620
N = int(input())
l = int(repr(N)[-1])
if l == 2 or l == 4 :
    print("hon")
elif l == 5 or l == 7 :
    print("hon")
elif l == 9 :
    print("hon")
elif l == 0 or l == 1 :
    print("pon")
elif l == 6 or l == 8 :
    print("pon")
elif l == 3 :
    print("bon")

Measured memory_bytes: 9192
#include "bits/stdc++.h"

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

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

    int n;
    cin >> n;
    set< int> st;
    for (int i = 0; i < n; i++) {
    	int x; cin >> x;
    	st.insert(x);
    }
    cout << (st.size() == n? "YES" : "NO") << "\n";
}

Measured memory_bytes: 9600
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using P = pair<ll, ll>;
const int MOD = (int)1e9 + 7;
const ll INF = 1LL << 60;
const int inf = 1<<30;
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; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
template <typename T>
ostream& operator<<(ostream& os, vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, pair<T,T> const&P){
    os << P.first;
    os << " ";
    os << P.second;
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
     os<<endl;
    return os;
}
//fixed<<setprecision(10)<<ans<<endl;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    string S;
    cin >> S;
    int ans=0;
    char before = ' ';
    for(auto s:S){
        if (s!=before) ans++;
        before = s;
    }


    cout << ans << endl;
}

Measured memory_bytes: 512
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "damage", long, "cost");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    string s, t;
    scan(s, t);
    long n, m;
    scan(n, m);
    auto u = sread();
    if (u == s)
        writefln("%s %s", n - 1, m);
    else
        writefln("%s %s", n, m - 1);
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rep1r(i, n) for (int i = ((int)(n)); i > 0; --i)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define mt make_tuple
#define pf push_front
#define pob pop_back
#define pof pop_front

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

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

    int n;
    cin >> n;
    deque<int> que;

    while (n--) {
        string cm;
        int    x;
        cin >> cm;
        if (cm == "insert") {
            cin >> x;
            que.push_front(x);
        }
        if (cm == "delete") {
            cin >> x;
            auto itr = find(que.begin(), que.end(), x);
            if (itr != que.end()) {
                que.erase(itr);
            }
        }
        if (cm == "deleteFirst") {
            que.pop_front();
        }
        if (cm == "deleteLast") {
            que.pop_back();
        }
    }
    n = que.size();
    for (int i = 0; i < n; i++) {
        cout << que[i] << (i + 1 < n ? " " : "\n");
    }

    return 0;
}



Measured memory_bytes: 6952
#include <iostream>
#include <vector>
using namespace std;
vector<int> m;
int c=0;
void Merge(int left,int mid,int right)
{
	int i,j;
	int n1=mid-left;
	int n2=right-mid;
	vector<int> L(n1+1);
	vector<int> R(n2+1);
	for(i=0;i<n1;i++)	L[i]=m[left+i];
	for(i=0;i<n2;i++) R[i]=m[mid+i];
	L[n1]=1000000001;
	R[n2]=1000000001;
	i=0;j=0;
	for(int k=left;k<right;k++){
		if(L[i]<=R[j]){
			m[k]=L[i];
			i+=1;
		}
		else{
			m[k]=R[j];
			j+=1;
		}
		c+=1;
	}
}
void Mergesort(int left,int right)
{
	int mid;
	if(left+1<right){
		mid=(left+right)/2;
		Mergesort(left,mid);
		Mergesort(mid,right);
		Merge(left,mid,right);
	}
}
int main(void)
{
	int n;
	cin >> n;
	m.resize(n);
	for(int i=0;i<n;i++) cin >> m[i];
	Mergesort(0,n);
	cout << m[0];
	for(int i=1;i<m.size();i++) cout << " " << m[i];
	cout << endl << c << endl;
	return 0;
}

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

#define rep(i,n) for(int i=0; i<(n); ++i)
#define rrep(i,n) for(int i=1; i<=(n); ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define foreach(it, v) for(typeof(v.begin()) it=v.begin(); it!=v.end(); ++it)
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second

typedef unsigned int uint;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef set<int> si;

//MOD//
const ll MOD = 1000000007;
struct big;
big ex(big a, ll tms);
typedef struct big{
  ll val;
  big():val(0){}
  big(ll val):val((val%MOD+MOD)%MOD){}
  big& operator += (const big& obj){ (val+=obj.val)%=MOD; return *this;}
  big& operator -= (const big& obj){ (val+=MOD-obj.val)%=MOD; return *this;}
  big& operator *= (const big& obj){ (val*=obj.val)%=MOD; return *this;}
  big& operator /= (const big& obj){ (val*=ex(obj,MOD-2).val)%=MOD; return *this;}
  big operator + (const big& obj)const{ return big(*this) += obj;}
  big operator - (const big& obj)const{ return big(*this) -= obj;}
  big operator * (const big& obj)const{ return big(*this) *= obj;}
  big operator / (const big& obj)const{ return big(*this) /= obj;}
  bool operator < (const big& obj)const{ return val < obj.val;}
  bool operator == (const big& obj)const{ return val == obj.val;}
} big;
istream& operator >> (istream& i, big& obj){ i>>obj.val; return i;}
ostream& operator << (ostream& o, const big& obj){ o<<obj.val; return o;}
big ex(big obj, ll tms){
  if(!tms) return 1;
  big ret = ex(obj, tms/2);
  ret *= ret;
  return (tms&1) ? ret*obj : ret;
}
//MOD//

ll pow(ll n, int m){
  if(!m) return 1;
  ll ret = pow(n, m/2);
  ret *= ret;
  return (m&1) ? ret*n : ret;
}

template <class F, class T>
void convert(const F &f, T &t){
  stringstream ss;
  ss << f;
  ss >> t;
}

int N, M;

int main(){
  scanf("%d%d",&N,&M);
  vi x[N];
  int a, b;
  rep (i, M) {
    scanf("%d%d",&a,&b);
    x[a-1].pb(b-1);
    x[b-1].pb(a-1);
  }
  vi ds;
  bool ts = false;
  rep (i, N) {
    if (x[i].size() % 2) {
      cout << "No\n";
      return 0;
    }
    if (x[i].size() == 4) ds.pb(i);
    if (x[i].size() > 4) ts = true;
  }
  if (ts || ds.size() >= 3) cout << "Yes\n";
  else if (ds.size() <= 1) cout << "No\n";
  else {
  int d1 = ds[0];
  int d2 = ds[1];
  rep (i, 4) {
    int now = d1;
    int next = x[d1][i];
    while (next != d2) {
      int nn = x[next][0];
      if (nn == now) nn = x[next][1];
      if (nn == d1) {
        cout << "Yes\n";
        return 0;
      }
      now = next;
      next = nn;
    }
  }
  cout << "No\n";
  }
  return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  lint N;
  cin>>N;
  map<lint,int> m;
  FOR(i,2,sqrt(N)+1){
    while(N%i==0){
      m[i]++;
      N/=i;
    }
  }
  if(N!=1)m[N]++;
  int ans=0;
  for(auto e:m){
    int t=e.second;
    int k=1;
    // cerr<<t<<endl;
    while(t-k>=0){
      t-=k;
      k++;
      ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

public class Main {
	
	static int discTime = 0;
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int[][] v = new int[n+1][n];
		int[] d = new int[n+1];
		int[] f = new int[n+1];
		
		for (int i = 0; i < n; i++) {
			int u = sc.nextInt();
			int k = sc.nextInt();
			for (int a = 0; a < k; a++) {
				v[u][a] = sc.nextInt();
			}
		}
		
		for (int i = 1; i <= n; i++) {
			if (d[i] == 0) {
				dfs(v,d,f,i);
			}
		}
		
		for (int i = 1; i <= n; i++) {
			System.out.println(i + " " + d[i] + " " + f[i]);
		}
		
	}
	
	static void dfs(int[][] v, int[] d, int[] f, int u){
		d[u] = ++discTime;
		for (int i = 0; i < v[u].length && v[u][i]>0; i++) {
			if (d[v[u][i]] == 0) {
				dfs(v, d, f, v[u][i]);
			}
		}
		f[u] = ++discTime;
	}
	
	
	
}


Measured memory_bytes: 28480
#include <stdio.h>

int main(void)
{
  int a[10], b[10], c[10], d[10];
  int n[50], cou[50];
  int i, j, k, s, top, all;
  int count = 0;
  int index = 0;

  do{
    if((scanf("%d", &n[index])) == EOF)
      break;
    else
      index++;
  }while((1 <= index) && (index <= 50));


 for(i = 0; i < 10; i++){
   a[i] = b[i] = c[i] = d[i] = i;
 }

 for(top = 0; top < index; top++){
   for(i = 0; i < 10; i++){
     for(j = 0; j < 10; j++){
       for(k = 0; k < 10; k++){
	 for(s = 0; s < 10; s++){

	  all = a[i] + b[j] + c[k] + d[s];
    
	  if(n[top] == all)
	    count++;
	 }
       }
     }
   }
   cou[top] = count;
   count = 0;
 }

  for(i = 0; i < index; i++)
  printf("%d\n", cou[i]);

  return 0;
}

Measured memory_bytes: 596
#!/usr/bin/env python3
import sys


def solve(S: str):
    l = ['SUN','MON','TUE','WED','THU','FRI','SAT']
    print(7 - l.index(S))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
N = int(input())
l = list(map(int, input().split()))
d = 0

for i in range(N-1):
  if l[i] - l[i+1] >= 2:
    d = 1

for i in range(N-2):
  if l[i] - l[i+1] == 1:
    for j in range(i+1, N-1):
      if l[j] - l[j+1] <= -1:
        break
      if l[j] - l[j+1] == 0:
        continue
      if l[j] - l[j+1] == 1:
        d = 1
        break

if d == 0:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 14396
#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = (a); i < (b); ++i)

using namespace std;
using ll = long long;

/**
 * main
 */
int main () {
  ll H; cin >> H;
  ll W; cin >> W;

  if (H == 1 || W == 1) {
    cout << 1 << endl;
  } else {
    ll RH = H % 2;
    ll RW = W % 2;
    ll ans = (H / 2) * (W / 2) * 2
      + (W / 2) * RH
      + (H / 2) * RW
      + RH * RW;

    cout << ans << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
unsigned int factorial(unsigned int n) 
{ 
    int res = 1, i; 
    for (i = 2; i <= n; i++) 
        res *= i; 
    return res; 
} 
int main()
{int n;
cin>>n;
double x[n];
double y[n];
for(int i=0;i<n;i++)
{cin>>x[i];
cin>>y[i];
}
double dis=0.0;
for(int i=0;i<n;i++)
{for(int j=0;j<n;j++)
{if(i==j)
continue;
else
dis+=factorial(n-1)*sqrt(pow(x[i]-x[j],2)+pow(y[i]-y[j],2));
}
}
unsigned long long int fact=factorial(n);
double average=dis/fact;
cout<<fixed<<setprecision(10)<<average;
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int k,n;
	cin>>k>>n;
	int a[200001],b[200005];
	for (int i=0;i<n;i++) cin>>a[i];
	for (int i=1;i<=n;i++){
		if (i!=n) b[i]=a[i]-a[i-1];
		else b[i]=k-a[i-1]+a[0];
	}
	sort(b+1,b+n+1);
	int res=0;
	//for (int i=1;i<=n;i++) cout<<b[i]<<" ";
	for (int i=1;i<n;i++) res+=b[i];
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 1792
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let n: usize = read();
    let p = read_vec::<f64>();

    let mut dp = vec![vec![0.0; n + 1]; n+1];
    dp[0][0] = 1.0;
    for i in 0..n {
        for j in 0..n + 1 {
            dp[i + 1][j] = dp[i][j] * (1.0 - p[i]);
            if j >= 1 {
                dp[i + 1][j] += dp[i][j - 1] * p[i];
            }
        }
    }

    let mut ans = 0.0;
    for i in n / 2 + 1..n + 1 {
        ans += dp[n][i];
    }
    println!("{:?}", ans);
}


Measured memory_bytes: 90364
#include <iostream>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;

int main()
{
    int n,q,v,count=0;;
    cin >> n;
    int s[n];
    REP(i,n){
        cin >> v;
        s[i] = v;
    }
    cin >> q;
    int t[q];
    REP(i,q){
        cin >> v;
        t[i] = v;
    }
    REP(i, q){
        REP(j, n){
            if(t[i] == s[j]) {
                count++;
                break;
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3088
#define pb push_back
#define ll long long
#include<bits/stdc++.h>
using namespace std;
int n, q;
string cmd;
struct node{
	node *l, *r;
	int key = 0;
	node(int k){
		key = k;
		l = r = NULL;
	}
};
node* insert(node* r, int key){
	if(r == NULL || r->key == key) return new node(key);
	if(r->key > key){
		r->l = insert(r->l, key);
	}else r->r = insert(r->r, key);
	return r;
}
void pre(node* r){
	if(!r) return;
//	if(ff) cout << " ";
	printf(" %d", r->key); 
	pre(r->l);
	pre(r->r);
}
void in(node* r){
	if(!r) return;
	in(r->l);
	printf(" %d", r->key); 
	in(r->r);
}
int cc = 0;
node* root = NULL;
bool search(int key, node* r){
	if(r == NULL) return false;
	if(r->key == key) return true;
	if(r->key > key) return search(key, r->l);
	else return search(key, r->r);
}
void solve(){
	root = NULL;
	cc = 0;
	cin >> q;
	while(q--){
		cin >> cmd;
		if(cmd[0] == 'i'){
			int x; cin >> x;
		//	cout << cmd << " " << x << endl;
			root = insert(root, x);
		}else if(cmd[0] == 'p'){
			in(root); 
			cout << endl;
			pre(root);
			cout << endl;
//			bool ok = false;
//			if(cc != 0) cout << endl, ok = true;
//			cc++;
//			if(q == 0 && ok == false) cout << endl;
		}else{
			int x; cin >> x;
			bool ok = search(x, root);
			if(ok) cout << "yes" << endl;
			else cout << "no" << endl;
		}
	}
	//cout << "root: " << root->key << endl;
}
int main(){
	solve();
	return 0;
}



Measured memory_bytes: 15672
#include<cstdio>
#include<vector>
#include<complex>
#include<algorithm>

#define	mp			make_pair
#define	pb			push_back
#define	rep(i,n)	for(int i=0;i<(n);i++)

using namespace std;

typedef	complex<double>	Point;

const double EPS=1e-9;

class Line:public vector<Point>{
public:
	Line(){}
	Line(const Point &a,const Point &b){ pb(a),pb(b); }
};

class Segment:public Line{
public:
	Segment(){}
	Segment(const Point &a,const Point &b):Line(a,b){}
};

double dot(const Point &a,const Point &b){
	return real(a)*real(b)+imag(a)*imag(b);
}

double cross(const Point &a,const Point &b){
	return real(a)*imag(b)-imag(a)*real(b);
}

enum {CCW=1,CW=-1,ON=0};
int ccw(const Point &a,Point b,Point c){
	b-=a,c-=a;
	double rotdir=cross(b,c);
	if(rotdir>EPS)		return CCW;
	if(rotdir<-EPS)		return CW;
	return ON;
}

inline void calc_abc(const Line &l,double &a,double &b,double &c){	// l : ax+by+c=0
	a=imag(l[0])-imag(l[1]);
	b=real(l[1])-real(l[0]);
	c=cross(l[0],l[1]);
}

bool intersect(const Segment &s,const Segment &t,Point *p=NULL){
	if(max(real(s[0]),real(s[1]))<min(real(t[0]),real(t[1]))-EPS
	|| max(real(t[0]),real(t[1]))<min(real(s[0]),real(s[1]))-EPS
	|| max(imag(s[0]),imag(s[1]))<min(imag(t[0]),imag(t[1]))-EPS
	|| max(imag(t[0]),imag(t[1]))<min(imag(s[0]),imag(s[1]))-EPS)	return false;

	if(ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1])<=0
	&& ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1])<=0){
		if(p){
			double a1,b1,c1,a2,b2,c2;
			calc_abc(s,a1,b1,c1);
			calc_abc(t,a2,b2,c2);
			double det=a1*b2-a2*b1;
			if(abs(det)<EPS){	// s is parallel to t
				Point q[3]={s[0],s[1],t[0]};
				rep(i,3){
					if(dot(q[i]-s[0],q[i]-s[1])<EPS && dot(q[i]-t[0],q[i]-t[1])<EPS){
						*p=q[i];
						break;
					}
				}
			}
			else	*p=Point(b1*c2-b2*c1,a2*c1-a1*c2)/det;
		}
		return true;
	}
	return false;
}

int n;
Point A,B;
Segment AB,S[100];
bool own[100],loc[100];

int solve(bool loca){
	vector< pair<double,int> > pts;
	rep(i,n){
		Point Q;
		if(intersect(AB,S[i],&Q))	pts.pb(mp(abs(A-Q),i));
	}

	sort(pts.begin(),pts.end());

	int cnt=0;
	bool now=loca;
	rep(i,pts.size()){
		int id=pts[i].second;
		if(own[id]){
			if(now!=loc[id]){ cnt++; now=!now; }
		}
		else{
			if(now==loc[id]){ cnt++; now=!now; }
		}
	}
	return cnt;
}

int main(){
	int T;	scanf("%d",&T);
	while(T--){
		int xa,ya,xb,yb;	scanf("%d%d%d%d%d",&xa,&ya,&xb,&yb,&n);
		A=Point(xa,ya);
		B=Point(xb,yb);
		AB=Segment(A,B);
		rep(i,n){
			int x1,y1,x2,y2,o,l;	scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&o,&l);
			S[i]=Segment(Point(x1,y1),Point(x2,y2));
			own[i]=o;
			loc[i]=l;
		}
		printf("%d\n",min(solve(0),solve(1)));
	}

	return 0;
}

Measured memory_bytes: 840
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;
long long a[100];
int main(){
	a[0] = 2;
	a[1] = 1;
	for(int i = 2; i <= 100; i++) a[i] = a[i-1] + a[i-2];
	int n;
	cin>>n;
	cout<<a[n];
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    int k;
    cin >> n >> k;

    int cnt = 0;
    while (n)
    {
        n /= k;
        cnt++;
    }
    
    cout << cnt << endl;
  
    return 0;
}

Measured memory_bytes: 256
use std::io;
use std::str;

#[derive(Debug, Clone, Copy)]
enum Direction {
    Up,
    Left,
    Diagonal,
    Empty,
}

fn lcs(s: &[char], t: &[char]) -> String {
    let n = s.len();
    let m = t.len();
    let mut dp = vec![vec![0; m + 1]; n + 1];
    let mut parent = vec![vec![Direction::Empty; m + 1]; n + 1];
    for i in 0..n {
        for j in 0..m {
            if s[i] == t[j] {
                dp[i + 1][j + 1] = 1 + dp[i][j];
                parent[i + 1][j + 1] = Direction::Diagonal;
            } else if dp[i][j + 1] < dp[i + 1][j] {
                // dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
                dp[i + 1][j + 1] = dp[i + 1][j];
                parent[i + 1][j + 1] = Direction::Up;
            } else {
                dp[i + 1][j + 1] = dp[i][j + 1];
                parent[i + 1][j + 1] = Direction::Left;
            }
        }
    }
    let mut ans = Vec::new();
    let mut i = n;
    let mut j = m;
    loop {
        if i == 0 && j == 0 {
            break;
        }
        match parent[i][j] {
            Direction::Diagonal => {
                ans.push(s[i - 1]);
                i -= 1;
                j -= 1;
            }
            Direction::Up => j -= 1,
            Direction::Left => i -= 1,
            Direction::Empty => {
                break;
            }
        }
    }
    // dp[n][m]
    ans.iter().rev().collect::<String>()
}

fn solve<R: io::BufRead, W: io::Write>(scan: &mut Scanner<R>, out: &mut W) {
    let s: Vec<char> = scan.token::<String>().chars().collect();
    let t: Vec<char> = scan.token::<String>().chars().collect();
    let ans = lcs(&s, &t);
    writeln!(out, "{}", ans).ok();
}

fn main() {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut scan = Scanner::new(stdin.lock());
    let mut out = io::BufWriter::new(stdout.lock());
    solve(&mut scan, &mut out);
}

pub struct Scanner<R> {
    reader: R,
    buffer: Vec<String>,
}

impl<R: io::BufRead> Scanner<R> {
    pub fn new(reader: R) -> Self {
        Self {
            reader,
            buffer: vec![],
        }
    }

    pub fn token<T: str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buffer.pop() {
                return token.parse().ok().expect("Failed parse");
            }
            let mut input = String::new();
            self.reader.read_line(&mut input).expect("Failed read");
            self.buffer = input.split_whitespace().rev().map(String::from).collect();
        }
    }

    pub fn tokens<T: str::FromStr>(&mut self) -> Vec<T> {
        assert!(self.buffer.is_empty());
        let mut input = String::new();
        self.reader.read_line(&mut input).expect("Failed read");
        input
            .split_whitespace()
            .map(|x| x.parse().ok().expect("Failed parse"))
            .collect()
    }
}


Measured memory_bytes: 46196