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

int K, S;

int main(){
  cin >> K >> S;

  int ans = 0;

  for(int x = 0; x <= K; ++x){
    for(int y = 0; y <= K; ++y){
      int z = S - x - y;
      if(0 <= z and z <= K) ++ans;
    }
  }

  cout << ans << endl;

  return 0; 
}

Measured memory_bytes: 256
n, m = map(int, input().split())

A = []
b = []

for i in range(n):
    A.append([int(j) for j in input().split()])

for i in range(m):
        b.append(int(input()))

for i in range(n):
    s = 0
    for j in range(m):
        s += A[i][j] * b[j]
    print(str(s))



Measured memory_bytes: 6016
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a * b / gcd(a, b);
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}

int main() {
	string str; cin >> str;
	string u = str.substr(0, 2), d = str.substr(2, 2);
	int up = atoi(u.c_str()), down = atoi(d.c_str());
	bool uy = 0, um = 0, dy = 0, dm = 0;
	if (up >= 0 && up < 100) uy = 1;
	if (up > 0 && up < 13) um = 1;
	if (down >= 0 && down < 100) dy = 1;
	if (down > 0 && down < 13) dm = 1;
	if (uy && dm) {
		if (um && dy) {
			cout << "AMBIGUOUS";
			return 0;
		}else {
		cout << "YYMM";
		return 0;
	}
	}
	
	if (um && dy) {
		if (uy && dm) {
			cout << "AMBIGUOUS";
			return 0;
		}else {
		cout << "MMYY";
		return 0;
	}
	}
	
	cout << "NA";



	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//NOT TO SUBMIT IN WRONG PLACE OR BY WRONG COMPILER
//ABC 178, task b, 2020/09/13
//ms,

/*
*/

int main(void){
  int64_t a, b, c, d;
  int64_t ans=-3000000000000000000;
  cin >>a >>b >>c >>d;

  ans=max(ans, a*c);
  ans=max(ans, a*d);
  ans=max(ans, b*c);
  ans=max(ans, b*d);

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


Measured memory_bytes: 3616
import java.util.Scanner;
class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
        String c0=sc.next();
        char[] c1=c0.toCharArray();

        char alphabet[]=new char[26];
        char c='a';
        for(int i=0; i<26; i++){
            alphabet[i]=c++;
        }
        for(int j=0; j<26; j++){
            if(c1[0]==alphabet[j]){
                System.out.println(alphabet[j+1]);
                break;
            }
        }
        sc.close();
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
using vvll = vector<vector<long long>>;
using pii = pair<int, int>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define reps(i,n) for(int i = 1; i <= (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define rreps(i,n) for(int i = (int)(n); i > 0; i--)
#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define RFOR(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define call(x) (x).cbegin(), (x).cend()
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
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 (b<a) {a=b; return 1;} return 0;}
const int INF = INT_MAX;
const int MOD = 1000000007;
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};

int main() {
    ll N;
    cin >> N;
    vi N_list;
    while (N > 0) {
        int i = N % 10;
        N_list.push_back(i);
        N /= 10;
    };
    int ans = 9 * (N_list.size() - 1) + N_list[N_list.size() - 1];
    if (N_list.size() != 1 && N_list[0] != 9) ans--;
    cout << ans << endl;
}

Measured memory_bytes: 256
<?php
      
    	$n = trim(fgets(STDIN));
		$ans = "";
          
        if($n === "Sunny"){
          $ans = "Cloudy";
        }else if($n === "Cloudy"){
          $ans = "Rainy";
        }
        else{
          $ans = "Sunny";
        }
    	 echo trim($ans);
      ?>

Measured memory_bytes: 3700
n=int(input()) 
l = list(map(int,input().split())) 
if n<=2:
  print(0)
  exit()
  
cnt = 0
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if (l[i]-l[j])*(l[j]-l[k])*(l[k]-l[i])==0:
        continue
      if l[i]<l[j]+l[k] and l[j]<l[i]+l[k] and l[k]<l[i]+l[j]:
        cnt+= 1
print(cnt)


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
    ll n;cin >>n;
    ll f[n][10];
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 10; ++j) {
            cin >>f[i][j];
        }
    }
    vector<vector<ll>>p(n,vector<ll>(11));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 11; ++j) {
            cin >>p[i][j];
        }
    }
    ll ans=-INF;
    for (int i = 1; i < (1LL<<10) ; ++i) {
        ll now=0;vector<ll>cnt(n,0);
        for (int j = 0; j < 10; ++j) {
            if(i&(1<<j)){
                for (int k = 0; k < n; ++k) {
                    if(f[k][j]==1){
                        cnt[k]++;
                    }
                }
            }
        }
        for (int l = 0; l < n; ++l) {
            now+=p[l][cnt[l]];
        }
        //if(i==512){
          //  cout <<cnt[0]<<" "<<cnt[1]<<endl;
            //cout <<p[0][0]<<" "<<p[1][1]<<endl;
        //}
        ans=max(ans,now);
    }
    cout <<ans <<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
d = list(map(int,input().split()))
MOD = 998244353
dmax = max(d)
dmin = min(d[1:])
cnt = [0] * n
for i, dd in enumerate(d):
    cnt[dd] += 1

if d[0] != 0 or dmin == 0:
    print(0)
    exit()
ans = 1
before = cnt[0]
for i in range(1,dmax+1):
    ans *= pow(before, cnt[i],MOD)
    before = cnt[i]
