akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
  template <size_t N>
  class sieve_of_eratosthenes {
    std::bitset<N> is_prime_;

  public:
    constexpr sieve_of_eratosthenes(){
      is_prime_ = ~is_prime_;
      is_prime_.reset(0), is_prime_.reset(1);
      for (size_t p = 2; p < N; p++) {
        if (!is_prime_.test(p)) continue;
        for (size_t j = 2; j * p < N; j++) {
          is_prime_.reset(p * j);
        }
      }
    }

    // Return the bitset testing if a number is prime.
    constexpr const auto& is_prime() const {return is_prime_;}

    // Returns the vector of prime numbers.
    template <typename T>
    auto primes() const {
      std::vector<T> primes{}; 
      for (size_t i = 0; i < N; i++) {
        if (is_prime_.test(i)) primes.push_back(i);
      }
      return primes;
    }
  };
  int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  auto primes = sieve_of_eratosthenes<10000000>{}.primes<long long>();
  auto make = [&] (int n) {
    auto ans = std::vector<std::vector<long long>>(n, std::vector<long long>(n, 0));
    auto anti_diag = [&] (int i, int j) {
      assert((i + j) % 2 == 0);
      return (i + j) / 2;
    };
    auto diag = [&] (int i, int j) {
      assert((i + j) % 2 == 0);
      return (i + n - 2 - j) / 2;
    };
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if ((i + j) % 2 == 0) {
          ans.at(i).at(j) =
            primes.at(anti_diag(i, j)) *
            primes.at(n + diag(i, j));
        } else {
          ans.at(i).at(j) =
            primes.at(anti_diag(i - 1, j)) *
            primes.at(anti_diag(i + 1, j)) *
            primes.at(n +  diag(i - 1, j)) *
            primes.at(n +  diag(i + 1, j)) + 1;
        }
      }
    }
    return ans;
  };
  int n; std::cin >> n;
  auto large = make(500);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      std::cout << (j > 0 ? " " : "") << large.at(i).at(j);
    }
    std::cout << std::endl;
  }
  return 0;
  }

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

typedef long long ll;
int main(){
  string S;
  cin >> S;
  int N;
  cin >> N;
  
  bool rev = false;
  stack<char> s;
  queue<char> q;
  
  for(int i = 0; i < N; i++){
    int tmp;
    cin >> tmp;
    if(tmp == 1){
      rev = !rev;
    } else {
      int tmp2;
      char x;
      cin >> tmp2 >> x;
      if(tmp2 == 1 && rev){
        q.push(x);
      } 
      if(tmp2 == 1 && !rev){
        s.push(x);
      }
      if(tmp2 == 2 && rev){
        s.push(x);
      }
      if(tmp2 == 2 && !rev){
        q.push(x);
      }
    } 
  }
  
  string ans = "";
  while(!s.empty()){
    char x = s.top();
    s.pop();
    ans = ans + x;
  }
  ans = ans + S;
  while(!q.empty()){
    char x = q.front();
    q.pop();
    ans = ans + x;
  }
  
  if(rev){
    reverse(ans.begin(), ans.end());
  }
  cout << ans << endl;
}

Measured memory_bytes: 2060
#include<stdio.h>
int main(void){
	int a[5],i,t,u;
	for(i=0;i<5;i++){
		scanf("%d",&a[i]);
	}
	if(a[0]<a[1]&&a[0]<a[2]){
		t=a[0];
	}
	else if(a[1]<a[0]&&a[1]<a[2]){
		t=a[1];
	}
	else{
		t=a[2];
	}
	if(a[3]<a[4]){
		u=a[3];
	}
	else{
		u=a[4];
	}
	printf("%d\n",t+u-50);
	return 0;
}

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

int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { 
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int total = 0;
  for (int i = 1; i <= N; ++i) {
    int sum = findSumOfDigits(i); 
    if (sum >= A && sum <= B) { 
      total += i;
    }
  }
  cout << total << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  vector<int> a(n), r;
  for(int & v : a) cin >> v;
  r = a;
  sort(r.begin(), r.end());
  map<int,int> ans;
  for(int i = 0; i < n; i++){
  	int l = n / 2 - 1;
    if(i <= l) l++;
    ans[r[i]] = r[l];
  }
  for(int v : a) cout << ans[v] << endl;
  return 0;
}

Measured memory_bytes: 12928
using System;

namespace C___Dice_and_Coin
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
            var N = read[0];
            var K = read[1];

            double result = 0;
            for(int i = 1 ;  i < N+1 ; i++)
            {
                var count = 0;
                while(K > i * Math.Pow(2,count)) count++;
                result += 1 / (N * Math.Pow(2,count));
            }
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 13140
import java.util.*;

class Main {
	Scanner sc;
	int N;
	int[] P;
	
	private void calc() {
		sc = new Scanner(System.in);
		int N = sc.nextInt();
		P = new int[N];
		for (int i = 0; i < N; i++) P[i] = sc.nextInt();

		int c = 0;
		int min = Integer.MAX_VALUE;
		for (int i = 0; i < N; i++) {
			if (min > P[i]) c++;
			min = Math.min(min, P[i]);
		}

		System.out.println(c);
	}

	public static void main(String[] args) {
		new Main().calc();
	}
}


