akhauriyash/Code-Regression huggingface dataset:
n=int(input())
import sys
for a in range(1,3501):
    for b in range(1,3501):
        if 4*a*b -n*a -n*b<=0:
            continue
        c=n*a*b/(4*a*b -n*a -n*b)
        if not 0<c<=3500:
            continue
        if c==int(c):
            print(a,b,int(c))
            sys.exit()

Measured memory_bytes: 41580
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <unordered_set>

#define DEBUG
#ifdef DEBUG
#define debug_printf printf
#else
#define debug_printf 1 ? 0 : printf
#endif

using namespace std;
typedef long long int ll;
typedef vector<ll> Vl;
typedef vector<int> Vi;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pl;

#define FST first
#define SND second

#define MAX_N   (100000)                  // 10^5
#define BASE    (1000000000 + 7)          // 10^9 + 7
#define INFI    (1000000000 + 7)          // 10^9 + 7
#define INFL    (1000000000000000000 + 7) // 10^18 + 7

int N;
set<int> G[MAX_N], V;

void make_tree(int v) {
  for (auto u: G[v]) {
    G[u].erase(v);
    make_tree(u);
  }
}

void remove_match(int v) {
  bool single = true;
  for (auto u : G[v]) {
    remove_match(u);
    if (single && V.find(u) != V.end()) {
      V.erase(u); V.erase(v);
      single = false;
    }
  }
}

string winner() {
  int root = 0;
  make_tree(root);
  remove_match(root);
  return (V.size() == 0)? "Second": "First";
}

int main() {
  cin >> N;

  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].insert(b);
    G[b].insert(a);
    V.insert(a);
    V.insert(b);
  }

  string ans = winner();
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 18944
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl;

typedef long long ll;
const ll INF = 99999999999999;
const ll MOD = 1000000007;

using namespace std;

