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

using namespace std;

#define EPS (1e-7)

double get_ex()
{
    int n, m;
    cin >> n >> m;
    double v, r, p = 1, e = 0;
    for (int i = 0; i < m; i++) {
        cin >> v >> r;
        e += v * r;
        p -= r;        
    }
    return e / (1 - p);
}

int main()
{
    int t;
    double max_ex = 0;
    cin >> t;
    while (t--) {
        max_ex = max(max_ex, get_ex());        
    }
    cout << (max_ex - get_ex() > EPS ? "YES" : "NO") << endl;    
    return 0;
}

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

typedef long long ll;
const ll M = 1000000007;

ll modpow(ll x,ll k){
    if(k == 0)return 1;
    ll ret = modpow(x,k/2);
    ret *= ret; ret %= M;
    if(k%2 == 1){
        ret *= x;
        ret %= M;
    }
    return ret;
}

ll fac[602],fac_inv[602];
void fac_init(){
    fac[0] = 1;
    for(int i = 1 ; i <= 600 ; i ++){
        fac[i] = fac[i-1]*i;
        fac[i] %= M;
    }
    for(int i = 0 ; i <= 600 ; i ++){
        fac_inv[i] = modpow(fac[i],M-2);
    }
}

ll f(int x,int y,int z){
    if(z < x || z < y || z > x+y)return 0;
    if(x == 0)return (y == z)?1:0;
    if(y == 0)return (x == z)?1:0;
    ll ret = 1;
    ret *= fac[z];
    ret *= fac_inv[z-x]; ret %= M;
    ret *= fac_inv[z-y]; ret %= M;
    ret *= fac_inv[x+y-z]; ret %= M;
    return ret;
}

ll ans[202][202];
int siz[202];
vector<int> ch[202];
void dfs(int v){
    for(int i = 0 ; i < ch[v].size() ; i ++){
        dfs(ch[v][i]);
        siz[v] += siz[ch[v][i]];
        for(int j = siz[v] ; j >= 0 ; j --){
            ll sum = 0;
            for(int k = 0 ; k <= j ; k ++)for(int l = 0 ; l <= j ; l ++){
                sum += (ans[v][k]*ans[ch[v][i]][l])%M*f(k,l,j);
                sum %= M;
            }
            ans[v][j] = sum;
        }
    }
    for(int i = 201 ; i > 0 ; i --){
        ans[v][i] = ans[v][i-1];
    }
    ans[v][0] = 0;
    siz[v] ++;
}

int main(){
    fac_init();
    int n;
    int a[202],b[202];
    
    scanf("%d",&n);
    for(int i = 0 ; i < n-1 ;  i ++){
        scanf("%d%d",&a[i],&b[i]);
        ch[a[i]].push_back(b[i]);
    }
    for(int i = 0 ; i < 202 ; i ++){
        for(int j = 0 ; j < 202 ; j ++){
            ans[i][j] = 0;
        }
        ans[i][0] = 1;
        siz[i] = 0;
    }
    
    int cnt[202] = {};
    for(int i = 0 ; i < n-1; i ++){
        cnt[b[i]] ++;
    }
    for(int i = 0 ; i < n ; i ++){
        if(cnt[i] == 0){
            dfs(i);
            ll ret = 0;
            for(int j = 0 ; j <= n ; j ++){
                ret += ans[i][j];
            }
            cout << ret%M << endl;
        }
    }
}

Measured memory_bytes: 3528
import java.util.Scanner;

public class Main {
	private Scanner sc;
	
	public static void main(String[] args) {
		new Main();
	}
	
	public Main() {
		sc = new Scanner(System.in);
		
		int index = 0;
		while (sc.hasNextLine() == true) {
			String line = sc.nextLine();

			boolean flag = true;
			for (int i = 0; i < (line.length() / 2); i++) {
				if (line.charAt(i) != line.charAt(line.length() - i - 1)) {
					flag = false;
					break;
				}
			}
			
			if (flag == true) index++;
		}
		
		System.out.println(index);
	}
}

Measured memory_bytes: 26120
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define re return 0

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

template<typename T>
void maxi(T &a, T &b) {
	a = max(a, b);
}

template<typename T>
void mini(T &a, T &b) {
	a = min(a, b);
}

