akhauriyash/Code-Regression huggingface dataset:
/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e5;
int num[N+7],n,m,bet[N+7];
long long ans;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++)
		scanf("%d",&num[i]);
	sort(num,num+m);
	for(int i=1;i<m;i++)
		bet[i]=num[i]-num[i-1],ans+=bet[i];
	sort(bet+1,bet+m);
	n--;
	for(int i=m-1;i>=1&&n;i--,n--)
		ans-=bet[i];
	printf("%lld\n",ans);
	return 0;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define INF 1000000007
// cin.eof() 入力個数の問題
int main() {
 int h,w;
 cin>>h>>w;
 char c[h+1][w+1];
 for(int i=1;i<=h;i++){
     for(int k=1;k<=w;k++){
         cin>>c[i][k];
     }
 }
for(int i=1;i<=2*h;i++){
    for(int k=1;k<=w;k++){
        cout<<c[(i+1)/2][k];
    }
    cout<<endl;
}


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, x, y) for (ll i = x; i <= y; i++)
#define BIT(t) (1ll << t)
#define PER(i, y, x) for (ll i = y; i >= x; i--)
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define pll pair<ll, ll>
#define SIZE(v) ll(v.size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
//        ios::sync_with_stdio(false);
//        cin.tie(nullptr);

int main(){
  ll n;
  cin >> n;
  ll ans = 1;
  while(ans * n % 360 != 0){
    ans++;
  }
  cout << ans << endl;
}

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

