akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
using namespace std;

int n,A[20];

int search(int i, int sum){
	if (sum==0) return 1;
	if (i>=n) return 0;
	int res=search(i+1,sum) || search(i+1,sum-A[i]);
	//?????£????????????????????°1;
	return res;
}

int main(){
	scanf("%d",&n);
	for (int i=0; i<n;i++) 
	scanf("%d", &A[i]);
	int q;
	scanf("%d",&q);
	int m;
	for (int i=0;i<q;i++){
	scanf("%d",&m);
	if (search(0,m)) printf("yes\n");
	else printf("no\n");
	}
}

Measured memory_bytes: 2612
def main():

    while True:
        m, f, r = tuple(map(int, input().split()))
        if m == f == r == -1:
            break
        elif m == -1 or f == -1:
            print('F')
        elif m + f >= 80:
            print('A')
        elif m + f >= 65:
            print('B')
        elif m + f >= 50:
            print('C')
        elif m + f >= 30:
            if r >= 50:
                print('C')
            else:
                print('D')
        else:
            print('F')

if __name__ == '__main__':
    main()


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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF (1LL<<25)     //33554432
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

signed main(void)
{
  ll n;
  cin >> n;

  int ans = 0;
  for(ll i = n; i>1; i = i/3 + !!(i%3)) ans++;
  cout << ans << endl;

  return 0;
}

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

int f(int x)
{
  int res = 0;
  while (0 < x)
  {
    res += x % 10;
    x /= 10;
  }
  return res;
}

int main()
{
  int N;
  cin >> N;
  string ans = "No";
  if (N % f(N) == 0)
    ans = "Yes";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main(){

    int A;
    int B;
    int K;

    cin >> A >> B >> K;

    for(int i = 0; i < K; i++){
        if(i % 2 == 0){
            if(A % 2 == 0){

            }else{
                A = A - 1;
            }
            B = B + A/2;
            A = A / 2;

        }else{
            if(B % 2 == 0){

            }else{
                B = B - 1;
            }
            A = A + B/2;
            B = B/2;
        }
    }

    cout << A << ' ' << B << endl;
    return 0;
}

Measured memory_bytes: 256
n,x = input().split()
n = int(n)
x = int(x)
candies = input().split()
candies = [int(i) for i in candies]
count = 0
for i in range(n-1):
  if candies[i]+candies[i+1] > x:
    k = candies[i+1]-(candies[i]+candies[i+1]-x)
    if k >= 0:
      count += candies[i]+candies[i+1]-x
      candies[i+1] = k
    else:
      count += candies[i+1]
      candies[i+1] = 0
      count += candies[i] - x
      candies[i] = x
    
print(count)

Measured memory_bytes: 14400
n = gets.chomp.to_i
h = gets.chomp.split.map(&:to_i)
h.reverse!
(n-1).times do |i|
  if h[i+1] - h[i] == 1
    h[i+1] -= 1
  elsif h[i+1] - h[i] > 1
    puts 'No'
    exit
  end
end
puts 'Yes'


Measured memory_bytes: 9604
import sys
def main():
    input = sys.stdin.readline

    N, M, K=map(int, input().split())
    friend_or_block = [set() for _ in range(N)]
    friends_chain = UnionFindTree(N)

    for _ in range(M):
        a, b = map(int, input().split())
        a, b = a-1, b-1
        friends_chain.union(a, b)
        friend_or_block[a].add(b)
        friend_or_block[b].add(a)

    for _ in range(K):
        c, d = map(int, input().split())
        c, d = c-1, d-1
        if friends_chain.same(c, d):
            friend_or_block[c].add(d)
            friend_or_block[d].add(c)

    print(*[friends_chain.size(i) - len(friend_or_block[i]) - 1 for i in range(N)])

class UnionFindTree:
    def __init__(self, n):
        self.parent = [-1] * n

    def find(self, x):
        p = self.parent
        while p[x] >= 0: x, p[x] = p[x], p[p[x]]
        return x

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

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

if __name__ == '__main__':
    main()



Measured memory_bytes: 92320
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
int main(){
  int n,max=0;bool b=true;
  cin>>n;
  vector<int> v(n);
  REP(i,n) cin>>v[i];
  REP(i,n-1){
   if(max<v[i])max=v[i];
      if(max-1>v[i+1]){
        b=false;break;
      }
  }
  
  if(b) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
return 0;
}


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

int main()
{
    int N, M;
    cin >> N >> M;
    int a, b;
    int count[N + 1] = {};
    for (int i = 0; i < M; i++)
    {
        cin >> a >> b;
        count[a]++;
        count[b]++;
    }
    for (int i = 1; i <= N; i++)
    {
        cout << count[i] << endl;
    }
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc127/tasks/abc127_b

import itertools
from collections import Counter
from collections import defaultdict
import bisect

def main():
    r, D, X = map(int, input().split())
    xi = X
    for i in range(1, 11):
        xi = r * xi - D
        print(xi)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };


signed main() {
	int n, cnt = 0;
	vector<int>list;

	cin >> n;

	for (int i = 0; i < n; i++) {
		int num;
		cin >> num;
		list.push_back(num);
	}

	if (n == 2) {
		if (list[0] == list[1]) {
			cout << 1 << endl;
		}
		else {
			cout << 0 << endl;
		}
	}
	else {


		for (int i = 1; i < n ; i++) {
			if (list[i - 1] == list[i]) {
				cnt++;
				i++;
			}
		}

		cout << cnt << endl;
	}

	return 0;
}

Measured memory_bytes: 256
N = int(input())

L = []
for i in range(N):
    a = int(input())
    L.append(a)

new = sorted(L)


ans = 0
for i in range(N):
    if L[i] != new[-1]:
        ans = new[-1]
    else:
        ans = new[-2]
    print(ans)



Measured memory_bytes: 70360
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> cnt(m);

	rep(i, n){
		int k;
		cin >> k;
		rep(j, k){
			int x;
			cin >> x;
			cnt[x - 1]++;
		}
	}
	int ans = 0;
	rep(i, m)ans += (cnt[i] >= n);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        a: usize,
        b: usize,
    }
    if (a * b) % 2 == 0 {
        println!("No");
    } else {
        println!("Yes");
    }
}


