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

#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

pair<int,int> factor(string s, int i) {
  int num = s[i] - '0';
  while(++i < s.size() && s[i] == '*') {
    num *= s[++i] - '0';
  }
  return make_pair(num, i);
}

int expr(string s) {
  int num, i;
  tie(num, i) = factor(s, 0);
  while(i < s.size()) {
    int p, j;
    tie(p, j) = factor(s, i+1);
    num += p;
    i = j;
  }
  return num;
}

int expr2(string s) {
  int i = 0;
  int num = s[i] - '0';
  while(++i < s.size()) {
    if (s[i] == '*')
      num *= s[++i] - '0';
    else
      num += s[++i] - '0';
  }
  return num;
}

int main() {
  string s;
  cin>>s;
  int ans;
  cin>>ans;
  int bob = expr2(s);
  int calc = expr(s);
  if (ans == bob) {
    if (ans == calc) {
      cout << 'U' << endl;
    } else {
      cout << 'L' << endl;
    }
  } else {
    if (ans == calc) {
      cout << 'M' << endl;
    } else {
      cout << 'I' << endl;
    }
  }
  return 0;
}

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

int pow2(int x, int n) {
  if (n == 0) return 1;
  if (n == 1) return x;
  int res = 1;
  for (int i = 0; i < 31; i++) {
    if (n >> i & 1) res *= pow(x, pow(2, i));    
  }
  return res;
}

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

  int n;
  cin >> n;
  cout << pow2(2, floor(log2(n))) << '\n';
  return 0;
}

Measured memory_bytes: 256
using ll=long long;using ull=unsigned long long;
#include<limits>
namespace pcl{template<typename T>constexpr T TNF=std::numeric_limits<T>::max()/2;constexpr int INF=TNF<int>;constexpr ll LNF=TNF<ll>;constexpr double DNF=TNF<double>;constexpr double EPS=1e-8;constexpr int P7=1'000'000'007;constexpr int DX[]={1,0,-1,0,1,1,-1,-1};constexpr int DY[]={0,1,0,-1,-1,1,1,-1};}
#include<algorithm>
#include<cmath>
#include<iostream>
namespace pcl{template<typename T>void updmax(T&a,T const&b){a=std::max(a,b);}template<typename T>void updmin(T&a,T const&b){a=std::min(a,b);}template<typename T,typename U,typename V>bool in_range(T const&begin,U const&mid,V const&end){return begin<=mid&&mid<end;}template<typename T,typename U,typename V>bool in_range(T const&begin,std::initializer_list<U>list,V const&end){auto p=std::minmax_element(list.begin(),list.end());return begin<=*p.first&&*p.second<end;}template<typename T,typename U,typename V>bool in_range_strict(T const&begin,std::initializer_list<U>list,V const&end){if(!std::is_sorted(list.begin(),list.end()))return false;return in_range(begin,list,end);}template<typename T>inline T cget(){T x;std::cin>>x;return x;}}
#include<iostream>
#include<vector>
namespace pcl{template<typename T>std::ostream&operator<<(std::ostream&os,std::vector<T>const&v){os<<'[';for(size_t i=0;i<v.size();i++){if(i!=0)os<<",";os<<v[i];}os<<']';return os;}template<typename T>std::istream&operator>>(std::istream&is,std::vector<T>&v){for(size_t i=0;i<v.size();i++)is>>v[i];return is;}}
#include<bits/stdc++.h>
using namespace std;using namespace pcl;int main(){int N;cin>>N;vector<pair<ll,ll>>AB(N);for(int i=0;i<N;i++){cin>>AB[i].second>>AB[i].first;}sort(AB.begin(),AB.end());ll curr=0;int i=0;for(;i<N;i++){curr+=AB[i].second;if(curr>AB[i].first)break;}if(i==N){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}}


Measured memory_bytes: 3328
# -*- coding: utf-8 -*-

import sys

def main():
    input = sys.stdin.readline
    n,m = map(int, input().split())
    x_list = list(map(int, input().split()))
    if n >= m:
        print(0)
        exit(0)
    sabun_list = []
    x_list.sort()
    for i,x in  enumerate(x_list):
        if i == 0:
            continue
        sabun_list.append(x - x_list[i-1])
    result = 0
    sum_max_sabun = 0
    sabun_list.sort(reverse=True)
    sum_max_sabun = sum(sabun_list[:n-1])
    
    result = (x_list[-1] - x_list[0]) - sum_max_sabun

    print(result)

