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

int main(){
    int N, M;
    cin >> N >> M;
    vector<set<int>> A(N);
    for (int i = 0; i < N; i++){
        int K;
        cin >> K;
        for (int j = 0; j < K; j++){
            int a;
            cin >> a;
            A.at(i).insert(a);
        }
    }
    int count = 0;
    for (int i = 1; i <= M; i++){
        bool ok = true;
        for (int j = 0; j < N; j++){
            if (A.at(j).count(i) == 0){
                ok = false;
                break;
            }
        }
        if (ok){
            count++;
        }
    }
    cout << count << endl;
}

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

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


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

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

int W,H,M;
double tgx,tg;
char f[500][500];
int v[500][500];
bool g[500][500];
bool h[500][500];
bool b[500];
int lx[500],rx[500];
double gx[500];
int n[500];

void paint(int x, int y, char c, int t)
{
	if(h[x][y]) return;
	if(f[x][y]!=c) return;

	v[x][y]=t;
	h[x][y]=1;

	for(int i=0; i<4; i++)
	{
		int tx=x+dx[i], ty=y+dy[i];
		if(ty==H) b[t]=1;
		if(tx<0||ty<0||tx>=W||ty>=H) continue;		
		paint(tx,ty,c,t);
	}
}

void connect(int x, int y, int c)
{
	if(h[x][y]) return;
	if(v[x][y]!=c) return;

	h[x][y]=1;

	for(int i=0; i<4; i++)
	{
		int tx=x+dx[i], ty=y+dy[i];
		if(ty==H)
		{
			lx[c]=min(lx[c], tx);
			rx[c]=max(rx[c], tx);
		}
		if(tx<0||ty<0||tx>=W||ty>=H) continue;
		if(i==0&&v[tx][ty]!=c&&v[tx][ty]!=-1) g[c][v[tx][ty]]=1;
		if(i==3&&v[tx][ty]!=c&&v[tx][ty]!=-1)
		{
			lx[c]=min(lx[c], tx);
			rx[c]=max(rx[c], tx);
		}
		connect(tx,ty,c);
	}
}

int center(int x, int y, int c)
{
	if(h[x][y]) return 0;
	if(v[x][y]!=c) return 0;

	h[x][y]=1;
	gx[c]+=x+0.5;
	int ret=1;

	for(int i=0; i<4; i++)
	{
		int tx=x+dx[i], ty=y+dy[i];
		if(tx<0||ty<0||tx>=W||ty>=H) continue;
		ret+=center(tx,ty,c);
	}

	return ret;
}

void calc(int c)
{
	tgx +=gx[c];
	tg  +=n[c];
	for(int i=0; i<M; i++)
		if(g[c][i]) calc(i);	

}

bool ok(int c)
{
	tgx=tg=0;
	calc(c);
	double t = 1.0*tgx/tg;

	return (lx[c] < t && t < rx[c]+1);
}