Measured memory_bytes: 4352
#include <stdio.h>

int main() {
  int i,j1,j2,k1,k2,s,m,h;
  scanf("%d\n",&i);
  
  j1=i%3600;
  j2=i-j1;
  h=j2/3600;

  k1=(i-h*3600)%60;
  k2=(i-h*3600)-k1;
  m=k2/60;
 
 s=i-m*60-h*3600;
  
  printf("%d:%d:%d\n",h,m,s);
  return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;

void Main(){
	int n;
	cin >> n;
	vi a(n);
	rep(i, n) cin >> a[i];

	for(int i = n-1; i >= 0; i--){
		int part_rem = 0;
		for(int j = i; j < n; j += i+1){
			part_rem += a[j];
		}
		if((part_rem - a[i]) % 2) a[i] = 1 - a[i];
	}

	int sum = 0;
	for(int i = 0; i < n; i++){
		sum += a[i];
	}
	cout << sum << endl;
	for(int i = 0; i < n; i++){
		if(a[i]) cout << i+1 << " ";    
	} 
	return;
}

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

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

void ioinit() { ios::sync_with_stdio(0); cin.tie(0); }

int main() {
  ioinit();
  int N, K;
  string S;
  cin >> N >> S >> K;
  for(int i = 0; i < N; i++){
    if(S[i] != S[K-1]) S[i] = '*';
  }

  cout << S << endl;
}


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

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
using lll = long long;
using ull = unsigned long long;
using namespace std;


int main(){
  lll ii,jj,kk;
  vector<int> ret;
  int n;

  cin >> n;

  vector<int> d;

  d.resize(n);
  
  for(ii=0;ii<n;ii++){
    cin >> d[ii];
  }

  lll sum = 0;

  for(ii=0;ii<n;ii++){
    for(jj=0;jj<n;jj++){
      if(ii!=jj){
        sum += d[ii]*d[jj];
      }
    }
  }

  cout << sum/2;
  return 0;
}


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

using namespace std;

int main() {
	string str;
	cin >> str;
	int n = str.size();
	int win = 0;
	int loses = 0;
	int rock = 0;
	int paper = 1;
	for (int i = 0; i < n; i++) {
		if (str[i] == 'g') {
			if (paper <= rock) {
				win++;
				paper++;
			} else {
				rock++;
			} 									
		} else {
			if (paper <= rock) {
				paper++;
			} else {
				loses++;
				rock++;
			}
		}		
	}
	cout << win - loses << endl;
	return 0;
}



Measured memory_bytes: 512
#include <stdio.h>

int main(){
  int N,K;
  int h[100000];
  int j=0;
  scanf("%d %d",&N,&K);
  for(int i=0;i<N;i++){
  scanf("%d",&h[i]);
if(h[i]>=K){j++;}
  
  }
printf("%d",j);
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define FR first
#define SE second
#define MP make_pair
#define PB push_back
#define vc vector
#define db double
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bin(x) (1ll<<(x))
#define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
#define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
#define mem(x,val) memset(x,val,sizeof x)
#define Swap(a,b,n) for(int I=0;I<=n;I++) swap(a[I],b[I])
#define PC __builtin_popcountll
#ifdef DEBUG
	#define debug(A,args...) fprintf(stderr,A,##args)
#else
	#define debug(A,args...) printf("")
#endif
#define deb debug("line %d\n",__LINE__)
namespace mine
{
	ll qread()
	{
		ll ans=0,f=1;char c=getchar();
		while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num){if(num<0) putchar('-'),num=-num;if(num>=10) write(num/10);putchar('0'+num%10);}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);putchar('\n');}
	template<typename T>inline bool chmax(T&a,const T&b){return a<b?a=b,1:0;}
	template<typename T>inline bool chmin(T&a,const T&b){return a>b?a=b,1:0;}
	ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
	bool IN(ll x,ll l,ll r){return l<=x and x<=r;}
	void GG(){puts("-1");exit(0);}
	
	const db eps=1e-8;
	const int INF=0x3f3f3f3f;
	const int MOD=998244353;
	int mm(const int x){return x>=MOD?x-MOD:x;}
	template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
	ll qpower(ll x,ll e,int mod=MOD){ll ans=1;while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
	ll invm(ll x){return qpower(x,MOD-2);}
	const int MM=1e6+10;
	ll fac[MM],facinv[MM],Inv[MM];ll Comb(int n,int m){return n<0 or n<m?0:fac[n]*facinv[m]%MOD*facinv[n-m]%MOD;}
	void PRE()
	{
		fac[0]=1;fo(i,1,MM-1) fac[i]=fac[i-1]*i%MOD;
		facinv[MM-1]=invm(fac[MM-1]);fd(i,MM-1,1) facinv[i-1]=facinv[i]*i%MOD;
		Inv[1]=1;fo(i,2,MM-1) Inv[i]=(MOD-MOD/i)*Inv[MOD%i]%MOD;
	}
	const int N=1e6+10;
	//------------------FIXED------------------
	map<int,int> cnt;vc<int> hh;
	void main()
	{
		int n=qread(),K=qread();fo(i,1,n) cnt[qread()]++;
		for(auto in:cnt) hh.PB(in.SE);sort(all(hh));
		int ans=0;fo(i,max(0,sz(hh)-K),sz(hh)-1) ans+=hh[i];write(n-ans);
	}
};//����������
signed main()
{
	#ifdef DEBUG
	//freopen("a.in","r",stdin);
	freopen("z.txt","r",stdin);
	//freopen("a.out","w",stdout);
	#endif
	srand(time(0));
	mine::PRE();
	mine::main();
	debug("\n------------------------------------------\nTime: %.2lf s",1.0*clock()/CLOCKS_PER_SEC);
}

Measured memory_bytes: 34172
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
const long long MOD = 1000000007;

ll N, Ma, Mb, a[50], b[50], c[50];
ll dp[50][401][401];

signed main(){
    cin >> N >> Ma >> Mb;
    REP(i, N) cin >> a[i] >> b[i] >> c[i];
    REP(i, N + 1) REP(j, 401) REP(k, 401) dp[i][j][k] = LONG_LONG_MAX / 2;
    dp[0][0][0] = 0;
    REP(i, N){
        REP(j, 401){
            REP(k, 401){
                dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
                if(j + a[i] > 400 || k + b[i] > 400) continue;
                dp[i + 1][j + a[i]][k + b[i]] = min(dp[i + 1][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);
            }
        }
    }
    ll ans = LONG_LONG_MAX / 2;
    FOR(i, 1, 401){
        FOR(j, 1, 401){
            if(i * Mb != j * Ma) continue;
            ans = min(ans, dp[N][i][j]);
        }
    }
    if(ans == LONG_LONG_MAX / 2) PRINT("-1"); 
    else PRINT(ans);
    return 0;
}

Measured memory_bytes: 55080
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <fstream>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, P> T;

const ll mod = 1000000007;
const ll INF = 100000010000;

ll N, A, B;

ll ans;

ll pow_mod(ll x, ll y)
{
	if (y == 0) return 1;
	if (y % 2 == 1)
	{
		return x * pow_mod(x, y - 1) % mod;
	}
	else
	{
		ll half = pow_mod(x, y / 2);
		return half * half % mod;
	}
}

ll div_mod(ll x)
{
	return pow_mod(x, mod - 2);
}

/*ll sum_bit(ll i)
{
	ll s = 0;
	while (i > 0)
	{
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add_bit(ll i, ll x)
{
	while (i <= 2 * N + 10)
	{
		bit[i] += x;
		i += i & -i;
	}
}*/

void init()
{
	cin >> N >> A >> B;
}

void output()
{
	cout << ans << endl;
}



void solve()
{
	if (abs(A - B) % 2 == 0)
	{
		ans = abs(A - B) / 2;
	}
	else
	{
		ans = min(A, B) - 1 + (abs(A - B) + 1) / 2;
		A = N + 1 - A;
		B = N + 1 - B;
		ans = min(ans, min(A, B) - 1 + (abs(A - B) + 1) / 2);
	}
}

int main()
{
	init();

	solve();

	

	output();

	cin >> N;
}

Measured memory_bytes: 256
#include <iostream> 
#include <vector>
#include <cmath>
#include <string>
#include <sstream>
#include <algorithm>
#include <queue>
#include <stack>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <cctype>
#include <climits>

using namespace std;

using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;

using ll = long long int;

#define mp(a,b) make_pair(a,b)

const int MOD = 1000 * 1000 * 1000 + 7;



int main() {
	int n;
	cin >> n;
	if (n >= 30) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}

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

int main()
{
  int64_t N, K, s = 0;
  cin >> N >> K;
  vector<int64_t> A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
    s += A.at(i);
  }
  vector<int64_t> divisors; // sの約数
  for (int64_t i = 1; i * i <= s; i++)
  {
    if (s % i != 0)
      continue;
    divisors.push_back(i);
    if (s / i != i)
    {
      divisors.push_back(s / i);
    }
  }
  sort(divisors.begin(), divisors.end());
  reverse(divisors.begin(), divisors.end());
  for (auto d : divisors)
  {
    vector<int64_t> rs;
    for (auto a : A)
    {
      if (a % d == 0)
        continue;
      rs.push_back(a % d);
    }
    sort(rs.begin(), rs.end());
    int64_t c1 = 0, c2 = 0;
    int r = rs.size() - 1;
    for (int l = 0; l < rs.size(); l++)
    {
      c1 += rs.at(l);
      while (c1 > c2)
      {
        c2 += d - rs.at(r);
        r--;
      }
      if (l >= r)
        break;
    }
    if (c1 <= K)
    {
      cout << d << endl;
      return 0;
    }
  }
}

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


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

fact = [1]
for i in range(1, N+1):
    fact.append(fact[i-1] * i % mod)
inv = [0] * (N+1)
inv[N] = pow(fact[N], mod-2, mod)
for i in range(N, 0, -1):
    inv[i-1] = inv[i] * i % mod
def nCr(n, r):
    if n == 0 and r == 0:
        return 1
    if r == 0:
        return 1
    if r < 0:
        return 0
    return fact[n] * inv[r] * inv[n-r] % mod


def main():
    if K == 1:
        print(0)
        return

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

    A.sort()
    mi = 0
    for i in range(N):
        m = nCr(N-1-i, N-K-i)
        mi += A[i] * m
        mi %= mod
    ma = 0

    A.reverse()
    for i in range(N):
        m = nCr(N-1-i, N-K-i)
        ma += A[i] * m
        ma %= mod

    ans = (ma - mi) % mod
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 22104
n = int(input())

def compress(n, k, depth=1):
    d, m = divmod(n, k)
    if d == 0:
        return n * depth
    return compress(d, k) + m * depth

minv = float("inf")
for n9 in range(n // 9 + 1):
    m = (n - n9 * 9)
    n6, n1 = divmod(m, 6)
    result = n1 + compress(n6, 6) + compress(n9, 9)
    minv = min(minv, result)
print(min(minv, n))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, to) for (int i = 0; i < (to); ++i)
#define repf(i, from, to) for (int i = (from); i < (to); ++i)
#define unless(cond) if (!(cond))
using namespace std;
using ll = long long;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

int main() {
  int n;
  V<int> a;
  map<int, int> candidate_x;
  cin >> n;
  a.resize(n);

  rep(i, n) {
    int elem;
    cin >> elem;

    a[i] = elem;

    candidate_x[elem - 1] = 0;
    candidate_x[elem] = 0;
    candidate_x[elem + 1] = 0;
  }

  // Count
  rep(i, n) {
    int elem = a[i];
    candidate_x[elem - 1]++;
    candidate_x[elem]++;
    candidate_x[elem + 1]++;
  }

  // Find max
  int max_x_count = 0;
  for(auto it = candidate_x.begin(); it != candidate_x.end(); it++) {
    max_x_count = max(it->second, max_x_count);
  }

  cout << max_x_count << endl;
}

Measured memory_bytes: 7912
#include <stdio.h>

void trace(int N,int A[]){
  int i;
  for(i=0;i<=N-1;i++){
    if(i>0){
    printf(" ");
    }
    printf("%d",A[i]);
    }
  printf("\n");
}

int main(void){

int n,i,j,k;
int v;
int A[100];
scanf("%d\n",&n);
for(i=0;i<=n-1;i++){
  scanf("%d",&A[i]);
}

trace(n,A);//???????????¨???

for(j=1;j<=n-1;j++){
  v=A[j];
  k=j-1;
  while(k>=0 && v<A[k]){
    A[k+1]=A[k];
    k--;
  }
  A[k+1]=v;
  trace(n,A);
  }

return 0;    
}

Measured memory_bytes: 600
#include<iostream>
using namespace std;
int main()
{
  int A, B, sum;
  cin >> A >> B;
  sum = 0;
  
  for(int i=0; i<2; i++){
    if(A>B){
      sum += A;
      A = A - 1;
    }else{
      sum += B;
      B = B - 1;
    }
  }
  
  cout << sum << endl;
  return 0;
}

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

int gcd(int x,int y){
		if(y==0)return x;
		else return gcd(y,x%y);
	}

signed main(){
	int n,m;cin>>n>>m;
	string s,t;cin>>s>>t;
	int d=gcd(n,m),n0=n/d,m0=m/d;
	bool flg=true;
	for(int i=0;i<d;i++){
		if(s[i*n0]!=t[i*m0])flg=false;
	}
	if(flg)cout<<d*m0*n0<<endl;
	else cout<<-1<<endl;

}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;
//ここから

void solve(){
  //0:羊,1:狼
  int n;
  string s;
  cin>>n>>s;
  vector<int>v(n);
  rep(a,2){//先頭の置き方
    rep(b,2){//2番目の置き方
    bool ok=true;
      v[0]=a,v[1]=b;
      for(int i=2;i<n;++i){
        if(s[i-1]=='o'){
          if(v[i-1]==0)v[i]=v[i-2];
          else v[i]=v[i-2]^1;
        }
        else {
          if(v[i-1]==0)v[i]=v[i-2]^1;
          else v[i]=v[i-2];
        }
      }
      rep(i,n){
        //if(a==0&&b==0)cout<<v[i]<<endl;
        if(s[i]=='o'){
          if(v[i]==0&&v[(i-1+n)%n]!=v[(i+1)%n])ok=false;
          else if(v[i]==1&&v[(i-1+n)%n]==v[(i+1)%n])ok=false;
        }
        else{
          if(v[i]==0&&v[(i-1+n)%n]==v[(i+1)%n])ok=false;
          else if(v[i]==1&&v[(i-1+n)%n]!=v[(i+1)%n])ok=false;
        }
      }
      if(ok){
        rep(i,n){
          if(v[i]==1)cout<<"W";
          else cout<<"S";
        }
        cout<<"\n";
        return;
      }
    }
  }
  
  cout<<-1<<"\n";
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 976
import sys
from bisect import bisect_left,bisect,bisect_right

icase=0
if icase==0:
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    d=[]
    cb=[[0]*2 for i in range(m)]
    for i in range(m):
        bi,ci=map(int,input().split())
        cb[i]=[ci,bi]
elif icase==1:
    n,m=3,2
    a=[1, 4, 5]
    cb=[[5, 1], [3, 2]]
elif icase==3:
    n,m=3,2
    a=[100, 100, 100]
    cb=[[99, 3], [99, 3]]
elif icase==2:
    n,m=10,3
    a=[1, 4, 5, 5, 7, 8, 13, 33, 52, 100]
    cb=[[30, 4], [10, 3], [4, 1]]
elif icase==4:
    n,m=11,3
    a=[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
    cb=[[1000000000, 4], [1000000000, 3], [1000000000, 3]]
elif icase==5:
    f=open(r"C:\Users\nishi\999atcoder\ABCD040-151\ABC127D\testcase_13_in.dat")
    ll=f.readline()
    n,m=map(int,ll.split())
    ll=f.readline()
    a=list(map(int,ll.split()))
    d=[]
    cb=[[0]*2 for i in range(m)]
    for i in range(m):
        ll=f.readline()
        bi,ci=map(int,ll.split())
        cb[i]=[ci,bi]
    f.close()
    ans=99913215738299
elif icase==6:
    f=open(r"C:\Users\nishi\999atcoder\ABCD040-151\ABC127D\testcase_12_in.dat")
    ll=f.readline()
    n,m=map(int,ll.split())
    ll=f.readline()
    a=list(map(int,ll.split()))
    d=[]
    cb=[[0]*2 for i in range(m)]
    for i in range(m):
        ll=f.readline()
        bi,ci=map(int,ll.split())
        cb[i]=[ci,bi]
    f.close()
    ans=95821339675952

a.sort()
cb.sort(reverse=True)

if cb[0][0]<=a[0]:
    print(sum(a))
    sys.exit()
    
asum=0
isum=0
isumm=0
for i in range(m):
    isum+=cb[i][1]
    if isum>n:
        if a[-1]<=cb[i][0]:
#        print("A",i)
            asum+=cb[i][0]*(n-isumm)
            print(asum)
            sys.exit()
#    isum=min(isum,n)
#    print(i,isum,a[isum-1])
        else:
#        print("C",i)
            ii=bisect_right(a,cb[i][0])
            asum+=cb[i][0]*(ii-isumm)
#        print(ii,isumm,asum)
#        asum+=sum(a[ii:isum])
            asum+=sum(a[ii:])
            print(asum)
            sys.exit()
    if a[isum-1]<=cb[i][0]:
        asum+=cb[i][0]*cb[i][1]
#        asum+=cb[i][0]*(isum-isumm)
#        print("B",i,isum,asum)
        isumm=isum
        continue
    else:
#        print("C",i)
        ii=bisect_right(a,cb[i][0])
        asum+=cb[i][0]*(ii-isumm)
#        print(ii,isumm,asum)
#        asum+=sum(a[ii:isum])
        asum+=sum(a[ii:])
        print(asum)
        sys.exit()
#        isumm=isum
#        break
    isumm=isum
    
#if isumm<n:
asum+=sum(a[isumm:])
        
print(asum)


Measured memory_bytes: 28268
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>

using namespace std;
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;

int main(){
    ll N,K,R,S,P;
    string T;
    cin>>N>>K>>R>>S>>P>>T;
    
    vector<string> T2(K,"");
    for(int i=0;i<N;i++){
        T2[i%K]+=T[i];
    }
    
    ll ans=0;
    for(int g=0;g<T2.size();g++){
        char y=-1;
        for(int i=0;i<T2[g].size();i++){
            char x=T2[g][i];
            if(i==0) {
                ans+=(x=='r')*P+(x=='s')*R+(x=='p')*S;
                y=x;
            }
            else{
                if(y!=x){
                    ans+=(x=='r')*P+(x=='s')*R+(x=='p')*S;
                    y=x;
                }
                else y=-1;
            }
        }
    }
    
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 5120
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>
#include <functional>

using namespace std;
#define ALL(x)              (x).begin(),(x).end()
#define REP(i, n)           for (int (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n)       for (int (i) = m ; (i) < (ll)(n) ; ++(i))
#define INF                 (int)2e9
#define MOD                 (1000 * 1000 * 1000 + 7)
#define Ceil(x, n)          (((((x))+((n)-1))/n))
#define CeilN(x, n)         (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)        ((x)-(x)%(n))
#define IsOdd(x)            (((x)&0x01UL) == 0x01UL)
#define IsEven(x)           (!IsOdd((x)))
#define M_PI                3.14159265358979323846
typedef long long           ll;
typedef pair<ll, ll>        P;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
char getNextChar(char ansPrev, char ansNow, char call)
{
	char stChar;
	if (ansNow == 'S') {
		if (call == 'o') {
			stChar = (ansPrev == 'S') ? 'S' : 'W';
		} else {
			stChar = (ansPrev == 'S') ? 'W' : 'S';
		}
	} else {
		if (call != 'o') {
			stChar = (ansPrev == 'S') ? 'S' : 'W';
		} else {
			stChar = (ansPrev == 'S') ? 'W' : 'S';
		}
	}
	return stChar;
}

bool check(string &s, string &ans)
{
	REPN(i, 1, s.size() - 1) {
		ans += getNextChar(ans[i - 1], ans[i], s[i]);
	}

	int i = s.size() - 1;
	char stChar = getNextChar(ans[i - 1], ans[i], s[i]);
	if (ans[0] != stChar) {
		return false;
	}

	stChar = getNextChar(ans[i], ans[0], s[0]);
	return ans[1] == stChar;
}

int main()
{
	int N;
	string s;
	cin >> N >> s;
	string ans;

	ans = "SW";
	if (check(s, ans)) {
		cout << ans << endl;
		return 0;
	}
	ans = "SS";
	if (check(s, ans)) {
		cout << ans << endl;
		return 0;
	}
	ans = "WS";
	if (check(s, ans)) {
		cout << ans << endl;
		return 0;
	}
	ans = "WW";
	if (check(s, ans)) {
		cout << ans << endl;
		return 0;
	}

	cout << -1 << endl;
	return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <cassert>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr ll INF = 3000000000000000000;

void solve() {
    int n;
    cin >> n;
    vector<ll> k(n), l(n), r(n);
    vector<vector<int>> S(n);
    REP(i, n) {
        cin >> k[i] >> l[i] >> r[i];
        --k[i];
        S[k[i]].push_back(i);
    }
    
    ll ans = 0;
    REP(i, n) ans += min(l[i], r[i]);
    priority_queue<ll> pq;
    for (int i = n - 1; i >= 0; --i) {
        for (int j: S[i]) {
            if (l[j] > r[j]) pq.push(l[j] - r[j]);
        }
        if (!pq.empty()) {
            ans += pq.top();
            pq.pop();
        }
    }
    while (!pq.empty()) pq.pop();
    for (int i = 1; i < n; ++i) {
        for (int j: S[i - 1]) {
            if (l[j] <= r[j]) pq.push(r[j] - l[j]);
        }
        if (!pq.empty()) {
            ans += pq.top();
            pq.pop();
        }
    }
    
    cout << ans << "\n";
    
}

int main() {
    int t;
    cin >> t;
    REP(i, t) solve();
}


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

int main()
{
    vector<vector<int>> a(3, vector<int>(3, 0));
    vector<vector<bool>> test(3, vector<bool>(3, false));
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> a.at(i).at(j);
        }
    }
    int n, b;
    cin >> n;
    for (int cnt = 0; cnt < n; cnt++)
    {
        cin >> b;
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                if (a.at(i).at(j) == b)
                {
                    test.at(i).at(j) = true;
                }
            }
        }
    }
    for (int i = 0; i < 3; i++)
    {
        if (test.at(i).at(0) and test.at(i).at(1) and test.at(i).at(2))
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    for (int j = 0; j < 3; j++)
    {
        if (test.at(0).at(j) and test.at(1).at(j) and test.at(2).at(j))
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    if (test.at(0).at(0) and test.at(1).at(1) and test.at(2).at(2))
    {
        cout << "Yes" << endl;
        return 0;
    }
    if (test.at(0).at(2) and test.at(1).at(1) and test.at(2).at(0))
    {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    final String S=sc.next();
    switch(S){
      case "Sunny":
        System.out.println("Cloudy");
        break;
      case "Cloudy":
        System.out.println("Rainy");
        break;
      case "Rainy":
        System.out.println("Sunny");
    }
  }
}

Measured memory_bytes: 20820
import math


def make_row(id, heap):
    s = "node " + str(id) + ": key = " + str(heap[id - 1]) + ", "
    length = len(heap)
    if 0 <= math.floor(id // 2) - 1 < length:
        s += "parent key = " + str(heap[math.floor(id // 2) - 1]) + ", "
    if 0 <= 2 * id - 1 < length:
        s += "left key = " + str(heap[2 * id - 1]) + ", "
    if 0 <= 2 * id < length:
        s += "right key = " + str(heap[2 * id]) + ", "
    return s


h = int(input())
heap = [int(x) for x in input().split()]

for id in range(1, h + 1):
    print(make_row(id, heap))


Measured memory_bytes: 5680
PROGRAM ATCODER

implicit none
integer(8) :: n, k, sizek, i, j, ans, x
integer(8),allocatable :: a(:), count(:)

read(*,*) n, k
allocate(a(n))

read(*,*) (a(i), i=1,n)

sizek = int(log(real(k,8))/log(real(2,8)))+1

allocate(count(sizek)) ! count(1)=1ビット目が1の数はいくつあるか
count = 0

do i = 1, sizek
	do j = 1, n
    	if(btest(a(j),i-1))then
        	count(i) = count(i) + 1
        end if
    end do
end do

do i = sizek, 1, -1
	if (count(i) <= n-count(i))then
    	x = x + 2**(i-1)
    end if
	if (x > k) then
		x = x - 2**(i-1)
    end if
end do

ans = 0
do j = 1, n
	ans = ans + xor(x,a(j))
end do

write(*,'(i0)') ans

END PROGRAM ATCODER


Measured memory_bytes: 1536
#include <iostream>

#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;

int main() {
    int w, h, x, y;
    cin >> w >> h >> x >> y;

    double area = double(w) * double(h);
    auto ans = 2 * x == w && 2 * y == h;
    printf("%lf %d\n", area / 2, ans);
    return 0;
}


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

int main () {
	string s;
	cin >> s;

	if (s[0] == s[1] || s[1] == s[2] || s[2] == s[0]) {
		cout << "No" << endl;
	}
	else cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int n = sc.nextInt();

        int m = sc.nextInt();

        int ans = (n * (n - 1) / 2) + (m * (m - 1) / 2);

        System.out.println(ans);

    }
}

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

using namespace std;

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

    int max_cnt = 0;
    bool flag = false;
    while(true){
    for(int i = 0; i < n; i++){
            if (arrInteger[i] % 2 == 1){
                flag = false;
                break;
            }
            arrInteger[i] /= 2;
            flag = true;
        }
        if(flag == false) break;

        max_cnt++;
    }

    cout << max_cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)

int main(void){
	int n;
	while(cin>>n,n){
		int gra[7]={0};
		rep(i,n){
			int data;
			cin>>data;
			if(data<10)gra[0]++;
			else if(data<20)gra[1]++;
			else if(data<30)gra[2]++;
			else if(data<40)gra[3]++;
			else if(data<50)gra[4]++;
			else if(data<60)gra[5]++;
			else gra[6]++;
		}
		rep(i,7){
			cout<<gra[i]<<endl;
		}
	}
}

Measured memory_bytes: 1160
#include<iostream>
#include<algorithm>
#include <iostream> 
#include <algorithm> 
#include<string>
#include<queue>
#include<utility>
#include<fstream>
#include<queue>
#include<set>
#include<stack>
#include<map>
//#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a)  for(int i=0;i<a.size();i++)
#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
 
 
template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
 
 
typedef pair<int,int >P;
//////////////////////////
/////////////////////////
int main(){
    int n,m;
    I2(n,m);
    vector<int>ans[2];
    bool fl = 0;
    for(int i = 1;i<=m;i++)ans[fl].push_back(i);
    for(int i = 1;i<=n;i++){
        int x;
        I(x);
        map<int,int>mp;
        for(int j = 1;j<=x;j++){
            int y;
            cin>>y;
            mp[y]++;
        }
        fl ^= 1;
        ans[fl].clear();
        for(int j = 0;j<ans[fl^1].size();j++){
            if(mp[ans[fl^1][j]]>0)ans[fl].push_back(ans[fl^1][j]);
        }

    }
    cout<<(int)ans[fl].size()<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define N 10000
#define INF 1000000000
#define WHITE 0
#define BLACK 2
#define GRAY 1


int main(){
  int kazu,i,j,k,cnt=0,u,m[500000][3];
  int d[N],color[N];

  scanf("%d",&kazu);

  for(i=0;i<kazu;i++){
    d[i] = INF;
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      m[cnt][0] = u;
      scanf("%d%d",&m[cnt][1],&m[cnt][2]);
      cnt++;
    }

  }
  d[0] = 0;
  color[u] = BLACK;

  while(color[u] != WHITE){
    color[u] = WHITE;
    for(i=0;i<cnt;i++){
      if(d[m[i][1]] > d[m[i][0]] + m[i][2]){
        d[m[i][1]] = d[m[i][0]] + m[i][2];
        color[u] = BLACK;
      }
    }
  }


  for(i=0;i<kazu;i++)printf("%d %d\n",i,d[i]);



  return 0;
}



Measured memory_bytes: 7600
n=int(input())
l=[]
for i in range(n):
    a, b = map(int, input().split())

    p=int((a*b)**(1/2))

    if p*(p+1) < a*b:
        ans=int(2*p-1)
    elif p**2==a*b and not a==b:
        ans=int(2*p-3)
    else:
        ans=int(2*p-2)
    l.append(ans)

for i in range(n):
    print(l[i])


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
 
 
#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr)
using namespace std;
 
signed main() {
    FAST_IO;
 
    int n;
    cin >> n;
    int a[n], b[n], c[n];
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];
    int dp[n + 1][3];
  // Set the base values
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    for (int i = 1; i < n; i++) {
        dp[i][0] = a[i] + max(dp[i - 1][1], dp[i - 1][2]);
        dp[i][1] = b[i] + max(dp[i - 1][0], dp[i - 1][2]);
        dp[i][2] = c[i] + max(dp[i - 1][1], dp[i - 1][0]);
    }
  // We want to print the maximum of all the states
    cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}); 
    return 0;
}

Measured memory_bytes: 2560
import Control.Monad
import Data.List
import Data.Ord
import qualified Data.ByteString.Char8 as B
import qualified Data.IntMap as M

mf n Nothing = Just n
mf n (Just a) = Just (n+a)

main = do
    n<-readLn::IO Int
    vs<-unfoldr (B.readInt.B.dropWhile(==' '))<$>B.getLine::IO[Int]
    print $ sol vs
---
sol vs = minimum $ map (\n-> on n + enn n ) $ M.keys mo
    where
        os = map fst $ filter (odd.snd) $ zip vs [1..]
        es = map fst $ filter (even.snd) $ zip vs [1..]
        mo = foldl' (flip (M.alter (mf 1))) M.empty os
        me = foldl' (flip (M.alter (mf 1))) M.empty es
        se = sortBy (flip $ comparing snd) $ M.toList me
        on n = (length os) - (mo M.! n)
        enn n = case dropWhile ((==n).fst) se of
            [] -> length es
            ((_,x):_) -> length es - x


Measured memory_bytes: 32124
#include <bits/stdc++.h>
#define int long long
using namespace std;
void solve(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int white[n],red[n];
    int idx1=0,idx2=0;
    for(int i=0;i<n;i++){
        if(s[i]=='W'){
            white[idx1++]=i;
        }
        else{
            red[idx2++]=i;
        }
    }
    int cnt=0;
    for(int i=0;i<idx1;i++){
        if(white[i]<red[idx2-1]){
            cnt++;
            idx2--;
        }
        if(idx2==0)
            break;
    }
    cout<<cnt;
}
int32_t main() {
	// your code goes here
	int t;
	t=1;
	while(t--){
	    solve();
	}
}

Measured memory_bytes: 5324
/*
ID: sabertooth
LANG:C++11
TASK: hamming
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
    ll a,b,c;
    cin>>a>>b>>c;
    int k;
    cin>>k;
    ll m1=max(a,max(b,c));
    ll m3=min(a,min(b,c));
    ll m2=a+b+c-m1-m3;
    for(int i=0;i<k;i++)m1*=2;
    cout<<m1+m2+m3<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

template<typename T>
vector<T> radix_conversion(T x, T b, int n = -1) {
  vector<T> res;
  T t = 1, k = llabs(b);
  while(x) {
    res.emplace_back((x * t) % k);
    if(res.back() < 0) res.back() += k;
    x -= res.back() * t;
    x /= k;
    t *= b/k;
  }
  if(res.empty()) res.emplace_back(0);
  for (int i = res.size(); i < n; ++i) res.emplace_back(0);
  reverse(res.begin(),res.end());
  return res;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n;
  cin >> n;
  vector<int> A(3);
  rep(i,3) cin >> A[i];
  vector<int> L(n);
  rep(i,n) {
    cin >> L[i];
  }
  int maxi = 1;
  rep(i,n) maxi *= 4;
  ll ans = 1LL<<60;
  rep(x, maxi) {
    auto v = radix_conversion(x, 4, n);
    vector<vector<int> > G(4);
    rep(i,n) G[v[i]].emplace_back(i);
    bool ok = true;
    ll cost = 0;
    rep(i,3) {
      int m = G[i].size();
      if (m == 0) {
        ok = false; break;
      }
      cost += 10 * (m-1);
      ll lensum = 0;
      rep(j,m) lensum += L[G[i][j]];
      cost += llabs(A[i] - lensum);
    }
    if (!ok) continue;
    chmin(ans, cost);
  } 
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <algorithm>
#include <tuple>
#include <numeric>

int main()
{
	int N;
	int red = 0;
	int blue = 0;

	std::cin >> N;
	std::string s;
	std::cin >> s;
	for (auto ch : s) {
		if (ch == 'R')
			++red;
		else
			++blue;
	}

	if (red > blue)
		std::cout << "Yes\n";
	else
		std::cout << "No\n";
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
public class Hello
{
    public static void Main()
    {
        
        int[] a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        int N = a[0];
        int M = a[1];
        int[] A = Console.ReadLine().Split(' ').Select(y => int.Parse(y)).ToArray();
        
        //まずは最大となるときの桁数を求める
        int[] dp = new int[N + 10]; //dp[i] : ちょうどi本のマッチ棒を使って，条件を満たす整数を作るときの最大桁数
        dp[0] = 0;
        
        for(int i = 1; i <= N; i++)
        {
            int max = -10;
            for(int j = 0; j < M; j++)
            {
                try
                {
                    max = Math.Max(max, dp[i - num(A[j])] + 1);
                }
                catch(IndexOutOfRangeException)
                {
                    continue;
                }
            }
            dp[i] = max;
        }
            
    　　//できるだけ大きい数を上位の桁に当てはめていく
        int remain = dp[N]; //残りの桁数
        int match = N; //残りのマッチの本数
        string ans = "";
        Array.Sort(A);
        
        
        while(match > 0)
        {
            for(int i = M - 1; i >= 0; i--)
            {
                try
                {
                    if(dp[match - num(A[i])] == remain - 1)
                    {
                        
                        ans += A[i];
                        match -= num(A[i]);
                        remain--;
                        break;
                    }
                }
                catch(IndexOutOfRangeException)
                {
                    continue;
                }
                
            }
        }
        
        Console.WriteLine(ans);
    }
    
    public static int num(int x)
    {
        int[] c = {0,2,5,5,4,5,6,3,7,6};
        return c[x];
    }
}


Measured memory_bytes: 25808
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);i++)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;i--)
#define lb lower_bound
#define ub upper_bound
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> void chmin(T& t, const U& u){if(t>u)t=u;}
template<typename T,typename U> void chmax(T& t, const U& u){if(t<u)t=u;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T mpow(T a, T n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}


signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n;cin>>n;
  bool ans=true;
  vector<string> v(n);
  rep(i,0,n)cin>>v[i];

  rep(i,0,n-1){
    if(v[i].back()!=v[i+1][0])ans=false;
  }

  sort(all(v));
  if(unique(all(v))!=v.end())ans=false;

  if(ans)puts("Yes");
  else puts("No");
}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 256
X,Y=map(int,input().split())
crane=(4*X-Y)//2
turtle=(Y-2*X)//2
if (4*X-Y)%2==0 and crane>=0:
    if (Y-2*X)%2==0 and turtle>=0:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 9132