Measured memory_bytes: 65696
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 1000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ans;
signed main(){
	
    int n,b[111111];
    cin>>n;
    rep(i,n-1)cin>>b[i];
    ans=b[0];
    rep(i,n-1){
        ans+=min(b[i],b[i+1]);
    }
    ans+=b[n-2];
	cout<<ans<<endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
#define int long long int
int count=0;
int answer=0;
void function(vector<int> &v,int initial,int final,int prev,int m,int arr[][4],int q)
{
	if(initial>final)
	{
		count++;
		int here=0;
		int j;
		for(j=0;j<q;j++)
		{
			int a=arr[j][0]-1;
			int b=arr[j][1]-1;
			int c=arr[j][2];
			int d=arr[j][3];
			if(v[b]-v[a]==c)
			{
				here+=d;
			}
		}
		answer=max(answer,here);
	}
	else
	{
		int j;
		for(j=prev;j<=m;j++)
		{
			v.push_back(j);
			function(v,initial+1,final,j,m,arr,q);
			v.pop_back();
		}
	}
}
int32_t main()
{
	int k,a,b;
	cin>>k>>a>>b;
	int j;
	for(j=a;j<=b;j++)
	{
		if(j%k==0)
		{
			cout<<"OK"<<endl;
			return 0;
		}
	}
	cout<<"NG"<<endl;
}


Measured memory_bytes: 3624
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <string>
#include <utility>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstring>
#include <complex>
#include <queue>
#include <stack>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
  int r,d,x;
  cin>>r>>d>>x;
  rep(i,10){
    x=r*x-d;
    cout<<x<<endl;
  }
}


Measured memory_bytes: 888
class UnionFind():
    def __init__(self, n):
        self.parent = [-1 for _ in range(n)]
        # 正==子: 根の頂点番号 / 負==根: 連結頂点数

    def find(self, x):
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return False
        else:
            if self.size(x) < self.size(y):
                x, y = y, x
            self.parent[x] += self.parent[y]
            self.parent[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        x = self.find(x)
        return -self.parent[x]

    def is_root(self, x):
        return self.parent[x] < 0

N,M=map(int,input().split())
uf = UnionFind(N)
hashi = [list(map(int,input().split())) for _ in range(M)]
lis = [0]*M
lis[M-1] = N*(N-1)//2

for i in range(M-2,-1,-1):
    x = hashi[i+1][0]-1
    y = hashi[i+1][1]-1
    if uf.same(x,y):
        lis[i] = tmp
    else:
        xs = uf.size(x)
        ys = uf.size(y)
        uf.unite(x,y)
        tmp = lis[i+1] - xs*ys
        lis[i] = tmp
        if not tmp:
            break 
for i in range(M):
    print(lis[i])


Measured memory_bytes: 34620
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0; }
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
ll nod(ll F) { return log10(F) + 1; }
//**定義場所**//
//gcd, isPrime, eratos, modinv, bitSearch, dfs, bfs, dijkstra, UnionFind//
ll i, j, k, l, m, n; ll N, M, K, H, W, L; string S;
ll MOD = 1000000007; ll ans = 0; ll INF = 9999999999999;
vl flag, color; vll path; vl A, T;
//***********//
int main() {
	ll X;
	cin >> K >> X;
	if (500 * K >= X) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}

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

def F(N,A,B):
    AB = list(zip(A,B))
    AB = [(a,b) for a,b in AB if a < b] # 有用なやつだけ
    AB.sort(key = lambda x: x[1]/x[0], reverse = True)
    if len(AB) == 0:
        return N
    if len(AB) == 1:
        a,b = AB[0]
        x = N//a
        return N + (b-a) * x
    if len(AB) == 2:
        (a,b),(c,d) = AB
        # 2種類目の硬価はa回未満しか使わない：ac個はa優先なので
        return max(N + (N - i * c) // a * (b-a) + i * (d-c) for i in range(a))
    # 効率の良いものから並んでいる
    dp = [0] * (N+1)
    for n in range(N+1):
        x = n
        for a,b in AB:
            if n >= a:
                y = dp[n-a] + b
                if x < y:
                    x = y
        dp[n] = x
    return dp[N]

N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]

answer = F(F(N,A,B),B,A)
print(answer)


AB = [(1,2),(3,4)]
(a,b),(c,d) = AB


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

int MOD(int a){
	return (a %= p) >= 0 ? a : a + p;
}

int power(int a, int N){
	if(N == 0) return 1;
	else if(N % 2 == 0) return power(MOD(a * a), N / 2);
	else return MOD(a * power(a, N - 1));
}

int inverse(int a){
	return power(a, p - 2);
}

int fact(int N){
	static vector<int> _fact(1, 1);
	for(int i = _fact.size(); i <= N; i++){
		_fact.push_back(MOD(i * _fact[i - 1]));
	}
	return _fact[N];
}
 
int fact_inv(int N){
	static vector<int> inv(2, 1), _fact_inv(2, 1);
	for(int i = inv.size(); i <= N; i++){
		inv.push_back(MOD(-(p / i) * inv[p % i]));
		_fact_inv.push_back(MOD(inv[i] * _fact_inv[i - 1]));
	}
	return _fact_inv[N];
}
 
int combination(int N, int k){
	if(k < 0 || N < k || N < 0) return 0;
	else return MOD(fact(N) * MOD(fact_inv(N - k) * fact_inv(k)));
}

signed main(){
	int N, i, ans = 0;
	scanf("%lld", &N);
	vector<int> pow2(N + 1, 1);
	for(i = 1; i <= N; i++){
		pow2[i] = MOD(2 * pow2[i - 1]);
	}
	for(i = N / 2 + 1; i <= N; i++){
		ans = MOD(ans + combination(N, i) * pow2[N - i]);
	}
	printf("%lld\n", MOD(power(3, N) - 2 * ans));
	return 0;
}