int main()
{
    ll m1, d1, m2, d2, ans = 0;
    cin >> m1 >> d1 >> m2 >> d2;
    if (m1 != m2)
    {
        ans = 1;
    }

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

Measured memory_bytes: 256
#n=int(input())
n,k=map(int,input().split())
al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
def f(l):
    res=1
    for li in l:
        res=res*li
    return res
sc=[]
alr=0
for i in range(k-1,n):
    if i==k-1:
        #score=f(al[i-k+1:i+1])
        first=al[i-k+1]
        alr=1
    else:
        #first=al[i-k]
        last=al[i]
        if last>first :
            print('Yes')
        else:
            print('No')
        first=al[i-k+1]


Measured memory_bytes: 31608
#A
#n = int(input())
#print(3*n**2)
#B
#n, d = map(int, input().split())
#canseerange = 2*d+1
#if n % canseerange == 0:
#    print(int(n/canseerange))
#else:
#    print(int(n/canseerange)+1
#C
n = int(input())
ans = 0
most1 = 0
most2 = 0
ed = False
for i in range(n):
    t = int(input())
    ed = False
    if most1 <= t:
        most2 = most1
        most1 = t
        ans = i
        ed = True
    elif most2 <= t and ed == False:
        most2 = t
for i in range(n):
    if i==ans:print(most2)
    else:print(most1)

Measured memory_bytes: 55640
N = int(input())
if N % 2 == 0:
	print( (N*N - 2*N) // 2)
else:
	print( (N*N - 2*N + 1) // 2)
for i in range(1, N):
	for j in range(i+1, N+1):
		if j != N - i + ((N+1)%2):
			print(str(i) + " " + str(j)) 

Measured memory_bytes: 3336
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<queue>
#include<deque>
#include<string>
#include<utility>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#include<ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<pli> vpli;

inline ll read(){
    ll Hashimoto=0;
	bool Kanna=1;
    char I_Love=getchar();
    while(I_Love<'0'||I_Love>'9'){
        if(I_Love=='-')Kanna=0;
        I_Love=getchar();
    }
    while(I_Love>='0'&&I_Love<='9'){
        Hashimoto=Hashimoto*10+I_Love-'0';
        I_Love=getchar();
    }
    return (Kanna?Hashimoto:-Hashimoto);
}
template<typename T1,typename T2> inline void Umax(T1 &a,T2 b){
	if(a<b)a=b;
}
template<typename T1,typename T2> inline void Umin(T1 &a,T2 b){
	if(a>b)a=b;
}

#define I_Love_Hashimoto_Kanna main
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define filein(s) freopen(s,"r",stdin);
#define fileout(s) freopen(s,"w",stdout);
#define file freopen("I_Love_Hashimoto_Kanna.out","w",stdout);
#define RE cout<<"I_Love_Hashimoto_Kanna"<<endl;
#define Tone(Kanna) cout<<Kanna<<endl;
#define Tall(Hashimoto,Kanna) for(int I_Love=0;I_Love<(Kanna);++I_Love)cout<<Hashimoto[I_Love]<<(I_Love==(Kanna)-1?"\n":" ");
#define FOR(I_Love,Hashimoto,Kanna) for(int I_Love=Hashimoto;I_Love<(Kanna);++I_Love)
#define MP(Hashimoto,Kanna) make_pair(Hashimoto,Kanna)
#define REV(Kanna) reverse(Kanna.begin(),Kanna.end());
#define SORT(Kanna) sort(Kanna.begin(),Kanna.end());
#define UNIQUE(Kanna) Kanna.erase(unique(Kanna.begin(),Kanna.end()),Kanna.end());
#define inf (1000000000)
#define linf (1000000000000000000ll)
#define mod (1000000007)

int n;
int a[111111];

int I_Love_Hashimoto_Kanna() {
	//完全想清楚了再开始写。
	//写不顺、不知道怎么写、很乱的时候，停下来好好想想。
	//做得慢总比做不出好。
	fastio;
	n=read();
	FOR(i,0,n)a[i]=read();
	if(n==3){
		if(a[0]!=(a[1]^a[2])){cout<<"No\n";return 0;}
		if(a[2]!=(a[1]^a[0])){cout<<"No\n";return 0;}
		if(a[1]!=(a[0]^a[2])){cout<<"No\n";return 0;}
		cout<<"Yes\n";
	}
	else {
		if(n%3==0){
			sort(a,a+n);
			FOR(i,0,n/3)if(a[i]!=a[0]){
				cout<<"No\n";
				return 0;
			}
			FOR(i,n/3,n/3*2)if(a[i]!=a[n/3]){
				cout<<"No\n";
				return 0;
			}
			FOR(i,n/3*2,n)if(a[i]!=a[n-1]){
				cout<<"No\n";
				return 0;
			}
			if(a[0]!=(a[n/3]^a[n-1])){cout<<"No\n";return 0;}
			if(a[n-1]!=(a[n/3]^a[0])){cout<<"No\n";return 0;}
			if(a[n/3]!=(a[0]^a[n-1])){cout<<"No\n";return 0;}
			
			cout<<"Yes\n";
		}
		else {
			FOR(i,0,n)if(a[i]!=a[0]){
				cout<<"No\n";
				return 0;
			}
			cout<<"Yes\n";
		}
	}
	return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		String p = sc.next();

		String ss = s + s;

		if(ss.contains(p)) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
	}

}



Measured memory_bytes: 26260
n = int(input())
S = input()

R = S.count('R')
G = S.count('G')
B = S.count('B')

ans = R * G * B

for i in range(n):
    for d in range(n):
        j = i + d
        k = j + d
        if k >= n:
            break
        if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
            ans -= 1

print(ans)


Measured memory_bytes: 68080
import java.io.IOException;
import java.util.Scanner;

/**
 * メインクラス
 *
 */
public class Main {

	/**
	 * メインメソッド
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {

		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int A = Integer.parseInt(sc.next());
		int B = Integer.parseInt(sc.next());

		int max = Math.min(A, B);
		int min = (A+B) - N;

		if (min < 0) {
			System.out.println(max + " " + 0);
		}else {
			System.out.println(max + " " + min);
		}

	}
}



Measured memory_bytes: 23380
def main():
  n, x, y = map(int, input().split())
  x -= 1
  y -= 1

  ans = [0] * (n - 1)

  for i in range(n - 1):
    for j in range(i + 1, n):
      dis = min(j - i, abs(i - x) + 1 + abs(y - j), abs(i - y) + 1 + abs(x - j))
      ans[dis - 1] += 1

  for a in ans:
    print(a)


main()


Measured memory_bytes: 3572
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define each(it,o) for(auto it= (o).begin(); it != (o).end(); ++ it)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define inrep int t;cin>>t; while(t--)
using namespace std;
using namespace __gnu_pbds; 


typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii > vpii;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pll > vpll; 
typedef vector<string> vs;
typedef long double ld;
const ll MOD = 1e9+7;
template<typename T> istream& operator>> ( istream &in,vector<T> &v ) {

    for ( unsigned   i=0; i<v.size(); i++ )
        in>>v[i];
    return in;
}
int main()
{
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int q;
    cin>>q;
    vector<int> a[n+1];
    ll sum[n+1]={0};
    for(int i=1;i<n;i++)
    {
        int g,h;
        cin>>g>>h;
        a[h].push_back(g);
    }
    for(int i=0;i<q;i++)
    {
        int o,p;
        cin>>o>>p;
        sum[o]+=p;
    }
    cout<<sum[1]<<" ";
    for(int i=2;i<=n;i++)
    {
        sum[i]+=sum[a[i][0]];
        cout<<sum[i]<<" ";
    }
    // #ifndef ONLINE_JUDGE
    //     cout<<"\nTime Elapsed : "<< 1.0*clock() / CLOCKS_PER_SEC << " s\n";
    // #endif
    
    return 0;
}

Measured memory_bytes: 14976
#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}    


signed main()
{
    showoff;
    int m1,d1,m2,d2;
    cin >> m1 >> d1 >> m2 >> d2;
    if(d2 < d1)cout << "1";
    else cout << "0";
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...#include <bits/stdc++.h>
 

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

int main(){
    ll a,b,c,d,k,ans;
    cin >> a >> b >> c >> d >> k;
    ans = (c*60+d)-(a*60+b)-k;
    cout << ans;
    return 0;
}


Measured memory_bytes: 3628
import java.util.*;

public class Main {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int N = scanner.nextInt();
        int K = scanner.nextInt();
        scanner.nextLine();

        GraphBuilder builder = new GraphBuilder();
        for (int i = 0; i < N - 1; i++) {
            int[] e = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
            builder.addEdge(e[0], e[1]);
            builder.addEdge(e[1], e[0]);
        }
        Map<Integer, Set<Edge>> edges = builder.build();
        long ans = (K * dfs(1, edges, new HashSet<>(), K)) % MOD;
        System.out.println(ans);
    }

    static long dfs(int s, Map<Integer, Set<Edge>> edges, Set<Integer> visited, int K) {
        if (K < edges.getOrDefault(s, Collections.emptySet()).size()) {
            return 0;
        }
        long ans = 1;
        if (visited.add(s)) {
            int n = s == 1 ? K - 1 : K - 2;
            long perm = 1;
            for (Edge edge : edges.getOrDefault(s, Collections.emptySet())) {
                if (!visited.contains(edge.to)) {
                    perm *= n--;
                    perm %= MOD;
                }
            }
            ans = perm;

            for (Edge edge : edges.getOrDefault(s, Collections.emptySet())) {
                ans *= dfs(edge.to, edges, visited, K);
                ans %= MOD;
            }
        }
        return ans;
    }

}

class Edge {
    public final int from;
    public final int to;
    public final int cost;

    public Edge(int from, int to, int cost) {
        this.from = from;
        this.to = to;
        this.cost = cost;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Edge edge = (Edge) o;
        return from == edge.from &&
                to == edge.to &&
                cost == edge.cost;
    }

    @Override
    public int hashCode() {
        return Objects.hash(from, to, cost);
    }
}

class GraphBuilder {
    private List<Edge> edges = new ArrayList<>();

    public void addEdge(int from, int to) {
        edges.add(new Edge(from, to, 1));
    }

    public void addEdge(int from, int to, int cost) {
        edges.add(new Edge(from, to, cost));
    }

    public Map<Integer, Set<Edge>> build() {
        Map<Integer, Set<Edge>> m = new HashMap<>();
        for (Edge e : edges) {
            if (!m.containsKey(e.from)) {
                m.put(e.from, new HashSet<>());
            }
            m.get(e.from).add(e);
        }
        return m;
    }

}




Measured memory_bytes: 203212
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#include <algorithm>
using namespace std;
#define fi first
#define se second
#define mkp make_pair

typedef pair<int,int> pii;

int cost[110][110];

struct s {
	int l, p, c;
	s(){}
	s(int l_,int p_,int c_) {l=l_;p=p_;c=c_;}
};
bool operator<(const s & a, const s & b) {
	if(a.l != b.l) return a.l < b.l;
	return a.c > b.c;
}

int main() {
	int N, M, L;
	while(cin >> N >> M >> L, N || M || L) {
		vector<vector<pair<int,pii> > > G(N);
		for(int i = 0; i < 110; i++) for(int j = 0; j < 110; j++) cost[i][j] = 1e9;
		for(int i = 0; i < M; i++) {
			int a, b, d, e;
			cin >> a >> b >> d >> e;
			a--; b--;
			G[a].push_back(mkp(b,pii(d,e)));
			G[b].push_back(mkp(a,pii(d,e)));
		}
		priority_queue
 q;
		q.push(s(L,0,0));
		cost[L][0] = 0;
		while(q.size()) {
			s cur = q.top(); q.pop();
			if(cur.c > cost[cur.l][cur.p]) continue;
			for(int i = 0; i < G[cur.p].size(); i++) {
				if(cost[cur.l][G[cur.p][i].fi] > cur.c + G[cur.p][i].se.se) {
					cost[cur.l][G[cur.p][i].fi] = cur.c + G[cur.p][i].se.se;
					q.push(s(cur.l, G[cur.p][i].fi, cost[cur.l][G[cur.p][i].fi]));
				}
				if(cur.l >= G[cur.p][i].se.fi && cost[cur.l-G[cur.p][i].se.fi][G[cur.p][i].fi] > cur.c) {
					cost[cur.l-G[cur.p][i].se.fi][G[cur.p][i].fi] = cur.c;
					q.push(s(cur.l-G[cur.p][i].se.fi, G[cur.p][i].fi, cur.c));
				}
			}
		}
		int res = 1e9;
		for(int i = 0; i <= L; i++) {
			res = min(res, cost[i][N-1]);
		}
		cout << res << endl;
	}
}

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

// macros
#define overload_rep(va_0, va_1, va_2, name, ...) name
#define rep_0(i, n) for(int i = 0; i < (n); ++i)
#define rep_1(i, x, y) for(int i = (x); i <= (y); ++i)
#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0)(__VA_ARGS__)
#define all(a) a.begin(), a.end()
#ifndef STOP_DEBUG
#define debug(...)\
    do { cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_cerr(__VA_ARGS__); cerr << noboolalpha; } while (0)
#else
#define debug(...)
#endif

// functions
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; }
void debug_cerr(){ cerr << '\n'; }
template<class Head, class... Tail>
void debug_cerr(Head head, Tail... tail){
    cerr << ' ' << head;
    debug_cerr(tail...);
}

// cin/cout setup
struct IoSetup{
    IoSetup(){
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} iosetup;

// libraries

// declarations
int N, sz;
int A[200000];
int pos[200000];
int val[200000];

// solve
int main(){

    cin >> N;
    rep(i, N)cin >> A[i];

    bool found = false;
    rep(i, N - 1)if(A[i + 1] <= A[i])found = true;
    if(!found){
        cout << "1\n";
        return 0;
    }

    int ok = N, ng = 1;
    while(ok - ng > 1){
        int md = (ok + ng) >> 1;
        ([&]{
            sz = 0;
            rep(i, N - 1){
                if(A[i + 1] > A[i])continue;
                while(sz > 0 && pos[sz - 1] > A[i + 1])sz--;
                if(sz == 0 || pos[sz - 1] < A[i + 1]){
                    pos[sz] = A[i + 1];
                    val[sz] = 1;
                    sz++;
                    continue;
                }
                while(true){
                    if(val[sz - 1] < md - 1){
                        val[sz - 1]++;
                        break;
                    }
                    sz--;
                    if(pos[sz] == 1 && val[sz] == md - 1)return false;
                    if(pos[sz - 1] + 1 < pos[sz]){
                        pos[sz]--;
                        val[sz] = 1;
                        sz++;
                        break;
                    }
                }
            }
            return true;
        }() ? ok : ng) = md;
    }

    cout << ok << '\n';
    return 0;

}


Measured memory_bytes: 1024
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1000000000;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
typedef pair<int, int> P;

/** Problem2545 : Lion **/
int N, X, M;
vector<int> L, R, S;
vector<int> tmp, ans;
int tMax;

bool solve(int n)
{
	if (n == N) {
		bool ok = true;
		rep(i, M) {
			int sum = 0;
			REP(j, L[i], R[i]+1) {
				sum += tmp[j];
			}
			if (sum != S[i])
				ok = false;
		}
		
		if (ok) {
			int t=0;
			rep(i, N) t+=tmp[i];
			if (t>tMax) {
				copy(tmp.begin(), tmp.end(), ans.begin());
				tMax = t;
			}
		}
		
		return ok;
	}
	
	bool res = false;
	rep(i, X+1) {
		tmp[n] = i;
		res |= solve(n+1);
	}
	
	return res;
}

int main()
{
	cin>>N>>X>>M;
	L.resize(M), R.resize(M), S.resize(M);
	rep(i, M) {
		cin>>L[i]>>R[i]>>S[i];
		L[i]--, R[i]--;
	}
	tmp.resize(N), ans.resize(N);
	tMax=0;
	
	if (solve(0)) {
		cout<<ans[0];
		REP(i, 1, N)
			cout << " " << ans[i];
		cout << endl;
	} else {
		cout<<-1<<endl;;
	}
}

Measured memory_bytes: 1216
#include<stdio.h>

int main(void)
{
	int a,b;
	
	for(a = 1 ; a < 10 ; a++){
		for(b = 1 ; b < 10 ; b++){
			printf("%dx%d=%d\n",a,b,a*b);
		}
	}
	
	return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <string>
#include <vector>

int main() {

	int n;
	std::cin >> n;

	std::vector<int> S, T, A;

	S.resize(n, 0);
	for (int i = 0; i < n; i++)
		std::cin >> S[i];

	int q;
	std::cin >> q;

	T.resize(q, 0);
	for (int i = 0; i < q; i++)
		std::cin >> T[i];

	int cnt = 0;
	for (int i = 0; i < q; i++) {
		for (int j = 0; j < n; j++) {
			if (T[i] == S[j]) {
				cnt++;
				break;
			}
		}
	}

	std::cout << cnt << std::endl;


	return 0;
}

Measured memory_bytes: 3132
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<cmath>
#include<climits>
#include<set>
#include<map>
#define ll long long
using namespace std;
/* ユークリッドの互除法 最大公約数*/
ll gcd(ll a, ll b) {
	ll r;
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}



/*最小公倍数*/
ll lcm(ll a, ll b) {
	return a / gcd(a, b)*b;
}
int main() {
	ll a, b;
	cin >> a >> b;
	cout << lcm(a, b) << endl;

}



Measured memory_bytes: 256
import sys
input = lambda : sys.stdin.readline().strip()
s = input()
t = input()
i = 0
j = 0
for i in range(len(t)):
    if j>=len(s):
        break
    if t[i]==s[j]:
        j+=1
    else:
        break
if j==len(s):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9052
n=int(input())
num=list(map(int,input().split()))

num2=[]
for i in num:
    if i%2==0:
        num2.append(i)
num3=[]        
for j in num2:
    if j%3==0 or j%5==0:
        num3.append(0)
    elif j%3!=0 or j%5!=0:
        num3.append(1)

a=sum(num3)

if a==0:
    print("APPROVED")
elif a!=0:
    print("DENIED")


Measured memory_bytes: 9152
using System;
class Program
{
  static void Main()
  {
    int N = int.Parse(Console.ReadLine());
    string[] A_ = Console.ReadLine().Split(' ');
    string[] B = Console.ReadLine().Split(' ');
    
    // A の方は int にしておく
    long[] A = new long[N + 1];
    for (int i = 0; i < N + 1; i++)
    {
      A[i] = long.Parse(A_[i]);
    }
    
    // 
    long count = 0;
    for (int i = 0; i < N; i++)
    {
      long b = long.Parse(B[i]);
      if (b <= A[i]){
        count += b;
      }
      else if (b <= A[i] + A[i + 1]){
        count += b;
        A[i + 1] = A[i + 1] - (b - A[i]);
      }
      else{
        count += A[i] + A[i + 1];
        A[i + 1] = 0;
      }
    }
    
    Console.WriteLine(count);
  }
}

Measured memory_bytes: 32604
n = int(input())
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))

count = 0

for i in range(n):
    atk = b[i]
    if a[i] >= atk:
        kill = atk
        a[i] -= kill
    else:
        kill = a[i]
        atk -= a[i]
        a[i] = 0
        kill += min(a[i + 1], atk)
        a[i + 1] = max(a[i + 1] - atk, 0)

    count += kill

print(count)


Measured memory_bytes: 18476
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

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

const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int INF_INT = 1e9;

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

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

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

int main(){
    int N;
    cin >> N;
    vector<ll> a(N);
    vector<ll> subsum(N);
    for(int i = 0; i < N; i++){
        cin >> a[i];
    }
    subsum[0] = a[0];
    for(int i = 1; i < N; i++){
        subsum[i] = subsum[i-1] + a[i];
    }
    sort(subsum.begin(),subsum.end());
    ll cnt = 0;
    for(int i = 0; i < N; i++){
        if(subsum[i] == 0) cnt++;
    }
    ll pre = subsum[0];
    ll nowcnt = 1;
    for(int i = 1; i < N; i++){
        if(pre == subsum[i]) nowcnt++;
        else{
            cnt +=  nowcnt * (nowcnt - 1) / 2;
            pre = subsum[i];
            nowcnt = 1;
        }
    }
    cout << cnt + nowcnt * (nowcnt - 1) / 2 << endl;
    return 0;
}


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

int main(){
  int D, M=26;
  cin >> D;
  vector<long long> c(M);
  for(int i=0; i<M; i++){
    cin >> c[i];
  }
  vector<vector<long long>> s(D,vector<long long>(M));
  for(int i=0; i<D; i++){
    for(int j=0; j<M; j++){
      cin >> s[i][j];
    }
  }
  long long la,onelos=0;
  for(int j=0; j<M; j++){
    onelos += c[j];
  }
  long long num = 1;
  vector<long long> sat(num,0), los(num,0), nlos(num,0);
  vector<pair<long long, long long>> tmpsat(num*M);
  vector<vector<long long>> last(num,vector<long long>(M,-1)), nlast(num,vector<long long>(M,-1));
  vector<vector<long long>> t(num,vector<long long>(D)), nt(num,vector<long long>(D));
  for(int i=0; i<D; i++){
    for(int j=0; j<num; j++){
      for(int k=0; k<M; k++){
        la = (long long)i - last[j][k];
    	tmpsat[j*M+k].first = sat[j] + s[i][k] - los[j] - onelos + la*c[k];
        tmpsat[j*M+k].second = j*M+k;
      }
    }
    sort(tmpsat.begin(), tmpsat.end(), greater());
    for(int j=0; j<num; j++){
      sat[j] = tmpsat[j].first;
      long long ty = tmpsat[j].second%M;
      long long prenum = tmpsat[j].second/M;
      nlast[j] = last[prenum];
      nlast[j][ty] = (long long)i;
      nlos[j] = los[prenum] + onelos - ((long long)i - last[prenum][ty])*c[ty];
      nt[j] = t[prenum];
      nt[j][i] = ty;
    }
    for(int j=0; j<num; j++){
      last[j] = nlast[j]; los[j] = nlos[j]; t[j] = nt[j];
    }
  }
  //cout << sat[0] << endl;
  for(int i=0; i<D; i++){
    cout << t[0][i]+1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3748
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(" ");
        var N = int.Parse(input[0]);
        var M = int.Parse(input[1]);
        var X = int.Parse(input[2]);

        var C = new List<int>();
        var A = new int[N + 1, M + 1];
        for(int i = 0; i< N; i++)
        {
            var line = Console.ReadLine().Split(" ");
            C.Add(int.Parse(line[0]));

            for(int j = 0; j < M; j++)
            {
                A[i + 1, j + 1] = int.Parse(line[j + 1]);
            }
        }

        var result = int.MaxValue;
        for (int bit = 0; bit < (1 << N); ++bit)
        {
            var money = 0;
            var sumList = new int[M];
            for (int i = 0; i < N; ++i)
            {
                if ((bit & (1 << i)) != 0)
                {
                    money += C[i];
                    for(int j = 0; j < M; j++)
                    {
                        sumList[j] += A[i + 1, j + 1];
                    }
                }
            }

            if (!sumList.Any(x => x < X))
            {
                result = Math.Min(result, money);
            }
        }
        if (result == int.MaxValue) Console.WriteLine("-1");
        else Console.WriteLine(result);

    }
}


Measured memory_bytes: 28512
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::iter::FromIterator;
// input macro
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn rec(v: usize, used: &mut Vec<bool>, g: &Vec<Vec<usize>>) -> i32 {
    used[v] = true;
    let flag = used.iter().all(|&x| x);
    let res = if flag {
        1
    } else {
        let mut s = 0;
        for i in g[v].iter() {
            if used[*i] == false {
                s += rec(*i, used, &g);
            }
        }
        s
    };
    used[v] = false;
    res
}

fn main() {
    input!{
        n: usize,
        m: usize,
        ab: [(usize1, usize1); m],
    }
    let mut g = vec![vec![]; n];
    for i in 0..m {
        let (a, b) = (ab[i].0, ab[i].1);
        g[a].push(b);
        g[b].push(a);
    }
    let mut used = vec![false; n];
    let ans = rec(0, &mut used, &g);
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
void pig_sort(vector<pair<ll, ll>> &v){
    vector<queue<pair<ll, ll>>> que((ll)1e5);
    for(auto u : v) que[u.second - 1].push(u);
    v.clear();
    ll i = 0;
    for(auto &q : que){
        while(q.size()){
            v[i] = q.front();
            q.pop();
            i++;
        }
    }
}
int main(){
    ll N, M;
    cin >> N >> M;
    vector<pair<ll, ll>> a(M);
    for(ll i = 0; i < M; i++) cin >> a[i].first >> a[i].second;
    pig_sort(a);
    ll ans = 0, bridge = -1;
    for(ll i = 0; i < M; i++){
        if(a[i].first < bridge && bridge <= a[i].second) continue;
        ans++;
        bridge = a[i].second;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 69504
#include <stdio.h>
#include <stdlib.h>

int main()
{
   int a,b;
   scanf("%d%d",&a,&b);
   if(b%a==0)
    {

        printf("%d\n",a+b);
    }
    else{

    printf("%d\n",b-a);
   }

   return 0;
}



Measured memory_bytes: 128
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<cmath>
#include<cstring>
using namespace std;
int main(){
  int i,j;
  int w,h;
  while(cin>>w>>h,w||h){
    int d,n;
    cin>>d>>n;
    int a[20][20]={};
    for(i=0;i<n;++i){
      char s,t;
      int p,q;
      cin>>s>>t>>p>>q;
      p--;
      a[p][s-'a']=q;
    }
    int m;
    cin>>m;
    int b[20][21],c[21][20];
    memset(b,-1,sizeof(b));
    memset(c,-1,sizeof(c));
    for(i=0;i<h;++i)
      for(j=1;j<w;++j)
	b[i][j]=0;
    for(i=1;i<h;i++)
      for(j=0;j<w;j++)
	c[i][j]=0;
    for(i=0;i<m;++i){
      char s,t,u;
      int p,q;
      cin>>s>>u>>p>>t>>u>>q;
      p--;
      q--;
      if(s==t){
	c[max(p,q)][s-'a']=-1;
      }else{
	b[p][max(s,t)-'a']=-1;
      }
    }
    int o;
    cin>>o;
    for(i=0;i<o;++i){
      char s,t,u;
      int p,q,r;
      cin>>s>>u>>p>>t>>u>>q>>r;
      p--;
      q--;
      if(s==t){
	c[max(p,q)][s-'a']=r;
      }else{
	b[p][max(s,t)-'a']=r;
      }
    }
    char s,t;
    int sx,sy,tx,ty;
    cin>>s>>t>>sy;
    sx=s-'a';
    sy--;
    cin>>s>>t>>ty;
    tx=s-'a';
    ty--;
    int f[101][4][20][20];
    memset(f,-1,sizeof(f));
    priority_queue<pair<pair<int,int>,pair<int,int> >,vector<pair<pair<int,int>,pair<int,int> > >,greater<pair<pair<int,int>,pair<int,int> > > > e;
    e.push(make_pair(make_pair(0,0),make_pair(sx,sy)));
    for(;;){
      int x,y,z,t;
      t=e.top().first.first;
      z=e.top().first.second;
      x=e.top().second.first;
      y=e.top().second.second;
      if(x==tx&&y==ty)
	break;
      e.pop();
      if(f[t][z][y][x]&&(a[y][x]==0||z%2!=(t/*+a[y][x]-1*/)%(a[y][x]*2)/a[y][x])){
	f[t][z][y][x]=0;
	if(z!=3&&b[y][x+1]>=0&&t+d+b[y][x+1]<=100&&f[t+d+b[y][x+1]][1][y][x+1])
	  e.push(make_pair(make_pair(t+d+b[y][x+1],1),make_pair(x+1,y)));
	if(z!=1&&b[y][x]>=0&&t+d+b[y][x]<=100&&f[t+d+b[y][x]][3][y][x-1])
	  e.push(make_pair(make_pair(t+d+b[y][x],3),make_pair(x-1,y)));
	if(z!=0&&c[y][x]>=0&&t+d+c[y][x]<=100&&f[t+d+c[y][x]][2][y-1][x])
	  e.push(make_pair(make_pair(t+d+c[y][x],2),make_pair(x,y-1)));
	if(z!=2&&c[y+1][x]>=0&&t+d+c[y+1][x]<=100&&f[t+d+c[y+1][x]][0][y+1][x])
	  e.push(make_pair(make_pair(t+d+c[y+1][x],0),make_pair(x,y+1)));
      }
    }
    cout<<e.top().first.first<<endl;
  }
  return 0;
}

Measured memory_bytes: 1644
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

typedef struct Edge {
    ll to, cost;
} Edge;

vector<vector<Edge>> g{};
vector<bool> vi;
vector<int> ans;

void dfs(int x, int c) {
    vi[x] = true;
    for (auto &&e: g[x]) {
        if (vi[e.to]) continue;
        int t = c^e.cost;
        ans[e.to] = t;
        dfs(e.to,t);
    }
    return;
}

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    g.resize(n); vi.resize(n); ans.resize(n);
    rep(i,n-1) {
        ll u,v,w; cin>>u>>v>>w;
        --u,--v;
        w %= 2;
        g[u].push_back({v,w}); g[v].push_back({u,w});
    }
    dfs(0,0);
    rep(i,n) cout << ans[i] << '\n';
    return 0;
}

Measured memory_bytes: 9600
program shift_only
  implicit none
  integer              :: n, m, i
  integer, allocatable :: a(:)
  read(*,*) n
  allocate(a(n))
  read(*,*) a(:)

  m = 0
  do
     do i = 1, n
        if (mod(a(i),2) .eq. 1) goto 114
     end do
     a = a/2
     m = m + 1
  end do

114 write(*,'(i0)') m
  
  deallocate(a)
  stop
end program shift_only

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(){
  int N;
  scanf("%d",&N);
  N %= 10;
  switch(N){
      case 0:
        printf("pon\n");
        break;
      case 1:
        printf("pon\n");
        break;
      case 2:
        printf("hon\n");
        break;
      case 3:
        printf("bon\n");
        break;
      case 4:
        printf("hon\n");
        break;
      case 5:
        printf("hon\n");
        break;
      case 6:
        printf("pon\n");
        break;
      case 7:
        printf("hon\n");
        break;
      case 8:
        printf("pon\n");
        break;
      case 9:
        printf("hon\n");
        break;  
  }
  return 0;
}

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

typedef long long ll;
using namespace std;
int main()
{
  string s;
  ll cnt[26]={0};
  cin>>s;
  rep(i,s.length()){
    cnt[s[i]-'a']++;
  }

  rep(i,26){
    if(cnt[i]>1){
      cout<<"no"<<endl;
      return 0;
    }
  }

  cout<<"yes"<<endl;
  return 0;
}


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

int keta(int num){
  int ans= 0 ;
  int rem;

  for (int i = 4; i >= 0 ; i--){
    rem = pow(10,i);
    ans += (num / rem); 
    num = num % rem;
  }
  return ans;
}


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

  vector<int> kagami(N);
  for (int i = 0; i < N; i++){
    cin >> kagami.at(i);
  }

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

  int ans = 1;

  for (int i = 0; i < N-1 ; i++){
    if(kagami.at(i) != kagami.at(i+1)){
      ans++;
    }
  }
  
  cout << ans << endl;

}


Measured memory_bytes: 256
//#include <bits/stdc++.h>                          //include all library
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <sstream>
#include <vector>
#include <stack>
#include <queue>
#include <string.h>
#include <functional> // greater<int> はfunctionalヘッダ
#include <numeric>
using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)          //REP(i, 10){...} //i=0～i=9までのループ
#define REPR(i, n) for(int i = n;i >= 0;i--)        //REPR(i, 10){...} //i=10～i=0までのループ
#define FOR(i, m, n) for(int i = m;i < n;i++)       //FOR(i, 3, 10){...} //i=3～i=9までのループ
#define FORR(i, m, n) for(int i = m;i >= n;i--)     //FORR(i, 10, 3){...} //i=10～i=3までのループ
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
#define PI 3.141592653589
#define npos -1

long long func(llong a, llong b, llong x){
	if(a%x==0 or b%x==0) return (b-a)/x +1;
	else return b/x - a/x;
}

int main(){
	long long a, b, c, d;
	cin >> a >> b >> c >> d;

	if(c > d){
		long long tmp = c;
		c = d;
		d = tmp;
	}
	long long cc = c, dd = d;
  	long long r = d % c;
  	while(r!=0){
    	d = c;
    	c = r;
    	r = d % c;
    }
    long long e = cc/c * dd;
    
	cout << b - a + 1 - (func(a, b, cc) + func(a, b, dd) - func(a, b, e)) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int N;
    int L[101];
    int X;
    scanf("%d",&N);
    scanf("%d",&X);
    int i;
    for(i=1;i<=N;i++){
        scanf("%d",&L[i]);
    }
    int D[102];
    D[1]=0;
    for(i=2;i<=N+1;i++){
        D[i]=D[i-1]+L[i-1];
    }
    int ans;
    ans=N+1;
    for(i=1;i<=N+1;i++){
        if(D[i]>X){
            ans=i-1;
            break;
        }
    }
    printf("%d",ans);
}

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

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n,tot=0;
	cin >> n;
	vector<int> m(n+1),h(n);
	for (int i=0; i<=n; ++i){
		cin >> m[i];
		tot += m[i];
	}
	for (int i=0; i<n; ++i){
		cin >> h[i];
	}
	for (int i=n-1; i>=0; --i){
		int a=h[i],c=m[i],b=m[i+1];
		m[i+1] -= min(a,b);
		a -= min(a,b);
		m[i] -= min(a,c);
	}
	for (int i=0; i<=n; ++i){
		tot -= m[i];
	}
	cout << tot;
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
 
using namespace std;
 
typedef long long ll;
 
ll name[100001], dist[100001], nxt[100001], sz[100001];
ll n, m;
ll temp1, temp2, temp3;
 
void merge(ll u, ll v, ll d) {
 
    ll nx = nxt[u];
    ll siz = sz[name[v]];
    nxt[u] = v;
    name[v] = name[u];
    ll temp = v;
    ll olddist = dist[temp];
    dist[temp] = dist[u] + d;
    while (nxt[temp] != v) {
        temp = nxt[temp];
        name[temp] = name[u];
        dist[temp] += dist[v] - olddist;
    }
    nxt[temp] = nx;
    sz[name[u]] += siz;
 
}
 
int main()
{
    ios::sync_with_stdio(false);
 
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
 
    cin >> n >> m;
 
    for (int i = 0; i <= n; ++i) {
        name[i] = i;
        sz[i] = 1;
        dist[i] = 0;
        nxt[i] = i;
    }
 
    ll u, v, d;
 
    for (int i = 0; i < m; ++i) {
        cin >> u >> v >> d;
 
        if (name[u] == name[v]) {
            if (dist[v] - dist[u] != d) {
                cout << "No";
                return 0;
            }
            continue;
        }
 
        if (sz[name[u]] > sz[name[v]])  {
            merge(u, v, d);
        }
        else {
            merge(v, u, -d);
        }
    }
 
    cout << "Yes";
 
    return 0;
 
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
typedef vector<vector<int>> Graph;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

ll grid[3100][3100];
int sum[3100][3100];

int main()
{
    ios::sync_with_stdio(false);

    int N, K;
    cin >> N >> K;

    rep(i, N) {
        int X, Y;
        char C;
        cin >> X >> Y >> C;

        int c = ((X/K) + (Y/K))%2;
        int x = X%K, y = Y%K;

        if (C == 'B') {
            if (c == 0) {
                grid[x][y]++;
                grid[x+K][y+K]++;
                grid[x+2*K][y+2*K]++;
                grid[x][y+2*K]++;
                grid[x+2*K][y]++;
            } else {
                grid[x+K][y]++;
                grid[x][y+K]++;
                grid[x+K][y+2*K]++;
                grid[x+2*K][y+K]++;
            }
        } else {
            if (c == 1) {
                grid[x][y]++;
                grid[x+K][y+K]++;
                grid[x+2*K][y+2*K]++;
                grid[x][y+2*K]++;
                grid[x+2*K][y]++;

            } else {
                grid[x+K][y]++;
                grid[x][y+K]++;
                grid[x+K][y+2*K]++;
                grid[x+2*K][y+K]++;
            }
        }
    }

#ifdef DEBUG
        rep(i, 2*K) {
            rep(j, 2*K) {
                cout << grid[j][i] << " ";
            }
            cout << endl;
    }
#endif

    rep(x, 3*K) rep(y, 3*K) sum[x+1][y+1] = grid[x][y] + sum[x][y+1] + sum[x+1][y] - sum[x][y];

    int ans = 0;
    for (int sx=0; sx<=2*K; sx++) {
        for (int sy=0; sy<=2*K; sy++) {
            int tmp = 0;
            tmp += sum[sx+K][sy+K] + sum[sx][sy] - sum[sx+K][sy] - sum[sx][sy+K];
            ans = max(ans, tmp);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 110848
#include<bits/stdc++.h> 
using namespace std; 
#define lc (x<<1)  
#define rc (x<<1|1)  
#define mid (l+r)/2  
int const N=3e5+10; 
int t[N<<2],n,a[N],k;  
int query(int x,int l,int r,int ll,int rr){
	if(ll<=l && r<=rr) return t[x];  
	if(rr<=mid) return query(lc,l,mid,ll,rr);  
	else if(ll>mid) return query(rc,mid+1,r,ll,rr);  
	else return  max(query(lc,l,mid,ll,rr),query(rc,mid+1,r,ll,rr));   
}
void update(int x,int l,int r,int p,int v){
	if(l==r){
		t[x]=max(t[x],v);  
		return ; 
	}  
	if(p<=mid) update(lc,l,mid,p,v); 
	else update(rc,mid+1,r,p,v);  
	t[x]=max(t[lc],t[rc]);  
}
int main(){
	ios::sync_with_stdio(false);  
	cin.tie(0); 
	cin>>n>>k; 
	for(int i=1;i<=n;i++)
		cin>>a[i];
	int ans=0;    
	for(int i=1;i<=n;i++){
		int Min=a[i]-k; 
		int Max=a[i]+k;  
		if(Min<0) Min=0; 
		if(Max>300000)  Max=300000; 
		int nw=query(1,0,3e5,Min,Max)+1;  
		update(1,0,3e5,a[i],nw);  
		ans=max(ans,nw);   
	}   
	cout<<ans<<'\n'; 
	return 0; 
} 


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

int main(){
    int ans = 0;

    for(int i = 0 ; i < 5 ; ++i){
        int n;
        cin >> n;
        ans += max(n, 40);
    }

    ans /= 5;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3076
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

#include <vector>
#include <stdio.h>
#include <iostream>
#include <unordered_set>
#include <algorithm>
#include <bitset>
#include <set>
#include <map>
#include <random>
#include <time.h>
#include <cassert>

#define prev askdnsajd
#define rank asasdmdnasd
#define next lsjndajbs
#define hash asmdklansd
#define index asdklnas
#define right sld
#define left sldl
using namespace std;

typedef long long ll;
typedef long double dbl;

template<class T>
void print(vector<T> s){
    for (T x : s)
        cout << x << " ";
    cout << endl;
}

void solve(){

}

int main(){
    srand(17);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("a.in", "r", stdin);
    int n;
    cin >> n;
    vector<int> s(n);
    for (int i = 0; i < n; i++)
        cin >> s[i];
    int cnt = 0;
    for (int i = 1; i < n - 1; i++){
        int a = 0, b = 0;
        if (s[i] > s[i - 1])
            a++;
        else
            b++;
        if (s[i] > s[i + 1])
            a++;
        else
            b++;
        if (a == b)
            cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
/*

*/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define LL long long 
using namespace std;
const int MAXN = 1e6 + 10, INF = 1e9 + 10;
inline LL read() {
	char c = getchar(); LL x = 0, f = 1;
	while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * f;
}
int N;
char s[MAXN];
int check(char x, int len) {
	int pre = 0, res = len;
	for(int i = 1; i <= N; i++) {
		if(s[i] == x) {
			if(i - pre - 1 > len) return 0;
			pre = i;
		}
	}
	res -= N - pre;
	return res >= 0;
}
int calc(char x) {
	int l = 0, r = N, ans = N;
	while(l <= r) {
		int mid = l + r >> 1;
		if(check(x, mid)) r = mid - 1, ans = mid;
		else l = mid + 1;
	}
	return ans;
}
main() {
	scanf("%s", s + 1);
	N = strlen(s + 1);
	int ans = INF;
	for(char i = 'z'; i >= 'a'; i--) 
		ans = min(ans, calc(i));
	printf("%d", ans);
	return 0;
}
/*
1
12 11
*/

Measured memory_bytes: 256
object Main{
  def main(args: Array[String]){
    if (sys.env.getOrElse("TEST", "")=="1"){
      println(test());
    }else{
      val input=io.Source.stdin.getLines().mkString("\n");
      println(solve(input).trim());
    }
  }
 
  def solve(input:String):String={
    val List(n,y)=input.split(" ").map(_.toInt).toList;
    for (a <- 0 to n){
      for (b <- 0 to n-a){
        val c=n-a-b;
        if(a*10000+b*5000+c*1000==y){
          return s"${a} ${b} ${c}";
        }
      }
    }

    "-1 -1 -1"
  }
 
  val tests=List("""9 45000""" -> """0 9 0""",
    """20 196000""" -> """-1 -1 -1""",
"""1000 1234000"""->"""14 27 959""",
"""2000 20000000"""->"""2000 0 0""");
 
  def test():String= {
    return tests.map{case (i,o)=>(i.trim(),o.trim())}.zipWithIndex.map{case ((input,outputExpect),i)=>{
      val output=solve(input).trim();
      s"test${i+1}:"+(if(output==outputExpect){
        "Passed"
      }else{
        s"Failed\nexpect:\n${outputExpect}\noutput:\n${output}"
      })
    }}.mkString("\n");
  }
}

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

#define ll long long int
#define pb                 push_back
#define T int time;        scanf("%d", &time); while(time--)
#define all(x)             x.begin(), x.end()
#define fill(a, b)         memset(a, b, sizeof(a))
#define mp                 make_pair
#define fst                first
#define snd                second
#define filein             freopen("input.txt", "r", stdin);
#define fileout            freopen("output.txt", "w", stdout);
int main(){
     int a,b,c;
	cin>>a>>b>>c;
	if(a==b and a!=c)cout<<"Yes"<<endl;
	else if(a==c and a!=b)cout<<"Yes"<<endl;
	else if(b==c and c!=a)cout<<"Yes"<<endl;

	else cout<<"No"<<endl;

}



Measured memory_bytes: 256