akhauriyash/Code-Regression huggingface dataset:
n = int(input())
xy = []
for i in range(n):
    x, y = map(int, input().split())
    xy.append([x, y])

res = 0
for i in range(n):
    for j in range(i+1, n):
        dist = ((xy[i][0] - xy[j][0]) ** 2 + (xy[i][1] - xy[j][1]) ** 2) ** (1/2)
        res += dist

print(res*2/n)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
using namespace std;
const int N=1<<19;
int n,Q,x,L,v[N],w[N],q[20];
int va[1<<10],vb[1<<10];
int a[1<<10],b[1<<10];
int getq(int l,int r,int *va,int *a){
	int m=1;
	va[0]=0; a[0]=0;
	static int t1[1<<10],t2[1<<10];
	For(i,l,r){
		For(j,0,m-1) va[j+m]=va[j]+::w[q[i]];
		For(j,0,m-1) a[j+m]=a[j]+  ::v[q[i]];
		int p1=0,p2=m;
		For(j,0,2*m-1)
			if (p1==m) t1[j]=va[p2],t2[j]=a[p2++];
			else if (p2==m*2) t1[j]=va[p1],t2[j]=a[p1++];
			else if (va[p1]<va[p2]) t1[j]=va[p1],t2[j]=a[p1++];
			else t1[j]=va[p2],t2[j]=a[p2++];
		m*=2;
		For(j,0,m-1)
			va[j]=t1[j],a[j]=t2[j];
	}
	For(j,1,m-1)
		a[j]=max(a[j],a[j-1]);
	//For(i,0,m) cout<<"INFO "<<va[i]<<' '<<a[i]<<' '; cout<<endl;
	return m;
}
void solve(){
	scanf("%d%d",&x,&L);
	*q=0;
	for (;x;q[++*q]=x,x>>=1);
	int m=(*q+1)/2;
	int v1=getq(1,m,va,a);
	int v2=getq(m+1,*q,vb,b);
	int ans=0,p1=v2-1;
	For(i,0,v1-1){
		for (;p1>=0&&va[i]+vb[p1]>L;--p1);
		if (p1>=0) ans=max(ans,a[i]+b[p1]);
	}
	printf("%d\n",ans);
}
int main(){
	scanf("%d",&n);
	For(i,1,n) scanf("%d%d",&v[i],&w[i]);
	scanf("%d",&Q);
	while (Q--) solve();
} 

Measured memory_bytes: 5904
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
minus = len([i for i in a if i < 0])
if minus == 0:
  minus = 1
elif minus == len(a):
  minus = len(a)-1
  
print(sum(a[minus:])- sum(a[:minus]))
for e in a[minus:-1]:
  print(str(a[0])+" "+str(e))
  a[0] -= e
for e in a[:minus]:
  print(str(a[-1])+" "+str(e))
  a[-1] -= e

Measured memory_bytes: 14144
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

long long modpow(long long a, long long n, long long MOD) {//a^n(MOD)を求める
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;//次の準備
        n >>= 1;
    }
    return res;
}