Measured memory_bytes: 358520
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

int n, m, p, a, b;
double d[50][50], t[10];
double dp[50][300];
bool vis[50][300];

double solve(int pos, int used)
{
    if (vis[pos][used])
        return dp[pos][used];
    vis[pos][used] = true;
    if (pos == b)
        return dp[pos][used] = 0;
    double res = 1e9;
    rep(i, n)
    {
        if (!(used & (1 << i)))
            continue;
        rep(j, m)
        {
            if (d[pos][j] == 1e9)
                continue;
            res = min(res, solve(j, used - (1 << i)) + (d[pos][j] / t[i]));
        }
    }
    return dp[pos][used] = res;
}

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

    while (1)
    {
        cin >> n >> m >> p >> a >> b;
        if (n == 0)
            break;
        rep(i, 50) rep(j, 300) vis[i][j] = false;
        a--, b--;
        rep(i, n) cin >> t[i];
        rep(i, 50) rep(j, 50) d[i][j] = 1e9;
        rep(i, p)
        {
            int x, y;
            double z;
            cin >> x >> y >> z;
            x--, y--;
            d[x][y] = d[y][x] = z;
        }
        double ans = solve(a, (1 << n) - 1);
        if (ans == 1e9)
            printf("Impossible\n");
        else
            printf("%.20lf\n", ans);
    }
}


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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

queue<string> que;

/*ll bfs(string S){
    que.push(S);
    string S_tmp;
    string S_tmp1=S;
    bool flag = true;
    ll size;
    while(que.size()){
        S_tmp1 = que.front();
        cout << S_tmp1 << endl;
        que.pop();
        for (ll i = 0; i < S_tmp1.size(); i++)
        {
            S_tmp = S_tmp1.erase(i, 1);
            size = S_tmp.size();
            if (size % 2 == 0)
            {
                for (ll i = 0; i < size / 2; i++)
                {
                    if (!(S.at(i) == S.at(i + size / 2)))
                    {
                        flag = false;
                    }
                    if (flag=true)
                    {
                        return size;
                        break;
                    }
                    else
                    {
                        que.push(S_tmp);
                    }
                }
            }
            else{
                que.push(S_tmp);
            }
        }
    }

}*/

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

    ll N;
    string S,S_tmp;
    cin >> S;
    ll size;
    ll flag = 0;

    while(S.size()>0){
        S_tmp = S.erase(S.size()-1);
        size = S_tmp.size();
        if (size % 2 == 0)
        {
            for (ll i = 0; i < size / 2; i++)
            {
                if (!(S_tmp.at(i) == S_tmp.at(i + size / 2)))
                {
                    flag = 1;
                }
            }
            if (flag == 0)
            {
                cout << size << endl;
                break;
            }
        }
        S = S_tmp;
        flag = 0;
        //cout << S << endl;
    }
}


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

#define get_variable_name(x) #x
#define debug(x) cout << #x << " = " << x << endl
#define rep(i, begin, end) for(int (i) = (begin); (i) < (end); (i)++)

#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(), (x).end())
#define REVERSE(x) reverse( (x).begin(),(x).end())
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define PW(x) (1LL<<(x))

using namespace std;
using ll = int64_t;
using P = pair<int, int>;

template<class T,class U>
ostream& operator<<(ostream &os, const pair<T, U> &p) {
    os << get_variable_name(p) << " = (" << p.first <<", " << p.second << ")";
    return os;
}

template<class T>
ostream& operator <<(ostream& os, const vector<T> &v){
    cout << get_variable_name(v) << " = [";
    for(auto i : v) 
        os << " " << i;
    os << " ]";
    return os;
}


const int INF = 1e8;

int x[52];
int N, A;
ll dp[52][52][2510];

ll ok(ll sum, int cnt) {
    if(cnt == 0) return 0LL;
    if(sum % cnt != 0) return 0LL;
    return (sum / cnt == A);
}

ll solve(int idx, int cnt, ll sum) {
    if(idx == N) {
        return ok(sum, cnt);
    }

    if(dp[idx][cnt][sum] >= 0LL) {
        return dp[idx][cnt][sum];
    }

    ll res = 0LL;
    res += solve(idx+1, cnt, sum);
    res += solve(idx+1, cnt+1, sum+x[idx]); 

    return dp[idx][cnt][sum] = res;
}

int main() {
    ios::sync_with_stdio(false);
    cin >> N >> A;
    rep(i, 0, N) cin >> x[i];
    memset(dp, -1, sizeof dp);
    cout << solve(0, 0, 0) << endl;
}


Measured memory_bytes: 53248
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