int main() {
	makei(N);
	int i = 0;
	while (pow(2, ++i) <= N);
	say((int)pow(2,i - 1));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (ll i = init; i < (n); i++)
#define repd(i, n, init) for (ll i = (n); i >= init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)

int main()
{
    ll A, B, C;
    cin >> A >> B >> C;
    if (A % 2 == 0 || B % 2 == 0 || C % 2 == 0)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << min(min(A * B, B * C), min(B * C, C * A)) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <complex>
using namespace std;
const double PI = 3.141592653589793238462643383279502884L;

int main(int argc, char **argv)
{
  int degree = 90;
  int d, t;
  char c;
  complex<double> v(0, 0);

  while (cin >> d >> c >> t) {
    if (!d && !t)
      break;

    auto next = polar((double)d, degree*PI/180.0);
    v += next;
    degree = (degree - t) % 360;
  }
  printf("%d\n%d\n", (int)v.real(), (int)v.imag());
  return 0;
}

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

//define ll long long;
//define ar array;

int row_cnt[6];
int col_cnt[6];
int arr[6][6];

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

    int h, w, k;
    cin >> h >> w >> k;
    int total = 0;
    for (int i = 0; i < h; i++){
        string k;
        cin >> k;
        for (int j = 0; j < w; j++){
            arr[i][j] = k[j];
            if (arr[i][j] == '#') {
                total++;
                row_cnt[i]++;
                col_cnt[j]++;
            }
        }
    }

    long long ans = 0;
    long long cur =0;
    for (int b = 0; b < (1<<h); b++){
        long long row_sum = 0;
        vector<int> rows;
        for (int i = 0; i < h; i++){
            if (b&(1<<i)) {
                row_sum+=row_cnt[i];
                rows.push_back(i);
            }
        }
        for (int c = 0; c < (1<<w); c++){
            vector<int> cols;
            long long col_sum = 0;
            for (int i = 0; i < w; i++){
                if (c&(1<<i)){
                    col_sum+=col_cnt[i];
                    cols.push_back(i);
                }
            }

            cur = row_sum + col_sum;
            for (auto x: rows){
                for (auto y: cols){
                    if (arr[x][y] == '#'){
                        cur--;
                    }
                }
            }

            if (cur == (total - k)){

                ans++;
            }
        }
    }
    cout << ans << endl;



    return 0;
}



Measured memory_bytes: 3640
#include <iostream>
#include <iomanip>
#include <bits/stdc++.h>
#include <vector>
#include <iterator>
#include <string>
#define pan(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define vi vector<int>
#define pb push_back
#define INF 1e9+7
#define PI 3.141592653
using namespace std;
 


int main() 
{ 
    int n;
    cin>>n;
    unordered_map<string,int> umap;
    ll ans=0;
    string s;
    pan(i,n){
        cin>>s;
        sort(s.begin(),s.end());
        umap[s]++;
    }
    for(auto x=umap.begin();x!=umap.end();x++){
        ll k=x->second;
        ans+=((k)*(k-1))/2;
    }
    cout<<ans;
} 


Measured memory_bytes: 10660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll mo = 1000000007;
ll mypow(ll a, ll b)
{
  ll res = 1;
  a %= mo;
  while (b)
  {
    if (b & 1)
      res = res * a % mo;
    a = a * a % mo;
    b >>= 1;
  }
  return res;
}
const ll MAX = 510000;
const ll MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit()
{
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (ll i = 2; i < MAX; i++)
  {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long COM(ll n, ll k)
{
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
vector<ll> factorial(ll n)
{
  vector<ll> fac;
  fac.push_back(1);
  for (ll i = 1; i < n + 10; i++)
  {
    fac.push_back((fac[i - 1] * i) % mo);
  }
  return fac;
}
int main()
{
/* 
https://onlinejudge.u-aizu.ac.jp/courses/library/7/DPL/5
ボール      箱	      入れ方に制限なし 箱の中身は1つ以下 箱の中身は1つ以上
区別できる   区別できる  1            2             3
区別できない  区別できる  4            5             6
区別できる   区別できない 7            8             9
区別できない  区別できない 10          11            12
*/
ll n , k ;
cin >> n >> k ;
auto mod = [](ll modx) {modx%=mo;modx+=mo;modx%=mo;return modx; };
COMinit();
vector<ll> fac = factorial(100000);
/* 
//1
cout << mypow(k,n) << endl;
 */
/* 
//2
cout << (COM(k,n)*fac[n])%mo << endl;
 */
/* 
//3
ll t=0;
rep(i,k+1){
  t=mod(t+mypow(-1,k-i)*COM(k,i)*mypow(i,n));
}
cout << t << endl;
 */

//4
cout << COM(n+k-1,n) << endl;
return 0;
}


Measured memory_bytes: 15872
# coding:utf-8
while True:
    line = raw_input().split()
    a = int(line[0])
    op = line[1]
    b = int(line[2])
    answer = 0
    if op == '+':
        answer = a + b
    elif op == '-':
        answer = a - b
    elif op == '*':
        answer = a * b
    elif op == '/':
        answer = a / b
    elif op == '?':
        break
    print "%d" % answer

Measured memory_bytes: 4652
#include <iostream>
using namespace std;
int main(void)
{
	int a,b,c,d,e,f,g,h,i,j,k;
	for (a=0;a<3;a++)
	{
		k=0;
		cin>>b>>c>>d>>e>>f>>g;
		h=e-b;
		j=g-d;
		if (j<0)
		{
			j=60+j;
			k=8;
		}
		i=f-c;	
		if (k==8)
		{
			i=i-1;
		}
		if (i<0)
		{
			i=60+i;
			h=h-1;
		}
		cout<<h<<" "<<i<<" "<<j<<endl;
	}
	return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<lint, lint> pi;

int n, m, a[5005], b[5005][205];
lint ans[5005][5005];
int pref[5005][205], suff[5005][205];

void solve(int s, int e){
	if(s == e){
		return;
	}
	int mid = (s+e)/2;
	solve(s, mid);
	solve(mid+1, e);
	for(int i=1; i<=m; i++){
		pref[mid][i] = b[mid][i];
		suff[mid+1][i] = b[mid+1][i];
	}
	for(int i=mid-1; i>=s; i--){
		for(int j=1; j<=m; j++){
			pref[i][j] = max(b[i][j], pref[i+1][j]);
		}
	}
	for(int i=mid+2; i<=e; i++){
		for(int j=1; j<=m; j++){
			suff[i][j] = max(b[i][j], suff[i-1][j]);
		}
	}
	for(int j=1; j<=m; j++){
		int p = e;
		for(int i=s; i<=mid; i++){
			while(p > mid && suff[p][j] >= pref[i][j]) p--;
			ans[i][mid + 1] += pref[i][j];
			ans[i][p + 1] -= pref[i][j];
		}
	}
}

void solve2(int s, int e){
	if(s == e){
		return;
	}
	int mid = (s+e)/2;
	solve2(s, mid);
	solve2(mid+1, e);
	for(int i=1; i<=m; i++){
		pref[mid][i] = b[mid][i];
		suff[mid+1][i] = b[mid+1][i];
	}
	for(int i=mid-1; i>=s; i--){
		for(int j=1; j<=m; j++){
			pref[i][j] = max(b[i][j], pref[i+1][j]);
		}
	}
	for(int i=mid+2; i<=e; i++){
		for(int j=1; j<=m; j++){
			suff[i][j] = max(b[i][j], suff[i-1][j]);
		}
	}
	for(int j=1; j<=m; j++){
		int p = s;
		for(int i=e; i>mid; i--){
			while(p <= mid && pref[p][j] > suff[i][j]) p++;
			ans[p][i] += suff[i][j];
			ans[mid+1][i] -= suff[i][j];
		}
	}
}

int main(){
	cin >> n >> m;
	for(int i=1; i<n; i++) scanf("%d",&a[i]);
	for(int i=1; i<=n; i++){
		for(int j=1; j<=m; j++){
			scanf("%d",&b[i][j]);
		}
	}
	solve(1, n);
	for(int i=1; i<=n; i++){
		for(int j=1; j<=n; j++) ans[i][j] += ans[i][j-1];
	}
	for(int i=1; i<=n; i++){
		for(int j=n; j; j--) ans[j][i] -= ans[j-1][i];
	}
	solve2(1, n);
	for(int i=1; i<=n; i++){
		for(int j=1; j<=n; j++) ans[j][i] += ans[j-1][i];
	}
	for(int i=1; i<=n; i++){
		for(int j=1; j<=m; j++) ans[i][i] += b[i][j];
	}
	lint ret = 0;
	for(int i=1; i<=n; i++){
		lint dist = 0;
		for(int j=i; j<=n; j++){
			ret = max(ret, -dist + ans[i][j]);
			dist += a[j];
		}
	}
	cout << ret;
}


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

long N, A[200000], B[200000];
long AA[200000], BB[200000];

int check(int k){
	long T = pow(2,k);
	for(long i=0;i<N;i++){
		AA[i] = A[i] % (2 * T);
		BB[i] = B[i] % (2 * T);
	}
	sort(BB, BB+N);
	/*
	for(int i=0;i<N;i++) printf("%d", AA[i]);
	printf("\n");
	for(int i=0;i<N;i++) printf("%d", BB[i]);
	printf("\n");
	*/
	long count = 0;
	for(long i=0;i<N;i++){
		long a = AA[i];
		//printf("%d\n",a);
		long* l1 = lower_bound(BB, BB+N, T - a);
		long* r1 = upper_bound(BB, BB+N, 2 * T - a - 1);
		long* l2 = lower_bound(BB, BB+N, 3 * T - a);
		long r2 = N;
		//printf("%d %d %d %d\n", (int)(l1-BB),(int)(r1-BB),(int)(l2-BB),r2);
		count += (long)(r1-BB) - (long)(l1-BB) + r2 - (long)(l2-BB);
	}
	if(count % 2 == 1) return 1;
	else return 0;
}

int main() {
	cin >> N;
	for(long i=0;i<N;i++) cin >> A[i];
	for(long i=0;i<N;i++) cin >> B[i];
	
	long ans = 0;
	for(int k=0;k<29;k++) if(check(k)) ans += 1 << k;
	cout << ans << endl;
	return 0;
}

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

int main() {
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);

	string a, b;
	cin >> a >> b;
	int cnt = 0;
	for (int i = 0; i < a.length(); ++i) {
		if (a[i] != b[i]) {
			cnt++;
		}
	}
	cout << cnt << endl;

}

Measured memory_bytes: 3796
import sys 
import math
# try:
# 	sys.stdin = open('input.txt', 'r') 
# 	sys.stdout = open('output.txt', 'w')
# except:
# 	pass
input = sys.stdin.readline
for tt in range(1):
	r = int(input())
	# a,b = map(int,input().split())
	# l = list(map(int,input().split()))
	print(2*math.pi*r)
	

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

const int Max = 100005;
vector<vector<int>>adj(Max);
int indegree[Max];
int dist[Max];
bool visited[Max];

void makeEdge(int u, int v){
	adj[u].push_back(v);
	indegree[v] += 1;
}

void dfs(int source){
	assert(!visited[source]);
	visited[source] = true;
	for(auto u: adj[source]){
	  dist[u] = max(dist[u], dist[source]+1);
	  indegree[u] -= 1;
	  if(indegree[u] ==0){
	    dfs(u);
	  }
	}
}

int main(){
  int n, m, u, v;
  cin >> n >> m;
  for(int i=0; i<m; i++){
    cin >> u >> v;
    makeEdge(u, v);
  }
  for(int i=1; i<=n; i++){
    if(!visited[i] && indegree[i] == 0){
      dfs(i);
    }
  }
  int ans = 0;
  for(int i=1; i<=n; i++){
    ans = max(ans, dist[i]);
  }
  cout << ans;
  return 0;
}


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

int main() {
    int n, d, x;
    cin >> n >> d >> x;

    vector<vector<int> > p(d, vector<int>(n));
    for (auto& i : p) for (auto& j : i) cin >> j;

    vector<int> dp(100001);
    dp[x] = 1;
    for (int i = 0; i < d-1; i++) {
        vector<int> s(100001);
        for (int j = 0; j < n; j++) {
            int sub = p[i+1][j] - p[i][j];
            if (sub <= 0) continue;
            for (int k = 0; k < 100001; k++) {
                if (k - p[i][j] >= 0) s[k] = max(s[k], s[k - p[i][j]] + sub);
            }
        }

        for (int j = 100000; j >= 0; j--)
            if (j + s[j] < 100001) dp[j + s[j]] |= dp[j];
    }

    int ans = 0;
    for (int i = 0; i < 100001; i++)
        ans = max(ans, dp[i] * i);

    cout << ans << endl;

    return 0;
}

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

int main(void){
    long long int H,W;
    long long int ans = 0;
    cin >> H >> W;
    if(H==1 || W==1){
        printf("1");
        return 0;
    }
    if(H%2!=0 && W%2!=0){
        ans = H*W/2 +1;
        printf("%lld",ans);
    }else{
        ans = H*W/2;
        printf("%lld",ans);
    }
    return 0;
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
	let mut s = String::new();
	std::io::stdin().read_line(&mut s).ok();
	s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
	read::<String>().split_whitespace()
		.map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
	(0..n).map(|_| read_vec()).collect()
}

pub trait LexicalPermutation {
	/// Return `true` if the slice was permuted, `false` if it is already
	/// at the last ordered permutation.
	fn next_permutation(&mut self) -> bool;
}
impl<T> LexicalPermutation for [T] where T: Ord {
	/// Original author in Rust: Thomas Backman <serenity@exscape.org>
	fn next_permutation(&mut self) -> bool {
		// These cases only have 1 permutation each, so we can't do anything.
		if self.len() < 2 { return false; }

		// Step 1: Identify the longest, rightmost weakly decreasing part of the vector
		let mut i = self.len() - 1;
		while i > 0 && self[i-1] >= self[i] {
			i -= 1;
		}

		// If that is the entire vector, this is the last-ordered permutation.
		if i == 0 {
			return false;
		}

		// Step 2: Find the rightmost element larger than the pivot (i-1)
		let mut j = self.len() - 1;
		while j >= i && self[j] <= self[i-1]  {
			j -= 1;
		}

		// Step 3: Swap that element with the pivot
		self.swap(j, i-1);

		// Step 4: Reverse the (previously) weakly decreasing part
		self[i..].reverse();

		true
	}
}

fn main() {
	let (n, a, b) = {
		let tmp: Vec<u64> = read_vec();
		(tmp[0], tmp[1], tmp[2])
	};

	let loop_num = (n / (a+b)) + 1;
	let mut count = (loop_num-1) * a;
	let tmp = (n - (loop_num-1) * (a + b));
	if tmp >= a {
		count += a;
	} else {
		count += tmp;
	}
	println!("{}", count);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007*1ll
using namespace std;
int ar[200002] ;
vector<int>ps,ne,tup ;
bool cmp(int a , int b) {return a>b ; }
int32_t main()
{
    int n,k ; cin>>n>>k ;
    int an=1 ;
    for(int i = 0 ; i < n ; i++) {cin>>ar[i] ; if(ar[i]>=0) an=0 ;}
    if(k==n)
    {
        int ans=1 ;
        for(int i = 0 ; i < n ; i++)
        {
            int x=ar[i] ;
            x=(x+mod)%mod ;
            ans=(ans*x)%mod ;
        }
        cout<<ans<<endl ;
    }
    else
    {
        if(an)
        {
           // cout<<"jkl "<<k<<endl ;
            if(k&1ll) sort(ar,ar+n,cmp) ;
            else sort(ar,ar+n) ;
            int ans=1 ;
            for(int i = 0 ; i < k ; i++)
            {
                int x=ar[i] ;
                x=(x+mod)%mod ;
                ans=(ans*x)%mod ;
            }
            cout<<ans<<endl ;
        }
        else
        {
           // cout<<"oo"<<endl ;
            int ans=1 ;
            for(int i = 0 ; i < n ; i++)
            {
                if(ar[i]>=0) ps.push_back(ar[i]) ;
                else ne.push_back(ar[i]) ;
            }
            sort(ps.begin(),ps.end()) ;
            sort(ne.rbegin(),ne.rend()) ;
          //  for(int i = 0 ; i < ps.size() ; i++) cout<<ps[i]<<" " ; cout<<endl ;
          //  for(int i = 0 ; i < ne.size() ; i++) cout<<ne[i]<<" " ; cout<<endl ;
            if(k&1)
            {
                int x=ps.back() ; ps.pop_back() ;
                ans=(ans*x*1ll)%mod ;
            }
            while((int)ps.size()>1)
            {
                int x=ps.back() ; ps.pop_back() ;
                int y=ps.back() ; ps.pop_back() ;
                int h=(x*y) ;
                tup.push_back(h) ;
            }
            while((int)ne.size()>1)
            {
                int x=ne.back() ; ne.pop_back() ;
                int y=ne.back() ; ne.pop_back() ;
                int h=(x*y) ;
                tup.push_back(h) ;
            }
            sort(tup.rbegin(),tup.rend()) ;
            //for(int i = 0 ; i < (int)tup.size() ; i++) cout<<tup[i]<<" " ; cout<<endl ;
            for(int i = 0 ; i < k/2 ; i++)
            {
                ans%=mod ; tup[i]%=mod ;
                ans=(ans*tup[i])%mod ;
            }
            cout<<ans%mod<<endl ;

        }
    }

}
// -1000000000 -1 -1000000000 -1000000000 -1000000000


Measured memory_bytes: 8064
N = int(input())
st, sx, sy = 0, 0, 0
for _ in range(N):
    t, x, y = map(int, input().split())
    distance = abs(x - sx) + abs(y - sy)
    dt = t - st
    if dt < distance or (dt - distance) % 2 == 1:
        print('No')
        break
else:
    print('Yes')

Measured memory_bytes: 3060
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;

int h;
int w;
char f[2005][2005];
int d[2005][2005];
int u[2005][2005];
int r[2005][2005];
int l[2005][2005];

int main()
{
    cin >> h >> w;
    for (int i = 0;i < h;i++){
        for (int j = 0;j < w;j++){
            cin >> f[i][j];
        }
    }
    
    for (int i = 0;i < w;i++){
        if (f[h-1][i] == '.'){
            d[h-1][i] = 1;
        }
        else {
            d[h-1][i] = 0;
        }
        
        if (f[0][i] == '.'){
            u[0][i] = 1;
        }
        else {
            u[0][i] = 0;
        }
    }
    
    for (int j = 0;j < h;j++){
        if (f[j][0] == '.'){
            l[j][0] = 1;
        }
        else {
            l[j][0] = 0;
        }
        
        if (f[j][w-1] == '.'){
            r[j][w-1] = 1;
        }
        else {
            r[j][w-1] = 0;
        }
    }
    
    for (int i = 0;i < h;i++){
        for (int j = 0;j < w;j++){
            if (f[i][j] == '.' && j >= 1){
                l[i][j] = l[i][j-1] + 1;
            }
            
            if (f[i][w-j-1] == '.' && j >= 1){
                r[i][w-j-1] = r[i][w-j] + 1;
            }
            
            if (f[i][j] == '#'){
                l[i][j] = 0;
                u[i][j] = 0;
                r[i][j] = 0;
                d[i][j] = 0;
            }
            
            if (f[i][j] == '.' && i >= 1){
                u[i][j] = u[i-1][j] + 1;
            }
            
            if (f[h-i-1][j] == '.' && i >= 1){
                d[h-i-1][j] = d[h-i][j] + 1;            }
        }
    }
    
    int ans = 0;
    for (int i = 0;i < h;i++){
        for (int j = 0;j < w;j++){
            ans = max(l[i][j] + r[i][j] + d[i][j] + u[i][j]-3,ans);
        }
    }
    
    cout << ans << endl;
}


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

using namespace std;
#define PROBLEM "B"

bool check[1000010];

int odd(int n){

	return 3*n + 1;
}

int even(int n){

	return n/2;
}


int main(){

	#ifdef DBG
	freopen("problem" PROBLEM ".in", "r", stdin);
	freopen("problem" PROBLEM ".out", "w", stdout);
	#endif

	memset(check, 0, sizeof(check));
	int n;
	int count = 0;
	while(cin >> n){

		while(!check[n]){

			check[n] = true;
			if(n % 2 == 0)
				n = even(n);
			else
				n = odd(n);
			count++;
		}
		cout << count+1 << endl;
	}

	return 0;
}

Measured memory_bytes: 1280
#include <stdio.h>
void print_32bits(unsigned x) //32ビットで表示する
{
    for (int i = 31; i >= 0; i--)
    {
        unsigned s = (x >> i);
        if (s & 1U)
        {
            putchar('1');
        }
        else
        {
            putchar('0');
        }
    }
    printf("\n");
}
int main(void)
{
    unsigned x;
    scanf("%u", &x);

    print_32bits(x);
    print_32bits(~x);
    print_32bits(x << 1);
    print_32bits(x >> 1);

    return 0;
}


Measured memory_bytes: 2620
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
#define Reve(a) reverse(a.begin(), a.end())
#define PI 3.14159265359
typedef long long ll;
const ll MOD = 1e9+7;

/*ll gcd(ll a, ll b){
  if(b==0) return a;
  return gcd(b, a%b);
}*/
/*ll myPow(ll x, ll n, ll m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}*/

/*ll lcm(ll a, ll b){
  ll g = gcd(a, b);
  b /= g;
  a *= b;
  return a;
}*/
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

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

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

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

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

int main(){
  double n, k; cin >> n >> k; 
  int n1 = n, k1=k, i;
  double ans = 0.000000000;
  for(i=1; i<=n; i++){
    int i1 = i; double f=1, g = 0.50000000; 
    while(i1<k){
      i1*=2;
      f *= g;
    }
  //printf("%.8lf\n", ans);

    ans += f;
    //ans+=myPow(f, sum, MOD);
    //sum=0;
  }
  n = 1/n;
  //printf("%.8lf\n", n);

  printf("%.10lf\n", ans*n);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
#include <set>
#include <cmath>
using namespace std;
#define MOD 1000000007

long long dp[1001][1001];

// 繰り返し二乗法
long long bipow(long long n, int m) {
    if (m == 0) return 1;
    if (m % 2 == 0) {
        n = (n * n) % MOD;
        return bipow(n, m / 2) % MOD;
    } else
        return (n * bipow(n, m - 1)) % MOD;
}

// fact_num[i] = i! % MOD
// fact_denpow[i] = (i**(MOD-2)) % MOD
// fact_den[i] = fact_denpow[i]! % MOD
// nCm = fact_num[n] * fact_den[m] * fact_den[n-m]
// で計算できる（MODを適切に取る）
// O(NlogN)
void set_table(int N, vector<long long> &fact_num, vector<long long> &fact_den){
    fact_num.resize(N+1, 0);
    fact_den.resize(N+1, 0);
    vector<long long> fact_denpow(N+1, 0);

    fact_num[0] = 1;
    for(int i=1; i<=N; i++) fact_num[i] = (fact_num[i-1] * i) % MOD;

    for(int i=0; i<=N; i++) fact_denpow[i] = bipow(i, MOD-2);
    fact_den[0] = 1;
    for(int i=1; i<=N; i++) fact_den[i] = (fact_den[i-1] * fact_denpow[i]) % MOD;
}

// mCn
long long comb(const vector<long long> &fact_num, const vector<long long> &fact_den, int m, int n){
    return ((fact_num[m] * fact_den[n]) % MOD * fact_den[m-n]) % MOD;
}

int main(){
    long long N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;

    vector<long long> fact_num, fact_den;
    set_table(N, fact_num, fact_den);

    dp[A-1][N] = 1;
    for(int i=A; i<=B; i++){
        for(int j=0; j<=N; j++)
            dp[i][j] = dp[i-1][j];

        for(int j=1; j<=N; j++){
            if(j - C*i < 0) continue;
            long long c = 1;
            long long cur = j;
            for(int k=1; k<C; k++){
                c = (c * comb(fact_num, fact_den, cur, i)) % MOD;
                cur -= i;
            }
            for(int k=C; k<=D; k++){
                c = (c * comb(fact_num, fact_den, cur, i)) % MOD;
                cur -= i;
                if(cur < 0) break;
                dp[i][cur] += (dp[i-1][j] * ((c * fact_den[k]) % MOD)) % MOD;
                dp[i][cur] %= MOD;
            }
        }
    }
    cout << dp[B][0] << endl;

    return 0;
}


Measured memory_bytes: 8064
#include<iostream>
#include<algorithm>
#include<vector>
#include<unordered_set>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define mod 1000000007
ll f(ll n){
  ll res=1;
  for(ll i=1;i<=n;i++)res=res*i%mod;
  return res;
}
int main(){
    ll n,m;cin>>n>>m;
    if(n>m)swap(n,m);
    if(m-n>1){
      cout<<0<<endl;
    }
    if(m-n==1){
      cout<<f(n)*f(m)%mod<<endl;
    }
    if(m-n==0){
      cout<<f(n)*f(m)*2%mod<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define dump(a) cout << (a) << '\n';
typedef int64_t Int;
Int mod = 1e9+7;
Int INF = 1e17;
// Int MOD = 998244353;

string cmp(string s, string t) {
    if (s.size() != t.size()) return s.size() > t.size() ? s : t;
    return s > t ? s : t;
}

int main() {
    ios::sync_with_stdio(false);
    Int n, m;
    cin >> n >> m;
    bool a[10] = {};
    Int cost[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    for (Int i = 0; i < m; i++) {
        Int x;
        cin >> x;
        a[x] = true;
    }
    string dp[10010] = {};
    for (Int i = 1; i < 10; i++) {
        string s = "";
        if (a[i]) s = s + (char)('0' + i);
        dp[cost[i]] = cmp(dp[cost[i]], s);
    }
   //  for (Int i = 1; i < 10; i++) dump(dp[i]);
    for (Int i = 2; i < n; i++) {
        if (dp[i] == "") continue;
        for (Int j = 1; j < 10; j++) {
            if (!a[j]) continue;
            string s = dp[i] + (char)('0' + j);
            string t = (char)('0' + j) + dp[i];
            dp[i + cost[j]] = cmp(dp[i + cost[j]], cmp(s, t));
        }
    }
    dump(dp[n]);
    return 0;  
} 

Measured memory_bytes: 39296
H, W, K = map(int, input().split())
X = [[1 if a == "#" else 0 for a in input()] for _ in range(H)]
ans = 0
for ii in range(1 << H):
    for jj in range(1 << W):
        if sum([sum([X[i][j] for j in range(W) if jj >> j & 1]) for i in range(H) if ii >> i & 1]) == K:
            ans += 1
print(ans)

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

bool has3(int x){
    while(x){
        if(x % 10 == 3) return 1;
        x /= 10;
    }
    return 0;
}

void call(int n){
    for(int i = 1; i <= n; i++){
        if(i % 3 == 0 || has3(i)) cout << " " << i;
    }
}

int main(){
    int n;
    cin >> n;
    call(n);
    cout << endl;
    return 0;
}


Measured memory_bytes: 3084
#include <array>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

void BreakDown(int n, int cnt[])
{
    while (n > 1)
    {
        bool devide = false;
        for (int i = 2; i <= n; ++i)
        {
            if (n % i == 0)
            {
                n /= i;
                ++cnt[i];
                devide = true;
                break;
            }
        }

        if (!devide)
        {
            ++cnt[n];
            break;
        }
    }
}

int main()
{
    int N;
    cin >> N;
    int cnt[1005];
    REP(i, 1005) cnt[i] = 0;
    REP(i, N)
    {
        int n = i + 1;
        BreakDown(n, cnt);
    }
    LL ans = 1;
    REP(i, N)
    {
        if (cnt[i + 1] > 0)
        {
            ans *= (cnt[i + 1] + 1);
            ans %= 1000000007;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
dishes = []
for i in range(5):
    dishes.append(int(input()))
last = 10
last_index = 5
for i in range(5):
    if dishes[i] % 10 != 0 and last > dishes[i]%10:
        last = dishes[i]%10
        last_index = i

ans = 0
for i in range(5):
    if i != last_index:
        if dishes[i] % 10 != 0:
            ans += dishes[i] + 10 - dishes[i] % 10
        else:
            ans += dishes[i]
    else:
        ans += dishes[i]
print(ans)
        

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

inline double Plus(double x)
{
  double a=0;
  for(int i=1; i<=x; i++)
    a += i;
  
  return a;
}

int main()
{
  long n,k;
  double p, ans=0.0, max=0.0;
  cin >> n >> k;
  vector<double> P;
  for(int i=0; i<n; i++)
  {
    cin >> p;
    P.push_back(Plus(p)/p);
    ans += Plus(p)/p;
    if(i >= k-1)
    {
      if(max < ans)
        max = ans;
      
      ans -= P.at(i-k+1);
    }
  }
  printf("%.12lf",max);
  return 0;
}

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

const int M = 1e6 + 10;
const int N = 2e5 + 10;

int n;
char ch[M];

pair<int, int> a[N];
int g[M][26];

bool cmp(pair<int, int> a, pair<int, int> b) {
	return a.first < b.first;
}

int tr[M][26], rt = 1, num[M], cnt = 1;

void Ins(int st, int len) {
	int now = rt;
	for (int i = 0; i < len; i++) {
		int j = ch[st + i] - 'a';
		if (!tr[now][j]) tr[now][j] = ++cnt;
		now = tr[now][j];
	}
	num[now]++;
}

int main() {
	cin >> n;
	int hav = 0;
	for (int i = 1; i <= n; i++) {
		scanf("%s", ch + hav);
		int len = strlen(ch + hav);
		reverse(ch + hav, ch + hav + len);
		a[i].first = len;
		a[i].second = hav;
		hav += len;
	}
	sort(a + 1, a + n + 1, cmp);
	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		int st = a[i].second, len = a[i].first;
		for (int j = 0; j < 26; j++) g[len][j] = 0;
		for (int j = len - 1; j >= 0; j--) {
			for (int k = 0; k < 26; k++) g[j][k] = g[j + 1][k];
			g[j][ch[st + j] - 'a'] = 1;
		}
		int now = rt;
		for (int j = 0; j < len; j++) {
			for (int k = 0; k < 26; k++) {
				if (!g[j][k] || !tr[now][k]) continue;
				ans += num[tr[now][k]];
			}
			now = tr[now][ch[st + j] - 'a'];
			if (!now) break;
		}
		Ins(st, len);
	}
	cout << ans << endl;
}

Measured memory_bytes: 203816
chars=list(input())
d_unique=list(set(chars))

if len(d_unique)==26:
    print("None")
elif "a" not in d_unique:
    print("a")
elif "b" not in d_unique:
    print("b")
elif "c" not in d_unique:
    print("c")
elif "d" not in d_unique:
    print("d")
elif "e" not in d_unique:
    print("e")
elif "f" not in d_unique:
    print("f")
elif "g" not in d_unique:
    print("g")
elif "h" not in d_unique:
    print("h")
elif "i" not in d_unique:
    print("i")
elif "j" not in d_unique:
    print("j")
elif "k" not in d_unique:
    print("k")
elif "l" not in d_unique:
    print("l")
elif "m" not in d_unique:
    print("m")
elif "n" not in d_unique:
    print("n")
elif "o" not in d_unique:
    print("o")
elif "p" not in d_unique:
    print("p")
elif "q" not in d_unique:
    print("q")
elif "r" not in d_unique:
    print("r")
elif "s" not in d_unique:
    print("s")
elif "t" not in d_unique:
    print("t")
elif "u" not in d_unique:
    print("u")
elif "v" not in d_unique:
    print("v")
elif "w" not in d_unique:
    print("w")
elif "x" not in d_unique:
    print("x")
elif "y" not in d_unique:
    print("y")
elif "z" not in d_unique:
    print("z")

Measured memory_bytes: 4084
#include <iostream>
#include <math.h>
#include <string>
#include <string.h> 
#include <stdio.h>
#include <cstdlib>
using namespace std;
#define MAX 200000
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define IN(n) scanf("%d",&n,);
#define OUT(n) printf("%d",n);
#define IN2(n,k) scanf("%d%d",&n,&k);
#define OUT2(n,k) printf("%d%d",n,k);
#define IN3(n,k,s) scanf("%d%d%d",&n,&k,&s);
#define OUT3(n,k,s) printf("%d%d%d\n",n,k,s);

int main(){
    string a;
    int b[100],i=0;
    while(cin>>a){
        if(a[0]=='+'){
            i--;
            b[i-1]=b[i-1]+b[i];            
        }
        else if(a[0]=='-'){
            i--;
            b[i-1]=b[i-1]-b[i];            
        }
        else if(a[0]=='*'){
            i--;
            b[i-1]=b[i-1]*b[i];
        }
        else {
            b[i++]=atoi(a.c_str());
        }

    }
    cout<<b[0]<<endl;
    return 0;
}

Measured memory_bytes: 3192
import qualified Data.ByteString.Char8 as BS
import Data.Maybe (fromJust)
import Data.List
import Data.Array.IArray

lowerBound:: (Integral i, Ix i, Ord e, IArray a e) => e -> a i e -> i
lowerBound x a =
    let (b,e) = bounds a in bsearch b (e + 1)
  where
    bsearch b e
      | e == b    = b
      | x <= a!p  = bsearch b p
      | otherwise = bsearch (p + 1) e
      where p = (b + e) `div` 2

main :: IO ()
main = do
    _ <- getLine
    l <- map (fst . fromJust . BS.readInt)
        . BS.words <$> BS.getLine :: IO [Int]
    let sl = listArray (0,length l - 1) $ sort l :: Array Int Int
    print $ sum
        [ let c = lowerBound ((sl!a)+(sl!b)) sl
           in c - (b+1)
          | a <- [0..length sl - 1], b <- [(a+1)..length sl - 1]
        ]


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


ll dp[110][5][2];

int main(){
    string s;
    int k;
    cin >> s >> k;
    int n = s.size();
    dp[0][0][0] = 1;
    rep(i,n){
        int si = s[i] -'0';
        if(si==0){
            rep(j,4){
                dp[i+1][j][0] += dp[i][j][0];
                dp[i+1][j+1][1] += dp[i][j][1] * 9;
                dp[i+1][j][1] += dp[i][j][1];
            }
            continue;
        }
        else{
            rep(j,4){
                dp[i+1][j][1] += dp[i][j][0] + dp[i][j][1];
                dp[i+1][j+1][1] += dp[i][j][1] * 9 + dp[i][j][0] *(si-1);
                dp[i+1][j+1][0] += dp[i][j][0];
            }
        }
    }
    ll ans = dp[n][k][1] + dp[n][k][0];
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main() {
  string S;
  cin >> S;
  int L = S.length();

  int64_t result = 0;
  int n = 0;
  for (int src = L - 1; src >= 0; src--) {
    if (S[src] == 'B') {
      int dst = L - 1 - n;
      result += dst - src;
      n++;
    }
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll =long long ;
int main() {
  ll a;
  cin>>a;
  ll b=0;
  ll c=0;
  vector<ll>vec(a);
  for(ll i=0;i<a;i++){
    cin>>vec.at(i);
    vec.at(i)=vec.at(i)%1000000007;
    b+=vec.at(i);
  }
  b=b%1000000007+1000000007;
  vector<ll>vo(a);
  for(ll i=0;i<a;i++){
    vo.at(i)=(b-vec.at(i))%1000000007;
    b=vo.at(i)+1000000007;
  }
  for(ll i=0;i<a;i++){
    c+=vo.at(i)*vec.at(i)%1000000007;
    c=c%1000000007;
  }
  cout<<c<<endl;   
}


Measured memory_bytes: 6404
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define CHAL_BC_APNE_BAAP_KO_MAT_SIKHA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define fr first
#define se second
#define mod 1000000007
int vis[200005];
vector<int> v[200005];
int k;
int n;
int c=1;
int bfs(int node){
	queue<pair<int,int> > q;
	q.push({node,1});
	vis[node]=1;
	int ans=c;
	ans=(ans*k)%mod;
	int level=1;
	while(!q.empty()){
		int node=q.front().fr;
		int minus=q.front().se;
		q.pop();
		int cnt=0;
		//cout<<ans<<endl;
		for(int i=0;i<v[node].size();i++){
			if(!vis[v[node][i]]){
				q.push({v[node][i],minus+1});
				vis[v[node][i]]=1;
				ans=(ans*(max(k-2,k-minus)-cnt))%mod;
				cnt++;
			}
		}
	}
	return ans;
}
signed main()
{
	CHAL_BC_APNE_BAAP_KO_MAT_SIKHA;		
	//int n,k;
	cin>>n>>k;
	for(int i=1;i<n;i++){
		int a,b;
		cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
	}
	cout<<bfs(1);
}


Measured memory_bytes: 11892
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "{ ";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "}";

    return os;
}

ll pow_mod(ll a, ll p) {
    ll res = 1;
    while(p) {
        if (p & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        p >>= 1;
    }

    return res;
}


ll mod_inv(ll a, ll m) {
    ll b = m, u = 0, v = 1;
    while(a) {
        ll t = b / a;
        swap(b -= t * a, a);
        swap(u -= t * v, v);
    }

    return (u % m + m) % m;
}

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

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#ifdef LOCAL
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int N, M;
    cin >> N >> M;

    map<ll, ll, greater<ll>> cnt;

    REP(i, N) {
        ll a;
        cin >> a;
        cnt[a]++;
    }

    REP(i, M) {
        ll b, c;
        cin >> b >> c;
        cnt[c] += b;
    }
    
    cout << fixed << setprecision(20);

    ll c = 0;
    ll ans = 0;
    auto it = cnt.begin();
    while(c < N) {
        ll cc = min(N-c, it->se);
        ans += cc * it->fi;
        ++it;
        c += cc;
    }

    cout << ans << endl;

}


Measured memory_bytes: 12800
#include <iostream>
#include <vector>
#include <queue>
#include <string.h>

/*
 * ref. http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_B
 */

using namespace std;

const int MAX_N = 100;

int n;
vector<int> adjlist[MAX_N];
int d[MAX_N];
queue<int> que;

void bfs() {
    int id = 1;

    d[id - 1] = 0;
    // for (int i = 0; i < (int) adjlist[id - 1].size(); i++) {
    //     int next_id = adjlist[id - 1][i];
    //     if (d[next_id - 1] < 0 || d[next_id - 1] > d[id - 1] + 1) {
    //         d[next_id - 1] = d[id - 1] + 1;
    //         que.push(next_id);
    //     }
    // }
    que.push(id);

    while (!que.empty()) {
        id = que.front();
        que.pop();

        for (int i = 0; i < (int) adjlist[id - 1].size(); i++) {
            int next_id = adjlist[id - 1][i];
            if (d[next_id - 1] < 0 || d[next_id - 1] > d[id - 1] + 1) {
                d[next_id - 1] = d[id - 1] + 1;
                que.push(next_id);
            }
        }
    }
}

int main(void) {
    cin >> n;

    for (int i = 0; i < n; i++) {
        int id, m;
        cin >> id >> m;
        for (int j = 0; j < m; j++) {
            int x;
            cin >> x;
            adjlist[id - 1].push_back(x);
        }
    }

    memset(d, -1, sizeof(d));
    bfs();

    for (int i = 0; i < n; i++) {
        int id = i + 1;
        cout << id << " " << d[id - 1] << endl;
    }

    return 0;
}



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

int main(){
ll n,k;
cin >> n >> k;
n = n%k;
n = min(n,k-n);
cout << n << endl;
}

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

using namespace std;
const long long INF = 1LL <<60;
const long long Mo=1000000007;
         

long long gcn(long long x,long long y){
  if(x%y==0){  
    return y;    
  }
  else{
    return gcn(y,x%y);
  }
}

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

int main(void){
  long long tmp,tmp1,tmp2;
  long long n,k,s;
  long long ttl=0;
  long long ac[100000]={};
  long long x=0;
  long long i,j;
  long long res=0;

  cin>>k>>s;

  for(i=0;i<=min(k,s);i++){
    tmp=s-i;
    if(tmp>2*k){
    }
    else if(tmp>=k){
      res+=(2*k-tmp+1);
    }
    else if(tmp<k){
      res+=(tmp+1);
    }
  }
  
  //cout<<setprecision(15)<<res<<endl;
  cout<<res<<endl;

  
  return 0;
    }

Measured memory_bytes: 3636
use std::io::*;

fn main() {
	let input = {
		let mut buf = vec![];
		stdin().read_to_end(&mut buf);
		buf.pop();
		unsafe { String::from_utf8_unchecked(buf) }
	};

	let (c1, c5, c10, c50, c100, c500) = {
		let mut iter = input.split(' ').map(|s| s.parse::<u32>().unwrap());

		(
			iter.next().unwrap(),
			iter.next().unwrap(),
			iter.next().unwrap(),
			iter.next().unwrap(),
			iter.next().unwrap(),
			iter.next().unwrap(),
		)
	};

	let c = c1 + c5 * 5 + c10 * 10 + c50 * 50 + c100 * 100 + c500 * 500;

	if c >= 1000 {
		println!("1");
	} else {
		println!("0");
	}
}



Measured memory_bytes: 5012
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

vector<ll> yakusu(ll n){
    vector<ll> ret;
    for(ll i = 1; i*i <= n; i++){
        if(n % i != 0) continue;
        ret.push_back(i);
        if(i*i != n) ret.push_back(n/i);
    }
    sort(ret.begin(), ret.end());
    return ret;
}

int main(){
    ll n;
    cin >> n;
    VL a(n);
    VB sm(1000010, false);
    rep(i, 0, n){
        cin >> a[i];
    }
    sort(ALL(a));
    VB seen(1000010, false);
    ll ans = 0;
    rep(i, 0, n){
        auto v = yakusu(a[i]);
        bool f = true;
        if(i != n-1 && a[i] == a[i+1]) f = false;
        for(auto e : v){
            if(seen[e]) f = false;
        }
        if(f) ans++;
        seen[a[i]] = true;
    }
    cout << ans << endl;
    return 0;
}

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

#define N 51

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const int MOD = 1e9 + 7;
int n;
ll k;

vvl operator*(vvl &a, vvl &b)
{
	vvl res(n, vl(n, 0));
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			for (int k = 0; k < n; k++)
				res[i][j] = (res[i][j] + (a[i][k] * b[k][j]) % MOD) % MOD;
		}
	}
	return res;
}

vvl solve(vvl &a, ll d)
{
	if (d == 1)
		return a;
	vvl tmp = solve(a, d / 2);
	tmp = tmp * tmp;
	if (d & 1)
		return tmp * a;
	return tmp;
}

int main()
{
	vvl a(N, vl(N));
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			cin >> a[i][j];
	vvl res = solve(a, k);
	ll ans = 0;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			ans = (ans + res[i][j]) % MOD;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
const long long N = 1e5+5;
const long long mod = 1e9+7;
using namespace std;
long long n, u, v, dp[N][2];
bool col[N];
vector<long long> adj[N];
long long mul(long long a, long long b){
	if(b == 0) return 0;
	if(b == 1) return a%mod;
	long long temp = mul(a, b/2);
	if(b%2==0) return (temp+temp)%mod;
	else return (temp+temp+a)%mod;
}
void dfs(long long i){
	col[i] = 1;
	dp[i][0] = dp[i][1] = 1;
	for(auto j: adj[i]){
		if(!col[j]){
			dfs(j);
			dp[i][0] = mul(dp[i][0], (dp[j][1] + dp[j][0])%mod);
			dp[i][1] = mul(dp[i][1], dp[j][0]);
		}
	}
//	prlong longf("dp[%d][0] = %d\n",i,dp[i][0]);
//	prlong longf("dp[%d][1] = %d\n",i,dp[i][1]);
	return;
}

int main() {
//	freopen("PERFECT1.inp", "r", stdin);
//	freopen("PERFECT1.out", "w", stdout);
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	scanf("%lld", &n);
	for(long long i = 2; i <= n; ++i) {
		scanf("%lld %lld", &u, &v);
		adj[u].push_back(v);	
		adj[v].push_back(u);	
	}
	dfs(1);
	printf("%lld",(dp[1][0]+dp[1][1])%mod);
}


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

int main() {
	int N;
	cin >> N;
	vector<long long> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	long long now = 0, num = 0, ans = 0;
	int l = 0;
	for (int r = 0; r < N; r++) {
		num++;
		now = now + A[r];
		while (l < r && ((now-A[r]) & A[r]) != 0) {
			now -= A[l];
			l++;
			num--;
		}
		ans += num;
	}
	cout << ans << endl;
}

Measured memory_bytes: 4796