    return


if __name__ == '__main__':
    main()

Measured memory_bytes: 19964
def solve(bi, ei, bs):
    mid = (bi+ei)//2
    print(mid, flush=True)
    s = input()
    if s=='Vacant':
        exit(0)
    elif (s==bs)^((mid-bi)%2):
        solve(mid, ei, s)
    else:
        solve(bi, mid, bs)

n = int(input())
print(0, flush=True)
s = input()
if s=='Vacant':
    exit(0)
solve(0, n, s)

Measured memory_bytes: 3660
import sys

# sys.stdin = open('b1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    n, k = read_int_list()
    l = read_int_list()
    l.sort()
    res = sum([i for i in l[-k:]])
    print(res)


main()


Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include <time.h>
typedef long long ll;
typedef long double ld;
#define INF (1LL<<60)
#define MOD1 1000000007
/*swap 交換*/
void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
/*2つのうち大きい数を返す*/
ll max2(ll a,ll b){return a>=b?a:b;}
/*2つのうち小さい数を返す*/
ll min2(ll a,ll b){return a>=b?b:a;}
/*絶対値*/
ll ABS(ll a){return a>=0?a:(-a);}
typedef struct{
    ll aa;
    ll bb;
}frequent;
// 小大
int compare(const void *a, const void *b){
    return *(ll *)a>*(ll *)b?1:*(ll *)a<*(ll *)b?-1:0;}
ll digits(ll a, ll b){return a/b?1+digits(a/b,b):1;}
/*nをa進数にしたときの、i桁目の数*/
ll placenai(ll n, ll a, ll i){return i==1?n%a:placenai(n/a,a,i-1);}
ll power2(ll n, ll mod){
    ll i,a[digits(n,2)],ans=1;
    for(i=0;i<digits(n,2);i++){
        if(i==0) a[i]=2;
        else a[i]=a[i-1]*a[i-1]%mod;
        ans*=placenai(n,2,i+1)==1?a[i]:1;
        ans%=mod;
    }
    return ans;
}
ll modfac(ll n, ll mod){
    if(n==1||n==0) return 1;
    ll i,x=1;
    for(i=2;i<=n;i++){
        x*=i%mod;
        x%=mod;
    }
    return x;
}
ll inv[200005],finv[200005];
void makeinv(){
    inv[1]=1;
    finv[0] = finv[1] = 1;
    ll i;
    for(i=2;i<200005;i++){
        inv[i]=MOD1 - inv[MOD1%i] * (MOD1 / i) % MOD1;
        finv[i] = finv[i - 1] * inv[i] % MOD1;
    }
}

int main(void){
    ll n,a,b,i,ans=0,ra,rb,x=1;
    scanf("%lld%lld%lld",&n,&a,&b);
    makeinv();
    for(i=1;i<=b;i++){
        x*=(n-i+1)%MOD1;
        x%=MOD1;
        if(i==a) ra=x;
        if(i==b) rb=x;
    }
    // printf("%lld? %lld %lld ",rb,finv[a],finv[b]);
    ra*=finv[a];
    rb*=finv[b];
    ra%=MOD1;
    rb%=MOD1;
    ans=power2(n,MOD1)-ra-rb-1;
    while(ans<0) ans+=MOD1;
    // printf("%lld %lld %lld ",power2(n,MOD1),ra,rb);
    printf("%lld\n",ans%MOD1);
    return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define ll long long
string s;
ll num,t=1,ans;
ll cnt[2200];
int main()
{
	cnt[0]=1;
	cin>>s;
	for(int i=s.size()-1;i>=0;i--)
	{
		num=(num+(s[i]-'0')*t)%2019;
	    ans+=cnt[num];
	    cnt[num]++;
	    t=t*10%2019;
	}
	cout<<ans;
    return 0;
}


Measured memory_bytes: 3752
#include<iostream>
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>

using namespace std;

class Counting {
	unsigned long long p, n;
	vector<long long> invMemo, facMemo, facInvMemo;
public:
	Counting(unsigned long long nn, unsigned long long np) {
		p = np;
		n = nn;
		invMemo.resize(n + 1);
		facMemo.resize(n + 1);
		facInvMemo.resize(n + 1);
		facMemo[0] = 1;
		facMemo[1] = 1;
		facInvMemo[0] = 1;
		facInvMemo[1] = 1;
		invMemo[0] = 0;
		invMemo[1] = 1;
		for (unsigned long long i = 2; i <= n; i++) {
			invMemo[i] = p - (p / i)*invMemo[p%i] % p;
			facMemo[i] = (facMemo[i - 1] * i) % p;
			facInvMemo[i] = (facInvMemo[i - 1] * invMemo[i]) % p;
		}
	}
	unsigned long long fac(unsigned long long k) {
		return facMemo[k];
	}
	unsigned long long facInv(unsigned long long k) {
		return facInvMemo[k];
	}
	unsigned long long choose(unsigned long long n, unsigned long long k) {
		if (!(0 <= k && k <= n))
			return 0;
		return (((facMemo[n] * facInvMemo[k]) % p)*facMemo[n - k]) % p;
	}
	unsigned long long divide(unsigned long long a, unsigned long long b) {
		return (a * invMemo[b]) % p;
	}
	unsigned long long mod(unsigned long long a) {
		a %= p;
		if (a < 0) a += p;
		return a;
	}
	unsigned long long power(unsigned long long a, unsigned long long e) {
		unsigned long long ans = 1;
		for (; e > 0; e /= 2) {
			if (e % 2 != 0)
				ans = ans * a % p;
			a = a*a%p;
		}
		return ans;
	}
};

int sx, sy, tx, ty;
string ans;

string go(int x, int y, int x2, int y2) {
	string a;
	for (int i = 0; i < x2 - x; i++) {
		a += 'R';
	}
	for (int i = 0; i < y2 - y; i++)
		a += 'U';
	return a;
}

string back(int x, int y, int x2, int y2) {
	string a;
	for (int i = 0; i < -x2 + x; i++) {
		a += 'L';
	}
	for (int i = 0; i < -y2 + y; i++)
		a += 'D';
	return a;
}

int main() {
	cin >> sx >> sy >> tx >> ty;
	ans += go(sx, sy, tx, ty);
	ans += back(tx, ty, sx, sy);
	ans += 'D';
	ans += go(sx, sy - 1, tx + 1, ty);
	ans += 'L';
	ans += 'U';
	ans += back(tx, ty + 1, sx - 1, sy);
	ans += 'R';
	cout << ans << endl;
	cin >> sx;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
/**
******************* Author:Bisnu sarkar ****************************
**/
/*
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/
#define fRead(x)       freopen(x,"r",stdin)
#define fWrite(x)      freopen (x,"w",stdout)
#define ull            unsigned long long
#define ll             long long
#define pii            pair<int,int>
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second
#define endl           '\n';
#define sz(s)          (int)s.size()
#define all(s)         s.begin(),s.end()
#define IO             ios_base::sync_with_stdio(false),cin.tie(NULL);
#define what_is(x)     cerr << #x << " is " << x << endl;
///*....Debugger....*///
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << ", ";
  err(++it, args...);
}
///*....Input....*///
template <typename T> inline void Int(T &n) {
  n = 0; int f = 1; register int ch = getchar();
  for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
  n = n * f;
}

template <typename T, typename TT> inline void Int(T &n, TT &m) { Int(n); Int(m); }
template <typename T, typename TT, typename TTT> inline void Int(T &n, TT &m, TTT &l) { Int(n, m); Int(l);}
double ind() {double x; scanf("%lf", &x); return x;}

///*....Bitmask....*///
int set_1(int n, int pos) {return n = (n | (1 << pos));}
int reset_0(int n, int pos) {return n = n & ~(1 << pos);}
bool check_bit(int n, int pos) {return n = n & (1 << pos);}

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

///*....Constraints....*///
const int N = (int) 1e6 + 5;
const int M = (int) 1e9 + 7;
const double pi = 2 * acos(0.0);
const double eps = 1e-9;


int main()
{
  ll t = 1;

  ll a, w, b, h;
  Int(a, w);
  Int(b, h);
  Int(t);

  if(a>b){
    a = a - w*t;
    b = b - h*t;

    if(a<=b)printf("YES\n");
    else{
      printf("NO\n");
    }
  }
  else if (w < h)printf("NO\n");
  else if (w == h) {
    if (a == b)printf("YES\n");
    else {
      printf("NO\n");
    }
  }
  else {
    a = a + t * w;
    b = b + t * h;

    if (a >= b) {
      printf("YES\n");
    }
    else {
      printf("NO\n");
    }
  }

  //printf("Case %d: ",++te);

  return 0;
}






Measured memory_bytes: 3620
import sys,math
sys.setrecursionlimit(10**9)
from collections import defaultdict
 
IA = lambda: map(int,input().split())
IAS= lambda: map(str,input().split())


L, n=IA()
a=list(IA())
a.sort()
cha=[0 for i in range(n)]

cha[0]=a[0]+L-a[n-1]

summ=cha[0]
maxx=cha[0]

for i in range(1,n):
    cha[i]=a[i]-a[i-1]
    summ+=cha[i]
    maxx=max(cha[i],maxx)

print(summ-maxx)


Measured memory_bytes: 86348
#include <stdio.h>

int main(){
   char res[16];
   int flag = 0;
   scanf("%s",res);
   for(int i = 0; i < 15; i++){
      if(res[i] == 'o'){
         //printf("%c\n",res[i]);
         flag++;
      }else if(res[i] == 'x'){
      }else{
         flag++;
      }
   }

   if(flag >= 8){
      printf("YES\n");
   }else{
      printf("NO\n");
   }
   return 0;
}

Measured memory_bytes: 128
package main

import "fmt"

func main() {
	var a, b, c, d, e, k int
	fmt.Scanln(&a)
	fmt.Scanln(&b)
	fmt.Scanln(&c)
	fmt.Scanln(&d)
	fmt.Scanln(&e)
	fmt.Scanln(&k)

	if e-a > k {
		fmt.Println(":(")
	} else {
		fmt.Println("Yay!")
	}
}


Measured memory_bytes: 512
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p){ os << "(" << p.first << ", " <<  p.second << ")"; return os; }

using namespace std;

void solve(long long N, std::string S){
    char last = '#';
    int ans = 0;
    REP(i, N) {
        if (S[i] != last) ans++;
        last = S[i];
    }
    cout << ans << endl;
}

// Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 512
/*input
4 3
###
###
...
###

*/
/*

  ####   #    #    ##    #####    ####           #    #
 #       #    #   #  #   #    #  #    #          #    #
  ####   ######  #    #  #    #  #    #          #    #
      #  #    #  ######  #    #  #    #          # ## #
 #    #  #    #  #    #  #    #  #    #          ##  ##
  ####   #    #  #    #  #####    ####  #######  #    #

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rep(i,m,n)	for(lld i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
using namespace std;
#define N  405
lld cntw=0,cntb=0;
bool vis[N][N];
lld h,w;
lld a[N][N];
void init()
{
	rep(i,0,N)
	{
		rep(j,0,N)
		{
			vis[i][j]=false;
		}
	}
}
void dfs(lld x,lld y)
{
	if(x>=h || y>=w || vis[x][y]==true || x<0 || y<0)
	{
		return ;
	}
	if(a[x][y]==1)
	{
		cntw++;
	}
	else
	{
		cntb++;
	}
	vis[x][y]=true;
	if(a[x+1][y]!=a[x][y])
	{
		dfs(x+1,y);
	}
	if(a[x-1][y]!=a[x][y])
	{
		dfs(x-1,y);
	}
	if(a[x][y+1]!=a[x][y])
	{
		dfs(x,y+1);
	}
	if(a[x][y-1]!=a[x][y])
	{
		dfs(x,y-1);
	}
}
inline void solve()
{
	init();
	cin>>h>>w;
	rep(i,0,h)
	{
		rep(j,0,w)
		{
			char x;
			cin >> x;
			if(x=='.')
			{
				a[i][j]=0;
			}
			else
			{
				a[i][j]=1;
			}
		}
	}
	lld ans=0;
	rep(i,0,h)
	{
		rep(j,0,w)
		{
			if(vis[i][j]==false && a[i][j]==1)
			{
				cntb=0;
				cntw=0;
				dfs(i,j);
				ans+=(cntb*cntw);
			}
		}
	}
	cout << ans << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	//cin>>tests;
	while(tests--)
	{
		solve();
	}
}

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

tako_list = list(map(int, input().split()))
tako_len = len(tako_list)

sum = 0

for i in range(0, n - 1) :
    for j in range(1, tako_len - i) :
        sum += tako_list[i] * tako_list[i + j]

print(sum)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int x, y;
    if(a % d == 0) x = a / d;
    else x = a / d + 1;
    if(c % b == 0) y = c / b;
    else y = c / b + 1;
    if(x >= y) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int x[4] = {-1,0,1,0};
int y[4] = {0,1,0,-1};
queue<P> q;
char c[1100][1100];
int b[1100][1100];
int h,w,ch,dh,cw,dw;
int main(){    
    cin >> h >> w;
    cin >> ch >> cw >> dh >> dw;
    for(int i = 1;i<=h;i++){
        for(int j = 1;j<=w;j++){
            cin >> c[i][j];
        }
    }
    //memset(b,-1,sizeof(b));
    q.push(make_pair(ch,cw));
    for(int i = 1;i<=h;i++){
        for(int j = 1;j<=w;j++){
            b[i][j] = -1;
        }
    }
    b[ch][cw] = 0;
    vector<vector<P> >v(1000010);
    v[0].push_back(make_pair(ch,cw));
    int now;
    while(1){
        int cnt = 0;
        while(!q.empty()){
            P tmp = q.front();
            q.pop();
            int dx = tmp.first;
            int dy = tmp.second;
            now = b[dx][dy];
            // if(dx == dh && dy == dw){
            //     cout << b[dh][dw] << endl;
            //     return 0;
            // }
            for(int i = 0;i<4;i++){
                int xx = dx  + x[i];
                int yy = dy  + y[i];
                if(xx >= 1 && xx <= h && yy >= 1 && yy <= w && c[xx][yy]!='#' && b[xx][yy]==-1 ){
                    b[xx][yy] = b[dx][dy];
                    q.push(make_pair(xx,yy));
                    v[now].push_back(make_pair(xx,yy));
                }
            }    
        }
        for(int i = 0;i<v[now].size();i++){
            int dx = v[now][i].first;
            int dy = v[now][i].second;
            for(int j = -2;j<=2;j++){
                for(int k = -2;k<=2;k++){
                    int xx = dx + j;
                    int yy = dy + k;
                    if(xx >= 1 && xx<=h && yy >= 1 && yy <= w && c[xx][yy]!='#' && b[xx][yy]==-1){
                        b[xx][yy] = b[dx][dy] + 1;
                        q.push(make_pair(xx,yy));
                        int t = b[xx][yy];
                        v[t].push_back(make_pair(xx,yy));
                        cnt++;
                    }
                }
            }
        }
        if(!cnt) break;
    }
    cout << b[dh][dw] << endl;
    // for(int i = 1;i<=h;i++){
    //     for(int j = 1;j<=w;j++){
    //         printf("%2d ",b[i][j]);
    //     }
    //     cout << endl;
    // }
   

    return 0;
}


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

using namespace std;

#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                        \
	sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
	{
sim > struct rge
{
	c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifdef LOCAL
	~debug()
	{
		cerr << endl;
	}
	eni(!=) cerr << boolalpha << i;
	ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c &)
	{
		ris;
	}
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define forn(i, n) for (ll i = 0; i < int(n); i++)
#define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define M_PI 3.14159265358979323846
#define EPS 1e-7

const ll MOD = 1e9 + 7;

void solve()
{
	ll n; cin >> n;
	vector<pair<int , int>> v(n);
	for (int i = 0; i < n; ++i)
	{
		int x, y; cin >> x >> y;
		v[i] = {x, y};
	}
	sort(all(v));
	double res = 0, cnt = 0;
	do
	{
		cnt = 0;
		for (int i = 1; i < n; ++i)
		{
			cnt += sqrt((v[i].first - v[i - 1].first) * (v[i].first - v[i - 1].first) + (v[i].second - v[i - 1].second) * (v[i].second - v[i - 1].second));
		}
		res += cnt;
		//debug() << imie(v);
	} while (next_permutation(all(v)));
	ld f = 1;
	for (int i = 1; i <= n; ++i)
	{
		f *= i;
	}
	cout << fixed << setprecision(8) << (double)(res / f);
	

}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	solve();
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<double,double> pd;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

int n, a[2][100], ans;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    F0R(i,2) F0R(j,n) {
        cin >> a[i][j];
        if (j) a[i][j] += a[i][j-1];
    }
    F0R(i,n) ans = max(ans,a[0][i]+a[1][n-1]-(i?a[1][i-1]:0));
    cout << ans;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)

Measured memory_bytes: 256
X, N = map(int, input().split())
ans={}
for P in list(map(int, input().split())):
    ans[X-P]=1

for i in range(0,101):
    if not i in ans:
        print(X-i)
        break
    elif not i*-1 in ans:
        print(X+i)
        break


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

int main()
{
    int a, b;
    cin >> a >> b;

    string ans = "";
    if (a > b) {
        for (int i = 0; i < a; i++) {
            ans += to_string(b);
        }
    }
    else {
        for (int i = 0; i < b; i++) {
            ans += to_string(a);
        }
    }

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

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cmath>
#define ll long long
#define out(a) printf("%d",a)
#define max a>b?a:b
#define min a<b?a:b
#define writeln printf("\n")
using namespace std;
int m,len;
char s[100050];
int read()
{
	int s=0,t=1; char c;
	while (c<'0'||c>'9'){if (c=='-') t=-1; c=getchar();}
	while (c>='0'&&c<='9'){s=s*10+c-'0'; c=getchar();}
	return s*t;
}
ll readl()
{
	ll s=0,t=1; char c;
	while (c<'0'||c>'9'){if (c=='-') t=-1; c=getchar();}
	while (c>='0'&&c<='9'){s=s*10+c-'0'; c=getchar();}
	return s*t;
}
int main()
{
	scanf("%s",s); len=strlen(s);
	m=read();
	for (int i=0;i<len;i+=m)
	  cout<<s[i];
	return 0;
}

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

def main():
    A, B, C, X, Y = map(int, input().split())
    max_c = max([X, Y]) * 2
    min_cost = float("inf")
    for n_c in range(0, max_c + 1, 2):
        n_a = max(X - n_c / 2, 0)
        n_b = max(Y - n_c / 2, 0)
        cost = A * n_a + B * n_b + C * n_c
        if cost < min_cost:
            min_cost = cost
    print(int(min_cost))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  char c;
  int n,m,s[10002]={};
  cin>>n>>m;
  for(int i=0;i<m;i++)
    for(int j=1;j<=n;j++){
      cin>>c;
      if(c=='W')s[j]++;
    }
 
  int ans,min=2000000;
  for(int i=1;i<=n;i++)
    s[i]+=s[i-1];
  for(int i=0;i<=n;i++){
    int t=m*i-s[i]+s[n]-s[i];
    if(t<min)min=t,ans=i;
  }
  cout<<ans<<" "<<ans+1<<endl;
  return 0;
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);

long long int  n;
string s,p,f;

cin>>n>>s;
if(n%2!=0)
cout<<"No"<<endl;
else
{
p=s.substr(0,(n/2));
f=s.substr(n/2,n/2);

if(p==f)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}

return 0;
}



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

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

    X -= accumulate(m.begin(), m.end(), 0);
    cout << N + X / *min_element(m.begin(), m.end()) << endl;
}

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

int main() {
  char c;
  cin >> c;
  if ( c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' )
    cout << "vowel" << endl;
  else
    cout << "consonant" << endl;
}

Measured memory_bytes: 256
/*
 * written by Yaqi Zhang
 * University of Wisconsin-Madison
 * 2020
 */

#include<algorithm>
#include<cstring>
#include<iostream>
#include<map>
#include<set>
#include<stdio.h>
#include<vector>

#define INF 0x3f3f3f3f
typedef long long ll;

using namespace std;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, b;
    cin >> n >> b;
    int cnt = 0;
    do {
        ++cnt;
        n /= b;
    } while (n);
    cout << cnt << endl;

