akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>


/*
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <ctype.h>
*/



using namespace std;

typedef pair<int , int > pii;
typedef pair<long , long> pll;
typedef pair<pii , int > piii;
typedef pair<pll , long > plll;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector <pii> vii;
typedef vector<pll> vll;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef unsigned long long int ulli;
typedef long long int lli;
typedef double d;
typedef float f;
typedef string s;
typedef char ch;
typedef pair<int,ll> pill;

#define loop(n) for(int i = 0; i < (n); i++)
#define lp(x , s , e) for(int x = (s); x < (e); x++)
#define lpe(x , s , e) for(int x = (s); x <= (e); x++)
#define readline(s) getline(cin,s)
#define NumofDigits(n) ((int)log10(n)+1)
#define CountofNumber(array,n,x)  (upper_bound(array, array+n, x)-lower_bound(array, array+n, x))
#define F first
#define S second
#define EPS 1e-7
#define modulo ll (1e9 + 7)
const long double PI = 3.141592653589793238L;
#define MP make_pair
#define PB push_back
#define all(a) a.begin(),a.end()
#define clr(x , val) memset((x) , (val) , sizeof(x))
#define endl '\n'

ll power(ll a, ll b)
{
    ll res = 1;
    for(int i = 0; i<b; i++)
       res *= a;

    return res;
}


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int s , w;
    cin >> s >> w;
    if (w >= s)
    	cout << "unsafe" << endl;
    else
    	cout << "safe" << endl;
    return 0;
}


Measured memory_bytes: 3600
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int ans = a * b;

        if (ans % 2 == 0){
            System.out.println("Even");
        } else {
            System.out.println("Odd");
        }

    }
}


Measured memory_bytes: 23764
MOD = 10**9 + 7

N = int(input())
A = list(map(int, input().split()))

num_per_digit = [0]*60

for i in range(60):
    num = 0
    for j,a in enumerate(A):
        num += a % 2
        A[j] //= 2
    num_per_digit[i] = num

result = 0    
for d,num in enumerate(num_per_digit):
    result = (result + num * (N - num) * pow(2, d, MOD)) % MOD
    
print(result)

Measured memory_bytes: 117824
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

C.append(0)

ans = sum(B)
for i in range(N-1):
    if A[i+1]-A[i] == 1:
        ans = ans + C[A[i]-1]
print(ans)

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

using namespace std;

template<typename T>
T gcd(const T& a, const T& b)
{
    if (a < b) {
        return gcd(b, a);
    }
    const T r = a % b;
    if (r == 0) {
        return b;
    }
    return gcd(b, r);
}

int main()
{
    int64_t A, B;
    cin >> A >> B;
    auto d = gcd(A, B);
    const auto sqrt_d = static_cast<int64_t>(sqrt(d) + 1);
    // printf("d=%d, sqrt_d=%d\n", d, sqrt_d);
    int64_t ans = 1;
    for (int64_t i = 2; i <= sqrt_d; ++i) {
        if (d % i == 0) {
            ++ans;
            while (d % i == 0) {
                d /= i;
            }
        }
    }

    if (d != 1) {
        ++ans;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int flag,n,A[2000],M[2000];

void solve(int i,int m){
  if(m==0) flag=1;
  else if(i <= n){
    solve(i+1,m-A[i]);
    solve(i+1,m);
  }
}

int main(){
  int i,q;

  scanf("%d",&n);
  // if(n>20)printf("範囲外\n");

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

  scanf("%d",&q);
  // if(q>20)printf("範囲外\n");

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

  for(i=0 ; i<q ; i++){
    flag = 0;
    solve(0,M[i]);
    if(flag==1){
      printf("yes\n");
    }
    else printf("no\n");
    
  }

  return 0;
}

Measured memory_bytes: 588
import java.util.Arrays;
import java.util.Scanner;

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

    void solve(Scanner sc) {
        int n = sc.nextInt();
        int ma = sc.nextInt();
        int mb = sc.nextInt();

        int[][][] dp = new int[n + 1][10 * n + 1][10 * n + 1];
        int INF = 50 * 100;
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= 10 * n; j++) {
                Arrays.fill(dp[i][j], INF);
            }
        }
        dp[0][0][0] = 0;

        for (int i = 1; i <= n; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            for (int j = 0; j <= 10 * n; j++) {
                for (int k = 0; k <= 10 * n; k++) {
                    dp[i][j][k] = dp[i - 1][j][k];
                    if (j - a >= 0 && k - b >= 0) {
                        dp[i][j][k] = Math.min(dp[i][j][k], dp[i - 1][j - a][k - b] + c);
                    }
                }
            }
        }

        int i = 1;
        int ans = INF;
        while (i * ma <= 10 * n && i * mb <= 10 * n) {
            ans = Math.min(ans, dp[n][i * ma][i * mb]);
            i++;
        }
        System.out.println(ans == INF ? -1 : ans);
    }
}


Measured memory_bytes: 54612
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
A.sort()
lim = A[-1]+1
B = [0] * lim
U = list(set(A))
C = Counter(A)

for a in U:
    if C[a] > 1:
        B[a] = 1
    for i in range(a*2, lim, a):
        B[i] = 1

ans = 0
for a in A:
    if B[a] == 0:
        ans += 1

print(ans)