ans %= MOD
print(ans)


Measured memory_bytes: 13908
#include <stdio.h>
#include <cstdlib>
#include <cassert>
#include <iostream>
#include <set>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <complex>
#include <map>
#include <queue>
#include <array>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef long double ld;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<pii> vii;
typedef vector<string> vs;
//typedef long long int;

int nx[200005][36];

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  string s;
  cin >> s;
  s = "a" + s;
  int n = s.size();
  vi v(n+1);
  for (int i = 0; i < n; ++i) v[i] = s[i] - 'a';
  for (int i = 0; i < 26; ++i) {
    nx[n-1][i] = n;
  }
  for (int i = n-2; i >= 0; --i) {
    memcpy(nx[i], nx[i+1], sizeof(nx[i]));
    nx[i][v[i+1]] = i+1;
  }
  vi l(n + 1, n + 1);
  l[n] = 1;
  for (int i = n-1; i >= 0; --i) {
    for (int j = 0; j < 26; ++j) {
      l[i] = min(l[i], 1 + l[nx[i][j]]);
    }
  }
  string res = "";
  int pos = 0;
/*  int ma = n+2, pos = -1;
  for (int i = 0; i < n; ++i) {
    if (l[i] < ma || (l[i] == ma && v[i] < v[pos])) {
      ma = l[i];
      pos = i;
    }
  }*/
  while (pos < n) {
    //cerr << pos << ' ' << l[pos] << endl;
    //res += 'a' + v[pos];
    int npos = -1, ma = n+2, add = 0;
    for (int j = 0; j < 26; ++j) {
      if (l[nx[pos][j]] < ma || (l[nx[pos][j]] == ma && v[nx[pos][j]] < v[npos])) {
        ma = l[nx[pos][j]];
        npos = nx[pos][j];
        add = j;
      }
    }
    pos = npos;
    res += 'a' + add;
  }
  cout << res << endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  bool ok = true;
  for (int i = 0; i < N; ++i) {
    int t, x, y;
    cin >> t >> x >> y;
    if (t < x + y || t % 2 != (x + y) % 2) {
      ok = false;
      break;
    }
  }

  if (ok) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())

# コーナーケース！！！

if h == 1 or w == 1:
	print(1)