    return 0;
}



Measured memory_bytes: 256
import java.util.*;
public class Main {
	
	public static long gcd(long a, long b) {
		return b == 0 ? a: gcd(b, a % b);
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = gcd(A, B);
		int X = (int)Math.sqrt(C);
		List<Integer> p = new ArrayList<>();
		p.add(1);
		p.add(2);
		p.add(3);
		for(int i = 5; i <= X; i += 2) {
			boolean isp = true;
			for(int j = 2; j*j <= i; j++) {
				if(i % j == 0) {
					isp = false;
					break;
				}
			}
			if(isp)
				p.add(i);
		}
		int ans = 0;
		Set<Integer> u = new HashSet<>();
		for(int i : p) {
			if(C % i == 0) {
				while(i != 1 && C % i == 0)
					C /= i;
				u.add(i);
				ans++;
			}
		}
		boolean isprime = true;
		if(C == 1)
			isprime = false;
		if(C % 2 == 0)
			isprime = false;
		if(C % 3 == 0)
			isprime = false;
		for(int i = 5; i <= Math.sqrt(C); i += 2)
			if(C % i == 0)
				isprime = false;
		if(C < X) {
			if(u.contains((int)C))
					isprime = false;
			
		}
		if(isprime)
			ans++;
		System.out.println(ans);

	}

}