const int MAX = 2000010;//設定して

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;//＊１
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  COMinit();
  
  ll n,a,b;cin>>n>>a>>b;
  ll nca=1,ncb=1;

  ll ans=modpow(2ll,n,mod);
  ans+=mod-1;
  ans%=mod;

  rep(i,1,a+1){
    nca*=inv[i];
    nca%=mod;
    nca*=(n+1-i);
    nca%=mod;
  }
  rep(i,1,b+1){
    ncb*=inv[i];
    ncb%=mod;
    ncb*=(n+1-i);
    ncb%=mod;
  }

  ans+=mod-nca;
  ans%=mod;
  ans+=mod-ncb;
  ans%=mod;
  cout<<ans<<ENDL;
}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 47232
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int maxn=1e5+10;
string s[maxn];
int m,n;
map<string,int>ma;
int main()
{
    std::ios::sync_with_stdio(false);
   int n;
   cin>>n;
   for(int i=0;i<n;i++)
   {
       cin>>s[i];
       sort(s[i].begin(),s[i].end());
   }
  ll ans=0;
    for(int i=0;i<n;i++)
    {
       // cout<<s[i]<<endl;
        ans+=ma[s[i]];
        ma[s[i]]++;
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 16640
#include<bits/stdc++.h>
#define int long long
#define fo(i,n)   for(i=0;i<n;i++)
#define mod       1000000007
using namespace std;

int32_t main()
{

	 int h,w;
    cin>>h>>w;
    if(h==1 or w==1)
    {
        cout<<1<<endl;
    }
    else
    {
      int ans=h*w;
      if(ans%2==0)
        {
            cout<<(h*w)/2<<endl;
        }
       else
       {
        cout<<((h*w)+1)/2<<endl;
       }
    }
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int main(){
  int A, B;
  rd(A);
  rd(B);
  if((A+B)%2){
    wt_L("IMPOSSIBLE");
    wt_L('\n');
  }
  else{
    wt_L((A+B)/2);
    wt_L('\n');
  }
  return 0;
}

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

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define double long double
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
double dfs(vector< vector< vector< double > > > &dp, int i, int j, int k) {
	if (dp[i][j][k] != -1)
		return dp[i][j][k];
	double ret = 1;
	if (i > 0)
		ret += dfs(dp, i - 1, j, k) * i / N;
	if (j > 0)
		ret += dfs(dp, i + 1, j - 1, k) * j / N;
	if (k > 0)
		ret += dfs(dp, i, j + 1, k - 1) * k / N;
	ret *= (double)N / (i + j + k);
	return dp[i][j][k] = ret;
}
signed main() {
	cin >> N;
	vector< vector< vector< double > > > dp(N + 1, vector< vector< double > >(N + 1, vector< double >(N + 1, -1)));
	vector< int > A(4, 0);
	dp[0][0][0] = 0;
	rep(i, N) {
		int a;
		cin >> a;
		A[a]++;
	}

	cout << dfs(dp, A[1], A[2], A[3]) << endl;
	return 0;
}

Measured memory_bytes: 433408
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

ll N, M;
ll gcd_func(ll a, ll b) {
    if (a < b) return gcd_func(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

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

    ll g = gcd_func(N, M);

    ll ans = N / g * M / g * g;

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


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Feb  9 10:45:37 2019

@author: shinjisu
"""
# arc 069 Scc puzzle


def getIntList(): return [int(x) for x in input().split()]


def db(x):
    global debug
    if debug:
        print(x)


def solve():
    if N >= M//2:
        return M//2
    return N + (M-N*2)//4


debug = False
N, M = getIntList()
db((N, M))
print(solve())


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s;
	cin >> s;
	for (int i = 97; i <= 122; i ++) {
		if (s.find((char)i) == string::npos) {
			cout << (char)i << endl;
			return 0;
		}
	}
	cout << "None" << endl;
}

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

int main() {
  int N;
  cin >> N;
  bool can = false;
  for (int i = 0; i <= N / 4; i++) {
    int sum = 4 * i;
    if (sum == N) can = true;
    else if (sum < N) {
      for (int j = 0;;j++) {
        sum += 7;
        if (sum == N) can = true;
        else if (sum > N) break;
      }
    }
  }
  
  if (can) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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


Measured memory_bytes: 256
n,k=gets.chomp.split(" ").map(&:to_i)
pi=gets.chomp.split(" ").map(&:to_i)

ary=Array.new(n,0.0)
ary2=Array.new(n,0.0)

(0..n-1).each do |x|
    ary[x]=(pi[x]+1)/2.0
end

(0..k-1).each do |y|
    ary2[y]=ary2[y-1]+ary[y]
end

(k..n-1).each do |i|
    ary2[i]=ary2[i-1]+ary[i]-ary[i-k]
end

p ary2.max

Measured memory_bytes: 19084
<?php
  fscanf(STDIN,"%d %d",$n,$m);
  $k = [];
  for($i=0; $i<$n; $i++){
    $k[] = explode(" ",trim(fgets(STDIN)));
  }
  if($n == 1){
    echo $k[0][0]."\n";
    exit;
  }
  for($x=0; $x<$n; $x++){
    unset($k[$x][0]);
  }
  $result = array_intersect($k[0],$k[1]);
  for($y=2; $y<$n; $y++){
    $result = array_intersect($result,$k[$y]);
  }
  echo count($result)."\n";
  ?>


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

int main() {
  int N, K;
  int x;
  
  cin >> N >> K;
  
  int distance = 0;
  for (int i = 0; i < N; i++) {
    cin >> x;
    if (x > (K - x)) {
      distance += (K - x);
    } else {
      distance += x;
    }
  }
  
  cout << (distance * 2) << endl;
}


Measured memory_bytes: 256
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

import sys

sys.setrecursionlimit(4000)
class iland:
    def __init__(self,w,h):
        self.w = w
        self.h = h

        self.c = [[0]*(w+2) for i in range(h+2)] 
        c_tmp = [list(int(i) for i in input().split()) for _ in range(h)]
        for i in range(h):
            for j in range(w):
                self.c[i+1][j+1] = c_tmp[i][j]

        self.d = [[0]*w for i in range(h)]

    def search(self,y,x):
        # 海
        if self.c[y+1][x+1] == 0:
            # self.d[y][x] = -1
            return 0
        # 探索済み
        if self.d[y][x] !=0:
            return 0

        # print(y,x)
        self.d[y][x] = 1
        self.search(y-1,x)
        self.search(y-1,x+1)
        self.search(y,x+1)
        self.search(y+1,x+1)
        self.search(y+1,x)
        self.search(y+1,x-1)
        self.search(y,x-1)
        self.search(y-1,x-1)

        return 1

ans = []
while (1):
    w,h = mi()

    if(w == 0 and h==0):
        break

    l = iland(w,h)

    # 0=umi 1=riku
    land_no = 0
  
    for i in range(h):
        for j in range(w):
            # print(l.d)
            # print(l.c)
            if l.search(i,j):
                land_no += 1
           
    # print(land_no)
    ans.append(land_no)

for i in ans:
    print(i)




Measured memory_bytes: 7644
/*選択ソート*/
#include <stdio.h>
#define N 100
int main(){
  int a[N], n, i, j, count=0, mini, tmp;

  scanf("%d", &n);

  for (i=0; i<n; i++){
    scanf("%d", &a[i]);
  }

  for (i=0; i<n; i++){
    mini = i;
    for (j=i; j<n; j++){
      if (a[j]<a[mini]){
	mini = j;
      }
    }
    if (i != mini){
      tmp = a[i];
      a[i] = a[mini];
      a[mini] = tmp;
      count++;
    }
  }

  

  for (i=0; i<n; i++){
    if (i==n-1){
      printf("%d\n", a[i]);
      break;
    }
    printf("%d ", a[i]);
  }

  printf("%d\n", count);

  return 0;
}
  



Measured memory_bytes: 2084
#include <stdio.h>
int main () {
  int n, i;
  scanf ("%d", &n);
  int a[2][100];
  int sum1[100];
  int sum2[100];
  int temp = 0;
  for (i = 0; i < n; ++i) {
    scanf ("%d", &a[0][i]);
    temp += a[0][i];
    sum1[i] = temp;
  }
  temp = 0;
  for (i = 0; i < n; ++i) {
    scanf ("%d", &a[1][i]);
    temp += a[1][i];
    sum2[i] = temp;
  }
  int max = 0;
  for (i = 0; i < n; ++i) {
    temp = sum1[i] + sum2[n-1] - sum2[i] + a[1][i];
    if (temp > max) {
      max = temp;
    }
  }
  printf ("%d\n", max);
  return 0;
}

Measured memory_bytes: 1708
class UnionFind:
    __slots__ = ["_data_size", "_roots"]

    def __init__(self, data_size: int) -> None:
        self._data_size = data_size
        self._roots = [-1] * data_size

    def __getitem__(self, x: int) -> int:
        while self._roots[x] >= 0:
            x = self._roots[x]
        return x

    def is_connected(self, x: int, y: int) -> bool:
        return self[x] == self[y]

    def unite(self, x: int, y: int) -> None:
        x, y = self[x], self[y]
        if x == y:
            return
        if self._roots[x] > self._roots[y]:
            x, y = y, x
        self._roots[x] += self._roots[y]
        self._roots[y] = x


import sys

readline = sys.stdin.readline

N, Q = map(int, readline().split())
tree = UnionFind(N)
res = []
for _ in range(Q):
    t, u, v = map(int, readline().split())
    if t:
        res.append(int(tree.is_connected(u, v)))
    else:
        tree.unite(u, v)
print("\n".join(map(str, res)))


Measured memory_bytes: 84780
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <limits.h>

bool sosu (int a){
    for (int i=2; i<a; i++){
        if (a%i==0){
            return false ;
        }
    }
    return true;
}

int main(void){
    int n,count=0;
    scanf("%d",&n);
    for (int i=2; i<=55555; i++){
        if (sosu(i)==true && i%5==1){
            printf("%d\n",i);
            count++;
        }
        if (count==n){
            break;
        }
    }    
    return 0 ;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
 
signed main(){
 
  while(true){
    int target;
    pair<int, pair<int,int> > ans = {-1,{0,0}};
    string num;
     
    cin>>target>>num;
 
    if(target == 0 && num == "0") break;
 
    for(int i = 0; i < (1<<(num.size()-1)); i++){
      int sum = 0, n = 0;
      for(int j = 0; j < num.size(); j++){
    n = n*10 + (num[j] - '0');
    if((i>>j)&1 || j == num.size()-1){
      sum += n;
      n = 0;
    }
      }
      if(sum >  target) continue;
      if(ans.first == sum) ans.second.first++;
      else if(ans.first < sum){
      ans = make_pair(sum,make_pair(1,i));
      }
    }
 
    if(ans.second.first > 1) cout<<"rejected"<<endl;
    else if(ans.first == -1) cout<<"error"<<endl;
    else {
      int n = 0;
      cout<<ans.first;
       
      for(int j = 0; j < num.size(); j++){
    n = n*10 + (num[j] - '0');
    if((ans.second.second>>j)&1 || j == num.size()-1){
      cout<<" "<<n;
      n = 0;
    }
      }
      cout<<endl;
    }
     
  }
   
 
  return 0;
}


Measured memory_bytes: 3104
PROGRAM piyo
      IMPLICIT NONE
      INTEGER,PARAMETER :: prec = 16
      real(prec) :: b
      integer(prec) :: aa,bb
      
      read*,aa,b
      

      bb = nint( b*100_prec )
      print'(i0)',aa*bb/100_prec
      
      
      stop
      !debugg
      
      
      
      END PROGRAM

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

int A, B, T;

int main() {
    cin >> A >> B >> T;
    int ans = 0;
    for (int i = 1; i <=T; i++) {
       if (i % A == 0) {
           ans += B;
       }
    }

    printf("%d\n", ans);
}

Measured memory_bytes: 256
#include <stdio.h>
char *flag(float n)
{
	if(n>48)
	{
		if(n>51)
		{
			if(n>54)
			{
				if(n>57)
				{
					if(n>60)
					{
						if(n>64)
						{
							if(n>69)
							{
								if(n>75)
								{
									if(n>81)
									{
										if(n>91)
										return "heavy";
										else
										return "light heavy";
									}
									else
									return "middle";
								}
								else
								return "light middle";
							}
							else
							return "welter";
						}
						else
						return "light welter";
					}
					else
					return "light";
				}
				else
				return "feather";
			}
			else
			return "bantam";
		}
		else
		return "fly";
	}
	else
	return "light fly";
}
int main()
{
	float n;
	while(scanf("%f",&n)!=EOF)
	printf("%s\n",flag(n));
	return 0;
}

Measured memory_bytes: 0
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 200100;

int n, a[N];
map < int, set <int> > m;

int main() {

	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}

	sort(a, a + n);

	for (int i = 0; i < n; i++) {
		m[a[i]].insert(i);
	}

	int res = 0;

	for (int i = n - 1; i >= 0; i--) {
		if (m[a[i]].count(i) == 0) {
			continue;
		}
		m[a[i]].erase(i);
		int x = 1;
		while (x <= a[i]) {
			x <<= 1;
		}
		int d = x - a[i];
		if (m[d].size() > 0) {
			++res;
			m[d].erase(m[d].begin());
		}
	}

	printf("%d\n", res);

	return 0;

}

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

using namespace std;

//typedefs
typedef long long ll;


int main() {
    ll x, k, d; cin >> x >> k >> d;
    ll p = abs(x) / d;
    ll r = min(k, p);
    
    if (x < 0) {
        x += (r * d);
    } else {
        x -= (r * d);
    }

    ll ans = 0;
    k -= r;

    if (x < 0) {
        if (k & 1) {
            x += d;
            ans = abs(x);
        } else {
            ans = abs(x);
        }
    } else {
        if (k & 1) {
            x -= d;
            ans = abs(x);
        } else {
            ans = abs(x);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
using namespace std;
int main(){
    int n;
    string ans ="No";
    cin >> n;
    string x = to_string(n);
    int sum=0;
    for(int i=0;i<x.length();i++){
        sum += stoi(x.substr(i,1));
    }
    if(n%sum==0){
        ans = "Yes";
    }
    cout << ans << endl;
}

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

using namespace std;

int n, m;
long long y[605], z[605], ans;
char x[305][305];
int ta;

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++)
		scanf("%s", x[i]);
	for (int i = 0; i < n; i++) {
		memset(y, 0, sizeof(y));
		memset(z, 0, sizeof(z));
		for (int j = 0; j < i; j++)
			for (int k = 0; k < m; k++)
				y[abs(j - i) + k] += x[j][k] == '#';
		for (int j = i + 1; j < n; j++)
			for (int k = 0; k < m; k++)
				z[abs(j - i) + k] += x[j][k] == '#';
		for (int j = 0; j < m; j++) {
			for (int k = 0; k < i; k++)
				y[abs(k - i) + j] -= x[k][j] == '#';
			for (int k = i + 1; k < n; k++)
				z[abs(k - i) + j] -= x[k][j] == '#';
			for (int k = 1; j - k >= 0 && i + k < n; k++)
				if (x[i][j - k] == '#' && x[i + k][j] == '#')
				  ans += y[k + j];
			for (int k = 1; j - k >= 0 && i - k >= 0; k++)
				if (x[i][j - k] == '#' && x[i - k][j] == '#')
				  ans += z[k + j];
			for (int k = 1; k < 305; k++) {
				ta = 0;
				if (i - k >= 0)
					ta += x[i - k][j] == '#';
				if (j - k >= 0)
					ta += x[i][j - k] == '#';
				if (i + k < n)
					ta += x[i + k][j] == '#';
				if (j + k < m)
					ta += x[i][j + k] == '#';
				if (ta == 3)
					ans++;
				else if (ta == 4)
					ans += 4;
			}
		}
	}
	for (int i = 0; i < n; i++)
		reverse(x[i], x[i] + m);
	for (int i = 0; i < n; i++) {
		memset(y, 0, sizeof(y));
		memset(z, 0, sizeof(z));
		for (int j = 0; j < i; j++)
			for (int k = 0; k < m; k++)
				y[abs(j - i) + k] += x[j][k] == '#';
		for (int j = i + 1; j < n; j++)
			for (int k = 0; k < m; k++)
				z[abs(j - i) + k] += x[j][k] == '#';
		for (int j = 0; j < m; j++) {
			for (int k = 0; k < i; k++)
				y[abs(k - i) + j] -= x[k][j] == '#';
			for (int k = i + 1; k < n; k++)
				z[abs(k - i) + j] -= x[k][j] == '#';
			for (int k = 1; j - k >= 0 && i + k < n; k++)
				if (x[i][j - k] == '#' && x[i + k][j] == '#')
				  ans += y[k + j];
			for (int k = 1; j - k >= 0 && i - k >= 0; k++)
				if (x[i][j - k] == '#' && x[i - k][j] == '#')
				  ans += z[k + j];
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 384
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner (System.in);
        int N = sc.nextInt();
        ArrayList<Integer> List = new ArrayList<>();
        for(int a=0;a<N;a++) List.add(sc.nextInt());

        while(true){
                Collections.sort(List);
                int min = List.get(0);
                for(int a=1;a<List.size();a++){
                        int amari = List.get(a)%min;
                        if(amari ==0) List.remove(a);
                        else List.set(a,amari);
                }
                if(List.size()==1)break;
            }
            System.out.println(List.get(0));
        }
    }



Measured memory_bytes: 60848
#include<stdio.h>
int main()
{ 
  char a[4];
scanf("%4s",a);
  
  if(a[0]==a[1] && a[2]==a[3] && a[2]!=a[1]) printf("Yes");
  else if(a[0]==a[2] && a[1]==a[3] && a[0]!=a[1]) printf("Yes");
  else if(a[0]==a[3] && a[1]==a[2] && a[0]!=a[1]) printf("Yes");
  else printf("No");
return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define INFTY (1<<30)
using namespace std;
int H,heap[2000001];

void maxHeapify(int i){
  int l,r,largest;
  l=i*2;
  r=i*2+1;

  //左の子、自分、右の子で値が最大のノードを選ぶ(maxヒープにするため）

  if(l<=H&&heap[l]>heap[i]) largest=l;
  else largest=i;

  if(r<=H&&heap[r]>heap[largest]) largest=r;
  
  if(largest!=i){//もし、自分が最大じゃなかったら
    swap(heap[i],heap[largest]);
    maxHeapify(largest);//最大から、また潜る
  }
}

void increacekey(int i,int key){
  if(key<heap[i])return ;
  heap[i]=key;
  while(i>1&&heap[i/2]<heap[i]){
    swap(heap[i/2],heap[i]);
    i=i/2;
  }
}

void insert(int key){
  H++;
  heap[H]=-INFTY;
  increacekey(H,key);
}

int extract(){
  int maxv;
  if(H<1) return -INFTY;
  maxv=heap[1];
  heap[1]=heap[H--];
  maxHeapify(1);
  return maxv;
}
int main(){
  int key;
  string com;
  while(1){
    cin>>com;
    if(com=="end") break;
    if(com=="insert"){
      scanf("%d",&key);
      insert(key);
    }else printf("%d\n",extract());
  }
  return 0;
}



Measured memory_bytes: 7212
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<string>
#include<queue>
#include<map>
using namespace std;
#define INF 0x3f3f3f3f
const int MAXN = 1005;
int H, W, N, dist[4] = {1,-1,4,-4};
map<string, int>Puzzle;
struct Node
{//当前位置，?数
	string s;
	int step;
};
bool check(int x)
{
	if (x >= 0 && x < 8)
	{
		return true;
	}
	return false;
}
void BFS(Node start)
{
	queue<Node>Q;
	Q.push(start);
	Puzzle.insert(make_pair(start.s, start.step));
	map<string,int>::iterator it;
	while (!Q.empty())
	{
		int index0 = 0;
		Node top, next;
		top = Q.front(); Q.pop();
		for (int i = 0; i < 8; i++)
		{
			if (top.s[i] == '0')
			{
				index0 = i;
				break;
			}
		}
		if (index0 == 3)
		{
			next.s = top.s; next.step = top.step + 1;
			swap(next.s[index0], next.s[index0 - 1]);
			it = Puzzle.find(next.s);
			if (it == Puzzle.end())
			{
				Puzzle.insert(make_pair(next.s, next.step));
				Q.push(next);
			}
			next.s = top.s; next.step = top.step + 1;
			swap(next.s[index0], next.s[index0 + 4]);
			it = Puzzle.find(next.s);
			if (it == Puzzle.end())
			{
				Puzzle.insert(make_pair(next.s, next.step));
				Q.push(next);
			}
		}
		else if (index0 == 4)
		{
			next.s = top.s; next.step = top.step + 1;
			swap(next.s[index0], next.s[index0 + 1]);
			it = Puzzle.find(next.s);
			if (it == Puzzle.end())
			{
				Puzzle.insert(make_pair(next.s, next.step));
				Q.push(next);
			}
			next.s = top.s; next.step = top.step + 1;
			swap(next.s[index0], next.s[index0 - 4]);
			it = Puzzle.find(next.s);
			if (it == Puzzle.end())
			{
				Puzzle.insert(make_pair(next.s, next.step));
				Q.push(next);
			}
		}
		else
		{
			for (int j = 0; j < 4; j++)
			{
				next.s = top.s; next.step = top.step + 1;
				if (check(index0 + dist[j]))
				{
					swap(next.s[index0], next.s[index0 + dist[j]]);
					it = Puzzle.find(next.s);
					if (it == Puzzle.end())
					{
						Puzzle.insert(make_pair(next.s, next.step));
						Q.push(next);
					}
				}
			}
		}
	}
}
void init()
{
	Node start;
	start.s = "01234567";
	start.step = 0;
	BFS(start);
}
int main()
{
	init();
	int num;
	while (scanf("%d",&num)!=EOF)
	{
		string ss;
		ss += num + '0';
		for (int i = 1; i < 8; i++)
		{
			scanf("%d", &num);
			ss += num + '0';
		}
		printf("%d\n",Puzzle.find(ss)->second);
	}
	return 0;
}

Measured memory_bytes: 3480
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef int_fast64_t ll;
typedef int_fast32_t intt;
typedef int_fast32_t tmp_m;
#define deb(x) cout << #x << ' ' << x << endl
#define rep(i, a, b) for (tmp_m i = a; i < b; ++i)
#define repp(i, a, b) for (tmp_m i = a; i >= b; --i)
#define pb push_back
#define st stack
#define pa pair
#define vc vector
#define qu queue
#define pq priority_queue
#define fr first
#define sc second
#define mp map
const intt mod = 1e9 + 7;

struct pr {
  intt x;
  intt y;
  intt dst;
  pr() {}
  pr(intt x, intt y, intt dst) : x(x), y(y), dst(dst) {}
  inline bool operator<(const pr& b) const {
    if (dst != b.dst) return dst > b.dst;
    if (x != b.x) return x > b.x;
    return y > b.y;
  }
};

struct point {
  intt x;
  intt y;
  point() {}
  point(intt x, intt y) : x(x), y(y) {}
  inline bool operator<(const point& b) const {
    if (x != b.x) return x > b.x;
    return y > b.y;
  }
};

inline bool spoint(point a, point b) {
  if (a.x != b.x) return a.x < b.x;
  return a.y < b.y;
}

inline bool spr(pr a, pr b) {
  if (a.dst != b.dst) return a.dst < b.dst;
  if (a.x != b.x) return a.x < b.x;
  return a.y < b.y;
}



void solve() {
  intt r;
  cin >> r;
  printf("%.12lf\n", 2 * r * M_PI);
  // cout << 2 * r * M_PI << endl;
}

void init() {
  // remove if interactive
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  srand(time(0));
  // memset(dp, -1, sizeof dp);
}

int main() {
  init();
  solve();
  return 0;
}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
#define REP(i, n) for(long long i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
 
int main() {
  string s,sa,sb;
  int ans = 0;//ans 1 yymm 2 mmyy
  cin >> s;
  if ((s[0] == '1' && s[1] == '0')||(s[0] == '1' && s[1] == '1')||(s[0] == '1' && s[1] == '2' )||( s[0] == '0' && s[1]!= '0')){
    ans +=2;
  }
  if((s[2] == '1' && s[3] == '0')||(s[2] == '1' && s[3] == '1')||(s[2] == '1' && s[3] == '2' )||( s[2] == '0' && s[3]!= '0')) {
    ans += 1;
  }
  if(ans == 1) {
    cout << "YYMM";
  } else if (ans == 2) {
    cout << "MMYY";
  } else if (ans == 3) {
    cout << "AMBIGUOUS";
  } else {
    cout << "NA";
  }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

int main() {
	int P, Q, R;
	cin >> P >> Q >> R;
	cout << min(P + Q, min(Q + R, P + R)) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <time.h>
#include <string>

using namespace std;


int main()
{
	int a[5];
	int k;
	cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4] >> k;
	for (int i = 0;i < 5;i++)
	{
		for (int j = 4;j >= 0;j--)
		{
			if (j == i)
			{
				j--;
			}
			else if (i < j)
			{
				if (a[j] - a[i]>k)
				{
					cout << ":(";
					return 0;
				}
			}
			else
			{
				if (a[i] - a[j]>k)
				{
					cout << ":(";
					return 0;
				}
			}
		}
	}
	cout << "Yay!";
    return 0;
}


Measured memory_bytes: 256
/*
g++ -std=c++11 -o2 -Wall ABC113B.cpp -o .\out\ABC113B.out
.\out\ABC113B.out
*/

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main(){
//  freopen("./input/input.txt", "r", stdin);
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  int t, a;
  int h[1005];
  cin >> n;
  cin >> t >> a;
  for (int i = 0; i < n; ++i) {
    cin >> h[i];
  }
  int diff = 1000000000;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int temp = abs(1000 * t - 6 *h[i] - 1000 * a);
    if (temp < diff) {
      diff = temp;
      ans = i;
    }
  }
  cout << ans + 1 << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>

typedef long long ll;

using namespace std;

int N;
int x[10], y[10];
 
double dist(int i, int j) {
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return pow(dx * dx + dy * dy, 0.5);
}
 
void solve() {
    cin >> N;
    for(int i = 1; i <= N; i++) cin >> x[i] >> y[i];
    double sum = 0.0;
    vector<int> v(N);
    for(int i = 0; i < N; i++) v[i] = i + 1;
    do {
        for(int i = 0; i < N - 1; i++) sum += dist(v[i], v[i+1]);
    } while(next_permutation(v.begin(), v.end()));
    int Factorial = 1;
    for(int i = 2; i <= N; i++) Factorial *= i;
    cout << fixed << setprecision(10) << sum / Factorial << endl;
    return;
}
 
int main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
from itertools import accumulate
INF = 10 ** 20
n = int(input())
c_lst = []
w_lst = []
for _ in range(n):
  c, w = map(int, input().split())
  c_lst.append(c)
  w_lst.append(w)
w_acc = [0] + list(accumulate(w_lst))
connect = [[None] * n for _ in range(n)]
for i in range(n):
  connect[i][i] = True

def can_connect(left, right):
  if connect[left][right] != None:
    return connect[left][right]
  connect[left][right] = \
     ((c_lst[left] >= w_acc[right + 1] - w_acc[left + 1]) and can_connect(left + 1, right)) or \
     ((c_lst[right] >= w_acc[right] - w_acc[left]) and can_connect(left, right - 1))
  return connect[left][right]

for i in range(n):
  for j in range(i + 1, n):
    can_connect(i, j)

dp = [INF] * (n + 1)
dp[0] = 0
for i in range(n):
  for j in range(i, n):
    if connect[i][j]:
      dp[j + 1] = min(dp[j + 1], dp[i] + 1)
    else:
      break
print(dp[n])


Measured memory_bytes: 13652
#include <bits/stdc++.h>
#include <algorithm>
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 int INF = 100000; 

int main(){
    ll a, b;
    char op;
    cin >> a >> op >> b;

    if(op == '+') cout << a + b << endl;
    else if(op == '-') cout << a - b << endl;

    return 0;
}


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

int W,H;
int sy, sx, gy, gx;

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

bool movable(vector<vector<char>> &c, vector<vector<int>> &mat, int h, int w, int hb, int wb) {
  if ((h<0) || (h>=H) || (w<0) || (w>=W)) {
    return false;
  }
  else if (mat[h][w]!=INF || (c[h][w]==c[hb][wb])) {
    return false;
  }
  else {
    return true;
  }
}


ll bfs(vector<vector<char>> &c, vector<vector<int>> &mat, pair<int,int> &q) {
  ll k,s;
  s=0;
  k = 1;
  queue<P> que;
  que.push(q);
  
  if (mat[q.first][q.second] != INF) return 0;
  else (mat[q.first][q.second] = 0);

  while(que.size()) {
    P p = que.front();
    que.pop();

    rep(i,4){
      if (movable(c,mat,p.first+dy[i],p.second+dx[i],p.first,p.second)) {
        que.push(P(p.first+dy[i],p.second+dx[i]));
        mat[p.first+dy[i]][p.second+dx[i]]=mat[p.first][p.second]+1;
        if (c[p.first+dy[i]][p.second+dx[i]]=='.') s++;
        else k++;
      }
    }
  }
  return k*s;
}

int main() {
  cin >> H >> W;

  vector<vector<char>> c(H,vector<char> (W));
  vector<pair<int,int>> P;
  rep(h,H) {
      string s;
      cin >> s;
    rep(w,W) {
      c[h][w] = s[w];
      if (s[w]=='#') {
          P.push_back(make_pair(h,w));
      }
    }
  }
  vector<vector<int>> mat(H,vector<int> (W, INF));
  ll ans = 0;
  for (auto p: P) {
    ll tmp = bfs(c,mat,p);
    ans += tmp;

  }
    cout << ans << endl;
}

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

#define ll long long int
#define endl '\n'

void solve()
{
	string s,t;
	cin>>s>>t;
	int max=0,t1=0;
	int j=0;
	for(int i=0;i<=s.size()-t.size();i++)
	{
		t1 = i;
		int ans=0;
		for(ll j=0;j<t.size();j++)
		{
			if(s[i]==t[j])
				ans++;
			i++;
		}
		i=t1 ;
		//cout<<i<<endl;
	//	cout<<ans<<endl;
		if(max<ans)
			max=ans;
	}   
	//cout<<max<<' ';
	cout<<(t.size()-max);
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    #ifdef JAY
        freopen("C:/Users/jayra/Desktop/cp/input.txt","r",stdin);
        freopen("C:/Users/jayra/Desktop/cp/output.txt","w",stdout);
    #endif

    
        solve();
   
}

Measured memory_bytes: 3664
#include<stdio.h>
int main(void)
{
    int N,i,x=0;
    
    scanf("%d",&N);
    
    for(i=1;i<=N;i++)
    {
	if(i<10)
	{x++;}
	else if(i<100)
	{}
	else if(i<1000)
	{x++;}
	else if(i<10000)
	{}
	else if(i<100000)
	{x++;}
	else
	{}
    }
    printf("%d\n", x);
    
    return 0;
}

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

int main(){
    while(1){
        int x,y;
        cin >> x >> y;
        if(x==0&&y==0)break;
        
        if(x > y){
            int tmp;
            tmp = x;
            x = y;
            y = tmp;
        }
        cout << x << " " << y << endl;
    }
}


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

int main() {
	int a;
  	int b;
  cin>>a>>b;
  int seki=a*b;
  if(seki%2==0){
    cout<<"Even"<<endl;
  }else{
    cout<<"Odd"<<endl;
  }
 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;
long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}

int main(){
    int A,P;cin >> A >> P;
    cout <<  (A*3+P)/2 << endl;
    return 0;
}

Measured memory_bytes: 3620
from collections import*
z,v,a=input,range,print
h,w,k=map(int,z().split());r,s,t,u=map(lambda x:int(x)-1,z().split())
b=[z()for _ in v(h)];l=[[-1]*w for _ in v(h)];l[r][s]=0
d=deque([(r,s)])
while d:
  x,y=d.popleft();j=l[x][y]
  if(x==t)&(y==u):exit(a(j))
  for e,f in[[1,0],[-1,0],[0,-1],[0,1]]:
    for i in v(1,k+1):
      p,q=x+e*i,y+f*i
      if not((0<=p<h)&(0<=q<w))or b[p][q]=="@" or 0<=l[p][q]<=j:break
      if l[p][q]<0:d+=[(p,q)];l[p][q]=j+1
a(-1)

Measured memory_bytes: 93516
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>//for queue and priority_queue
#include <fstream>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#define endl "\n"
typedef long long ll;
using namespace std;
void Lancer() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
bool isPrime(ll n){
	if (n == 2 || n == 3 || n == 5)
		return true;
	else if (n % 2 == 0 || n % 3 == 0 || n % 5 == 0 || n == 1)
		return false;
	else {
		for (int i = 5; i <= sqrt(n); i += 2){
			if (n%i == 0)
				return false;
		}
		return true;
	}
}

char arr[57][57];
int main(){
	Lancer();
	ll n, k, res = 1;
	cin >> n >> k;
	while (n--)
	{
		if ((res + k) < (res * 2))
			res += k;
		else
			res *= 2;
	}
	cout << res;
	cout << endl;
	return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()

#define cMOD 1000000007ULL
#define cINF ((1ull<<62)-1)
#define cINFINT ((1<<30)-1)

int main()
{
    ll n; cin>>n;
    vector<ll> w( n, 0 );
    REP( i, w.size() )
    {
        cin >> w[i];
    }
    
    ll minm = 100000000;
    REP(t,n) if(t!=0)
    {
        ll sum1=0, sum2=0;
        REP(i,n)
        {
            if( i <= t ) sum1 += w[i];
            else sum2 += w[i];
        }
        minm = min(minm, abs(sum1-sum2));
    }

    cout << minm << endl;
    return 0;
}

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


using namespace std;
double pi=3.14159265358979323846264338;


inline void ex(){cout<<"NO"<<endl;exit(0);}
long long a,b,c,d;
const long long N=1000000007;
long long arr[2001];
long long n;
long long mpow(long long a, long long b){
	long long cur=a;
	long long ans=1;
	for(;;){
		if(b==0)return ans;
		if(b&1){
			ans=ans*cur%N;

		}
		b=b>>1;
		cur=cur*cur%N;
	}
}
long long ch(long long a,long long b){
	if(b==0)return 1;
	if(a==b)return 1;
	long long k=arr[b]*arr[a-b]%N;

	k=mpow(k,N-2);

	return k*arr[a]%N;
}
int main(){
	arr[1]=1;
	for(int i=2;i<=2000;i++)arr[i]=i*arr[i-1]%N;
	long long cnt=0;
	cin>>n;
	for(int i=1;i*3<=n;i++){
		cnt+=ch(n-3*i+i-1,i-1);
		//cout<<cnt<<endl;
		cnt=cnt%N;
	}
	cout<<cnt<<endl;
	return 0;
			
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1e9+7;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

int main(){
    ll N;
    string S;
    cin >> N >> S;
    if (S[0]=='W'||S[2*N-1]=='W'){
        cout << 0 << endl;
        return 0;
    }
    vector<ll> dp(2*N);
    dp[0]=1;
    ll now=1;
    rep2(i,1,2*N){
        dp[i]=dp[i-1];
        if (S[i]=='B'&&now%2==0) ++now;
        else if (S[i]=='W'&&now%2==1) ++now;
        else{
            dp[i]=dp[i]*now%MOD;
            --now;
            if (now<0){
                cout << 0 << endl;
                return 0;
            }
        }
    }
    if (now!=0){
        cout << 0 << endl;
        return 0;
    }
    ll ans=dp[2*N-1];
    rep(i,N) ans=ans*(i+1)%MOD;
    cout << ans << endl;
}

Measured memory_bytes: 2180
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 1000000007
#define i_5 1000000005

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
#define inf 100000000/*10^8*/
#define rep(i,l,r) for(int i=l;i<=r;i++)
const double EPS=1E-8;

////////////////////////////////////////


int main(){
    int n;cin>>n;
    int a[n+2];rep(i,1,n)cin>>a[i];a[0]=0;a[n+1]=0;
    
    ll sum=0;
    rep(i,0,n){
        sum+=abs(a[i+1]-a[i]);
    }
    rep(i,1,n){
        if((a[i]-a[i-1])*(a[i+1]-a[i])>=0)cout<<sum<<endl;
        else{
            int b=abs(a[i+1]-a[i]),c=abs(a[i]-a[i-1]);
            if(b>c)swap(b,c);
            cout<<sum-2*b<<endl;
        }
    }
    
    
    return 0;
}


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

int main() {

  int n;
  cin >> n;
  vector<vector<int>> a(n, vector<int>(3));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 3; ++j) {
      cin >> a[i][j];
    }
  }
  vector<vector<int>> dp(n, vector<int>(3, 0));
  dp[0] = a[0];
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < 3; ++j) {
      for (int k = 0; k < 3; ++k) {
        if (k != j) {
          dp[i][j] = max(dp[i][j], dp[i-1][k] + a[i][j]);
        }
      }
    }
  }
  cout << *max_element(dp[n-1].begin(), dp[n-1].end()) << '\n';
  return 0;
}


Measured memory_bytes: 14044
#include <iostream>
using namespace std;
#define rep(i,N) for (long i = 0; i <=N; i++)
int main(){
        long N,Y; cin >> N >> Y;
        long k;
        rep(i,N) rep(j,N){
                k=Y/1000-10*i-5*j;
                if(i+j+k == N && i >=0 && j>=0 && k>=0) {
                        printf("%ld %ld %ld\n",i,j,k);;
                        return 0;
                }
        }
        cout << "-1 -1 -1" << endl;

        return 0;
}

Measured memory_bytes: 384
using System;

namespace abc065A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            long X = long.Parse(str[0]);
            long A = long.Parse(str[1]);
            long B = long.Parse(str[2]);
            long Ans = X - (B - A);
            if (Ans >= 0 && A >= B)
                Console.WriteLine("delicious");
            else if (Ans >= 0 && A < B)
                Console.WriteLine("safe");
            else
                Console.WriteLine("dangerous");
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main() {
	int N, a[1001];
	cin >> N;
	for (int i = 0; i < N; ++i) cin >> a[i];

	ll x = 0, y = 0;
	vi u, v;
	for (int i = 0; i < N; ++i) {
		if (a[i] > 0) {
			if (i & 1) {
				x += a[i];
				u.pb(i);
			}
			else {
				y += a[i];
				v.pb(i);
			}
		}
	}
	if (x < y) x = y, u = v;
	if (!x) x = *max_element(a, a + N);
	if (u.empty()) u.pb(max_element(a, a + N) - a);
	vi ans;
	int idx = -1;
	for (int i = 0; i < u.front(); ++i, ++idx) ans.pb(i - idx);
	for (int i = 0; i < u.size() - 1; ++i) {
		for (int j = (u[i + 1] + u[i]) >> 1; j < u[i + 1]; ++j, idx += 2) ans.pb(j - idx);
	}
	for (int i = N - 1; i > u.back(); --i) ans.pb(i - idx);
	cout << x << '\n' << ans.size() << '\n';
	for (auto& x : ans) cout << x << '\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <string.h>
#include <cstdlib>
#include <iomanip>
#include <stdio.h>

using namespace std;

class Dice {
  private:
   int face[6];

  public:
    int getTop();
    int getFace(int);
    void setFace(int label,int value);
    void turnOver(char dir);
    void debugOut();
};

int Dice::getTop(){
  return face[0];
}

int Dice::getFace(int i){
  return face[i];
}

void Dice::setFace(int label,int value){
  if(label>5) return;
  face[label] = value;
}

void Dice::turnOver(char c){
  int tmp;
  if(c=='N'){
    tmp = face[0];
    face[0] = face[1]; face[1] = face[5];
    face[5] = face[4]; face[4] = tmp; // face[0]
  }

  if(c=='S'){
    tmp = face[0];
    face[0] = face[4]; face[4] = face[5];
    face[5] = face[1]; face[1] = tmp; //face[0]
  }

  if(c=='E'){
    tmp = face[0];
    face[0] = face[3]; face[3] = face[5];
    face[5] = face[2]; face[2] = tmp; //face[4]
  }

  if(c=='W'){
    tmp = face[0];
    face[0] = face[2]; face[2] = face[5];
    face[5] = face[3]; face[3] = tmp; //face[4]
  }
}

void Dice::debugOut(){
    for(int i=0;i<6;i++)
      printf("%d,",face[i]);
    putchar('\n');
}

int main(){
  Dice dice;
  int l,n,t,f,count_n=0;

  for(int i=0;i<6;i++){
      scanf("%d ",&l);
      dice.setFace(i,l);
  }
  scanf("%d\n",&n);
  for(int i=0;i<n;i++){
     scanf("%d %d",&t,&f);
     for(;;){
       //dice.debugOut();
       if(dice.getFace(0) == t) {
        if(dice.getFace(1) == f) {
         printf("%d\n",dice.getFace(2));
         break;
        }else{
          dice.turnOver('W');
          dice.turnOver('S');
          dice.turnOver('E');
        }

      } else {
        if(count_n<3){
          dice.turnOver('N');
           count_n++;
        } else {
          count_n=0;
          dice.turnOver('E');
        }
      }
    }
  }
}



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

int main()
{
	int a1, a2, a3;
	cin >> a1 >> a2 >> a3;

	if( a1 + a2 + a3 >= 22 )
		cout << "bust" << endl;
	else
		cout << "win" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int out[101]={0};
	int n;
	while(cin>>n)out[n]++;
	int ma=0;
	rep(i,100)ma=max(ma,out[i]);
	rep(i,100)if(ma==out[i])cout<<i<<endl;
}

Measured memory_bytes: 1160