akhauriyash/Code-Regression huggingface dataset:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    d = defaultdict(lambda : 0)
    for i in a:
        d[i] += 1
    s = 0
    for i,j in d.items():
        s += j*(j-1)>>1
    for i in a:
        j = d[i]
        print(s-(j*(j-1)>>1)+((j-1)*(j-2)>>1))
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 82892
# ABC136d
import sys
import re
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

s = input()
l = re.findall("R+L+", s)
ans = []

# print(l)

for i in l:
    R = math.ceil((i.count("R")-1)/2) + math.ceil(i.count("L")/2)
    L = math.ceil(i.count("R")/2) + math.ceil((i.count("L")-1)/2)
    #print(i, R, L)
    for j in range(len(i)):
        if (i[j] == "R" and i[j + 1] == "L"):
            ans.append(L)
            ans.append(R)
            j += 1
        elif(not(i[j] == "L" and i[j - 1] == "R")):
            ans.append(0)
print(*ans)


Measured memory_bytes: 9716
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    vs = [int(x) for x in stdin.readline().rstrip().split()]
    vs = sorted(vs)
    for _ in range(N - 1):
        new = (vs[0] + vs[1]) / 2
        vs = vs[2:]
        vs.append(new)
        vs.sort()
    print(vs[0])


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
# -*- coding:utf8 -*-

n, x = map(int, input().split())
l = list(map(int, input().split()))
ans = 1
d = 0
for i in range(n):
    di = d + l[i]
    if di <= x:
        ans += 1
        d = di
    else:
        break
print(ans)



Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	long long int a,b,x,val,val2;
	cin>>a>>b>>x;
	if(x<b)
		{
			val=(a*x)/b;
			cout<<val;
			return 0;
		}
	else {
		val=(a*(b-1))/b;
		cout<<val;
	}
    return 0;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

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

	int N=in();
	if(N==1){
		cout << "Hello World" << endl;
		return 0;
	}
	cout << (in()+in()) << endl;
	return 0;
}


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