Measured memory_bytes: 24276
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
static long factMax = 200000;//nCkにおけるnの最大値
static long[] factorials = new long[factMax+1];//i!(mod p)をO(n)で先にメモ。
static long[] factorialRs = new long[factMax+1];//i!^-1(mod p), pは素数でO(n)。

	static void Main()
	{
    string[] input = Console.ReadLine().Split(' ');
    long n = long.Parse(input[0]);
    long k = long.Parse(input[1]);
    long p = 1000000007;
  
    factorials[0] = 1;
    factorialRs[factMax] = DivideModFactorial(factMax,p);
    for(long i = 1; i <= factMax; i++)
    {
      factorials[i] = (factorials[i-1]*i)%p;//i!(mod p)
      factorialRs[factMax-i] = (factorialRs[factMax+1-i]*(factMax+1-i))%p;//逆元も先にメモ
    }

    Console.WriteLine(SplitNumber(n,k,p));
	}

  static long SplitNumber(long n, long k, long mod)
  {//区別しないn個の玉を区別しないk個の箱に分ける方法の個数(mod)をO(nk)で返す。
  //数え方は、dp[n,k]は、0個の箱を含む時+dp[n,k-1]、含まない時dp[n-k,k]とする。
    long[,] dp = new long[n+1,k+1];
    
    for(int i = 0; i <= k; i++)
    {
      dp[0,i] = 1;
      for(int j = 1; j <= n; j++)
      {
        if(j-i >= 0) dp[j,i] += dp[j-i,i];
        if(i-1 >= 0) dp[j,i] += dp[j,i-1];
     
        dp[j,i] %= mod;
      }
    }

    return dp[n,k];
  }

  static long MathPow(long x, long a)//戻り値はx^a。O(loga)
  {
    long num = 2;
    long answer = 1;
    long check = a;
    long memo = x;
  
    while(check > 0)
    {
      if(check % num == num / 2)
      {
        check -= num / 2;
        answer *= memo;
      }
    memo *= memo;
    num *= 2;
    }
    return answer;
  }

  static long DivideMod(long x, long a, long p)//戻り値はx^a(mod p)。O(loga)
  {
    long num = 2;
    long answer = 1;
    long check = a;
    long memo = x%p;
    
    while(check > 0)
    {
      if(check % num == num / 2)
      {
        check -= num / 2;
        answer *= memo;
        answer %= p;
      }
    memo *= memo;
    memo %= p;
    num *= 2;
    }
    return answer;
  }

  static long DivideModReverse(long x, long p)//戻り値はx^-1(mod p), pは素数。O(logp)
  {
    long answer = DivideMod(x, p-2, p);
    return answer;
  }

  static long ModFactorial(long x, long p)//戻り値はx!(mod p)
  {
    long answer = 1;
    for(int i = 2; i <= x; i++)
    {
      answer *= i;
      answer %= p;
    }
    return answer;
  }

  static long DivideModFactorial(long x, long p)//戻り値はx!^-1(mod p), pは素数
  {
    long answer = 1;
    for(long i = x; i >= 2; i--)
    {
      answer *= DivideModReverse(i, p);
      answer %= p;
    }
    return answer;
  }

  static long Comb(long a, long b, long p)//組み合わせC(a,b)(mod p)をO(1)で返す
  {
    if(a-b < 0) return 0;//引数a-bが負なら0を返す
    long answer = 1;
    answer *= factorials[a];
    answer %= p;
    answer *= factorialRs[a-b];
    answer %= p;
    answer *= factorialRs[b];
    answer %= p;
    return answer;
  }
  
}



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