Measured memory_bytes: 47340
#include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    #define SF scanf
    #define PF printf
    #define MAXN 100010
    using namespace std;
    typedef long long ll;
    int n;
    ll a,b,c,d;
    ll gcd(ll x,ll y){
        if(y==0)
            return x;
        return gcd(y,x%y);
    }
    int main(){
        SF("%d",&n);
        while(n--){
            SF("%lld%lld%lld%lld",&a,&b,&c,&d);
            if(a<b){
                PF("No\n");
                continue;
            }
            if(b>d){
                PF("No\n");
                continue;
            }
            if(c+1>=b){
                PF("Yes\n");
                continue;
            }
            ll g=gcd(b,d);
            if((a-c-1ll)/g-(a-b)/g>0)
                PF("No\n");
            else
                PF("Yes\n");
        }
    } 

Measured memory_bytes: 128
N = int(input())
src = list(map(int,input().split()))
ks = [0] * 9
for r in src:
    if r >= 3200:
        ks[-1] += 1
    else:
        ks[r//400] += 1
c = len([k for k in ks[:-1] if k])
mn = max(1, c)
mx = c + ks[-1]
print(mn,mx)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
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;}
const int inf = 1001001001;

int main() {
    ll n;
    cin >> n;
    ll ans = 1;
    for(ll i = 1; i*i <= n; i++) {
        if (n % i == 0) chmax(ans, i);
    }
    cout << ans+(n/ans)-2 << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

MOD = 10 ** 9 + 7


def main():
    N, M = map(int, input().split())
    memo = [0] * max((N + 1), 10)
    a = [0] * M

    memo[0] = 1
    memo[1] = 1
    memo[2] = 2
    for i in range(3, max(N+1, 10)):
        memo[i] = memo[i-1] + memo[i-2]

    # print(memo)
    ans = 1

    for i in range(M):
        a[i] = int(input())

        if i != 0 and abs(a[i] - a[i-1]) == 1:
            print(0)
            return

        if a[i] == 1:
            ans *= 1
        elif i == 0:
            ans *= memo[a[i] - 1]
            ans %= MOD
            # print(a[i], ans, a[i] - 1)
        else:
            ans *= memo[a[i] - a[i-1] - 2]
            ans %= MOD
            # print(a[i], ans, a[i] - a[i-1] - 2)

    if M == 0:
        ans *= memo[N]
        ans %= MOD
        # print(ans, N - a[M-1] - 1)
        print(ans)
    else:
        ans *= memo[N - a[M-1] - 1]
        ans %= MOD
        # print(ans, N - a[M-1] - 1)
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 474616
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int A = scanner.nextInt();
		if (N % 500 > A) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define PB push_back
#define rep(i, a, b) for(ll i = ll(a); i <= ll(b); i++)
vector<vector<ll> > V;
ll P[5005];
ll C[5005];
ll n, k;
ll vis[5005];
signed main() {
	cin >> n >> k;
	rep(i, 1, n)cin >> P[i];
	rep(i, 1, n)cin >> C[i];
	memset(vis, 0, sizeof(vis));
	rep(i, 1, n)if(!vis[i]) {
		ll x = i;
		x = P[x];
		vector<ll> k;
		k.PB(i);
		while(x != i) {
			k.PB(x);
			x = P[x];
		} 
		for(int i = 0; i < k.size(); i++)vis[k[i]] = 1;
		
		V.PB(k);
	}
//	for(ll i = 0; i < V.size(); i++) {
//		printf("%d:\n", i);
//		for(ll j = 0; j < V[i].size(); j++) {
//			printf("%d ", V[i][j]);
//		}
//		puts("");
//	}
	ll Ans = -1e18;
	for(ll i = 0; i < V.size(); i++) {
		vector<ll> t = V[i]; 
		ll len = t.size();
		for(ll r = 0; r < len; r++) {
			vector<ll> S(len + 5);
			for(int j = 0; j < len; j++)S[j + 1] = S[j] + C[t[j]];
			for(int j = 0; j < len; j++){
				ll l1;
				if(j != 0)l1 = 0;
				else l1 = 1;
				ll l2 = (k + len - j) / len - 1;
				if(l1 > l2)continue;
				ll d;
				if(S[len] > 0) {
					d = l2;
				}
				else d = l1;
				ll res = S[len] * d + S[j];
				Ans = max(Ans, res);
			}
			rotate(t.begin(), t.begin() + 1, t.end());
		} 
	}
	cout << Ans << endl;
	return 0;
} 

Measured memory_bytes: 3876
///mAAria...
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
typedef pair<int,int> pii;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define inf 1000000000

const long double PI = acos(-1);

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

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

void solve(){

    int n,k,q;
    cin >> n >> k >> q;

    map<int,int> m;

    for(int i = 1;i<=n;i++)m[i] = 0;

    for(int i = 1;i<=q;i++){
        int a;
        cin >> a;
        m[a]++;
    }

    for(auto i:m){
        int temp = q-i.second;
        temp = k-temp;
        m[i.first] = temp; 

    }

    for(int i = 1;i<=n;i++){
    if(m[i]>0)cout << "Yes" << endl;
    else cout << "No" << endl;
    }
} 

signed main() 
{   
    IOS;
    int t = 1;
    //cin >> t;

    for(int i = 1;i<=t;i++){
        solve();
    }
    return 0;
} 

 


Measured memory_bytes: 6912
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

int a, b, c;
int main()
{
	cin >> a >> b >> c;
	if (a + b >= c) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#define REP(i,n) for (long i=0;i<(n);i++)
#define FOR(i,a,b) for (long i=(a);i<(b);i++)
#define RREP(i,n) for(long i=n;i>=0;i--)
#define RFOR(i,a,b) for(long i=(a);i>(b);i--)
#define dump1d_arr(array) REP(i,array.size()) cerr << #array << "[" << (i) << "] ==> " << (array[i]) << endl;
#define dump2d_arr(array) REP(i,array.size()) REP(j,array[i].size()) cerr << #array << "[" << (i) << "]" << "[" << (j) << "] ==> " << (array[i][j]) << endl;
#define dump(x)  cerr << #x << " => " << (x) << endl;
#define CLR(vec) { REP(i,vec.size()) vec[i] = 0; } 
#define llINF (long long) 9223372036854775807
#define loINF (long) 2147483647
#define shINF (short) 32767
#define SORT(c) sort((c).begin(),(c).end())

using namespace std;
typedef vector<long> VI;
typedef vector<VI> VVI;
typedef pair<long,long> pr;
struct Order {
	bool operator() (pr const& a,pr const& b) const {
		return a.first > b.first || ((a.first == b.first) && (a.second > b.second));
	}
};
typedef priority_queue<pr,vector<pr>,Order> pq;
struct edge {long to,cap,dis,rev;};

class Primal_dual {
private:
	vector<vector<edge>> E;
	vector<long> pt;	
	vector<long> dist;
	vector<pr> prev; // 直前の頂点
	size_t V;
public:
	Primal_dual() : V(0) { }
	Primal_dual(size_t v) :
		E(v,vector<edge>(0)),pt(v,0),prev(v),dist(v),V(v){ }

	size_t size() { return V; }

	void add_edge(long from,long to,long cap,long dis){
		E[from].push_back({to,cap,dis,(long)E[to].size()});
		E[to].push_back({from,0,-dis,(long)E[from].size()-1});
	}

	short dijekstra(long start,long goal){
		pq que;
		REP(i,V) dist[i] = 2147483647;
		dist[start] = 0;
		que.push(pr(0,start));

		while (! que.empty()){
			pr next = que.top();
			que.pop();
			long next_v = next.second;

			if (dist[next_v] < next.first) continue; //既により最適が見つかっている

			REP(i,E[next_v].size()){
				edge* e = &E[next_v][i];

				if (e->cap > 0 && dist[e->to] > (dist[next_v] + e->dis + pt[next_v] - pt[e->to])){
					dist[e->to] =  (dist[next_v] + e->dis + pt[next_v] - pt[e->to]);
					prev[e->to] = {next_v,i};
					que.push(pr(dist[e->to],e->to));
				}
			}
		}

		if (dist[goal] == 2147483647) return 1;
		else return 0;
	}

	long min_cost_flow(long start,long goal,long F){
		long sum_cost = 0;
		while (F > 0){
			if (dijekstra(start,goal)) return (-1); //流量Fは流せない
			REP(i,V) pt[i] += dist[i]; //potentialの更新

			long flow = F;
			for (long node = goal;node != start;node = prev[node].first){
				flow = min(flow,E[prev[node].first][prev[node].second].cap); //今回のフロー量を決定
			}
			F -= flow;
			sum_cost += (flow * pt[goal]);

			for (long node = goal;node != start;node = prev[node].first) {
				edge* e = &E[prev[node].first][prev[node].second]; //使った辺の情報
				e->cap -= flow;
				E[node][e->rev].cap += flow;
			}
		}
		return sum_cost;
	}
};

int main(void){
	long V,E,F;
	cin >> V >> E >> F;

	Primal_dual pd(V);

	long u,v,c,d;
	REP(i,E){
		cin >> u >> v >> c >> d;
		pd.add_edge(u,v,c,d);
	}

	cout << pd.min_cost_flow(0,V-1,F) << endl;
}










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

using namespace std;
#define REPP(i,a,b,c) for(int i=a; i<=b; i+=c)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,c) for(int i=a; i>=b; i-=c)
#define REV(i,a,b) REVV(i,a,b,1)
#define FOR(i,a) REP(i,0,(int)a-1)
#define FORD(i,a) REV(i,(int)a-1,0)
#define PB push_back
#define POB pop_back
#define FI first
#define SE second
#define MP make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef vector < int > vi;
typedef vector < pii > vii;
typedef vector < ll > vl;
typedef pair < ll , ll > pll;

const double PI = acos(-1);
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;
const int INF = 1e9;
	

ll addMod(ll a, ll b){
	if(a + b >= MOD) return a + b - MOD;
	return a + b;
}

ll mulMod(ll a, ll b){
	return (a*b)%MOD;
}

ll fast(ll a, ll b){
	if(b == 0) return 1;
	ll tmp = fast(a,b/2);
	tmp = mulMod(tmp,tmp);
	if(b%2 == 1) tmp = mulMod(tmp,a);
	return tmp;
}

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

#define getc getchar
template<typename T>
T getnum(){
	int sign = 1;
	T ret = 0;
	char c;

	do{
		c = getc();
	}while(c == ' ' || c == '\n');
	if(c == '-')sign = -1;
	else ret = c-'0';
	while(1){
		c = getc();
		if(c < '0' || c > '9')break;
		ret = 10*ret + c-'0';
	}
	return sign * ret;
}

inline void ini(int& x){
	x = getnum<int>();
}

//////////////////////////////////////////////

const int N = 1e5;

int arr[N + 5];
int cnt[N + 5];

int main(){
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n; cin >> n;
	REP(i,1,n) cin >> arr[i];
	ll ans = 1;
	int cnt0 = 0;
	REP(i,1,n){
		if(arr[i] > 0){
			ans = mulMod(ans,cnt[arr[i]-1]);
			cnt[arr[i]-1]--;
		}
		else ans = mulMod(ans,3-cnt0), cnt0++;
		cnt[arr[i]]++;
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int a,v;
  cin>>a>>v;
  int b,w;
  cin>>b>>w;
  int t;
  cin>>t;
  
  int res=1;
  
  	if(w>=v)
  	res=0;
  	else
  	{
  		int relative_velocity=v-w;
  		int dist=abs(b-a);
  		double time_taken=double(dist)/double(relative_velocity);
  		if(time_taken<=t)
  		res=1;
  		else res=0;
  		
  	}
  
  if(res)
  cout<<"YES"<<endl;
  else
  cout<<"NO"<<endl;
  
  
}


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

import math
x = int(input())

#aもbも0以上のとき
border = 1;
while border ** 5 - (border - 1) ** 5 < x:
    border += 1

for i in range(border + 1):
    aa = ((x + i ** 5) ** (1.0 / 5.0)) #仮
    a = round(aa)
    if a ** 5 - i ** 5 == x:
        b = i
        print(a, b)
        break
else:
    b = -1

    while x + b ** 5 >= 0:

        aa = ((x + b ** 5) ** (1.0 / 5.0))  # 仮
        a = round(aa)
        if a ** 5 - b ** 5 == x:
            print(a, b)
            break
        b -= 1


Measured memory_bytes: 9316
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	int n;
	cin>>n;
	if(n%2==0){
		cout<<n/2<<endl; 	
	}else{
		cout<<n/2+1<<endl;
	}
	return 0;
}


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

int main() {
  string S; cin >> S;
  int N = S.size();
  long sum = 0;
  for (long p = (1<<(N-1)); p < (1<<N); p++) {
    long a = 0, b = 0;
    for (int i = 0; i < N; i++) {
      b = b * 10 + (S[i] - '0');
      if (p & (1<<i)) {
        a += b; b = 0;
      }
    }
    sum += a;
  }
  cout << sum << endl;
}

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

int main()
{
    int R,G,B,N;
    cin >> R >> G >> B >> N;

    int ans=0;
    for(int r=0;r<=N;++r)
    {
        for(int g=0;g<=N;++g)
        {
            int b = (N-r*R-g*G)/B;
            if (0<=b&&(r*R+g*G+b*B)==N)
            {
                ans++;
            }
        }
    }
    cout << ans << endl;
}


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

int main() {
    ll n;
    cin >> n;

    vector<ll> a(n+1);
    ll sum = 0;
    rep(i, n+1) { cin >> a[i]; sum += a[i]; }

    ll ans = 0;
    ll lim = 1;
    rep(i, n+1) {
        ans += lim;
        //printf("ans=%d, sum=%d, lim=%d\n", ans, sum, lim);
        sum -= a[i];
        lim = min((lim-a[i])*2, sum);
        if (lim < 0) {
            ans = -1; break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 4016
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int N;cin>>N;
	int t = N;
	int divisor = 0;
	while(t != 0){
		divisor += t%10;
		t /= 10;
	}
	cout<<((N%divisor == 0)?"Yes":"No")<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
using namespace std;
int dp[1<<11][11][333];
int solve(int bit,int i,int sum){
  if(i>=11) return 0;
  if(sum>330) return 0;
  if(!i) return (sum)?0:1;
  if(dp[bit][i][sum] >= 0) return dp[bit][i][sum];
  int ret = 0;
  for(int j = 0; j < 10; j++){
    if(bit & 1<<j) continue;
    ret += solve(bit | 1<<j,i-1,sum-j*i);
  }
  return dp[bit][i][sum] = ret;
}
int main(void){
  int n,s;
  memset(dp,-1,sizeof(dp));
  while(cin >> n >> s){
    cout << solve(0,n,s) << endl;
  }
}

Measured memory_bytes: 30472
#include <iostream>
#include <string.h>

using namespace std;

int main()
{
  char s[100], p[100], s2[200];
  cin >> s >> p ;
  strcpy(s2 ,s);
  strcat(s2 ,s);

  if (strstr(s2, p) != NULL) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 3096
// Problem : F - Contrast
// Contest : AtCoder - AtCoder Beginner Contest 178
// URL : https://atcoder.jp/contests/abc178/tasks/abc178_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
using namespace std;

/* DEBUGGING */
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif

/* MACROS */ 
typedef long long int ll;
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

typedef map<int,int> mii;

#define  ff          first
#define  ss          second
#define  pb          push_back
#define  IOS         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  lb          lower_bound
#define  ub          upper_bound
#define  all(x)      (x).begin(), (x).end()
#define  lcm(x, y)   ((x) * (y) / __gcd(x, y))
#define  ps(x,y)     fixed<<setprecision(y)<<x
#define  setbit(x)   __builtin_popcountll(x)
#define  rep(i,a,b)  for(int i=a ; i<b ; ++i)
#define  repr(i,a,b) for(int i=a ; i>=b ; --i)

/* CONSTANTS */ 
#define PI 3.141592653589793
const ll MOD = 1e9 + 7;
const ll INF = 1000000000;
const ll MAX_N = 2e5 + 2;

// #define cerr if(false)cerr
/* CODE STARTS HERE */

void solve(){
    int n; cin >> n;
    
    vi v1(n),v2(n);
    
    rep(i,0,n) cin >> v1[i];
    rep(i,0,n) cin >> v2[i];
    
    reverse(all(v2));
    
    int bk = n-1,ft = 0;
    
    rep(i,0,n){
        int curr = v1[i];
        bk = n-1,ft = 0;
        
        while(i<n && v1[i]==curr){
            if(v1[i]==v2[i]){
                if(ft<i && v1[i]!=v2[ft] && v2[i]!=v1[ft]) swap(v2[i],v2[ft]), ft++;
                else if(bk>i && v1[i]!=v2[bk] && v2[i]!=v1[bk]) swap(v2[i],v2[bk]), bk--;
                else{cout << "No"; return;}
            }
            
            i++;
        }
        
        i--;
    }
    
    cout << "Yes\n";
    for(auto x:v2) cout << x << " ";
}

int main(){
    IOS;
    solve();
}


Measured memory_bytes: 4760
#include<iostream>
#include<math.h>
using namespace std;
bool Isprime(int n){
  for(int i =2;i<=sqrt(n);i++){
    if(n%i==0)return false;
  }
  return true;
}
int main(){
  int n;
  cin >>n;
  int count =0;
  for(int i =0;i<n;i++){
    int a;
    cin >>a;
    if(Isprime(a)){
      count++;
    }
  }
  cout <<count<<endl;
  return 0;
}



Measured memory_bytes: 3072
package main

import (
	"bufio"
	"fmt"
	"os"
)

var stdin = bufio.NewScanner(os.Stdin)

func main() {
	stdin.Scan()
	s := stdin.Text()
	stdin.Scan()
	t := stdin.Text()
	c := 0
	for index := 0; index < 3; index++ {
		if s[index] == t[index] {
			c++
		}
	}
	fmt.Println(c)
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <stdint.h>
using namespace std;
typedef long long ll;

int main(void){
    uint64_t n, k, a[1005], s[1005];
    cin >> n >> k;
    s[0] = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        s[i + 1] = s[i] + a[i];
    }
    
    vector<uint64_t> sum[40];
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j <= n; j++) {
            sum[0].push_back(s[j] - s[i]);
        }
    }
    
    /*
    sort(sum[0].begin(), sum[0].end());
    for (int i = 0; i < sum[0].size(); i++) {
        cout << showbase << bitset<40>(sum[0][i]) << endl;
    }*/
    
    
    //sort(sum.begin(), sum.end());
    
    uint64_t ans = 0, idx = 0;
    for (int i = 39; i >= 0; i--) {
        int cnt = 0;
        for (int j = 0; j < sum[idx].size(); j++) {
            if ((sum[idx][j] & (static_cast<uint64_t>(1) << i)) > 0) cnt++;
        }
        /*cout << i << " " << cnt << endl;
        //cout << cnt << endl;
        cout << i << " ";
        for (int j = 0; j < sum[idx].size(); j++) cout << sum[idx][j] << " ";
        cout << endl;*/
        
        if (cnt >= k) {
            for (int j = 0; j < sum[idx].size(); j++) {
                if (sum[idx][j] & (static_cast<uint64_t>(1) << i)) {
                    sum[idx + 1].push_back(sum[idx][j]);
                }
            }
            idx++;
            ans = ans + (static_cast<uint64_t>(1) << i);
        }
    }
    
    cout << ans << endl;
    
}


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

const int inf = 1e9;
const ll linf = 1e18;

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

    string s, t; cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());
    cout << ((s < t) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 764
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;

int main(void) {
	string s;
	cin >> s;
	while(s.length()>1){
		s.erase(s.length()-2, s.length());
		int flag=0;
		for(int i=0; i<s.length()/2-1; i++){
			if(s[i]!=s[s.length()/2+i]){
				flag=1;
				break;
			}
		}
		if(!flag){
			cout << s.length() << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect


def zz():
    return list(map(int, input().split()))


def z():
    return int(input())


def S():
    return input()


def C(line):
    return [input() for _ in range(line)]


N = z()
S = S()
wester = [0] * N
west_sum = 0
easter = [0] * N
sum_ = [0]*N
east_sum = S.count('E')
for i, s in enumerate(S):
    wester[i] = west_sum
    if (s == 'W'):
        west_sum += 1
    else:
        east_sum -= 1
    easter[i] = east_sum
    sum_[i] = wester[i] + easter[i]
# print(wester)
# print(easter)
print(min(sum_))


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

using namespace std;

#define ll long long
#define pii pair<int, int>
#define MAX 105

int C[MAX], W[MAX];
ll dp[MAX][100005];

int main() {

    int n, w;
    cin >> n >> w;

    for(int i = 1; i <= n; i++) cin >> W[i] >> C[i];


    for(int i = 1; i <= n; i++) {
        for(int j = 0; j <= w; j++) {
            if(j - W[i] >= 0) {
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - W[i]] + C[i]);
            }
            else dp[i][j] = dp[i - 1][j];
        }

    }

    cout << dp[n][w] << '\n';

    return 0;
}


Measured memory_bytes: 79360
#include <iostream>
using namespace std;
 
int main() {
  int a,b,c,d;
  int ta = 0,ao = 0;
  cin >> a >> b >> c >> d;
  if(c%b != 0) ta = c/b+1;
  if(a%d != 0) ao = a/d+1;
  if (ta <= ao) cout << "Yes" << "\n";
  else cout << "No" << "\n";
  return 0;
}

Measured memory_bytes: 3596
import java.util.*

object MainKt {
    @JvmStatic
    fun main(args: Array<String>) {
        val scanner = Scanner(System.`in`)
        val n = scanner.nextInt()
        val T = scanner.nextInt()

        var min = -1
        for (i in 0..n-1){
            val c = scanner.nextInt()
            val t = scanner.nextInt()

            if (t<=T) {
                if (min==-1) min = c
                else min = Math.min(min, c)
            }
        }

        println(if(min==-1) "TLE" else min)

    }
}

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

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<vector<int>> cs(3, vector<int>(n + 1, 0));
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < n; j++) {
            if (s[j] == "RGB"[i]) cs[i][j]++;
            cs[i][j + 1] += cs[i][j];
        }
    }
    ll ans = 0;
    for (int i = 0; i < 3; i++) {
        for (int j = 1; j < n; j++) {
            for (int k = j + 1; k < n; k++) {
                if ("RGB"[i] == s[j]) continue;
                if ("RGB"[i] == s[k]) continue;
                if (s[j] == s[k]) continue;
                ans += cs[i][j];
                if (2 * j - k >= 0 && "RGB"[i] == s[2 * j - k]) ans--;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int X, A, B;

int main() {
  cin >> X >> A >> B;
  cout << (X - A) % B << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll g[3][2];
ll su=0;
ll dp[4][5005];

ll solve(ll n){
	int cnt=0;
	for(int i=0;i<3;i++){
		if(g[i][0]<g[i][1])cnt++;
	}
	if(cnt==0)return n;
	if(cnt==1){
		for(int i=0;i<3;i++){
			if(g[i][0]<g[i][1]){
				ll bo=n/g[i][0];
				return n+bo*(g[i][1]-g[i][0]);		
			}
		}
	}
	if(cnt==2){
		for(int i=0;i<3;i++){
			if(g[i][0]<g[i][1]){
				ll ans=n;
				for(ll j=0;j*g[i][0]<=n;j++){
					ll val=n+j*(g[i][1]-g[i][0]);
					ll rest=n-g[i][0]*j;
					for(int k=i+1;k<3;k++){
						if(g[k][0]<g[k][1]){
							ll bo=rest/g[k][0];
							ll val2=bo*(g[k][1]-g[k][0]);
							ans=max(ans,val+val2);
						}
					}
				}
				return ans;
			}
		}
	}
	if(cnt==3){
		dp[0][n]=n;
		for(int i=0;i<3;i++){
			for(int j=0;j<=n;j++){
				for(int k=0;k*g[i][0]<=j;k++){
					dp[i+1][j-k*g[i][0]]=max(dp[i+1][j-k*g[i][0]],dp[i][j]+k*(g[i][1]-g[i][0]));
				}
			}
		}
		ll ans=n;
		for(int i=0;i<=n;i++){
			ans=max(ans,dp[3][i]);
		}
		return ans;
	}
}

int main(void){
	int n;
	scanf("%d",&n);
	for(int i=0;i<2;i++){
		scanf("%lld%lld%lld",&g[0][i],&g[1][i],&g[2][i]);
	}
	ll ans=solve(n);
	//printf("%lld\n",ans);
	swap(g[0][0],g[0][1]);
	swap(g[1][0],g[1][1]);
	swap(g[2][0],g[2][1]);
	printf("%lld\n",solve(ans));
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10; //1e-9?
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int h = 100, w = 100;
    int a, b; cin >> a >> b;

    auto s = defvec<char>('#', h, w);
    int a_cnt = a - 1, b_cnt = b - 1;
    FOR(y, 0, h)s[y][w - 1] = '.';
    FOR(x, 0, w)s[h - 1][x] = '.';

    for (int y = 3; y < h - 1 && 0 < b_cnt; y += 4, --b_cnt) {
        FOR(x, 0, w)s[y][x] = '.';
    }
    for (int x = 3; x < w - 1 && 0 < b_cnt; x += 4) {
        for (int y = 0; y < h && 0 < b_cnt; ++y) {
            if (s[y][x] == '.')--b_cnt;
            else s[y][x] = '.';
        }
    }

    for (int y = 1; y < h && 0 < a_cnt; y += 4) {
        for (int x = 1; x < w && 0 < a_cnt; x += 4, --a_cnt) {
            s[y][x] = '.';
        }
    }

    cout << h << " " << w << "\n";
    FOR(y, 0, h) {
        FOR(x, 0, w)cout << s[y][x];
        cout << "\n";
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int main() {
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];

    deque<int> dq;
    int ans=1;
    dq.push_back(a[0]);
    for(int i=1;i<n;i++){
        int x=lower_bound(all(dq),a[i])-dq.begin();
        if(x==0){
            ans++;
            dq.push_front(a[i]);
        }
        else dq[x-1]=a[i];
        //cout<<x<<" "<<ans<<endl;
    }

    cout<<ans<<endl;
}

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

int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  for (int i = 0; i < n; ++i)
    scanf("%d", &a[i]);
  int ans = 0;
  for (int i = 1; i < n; ++i)
    if (a[i] == a[i - 1])
      a[i] = -1, ++ans;
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int arr[10000001];
int main()
{
    ll n;
    cin>>n;
    for(ll i=1;i<=n;i++){
        for(ll j=i;j<=n;j+=i) arr[j]++;
    }
    ll sum=0;
    for(ll i=1;i<=n;i++) sum+=i*arr[i];
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 42604
// E.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

typedef pair<int, int> II;

int main(int argc, char* argv[]) {
	int n;
	cin >> n;
	vector<vector<int>> dep(n, vector<int>(n));
	vector<vector<int>> ord(n, vector<int>(n - 1));
	vector<vector<int>> done(n, vector<int>(n));
	vector<int> index(n);
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n - 1; ++j) {
			int a;
			cin >> a;
			--a;
			ord[i][j] = a;
			if (j > 0) {
				dep[i][a] += 1;
				dep[a][i] += 1;
			}
		}
	}
	vector<II> q;
	for (int i = 0; i < n; ++i) {
		int a = ord[i][0];
		if (!dep[i][a]) {
			q.push_back(II(i, a));
		}
	}
	int rem = n * (n - 1);
	int ans = 0;
	while (q.size()) {
		++ans;
		vector<II> next;
		vector<int> u(n);
		for (const II& t : q) {
			int a = t.first;
			int b = t.second;
			if ((u[a] || u[b]) && !done[a][b]) {
				next.push_back(t);
				continue;
			}
			u[a] = 1;
			u[b] = 1;
			done[a][b] = 1;
			done[b][a] = 1;

			--rem;
			index[a] += 1;
			if (index[a] < n - 1) {
				int nb = ord[a][index[a]];
				dep[a][nb] -= 1;
				dep[nb][a] -= 1;
				if (dep[a][nb] <= 0) {
					next.push_back(II(a, nb));
				}
				if (dep[nb][a] <= 0) {
					next.push_back(II(nb, a));
				}
			}
		}
		q = next;
	}
	cout << (rem > 0 ? -1 : ans) << endl;
	return 0;
}


Measured memory_bytes: 12160
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int idx = 0;
  rep(i, n) {
    cin >> a[i];
    if (abs(a[i]) > abs(a[idx]))
      idx = i;
  }
  if (a[idx] > 0) {
    cout << (n-1)*2 << endl;
    cout << idx+1 << ' ' << 2 << endl;
    cout << idx+1 << ' ' << 2 << endl;
    for (int i = 2; i < n; i++) {
      cout << i << ' ' << i+1 << endl;
      cout << i << ' ' << i+1 << endl;
    }
  } else if (a[idx] < 0) {
    cout << (n-1)*2 << endl;
    cout << idx+1 << ' ' << n-1 << endl;
    cout << idx+1 << ' ' << n-1 << endl;
    for (int i = n-1; i > 1; i--) {
      cout << i << ' ' << i-1 << endl;
      cout << i << ' ' << i-1 << endl;
    }
  } else
    cout << 0 << endl;
  return 0;
}

Measured memory_bytes: 256
N = gets.to_i
s = N.times.map {
  gets.chomp.split(//).sort
}

s = s.group_by(&:itself).map {|k, v| [k, v.size]}

ans = s.inject(0) {|acc, (k, v)|
  next acc if v == 1
  acc + (v * (v - 1) / 2)
}

puts ans


Measured memory_bytes: 106748
def main():
    n = int(input())
    vv = list(map(int, input().split()))
    cc = list(map(int, input().split()))
    res = 0
    for v, c in zip(vv, cc):
        if v > c:
            res += v - c
    print(res)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;

struct UnionFind {
    UnionFind(int n) {
        parent.resize(n, -1);
        weight.resize(n, 0);
    }
    int find(int x) {
        if (parent[x] < 0)
            return x;
        else
            return parent[x] = find(parent[x]);
    }
    bool isSame(int x, int y) { return find(x) == find(y); }
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) {
            weight[x]++;
            return;
        }
        if (parent[x] < parent[y])
            swap(x, y);
        parent[x] += parent[y];
        parent[y] = x;
        weight[x] += weight[y] + 1;
    }
    int getSize(int x) { return -parent[find(x)]; }
    int getWeight(int x) { return weight[find(x)]; }

private:
    vector<int> parent;
    vector<int> weight;
};

int main() {
    int N, M;
    cin >> N >> M;
    UnionFind uf(N);
    for (int i = 0; i < M; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        x--;
        y--;
        uf.unite(x, y);
    }

    set<int> p;
    for (int i = 0; i < N; i++) {
        p.insert(uf.find(i));
    }
    cout << p.size() << endl;
}


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

int main(){
	double x1,y1,x2,y2; cin >> x1 >> y1 >> x2 >> y2;
	cout << fixed << setprecision(8) << sqrt(pow(x1-x2,2.0)+pow(y1-y2,2.0)) << endl;
	return 0;
}

Measured memory_bytes: 3244
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };

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

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b, ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}
	int size(int a) {
		return par[root(a)];
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};


int main() {
	int x, y;
	cin >> x >> y;
	if ((x + y) % 3 == 0) {
		int z = (x + y) / 3;
		int m=z * 2;
		if (x <= m) {
			int n = m - x;
			if ((z - n) + n * 2 == y) {
				ll ans = c(z, n, mod);
				cout << ans << endl;
				return 0;
			}

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

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 2000


int main(){
	int a[N];
	f(i, N)a[i] = 0;
	int n, k;
	int x, y, z;
	long long s, ans;
	bool v = true;
	ans = 0;
	scanf("%d %d", &n,&k);
	f(i, n){
		scanf("%d", &y);
		f(j, y){
			scanf("%d", &x);
			a[x - 1]++;
		}
	}
	f(i, k){
		if (a[i] == n)ans++;
	}

	printf("%lld\n", ans);


	return 0;
}


Measured memory_bytes: 128
import sys
import math
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")
n=int(input())
a=list(map(int,input().split()))
cnt=0
i=0
j=0
tmp=0
while(i<n):
    while(j<n):
        if tmp&a[j]==0:
            tmp+=a[j]
            cnt+=j-i+1
            # print(str(i)+" "+str(j))
        else:
            break
        j+=1
    tmp^=a[i]
    i+=1
print(cnt)

Measured memory_bytes: 73072
#include <bits/stdc++.h>
using namespace std;
 
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
 
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
 
#define forn(i,n) for(int i=0;i<(int)n;i++)
#define forab(i,a,b) for(int i=a;i<=b;i++)
#define all(x) x.begin(),x.end()
#define trav(i,x) for(auto& i:x)
#define endl cout<<"\n";
const int mod = 1e9+7;
 
int main()
{
 
    FAST_IO;
    string s;
    cin>>s;
    if(s[s.size()-1]=='s')
		cout<<(s+"es");
	else
		cout<<(s+"s");
	return 0;
}


Measured memory_bytes: 3652
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))

def main():
    n, m = MII()
    food = set(MII()[1:])
    for i in range(n-1):
        a = MII()[1:]
        food &= set(a)
    print(len(food))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
N,M,X = map(int,input().split())
A = list(map(int,input().split()))
Rcnt = 0
Lcnt = 0
for i in range(X,N+1):
    if i in A:
        Rcnt += 1
for i in range(X):
    if i in A:
        Lcnt += 1

print(min(Lcnt,Rcnt))

Measured memory_bytes: 3060
import sys
import numpy as np
from numba import njit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

U = 10**6 + 10

@njit('(i8[::1],i8[::1])', cache=True)
def solve(A, primes):
    B = np.zeros(U + 1, np.int64)
    for x in A:
        B[x] += 1
    for p in primes:
        for i in range(U // p + 1):
            B[p * i] += B[i]
    ret = 0
    for x in A:
        ret += B[x] == 1
    return ret

def prime_table(N):
    is_prime = np.zeros(N, np.int64)
    is_prime[2:3] = 1
    is_prime[3::2] = 1
    for p in range(3, N, 2):
        if p * p >= N:
            break
        if is_prime[p]:
            is_prime[p * p::p + p] = 0
    return is_prime, np.where(is_prime)[0]

A = np.array(read().split(), np.int64)[1:]
_, primes = prime_table(U)

print(solve(A, primes))

Measured memory_bytes: 125100
#include<bits/stdc++.h>
using namespace std;
#define fastio() ios::sync_with_stdio(0),cin.tie(0);
int main()
{
  fastio();
	int n,flag=0;
	string cur,tmp;
	set<string> s;
	cin >> n;
	for(int i=0;i<n;i++)
	{	
		cin >> cur;
		if (s.count(cur))flag = true;
		if (i>0&&cur[0] != tmp[tmp.size() - 1])flag = true;
		tmp = cur;
		s.insert(cur);
	}
	flag ? cout << "No" : cout << "Yes";
	return 0;
}

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

using namespace std;

int main()
{
    int K;
    string S;
    cin >> S;
    cin >> K;
    set<string, greater<string>> strs;
    set<string, greater<string>>::iterator sit;
    for (int l = 1; l <= S.length(); l++)
    {
        for (int i = 0; i < S.length() - l + 1; i++)
        {
            if(strs.size() < K){
                strs.insert(S.substr(i, l));
            }
            else{
                sit = strs.begin();
                if(*sit > S.substr(i, l)){
                    strs.erase(strs.begin());
                    strs.insert(S.substr(i, l));
                }
            }
        }
    }
    sit = strs.begin();
    cout << *sit << endl;
}

Measured memory_bytes: 256
def f(N, X, a, p):
    if X == 1:
        return 1 if N == 0 else 0
    elif X <= 1 + a[N - 1]:
        return f(N - 1, X - 1, a, p)
    elif X == 2 + a[N - 1]:
        return p[N - 1] + 1
    elif X <= 2 + 2 * a[N - 1]:
        return p[N - 1] + 1 + f(N - 1, X - 2 - a[N - 1], a, p)
    else:
        return 2 * p[N - 1] + 1
        
def f_(N, X, a, p):
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= 1 + a[N - 1]:
        return f(N - 1, X - 1, a, p)
    else:
        return p[N - 1] + 1 + f(N - 1, X - 2 - a[N - 1], a, p)
        

N, X = map(int, input().split())
a = [1 for i in range(N + 1)]
p = [1 for i in range(N + 1)]
a[0] = 1;
p[0] = 1;

for i in range(1, N + 1):
    a[i] = 2 * a[i - 1] + 3
    p[i] = 2 * p[i - 1] + 1
    
print(f(N, X, a, p))

Measured memory_bytes: 3064