int main(void) {
    int N;
    cin >> N;
    int N_digit = 1;
    int nr = N % 10;
    int nl = N;
    while (nl >= 10) {
        nl /= 10;
        N_digit *= 10;
    }
    unsigned int count = 0;
    for (int i = 1; i <= N; i++) {
        int l, r;
        r = i % 10;
        if (r == 0) {
            continue;
        }
        l = i;
        while (l >= 10) {
            l /= 10;
        }
        // one digit
        if (l == r) {
            ++count;
            // printf("(%d,%d),", i, l);
        }
        // more than one digit
        for (int digit = 10;; digit *= 10) {
            int B = digit * r + l;
            if (digit < N_digit) {
                count += digit / 10;
                // printf("(%d,%d) * %d,", i, B, digit / 10);
            } else if (B > N) {
                break;
            } else if (nl == r) {
                int bc = count;
                count += (N - nr - nl * N_digit) / 10 + 1;
                if (nr < l) {
                    --count;
                }
                // printf("(%d,%d) + %d,", i, B, count - bc);
                break;
            } else {
                count += digit / 10;
                // printf("(%d,%d) / %d,", i, B, digit / 10);
                break;
            }
        }
    }
    printf("%d\n", count);
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define ppb pop_back
#define INF 1e18
typedef long long ll;

using namespace std;

int main(int argc,char* argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    ll n;cin>>n;
    ll count = n/11;
    count *= 2;
    n %= 11;
    while(n>=6){n-=6;count++;}
    while(n>=5){n-=5;count++;}
    while(n>=4){n-=4;count++;}
    while(n>=3){n-=3;count++;}
    while(n>=2){n-=2;count++;}
    while(n>=1){n-=1;count++;}

    cout<<count<<endl;

    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i, N) A.at(i) = pow(10, 7);
  for (int i = 0; i < N - 1; i++) {
    int x;
    cin >> x;
    A.at(i) = min(x, A.at(i));
    A.at(i + 1) = min(x, A.at(i + 1));
  }
  int64_t sum = 0;
  rep(i, N) sum += A.at(i);
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#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()
#define ins insert
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int x,y;
	cin>>x>>y;
	if((y-2*x)%2==0&&((4*x-y)%2==0&&(4*x-y>=0)&&(y-2*x>=0))){
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
	
	
	
	    
	return 0;
}

Measured memory_bytes: 3624
N = int(input())
A = list(map(int,input().split()))
cnt4, cnt2 = 0, 0
for a in A:
  if a%4==0: cnt4 += 1
  elif a%2==0: cnt2 += 1

cnt2 = cnt2 if cnt2%2==0 else cnt2-1
print('Yes' if (N-cnt2)//2<=cnt4 else 'No')

Measured memory_bytes: 62576
mod=10**9+7
n=int(input())
a=list(map(int,input().split()))
l=[0 for i in range(60)]
for x in a:
    x=bin(x)[2:]
    col=0
    for b in x[::-1]:
        if b=='1':
            l[col] = l[col]+1
        col+=1
l2=[0 for i in range(60)]
for x in a:
    x=bin(x)[2:]
    x=x.zfill(60)
    col=0
    for b in x[::-1]:
        if b=='0':
            l2[col] = l2[col] + l[col]
        else:
            l2[col] = l2[col] + n - l[col]
        col+=1
cnt=0
c=1
for i in range(60):
    cnt+=l2[i]*c
    c*=2
    c%=mod
print(cnt//2%mod)

Measured memory_bytes: 123056
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <bitset>
#include <tuple>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i <(int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i,k,n) for (int i = (int)(n)-1; i >= k; i--)
#define INF 1LL<<61
int main(){
   int n,k;
   cin >> n >> k;
   int ans = 0;
   rep(i,n){
       int h;
       cin >> h;
       if(h>=k) ans++;
   }
   cout << ans << endl;
   
    return 0;
}


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

int main()
{
	string s;
	cin >> s;
	reverse(s.begin(), s.end());
	auto pat = vector<string>({ "dream", "dreamer", "erase", "eraser" });
	for(auto&& p : pat) reverse(p.begin(), p.end());
	int t = 0;
	bool match = true;
	while(match && t < (int)s.size()){
		match = false;
		for(auto i = 0; i < 4; ++i){
			if(s.substr(t, (int)pat[i].size()) == pat[i]){
				match = true;
				t += (int)pat[i].size();
				break;
			}
		}
	}
	cout << (t == (int)s.size() ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 512
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

int main(void){
    int X, Y; cin >> X >> Y;
    if (4 * X - Y >= 0 && -2 * X + Y >= 0 && (4 * X - Y) % 2 == 0 && (-2 * X + Y) % 2 == 0)
        cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3672
import java.util.*;

public class Main {
    static Scanner sc;

    public void main() {
        int n = sc.nextInt();

        String left = query(0);
        String right = query(n - 1);

        int l = 0;
        int r = n - 1;
        while (true) {
            int id = (l + r) / 2;
            String tmp = query(id);

            if (((r - id) % 2 == 0) == (tmp.equals(right))) {
                r = id;
                right = tmp;
            } else {
                l = id;
                left = tmp;
            }
        }
    }

    private String query(int id) {
        System.out.println(id);
        System.out.flush();

        String response = sc.next();
        if (response.equals("Vacant")) {
            System.exit(0);
        }

        return response;
    }

    public static void main(String[] args) {
        sc = new Scanner(System.in);
        new Main().main();
        sc.close();
    }
}


Measured memory_bytes: 25636
/*
██╗  ██╗ █████╗ ██████╗ ███████╗███████╗███╗   ███╗        ██╗  ██╗██╗  ██╗ █████╗ ██╗     ███████╗██████╗
██║ ██╔╝██╔══██╗██╔══██╗██╔════╝██╔════╝████╗ ████║        ██║ ██╔╝██║  ██║██╔══██╗██║     ██╔════╝██╔══██╗
█████╔╝ ███████║██████╔╝█████╗  █████╗  ██╔████╔██║        █████╔╝ ███████║███████║██║     █████╗  ██║  ██║
██╔═██╗ ██╔══██║██╔══██╗██╔══╝  ██╔══╝  ██║╚██╔╝██║        ██╔═██╗ ██╔══██║██╔══██║██║     ██╔══╝  ██║  ██║
██║  ██╗██║  ██║██║  ██║███████╗███████╗██║ ╚═╝ ██║███████╗██║  ██╗██║  ██║██║  ██║███████╗███████╗██████╔╝
╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚══════╝╚═╝     ╚═╝╚══════╝╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚══════╝╚═════╝
Believe in yourself ,( try and try and then try ), You can do it  
*/
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#define endl "\n"
#define Ceil(x,y) ((x+y-1)/y)
#define clr(arr, x) memset(arr, x, sizeof arr)
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define rt(s) return cout<<s,0
#define watch(x) cout<<(#x)<<" = "<<x<<endl
#define sz(s)	(int)(s.size())
#define OO 0x3f3f3f3f3f3f3f3fLL
const int oo = 0x3f3f3f3f, mod = 1e9 + 7;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//x = xDegrees*3.14159265 / 180;
//ef1tn=(( (n / 2)*( (n / 2) + 1) / 2) * 2);
//of1tn=(n * (n + 1) / 2 - 2 * ((n / 2) * (n / 2 + 1) / 2));
int dx[] { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy[] { 0, 0, 1, -1, 1, -1, 1, -1 };
void K_K(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
ll gcd(ll a, ll b) {
	return b == 0 ? abs(a) : gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
int n, w;
vector<pair<ll,ll>>arr;
ll dp[101][100005];
ll sol(int idx, int cap){
	if (cap < 0)
		return -oo;
	if (idx == n)
		return 0;
	ll &ret = dp[idx][cap];
	if (~ret)
		return ret;
	return ret = max(sol(idx + 1, cap), sol(idx + 1, cap - arr[idx].first) + arr[idx].second);
}
int main(){
	K_K();
	cin >> n >> w;
	arr.resize(n);
	clr(dp, -1);
	for (int i = 0; i < n; i++)
		cin >> arr[i].first >> arr[i].second;
	cout << sol(0, w);
}

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);


int main() {
	
	FAST;
	
	string s;
	cin >> s;
	int ans = 0, cur = 0;
	for (int i = 0; i < s.length(); i ++) {
		if (s[i] == 'R') cur ++;
		else {
			ans = max(ans, cur);
			cur = 0;
		}
 	}
 	ans = max(ans, cur);
 	cout << ans << '\n';
 	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  int k,x;
  int a=0;
  cin >> k >> x;
  a=k;
  k-=1;
  x-=k;
  for(int i=0;i<(a+a)-1;i++){
    cout << x << flush;
    cout << " " << flush;
    x++;
  }
  cout << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4") // wonderful

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


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


    int h, a; cin >> h >> a;

    int res = h/a;

    if (h % a != 0)
        res++;

    cout << res;


    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{   
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      for(int i=1;i<=50000;i++){
        double t = i*1.08;
        if((int)t==n){
          System.out.println(i);
          return;
        }
      }
      System.out.println(":(");
    }
    public static int lcm(int x, int y){
      return x*y/gcd(x,y);
    }
    public static int gcd(int x, int y){
      if(x < y)return gcd(y,x);
      if(y==0)return x;
      return gcd(y,x%y);
    }
}

Measured memory_bytes: 20820
from collections import defaultdict
from itertools import product, groupby
from math import pi
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = 10 ** 10


def main():
    K = int(input())
    a = [i + (K // 50) for i in range(50)]
    for i in range(K % 50):
        for j in range(50):
            a[j] += 50 if i == j else -1
    print(50)
    print(*a)


if __name__ == '__main__':
    main()


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  int N = nextLong();
  if (N % 1000) {
    cout << (1000 - N % 1000) << endl;
  } else {
    cout << 0 << endl;
  }
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;

const int MOD = 1000000007;

int main() {
    int N;
    cin >> N;
    vector<int> odd(100001);
    vector<int> even(100001);
    for (int i = 0; i < N; i++) {
        int n;
        cin >> n;
        if (i % 2 == 0) {
            even[n]++;
        } else {
            odd[n]++;
        }
    }

//    int maxEven = 0;
//    int maxEvenNum = 0;
//    int maxEven2 = 0;
//    for (int i = 0; i < even.size(); i++) {
//        if (maxEven < even[i]) {
//            maxEven2 = maxEven;
//            maxEvenNum = i;
//            maxEven = even[i];
//        } else if (maxEven2 < even[i]) {
//            maxEven2 = even[i];
//        }
//    }
//
//
//    int maxOdd = 0;
//    int maxOddNum = 0;
//    int maxOdd2 = 0;
//    for (int i = 0; i < odd.size(); i++) {
//        if (maxOdd < odd[i]) {
//            maxOdd2 = maxOdd;
//            maxOddNum = i;
//            maxOdd = odd[i];
//        } else if (maxOdd2 < odd[i]) {
//            maxEven2 = odd[i];
//        }
//    }

//    if (maxEvenNum == maxOddNum) {
//        int maxNum = maxOdd + maxEven2;
//        chmax(maxNum, maxOdd2 + maxEven);
//        cout << N - maxNum << endl;
//    } else {
//        cout << N - (maxEven + maxOdd) << endl;
//    }

    priority_queue<int> e_que;
    int maxEvenNum = 0;
    for (int i = 0; i < even.size(); i++) {
        if (even[i] == 0) continue;

        if (e_que.empty() || e_que.top() < even[i]) {
            maxEvenNum = i;
        }
        e_que.push(even[i]);
    }

    priority_queue<int> o_que;
    int maxOddNum = 0;
    for (int i = 0; i < odd.size(); i++) {
        if (odd[i] == 0) continue;

        if (o_que.empty() || o_que.top() < odd[i]) {
            maxOddNum = i;
        }
        o_que.push(odd[i]);
    }

    int maxEven = e_que.top();
    e_que.pop();
    int maxEven2 = 0;
    if(!e_que.empty()) {
        maxEven2 = e_que.top();
    }

    int maxOdd = o_que.top();
    o_que.pop();
    int maxOdd2 = 0;
    if(!o_que.empty()) {
        maxOdd2 = o_que.top();
    }


    if (maxEvenNum == maxOddNum) {
        int maxNum = maxOdd + maxEven2;
        chmax(maxNum, maxOdd2 + maxEven);
        cout << N - maxNum << endl;
    } else {
        cout << N - (maxEven + maxOdd) << endl;
    }
}

Measured memory_bytes: 1660
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>

using namespace std;

typedef long long ll;

int main() {
    int n, m;
    ll ans = 0;
    scanf("%d%d", &n, &m);
    vector< vector<ll> > d(n, vector<ll>(3));
    vector<ll> sum(n);
    for (int i = 0; i < n; ++i) for (int j = 0; j < 3; ++j) scanf("%lld", &d.at(i).at(j));
    for (int i = 0; i < (1 << 3); ++i) {
        for (int j = 0; j < n; ++j) {
            sum.at(j) = 0;
            for (int k = 0; k < 3; ++k) sum.at(j) += d.at(j).at(k) * ((i >> k << 1 & 2) - 1);
        }
        sort(sum.begin(), sum.end(), greater<ll>());
        ans = max(ans, accumulate(sum.begin(), sum.begin() + m, 0LL));
    }
    printf("%lld\n", ans);
    return 0;
}


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

#define long long long int

using namespace std;

// @author: pashka

int main() {
    ios::sync_with_stdio(false);

    double a, b, x;
    cin >> a >> b >> x;

    // (b + y) == x / a / a * 2

    double y = x / a / a * 2 - b;
    double ans;
    if (y >= 0) {
        ans = atan2(b - y, a);
    } else {
        // y * b / 2 == x / a
        y = x / a * 2 / b;
        ans = atan2(b, y);
    }
    ans = ans / M_PI * 180;
    cout << setprecision(20) << 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();
        int k = sc.nextInt();
        int[] h = new int[n];
        int ans = 0;
        for (int i = 0;i < n; i++) {
            if (sc.nextInt() >= k) ans++;
        }
        System.out.println(ans);
        
    }
}


Measured memory_bytes: 48748
#include <cstdio>
#define N 10000001
typedef long long ll;
ll s[N];
int max_v[N];
int main(void)
{
	int n;
	scanf("%d", &n);
	int i, j, k;
	for (i = 1; s[i - 1] <= n; ++i) {
		s[i] = s[i - 1] + i;
		max_v[s[i]] = i;
	}
	k = i;
	for (i = 1; i < k; ++i) {
		if (s[i - 1] < n && n <= s[i]) {
			int exc = s[i] - n;
			for (j = 1; j <= max_v[s[i]]; ++j) {
				if (j != exc) printf("%d\n", j);
			}
		}
	}
}


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

#define debug(x) cerr << #x << " = " << x << '\n';
#define PR(A, n) cerr << #A << " = "; for (int i=1; i<=n; ++i) cerr << A[i] << ' '; cerr << '\n';
#define PR0(A, n) cerr << #A << " = "; for (int i=0; i<n; ++i) cerr << A[i] << ' '; cerr << '\n';

const int maxn = 100002;

int n, m, a[maxn], nCC;
vector<int> CC[maxn], g[maxn], p;
bool visited[maxn];

void visit(int u) {
	visited[u] = true;
	CC[nCC].push_back(a[u]);
	for (int i=0; i<g[u].size(); ++i) {
		int v = g[u][i];
		if (!visited[v])
			visit(v);
	}
}

int main() {
	//freopen("C.inp", "r", stdin);
	//freopen("C.out", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> m;
	for (int i=1; i<=n; ++i)
		cin >> a[i];
	for (int i=1; i<=m; ++i) {
		int u, v; cin >> u >> v;
		++u; ++v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	for (int i=1; i<=n; ++i)
		if (!visited[i]) {
			++nCC;
			visit(i);
		}
	if (nCC==1) {
		cout << 0;
		return 0;
	}
	int64_t res = 0;
	for (int i=1; i<=nCC; ++i) {
		sort(CC[i].begin(), CC[i].end());
		res += CC[i][0];
		for (int j=1; j<CC[i].size(); ++j)
			p.push_back(CC[i][j]);
	}
	sort(p.begin(), p.end());
	if (p.size()<nCC-2)
		cout << "Impossible";
	else {
		for (int i=0; i<nCC-2; ++i)
			res += p[i];
		cout << res;
	}
}

Measured memory_bytes: 9852
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;
#define all(x) (x).begin(),(x).end()

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll fac(ll n){
    ll t = 1;
    rep1(i, n + 1)t *= i;
    return t;
}

int main()
{
    ll n,cnt = 0,a;
    cin >> n;
    rep0(i, n){
        cin >> a;
        if (a % 2 == 1) {
            ++cnt;
        }
    }
    if (cnt % 2 == 0) {
        YES;
    }else{
        NO;
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  LL N; std::cin >> N;

  LL total = 0;
  for (LL i = 1; i*i <= N; ++i) {
    if (N%i == 0) {
      LL a = i - 1;
      LL b = N/i - 1;

      if (a>0 && N/a == N%a) total += a;
      if (b>0 && N/b == N%b) total += b;
    }
  }

  std::cout << total << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma gcc optimize("ofast")
using namespace std;

#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define mod 1000000007
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0);
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;

ll modexp(ll a,ll b,ll m)
{
	ll r=1;
	a=a%m;
	while(b>0)
	{
	if(b&1)
		r=(r*a)%m;
	b=b/2;
	a=(a*a)%m;
	}
	return r%m;
}


int main() {
   ll n; cin>>n;
   while(1)
   {
       ll flag = 0;
       for(ll i = 2;i<=sqrt(n);i++)
       {
           if(n%i==0)
           {
               flag = 1;
           }
       }
       if(!flag)
       {
           cout<<n<<endl;
           return 0;
       }
       n++;
   }
   return 0;
}
/*

*/


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

int main()
{
    int N;
    cin >> N;
    vector<int> pos_lst(N); int total = 0;
    for(int &x: pos_lst)
    {
        cin >> x;
        total += x;
    }

    int center = round((float)total / N); total = 0;
    for(int &x: pos_lst) total += pow(x - center, 2);
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define vb vector<bool>
#define vs vector<string>
#define px(x) cout << x << endl
#define pfi(x) printf("%d\n", x)
#define pfs(x) printf("%s\n", x)
#define sfi(x) scanf("%d", &x)
#define sfs(x) scanf("%s", x)


int main(int argc, char const *argv[])
{          
   string s;
   cin >> s;

   int ca = 0;
   int cb = 0;

   for(int i=0; i<s.length(); i++){
    if(s[i] == 'A'){
        ca += 1;
    }else if(s[i] == 'B'){
        cb += 1;
    }
   }

   if(ca == 2 && cb == 1){
    cout << "Yes";
   }else if(ca == 1 && cb ==2){
    cout << "Yes";
   }else{
    cout << "No";
   }






    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long N;
  cin >> N;
  string ret;
  rep (i, N) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if (i == 0) {
      ret = s;
      continue;
    }
    long x = 0;
    long y = 0;
    vector<char> cvec;
    while (x < ret.size() and y < s.size()) {
      if (ret[x] == s[y]) {
        cvec.push_back(ret[x]);
        x++;
        y++;
      } else if (ret[x] < s[y]) x++;
      else if (ret[x] > s[y]) y++;
    }
    ret = string(cvec.begin(), cvec.end());
  }
  cout << ret << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
// AtCoder Beginner Contest 100
// C - *3 or /2
#include <bits/stdc++.h>
using namespace std;

#define IEF(i, s, t)    for(int i=s; i<t; i++)
#define NEF(i, s, t)    for(int i=s; i>=t; i--)
#define MAXN 100005
#define ll long long

int main(){
    ios_base::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll>arr(N);
    IEF(i, 0, N)
    {
        cin >> arr[i];
    }
    
    ll ans = 0;
    
    IEF(i, 0, N){
        while(arr[i] % 2 == 0){
            ans++;
            arr[i] /= 2;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(int argc, char const *argv[]) {
	char str[101];
	int n, m, k;
	int ans;

	int d10;

	fgets(str, 100, stdin);
	sscanf(str, "%d %d %d\n", &n, &m, &k);

	d10 = n;
	d10 = m > d10 ? m : d10;
	d10 = k > d10 ? k : d10;

	ans = d10*10 - d10 + n + m + k;

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

	return 0;
}


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

set<string> S;
string f(char c){
	if( c == 'A' ) return "BB";
	else return "AA";
}
void solve(string s,int step=4){
	if( step < 0 ) return;
	if( S.count(s) ) return;
	else S.insert(s);

	for(int i = 0 ; i < s.size() ; i++){
		string t = s.substr(0,i) + f(s[i]) + s.substr(i+1);
		solve(t,step-1);
	}
	for(int i = 0 ; i+2 < s.size() ; i++){
		if( s[i] == s[i+1] and s[i+1] == s[i+2] ){
			string w = s.substr(0,i) + s.substr(i+3);
			solve(w);
		}
	}
}


vector<int> sumarr(string S,char c){
	vector<int> r;
	r.push_back(0);
	int sum = 0;
	for(int i = 0 ; i < S.size() ; i++){
		sum += S[i] == c;
		r.push_back(sum);
	}
	return r;
}
void solve(string S, string T, long long q, vector<long long> a, vector<long long> b, vector<long long> c, vector<long long> d){
	/*
	solve("A");
	vector<string> sss(::S.begin(),::S.end());
	sort(sss.begin(),sss.end(),[&](string a,string b){return a.size() < b.size(); });
	int len = 0;
	string p = "";
	for( auto s : sss ){
		if( p.size() != s.size() ) len = 0;
		len++;
		cout << s << " " << len << endl;
		p = s;
	}
	g(1,1);
	for( auto G : w)
		cout << G.first << " " << G.second << endl;
	*/
	auto sa = sumarr(S,'A');
	auto sb = sumarr(S,'B');
	auto ta = sumarr(T,'A');
	auto tb = sumarr(T,'B');
	
	for(int i = 0 ; i < a.size() ; i++){
		int cAs = sa[b[i]] - sa[a[i]-1];
		int cBs = sb[b[i]] - sb[a[i]-1];
		int cAt = ta[d[i]] - ta[c[i]-1];
		int cBt = tb[d[i]] - tb[c[i]-1];
		int y = 0;
		//cout << cAs << " " << cBs << "|" << cAt << " " << cBt << endl;
		for(int j = 0 ; j < 4 ; j++){
			if( (cAs + j * 2) % 3 == cAt % 3 ){
				if( (cBs + j * 2 ) % 3 == cBt % 3 ){
					y = 1;
				}
			}
		}
		if(y) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

int main(){	
	string S;
	long long q;
	string T;
	cin >> S;
	cin >> T;
	scanf("%lld",&q);
	vector<long long> d(q-1+1);
	vector<long long> a(q-1+1);
	vector<long long> c(q-1+1);
	vector<long long> b(q-1+1);
	for(int i = 0 ; i <= q-1 ; i++){
		scanf("%lld",&a[i]);
		scanf("%lld",&b[i]);
		scanf("%lld",&c[i]);
		scanf("%lld",&d[i]);
	}
	solve(S, T, q, a, b, c, d);
	return 0;
}


Measured memory_bytes: 11048
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class Hello{
    public static void Main(){
        // Your code here!
        //var n = int.Parse(Console.ReadLine());
        int n = int.Parse(Console.ReadLine());
        //var t = Console.ReadLine();
        int ans = 0;
        if(n > 1000){
            n = n % 1000;
        }
        if(n == 0){
            ans = 0;
        }else{
            ans = 1000 - n;
        }
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 17540
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

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

using namespace std;
using ll = long long;

const ll mod = 1000000007;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
// bool debug=false;

/*---------------------------------------------------*/

int main() {
  int N, Q;
  string S;
  int data[100005] = {};
  cin >> N >> Q;
  cin >> S;
  
  for(int i = 0; i < S.size(); i++) {
    if(S[i] == 'A' && S[i + 1] == 'C') {
      data[i + 1]++;
    }
  }
  for(int i = 1; i < S.size(); i++) data[i] += data[i - 1];

  
  int l, r;
  for(int i = 0; i < Q; i++) {
    cin >> l >> r;
    l--; r--;
    cout << data[r] - data[l] << endl;
  }
  return 0;
}


Measured memory_bytes: 1408
import scala.io.StdIn._

object Main extends App {
  val n: Long = readLine.toLong
  val a: Array[Long] = (1 to 5).map(_ => readLine.toLong).toArray
  val min_v: Long = a.min
  val cnt = if (n % min_v > 0) n / min_v + 1 else n / min_v
  println(cnt+4)
}

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

using namespace std;

#define db(x) cout << (x) << '\n';
#define all(x) x.begin(),x.end()
#define UNIQUE(x) sort(all(x)),x.resize(unique(all(x))-x.begin())
#define LB(v,x) lower_bound(all(v),x)
#define UB(v,x) upper_bound(all(v),x)
#define endl "\n"
#define F first
#define S second
#define PB push_back
#define PF push_front
#define int long long
#define double long double
#define trick int m = (l+r)>>1,lc=n<<1,rc=lc|1

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;

int dy[]={0,1,1,1,0,-1,-1,-1};
int dx[]={-1,-1,0,1,1,1,0,-1};
const int maxn = 1e5;
const int OO = 1e18;
const int mod = 1e9 + 7;
const double PI = acos(-1);

void maxself(int &a,int b)
{a=max(a,b);}
void minself(int &a,int b)
{a=min(a,b);}

vector<vi> g(maxn);
int n;
int left(int i,vector<bool> &mk)
{
    for(int j=i-1;j>=0;j--)
    {
        if(mk[j]==0)
            return j;
    }
}
int right(int i,vector<bool> &mk)
{
    for(int j=i+1;j<n;j++)
    {
        if(mk[j]==0)
            return j;
    }
}

int32_t main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

//	freopen("name.in","r",stdin);
//	freopen("name.out","w",stdout);

    int x,n;
    cin >> x >> n;
    int a[n];
    for(int i=0;i<n;i++)
        cin >> a[i];
    for(int i=0;i<=200;i++)
    {
        int neg = x - i;
        int pos = x + i;
        bool A=1,B=1;
        for(int j=0;j<n;j++)
        {
            if(neg == a[j])
                A = 0;
                
            if(pos == a[j])
                B = 0;
        }
        if(A)
        {
            cout << neg;
            return 0;
        }
        if(B)
        {
            cout << pos;
            return 0;
        }
    }

	return 0;
}



Measured memory_bytes: 5448
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{   int max(int a,int b);
int max1(int x,int y,int z);
    int a,b,c,n,m;
    int answer,s1,s2,s3;
    while(cin>>a>>b>>c>>n>>m)
    {
        if(n>m)
        {
            s1=(n-(n-m))*2*c+(n-m)*a;
            s2=n*c*2;
        }
        else
        {
         s2=m*c*2;

        s1=(m-(m-n))*2*c+(m-n)*b;
        }
        s3=m*b+n*a;

     answer=max1(s1,s2,s3);
        cout<<answer<<endl;


    }
}
int max(int a,int b)
{
    return a<b?a:b;
}
int max1(int x,int y,int z)
{   int a;
     a=max(x,y);
    return a<z?a:z;
}

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

int n;
double a[105],s=0;

int main(void){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lf",&a[i]);
		s+=(1.0/a[i]+0.0);
	}
	printf("%.14lf",1.0/s);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  int64_t n;
  cin>>n;
  std::vector<int64_t> d(n);
  for(auto&& e: d) {
    cin>>e;
  }
  int64_t ans=0;
  for (int i = 0; i < n; ++i)
  {
    for (int j = 0; j < n; ++j)
    {
      if(i==j) continue;
      ans+=d[i]*d[j];
    }
  }
  cout<<ans/2;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
typedef long long ll;
int main(){
	string s;
	cin>>s;
	ll cnt[26]={};
	for(char c:s) cnt[c-'a']++;
	ll ans = 1;
	rep(i,26) rep(j,i) ans += cnt[i]*cnt[j];
	cout<<ans<<endl;
}


Measured memory_bytes: 640
K = int(input())
A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(A[K-1])


Measured memory_bytes: 3316
#include <stdio.h>
#include <math.h>

int main() {
  int number_n, number_k, i, j;
  scanf("%d %d", &number_n, &number_k);
  double probability = 1.0, sum_probability = 0.0;
  for(i = 1; i <= number_n; i++) {
    for(j = 0; pow(2, j) * i < number_k; j++) {
      probability /= 2.0;
    }
    sum_probability += probability;
    probability = 1.0;
  }

  printf("%16.15f\n", sum_probability / number_n);
  return 0;
}


Measured memory_bytes: 128
import java.util.*;
import java.text.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int count = 0;
		int a = 0;

		for(int i = 1; i <= num; i++){
			a = i%2;
			if(a == 1){
				count+=1;
			}
		}
		double prob = (double)count/num;
		System.out.println(prob);

	}
}

Measured memory_bytes: 23508
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int kazu,i,j,cnt=0,hz,smi;
		Scanner sca = new Scanner(System.in);
		kazu=sca.nextInt();
		int hai[]=new int[kazu];
		for(i=0;i<kazu;i++){
			hai[i]=sca.nextInt();
		}  
		for(i=0;i<kazu;i++){
			smi=i;
			for(j=i+1;j<kazu;j++){
				if(hai[smi]>hai[j]){
					smi=j;
				}
				}
			if(smi!=i){
				hz=hai[smi];
				hai[smi]=hai[i];
				hai[i]=hz;
				cnt++;
			}
		}
	     for(i=0;i<kazu;i++){
	    	    if(i!=kazu-1){	 
	    	     System.out.print(hai[i]+" ");
	    	     }else{
	    	    	 System.out.println(hai[i]);
	    	     }
	    }
	    	     System.out.println(cnt);

	}
		
	}


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

int main() {
    int n;
    char s[1000], t[1000];
    char ans[10000];
    
    cin >> n;
    cin >> s >> t;
    
    rep(i, n){
        ans[2*i] = s[i];
        ans[2*i + 1] = t[i];
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
def rec(visited,curpos):
    if (dp[visited][curpos] >= 0): return dp[visited][curpos]

    if (curpos == 0) & (visited == ((1 << v) - 1)) : 
        dp[visited][curpos] = 0
        return 0
    ret = float('inf')
    for i in range(v):
        if not ((visited >> i) & 1):
            ret = min(ret , rec((visited | 1 << i) , i ) + dis[curpos][i])
    dp[visited][curpos] = ret
    return ret

v,e = map(int, input().split())
dis = [[float('inf') for i in range(v)] for j in range(v)]
dp = [[-1 for j in range(v)] for k in range(1 << v)]

for i in range(e):
    s,t,d = map(int, input().split())
    dis[s][t] = d

ans = float('inf')
rec(0,0)
ans = min(ans , dp[0][0])

if ans == float('inf'):
    print('-1')
else:
    print(ans)


Measured memory_bytes: 19048
import java.util.*;
import java.math.BigInteger;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();

        BigInteger product = new BigInteger("1");
        long limit = (long) Math.pow(10, 18);
        //  System.out.println(limit);
        boolean smaller = true;

        for (int i = 1; i <= N; i++) {
            long A_i = scan.nextLong();
            if (A_i == 0) {
                System.out.println(0);
                return;
            }

            if (smaller) {
                product = product.multiply(BigInteger.valueOf(A_i));
            }

            if (product.compareTo(BigInteger.valueOf(limit)) == 1) {
                smaller = false;
            }

           // System.out.println("product is" + product + " smaller is" + smaller);
        }

        if (smaller) {
            System.out.println(product);
        } else {
            System.out.println(-1);
        }
    }

}


Measured memory_bytes: 60420
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<map>
#define pii pair<int,int>
#define mod 1000000007
#define MOD 998244353
#define SED 233
#define N 200020
#define sed 173
using namespace std;
int has[N],pw[N];
int geth(int x,int y)
{
	return (has[y]-1ll*has[x-1]*pw[y-x+1]%mod+mod)%mod;
}
int _has[N],_pw[N];
int _geth(int x,int y)
{
	return (_has[y]-1ll*_has[x-1]*_pw[y-x+1]%MOD+MOD)%MOD;
}
int n;
char ch[N];
map<pii,bool>vis;
bool check(int len)
{
	vis.clear();
	for(int i=n-len+1;i;i--)
	{
		int j=i+len;
		if(j+len-1<=n)vis[make_pair(geth(j,j+len-1),_geth(j,j+len-1))]=1;
		pii tmp=make_pair(geth(i,i+len-1),_geth(i,i+len-1));
		if(vis[tmp])return true;
	}
	return false;
}
int main()
{
	scanf("%d%s",&n,ch+1),pw[0]=_pw[0]=1;
	for(int i=1;i<=n;i++)
		pw[i]=1ll*pw[i-1]*sed%mod,has[i]=(1ll*has[i-1]*sed%mod+ch[i])%mod,
		_pw[i]=1ll*_pw[i-1]*SED%MOD,_has[i]=(1ll*_has[i-1]*SED%MOD+ch[i])%MOD;
	int l=1,r=n,ret=0;
	while(l<=r)
	{
		int mid=(l+r)>>1;
		if(check(mid))l=mid+1,ret=mid;
		else r=mid-1;
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef vector<Int> vInt;
typedef pair<int,int> pint;
typedef pair<Int,Int> pInt;
typedef vector<string> vstring;
typedef vector<pint> vpint;
typedef vector<pInt> vpInt;
typedef stringstream SS;

template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define repn(i,m,n) for(int i=(m);i<(n);++i)
#define repd(i,n) for(int i=(n)-1;i>=0;--i)
#define repnd(i,m,n) for(int i=(n)-1;i>=(m);--i)
#define rep0(i,n) for(i=0;i<(n);++i)
#define repn0(i,m,n) for(i=(m);i<(n);++i)
#define repd0(i,n) for(i=(n)-1;i>=0;--i)
#define repnd0(i,m,n) for(i=(n)-1;i>=(m);--i)
#define repc(i,n) for(int i=0;i<=(n);++i)
#define repcn(i,m,n) for(int i=(m);i<=(n);++i)
#define repcd(i,n) for(int i=(n);i>=0;--i)
#define repcnd(i,m,n) for(int i=(n);i>=(m);--i)
#define repc0(i,n) for(i=0;i<=(n);++i)
#define repcn0(i,m,n) for(i=(m);i<=(n);++i)
#define repcd0(i,n) for(i=(n);i>=0;--i)
#define repcnd0(i,m,n) for(i=(n);i>=(m);--i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define IL for(;;)
#define MP make_pair
#define PB push_back
#define X second
#define Y first
#define p_queue(n) priority_queue<n,vector<n>,greater<n> >
#define PUTLINE cout<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647/3;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

double color[30][3];

int main() {
	int n, m;
	cin >> n >> m;
	rep (i, n) cin >> color[i][0] >> color[i][1] >> color[i][2];
	int tmp, low;
	double mx = 0;
	if (m > 1) {
		for (int bit = (1 << m) - 1; bit < (1 << n); low = bit & -bit, tmp = bit, bit += low, bit |= (bit ^ tmp) / low >> 2) {
			double sum = 0;
			rep (i, n) if ((bit & 1 << i) > 0) repn (j, i + 1, n) if ((bit & 1 << j) > 0) {
				sum += pow(color[i][0] - color[j][0], 2);
				sum += pow(color[i][1] - color[j][1], 2);
			sum += pow(color[i][2] - color[j][2], 2);
			}
			chmax(mx, sum);
		}
	}
	printf("%.12lf\n", mx);
	return 0;
}

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

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

Measured memory_bytes: 256
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); bool s=false; if(c=='-'){s=true;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }

void rsorta_d32(void *base, const int count, const int size, const int index){
	typedef int32_t rsort_t;
	rsort_t (*a)[size] = (rsort_t(*)[size])base;
	rsort_t (*b)[size] = (rsort_t(*)[size])malloc(count*size*sizeof(rsort_t));
	int c[0x100];
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(0<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(0<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(1<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(1<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(2<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(2<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(3<<3))+0x80]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(3<<3))+0x80]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	free(b);
}

int main(void){
	int n=nextint();
	int ans=n+n*n+n*n*n;
	printf("%d\n", ans);
}


Measured memory_bytes: 1560
//
// Created by tattsun on 2017/02/11.
//

#include <iostream>

using namespace std;

int main() {
    int alice, bob;
    cin >> alice >> bob;

    if(alice == bob) {
        cout << "Draw" << endl;
        return 0;
    }

    if(alice == 1) {
        cout << "Alice" << endl;
        return 0;
    }

    if(bob == 1) {
        cout << "Bob" << endl;
        return 0;
    }

    if(alice > bob) {
        cout << "Alice" << endl;
    } else {
        cout << "Bob" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define bug1( x ) {cerr << (#x) <<"="<< x << endl;}
#define bug2( x , y ) {cerr << (#x) <<"="<< (x) << "    " << (#y) << "="<< (y) << endl;}
#define bug3( x , y , z ) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << endl;}
#define bug4( x , y , z , w) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << endl;}
#define bug5( x , y , z , w ,p) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << endl;}
#define bug6( x , y , z , w ,p , q) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << "    " << (#q) <<"="<< q << endl;}
#define bugn( x , n ) {cerr << (#x) <<":";for(int i=0;i<n;i++)cerr << x[i] <<"  "; cerr << endl;}
#define bugnm( x , n , m ) {cerr << (#x)<<endl;for(int i=0;i<n;i++){cerr << "Row #" << i<< ":";for(int j=0;j<m;j++)cerr << x[i][j] << "   ";cerr << endl;}}
typedef long long ll;
typedef long double ld;
using namespace std;

int n,m;
string s;
vector<int>path;
vector<int>vis(100000+5);
void dfs(int n){
	if( vis[n] )return;
	vis[n]=1;
	if( n == 0){
		reverse(path.begin(),path.end());
		for(auto p:path){
			cout << p << " " ;
		}
		exit(0);
	}
	for(int k = min(n,m) ; k >= 1 ; k-- ){
		if( s[ n - k ] == '0' ){
			path.push_back(k);
			dfs(n-k);
			path.pop_back();
		}
	}
}
int32_t main(){
	IOS
	cin >> n >> m >> s;
	dfs(n);
	cout << -1 << endl;
 }
/*
 * long long or int?
 * index out of bound? 
 * Tested on own test case?corner?
 * Make more general solution.
 * Read Read Read Read ....
 */


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

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

    int ans = 0;
    for (int i = 0; i < S.length(); i++){
        if (S[i]=='+'){
            ans++;
        }
        else{
            ans--;
        }
    }

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
	}

	void solve() {
		Scanner sc = new Scanner(System.in);
		long n = Integer.parseInt(sc.next());
		long m = Integer.parseInt(sc.next());
		sc.close();
		long res = 0;

		if(n==2||m==2)res = 0;
		else if(n>2&&m>2)res = n*m-(n*2+m*2-4);
		else if(n==1&&m==1)res = 1;
		else res = n*m-2;

		System.out.println(res);
	}

}


Measured memory_bytes: 22996
N,W = map(int,input().split())
Value = []
weight = []
inf=float("inf")
dp=[[0 for i in range(W+1)] for j in range(N+1)]

for i in range(N):
    v,w = map(int,input().split())
    Value.append(v)
    weight.append(w)


for i in range(N):
  for w in range(W+1):
    if w>=weight[i]:
      dp[i+1][w] = max(dp[i][w-weight[i]]+Value[i],dp[i][w],dp[i+1][w-weight[i]]+Value[i])
    else:
      dp[i+1][w] = dp[i][w]

print(dp[N][W])


Measured memory_bytes: 42300