using namespace std;

// when range [l, r), has property notP~P, want first P.
// when return r, means not found.
template <typename T>
T bs_first(T l, T r, function<bool (T)> f) {
    assert(l < r);
    T mid;
    while (l != r) {
        mid = l + (r-l)/2;
        if (f(mid)) {
            r = mid;
        }else {
            l = mid + 1;
        }
    }
    return r;
}

void solve() {
    int n; cin >> n;
    vector<vector<int>> g(n+1);
    vector<int> deg(n+1);
    for (int _ = 1; _ < n; _++) {
        int x,y;
        cin >> x >> y;
        deg[x]++;
        deg[y]++;
        g[x].emplace_back(y);
        g[y].emplace_back(x);
    }
    int root, cnt=0;
    for (int i = 1; i <= n; i++) {
        if (deg[i] & 1) cnt++;
        if (deg[i] == 1) root=i;
    }
    int A = cnt/2;
    int vir = 0; g[vir].emplace_back(root);
    auto ck = [&](int x){
        vector<int> dp(n+1);
        function<bool(int,int)> dfs = [&](int u, int p){
            vector<int> arm;
            for (int v: g[u])if(v!=p){
                if (!dfs(v, u)) return false;
                arm.emplace_back(dp[v]);
            }
            if (arm.size()%2==0) arm.emplace_back(0);
            sort(arm.begin(), arm.end());
            int m = arm.size();
            int i = bs_first<int>(0, m, [&](int i){
                    int l=0, r=m-1;
                    while (l<r) {
                        if (l==i) l++;
                        if (r==i) r--;
                        if (l < r) {
                            if (arm[l] + arm[r] > x) return false;
                            l++; r--;
                        }
                    }
                    return true;
                    });
            if (i == m) return false;
            dp[u] = arm[i] + 1;
            if (u == root) {
                return dp[u] <= x+1;
            } else {
                return dp[u] <= x;
            }
        };
        return dfs(root, vir);
    };
    int B = bs_first<int>(1, n+1, ck);    
    cout << A << ' ' << B << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 23680
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    ll i,j,k,n,a,b,c[3];

    c[0]=c[1]=c[2]=0;

    cin>>a>>b;
    c[a-1]=1;
    c[b-1]=1;
    for(i=0;i<3;i++)
        if(c[i]==0)
            cout<<i+1<<"\n";






    return 0;
}

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