int main(){
  int n;
  string s;
  cin >> n >> s;
  int r=0, b=0;
  for(int i=0; i<n; i++){
    if(s[i]=='R')r++;
    else b++;
  }
  if(r>b)cout << "Yes";
  else cout << "No";
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
class Main {
    public static void main(final String[] args) {
        Scanner scan = new Scanner(System.in);
        String s = scan.nextLine();
        int sLen = s.length();
        long ans = 0;
        for (int i = 0; i < Math.pow(2,sLen - 1); i++) {
            StringBuilder sb = new StringBuilder(s);
            int cnt = 1;
            for (int k = 0; k < sLen - 1; k++) {
                if ((1 & i >> k) == 1) {
					sb.insert(k + cnt, ",");
					cnt++;
                }
            }
            String[] temp = sb.toString().split(",");
            for (int j = 0; j<temp.length; j++) {
                ans += Long.parseLong(temp[j]);
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N, M;
    cin >> N >> M;
    VLL P(M+1),Y(M+1);
    vector<vector<int>> pref_year(N+1);
    rep(i,M){
        cin >> P[i] >> Y[i];
        pref_year[P[i]].PB(Y[i]);
    }
    map<ll, ll> year_rank;
    rept(i,1,N+1){
        sort(all(pref_year[i]));
        rep(j,pref_year[i].size()){
            year_rank[pref_year[i][j]]=j+1;
        }
    }
    rep(i,M){
        cout << zero_pad(6) << P[i] << zero_pad(6) << year_rank[Y[i]] << endl;
    }
}


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

int main()
{
	int N,x[100005]={0};
	cin >> N;
	for(int i=0; i<N; i++)
	{
		int a,b;
		cin>>a>>b;
		x[a]++; x[b+1]--;
	}

	int ans=0,tmp=0;
	for(int i=2; i<N+2; i++)
	{
		tmp+=x[i];
		if(tmp>=i-1)
		ans=max(ans,min(tmp,i-1));
	}

	cout << ans << endl;
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    LL x;
    cin >> x;
    double res = 0;
    LL p = 100;
    LL c = 0;
    while(p < x) {
        p += p / 100;
        c++;

    }
    cout << c << endl;

    return 0;
}



Measured memory_bytes: 3616
s=input()
a=int(s[:2])
b=int(s[2:])
ac=0
bc=0
if 0<a and a<13:
  ac=1
if 0<b and b<13:
  bc=1
  
if ac and bc:
  print("AMBIGUOUS")
elif ac:
  print("MMYY")
elif bc:
  print("YYMM")
else:
  print("NA")

Measured memory_bytes: 9188
import sys


def input():
    return sys.stdin.readline().strip()


def main():
    N, M = map(int, input().split())
    if M == 1:
        print(1, 2)
    else:
        c = (M + 1) // 2
        d = M + (M + 1) // 2
        for i in range(1, M + 1):
            if i % 2 == 1:
                print(c, c + i)
                c -= 1
            else:
                print(d, d + i)
                d -= 1


if __name__ == "__main__":
    main()


Measured memory_bytes: 9280
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <queue>
#include<iomanip>
#include <cmath>
#include <set>

#define ABS(x) ((x)>0?(x):-(x))
#define MIN(x,y) ((x)>(y)?(y):(x))

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

using namespace std;
typedef long long ll;

ll newton(long long int a, long long int  b)
{
	if(a==b)
		return a;
	while(a != 0 && b != 0)
	{
		if(a > b)
		{
			b += a;
			a = b-a;
			b -= a;
		}
		b %= a;
	}
	return a;
}

struct UnionFind {
	vector<int> p;
	UnionFind(int N):p(N)
	{
		for(int i=0; i< N; i++)
		{
			p[i] = i;
		}
	}
	int root(int x)
	{
		if(p[x] == x)
			return x;
		return p[x] = root(p[x]);
	}
	void unite(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		if(rx == ry) return;
		p[rx] = ry;
	}
	bool issame(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

//大きな数に対する割り算をするとき、MODを指定することで掛け算の値に変換できる

ll div2mul_calc(ll a, ll b, ll m)
{
	if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll d = div2mul_calc(a, b / 2, m);
        return (d * d) % m;
    } else {
        return (a * div2mul_calc(a, b - 1, m)) % m;
    }
}
ll div2mul(ll n, ll mod)
{
	return div2mul_calc(n, mod-2, mod);
}

ll twoRow(ll a, ll b, ll mod)
{
	ll ret = 1;
	for(ll i = 1 ;i <= a+b;++i)
	{
		ret *= i;
		ret %= mod;
	}
	for(ll i = 1 ;i <= a;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	for(ll i = 1 ;i <= b;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	return ret;
}

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

int main()
{
	priority_queue<int> p;
	vector<pair<int,int> > v;
	ll N,M;
	ll i,j,k;
	cin >> N >> M;
	for(i=0;i<N;++i)
	{
		cin>>j>>k;
		v.push_back(make_pair(j,k));
	}
	sort(v.begin(),v.end());
	j = 0;
	ll v_len = v.size();

	ll ans = 0;
	for(i=1;i<=M;++i)
	{
		while(j<v_len&&v[j].first<=i)
		{
			p.push(v[j].second);
			++j;
		}
		if(p.size() > 0)
		{
			ans += p.top();
			p.pop();
		}
	}
	cout << ans << endl;
	return 0;
}




















Measured memory_bytes: 1908
n = int(raw_input())
b = map(int, raw_input().split(' '))
def f(b):
	n = len(b)+1
	s = 0
	for i in range(n):  s += min(b[i] if i < n-1 else +float('inf'), b[i-1] if i-1>=0 else +float('inf'))
	return s
print f(b)


Measured memory_bytes: 28012
/*Code by Codercjh*/
#include<bits/stdc++.h>
#define fr(i,a,b) for(int i=(a);i<=(b);++i)
#define rf(i,a,b) for(int i=(a);i>=(b);--i)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
using namespace std;
typedef long long ll;
template<typename T>
inline void read(T &x){
	char c=getchar();T fh=0;bool f=false;
	while(!isdigit(c))f|=(c=='-'),c=getchar();
	while(isdigit(c))fh=(fh<<1)+(fh<<3)+(c^48),c=getchar();
	x=f?-fh:fh;
	return;
}
queue<ll> q;
int k;
int main(){
    read(k);
	fr(i,1,9)q.push(i);
	if(k<=9)return cout<<k,0;
	while(k){
		ll x=q.front();q.pop();--k;
		if(k==0)return cout<<x,0;
		if(x%10!=0)q.push(10*x+x%10-1);
		q.push(10*x+x%10);
		if(x%10!=9)q.push(10*x+x%10+1); 
	} 
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <cmath>

int prime(int number) {
    int s_num = sqrt(number);
    if (number == 2) {
        return 1; 
    } else if (number % 2 == 0) {
        return 0;
    }
    for (int i = 3; i <= s_num; i += 2) {
        if (number % i == 0) {
            return 0;
        }
    }
    return 1;
}

int main(void) {
    int number;
    int count = 0;
    int max = 1;

    std::vector<int> v(1000000, 0);

    while (std::cin >> number) {
        if (number > max) {
            for (int i = max + 1; i <= number; i++) {
                if (prime(i) == 1) {
                    count++;
                }
                v[i - 1] = count;
                max = number;
            }
        }
        std::cout << v[number - 1] << std::endl;
    }
    return 0;
}

Measured memory_bytes: 6552
#include <bits/stdc++.h>
int N,M,a;
int main(){
    std::cin >> N >> M;
    int k[++N]={},s[N]={1};
    while(M--)std::cin>>a,k[a]=1;
    s[1]=!k[1];
    for(a=2; a<N; a++)if(!k[a])s[a] = (s[a-1] + s[a-2])%1000000007;
    std::cout << s[N-1] << '\n';
}

Measured memory_bytes: 1024
import heapq
n,m=map(int,input().split())
item=list(map(lambda x: -int(x),input().split()))
heapq.heapify(item)

for i in range(m):
    top=-heapq.heappop(item)
    top //=2
    heapq.heappush(item,-top)

print(-sum(item))

Measured memory_bytes: 72216
main = do interact (\li -> (show $ (\x -> x / 6.283185307179586 * 360) $ ((\[a,b,x] -> atan(if x <= b/2 * (a^2) then ((a * b ^ 2) / ( 2 * x)) else ((2 * (b - (x / (a ^ 2)))) / a))) :: [Double] -> Double) $ ((map read $ words li) :: [Double])) ++ "\n")

Measured memory_bytes: 4288
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int a,b; cin>>a>>b;
    for(int i=-10000;i<=10000;i++){
        if((a+i)/2==b&&(a+i)%2==0){cout<<i<<endl; return 0;}
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,m;
  cin>>n>>m;
  vector<ll>id(n),be(n),de(n),po(n);
  rep(i,n){id[i]=i;cin>>be[i]>>de[i]>>po[i];}
  ll res=0;
  rep(i,8)
  {
    int wb=1,wd=1,wp=1;
    if(i&1)wb=-1;
    if(i&2)wd=-1;
    if(i&4)wp=-1;
    ll tres=0;
    vector<ll>bdp(n);
    rep(j,n)
    {
      bdp[j]=wb*be[j]+wd*de[j]+wp*po[j];
    }
    sort(all(bdp),greater<ll>());
    rep(j,m)tres+=bdp[j];
    chmax(res,tres);
  }
  cout<<res<<endl;

  return 0;

}


Measured memory_bytes: 256
N,W=(int(x) for x in input().split())
value=[]
weight=[]
for n in range(N):
    a,b=(int(x) for x in input().split())
    value.append(a)
    weight.append(b)
def knap(N,W,value,weight):
    dp=[[0]*(W+1) for _ in range(N+1)]
    for i in range(N+1):
        for w in range(W+1):
            if i>0:
                if weight[i-1]<=w:
                    dp[i][w]=max(dp[i-1][w],dp[i-1][w-weight[i-1]]+value[i-1])
                else:
                    dp[i][w]=dp[i-1][w]
    return dp[N][W]
print(knap(N,W,value,weight))



Measured memory_bytes: 25520
#include<stdio.h>
#include<string.h>
int main()
{

    int a;
    char str[80];
    scanf("%d",&a);
    scanf(" %[^\n]",str);
    if(a<3200){
        printf("red\n");

    }
    if(a>=3200){
        printf("%s\n",str);
    }
    return 0;
}


Measured memory_bytes: 128
from collections import Counter

def main():
    n = int(input())
    A = [int(e) for e in input().split()]

    Da = Counter(A)
    cnt = 0
    for v in Da.values():
        cnt += v*(v - 1)//2

    for i in range(n):
        print(cnt - (Da[A[i]] - 1))

if __name__ == "__main__":
    main()


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

int par[20000000]; //union-find
int ranks[20000000]; //union-find

void init(int n){ //union-find 初期化
    for(int i=0;i<n;i++){
        par[i]=i;
        ranks[i]=0;
    }
}

int find(int x){ //union-find 根を探す
    if(par[x]==x){
        return x;
    }
    else{
        return par[x]=find(par[x]);
    }
}

void unite(int x, int y){ //union-find グループの統合
    x=find(x);
    y=find(y);
    if(x==y) return;
    if(ranks[x]<ranks[y]){
        par[x]=y;
    }
    else{
        par[y]=x;
        if(ranks[x]==ranks[y]) ranks[x]++;
    }
}

bool same(int x, int y){ //union-find 同じかグループかどうか判定
    return find(x) == find(y);
}

int main(){
    int n,m;
    cin >> n >> m;
    int x[m],y[m];
    vector<int> v;
    map<int,int> mp;
    map<int,int> mp2;
    init(n);
    rep(i,n){
        int x;
        cin >> x;
        //v.push_back(x-1);
        mp.insert(make_pair(i,x-1));
        mp2.insert(make_pair(x-1,i));
    }

    rep(i,m){
        int xx,yy;
        cin >> xx >> yy;
        x[i]=xx-1;
        y[i]=yy-1;
        unite(x[i],y[i]);
    }
    int ans=0;
    
    rep(i,n){
        if(i!=mp.at(i)){
            if(same(i,mp2.at(i))){
                int save1=mp.at(i);
                int save2=mp2.at(i);
                mp.erase(i);
                mp.erase(save2);
                mp2.erase(save1);
                mp2.erase(i);
                mp.insert(make_pair(i,i));
                mp.insert(make_pair(save2,save1));
                mp2.insert(make_pair(i,i));
                mp2.insert(make_pair(save1,save2));
                ans++;
            }
        }
        else ans++;
    }

    cout << ans << endl;


}

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



int main(){
	int n,q;cin >> n;
	int a[n];
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	cin >> q;
	int b[q];
	int ans=0;
	for(int i=0;i<q;i++){
		cin >> b[i];
		for(int j=0;j<n;j++){
			if(b[i] == a[j]){
				ans++;
				break;
			}
		}
	}
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
long double X[200100];
int N;
long long Count(long double len)
{
  long long Ans=0;
  for(int i=0;i<N;i++)
  {
    Ans+=(long long)(X[i]/len);
    //Ans+= ceil(X[i]/len)-1;
  }
  return Ans;
}

int main()
	{
	  long long K;
	  cin>>N>>K;
	  for(int i=0;i<N;i++)
	{
		cin>>X[i];
		//X[i]-=0.1;
	}

  long double l=1,r=1e9;
  //while(l<r-0.1)//解答を引っ張ってきた人の条件。なぜかOKだったが、lとｒの整数部が異なる状態でループを出ると問題になるはず
	for(int i=0;i<35;i++)//OK log2(10^9)=30.二分探索だとこのやり方安定する。ただし、浮動小数のせいか34以上でないと通らず。
  //while(!((ceil(r)-ceil(l)) == 0))//NG:左端が初期値0のままだと、右端のceilは0にならず、無限ループ
	//while(!((floor(r)-floor(l)) == 0))//OK:右端がぴったり整数にならなければ成立.(あまりよくない)
  {
    long double mid=(l+r)/2;
    if(Count(mid)<=K) r=mid;
    else	l=mid;
  }
  cout<<(long long)(l+0.999)<<endl;
  return 0;
}

Measured memory_bytes: 6828
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
const int N = 305;
int pos[N], vis[N], a[N][N], cnt[N];
int n, m;

int dfs(int s){
  memset(cnt, 0, sizeof(cnt));
  int ans = 0, mpos = -1;
  for(int i = 0; i < n; i++){
    while(vis[a[i][pos[i]]]) pos[i]++;
    cnt[a[i][pos[i]]]++;
  }
  for(int i = 1; i <= m; i++)
    if(!vis[i] && cnt[i] > ans){
      ans = cnt[i];
      mpos = i;
    }
  vis[mpos] = 1;
  if(ans == ceil(1.0 * n / s))  return ans;
  else return min(ans, dfs(s-1));
}

int main()
{
  scanf("%d%d", &n, &m);
  for(int i = 0; i < n; i++)
    for(int j = 0; j < m; j++)
      scanf("%d", &a[i][j]);
  int ans = dfs(m);
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

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


        int i,j,t;
        String st;
   
        t = s.nextInt();
        for(i=0;i<t;i++){
            int[] num = new int[10];
            int[] g = new int[10],b =new int[10], r =new int[10];
            boolean ch=true;
            for(j=0;j<9;j++)num[j]=s.nextInt();
            for(j=0;j<9;j++){

                st = s.next();
                if(st.charAt(0)=='G')g[num[j]]++;
                else if(st.charAt(0)=='B')b[num[j]]++;
                else if(st.charAt(0)=='R')r[num[j]]++;
            }
            for(j=1;j<=9;j++){
                if(g[j]>=3)g[j]-=3;
                if(j<8&&g[j]==2&&g[j+1]>1&&g[j+2]>1){
                    g[j]-=2;
                    g[j+1]-=2;
                    g[j+2]-=2;
                }
                if(j<8&&g[j]==1&&g[j+1]>0&&g[j+2]>0){
                    g[j]--;
                    g[j+1]--;
                    g[j+2]--;
                }
                if(b[j]>=3)b[j]-=3;
                if(j<8&&b[j]==2&&b[j+1]>1&&b[j+2]>1){
                    b[j]-=2;
                    b[j+1]-=2;
                    b[j+2]-=2;
                }
                if(j<8&&b[j]==1&&b[j+1]>0&&b[j+2]>0){
                    b[j]--;
                    b[j+1]--;
                    b[j+2]--;
                }
                if(r[j]>=3)r[j]-=3;
                if(j<8&&g[j]==2&&r[j+1]>1&&r[j+2]>1){
                    r[j]-=2;
                    r[j+1]-=2;
                    r[j+2]-=2;
                }
                if(j<8&&r[j]==1&&r[j+1]>0&&r[j+2]>0){
                    r[j]--;
                    r[j+1]--;
                    r[j+2]--;
                }
                if(g[j]>0||b[j]>0||r[j]>0){
                    ch = false;
                    break;
                }   
            }
            if(ch==true)System.out.println(1);
            else System.out.println(0);
            for(j=0;j<=9;j++){
                g[j]=0;
                b[j]=0;
                r[j]=0;
                num[j]=0;
            }
            ch=true;
        }

    }
}


Measured memory_bytes: 28648
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

using P = pair<s64, s64>;

vector< vector< P > > g;

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

    int n, m, s;
    cin >> n >> m >> s;
    s = MIN(2500, s);

    g.resize(n * 2501);
    int u, v, a, b;
    rep (i, m)
    {
        cin >> u >> v >> a >> b;
        --u; --v;

        for (int j = 2499; j - a >= 0; --j)
        {
            g[j * n + u].emplace_back((j - a) * n + v, b);
            g[j * n + v].emplace_back((j - a) * n + u, b);
        }
        g[2500 * n + u].emplace_back(2500 * n + v, b);
        g[2500 * n + v].emplace_back(2500 * n + u, b);
    }

    rep (i, n)
    {
        s64 c, d;
        cin >> c >> d;
        rep (j, 2500)
        {
            g[j * n + i].emplace_back(MIN(2500, j + c) * n + i, d);
        }
    }

    vs64 d(n * 2501, 1e18);
    d[s * n + 0] = 0;
    vector< bool > reached(n * 2501, false);
    priority_queue< P > pq;
    pq.push(P{0, s * n + 0});
    while (!pq.empty())
    {
        P du = pq.top(); pq.pop();
        s64 dist = -du.first;
        int u = du.second;

        if (reached[u]) continue;
        reached[u] = true;

        for (auto v : g[u])
        {
            int to = v.first;
            s64 t = v.second;
            if (d[to] > dist + t)
            {
                pq.push(P{-(dist + t), to});
                d[to] = dist + t;
            }
        }
    }

    for (int t = 1; t < n; ++t)
    {
        s64 ans = 1e18;
        rep (i, 2501) ans = MIN(ans, d[n * i + t]);
        cout << ans << "\n";
    }
    return 0;
}



Measured memory_bytes: 23860
/*
 
*/
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <set>
#include <map>
#include <stack>
#include <deque>
 
#define ll long long
#define cint const int
#define ld long double
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
 
using namespace std;
 
typedef vector <long long> vll;
typedef vector <string> vs;
typedef vector <char> vc;
typedef set <int> si;
typedef set <string> ss;
typedef pair <int, int> pi;
typedef pair <long long, long long> pll;
typedef pair <int, long long> pil;
typedef pair <int, string> pis;
typedef pair <int, char> pic;
typedef pair <long long, int> pli;
typedef pair <long long, string> pls;
typedef pair <long long, char> plc;
typedef pair <string, int> psi;
typedef pair <string, long long> psl;
typedef pair <string, char> psc;
typedef pair <char, int> pci;
typedef pair <char, long long> pcl;
typedef pair <char, string> pcs;
 
string s;
 
int main () {
	cin >> s;
	int mn = 100000;
	for (int i = 0; i < sz(s) - 2; ++i) {
	    int n = (int(s[i + 2]) - 48) + ((int(s[i + 1]) - 48) * 10) + ((int(s[i]) - 48) * 100);
	    mn = min(mn, abs(753 - n));
	}
	cout << mn;
	return 0;
}

Measured memory_bytes: 256
S=input()

ans='NO'
if S.find('k')==0 and S.rfind('eyence')==len(S)-6:
    ans='YES'
elif S.find('ke')==0 and S.rfind('yence')==len(S)-5:
    ans='YES'
elif S.find('key')==0 and S.rfind('ence')==len(S)-4:
    ans='YES'
elif S.find('keye')==0 and S.rfind('nce')==len(S)-3:
    ans='YES'
elif S.find('keyen')==0 and S.rfind('ce')==len(S)-2:
    ans='YES'
elif S.find('keyenc')==0 and S.rfind('e')==len(S)-1:
    ans='YES'

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll factorial(ll n) {
    ll x = 1;
    for (int i = 1; i <= n; i++) {
        // x = x * i;
        x = x * i % 1000000007;
    }
    return x;
}

int main() {
    ll n, m;
    cin >> n >> m;
    if (n == m) {
        ll x = factorial(n);
        ll ans = x * x * 2 % 1000000007;
        cout << ans << endl;
    } else if (n == m + 1 || n + 1 == m) {
        ll ans = factorial(n) * factorial(m) % 1000000007;
        cout << ans << endl;
    } else {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 384
package main

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

func main() {
	H := readInt()
	N := readInt()
	AB := make([]struct{ A, B int }, N)
	for i := 0; i < N; i++ {
		AB[i].A = readInt()
		AB[i].B = readInt()
	}

	x := H + 10000 + 1
	dp := make([]int, x)
	for i := 0; i < x; i++ {
		dp[i] = math.MaxInt64
	}

	dp[0] = 0
	for i := 0; i < H; i++ {
		if dp[i] == math.MaxInt64 {
			continue
		}
		for j := 0; j < N; j++ {
			a := AB[j].A
			b := AB[j].B
			if dp[i]+b < dp[i+a] {
				dp[i+a] = dp[i] + b
			}
		}
	}

	result := math.MaxInt64
	for i := H; i < x; i++ {
		if dp[i] < result {
			result = dp[i]
		}
	}
	fmt.Println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


Measured memory_bytes: 896
#include <iostream>

using namespace std;

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


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

using namespace std;

////////////////////////////////////////////////////////////////////////////////////////////////////
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define wt(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define wt(x...)
#endif
/////////////////////////////////////////////////////////////////////////////////////////////////


#define LL long long
const int MAXN = 212345;
const int INF  = 0x3f3f3f3f;

int S (int x) {
	int s = 0;
	
	while (x > 0) {
		s += x % 10;
		x /= 10;
	}

	return s;
}


int main () {

	int N;
	scanf("%d", &N);

	int s = S(N);

	printf("%s\n", (N % s == 0) ? "Yes" : "No" );

	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split()]
q = int(input())
hako = [0]*(10**6)
ind = list(range(10**6))
S = sum(a)
s = []

for i in a:
    hako[i] += 1

for i in range(q):
    b, c = [int(i) for i in input().split()]
    S += (ind[c] - ind[b])*hako[b]
    s.append(S)
    hako[c] += hako[b]
    hako[b] = 0
for i in range(q):
    print(s[i])

Measured memory_bytes: 65888
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>
#include<limits>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main(){
  int n;
  cin>>n;
  VI a(n);
  rep(i,n) cin>>a[i];

  bool flag=true;
  rep(i,n){
    if(a[i]%2==0){
      if(a[i]%3!=0 && a[i]%5!=0){
         flag=false;
      }
    }
  }

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

Measured memory_bytes: 256
#include<stdio.h>
int asc(const void *a,const void *b){
  return *(int *)a- *(int *)b;
}
int main(){
  int max=0,i,n,a[111];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    max+=a[i];
  }
  if(max%10==0){
    qsort(a,n,sizeof(int),asc);
    for(i=0;i<n;i++){
      if((max-a[i])%10!=0){
        max-=a[i];
        break;
      }
    }
    if(i==n)max=0;
  }
  printf("%d\n",max);
  return 0;
}


Measured memory_bytes: 128
H,W,K = list(map(int,input().split()))
C = [list(input()) for _ in range(H)]

def F1(c):
    for i in range(W):
        for j in range(H-1,-1,-1):
            if c[j][i] != 'X': continue
            for k in range(j-1,-1,-1):
                if c[k][i] != 'X':
                    c[j][i], c[k][i] = c[k][i], c[j][i]
                    break
    return c

def F2(c):
    delete_sum = 0
    for i in range(H):
        for j in range(W):
            if c[i][j] == 'X': continue
            tmp = c[i][j]
            count = 1
            for k in range(j+1,W):
                if c[i][k] == tmp:
                    count += 1
                else:
                    break
            if count >= K:
                for k in range(j,W):
                    if c[i][k] == tmp:
                        delete_sum += int(c[i][k])
                        c[i][k] = 'X'
                    else:
                        break
    return c, delete_sum

MAX = 0
for i in range(H):
    for j in range(W):
        tmpC = []
        for k in range(H):
            tmpC.append(C[k][:])
        tmpC[i][j] = 'X'
        tmpC = F1(tmpC)
        point = 0
        for k in range(1000):
            tmpC, delete_sum = F2(tmpC)
            if delete_sum == 0:
                break
            tmpC = F1(tmpC)
            point += 2**k*delete_sum
        MAX = max(MAX,point)
print(MAX)


Measured memory_bytes: 74988
#include<bits/stdc++.h>
# define  _deb(x) { cerr << "\033[94m"<< "[ " << #x << " = " << (x) << " ]\n\033[0m"; }
using namespace std;
#define int long long
const int xx = 2e5+10;
vector<int>g[xx];
int cost[xx];
int vis[xx];
void bfs(int s){
	vis[s] = 1;
	queue<int>q;
	q.push(s);
	while(!q.empty()) {
		int u = q.front();
		q.pop();
		for(auto v: g[u]){
			if(!vis[v]){
				cost[v] = cost[v] + cost[u];
				vis[v] = 1;
				q.push(v);
			}
		}
	}
}
signed main(){
	int n,q;
	cin >> n >> q;
	for(int i=0;i<n-1;i++){
		int u,v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	for(int i=0;i<q;i++){
		int u,w;
		cin >> u >> w;
		cost[u] += w;
	}
	bfs(1);
	for(int i=1;i<=n;i++){
		if(i==n) cout<<cost[i]<<'\n';
		else{
			cout << cost[i]<<" ";
		}
	}
}
	

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

typedef long long ll;
typedef pair<int, int> pi;

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep_op(i, a, n) for (int i = a; i < n; i++)
#define rep_d(j, n) for (int j = n; j >= 0; j--)
#define rep_d_op(j, n, a) for (int j = n; j >= a; j--)

template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}

const int MOD = 1000000007;

const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};
const ll INF = 1LL << 60;

// int max = *std::max_element(vec.begin(), vec.end());
// int sum = accumulate(list, list + size, 0);

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

bool is_prime(int x)
{
    if (x <= 1)
    {
        return false;
    }
    for (int i = 2; i * i <= x; i++)
    {
        if (x % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    int a, b, m;
    cin >> a >> b >> m;
    vector<int> A(a);
    rep(i, a) cin >> A[i];
    vector<int> B(b);
    rep(i, b) cin >> B[i];

    int min_a = *min_element(A.begin(), A.end());
    int min_b = *min_element(B.begin(), B.end());

    int ans = min_a + min_b;

    rep(i, m)
    {
        int x, y, c;
        cin >> x >> y >> c;
        ans = min(ans, A[x - 1] + B[y - 1] - c);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
s = input()
siro = 0
kuro = 0
for i in range(len(s)):
	if i%2 == 0:
		if s[i] == '0':
			kuro += 1
		if s[i] == '1':
			siro += 1
	if i%2 ==1:
		if s[i] == '0':
			siro += 1
		if s[i] == '1':
			kuro += 1
print(min(siro,kuro))
		

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main () {
	int a,b,ans=0;
	cin>>a>>b;
	for (int i=0;i<a;i++) {
		int c;
		cin>>c;
		if (c>=b) {
			ans++;
		}
	}
	cout<<ans;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B;
  cin >> A >> B;
  if ((A == 1 && B == 2) || (A == 2 && B == 1)) {
    cout << 3 << endl;
  }
  else if ((A == 1 && B == 3) || (A == 3 && B == 1)) {
    cout << 2 << endl;
  }
  else {
    cout << 1 << endl;
  }
}

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

int main(){
    int a,b,k;
    cin >> a >> b >> k;
    if (b-a+1 <= 2*k){
        for (int i = a;i <= b;i++){
            cout << i << endl;
        }
    }
    else{
            for (int i = a;i < a+k;i++){
                cout << i << endl;
            }
            for (int i = b-k+1;i <= b;i++){
                cout << i << endl;
            }
    }
}

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



void swap (int *x, int *y) {
  int temp;

  temp = *x;
  *x = *y;
  *y = temp;

  return;
}

int gcd(int a,int b){
  if(a<b){
    swap(&a,&b);
  }

  if(b==0){
    return a;
  }

  int r=a%b;
  while(r!=0){
    a = b;
    b = r;
    r = (a%b);
  }

  return b;
}

/* クイックソート */
int dn(const void*a,const void*b){return*(int*)b-*(int*)a;}


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

int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}

int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}

void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }

  return;
}

void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }

  return;
}

/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/

int main(void){
  int d,t,s;
  scanf("%d%d%d",&d,&t,&s);

  /*
  
  分数で表した解答は切り捨ての関係で落ちる

  今回の問題は大丈夫だけど，小数は誤差が怖いから基本的に使わないほうがいい

  */

  if(d<=t*s){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }

  return 0;
}

Measured memory_bytes: 1588
#include<bits/stdc++.h>
#define M 1000000007
using namespace std;
typedef long long int ll;
int main()
{
   int n;
   cin>>n;
   ll arr[n];
   for(int i=0;i<n;i++)
    cin>>arr[i];
   ll tot=0,prev=arr[0];
   for(int i=1;i<n;i++)
   {
       tot = ((tot)%M+ (prev*arr[i])%M)%M;
       prev = (prev+arr[i])%M;
   }
   cout<<tot%M<<endl;
}


Measured memory_bytes: 5172
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
    int a;
    int b;
    int d;
    int r;
    
    cin >> a >>b;
    
    double f;
    
    d = a / b;
    r = a % b;
    f = 1.0 * a / b;
    
    printf("%d %d %.5lf\n",d,r,f);
    
    return 0;
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int how_two(int n)
{
	int res = 0;
	while(n%2==0)
	{
		res ++;
		n/=2;
	}
	return res;
}

int main()
{
	int n;
	cin >> n;
	ll ans = 0;
	for(int i = 0;i<n;++i)
	{
		int x;
		cin >> x;
		ans += how_two(x);
	}
	cout<<ans<<endl;
	return 0;
}

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

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

using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;

const int INF = 1001001001;
const int MOD = 1000000007;
const long long INFL = (1LL << 60);
const double EPS = 1e-9;

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

  int res = 0;
  rep(i, N - 2) {
    if (s.substr(i, 3) == "ABC") res++;
  }

  cout << res << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Security.Principal;
using System.Text;
class Simple {
    private int N, H;
    private int[] a, b;
    void Solve() {
        //input
        N = io.Int;
        H = io.Int;
        a = new int[N];
        b = new int[N];
        for(int i = 0; i < N; ++i) {
            a[i] = io.Int;
            b[i] = io.Int;
        }
        //cal
        Array.Sort(b);
        long sum = 0;
        long cnt = 0;
        long maxA = a.Max();
        for(int i = N - 1; i >= 0 && sum < H && maxA < b[i]; i--) {
            sum += b[i];
            cnt++;
        }
        if(sum < H) {
            var shortage = H - sum;
            if(shortage % maxA == 0) cnt += shortage / maxA;
            else cnt += shortage / maxA + 1;
        }
        //ret
        Console.WriteLine(cnt);
    }
    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) { new Simple().Stream(); }
    void Stream() {
        Solve();
        io.writeFlush();
    }
}
class SimpleIO {
    string[] nextBuffer;
    int BufferCnt;
    char[] cs = new char[] {' '};
    StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
    public SimpleIO() {
        nextBuffer = new string[0];
        BufferCnt = 0;
        Console.SetOut(sw);
    }
    public string Next() {
        if(BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++];
        string st = Console.ReadLine();
        while(st == "") st = Console.ReadLine();
        nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        BufferCnt = 0;
        return nextBuffer[BufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void writeFlush() { Console.Out.Flush(); }
}

Measured memory_bytes: 17448
import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline
def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')
#import numpy as np

from itertools import permutations
from math import factorial

def main():
	n=II()
	li=[TI() for _ in range(n)]
	ans=0
	for p in permutations(range(n),n):
		tmp=0
		px=py=1001
		for i in p:
			x,y=li[i][0],li[i][1]
			if px==1001:
				px,py=x,y
			else:
				tmp+=((px-x)**2+(py-y)**2)**0.5
				px,py=x,y
		ans+=tmp

	ans/=factorial(n)
	print(ans)

if __name__ == "__main__":
	main()


Measured memory_bytes: 40432
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main() {
    int n;
    cin >> n;
    vector<vector<ll> > a(n, vector<ll>(n));
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin >> a[i][j];
        }
    }
    vector<ll> sum(1<<n), dp(1<<n);
    for(int S=1;S<1<<n;S++){
        for(int i=0;i<n;i++){
            if(((S>>i)&1) != 1) continue;
            for(int j=i+1;j<n;j++){
                if((S>>j)&1){
                    sum[S] += a[i][j];
                }
            }
        }
    }
    for(int i=1;i<1<<n;i++) dp[i] = sum[i];
    for(int S=1;S<1<<n;S++){
        for(int T=S;T>0;T=(T-1)&S){
            dp[S] = max(dp[S], dp[T]+dp[S^T]);
        }
    }
    cout << dp[(1<<n)-1] << endl;
    return 0;
}


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

int main() {
	int n,min=9999999,max=-1000000,su;
	long long sum=0;
	
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>su;
		if(su<min) min=su;
		if(su>max) max=su;
		sum+=su;
	}
	cout<<min<<" "<<max<<" "<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3104
#%%
inf = 10**9 + 7

n = int(input())
a = list(map(int, input().split()))
count = [0] * 70
for i in range(n):
    tmp = list(str(bin(a[i])[2:]))[::-1]
    #print(tmp)
    for j in range(len(tmp)):
        if tmp[j] == '1':
            k = 69 - j
            count[k] += 1

#print(count)

ans = 0
for i in range(70):
    k = 2 ** (69 - i)
    k %= inf
    x = count[i] % inf
    y = (n - x) % inf
    ans += (x * y * k) % inf
    ans %= inf

ans %= inf
print(ans)



# %%


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

int main(){
  int k, s; cin >> k >> s;
  int ans = 0;
  
  for(int i = 0; i <= k; i++){
  for(int j = 0; j <= k; j++){
  
  if(s-i-j>=0 && s-i-j<=k) ans++;
  }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

int ans;
string s;
int K;
ll dp[105][4][2];

int main(void) {
    cin >> s;
    scanf("%d", &K);
    int n = (int)s.size();


    ll x = s[0] - '0'; 
    dp[0][1][0] = 1;
    if (x > 1) dp[0][1][1] = x-1;
    dp[0][0][1] =1;
    
    rep(i, 1, n) {
        if (s[i] == '0') rep(j, 1, 4) dp[i][j][0] = dp[i-1][j][0];
        else {
            rep(j, 2, 4) {
                dp[i][j][0] = dp[i-1][j-1][0];
            }
        }
    }

    rep(i, 1, n) {
        ll d = s[i] - '0';
        dp[i][0][1] = 1;
        rep(j, 1, 4) {
            dp[i][j][1] += dp[i-1][j-1][1]*9 + dp[i-1][j][1];
            if (d > 0) dp[i][j][1] += dp[i-1][j-1][0] * (d-1) + dp[i-1][j][0];
        }
    }

    printf("%lld\n", dp[n-1][K][0]+dp[n-1][K][1]);

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int A, B, N;
	cin >> N >> A >> B;
	if (N == 1)
	{
		if (A == B)
			printf("1\n");
		else
			printf("0\n");
	}
	else
	{
		if (A > B)
			printf("0\n");
		else
			printf("%lld\n", (long long)(B - A)*(N - 2) + 1);
	}
	return 0;
}

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

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> x(m), y(m-1);
  rep(i, m) cin >> x[i];
  sort(x.begin(), x.end());
  rep(i, m-1) y[i] = x[i+1] - x[i];
  sort(y.begin(), y.end());
  int l = max(0, m-n);
  int ans = 0;
  rep(i, l) ans += y[i];
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 4028
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int Total,Task,a,sum=0;
    cin>>Total>>Task;
    while(Task--)
    {
        cin>>a;
        sum+=a;
    }
    if(Total-sum<0)
    {
        cout<<"-1"<<endl;
    }
    else
    {
        cout<<Total-sum<<endl;
    }
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

int main() {
    cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(20);

    ll N; cin >> N;
    vpll v1, v2;
    rep(i, N) {
        ll a, b;
        cin >> a >> b;
        v1.emplace_back(a, b);
        v2.emplace_back(b, a);
    }
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());

    ll ans;
    if(N % 2 == 1) {
        ans = v2[(N-1)/2].first - v1[(N-1)/2].first + 1;
    }
    else {
        ans = v2[N/2].first + v2[N/2-1].first - v1[N/2].first - v1[N/2-1].first + 1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 9800
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

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

	int n, i, j, k, x, ans;
	set<int> a, b;
	vector<int> c;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> x;
		if (i % 2 == 0) a.insert(x);
		c.push_back(x);
	}
	sort(c.begin(), c.end());

	ans = 0;
	for (i = 1; i < n; i+=2) {
		if (a.find(c[i]) != a.end()) {
			ans++;
		}
	}
	cout << ans << "\n";


	return 0;
}



Measured memory_bytes: 2936