int main() {
	long n,m;
	cin >> n >> m;
	long a[1005];
	long total = 0;
	rep( i, n )
	{
		cin >> a[i];
		total += a[i];
	}
	sort( a, a + n, greater<long>() );
	bool ok = true;
	rep( i, m )
	{
		if( 4 * m * a[i] < total )
		{
			ok = false;
			break;
		}
	}

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


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

const int64_t MOD = 1000000007;
typedef int64_t ll;
typedef uint64_t ull;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

/* 
  //エラトステネスのふるい
  int maxNum = 100000;
  char isNotPrime[maxNum+1] = {};
  isNotPrime[0]=isNotPrime[1]=1;
  for(int i=2;i<maxNum;i++){
    if(isNotPrime[i]==1) continue;
    int num = i+i;
    while(num<=maxNum){
      isNotPrime[num]=1;
      num += i;
    }
  }
*/
// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

// 降順ソート vector<int> v;
// sort(v.begin(),v.end(),greater<int>());

// keyが降順ソートされるmap
// map<int, int, std::greater<int>> edges;

signed main() {
  int n;
  cin >> n;
  
  map<ll, int, std::greater<int>> edges;

  ll e;
  for(int i=0;i<n;i++){
    cin >> e;
    edges[e]++;
  }

  int count = 0;
  ll area = 1;
  for(auto ed: edges){
    if(ed.second>=2){
      ed.second -= 2;
      area *= ed.first;
      count++;
    }
    if(count==2)break;
    if(ed.second>=2){
      ed.second -= 2;
      area *= ed.first;
      count++;
    }
    if(count==2)break;
  }
  
  if(count==2)
  	cout << area << endl;
  else
    cout << "0" << endl;
  return 0;
}
  

Measured memory_bytes: 9680
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD;
#define MODSUB(SUB_X,SUB_Y)  (SUB_X-SUB_Y)+MOD)%MOD;
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD;
#define LCM(LCM_X,LCM_Y) (LCM_X*LCM_Y)/__gcd(LCM_X,LCM_Y);
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};
int mark[200];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    ll n,ans;
    cin>>n;
    ans=n;
    ll sq=sqrt(n);
    for(ll i=1;i<=sq;i++){
        if(n%i==0){
            ll m=n/i;
            ans=min(ans,m+i-2);
        }
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

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

	    int n=gi();
	    int a=gi();
	    int b=gi();
	    
	    System.out.print(Math.min(a, b) +" "+Math.max(a+b-n,0));
//	    if (m1==m2) {
//	    	System.out.print("0");
//	    }else {
//	    	System.out.print("1");
//	    }



	}

	public static long d(long n) {
		String a=String.valueOf(n);
		return (long)a.length();
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 38764
import java.util.Scanner;
import java.util.HashMap;
import java.util.Map;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] valArr = sc.nextLine().split(" ");
        long n = Long.parseLong(valArr[0]);
        long m = Long.parseLong(valArr[1]);
        long acCount = 0;
        long waCount = 0;

        if (m == 0) {
            sc.close();
            System.out.println("0 0");
        } else {
            Map<Long, Boolean> resultMap = new HashMap<>();
            Map<Long, Long> waCountMap = new HashMap<>();
            for (long i = 1; i <= n; i++) {
                resultMap.put(i, false);
                waCountMap.put(i, 0L);
            }

            while (sc.hasNext()) {
                String apply = sc.nextLine();
                Long problemNo = Long.parseLong(apply.split(" ")[0]);
                String result = apply.split(" ")[1];
                boolean registedResult = resultMap.get(problemNo);
                if (registedResult) {
                    continue;
                }
                if (result.equals("AC")) {
                    acCount++;
                    resultMap.put(problemNo, true);

                } else {
                    long divWaCount = waCountMap.get(problemNo);
                    divWaCount++;
                    waCountMap.put(problemNo, divWaCount);
                }
            }

            sc.close();

            for (long i = 1; i <= n; i++) {
                boolean finalResult = resultMap.get(i);
                if (finalResult) {
                    waCount = waCount + waCountMap.get(i);
                }
            }

            System.out.println(acCount + " " + waCount);
        }
    }

}

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