int main()
{
    int a;
    char s[20];
    scanf("%d", &a);
    scanf("%s",s);
    if(a>=3200){
        printf("%s\n",s);
    }else{
        printf("red\n");
    }
    return 0;
}

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

int main(){
  int N;
  std::cin >> N;
  int s = std::ceil(N/4.0f);
  for(int h = std::max(1, s);h<3600;h++){
//    std::cout<<1.0f / (4.0f / N - 1.0f / h)<<std::endl;
    int start = std::ceil(1.0f / (4.0f / N - 1.0f / h));
//    std::cout<<start<<std::endl;
    for(int n = std::max(1, start);n<3600;n++){
//        std::cout<<h<<" "<<n<<std::endl;
        float divisor = (4.0f / N - 1.0f /n - 1.0f /h);
//            std::cout<<4.0f / N<<" "<<1.0f /n<<" "<<1.0f /h<<std::endl;
//        std::cout<<divisor<<std::endl;
        if(divisor <= 0) continue;
//        std::cout<<divisor<<std::endl;
        int w = std::round(1.0f / divisor);
        if(w<=0) continue;
        if (4 * w * n * h == (N * w * n + N * w * h + N * n * h)){
            std::cout<<h<<" "<<n<<" "<<w<<std::endl;
            exit(0);
        }
    }
//    for n in range(std::max(0, start), 3600):
//        try:
//            w = float(1) / (float(4) / N - float(1) / n - float(1) / h)
//        except ZeroDivisionError:
//            continue
//        w = int(round(w))
//        if w <= 0:
//            continue
//        if (4 * w * n * h == (N * w * n + N * w * h + N * n * h)):
//            print("{} {} {}".format(h, n, w))
//            exit(0)
//    for(int )
  }

//  int btmp;
//  int btmps[N];
//  BinaryIndexTree* bit;
//  bit = new BinaryIndexTree(N);
//
//
//  for(int i=0;i<N;i++){
//    cin >> btmp;
//    //cout << btmp << endl;
//    btmps[i] = btmp;
//  }
//  vector<vector<int>> indexed_data;
//  vector<int> pair = {0,0};
//  indexed_data.push_back(pair);
//  for(int i=0;i<N;i++){
//    vector<int> pair = {i+1, btmps[i]};
//    indexed_data.push_back(pair);
//    bit->add(i+1, 1);
//  }
//
//
//  sort(indexed_data.begin(), indexed_data.end(),
//       [](vector<int> pair, vector<int> other_pair){
//         return (pair[1]<=other_pair[1]);
//       });
//
//  long ans = 0;
//  for(int i=1;i<N+1;i++){
//    int index = indexed_data[i][0];
//    bit->add(index, -1);
//    long left_count = bit->fetch(index-1);
//    long right_count = bit->fetch(-1) - bit->fetch(index);
//    // cout<<"index"<<i<<endl;
//    // cout<<"count"<<left_count<<"\t"<<right_count<<endl;
//    // cout<<indexed_data[i][0]<<"\t"<<indexed_data[i][1]<<endl;
//    ans += min({left_count, right_count});
//  }
//  cout << ans <<endl;
}






Measured memory_bytes: 384
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;