elif h % 2 == 1 and w % 2 == 1:
	print(h * w // 2 + 1)
else:
	print(h * w // 2)

Measured memory_bytes: 38256
N,K = (int(i) for i in input().split()) 
A = [int(i) for i in input().split()] 

mod = 10**9+7
ans = 0

for i in range(N):
	bs = [1 if g < A[i] else 0 for g in A]
	ans += (K+1)*K*sum(bs)//2 - sum(bs[:i])*K
print(int(ans)%mod)

Measured memory_bytes: 3188
import math

N, A, B, C = map(int,input().split())
mod = 10**9+7

def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

g1 = [1, 1]
g2 = [1, 1]
inv = [0, 1] 
for i in range(2, 2*10**5+1):
    g1.append((g1[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod//i)) % mod)
    g2.append((g2[-1] * inv[-1]) % mod)

def g(a):
    b, u, v = mod, 1,0
    while b:
        t = a//b
        a -= t * b
        u -= t * v
        a,b,u,v = b,a,v,u
        u %= mod
    return u if u > 0 else u + mod

p1,p2 = A * g(A + B) % mod, B * g(A + B) % mod
p3 = (100 - C) * g(100) % mod

ans = 0
for i in range(N):
    ans += (N+i)*cmb(N+i-1,i,mod)*(pow(p1,N,mod) * pow(p2,i,mod) + pow(p1,i,mod) * pow(p2,N,mod))
    ans %= mod
ans = ans * g(p3) % mod
print(ans)

Measured memory_bytes: 26916
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;

const int MAXN = 55555;
int prime[MAXN+1]; // n 以下の素数のうち i 番目の素数
bool is_prime[MAXN+1]; // 整数 i が素数であるかどうか
int sieve(int n = MAXN) {
  int res = 0;
  fill(is_prime, is_prime + MAXN, true);
  is_prime[0] = is_prime[1] = false; // 0 と 1 は素数ではない。
  reps(i,2,n+1) {
    if(!is_prime[i]) continue;
    prime[res++] = i;
    for(int j = 2*i ; j<=n ; j+=i ) is_prime[j] = false; // 素数 i の倍数は素数ではない (ふるい(篩)にかける)
  }
  return res;
}


void Main(){

  int N;
  cin>>N;

  sieve();

  rep(i,MAXN+1){
    if(is_prime[i] and i%10==1){
      cout<< i <<" ";
      --N;
    }
    if(N<=0) break;
  }


  cout<<"\n";
}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define SMAX 10000

int main(){
  unsigned short *X,*Y;

  int D[SMAX+ 1];
  int num,j,i;
  scanf("%d",&num);

  X= malloc(sizeof(short) * num+1);
  Y = malloc(sizeof(short) * num +1);

  for(i=0;i<=SMAX;i++){
    D[i] = 0;
  }

  for(i=0;i<num; i++){
    scanf("%hu",&X[i+1]);
    D[X[i+1]]++;
    
  }

  for(i=1;i<=SMAX;i++){
    D[i]=D[i] + D[i-1];
}

  for(j=1;j<=num;j++){
    Y[D[X[j]]] = X[j];
    D[X[j]]--;
  }

  for(i=1;i<=num;i++){
    if(i>1){
      printf(" ");
    }
    printf("%d",Y[i]);
  }
  printf("\n");

  return 0;
}
  



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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver2 {
 public:
  int n, k;
  Solver2(LL n, LL k) : n(n), k(k){};

  void solve() {
    if (2 * k > n + 1) {
      cout << -1 << endl;
      return;
    }
    vector<int> a(n), b(n), c(n), ub(n), uc(n);
    vector<vector<int>> ans;
    for (int i = 0; i < n; ++i) {
      a[i] = k + i;
      b[i] = k + n + i;
      c[i] = k + 2 * n + i;
    }
    DBG(a, b, c)
    int mx = min(b.back(), 2 * n);
    int pos = mx - (k + n);
    int j = n - 1;
    for (int i = pos, k = n - 1; i >= 0 && k >= 0; --i, --j, k -= 2) {
      DBG(i, j, k)
      ans.push_back({a[j], b[i], c[k]});
      ub[i] = 1;
      uc[k] = 1;
    }
    for (int i = n - 1, k = n - 1; j >= 0; --j) {
      while (ub[i]) --i;
      while (uc[k]) --k;
      ans.push_back({a[j], b[i], c[k]});
      ub[i] = 1;
      uc[k] = 1;
    }
    for (auto &&v : ans) {
      cout << v[0] << ' ' << v[1] << ' ' << v[2] << endl;
    }
  }
};
}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0, k;
  std::cin >> n >> k;

  Problem::Solver2 sol(n, k);
  sol.solve();
  return 0;
}


Measured memory_bytes: 10160
# -*- coding: utf-8 -*-
from collections import Counter
N = int(input())
a_i = list(map(int, input().split()))
c = Counter(a_i)
rtn = 0
for a,cnt in c.items():
    if cnt > a:
        rtn += cnt-a
    elif cnt < a:
        rtn += cnt
print(rtn)        


Measured memory_bytes: 18676
#define FILEIO(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout);
#include <stdio.h>
#include <queue>
#include <algorithm>
#define N 10005
using namespace std;
int n,k,q,a[N],b[N],c[N];
inline int min(int a,int b){return a<b?a:b;}
int solve(int x) {
	int i,j,ans=0,m=0,t,p;
	for(i=0;i<n;++i) {
		for(j=i;j<n&&a[j]>=x;++j);
		if(j-i>=k) {
			p=j-i-k;
			for(t=0;i<j;) b[t++]=a[i++];
			sort(b,b+t);
			while(~p) c[m++]=b[p--];
		}
	}
	if(m<q) return 1<<30;
	sort(c,c+m);
	return c[q-1]-x;
}
int main() {
//	FILEIO("operation");
	int i,ans=1<<30;
	scanf("%d%d%d",&n,&k,&q);
	for(i=0;i<n;++i) scanf("%d",a+i);
	for(i=0;i<n;++i) ans=min(ans,solve(a[i]));
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

public class CSharp
{
    public static void Main()
    {
        Kyopuro chokudai = new Kyopuro();
        chokudai.AtCoder();
    }
}

public class Kyopuro
{

    int n, k;
    int[] a, b, y;
    List<int>[] x;
    bool[] v;

    public void AtCoder()
    {
        string[] input;
        input = Console.ReadLine().Split(' ');
        n = int.Parse(input[0]);
        k = int.Parse(input[1]);
        a = new int[n - 1];
        b = new int[n - 1];
        v = new bool[n];
        x = new List<int>[n];
        y = new int[n];

        for (int i = 0; i < n; i++) x[i] = new List<int>();
        for(int i=0; i<n-1; i++)
        {
            input = Console.ReadLine().Split(' ');
            a[i] = int.Parse(input[0]) - 1;
            b[i] = int.Parse(input[1]) - 1;
            x[a[i]].Add(b[i]);
            x[b[i]].Add(a[i]);
        }

        y[0] = k;
        v[0] = true;
        dfs(0, 1);
        long ans = 1;
        for (int i = 0; i < n; i++)
        {
            DebugWL(y[i]);
            ans = ans * y[i] % 1000000007;
        }
        
        Console.WriteLine(ans);
    }

    public void dfs(int u, int c)
    {
        int tmp = 0;
        for (int i=0; i<x[u].Count; i++)
        {
            
            if (!v[x[u][i]])
            {
                y[x[u][i]] = k - c - tmp;
                v[x[u][i]] = true;
                dfs(x[u][i], Math.Min(2, c + 1));
                tmp++;
            }
        }
    }
    public static void DebugWL(object x) { System.Diagnostics.Debug.WriteLine(x); }
}

Measured memory_bytes: 30732
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;

class Point{
public:
  double x,y;
  Point(double x=0,double y=0):x(x),y(y){}

  Point operator+(Point p){return Point(x+p.x,y+p.y);}
  Point operator-(Point p){return Point(x-p.x,y-p.y);}
  Point operator*(double k){return Point(x*k,y*k);}
  Point operator/(double k){return Point(x/k,y/k);}

  double abs(){return sqrt(norm());}

  double norm(){return (x*x+y*y);}
};
typedef Point Vector;

class Segment{
public:
  Point p1,p2;
  Segment(Point p1,Point p2):p1(p1),p2(p2){}
};
typedef Segment Line;

double dot(Vector a,Vector b){return (a.x*b.x+a.y*b.y);}
double cross(Vector a,Vector b){return (a.x*b.y-a.y*b.x);}

Point project(Segment s,Point p){
  Vector base=(s.p2-s.p1);
  double r=(dot(p-s.p1,base)/base.norm());
  return (s.p1+base*r);
}

Point reflect(Segment s,Point p){
  return p+(project(s,p)-p)*2;
}

int main()
{
  Point A,B,C,D;
  int q;

  cin>>A.x>>A.y>>B.x>>B.y;
  cin>>q;
  for(int i=0;i<q;i++){
    cin>>C.x>>C.y;
    D=reflect(Segment(A,B),C);
    printf("%.10f %.10f\n",D.x,D.y);
  }
  return 0;
}

Measured memory_bytes: 1252
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        
        boolean hantei = true;
        int i = 1;
        while(hantei) {
            if(N < Math.pow(K, i)) {
                System.out.println(i);
                hantei = false;
            }
            i++;
        }
    }
}

Measured memory_bytes: 21588
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

using namespace std;

#define lli long long int
#define REP(i,n) for(int i=0;i<n;i++)
#define REP2(i,n) for(int i=1;i<=n;i++)
#define DEBUG 0

typedef struct UnionFind{
	vector<lli> par; //par[i]:iの親番号 par[3] = 2 : 3の親が2
	vector<lli> size;//size[i]:iの大きさ 自分のみのときは1,根っこにsizeを持たせる*/

	UnionFind(int N){/*最初はすべてが根であると初期化*/
		REP(i,N){
			par.push_back(i);
			size.push_back(1);
		}
	}

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

	void unite(lli x,lli y){/*xとyの併合*/
		lli rx = root(x);
		lli ry = root(y);
		if(rx == ry)return;
		par[rx] = ry; /*xとyの根が同じじゃない: xの根をrxをyの根ryに変更する */
		lli resize = size[rx] + size[ry];
		size[rx] = resize;
		size[ry] = resize;
	}

	bool same(lli x,lli y){
		lli rx = root(x);
		lli ry = root(y);
		return rx == ry;
	}

	lli getSize(lli x){
		lli rx = root(x);
		return size[rx];
	}
};

int main(){

	lli n,k,l;
	cin>>n>>k>>l;
	UnionFind load(n),train(n);
	map<pair<lli,lli>,lli> mp;

	REP(i,k){
		lli p,q;
		cin>>p>>q;
		p--;
		q--;
		load.unite(p,q);
	}
	REP(i,l){
		lli r,s;
		cin>>r>>s;
		r--;
		s--;
		train.unite(r,s);
	}

	lli a[300000],b[300000];
	REP(i,n){
		a[i]=load.root(i);
		b[i]=train.root(i);
		mp[make_pair(a[i],b[i])]++;
	}

	REP(i,n){
		cout<<mp[make_pair(a[i],b[i])]<<" ";
	}
	cout<<endl;

	return 0;
}

Measured memory_bytes: 23268
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;
const int SIZE = 100009;
int n, q, a, b, c, d, x, y, u, v, depth[SIZE], idx[SIZE], ori[SIZE];
vector<pair<int, pair<int, int> > > vec[SIZE];
vector<pair<int, int> > dat;
vector<int> sp;
bool mk[SIZE];
pair<int, int> sta[350][SIZE];
pair<int, pair<int, int> > par[SIZE];
int par2[20][SIZE];

void dfs(int from, int x)
{
	int cur = 0;
	if (from >= 0) cur = vec[from][x].fi;
	par[cur].fi = from;
	if (cur) par[cur].se.fi = vec[from][x].se.fi;
	if (cur) par[cur].se.se = vec[from][x].se.se;
	if (cur) ori[cur] = ori[from] + vec[from][x].se.se;
	if (cur) depth[cur] = depth[from] + 1;
	dat.pb(make_pair(depth[cur], cur));
	for (int i = 0; i < (int)vec[cur].size(); i++) {
		if (vec[cur][i].fi != from) {
			dfs(cur, i);
		}
	}
}

int fun(int cc, int dd, int cur)
{
	int cnt = 0, sum = 0;
	int t_cur = cur;
	while (1) {
		if (cur <= 0) break;
		if (mk[cur]) {
			cnt += sta[idx[cur]][cc].se;
			sum += sta[idx[cur]][cc].fi;
			break;
		}
		else {
			if (par[cur].se.fi == cc) {
				cnt++;
				sum += par[cur].se.se;
			}
		}
		cur = par[cur].fi;
	}
	int retval = ori[t_cur] - sum + cnt * dd;
	return retval;
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> q;
	for (int i = 0; i < n - 1; i++) {
		cin >> a >> b >> c >> d;
		a--; b--;
		vec[a].pb(make_pair(b, make_pair(c, d)));
		vec[b].pb(make_pair(a, make_pair(c, d)));
	}
	dfs(-1, 0);
	sort(dat.begin(), dat.end());
	for (int i = (int)dat.size() - 1; i >= 0; i--) {
		bool ok = false;
		int tmp = dat[i].se;
		for (int j = 0; j < 350; j++) {
			if (tmp < 0) break;
			if (mk[tmp]) {
				ok = true;
				break;
			}
			else {
				tmp = par[tmp].fi;
			}
		}
		if (ok) continue;
		if (tmp < 0) continue;
		if (!mk[tmp]) {
			mk[tmp] = true;
			sp.pb(tmp);
		}
	}
	for (int i = 0; i < (int)sp.size(); i++) {
		//if (i >= 500) break;
		int t = sp[i];
		idx[sp[i]] = i;
		while (1) {
			if (t <= 0) break;
			sta[i][par[t].se.fi].fi += par[t].se.se;
			sta[i][par[t].se.fi].se++;
			t = par[t].fi;
		}
	}
	for (int i = 0; i < n; i++) par2[0][i] = par[i].fi;
	for (int i = 1; i < 18; i++) {
		for (int j = 0; j < n; j++) {
			if (par2[i - 1][j] < 0) {
				par2[i][j] = -1;
			}
			else par2[i][j] = par2[i - 1][par2[i - 1][j]];
		}
	}
	while (q--) {
		cin >> x >> y >> u >> v;
		u--; v--;
		int tu = u, tv = v, lca;
		if (depth[u] < depth[v]) swap(u, v);
		for (int i = 0; i < 17; i++) {
			if (u < 0) break;
			if (((depth[u] - depth[v]) >> i) & 1) {
				u = par2[i][u];
			}
		}
		for (int i = 17; i >= 0; i--) {
			if (u < 0 || v < 0) break;
			if (par2[i][u] != par2[i][v]) {
				u = par2[i][u];
				v = par2[i][v];
			}
		}
		if (u == v) lca = u;
		else lca = par2[0][u];
		if (u < 0 || v < 0 || lca < 0) {
			cout << 0 << E;
			continue;
		}
		int ans = fun(x, y, tu);
		ans += fun(x, y, tv);
		ans -= 2 * fun(x, y, lca);
		cout << ans << E;
	}
	//system("pause");
	return 0;
}


Measured memory_bytes: 248564
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
std::mt19937 rnd(time(NULL));
#define rand rnd
#define pr std::pair<int,int>
#define fi first
#define se second
template<class T>void cxk(T&a,T b){a=a>b?a:b;}
template<class T>void cnk(T&a,T b){a=a<b?a:b;}
#ifdef mod
int pow(int x,int y){
	int ret=1;
	while(y){
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;y>>=1;
	}
	return ret;
}
template<class Ta,class Tb>void inc(Ta&a,Tb b){a=a+b>=mod?a+b-mod:a+b;}
template<class Ta,class Tb>void dec(Ta&a,Tb b){a=a>=b?a-b:a+mod-b;}
#endif
int fir[100010],dis[400010],nxt[400010],id=1;
void link(int a,int b){nxt[++id]=fir[a],fir[a]=id,dis[id]=b;}
std::vector<int>G[100010];
int FA[100010],fw[100010],D[100010];
int col[100010],ans[200010];
void dfs(int x){
	for(int i:G[x]){
		ans[fw[i]]=D[i];
		if(!col[i])col[i]=3-col[x],dfs(i);
	}
}
int main(){
#ifdef LOCAL
	freopen("in.in","r",stdin);
	//freopen("out.out","w",stdout);
#endif
	int n=gi(),m=gi(),u,v;
	for(int i=1;i<=n;++i)D[i]=gi();
	for(int i=1;i<=m;++i)u=gi(),v=gi(),link(u,v),link(v,u),ans[i]=1000000000;
	D[0]=2e9;
	for(int x=1;x<=n;++x){
		int o=0,p;
		for(int i=fir[x];i;i=nxt[i])if(D[dis[i]]<D[o]||(D[dis[i]]==D[o]&&dis[i]<o))o=dis[i],p=i>>1;
		if(D[o]>D[x])puts("-1"),exit(0);
		G[FA[x]=o].push_back(x);fw[x]=p;
	}
	for(int i=1;i<=n;++i)if(FA[FA[i]]==i&&i<FA[i])col[i]=1,dfs(i);
	for(int i=1;i<=n;++i)putchar(col[i]==1?'B':'W');puts("");
	for(int i=1;i<=m;++i)printf("%d\n",ans[i]);
	return 0;
}


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

int main() {
    int a, b, k;
    cin >> a >> b >> k;
    for (int i = 0; i < k; i++) {
        if (i%2 == 0) {
            if (a%2==1) a--;
            b += a/2;
            a /= 2;
        }
        else {
            if (b%2==1) b--;
            a += b/2;
            b /= 2;
        }
    }
    printf ("%d %d",a,b);
}

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n, m = LI()
if n == 1 and m == 1:
    print(1) 
elif n == 1:
    print(max(0, m-2))
elif m == 1:
    print(max(0, n-2))
else:
    print((n-2)*(m-2))

Measured memory_bytes: 65576
#include<bits/stdc++.h>
#include<set>
#include<queue>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
using namespace std;
typedef long long ll;

#define pb push_back
#define PI acos(-1.0)
#define MAX 10000007 //1e7+7
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define __FastIO  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
struct P
{
  ll pos,val;
};


int main(){
  ll N,M,A,B,C,D,testCase,K;
  ll arr[1005],brr[100005];
  map<ll,ll>mp;
  vector<ll>v,v1;
  vector< pair<ll,ll> >Pair;
  string str;
  while(cin>>str)
  {
    if(str=="SAT")
    {
      cout<<"1"<<endl;
    }
    else if(str=="SUN")
    {
      cout<<"7"<<endl;
    }
    else if(str=="MON")
    {
      cout<<"6"<<endl;
    }
    else if(str=="TUE")
    {
      cout<<"5"<<endl;
    }
    else if(str=="WED")
    {
      cout<<"4"<<endl;
    }
    else if(str=="THU")
    {
      cout<<"3"<<endl;
    }
    else if(str=="FRI")
    {
      cout<<"2"<<endl;
    }
    
  }
  return 0;
}


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

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

  int max=-1;
  for(int i=0;i<n-1;i++)
    for(int j=i+1;j<n;j++){
      int k=a[i]*a[j];
      if(k>max){
	int digit=k%10;
	int dummy=k/10;
	while(dummy>0){
	  if(digit-1==dummy%10) digit=dummy%10;
	  else break;
	  dummy/=10;
	}
	if(dummy==0) max=k;
      }
    }
  
  cout<<max<<endl;
}


Measured memory_bytes: 3076
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<vector>

int main() {
   
   int N, M, X, Y;
   std::cin >> N >> M >> X >> Y;
   int x;
   int y;

   for (int i = 0; i < N; i++) {
      int tmp;
      std::cin >> tmp;
      if (i == 0) x = tmp;
      if (tmp > x) x = tmp;
   }
   for (int i = 0; i < M; i++) {
      int tmp;
      std::cin >> tmp;
      if (i == 0) y = tmp;
      if (tmp < y) y = tmp;
   }
   for (int i = X + 1; i <= Y; i++) {
      if (x < i && i <= y) {
         std::cout << "No War" << std::endl;
         return 0;
      }

   }
   std::cout << "War" << std::endl;
   return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
ll T,n,ans,a[205];
vector<ll> g;
string s;
int main(){
	T=read();
	while(T--){
		n=read(),ans=0;
		g.clear();
		for(int i=0;i<n;i++)
			a[i]=read();
		cin >> s;
		for(int i=n-1;i>=0;i--){
			for(int j=0;j<g.size();j++)
				a[i]=min(a[i],a[i]^g[j]);
			if(a[i]==0)continue;
			if(s[i]=='0')g.push_back(a[i]);
			else ans=1;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll   = long long;
using pll  = pair<ll,ll>;
using vll  = vector<pll>;
using vvll = vector<vll>;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define dmax(a,b) a=max(a,b)

int main() {
    int n; cin >> n;
    vll a(1<<n);
    vvll dp(1<<n, vll(2));
    rep(i,1<<n) {
        scanf("%ld", &a[i].first);
        a[i].second = i;
        dp[i][0] = a[i];
    }
    rep(b,1<<n) {
        rep(i,n) {
            int nb = b | (1<<i);
            if (nb == b) continue;
            set<pll> S;
            rep(j,2) {
                S.insert(dp[b][j]);
                S.insert(dp[nb][j]);
            }
            auto mx = S.rbegin();
            dp[nb][0] = *mx;
            dp[nb][1] = *++mx;
        }
    }
    ll ans = 0;
    rng(i,1,1<<n) {
        dmax(ans, dp[i][0].first + dp[i][1].first);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 25600
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
//#define i_7 (ll)(1E9+7)
#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
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;
}

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




ll po(ll i,ll p){
    if(p==0)return 1;
    else{
        i=mod(i);
        if(p==1)return i;
        if(p%2==0)return po(mod(i*i),p/2);
        return mod(i*po(i,p-1));
    }
}
ll bunbo(ll n){
    return po(n,i_5);
}


#define N 500004
ll kai[N];
ll kai2[N];
void calc(){
    kai[0]=1;
    kai2[0]=1;
    rep(i,1,N-1){
        kai[i]=mod(kai[i-1]*i);
    }
    kai2[N-1]=po(kai[N-1],i_5);
    for(ll i=N-2;i>=0;i--){
        kai2[i]=mod(kai2[i+1]*(i+1));
    }
}
ll comb(ll n,ll k){
    if(n<k)return 0;
    if(n==0)return 1;
    return mod(mod(kai[n]*kai2[n-k])*kai2[k]);
}


int main(){fastio
    calc();
    ll n,m,k;cin>>n>>m>>k;
    ll ans=0;
    rep(same,0,k){
        ll kaz=n-same;
        ll cmb=comb(n-1,same);
        
        ll ad=mod(cmb*m);
        ad=mod(ad*po(m-1,kaz-1));
        Add(ans,ad);
       // cout<<ad<<endl;
    }
    cout<<mod(ans)<<endl;
    
    return 0;
}




Measured memory_bytes: 11464
#include <stdio.h>
#include <string.h>
#include <math.h>

int main() {

    char s[100];
    char temp[50];

    scanf("%s", s);

    int l1 = strlen(s);
    int l2 = l1 / 2;
    int l3 = l2 / 2;
    int isCheck = 1;

    for (int i = 0; i < l2; i++) {
        //printf("%d %d %c %c\n", l1, i, s[i], s[l1 - i - 1]);
        if (s[i] != s[l1 - i - 1]) {
            isCheck = 0;
        } else {
            temp[i] = s[i];
        }
    }

    if (isCheck == 1) {

        for (int j = 0; j < l2; j++) {

            //printf("%c %c\n", temp[j], temp[l2 - j - 1]);
            if (temp[j] != temp[l2 - j - 1]) {
                isCheck = 0;
            }

        }

    }

    printf("%s", (isCheck == 1 ? "Yes" : "No"));


    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    string s;
    
    cin>>s;
    
    bool app[26];
    for(int i=0;i<26;i++) app[i]=false;
    for(int i=0;i<s.size();i++) app[s[i]-'a']=true;
    
    for(int i=0;i<26;i++){
        if(!app[i]){
            cout<<char(i+'a')<<endl;
            return 0;
        }
    }
    cout<<"None"<<endl;
    
}

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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;

int K;

int main(void) {

    cin >> K;

    queue<ll> Q;
    rep(i, 9) {
        Q.push(i + 1);
    }

    ll ans;
    for(int i = 1; i <= K; ++i) {
        ll x = Q.front();
        Q.pop();
        if (i == K) {
            ans = x;
            break;
        }

        if (x % 10 != 0) Q.push(10 * x + (x % 10 - 1));
        Q.push(10 * x + (x % 10));
        if (x % 10 != 9) Q.push(10 * x + (x % 10 + 1));
    }

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

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int mod=1e9+7;
//const int mod=998244353;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=4e5+10;
const ll inf=0x3f3f3f3f;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    string s;
    cin>>s;
    int q;cin>>q;
    vector<char> v1,v2;
    int x=0;
    while(q--){
        int t;cin>>t;
        if(t==1)x^=1;
        else{
            int f;
            char c;
            cin>>f>>c;
            if(f==1){
                if(!x)v1.pb(c);
                else v2.pb(c);
            }
            else{
                if(!x)v2.pb(c);
                else v1.pb(c);
            }
        }
    }
    if(!x){
        for(int i=v1.size()-1;i>=0;i--)
            cout<<v1[i];
        cout<<s;
        for(auto c:v2)cout<<c;
    }
    else{
        for(int i=v2.size()-1;i>=0;i--)
            cout<<v2[i];
        reverse(all(s));
        cout<<s;
        for(auto c:v1)cout<<c;
    }
}


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

int make2pow(int N) {
    int res = 1;
    for (int i = 0; i < N; ++i) {
        res *= 2;
    }
    return res;
}

int main() {
    int N, M, X;
    cin >> N >> M >> X;

    vector<int> C(N);
    vector<vector<int>> A(N, vector<int>(M));

    for (int i = 0; i < N; ++i) {
        cin >> C[i];
        for (int j = 0; j < M; ++j) {
            cin >> A[i][j];
        }
    }

    int ans_cost = -1;

    for (int i = 0; i < make2pow(N); ++i) {
        int cost_sum = 0;
        vector<int> A_sum(M);

        for (int j = 0; j < N; ++j) {
            if (i & (1 << j)) {
                cost_sum += C[j];
                for (int k = 0; k < M; ++k) {
                    A_sum[k] += A[j][k];
                }
            }
        }

        bool cleared = true;
        for (int k = 0; k < M; ++k) {
            if (A_sum[k] < X) {
                cleared = false;
            }
        }

        if (!cleared) {
            continue;
        }

        if (ans_cost < 0) {
            ans_cost = cost_sum;
        } else {
            ans_cost = min(ans_cost, cost_sum);
        }
    }

    cout << ans_cost << endl;

}

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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef pair<double, double> P;

//const ll mod = 1e10;
typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;

double arg(P p) {
    return atan2(p.first, p.second);
}

int main() {
    int n;
    cin >> n;
    vector<P> points(n);
    for (P &p:points) cin >> p.first >> p.second;

    sort(points.begin(), points.end(), [](P p1, P p2) {
        return arg(p1) < arg(p2);
    });

    double ans = 0;

    for (int l = 0; l < n; l++) {
        vector<int> v;
        double y = 0, x = 0;
        for (int r = l; r < l + n; r++) {
            v.push_back(r);
            P p = points[r % n];

            y += p.first;
            x += p.second;

            double xx = x * x, yy = y * y;
            double now = sqrt(xx + yy);

            cmax(ans, now);

        }
    }


    cout << setprecision(20) <<  ans << endl;

}

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

int main() {
    int n, t;
    cin >> n >> t;
    int ans = 1001, min_t = 1000;
    for (int i = 0; i < n; i++) {
        int ci, ti;
        cin >> ci >> ti;
        if (ti <= t) {
            if (ti < min_t) {
                ans = min(ans, ci);
            }
        }
    }
    if (ans >= 1001) {
        cout << "TLE" << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}


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

int main(){
  int n, x;
  int sum = 0, mmin = 1000;;
  int m;
  
  cin >> n >> x;
  for ( int i = 0; i < n; i++ ){
    cin >> m;
    sum += m;
    mmin = min( mmin, m );
  }
  
  cout << n + ( x - sum ) / mmin << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define rt return
#define ENDL cout<<endl
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; }

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};



int main(){
    int N,W;cin >> N >> W;
        vector<pair<LL,LL>> vec;
        vec.push_back({0,0});
        for(int i = 0;i < N;i++){
            int b;cin >>b;
            int c;cin >> c;
            vec.push_back({b,c});
        }
        vector<vector<LL>> dp(N+1, vector<LL>(W+10,-1e18));
        dp.at(0).at(0)=0;
        for(int a = 1;a <= N;a++){
            for(int b = 0;b <= W;b++){
                if(b - vec.at(a).first >= 0){
                        dp[a][b] = max(dp[a-1][b-vec.at(a).first] + vec.at(a).second,dp[a][b]);
                }
                dp[a][b] = max(dp[a][b],dp[a-1][b]);
            }
        }
        /*
        for(int a = 0;a <= N;a++){
            for(int b = 0;b <= W;b++){
                cout<<dp[a][b]<<" ";
            }
            cout<<endl;
        }
        */
        cout<<*max_element(dp.back().begin(),dp.back().end())<<endl;
}


Measured memory_bytes: 80256
inp = input()
v = input().split(" ")

n = int(inp.split(" ")[0])
m = int(inp.split(" ")[1])

votes = [int(v_) for v_ in v]
votes.sort(reverse=True)

total = sum(votes)
border = total / ( 4 * m )

i = 1
for vote in votes:

    if vote < border :
        print("No")
        exit()

    if i == m:
        print("Yes")
        exit()

    i+=1



Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
class Ho{
  static void Main(){
    int[,] a1= new int[3,3];
    for(var i = 0;i<3;i++){
      var zen = Console.ReadLine().Split();
      a1[i,0]=int.Parse(zen[0]);
      a1[i,1]= int.Parse(zen[1]);
      a1[i,2]=int.Parse(zen[2]);        
    }
    var n = int.Parse(Console.ReadLine());
    for(var i = 0;i<n;i++){
      var b = int.Parse(Console.ReadLine());
      for(var j = 0;j<3;j++){
        for(var h = 0;h <3;h++){
        if(a1[j,h] == b){
          a1[j,h] = 0;
        }
      }
     }
    }
    for(var i = 0;i<3;i++){
      if(a1[i,0] == a1[i,1] &&a1[i,0]== a1[i,2]){
        Console.WriteLine("Yes");
        return;
      }
      if(a1[0,i] == a1[1,i] && a1[1,i]== a1[2,i]){
         Console.WriteLine("Yes");
        return;
      }
      if(a1[0,0] == a1[1,1]&&a1[1,1] == a1[2,2]){
           Console.WriteLine("Yes");
        return;
      }
      if(a1[0,2] == a1[1,1]&& a1[1,1] == a1[2,0]){
           Console.WriteLine("Yes");
        return;
      }
      
    }
    Console.WriteLine("No");
  }
}

Measured memory_bytes: 13140
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef int64_t LL;
typedef uint64_t ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
template<class T, class... U> void DEBUG(const T &head, const U &... tail) { 
#ifdef HOME
    _W('#'); _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...);
#endif
}
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
VI e[SIZE];
int deg[SIZE],N;
set<int>H;
int dfs(int x,int lt){
    if(SZ(e[x])>2)return x;
    REP(i,SZ(e[x])){
        int y=e[x][i];
        if(lt!=y)return dfs(y,x);
    }
    return -1;
}
int main(){
    R(N);
    REPP(i,1,N){
        int x,y;
        R(x,y);
        e[x].PB(y);
        e[y].PB(x);
        deg[x]++;
        deg[y]++;
    }
    int ma=0;
    REP(i,N){
        ma=max(ma,deg[i]);
    }
    if(ma==2)W(1);
    else{
        int an=0;
        REP(i,N){
            if(deg[i]==1){
                H.insert(dfs(i,i));
                an++;
            }
        }
        W(an-SZ(H));
    }
    return 0;
}


Measured memory_bytes: 30336
A=list(map(int, input().rstrip().split())) #input parameters\
count=int(0)
A.sort()
while A[0]+1<A[1]:
    A[0]+=2
    count+=1
while A[0]!=A[2]:
    A[0]+=1
    A[1]+=1
    A.sort()
    count+=1
print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define N_MAX 1000
#define ll long long int
using namespace std;

int main() {
	int N; cin >> N;
	vector<int> P(N),Q(N);
	for (int i = 0; i < N; i++) {
		cin >> P[i]; P[i]--;
	}
	for (int i = 0; i < N; i++) {
		cin >> Q[i]; Q[i]--;
	}

	vector<int> A(N);
	for (int i = 1; i <= N; i++) A[i] = i;

	int a = 0, b = 0, cnt = 0, flagp = 0, flagq = 0;
	do {
		cnt++;

		int cnta = 0;
		if (flagp == 0) {
			for (int i = 0; i < N; i++) {
				if (P[i] == A[i]) cnta++;
				else break;
				if (cnta == N) a = cnt;
			}
		}

		int cntb = 0;
		if (flagq == 0) {
			for (int i = 0; i < N; i++) {
				if (Q[i] == A[i]) cntb++;
				else break;
				if (cntb == N) b = cnt;
			}
		}

	} while (next_permutation(A.begin(), A.end()));

	cout << fabs(a-b) << endl;
}


Measured memory_bytes: 256
/*

* author:mel0n
* le epic style 
*
*

*/

#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(0)
#define lli long long int
#define pi pair<int,int>
#define all(x) (x).begin(),(x).end()

using namespace std;



int main()
{
lli n;
cin>>n;
vector <lli> f(n);
for(lli i=0;i<n;i++)
	cin>>f[i];

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

lli res=0;
for(lli i=1;i<=n-1;i++)
{

if(i==1)
{res+=f.back();
f.pop_back();
continue;
}
if(i%2==0)
{
res+=f.back();
continue;
}
if(i%2==1)
{
res+=f.back();
f.pop_back();
continue;
}


}


cout<<res<<endl;



}



Measured memory_bytes: 4852