char Aa(char a, bool b) {
	//b ??§??????
	if (b) {
		if (a >= 'a')return a - 32;
		return a;
	}
	else {
		if (a <= 'Z')return a + 32;
		return a;
	}
}
int main() {
	string a; char b;
	while (cin >> a >> b, b != 'X') {
		vector<string>c; string d; 
		d += a[0];
		for (int i = 1; i < a.length();i++) {
			char e = a[i];
			if (e == '_') { c.push_back(d); d = ""; }
			else if (e <= 'Z') { c.push_back(d); d = ""; d += e; }
			else d += e;
		}
		c.push_back(d);
		switch (b)
		{
		case 'U':
			for (string i : c) {
				cout << Aa(i[0], true);
				for (int x = 1; x < i.length(); x++) {
					cout << i[x];
				}
			}
			cout << endl; break;
		case 'L':
			for (int j = 0; j < c.size(); j++) {
				if (j)cout << Aa(c[j][0], true);
				else cout << Aa(c[j][0], false);
				for (int i = 1; i < c[j].length(); i++)cout << c[j][i];
			}
			cout << endl; break;
		case 'D':
			for (int j = 0; j < c.size(); j++) {
				if (j)cout << '_';
				cout << Aa(c[j][0], false);
				for (int i = 1; i < c[j].length(); i++)cout << c[j][i];
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 3100
import Data.List
import qualified Data.ByteString.Char8 as B
main :: IO ()
main = getLine >> breads >>= main' . sort
    where
        main' ds = getLine >> breads >>= putStrLn . solve ds . sort

solve :: [Int] -> [Int] -> String
solve (d : ds) (t : ts)
    | d > t = "NO"
    | d < t = solve ds (t : ts)
    | otherwise = solve ds ts
solve _ [] = "YES"
solve _ _ = "NO"


breads :: IO [Int]
breads = unfoldr uff <$> B.getLine
    where
        uff b = check <$> B.readInt b
        check (a, b)
            | B.null b = (a, b)
            | otherwise = (a, B.tail b)


Measured memory_bytes: 59772
import sys
import itertools
input = sys.stdin.readline
def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d
n = 10
h,w = map(int,input().split())
d = [[] for i in range(10)] 
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(10):
    d[i] = list(map(int,input().split()))

d = warshall_floyd(d)

res = 0
for i in range(h):
    p = tuple(map(int,input().split()))
    for e in p:
        if e == -1:
            continue
        res += d[e][1]
print(res)

Measured memory_bytes: 40684
N, M = map(int, input().split())
PS = [[0, 0] for i in range(N)] 
for i in range(M):
  p, s = input().split()
  if s == "AC":
    PS[int(p) - 1][0] = 1
  elif s == "WA" and PS[int(p) - 1][0] == 0:
    PS[int(p) - 1][1] += 1
ac = 0
wa = 0
for ps in PS:
  if ps[0] == 1:
    ac += 1
    wa += ps[1]
print(ac, wa)

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

using namespace std;

using pii = pair<int, int>;

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

constexpr int INF = 1e9;

pair<int, double> solve(int y, int x, vector<string> const& v, vector<vector<bool>>& used, bool& ans) {
    const int H = v.size();
    const int W = v[0].size();
    char c = v[y][x];
    int m = 0;
    double mx = 0;
    queue<pii> que;
    que.push(make_pair(y, x));
    int above_m = 0;
    double above_mx = 0;
    int min_x = INF, max_x = -INF;
    while(!que.empty()) {
        pii p = que.front();
        que.pop();
        if(used[p.first][p.second]) {
            continue;
        }
        mx += p.second + 0.5;
        m++;
        used[p.first][p.second] = true;
        for(int i=0; i<4; ++i) {
            int ny = p.first + dy[i], nx = p.second + dx[i];
            if(ny < 0 || H <= ny || nx < 0 || W <= nx || used[ny][nx] || v[ny][nx] != c) {
                continue;
            }
            que.push(make_pair(ny, nx));
        }
        if(p.first + 1 < H && !used[p.first+1][p.second] && v[p.first+1][p.second] != c && v[p.first+1][p.second] != '.') {
            pii r = solve(p.first+1, p.second, v, used, ans);
            above_m += r.first;
            above_mx += r.second;
        }
        if(p.first-1 < 0 || 0 <= p.first-1 && v[p.first-1][p.second] != c && v[p.first-1][p.second] != '.') {
            min_x = min(min_x, p.second);
            max_x = max(max_x, p.second+1);
        }
    }
    pair<int, double> res = make_pair(above_m + m, above_mx+mx);
    double gx = res.second / res.first;
    ans &= (min_x < gx && gx < max_x);
    return res;
}

int main() {
    int w, h;
    while(cin >> w >> h, w) {
        vector<string> v(h);
        for(int i=h-1; i>=0; --i) {
            cin >> v[i];
        }
        vector<vector<bool>> used(h, vector<bool>(w));
        bool ans = true;
        for(int i=0; i<h; ++i) {
            for(int j=0; j<w; ++j) {
                if(v[i][j] != '.' && !used[i][j]) {
                    solve(i, j, v, used, ans);
                }
            }
        }
        if(ans) {
            cout << "STABLE" << endl;
        } else {
            cout << "UNSTABLE" << endl;
        }
    }
}


Measured memory_bytes: 3140
import std.stdio, std.algorithm, std.range, std.conv, std.string, std.math, std.container, std.typecons;
import core.stdc.stdio;
// foreach, foreach_reverse, writeln

void main() {
	int n, k;
	scanf("%d%d", &n, &k);
	int[] x = new int[n];
	foreach (i; 0..n) scanf("%d", &x[i]);
	int c = x.assumeSorted.lowerBound(0).length.to!int;
	int ans = 1<<30;
	foreach (i; 0..c+1) {
		if (i+k > n) break;
		int l = 0, r = 0;
		if (i != c) {
			if (c-i > k) continue;
			l = -x[i];
		}
		r = max(0, x[i+k-1]);
		ans = min(ans, l*2+r);
		ans = min(ans, l+r*2);
	}
	writeln(ans);
}

Measured memory_bytes: 636
#include <iostream>

using namespace std;

int main(void){

  long long X, K, D;
  long long XD, KK;
  long long ans;

  cin >> X >> K >> D;

  if(X<0) X*=-1;

  if(X/D>=K) ans = X - D * K;
  else{
    XD = X / D;
    KK = K - XD;
    X -= XD * D;
    if(KK%2==1) if((X-=D)<0) X*=-1;
    ans = X;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3636
class UnionFind:
    def __init__(self, N):
        self.N = N
        self.parents = [-1] * N

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return (i for i in range(self.N) if self.find(i) == root)

    def roots(self):
        return (i for i, x in enumerate(self.parents) if x < 0)

    def group_count(self):
        return len(list(self.roots()))

    def all_group_members(self):
        dic = {}
        for x in range(self.N):
            r = self.find(x)
            dic.setdefault(r, [])
            dic[r].append(x)
        return dic

import sys
input=sys.stdin.readline
def main():
    N,M=map(int, input().split())
    L=[list(map(int, input().split()))[1:]for _ in range(N)]
    UF=UnionFind(N+M)
    for i in range(N):
        for l in L[i]:
            UF.union(i,N+l-1)
    b=set(i for i in UF.members(0) if i < N)==set(range(N))
    print("YNEOS"[not b::2])

if __name__ == "__main__":
    main()

Measured memory_bytes: 35720
#include <algorithm>
#include <cassert>
#include <iostream>
#include <queue>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

typedef vector<int> SV;
typedef vector<SV> SVV;

#define INF 9999
#define DIVIDER 1000000007
typedef long long int lli;

long long int dfs(vector<int> &bv, vector<lli> &cache, int step, int n) {
  if (step == n) {
    cache[step] = 1;
    return 1;
  } else if (step > n) {
    cache[step] = 0;
    return 0;
  } else {
    if (bv[step]) {
      if (cache[step + 1] == INF) {
        cache[step + 1] = dfs(bv, cache, step + 1, n);
      }
      if (cache[step + 2] == INF) {
        cache[step + 2] = dfs(bv, cache, step + 2, n);
      }
      return (cache[step + 1] + cache[step + 2]) % DIVIDER;
    } else {
      cache[step] = 0;
      return 0;
    }
  }
}

int main(int argc, char const *argv[]) {
  int n, m;
  cin >> n;
  cin >> m;

  vector<int> bv(n + 10, 1);
  vector<lli> cache(n + 10, INF);

  int ai;
  for (int i = 0; i < m; i++) {
    cin >> ai;
    bv[ai] = 0;
  }

  lli ans = dfs(bv, cache, 0, n);

  cout << ans % DIVIDER;
  // cout << ans;

  return 0;
}


Measured memory_bytes: 9216
#include<stdio.h>
int main(){
	int N,K,i;
	scanf("%d", &N);
	scanf("%d", &K);
	int total= 1;
	for(i=0;i<N;i++){
		if(total<K){
			total= total*2;
		}else{
			total= total+K;
		}
		
	}
	printf("%d", total);
	
	
	return 0;
}

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

using namespace std;

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<int> a;
    for(int i = 0; i < n; i++){
        int t;
        cin >> t;
        a.push_back(t);
    }

    ll s1 = 0, s2 = 0, c1 = 0, c2 = 0;
    for(int i = 0; i < n; i++){
        s1 += a[i];
        s2 += a[i];
        if(i % 2 == 0 && s1 <= 0){
            c1 += abs(1 - s1);
            s1 = 1;
        }else if(i % 2 == 1 && s1 >= 0){
            c1 += abs(-1 - s1);
            s1 = -1;
        }

        if(i % 2 == 0 && s2 >= 0){
            c2 += abs(-1 - s2);
            s2 = -1;
        }else if(i % 2 == 1 && s2 <= 0){
            c2 += abs(1 - s2);
            s2 = 1;
        }
    }

    cout << min(c1, c2) << endl;

    return 0;
}

Measured memory_bytes: 892
import numpy as np
import math

N, H = 2, 10
ARR = [
    [3, 5],
    [2, 6]
]

N, H = 4, 1000000000
ARR = [
    [1, 1],
    [1, 10000000],
    [1, 30000000],
    [1, 99999999]
]

N, H = 5, 500
ARR = [
    [35, 44],
    [28, 83],
    [46, 62],
    [31, 79],
    [40, 43]
]

N, H = map(int, input().split())
ARR = [list(map(int,input().split())) for i in range(N)]


def calculate(n, h, arr):
    arr = np.array(arr)
    A1 = arr[:, 0]
    B1 = arr[:, 1]

    largestA1 = max(A1)

    b2 = sorted(B1, key=lambda x: -x)

    result = 0
    for i in range(len(b2)):

        if h <= 0:
            break
        if b2[i] >= largestA1:
            h = h - b2[i]
            result += 1
        else:
            break

    if h > 0:
        result += math.ceil(h / largestA1)

    return result


res = calculate(N, H, ARR)
print(res)


Measured memory_bytes: 40340
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int m, n, ball[100005], ans;
bool used[100005];
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n >> m;
    fill(ball, ball+100005, 1);
    used[1] = true;
    rep(i, 0, m) {
        int x, y;
        cin >> x >> y;
        if (used[x]) used[y] = true; 
        ball[x]--;
        ball[y]++;
        if (ball[x] == 0) {
            used[x] = false;
        }
    }
    cout << count(used, used+n+1, true) << endl;
    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
//#define int long long
using namespace std;
const int origin = 8000;
bool dpx[8000+1][origin*2+1];
bool dpy[8000+1][origin*2+1];

int main() {
    string s; // F:move T:rotate
    int x, y, d1, tmp;
    cin >> s >> x >> y;
    vector<int> mx, my;
    bool first = true, even = true;
    for (int i = 0; i < s.size(); i++) {
        tmp = 0;
        while(i >= 0 && s[i] == 'F') {
            tmp++;
            i++;
        }
        if(first) {
            d1 = tmp;
            first = false;
        } else if(even) {
            my.push_back(tmp);
            even = false;
        } else {
            mx.push_back(tmp);
            even = true;
        }
    }
    //x
    dpx[0][origin+d1] = true;
    for (int i = 0; i < mx.size(); i++) {
        for (int j = -8000; j <= 8000; j++) {
            dpx[i+1][j+origin+mx[i]] |= dpx[i][j+origin];
            dpx[i+1][j+origin-mx[i]] |= dpx[i][j+origin];
        }
    }
    // y
    dpy[0][origin] = true;
    for (int i = 0; i < my.size(); i++) {
        for (int j = -8000; j <= 8000; j++) {
            dpy[i+1][j+origin+my[i]] |= dpy[i][j+origin];
            dpy[i+1][j+origin-my[i]] |= dpy[i][j+origin];
        }
    }
    string ans = "No";
    if(dpx[mx.size()][origin+x] && dpy[my.size()][origin+y]) ans = "Yes";
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 127232
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), m = sc.nextInt(), ans = 0;
        int[] a = new int[m], b = new int[m];
        for(int i = 0; i < m; i++){
            a[i] = sc.nextInt() - 1;
            b[i] = sc.nextInt() - 1;
        }
        for(int x = 0; x < m; x++){
            boolean[][] bl = new boolean[n][n];
            for(int i = 0; i < m; i++)
                if(i != x)
                    bl[a[i]][b[i]] = true;
            for(int k = 0; k < n; k++)
                for(int from = 0; from < n; from++)
                    for(int to = from + 1; to < n; to++)
                            if(bl[Math.min(k, from)][Math.max(k, from)] && bl[Math.min(k, to)][Math.max(k, to)])
                                bl[from][to] = true;
            boolean flag = true;
            for(int from = 0; from < n; from++)
                for(int to = from + 1; to < n; to++)
                    if(!bl[from][to])
                        flag = false;
            if(!flag)
                ans++;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23124
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  int x, y;
  cin >> x >> y;
  int tmp = y, cnt = 0;
  string ans = "No";
  while (tmp > 0) {
    cnt++;
    tmp /= 10;
  }
  for (int i = 0; i < cnt; i++) x *= 10;
  int num = x + y;
  for (int i = 1; i < 1000; i++) {
    if (i * i == num) ans = "Yes";
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } 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; }


using namespace std;
const ll MAXN = 8020;
bool dp_x[MAXN][MAXN*2] = {false}, dp_y[MAXN][MAXN*2] = {false};

int main(){
    string s;
    cin >> s;
    int x, y;
    cin >> x >> y;

    vector<int> t;
    int cnt = 0;

    // 文字列を変形する
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'T') {
            if (cnt != 0) t.push_back(cnt);
            t.push_back(0);
            cnt = 0;
        } else {
            cnt++;
            if (i == s.size()-1) t.push_back(cnt);
        }
    }


    dp_x[0][8000] = true;
    dp_y[0][8000] = true;

    bool flag = false;
    bool xy = true;
    int cnt_x = 0, cnt_y = 0;

    for (int i = 0; i < t.size(); i++) {
        if (t[i] == 0) {
            xy = !xy;
        } else if (xy) {
            cnt_x++;
            for(int j = 0; j < MAXN*2; j++) {
                if (dp_x[cnt_x-1][j]) {
                    if (j + t[i] < MAXN*2) dp_x[cnt_x][j+t[i]] = true;
                    if (j - t[i] >= 0 && flag) dp_x[cnt_x][j-t[i]] = true;
                }
            }
        } else if (!xy) {
            cnt_y++;
            for (int j = 0; j < MAXN*2; j++) {
                if (dp_y[cnt_y-1][j]) {
                    if (j + t[i] < MAXN*2) dp_y[cnt_y][j+t[i]] = true;
                    if (j - t[i] >= 0) dp_y[cnt_y][j-t[i]] = true;

                }
            }
        }

        if (!flag) flag = true;
    }


    cout << ((dp_x[cnt_x][x+8000] && dp_y[cnt_y][y+8000]) ? "Yes" : "No") << endl;

}

Measured memory_bytes: 64384
#include <bits/stdc++.h>
using namespace std;
const int p = 1000000000 + 7;
#define int long long
signed main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	map<int,int>m1,m2;
	for(int i=0;i<n;i++){
		m2[s[i]-'a']++;
	}
	int ans=1;
	for(int i=0;i<n;i++){
		if(m1[s[i]-'a']==0){
			m1[s[i]-'a']++;
			ans=(ans*(m2[s[i]-'a']+1))%p;
		}
	}
	cout << (ans-1+p)%p;
	// your code goes here
	return 0;
}

Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){

    int N, M;
    cin >> N >> M;
    int flg[11][11] = {};
    int p[11] = {};
    for(int i = 0; i < M; i++){
        int k;
        cin >> k;
        for(int j = 0; j < k; j++){
            int s;
            cin >> s;
            s--;
            flg[i][s] = 1;
        }
    }
    for(int i = 0; i < M; i++)cin >> p[i];
    int ans = 0;
    for(int i = 0; i < (1 << N); i++){
        int f = 1;
        for(int j = 0; j < M; j++){
            int cnt = 0;
            for(int k = 0; k < N; k++){
                if((i & (1 << k)) && flg[j][k])cnt++;
            }
            if(cnt % 2 != p[j]){
                f = 0;
            }
        }
        if(f)ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;
int f(int i, int j) {
	if (i%j == 0)
		return i / j;
	else
		return i / j + 1;
}
int main() {
	int n, m, ans = 0, A[101010], B[101010];
	cin >> n >> m;
	rep(i, n) cin >> A[i] >> B[i];

	sort(A, A + n, greater<int>());
	sort(B, B + n, greater<int>());

	rep(i, n) {
		if (B[i] >= A[0]) {
			ans++;
			m -= B[i];
		}
		else {
			ans += f(m, A[0]);
			m -= A[0] * f(m, A[0]);
		}
		if (m <= 0) break;
	}
	if (m <= 0)
		cout << ans << endl;
	else
		cout << ans + f(m, A[0]) << endl;
	return 0;
}

Measured memory_bytes: 1024
from collections import deque
n = int(input())
e = [[] for i in range(n)]
num = 0

for i in range(n-1):
    a,b = map(int,input().split())

    e[a-1].append([b-1,i])
    e[b-1].append([a-1,i])
    num = max(num,len(e[a-1]),len(e[b-1]))

ans = [-1]*(n-1)

q = deque([])
q.append((0,-1))

while q:
    bef,pn = q.popleft()
    c = 0
    for cn,nex in enumerate(e[bef]):
        if ans[nex[1]] == -1:
            c += 1
            if c == pn:
                c += 1
            ans[nex[1]] = c
            q.append((nex[0],c))

print(num)        
for i in ans:
    print(i)

Measured memory_bytes: 46412
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));


int main(){	
	long long N;
	scanf("%lld",&N);
	
	ll k;
	for (k=1; k*k<=2*N; k++) {
		if (k*(k-1) == 2*N) break;
	}
	if (k*(k-1) != 2*N) {
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	cout << k << endl;
	vector<ll> S[k];
	ll cnt = 1;
	rep(i, k) {
		rep(j, k) {
			if (i>=j) continue;
			S[i].push_back(cnt);
			S[j].push_back(cnt);
			cnt++;
		}
	}

	rep(i, k) {
		cout << k-1 << " ";
		rep(j, k-1) {
			cout << S[i][j];
			if (j != k-2) cout << " "; else cout << endl;
		}
	}

	return 0;
}



Measured memory_bytes: 3200
s = STDIN.gets().strip();
t = STDIN.gets().strip();

dict1 = {}

for i in 0...s.length do
  dict1[s[i]] ||= 0
  dict1[s[i]] += 1
end

dict2 = {}
for i in 0...t.length do
  dict2[t[i]] ||= 0
  dict2[t[i]] += 1
end

if dict1.values.sort == dict2.values.sort
  puts "Yes"
else
  puts "No"
end

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

using namespace std;

void solve()
{
	string S;
	cin >> S;
	vector<int> as(3);
	for (char c : S)
	{
		as[c-'a']++;
	}
	sort(as.begin(), as.end());
	cout << (as[2]-as[0] < 2 ? "YES" : "NO") << endl;
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  int aM,aS,bM,bS;
  if(100*a%8==0){
    aS=100*a/8;
  }else{
    aS=100*a/8;
    aS++;
  }
  a++;
  if(100*a%8!=0){
    aM=100*a/8;
  }else{
    aM=100*a/8;
    aM--;
  }
  bS=10*b;
  bM=bS+9;
  if(aM<bS ||bM<aS){
    cout<<-1<<endl;
  }else if(aS<=bS){
    cout<<bS<<endl;
  }else{
    cout<<aS<<endl;
  }
  return 0;
}


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

int calcMP(int A, int B, int C, vector<int> l, vector<int> l_a, vector<int> l_b, vector<int> l_c) {
    int sum_a = 0, sum_b = 0, sum_c = 0;
    
    if(l_a.size() == 0 || l_b.size() == 0 || l_c.size() == 0) return -1;
    for(auto &e: l_a) sum_a += l[e];
    for(auto &e: l_b) sum_b += l[e];
    for(auto &e: l_c) sum_c += l[e];

    int mp_a = (l_a.size() - 1) * 10 + abs(A-sum_a);
    int mp_b = (l_b.size() - 1) * 10 + abs(B-sum_b);
    int mp_c = (l_c.size() - 1) * 10 + abs(C-sum_c);

    return mp_a + mp_b + mp_c;
}

int main() {
    int N, A, B, C;
    vector<int> l;
    vector<int> l_a, l_b, l_c, l_n;
    int minMP = 99999999;

    cin >> N >> A >> B >> C;
    for(int i = 0; i < N; i++) {
        l.push_back(0);
        cin >> l[i];
    }

    for(int i = 0; i < pow(4, N); i++) {
        l_a.clear();
        l_b.clear();
        l_c.clear();
        l_n.clear();

        for(int j = 0; j < N; j++) {
            int kind = (i>>(2*j)) % 4;
            switch(kind) {
            case 0:
                l_n.push_back(j);
                break;
            case 1:
                l_a.push_back(j);
                break;
            case 2:
                l_b.push_back(j);
                break;
            case 3:
                l_c.push_back(j);
                break;
            }
        } 
        int mp = calcMP(A, B, C, l, l_a, l_b, l_c);
        if(mp < 0) continue;
        minMP = min(minMP, mp);
    }

    cout << minMP << endl;   
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;


int main(void){
  int k,i,j,dp[105][2][4]={};
  string n;
  
  cin >> n >> k;
  dp[0][1][0]=1;
  for (i=0;i<n.size();i++){
    dp[i+1][0][0]=1;
    for (j=1;j<=3;j++){
      if (n[i]!='0') dp[i+1][0][j]+=dp[i][1][j];
      dp[i+1][0][j]+=dp[i][0][j-1]*9+dp[i][0][j];
      dp[i+1][0][j]+=dp[i][1][j-1]*max(0,n[i]-'0'-1);
      if (n[i]=='0') dp[i+1][1][j]=dp[i][1][j];
      else dp[i+1][1][j]=dp[i][1][j-1];
    }
  }
  
  cout << dp[n.size()][0][k]+dp[n.size()][1][k] << endl;
  
  return 0;
}

Measured memory_bytes: 256