int main(){
    ll x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    vector<int> p(a),q(b),r(c);
    for(int i=0;i<a;i++) cin>>p[i];
    for(int i=0;i<b;i++) cin>>q[i];
    for(int i=0;i<c;i++) cin>>r[i];
    sort(p.rbegin(),p.rend());
    sort(q.rbegin(),q.rend());
    priority_queue<int> t;
    for(int i=0;i<x;i++) t.push(p[i]);
    for(int i=0;i<y;i++) t.push(q[i]);
    for(int i=0;i<c;i++) t.push(r[i]);
    ll ans=0;
    for(int i=0;i<x+y;i++){
        ans+=t.top();
        t.pop();
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 6464
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define F(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define FD(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define pii pair<int,int>
#define reset(x,y) memset(x, y,sizeof(x))
#define MIN(x,y) if (x > (y)) x = (y)
#define MAX(x,y) if (x < (y)) x = (y)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define EL putchar('\n');
#define mod 1000000007
#define oo 404
int read()
{
    int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
    while (c >= '0' && c <= '9') {x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
void write(int x)
{
    if (x > 9) write(x / 10);
    putchar(x % 10 + '0');
}
int n;
int a[oo];
int sum[oo];
int f[oo][oo];
void ReadInPut()
{
    n=read();
    F(i,1,n){a[i]=read();sum[i]=sum[i-1]+a[i];}
}
int tinh(int l,int r)
{
    if(l>=r)return 0;
    if(f[l][r]!=-1)return f[l][r];
    f[l][r]=1e16;
    F(i,l,r-1)
    {
        MIN(f[l][r],tinh(l,i)+tinh(i+1,r)+sum[r]-sum[l-1]);
    }
    return f[l][r];
}
void Solve()
{
    reset(f,-1);
    cout<<tinh(1,n);
}
main()
{
//    freopen("t.INP","r",stdin);
  //  freopen(".OUT","w",stdout);
    int sotest=1;
    //cin>>sotest;
    for(int i=1;i<=sotest;i++)
    {
        ReadInPut();
        Solve();
    }
}


Measured memory_bytes: 1536
#include <algorithm>
#include <climits>
#include <functional>
#include <iterator>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#ifdef _MSC_VER
using ll = __int64;
using ull = unsigned __int64;
#else
using ll = long long int;
using ull = unsigned long long int;
#endif

// 二乗を計算する。
ll sq(ll x) { return x * x; }

// 領域内にいるか。
bool within(ll x, ll min, ll max) {
	return min <= x && x <= max;
}

// container の中から key より小さい値を見つける。
// 見つからない場合は container.end() を返す。
template<typename T>
typename T::iterator less_than(T& container, typename T::key_type& key) {
	typename T::iterator prev = container.lower_bound(key);
	if (prev == container.begin()) prev = container.end();
	else prev--;
	return prev;
}

// container の中から key より大きい値を見つける。
// 見つからない場合は container.end() を返す。
template<typename T>
typename T::iterator greater_than(T& container, typename T::key_type& key) {
	return container.upper_bound(key);
}

// b^e (mod m) を求める
ll modpow(ll b, ll e, ll m) {
	ll result = 1;
	while (e > 0) {
		if ((e & 1) == 1) result = (result * b) % m;
		e >>= 1;
		b = (b * b) % m;
	}
	return result;
}


// ここから解法


int main(void) {
	std::ios_base::sync_with_stdio(false);

	int N;
	cin >> N;
	cout << ((N - 2) * 180) << endl;

	return 0;
}



Measured memory_bytes: 256
x = []
for y in range(9):
        x += [[chr(65+y),y]]
Room = dict(x)

By = [[0,0,1,3],[0,1,2,4],[1,2,2,5],[0,3,4,6],[1,3,5,7]]
By += [[2,4,5,8],[3,6,6,7],[4,6,7,8],[5,7,8,8]]

while 1:
        BatP = input()
        if BatP == 0:
                break
        Info = raw_input().split()
        Prob = [0 for x in range(9)]
        Prob[Room[Info[0]]] = 1

        while 0 < BatP:
                BatP -= 1
                AftI = Prob[:]
                Prob = [0 for x in range(9)]

                for x in range(9):
                        if x == Room[Info[2]]:
                                for y in range(4):
                                        Prob[By[x][y]] += AftI[By[x][y]] *0.25
                        else:
                                for y in range(4):
                                        Prob[x] += AftI[By[x][y]] * 0.25

        print('{:.8f}'.format(Prob[Room[Info[1]]]))

Measured memory_bytes: 4336
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){

	int n;
	while(cin>>n){
		int mul=1;
		vector<int> v;
		while(n!=0){
			if(n%2==1){
				v.push_back(mul);
			}
			mul*=2;
			n/=2;
		}
		for(int i = 0; i < v.size(); i++){
			cout<<v[i];
			if(i!=v.size()-1)
				cout<<" ";
			else
				cout<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define d double
#define INF INT_MAX
#define output for(int i=0;i<sizex;i++) { for(int j=0;j<sizey;j++) { cout << moveChart[i][j] << " "; }cout<<endl; }cout<<endl;

int n, k;
int arr[101];
int dp[3][100001];

inline int otherPlayer( int x ){
    if( x == 1 ) return 2;
                 return 1;
}

int solve( int player, int rem ){

    if( !rem ) return otherPlayer(player);
    if( rem < 0 ) return player;

    if( dp[player][rem] != -1 ) return dp[player][rem];

    int playerWins = 0;
    for(int i=0;i<n;i++){

        int res = solve( otherPlayer(player), rem - arr[i] );
        if( res == player ) playerWins++;

    }

    if( playerWins  ) return dp[player][rem] = player;
                      return dp[player][rem] = otherPlayer(player);

}

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

    memset( dp, -1, sizeof dp );

    cin >> n >> k;
    for(int i=0;i<n;i++) cin >> arr[i];

    int res = solve( 1, k );
    if( res == 1 ) cout << "First" << endl;
    else if( res == 2 ) cout << "Second" << endl;
    else cout << "Error" << endl;

}

Measured memory_bytes: 7680
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--) 
#define Rep(i,a) for(int i = 0; i < a; i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ab(x) ((x) < 0 ? -(x) : (x))
using namespace std;
typedef long long LL;
typedef map<int, int>::iterator mit;
typedef set<int>::iterator sit;
const int N = 1e5 + 10;
int n, a[N], t, c[N];

struct edge{ int to, pre; }e[N << 1]; int u[N], l = 0;
void ins(int a, int b) { e[++l] = (edge){b, u[a]}, u[a] = l; }
#define v e[i].to
#define reg(i,a) for(int i = u[a]; i; i = e[i].pre)

int d[N];
bool flag = true;
int r[N], rt;
void dfs(int x, int f) {
	if (d[x] == 1) { r[x] = a[x]; return; }
	LL s = 0; 
	reg(i,x) if (v != f) dfs(v, x), s += r[v];
	if (s < a[x] || s > 2 * a[x]) flag = false;
	r[x] = 2 * a[x] - s; if (x == rt && r[x]) flag = false;
	reg(i,x) if (r[v] > a[x]) flag = false;
}

int main() {
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",&a[i]);
	if (n == 2) { printf(a[1] == a[2] ? "YES" : "NO"); return 0; }
	rep(i,1,n - 1) {
		int a, b; scanf("%d%d",&a,&b);
		ins(a, b), ins(b, a);
		d[a]++, d[b]++;
	}
	rt = 0;
	rep(i,1,n) if (d[i] > 1) rt = i;
	dfs(rt, 0);
	printf(flag ? "YES" : "NO");
	return 0;
}


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

using namespace std;

int main(){
  int r,g,b;
  cin >> r >> g >> b;
  
  if ((100*r + 10*g + b) % 4 == 0)  cout << "YES" << endl;
  else  cout << "NO" << endl;  
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
const ll MOD = 0;

ll CW[10000010];

int main() {
	for (int i = 0;i < 10000010;i++) {
		CW[i] = 0;
	}
	ll N;
	cin >> N;
	for (int i = 1;i <= N;i++) {
		for (int j = i;j <= N;j += i) {
			CW[j]++;
		}
	}
	ll ans = 0;
	for (ll i = 1;i <= N;i++) {
		ans += CW[i] * i;
	}
	cout << ans << endl;
}

Measured memory_bytes: 81756
n = int(input())
a = list(map(int, input().split()))
len_a = len(a)
i = len_a // 2
a.sort()
a.reverse()
if len_a % 2 == 0:
    result = a[0] + 2*(sum(a[1:i]))
else:
    result = a[0] + 2*(sum(a[1:i]))+a[i]

print(result)


Measured memory_bytes: 31596
#include<stdio.h>
            int main(void)
            {
              int ng;
              int mk;
              int gc=1;
              int kc=1;
              int c;
              
              scanf("%d",&ng);
              scanf("%d",&mk);
              
              gc=(ng*(ng-1))/2;
              kc=(mk*(mk-1))/2;
              
              c=gc+kc;
             
              printf("%d",c);
              return 0;
            }

Measured memory_bytes: 128
from collections import deque


def main():
    s = deque(list(input()))
    q = int(input())
    rev = False
    for _ in range(q):
        query = input().split()
        if query[0] == "1":
            if not rev:
                rev = True
            else:
                rev = False
        else:
            if query[1] == '1':
                pass
                if rev:
                    s.append(query[2])
                else:
                    s.appendleft(query[2])
            else:
                if rev:
                    s.appendleft(query[2])
                else:
                    s.append(query[2])
    if rev:
        s.reverse()
    print(*s, sep="")


if __name__ == "__main__":
    main()


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

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

	int *n = new int[2000000], *r = new int[2000000];
	int cur = N.length();
	n[cur] = r[cur] = 0;
	for(cur--; cur>=0; cur--){
		if(n[cur+1] == 0){
			n[cur] = N[cur] - '0';
			r[cur] = (10 - (N[cur] - '0')) % 10;
		} else {
			n[cur] = N[cur] - '0'
				+ min(n[cur+1], 1+r[cur+1]);
			r[cur] = 9 - (N[cur] - '0')
				+ min(r[cur+1], 1+n[cur+1]);
		}
	}
	cout << min(n[0], 1+r[0]);
	return 0;
}


Measured memory_bytes: 12292
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = list(map(int, input().split()))
a = [(-num, i) for i,num in enumerate(a)]
a.append((0, -1))
import heapq
heapq.heapify(a)
ans = [0]*n

pnum, pi = heapq.heappop(a)
pnum *= -1
count = 1
v = pnum
while a:
    num, i = heapq.heappop(a)
    num *= -1
    if i<pi:
        ans[pi] = v - num*count
        v = num*(count+1)
        count += 1
        pi = i
    else:
        count += 1
        v += num
write("\n".join(map(str, ans)))

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(3);
  
  auto det = [&](double a, double b, double c, double d) { return a * d - b * c; };
  double a, b, c, d, e, f;
  while (cin >> a >> b >> c >> d >> e >> f) {
    double x = det(c, b, f, e) / det(a, b, d, e);
    double y = det(a, c, d, f) / det(a, b, d, e);
    if (fabs(x) < 1e-10) x = 0;
    if (fabs(y) < 1e-10) y = 0;
    cout << x << " " << y << endl;
  }

  return 0;
}


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

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 ll INF = 1LL << 60;

vector<vector<ll>> dp(110, vector<ll>(10010, 0));

struct Item {
    int v, w;
};

int main() {
    int N, W;
    cin >> N >> W;
    vector<Item> I(N + 1);
    for (int i = 1; i <= N; i++) {
        scanf("%d%d", &I[i].v, &I[i].w);
    }

    for (int i = 1; i <= N; i++) {
        for (int w = 1; w <= W; w++) {
            if (w - I[i].w >= 0) {
                chmax(dp[i][w], dp[i - 1][w - I[i].w] + I[i].v);
            }
            chmax(dp[i][w], dp[i - 1][w]);
        }
    }

    cout << dp[N][W] << endl;

    return 0;
}


Measured memory_bytes: 11428
#include <stdio.h>
#include <string.h>
int map[805][805]={0};
int p[805];
int c, n, max;
int cnt[805][805] = {0};
int type[805] = {0};			// 0:leaf
int vis[805]={0};
int leaf;
int d[805] = {0};

void init(){
	c = 0;
	leaf = 0;
	max = 0;
	for(int i=2;i<=n;i++)	//1<=pi<i
	{
		scanf("%d", &p[i]);
		cnt[i][++cnt[i][0]] = p[i];			// 隣接の点のデータを 
		cnt[p[i]][++cnt[p[i]][0]] = i;		//記入
	} 
	for(int i=2;i<=n;i++)
	{
		scanf("%d", &d[i]);
		map[i][p[i]] = map[p[i]][i] = d[i];
		c += d[i];
	}
	for(int i=1;i<=n;i++)
	{
		if(cnt[i][0] > 1)
			type[i] = 1;
		else
			leaf += map[i][cnt[i][1]];	
	}
	c -= leaf;
}

void reset(){
	memset(cnt,0,sizeof(cnt));
	memset(map,0,sizeof(map));
	memset(type,0,sizeof(type));
}

void dfs(int now, int dis){
	vis[now] = 1;
	for(int i=1;i<=cnt[now][0];i++){
		if(vis[cnt[now][i]] != 1 && type[cnt[now][i]] != 0)
			dfs(cnt[now][i],dis+map[now][cnt[now][i]]);
	}
	vis[now] = 0;			
	if(dis > max) max = dis; 
}

int main(){ 
	while(scanf("%d",&n), n){
		init();
		for(int i=1;i<=n;i++){				//葉と隣接する 
			if(type[i] == 0){ 				//ところで最小直径 
				dfs(cnt[i][1], 0);				//を計算 
			}
		}
		printf("%d\n", leaf + 3*c - max);
		reset();
	}
} 


Measured memory_bytes: 7804