int main()
{
	while(cin >> W >> H, (W||H))
	{
		M=0;
		memset(h,0,sizeof(h));
		memset(b,0,sizeof(b));
		memset(g,0,sizeof(g));
		memset(gx,0,sizeof(gx));

		for(int i=0; i<H; i++)
		for(int j=0; j<W; j++)
		{
			cin >> f[j][i];
			v[j][i]=-1;
		}

		for(int i=0; i<H; i++)
		for(int j=0; j<W; j++)
		if(f[j][i]!='.'&&h[j][i]!=1)
		{
			paint(j,i,f[j][i],M);
			++M;
		}

		for(int i=0; i<M; i++)
		{
			lx[i]=(1<<25);
			rx[i]=-1;
		}

		memset(h,0,sizeof(h));
		for(int i=0; i<H; i++)
		for(int j=0; j<W; j++)
			if(f[j][i]!='.') connect(j,i,v[j][i]);

		memset(h,0,sizeof(h));
		for(int i=0; i<H; i++)
		for(int j=0; j<W; j++)
			if(f[j][i]!='.'&&h[j][i]!=1) n[v[j][i]]=center(j,i,v[j][i]);

		
		bool gd=true;
		for(int i=0; i<M; i++)
			gd&=ok(i);

		cout << (gd?"":"UN") << "STABLE" << endl;					 	
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define P pair<int,int>
#define pb push_back
#define fi first
#define se second
int n,m,st,d[1010];
vector<int>v[1010],vg[1010],ans;
P es[2010];
int mid=INF,mi;
queue<int>q;
void dfs(int x){
	if(d[x]==0)return;
	for(int i:vg[x]){
		if(d[i]==d[x]-1){
			ans.pb(i);
			dfs(i);
			break;
		}
	}
}
int main(){
	cin>>n>>m;
	rep(i,m){
		int a,b;
		cin>>a>>b;
		a--,b--;
		v[a].pb(b);
		vg[b].pb(a);
		es[i]={b,a};
	}
	rep(i,m){
		P e=es[i];
		fill(d,d+n,INF);
		d[e.fi]=0;
		q.push(e.fi);
		while(!q.empty()){
			int p=q.front();
			q.pop();
			for(int j:v[p]){
				if(d[j]>d[p]+1){
					d[j]=d[p]+1;
					q.push(j);
				}
			}
		}
		if(mid>d[e.se]){
			mid=d[e.se];
			mi=i;
		}
	}
	if(mid==INF){
		puts("-1");
		return 0;
	}
	P e=es[mi];
	fill(d,d+n,INF);
	d[e.fi]=0;
	q.push(e.fi);
	while(!q.empty()){
		int p=q.front();
		q.pop();
		for(int j:v[p]){
			if(d[j]>d[p]+1){
				d[j]=d[p]+1;
				q.push(j);
			}
		}
	}
	ans.pb(e.se);
	dfs(e.se);
	cout<<ans.size()<<endl;
	for(int i:ans){
		cout<<i+1<<endl;
	}
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& a){for(auto&& it:a)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(int& a){printf("%d",a);}
void print(long long& a){printf("%lld",a);}
template<class T> void print(T& a){cout<<a;}
template<class T> void print(vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(Head& head, Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(T& a){cerr<<a;}
template<class T> void dprint(vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(Head& head, Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    int n;
    ll x,ans=1;
    in(n);
    map<ll,ll> map;
    set<ll> set;
    rep(i,n){
        in(x);
        if(map.count(x)){
            map[x]++;
        }else{
            set.insert(x);
            map[x]=1;
        }
    }
    int d=0,counter=0;
    for(auto it=set.rbegin();it!=set.rend();it++){
        if(map[*it]>=4){
            if(ans==1)ans=(ll)(*it)*(ll)(*it);
            else ans*=(ll)(*it);
            break;
        }
        if(map[*it]>=2){
            ans*=(ll)(*it);
            d++;
            if(d==2)break;
        }else{
            counter++;
        }
    }
    if(counter==set.size())ans=0;
    out(ans);
}

Measured memory_bytes: 14660
import itertools
N,M,X = map(int,input().split())
CAs = [list(map(int,input().split())) for _ in range(N)]


ans = float("inf")
for p in itertools.product([0,1],repeat = N):
    cost = 0
    algo = [0]*M
    for i in range(N):
        if p[i]:
            cost += CAs[i][0]
            for j in range(M):
                algo[j] += CAs[i][j+1]
    for a in algo:
        if a < X:
            break
    else:
        ans = min(ans,cost)

print(ans if ans != float("inf") else -1)

Measured memory_bytes: 9224
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int l = 0;
		for(int i = 1; i <= n; i+=2) {
			int k = 0;
			for(int j = 1; j <= i; j++) {
				double x = (double)i / j;
				if(x - Math.floor(x) == 0)k++;
			}
			if(k == 8)l++;
		}

		System.out.println(l);
	}

}

Measured memory_bytes: 23364
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

int main() {
  while (true) {
    int n, m, p;
    cin >> n >> m >> p;
    if (n == m && m == p && n == 0)
      break;
    vector<int> x(n);
    for (int i = 0; i < n; i++)
      cin >> x[i];
    long long sum = 0;
    for (int i = 0; i < n; i++)
      sum += x[i];
    sum *= (100 - p);
    if (x[m - 1] == 0)
      cout << 0 << endl;
    else
      cout << sum / x[m - 1] << endl;
  }

  return 0;
}



Measured memory_bytes: 3028
// TEMPLATE {{{
#include <bits/stdc++.h>
using namespace std;
#ifndef LOCAL
#define OJ 1
#else
#define OJ 0
#endif
 
#define endl '\n'
#define TIMESTAMP merr << "Execution time: " << (double)clock()/CLOCKS_PER_SEC << " s.\n"
class C_ {}; template <typename T> C_& operator <<(C_& __m, const T& __s) { if (!OJ) cerr << "\E[91m" << __s << "\E[0m"; return __m; }
C_ merr;
 
struct __s { __s() { if (OJ) { ios_base::Init i; cin.sync_with_stdio(0); cin.tie(0); } } ~__s(){ TIMESTAMP; } } __S;
/// END OF TEMPLATE }}}

#define size_t unsigned long long

int main(void) {
    size_t h,w;
    bool u[1111][1111] = {};
    queue<tuple<size_t,size_t,size_t>> Q;
    cin >> h >> w;
    for (size_t i = 0; i < h; i++) {
        string s;
        cin >> s;
        for (size_t j = 0; j < w; j++) {
            if (s[j] == '#') {
                Q.push(make_tuple(i,j,0ULL));
                u[i][j] = 1;
            }
        }
    }
    size_t cnt = 0;
    while (Q.size()) {
        size_t x,y,len;
        tie(x,y,len) = Q.front();
        cnt = len;
        // merr << x << " " << y << " " << len << '\n';
        Q.pop();
        for (long dx = -1; dx <= 1; dx++) {
            for (long dy = -1; dy <= 1; dy++) {
                if (abs(dx) + abs(dy) != 1) {
                    continue;
                }
                size_t nx = x+dx, ny = y+dy;
                if (nx >= h || ny >= w) continue;
                if (u[nx][ny]) continue;
                u[nx][ny] = 1;
                Q.push(make_tuple(nx,ny,len+1));
            }
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 25652
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt(), k=sc.nextInt();
		int[] array = new int[n];
		for(int i=0;i<n;i++) {
			double least = (double)k/(i+1);
			least = Math.log(least)/Math.log(2.0);
			for(int j=0;;j++) {
				if(j>=least) {
					array[i]=j;
					break;
				}
			}
		}
		double sum =0.0;
		for(int i=0;i<n;i++) {
			sum += (double)1/power(2,array[i]);
		}
		System.out.printf("%.10f\n",(double)sum/n);
	}

	static int power(int tei, int ruijo) {
		int k=tei;
		if(ruijo==0) return 1;
		if(ruijo==1) return tei;
		for(int i=1;i<ruijo;i++) tei*=k;
		return tei;
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
int main(){
	int a,b,c;
	cin >>a>>b>>c;
	if (a==b && c==b)
		cout <<"Yes"<<endl;
	else
		cout <<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <string>
#include <cstdio>
#include <cstdlib>
using namespace std;

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

const ll MOD = 1000000007;
ll S;

ll solve(){
    if(S < 3) return 0;
    ll MN = S / 3 + 1;
    vector<vector<ll>> dp(MN, vector<ll>(S+1, 0));
    dp[0][0] = 1;
    for(int i=0; i<=S; i++){
        dp[0][i] = 1;
    }

    ll ans = 0;
    for(int i=1; i<MN; i++){
        for(int s=3; s<=S; s++){
            dp[i][s] = dp[i][s-1];
            dp[i][s] += dp[i-1][s - 3];
            dp[i][s] %= MOD;
        }

        ans += dp[i][S] - dp[i][S-1];
        ans = (ans % MOD + MOD) % MOD;
        ans %= MOD;
    }
    return ans;

}

int main(){
    //freopen("in.txt", "r", stdin);
    cin>>S;

    cout<<solve()<<endl;
    

    return 0;
}

Measured memory_bytes: 13584
n, m = map(int, input().split())
tree = [-i for i in range(n+1)]
rank = [1 for _i in range(n+1)]
def search_root(num, tree=tree):
    if tree[num] < 0:
        return num
    else:
        tree[num] = search_root(tree[num])
        return tree[num]

for _i in range(m):
    x, y, z = map(int, input().split())
    x, y = sorted([search_root(x), search_root(y)])
    if x==y:
        continue
    else:
        if rank[x]<rank[y]:
            rank[y] += 1
            tree[x] = y
        else:
            rank[x] += 1
            tree[y] = x
print(sum(1 for i in tree if i<0))

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

int main() {
  int A, B, H, M;
  cin >> A >> B >> H >> M;

  double xa, ya, xb, yb;
  xa = A * cos((H+(double)M/60)/12*2*M_PI);
  ya = A * sin((H+(double)M/60)/12*2*M_PI);
  xb = B * cos((double)M/60*2*M_PI);
  yb = B * sin((double)M/60*2*M_PI);

  cout << setprecision(20) << pow(pow(xa-xb,2)+pow(ya-yb,2),0.5) << endl;
  return 0;
}

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

map< long long int,  long long int> prime_factor(long long int n) {
  map< long long int, long long int > ret;
  for(long long int i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main() { 
    long long int n, p, ans = 1;
    cin >> n >> p;
    auto mp = prime_factor(p);
    auto begin = mp.begin(), end = mp.end();
    for(auto iter = begin; iter != end; iter++) {
        //cerr << iter->first << " " << iter->second << endl;
        ans *= pow(iter->first, (iter->second/n));
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
	int n, mx = 0, a[111111], res = 0;
	vector<int> v;
	cin>>n;
	for(int i = 0; i < n; i++){
		cin>>a[i];
		mx = max(mx, a[i]);
	}
	for(int i = 1; i <= mx; i++){
		if(mx % i == 0) v.push_back(i);
	}
	for(int i = 0; i < n; i++){
		for(int j = 0; j < v.size(); j++){
			if(v[j] >= a[i]){
				res += v[j] - a[i];
				break;
			}
		}
	}
	cout<<res<<endl;
}


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

string path(int x, int y, int goal_x, int goal_y){

}

int main(){
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int p = tx - sx;
    int q = ty - sy;
    string ans;
    for (int i=0; i<p; i++) ans += "R";
    for (int i=0; i<q; i++) ans += "U";
    for (int i=0; i<p; i++) ans += "L";
    for (int i=0; i<q; i++) ans += "D";

    ans += "D";
    for (int i=0; i<p+1; i++) ans += "R";
    for (int i=0; i<q+1; i++) ans += "U";
    ans += "L";
    ans += "U";
    for (int i=0; i<p+1; i++) ans += "L";
    for (int i=0; i<q+1; i++) ans += "D";
    ans += "R";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3584
#pragma region def
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

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

using llint = long long;
using vint = vector<int>;
using vvint = vector<vector <int>>;
using pint = pair<int, int>;
const int INF = 1e9;
const long long llINF = 1e18;
#pragma endregion

int main () {
    int n; cin >> n;
    vint a(n);
    set<int> st;
    rep(i, n) {
        cin >> a[i];
        st.insert(a[i]);
    }
    if (a.size() == st.size()) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 10368
#!/usr/bin/env python3
import sys
from collections import deque

def solve(N: int, K: int, V: "List[int]"):

    mani = []
    for ac in range(K+1):
        for bc in range(K+1):
            for cc in range(K+1):
                if (ac+bc+cc) == K:
                    mani.append([ac,bc,cc])

    max_v = 0
    for m in mani:
        VV = deque(V)
        MV = []
        lenVV = len(VV)
        for i in range(min(m[0],lenVV)):
            MV.append(VV.popleft())

        lenVV = len(VV)
        for i in range(min(m[1],lenVV)):
            MV.append(VV.pop())

        MV.sort()
        MV = deque(MV)
        for i in range(m[2]):
            if len(MV) > 0 and MV[0] < 0:
                MV.popleft()

        max_v = max(max_v,sum(MV))

    print(max_v)



            



# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    V = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, K, V)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3820
n, l = map(int, input().split())

apple_sum = 0
apple_min = 1000
apple_min_index = -1

for i in range(n):
    apple_sum += i+l
    if apple_min > abs(i+l):
        apple_min = abs(i+l)
        apple_min_index = i

ans = 0
for i in range(n):
    if i != apple_min_index:
        ans += i+l

print(ans)


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	
	static int sum = 0; //print
	
	void search(char[][] board, int i) {
		out: for(int j = 0; j < board[i].length; j++) {//1??????????????¢?´¢
			if(board[i][j] == board[0][0]) {
				for(int k = j + 1; k < board[i].length; k++) {//2??????????????¢?´¢
					if(board[i][k] == board[0][1]) {
						int interval = k - j;//1???????????¨2??????????????????
						int cnt = 2;//?????????????????¢?´¢???????????????
						if(cnt == board[0].length) {
							sum = sum + 1;
							break out;
						} else {
							for(int m = k + interval; m < board[i].length; m = m + interval) {//3???????????\????????¢?´¢
								if(board[i][m] == board[0][cnt]) {
									cnt = cnt + 1;
									if(cnt == board[0].length) {
										sum = sum + 1;
										break out;
									}
								} else {
									break;
								}
							}
						}
					}
				}				
			}
		}
	}
	
	
	void doIt() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		char[][] board = new char[n + 1][];
		board[0] = sc.next().toCharArray();
		for(int i = 1; i <= n; i++) {
			board[i] = sc.next().toCharArray();
			new Main().search(board, i);
		}
		
		System.out.println(sum);
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().doIt();
	}

}

Measured memory_bytes: 27572
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

vector<int> G[100010];

int main(){
  //using namespace std;
  int n, m;
  cin>>n>>m;
  int h[n];
  REP(i, n) cin>>h[i];
  int a[m], b[m];
  REP(i, m){
    cin>>a[i]>>b[i];
    a[i]--; b[i]--;
    G[a[i]].push_back(b[i]);
    G[b[i]].push_back(a[i]);
  }
  int ans = 0;
  REP(i, n){
    bool flag = true;
    for(int adj: G[i]){
      if(h[i] > h[adj]) continue;
      flag = false;
      break;
    }
    if(flag) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9976
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
int n;
bool color[123456], b[123456];
vector<pair<int, int>>l[123456];
void f(int p) {
	for (int i = 0; i < l[p].size(); i++) {
		if (!b[l[p][i].first]) {
			b[l[p][i].first] = 1;
			color[l[p][i].first] = (color[p] + l[p][i].second) % 2;
			f(l[p][i].first);
		}
	}
	return;
}
signed main() {
	cin >> n;
	for (int i = 1; i < n; i++) {
		int x, y, v; cin >> x >> y >> v;
		l[x].push_back(make_pair(y, v));
		l[y].push_back(make_pair(x, v));
	}
	color[1] = 0; b[1] = 1;
	f(1);
	for (int i = 1; i <= n; i++)cout << color[i] << endl;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
const int MAX = 510000;
const ll mod = 1e9+7;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i-1] * (ll)i % mod;
        inv[i] = mod - inv[mod%i] * (mod/(ll)i) % mod;
        finv[i] = finv[i-1] * inv[i] % mod;
    }
}

ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

int main(){
  ll n, k;
  cin >> n >> k;
  COMinit();
  ll ans = COM(2*n-1,n);
  for(ll i = n-1; i > k; i--) {
    ll d = (COM(n,i) * COM(n-1,i)) % mod; 
    (ans -= d) %= mod;
  }
  cout << (ans + mod) % mod << endl;
  return 0;
}

Measured memory_bytes: 12160
K = int(input())-1
print([1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51][K])

Measured memory_bytes: 9184
#include<bits/stdc++.h>
using namespace std;
map<int,int>m;
main()
{
	int t,u;
    int co=0;
    scanf("%d",&t);
    for(int i = 0;i < t;i++)
    {
        scanf("%d",&u);
        m[u]++;
        if(m[u]%2==0)
        co--;
        else
        co++;
    }
    printf("%d",co);
}


Measured memory_bytes: 4864
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main() {
    int N, g=0, flag=0;

    cin >> N;

    vector<int> A(N);

    for(int i=0; i<N; i++) {
        cin >> A[i];
        if(A[i]%2==0) {
            if(A[i]%3==0 || A[i]%5==0) {
                g++;
            } else {
                flag++;
            }
        }
    }

    if(flag==0) {
        cout << "APPROVED" << endl;
    } else {
        cout << "DENIED" << endl;
    }

    return 0;
    
}

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

int main()
{
    int r, g, b, k;
    cin >> r >> g >> b >> k;
    while (g <= r)
    {
        g *= 2;
        k--;
    }
    while (b <= g)
    {
        b *= 2;
        k--;
    }
    if (k < 0)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	ll n;
	cin >> n;
	vector<ll> divisors;
	//Left's find all divisors of N in O(sqrt(n))
	for(ll div = 1; div * div <= n; ++div){
		if(n % div == 0){
			if(div != 1) divisors.push_back(div);
			if(div != (n/div)) divisors.push_back(n/div);
		}
	}
	// Find all favorite numbers and print the sum of those
	ll sum = 0;
	for(auto div : divisors){
		//cout << "check: " << div << '\n';
		ll m = div - 1;
		if(n / m == n % m){
			sum += m;
		}
	}
	cout << sum << '\n';
	return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner stdIn = new Scanner(System.in);
        String s = stdIn.next();
        //int a = stdIn.nextInt();
        
        
        for(int i = 0; i < s.length() - 1; i++){
            System.out.print("x");
        }
        
        System.out.println("x");
    }
}


Measured memory_bytes: 23892
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

A, B = mapint()
from math import gcd
g = gcd(A, B)

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return len(set(a))

print(prime_factorize(g)+1)



Measured memory_bytes: 62812
#include<iostream>
using namespace std;
int n, a, b, c, sum;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a >> b >> c; sum = 0;
		while (c > 0 && a > 0 && b > 0) {
			a--; b--; c--; sum++;
		}
		while (a > 1 && b > 0) {
			a -= 2; b--; sum++;
		}
		while (a > 2) {
			a -= 3; sum++;
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  if((A+B)>(C+D)){
    cout<<"Left"<<endl;
  }else if((A+B)==(C+D)){
    cout<<"Balanced"<<endl;
  }else{
    cout<<"Right"<<endl;
  }
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        long d = sc.nextLong();

        List<Long> list = new ArrayList<>();
        list.add(a * c);
        list.add(a * d);
        list.add(b * c);
        list.add(b * d);

        list.stream().max(Comparator.naturalOrder()).ifPresent(System.out::println);
    }
}


Measured memory_bytes: 35636
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define INF 0x3f3f3f3f
using namespace std;

int x[1000];
vector<int>E[1000];
int memo[2000];
map<int,int>dp[2000];

void dfs(int v){
	if(E[v].empty()){
		memo[v]=0;
		return;
	}
	for(auto u:E[v]){
		dfs(u);
	}
	//dp...同じ色の合計がjである時の異なる色の最小値
	dp[0][0]=0;
	int sum=0;
	rep(i,E[v].size()){
		dp[i+1].clear();
		int nxt=0;
		for(auto&p:dp[i]){
			int j=p.first;
			//同じ色
			if(j+x[E[v][i]]<=x[v]){
				if(dp[i+1].count(j+x[E[v][i]])==0)dp[i+1][j+x[E[v][i]]]=dp[i][j]+memo[E[v][i]];
				else dp[i+1][j+x[E[v][i]]]=min(dp[i+1][j+x[E[v][i]]],dp[i][j]+memo[E[v][i]]);
			}
			//異なる色
			if(j+memo[E[v][i]]<=x[v]){
				if(dp[i+1].count(j+memo[E[v][i]])==0)dp[i+1][j+memo[E[v][i]]]=dp[i][j]+x[E[v][i]];
				else dp[i+1][j+memo[E[v][i]]]=min(dp[i+1][j+memo[E[v][i]]],dp[i][j]+x[E[v][i]]);
			}
			nxt=max({nxt,j+x[E[v][i]],j+memo[E[v][i]]});
		}
		sum=nxt;
	}
	memo[v]=INF;
	rep(i,x[v]+1){
		if(dp[E[v].size()].count(i)==0)continue;
		memo[v]=min(memo[v],dp[E[v].size()][i]);
	}
	if(memo[v]==INF){
		puts("IMPOSSIBLE");exit(0);
	}
}
int main(){
	int n;scanf("%d",&n);
	rep(i,n-1){
		int p;scanf("%d",&p);p--;
		E[p].push_back(i+1);
	}
	rep(i,n)scanf("%d",&x[i]);
	dfs(0);
	puts("POSSIBLE");
}


Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#define INF 1<<28
using namespace std;

int p[1000001];
int memo[1000001][6];
int memo2[1000001];

int solve(int n, int count){

  if(!n) return 0;
  if(n <= 0 || !count) return INF;
  if(memo[n][count]) return memo[n][count];

  int ans = INF;
  for(int i=0;p[i]<=n; i++){
    ans = min(ans, solve(n-p[i], count-1)+1);
  }

  return memo[n][count] = ans;
}

int solve2(int n){
  
  if(!n) return 0;
  if(n<0) return INF;
  if(memo2[n]) return memo2[n];

  int ans = INF;
  for(int i=0;p[i]<=n; i++){
    if(!(p[i]%2)) continue;
    ans = min(ans, solve2(n-p[i])+1);
  }

  return memo2[n] = ans;
}

int main(){
  
  int n;

  for(int i=0;i<=1000000;i++) p[i] = i*(i+1)*(i+2)/6;
  for(int i=1;i<=1000000;i++) solve(n, 5), solve2(i);

  while(cin >> n, n)
    cout << solve(n, 5) << " " << solve2(n) << endl;
}

Measured memory_bytes: 32408
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> l(n*2);
    rep(i,n*2) cin>>l.at(i);
    sort(l.begin(),l.end());
    int ans=0;
    rep(i,n){
        ans+=l.at(2*i);
    }
    cout<<ans;
}

Measured memory_bytes: 256
#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))
  
n=int(input())
L=input_array()
count=0
for i in range(0,n):
	for j in range(i+1,n):
		for k in range(j+1,n):
			if L[i]!=L[j] and L[j]!=L[k] and L[i]!=L[k]:
				a=L[i]+L[j]
				b=L[j]+L[k]
				c=L[i]+L[k]
				if a>L[k] and b>L[i] and c>L[j]:
					count+=1

print(count)


Measured memory_bytes: 9208
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	n := readInt()
	k := readInt()
	println(n-k+1)
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace::std;
#define rep(i, n) for(lint i = 0; i < (lint)(n); i++)
typedef long long lint;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;

int main(){
    bitset<40001>b;
    lint n,q;
    cin>>n;
    vector<lint>a(n);
    rep(i,n)cin>>a[i];
    cin>>q;
    vector<lint>m(q);
    rep(i,q)cin>>m[i];
    b[0]=1;
    rep(i,n)b|=b<<a[i];
    rep(i,q){
        if(b[m[i]])cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
}


Measured memory_bytes: 3220
#include<stdio.h>
#include<map>
using namespace std;
int main() {
	int m,n,d,t;
	map<int,int> dd,tt;
	map<int,int>::iterator it,id;
	scanf("%d",&n);
	for(int i=0; i<n; i++) {
		scanf("%d",&d);
		dd[d]++;
	}
	int count=0;
	scanf("%d",&m);
	if(m>n) {
		printf("NO\n");
		return 0;
	}
	for(int i=0; i<m; i++) {
		scanf("%d",&t);
		tt[t]++;
	}
	for(it=tt.begin(); it!=tt.end(); it++) {
		if(it->second > dd[it->first]) {
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	return 0;
}

Measured memory_bytes: 18944
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<stack>

using namespace std;
int main()
{
	stack<char> s;
	string l;
	cin >> l;
	int len = l.length();
	s.push(l[0]);
	for (int i = 1; i < len; i++)
	{
		if(s.empty()||l[i]==s.top())
			s.push(l[i]);
		else
			s.pop();		
	}
	cout << len - s.size() << endl;
	return 0;
}

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

int main(){

  int n;
  cin >> n;
  vector<int> numbers(3);
  vector<int> before(3);
  vector<int> now(3);
  for(int i=0; i<3; ++i) cin >> now[i];
  for(int i=1; i<n; ++i){
    before = now;
    now = {0,0,0};
    for(int i=0; i<3; ++i) cin >> numbers[i];
    for(int i=0; i<3; ++i){
      for(int j=0; j<3; ++j){
        if(i!=j){
          now[j] = max(now[j],before[i]+numbers[j]);
        }
      }
    }
  }
  cout << *max_element(now.begin(),now.end()) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

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

Measured memory_bytes: 0
n,m=map(int,input().split())
#g=[[]for _ in range(n)]
abc=[list(map(int,input().split())) for _ in range(m)]
abc=[[a-1,b-1,-c] for a,b,c in abc]
# BellmanFord
# ベルマンフォード法
def BellmanFord(edges,num_v,source):
  #グラフの初期化
  inf=float("inf")
  dist=[inf for i in range(num_v)]
  dist[source]=0  
  #辺の緩和
  for i in range(num_v):
    for edge in edges:
      if dist[edge[0]] != inf and dist[edge[1]] > dist[edge[0]] + edge[2]:
        dist[edge[1]] = dist[edge[0]] + edge[2]
        #if i==num_v-1: return -1
  negative=[False]*n
  for i in range(num_v):
    for edge in edges:
      if negative[edge[0]]:negative[edge[1]]=True
      if dist[edge[0]] != inf and dist[edge[1]] > dist[edge[0]] + edge[2]:
        negative[edge[1]] = True
  return dist[n-1],negative[n-1]
c,d=BellmanFord(abc,n,0)
# 負の閉路にNが含まれない時はinfじゃない
if d:
  print('inf')
else:
  print(-c)

Measured memory_bytes: 3828
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto n = readln.chomp.to!int;
  auto m = n;
  int cnt;
  int k = 1;
  while (n) {
    auto t = n / 10;
    if (t) {
      cnt += 10 ^^ k - 10 ^^ (k - 1);
    } else {
      cnt += m - 10 ^^ (k - 1) + 1;
    }
    k += 2;
    n /= 100;
  }
  cnt.writeln;
}


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

 public:
  ModInt(long long v = 0) : x(v % MOD) {
    if (x < 0) x += MOD;
  }

  ModInt& operator+=(const ModInt& r) {
    x += r.x;
    if (x >= MOD) x -= MOD;
    return *this;
  }

  ModInt& operator-=(const ModInt& r) {
    x -= r.x;
    if (x < 0) x += MOD;
    return *this;
  }
  ModInt& operator*=(const ModInt& r) {
    x = (x * r.x) % MOD;
    return *this;
  }
  ModInt& operator/=(const ModInt& r) {
    *this *= r.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt& r) const { return ModInt(*this) += r; }
  ModInt operator-(const ModInt& r) const { return ModInt(*this) -= r; }
  ModInt operator*(const ModInt& r) const { return ModInt(*this) *= r; }
  ModInt operator/(const ModInt& r) const { return ModInt(*this) /= r; }
  bool operator==(const ModInt& r) const { return x == r.x; }
  bool operator!=(const ModInt& r) const { return x != r.x; }

  ModInt inverse() const {
    long long a = x, b = MOD, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt<MOD> pow(long long n) const {
    ModInt ret(1), mul(x);
    while (n > 0) {
      if (n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream& operator<<(ostream& os, const ModInt& x) { return os << x.x; }

  friend istream& operator>>(istream& is, ModInt& x) { return is >> x.x; }

  int getMod() { return MOD; }

  long long val() { return x; }
};

using mint = ModInt<1000000007>;

int N, M, K;

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

  vector<mint> fact(N * M - 1), ifact(N * M - 1);
  fact[0] = 1;
  rep(i, N * M - 2) fact[i + 1] = fact[i] * (i + 1);
  rep(i, N * M - 1) ifact[i] = fact[i].inverse();

  auto comb = [&](int n, int k) { return fact[n] * ifact[k] * ifact[n - k]; };

  mint ans = 0;
  rep(i, M) ans += comb(N * M - 2, K - 2) * i * (M - i) * N * N;
  rep(i, N) ans += comb(N * M - 2, K - 2) * i * (N - i) * M * M;

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


Measured memory_bytes: 3328
#include <bits/stdc++.h>
 #include <math.h>
using namespace std;
#define ll long long
#define pi 3.14159265359

int main(){
 int n;
  cin>>n;
  string s;
  cin>>s;
  int ans=n;
  for(int i=0;i<n-1;i++){
    if(s[i]==s[i+1])ans--;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long; // ll は long long　と同じとする。(int64_t)
int main(){
    int N , K;
    cin >> N >> K;
    ll ans = K;
    int i = N - 1;
    while(i > 0){
        ans*=(K - 1);
        i--;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;


int main() {
  int H, W, K; cin >> H >> W >> K;
  vector<vector<int>> S;
  S.resize(H, vector<int>(W));
  for (int r = 0; r < H; ++r) {
    for (int c = 0; c < W; ++c) {
      char x; cin >> x;
      S[r][c] = x - '0';
    }
  }

  int vmin = INT_MAX;
  for (int rbit = 0; rbit < (1 << (H-1)); ++rbit) {
    vector<int> group(H);
    group[0] = 0;
    for (int r = 0; r < H-1; ++r) {
      if (rbit & (1 << r)) group[r + 1] = group[r] + 1;
      else                 group[r + 1] = group[r];
    }

    int num_line = group[H-1];
    int num_group = num_line + 1;
    vector<vector<int>> counts(num_group, vector<int>(W, 0));
    for (int c = 0; c < W; ++c) {
      for (int r = 0; r < H; ++r) {
        int group_no = group[r];
        counts[group_no][c] += S[r][c];
      }
    }

    // Check valid case or not.
    bool overK = false;
    for (int c = 0; c < W; ++c) {
      for (int n = 0; n < num_group; ++n) {
        if (counts[n][c] > K) {
          overK = true;
          break;
        }
      }
      if (overK) break;
    }
    if (overK) continue;

    // Draw vertical line to split count < K in each region.
    vector<int> sums(num_group, 0);
    for (int c = 0; c < W; ++c) {
      bool overK2 = false;
      for (int n = 0; n < num_group; ++n) {
        sums[n] += counts[n][c];
        if (sums[n] > K) {
          overK2 = true;
          break;
        }
      }

      if (overK2) {
        ++num_line;
        // Clear.
        for (int n = 0; n < num_group; ++n) {
          sums[n] = counts[n][c];
        }
      }
    }
    vmin = min(vmin, num_line);
  }
  cout << vmin << endl;
}


Measured memory_bytes: 384
from collections import Counter 

n=int(input())
a=list(map(int,input().split()))

x=[]
y=[]

for i in range(n):
    if i%2==0:
        x.append(a[i])
    else:
        y.append(a[i])

cx=Counter(x)
cy=Counter(y)

ax=cx.most_common(2)
ay=cy.most_common(2)

if len(ax)==1:
    ax=ax+ax

if len(ay)==1:
    ay=ay+ay
   

if not ax[0][0]==ay[0][0]:
    print(n-ax[0][1]-ay[0][1])
else:
    if ax[0][1]==n//2:
        if ay[0][1]==n//2:
            print(n-ay[0][1])
        else:
            print(n//2-ay[1][1])
    elif ay[0][1]==n//2:
        print(n//2-ax[1][1])
    else:
        if ax[0][1]<ay[0][1]:
            print(n-ax[1][1]-ay[0][1])
        elif ax[0][1]>ay[0][1]:  
            print(n-ax[0][1]-ay[1][1])
        else:
            if ax[1][1]<ay[1][1]: 
                print(n-ax[0][1]-ay[1][1])
            else:
                print(n-ay[0][1]-ax[1][1])
     


Measured memory_bytes: 19168
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void) {
    int a,b,c,n=0;
    scanf("%d%d%d", &a,&b,&c);
    for (int i = a; i <= b; i++) {
        if (c%i == 0)n++;
    }
    printf("%d\n",n);
        
    
    return 0;
}


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

ll gcm(ll a, ll b) {
	ll result = a;
	ll k = 0;
	ll n = b;
	do {
		k = result % n;
		result = n;
		n = k;
	} while(k != 0);
	return result;
}

ll lcm(ll a, ll b) {
	ll g;
	g = gcm(a, b);
	return a*b/g;
}

ll lcm_n(ll *numbers, ll n) {
	ll l;
	l = numbers[0];
	for (ll i = 1; i < n; i++) {
		l = lcm(l, numbers[i]);
	}
	return l;
}

int main()
{
	ll n;
	cin >> n;
	ll a[n];
	rep(i, n)
		cin >> a[i];
	ll m = lcm_n(a, n) - 1;
	ll ans = 0;
	rep(i, n)
		ans += a[i]-1;
	cout << ans << endl;
	return (0);
}


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

#define SIZE_OF_ARRAY(array) sizeof(array)/sizeof(array[0])

int main() {
    long long N;
    cin >> N;
    std::vector<long long> A;
    std::vector<long long> A_;
    for(int i = 0; i < N; i++){
        A.push_back(0);
    }
    for(int i = 0; i < N; i++){
        long long n;
        cin >> n;
        A_.push_back(n-1);
        A.at(n-1)++;
    }
    long long count = 0;
    for(int i=0; i < N; i++){
        //cout << A.at(i) << endl;
        count += A.at(i)*(A.at(i)-1)/2;
    }
    for(int i = 0; i < N; i++){
        cout << count - (A.at(A_.at(i)) - 1) << endl;
    }
}

Measured memory_bytes: 5872
#include<bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define INF 10000000000000000LL
#define ll  long long 
const int inf =INT_MAX;
const int MAX=3e5+9;
const ll MOD=1e9+7;
const int TOT_PRIMES=1e6+9;
const int MAX_A=71;
const int LN=20;
using namespace std;

int main(){
    ll N;
    cin >> N;
    vector <ll> a(N);
    for(int i = 0; i < N; i++)
        cin >> a.at(i);
    ll ymax = *max_element(a.begin(), a.end());
    ll ymin = *min_element(a.begin(), a.end());
    cout << ymax - ymin << "\n";
    return 0;
}

Measured memory_bytes: 3640
#template
def inputlist(): return [int(k) for k in input().split()]
#template
mod = 10**9+7
S = list(input())
n = len(S)
#桁dp
dp = [[0]*(13) for _ in range(n+1)]
if S[0] == '?':
    for i in range(10):
        dp[1][i] = 1
if S[0] != '?':
    dp[1][int(S[0])] = 1
for i in range(1,n):
    i+=1
    if S[i-1] == '?':
        for m in range(13):
            for j in range(10):
                dp[i][(10*m+j)%13] += dp[i-1][m]
                dp[i][(10*m+j)%13] %= mod
        continue
    if S[i-1] != '?':
        for m in range(13):
            dp[i][(10*m+int(S[i-1]))%13] += dp[i-1][m]
            dp[i][(10*m+int(S[i-1]))%13] %= mod
dp[n][5] %= mod
print(dp[n][5])

Measured memory_bytes: 65860
from collections import defaultdict, deque
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
# MOD = 10 ** 9 + 7
# INF = float("inf")


def main():
    n, m = map(int, input().split())
    dd = defaultdict(int)
    for _ in range(n):
        a, b = map(int, input().split())
        dd[a] += b
    dd_sort = sorted(dd.items(), key=lambda x: x[0])
    ans = 0
    r = m
    for cost, num in dd_sort:
        if r >= num:
            ans += cost * num
            r -= num
        else:
            ans += cost * r
            break
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 24544
import itertools

N, M, Q = map(int, input().split())
a, b, c, d = [], [], [], []

for i in range(Q):
    t = [int(x) for x in input().split()]
    a.append(t[0] - 1)
    b.append(t[1] - 1)
    c.append(t[2])
    d.append(t[3])

ans = 0
for A in itertools.combinations_with_replacement(range(1, M + 1), N):
    score = 0
    for i in range(Q):
        if A[b[i]] - A[a[i]] == c[i]:
            score += d[i]

    ans = max(ans, score)

print(ans)

Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INF 1245678912346
#define MOD 1000000007
#define rep(i,n) for(int i = 0; i < n; i++)
#define MAX_VAL 0

// int ab[200010], c[2000010];
signed main(){
	int N, l, K, ans = INF, sum=0, temp = 0, tt = 0, ttt=0;
	int a=0, b=0;
	vector<int> L;
	cin>>N;
	rep(i,N){
		 cin>>l;
		 // cout<<l<<" "<<sum<<endl;
		sum += l;
		L.push_back(l);

	}

	// sort(L.begin(),L.end());
	
	// sum = L[0];
	
	for(int i = 0; i < N-1; i++){
		temp += L[i];
		ans = min(abs(sum-temp-temp), ans);
		// cout<<sum<<" "<<sum-temp<<" "<<temp<<" "<<sum-temp-temp<<endl;
	}
	
	cout<<ans<<endl;

	return 0;
}

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

using namespace std;

long long a[200005], b[200005];

int main() {
	int n, m, k;
	scanf("%d%d%d", &n, &m, &k);
	
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		a[i] += a[i - 1];
	}
	
	for (int i = 1; i <= m; i++) {
		scanf("%d", &b[i]);
		b[i] += b[i - 1];
	}
	
	int res = 0;
	int p = m;
	
	for (int i = 0; i <= n; i++) {
		while (p >= 0 && a[i] + b[p] > k) {
			p--;
		}
		
		if (a[i] + b[p] <= 1LL * k) res = max(res, i + p);
	}
	
	printf("%d\n", res);
}


Measured memory_bytes: 6940
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll=long long;
int a1,b1;
int main(){
  int n,a,b;cin>>n>>a>>b;
  string s;cin>>s;
  rep(i,n){
    int sum=a+b;
    if(s[i]=='a'){
      if(a1<sum)cout<<"Yes"<<endl,a1++;
      else cout<<"No"<<endl;
    }else if(s[i]=='b'){
      if(a1<sum&&b1<b)cout<<"Yes"<<endl,a1++,b1++;
      else cout<<"No"<<endl;
    }else cout<<"No"<<endl;
  }
}

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

int main(){
  int n,k;
  cin >> n >> k;

  vector<int>l(n);
  for (int i = 0; i < n; i++)
  {
    cin >> l[i];
  }
  sort(l.begin(),l.end());
  reverse(l.begin(),l.end());

  int ans = 0;
  for (int i = 0; i < k; i++)
  {
    ans+=l[i];
  }
  cout << ans << endl;  
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;

constexpr int sz = 3 * 1e5, half = 1e5;
int par[sz], h[sz];
void uinit() {
	for (int i = 0; i < sz; i++)
		par[i] = i, h[i] = 1;
}
int root(int x) {
	if (x == par[x])
		return x;
	return (par[x] = root(par[x]));
}
void unite(int x, int y) {
	x = root(x);
	y = root(y);
	if (x == y)
		return;
	if (h[x] < h[y])
		swap(x, y);
	par[y] = x;
	h[x] = max(h[x], h[y] + 1);
}

int n, m, visit[sz];
int main() {
	scanf("%d %d", &n, &m);
	uinit();
	for (int i = 0; i < m; i++) {
		int x, y, z;
		scanf("%d %d %d", &x, &y, &z);
		unite(x, y);
	}

	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		if (visit[root(i)])
			continue;
		cnt++;
		visit[root(i)] = true;
	}
	printf("%d\n", cnt);
}

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

#define I inline
#define fi first
#define se second
#define R register
#define LL long long
#define mp make_pair
#define reg register int
#define pii pair<int,int>
#define fo(i, a, b) for(reg i = a; i <= b; i++)
#define fd(i, a, b) for(reg i = a; i >= b; i--)
#define cr const reg&
using namespace std;

I int _max(cr x, cr y) {return x > y ? x : y;}
I int _min(cr x, cr y) {return x < y ? x : y;}
I int read() {
	reg x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
	return x * f;
}
I void ptt(LL x) {if(x >= 10) ptt(x / 10); putchar(x % 10 + '0');}
I void put(LL x) {x < 0 ? putchar('-'), ptt(-x) : ptt(x);}
I void pr1(LL x) {put(x), putchar(' ');}
I void pr2(LL x) {put(x), puts("");}

const int N=1e5+5;
char s[N];int cnt[3],n,mx;
int main(){
    scanf("%s",s+1),n=strlen(s+1);
    fo(i,1,n)++cnt[s[i]-'a'];
    mx=max(cnt[0],max(cnt[1],cnt[2]));
    if(!cnt[0]||!cnt[1]||!cnt[2])return puts(mx<=1?"YES":"NO"),0;
    fo(i,0,2)if(cnt[i]<mx-1)return puts("NO"),0;
    puts("YES");
    return 0;
}



Measured memory_bytes: 384