akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Scanner
{
    private readonly char Separator = ' ';
    private int Index = 0;
    private string[] Line = new string[0];
    public string Next()
    {
        if (Index >= Line.Length)
        {
            Line = Console.ReadLine().Split(Separator);
            Index = 0;
        }
        var ret = Line[Index];
        Index++;
        return ret;
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public string[] StringArray()
    {
        Line = Console.ReadLine().Split(Separator);
        Index = Line.Length;
        return Line;
    }

    public int[] IntArray()
    {
        var l = StringArray();
        var res = new int[l.Length];
        for (int i = 0; i < l.Length; i++)
        {
            res[i] = int.Parse(l[i]);
        }
        return res;
    }

    public long[] LongArray()
    {
        var l = StringArray();
        var res = new long[l.Length];
        for (int i = 0; i < l.Length; i++)
        {
            res[i] = long.Parse(l[i]);
        }
        return res;
    }
}

class Program
{
    private int N, A, B;
    private void Scan()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        A = sc.NextInt();
        B = sc.NextInt();
    }

    public void Solve()
    {
        Scan();
        var ans = Math.Min(B, A * N);
        Console.WriteLine(ans);
    }



    static void Main(string[] args)
    {
        new Program().Solve();
    }
}

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

using namespace std;


#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define int long long

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

template <typename T>
void print(T x)
{
	std::cout << x <<" " ;
}


template <typename T>
void println(T x)
{
	std::cout << x << "\n";
}

unsigned factorial(unsigned num) {
	unsigned digit = 1;
	rep1(i, num + 1)digit *= i;
	return digit;
}

signed main(void) {
	int N;
	vector<int> x;
	vector<int> y;

	cin >> N;
	x.resize(N);
	y.resize(N);

	rep(i, N) {
		cin >> x[i] >> y[i];
	}

	vector<int> p(N);
	iota(p.begin(), p.end(), 1);
	double ans = 0;
	do {
		rep(i, N-1) {
			ans += sqrt(pow(x[p[i + 1]-1] - x[p[i]-1], 2) + pow(y[p[i + 1]-1] - y[p[i]-1], 2));
		}
	} while (next_permutation(p.begin(), p.end()));

	std::cout << std::fixed;
	std::cout << std::setprecision(6) << ans/factorial(N);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
const ll ATCODER_AMARI = 1000000007; //10^9 + 7
const ll INF = 10000000000000;

//階乗関数　ATCODER_AMARIに注意
ll factorial(ll k){
  ll sum = 1;
  for(int i = 1 ; i < k + 1; i++) {
    sum *= i;
    //sum = sum % ATCODER_AMARI;
  }
  return sum;
}

int main() {
  ll n;
  cin >> n;
  std::vector<ll> a(n);

  for(ll i; i < n; i++) cin >> a.at(i);

  sort(a.begin(), a.end());

  ll tmp = a.at(0);
  int flag = 0;

  for(ll i = 0; i < n; i++) {

    if(a.at(i) != tmp) flag++;
    tmp = a.at(i);
  }

  if(flag == 0) {
    if(a.at(0) == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
  }
  else if(n % 3 == 0) {
    
    if(flag == 1) {
      if(a.at(n / 3 - 1) == 0 && a.at(n / 3) != 0) cout << "Yes" << endl;
      else cout << "No" << endl;
      return 0;
    }
    else if(flag == 2) {
      if(a.at(n / 3 - 1) != a.at(n / 3) && a.at(2*n / 3 - 1) != a.at(2*n / 3)) {
        int k = a.at(n / 3 - 1) ^ a.at(n / 3) ^ a.at(2*n / 3);
        if(k == 0) {
          cout << "Yes" << endl;
          
        //  cout << a.at(n / 3 - 1) << ' ' << a.at(n / 3) << ' ' << a.at(n * 2 / 3) << ' ' << k << endl;
          //cout << 1 << endl;
          return 0;
        }
        else cout << "No" << endl;
        return 0;
      }
      else {
        cout << "No" << endl;
        return 0;
      }
    }
    else {
      cout << "No" << endl;
      return 0;
    }
    
  }
  else{
    cout << "No" << endl;
    return 0;
  }
}

Measured memory_bytes: 4052
#include<bits/stdc++.h>
using namespace std;
int n,a[100000];
double sum=0;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
       double x;
        cin>>x;
        sum=sum+1/x;
    }
    cout<<1/sum;

}


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

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

  int ans = 0;

  for(int i = 0; i < (int)S.size(); i++){
    //cout << S[i] <<endl;
    if(S[i] != T[i]){
      ans++;
    }
  }

  cout << ans << endl;

  //int N, M;
  //cin >> N >> M ;
  //cout << N << endl;
  //cout << M << endl;

  /*int N = 3;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

  for (int i = 0; i < vec.size(); i ++){
    cout << vec.at(i) << endl;
  }

  for (int i = 0; i < vec.size()-1; i ++){
    cout << vec.at(i) << " ";
  }
  cout << vec.at(vec.size() - 1) << endl;*/
}


Measured memory_bytes: 3872
n,k=map(int,input().split())
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


for i in range(1,k+1):
    if n-k>=i-1:
        print(cmb(k-1,k-i)*cmb(n-k+1,n-k-i+1)%(10**9+7))
    else:
        print(0)


Measured memory_bytes: 50524
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N=1e5+50;
const LL inf=1e18;
int x,y,z,n;LL ans,d1[N],d2[N],now,anss=-inf;
struct node{int a,b;bool friend operator <(node a,node b){return 0ll+a.a-a.b>0ll+b.a-b.b;}}d[N];
priority_queue<int>q;
int main(){
    scanf("%d%d%d",&x,&y,&z);n=x+y+z;
    for(int i=1,a,b,c;i<=n;i++){
        scanf("%d%d%d",&a,&b,&c);
        ans+=c;d[i]=node{a-c,b-c};
    }
    sort(d+1,d+n+1);d1[0]=x?-inf:0;
    for(int i=1;i<=n;i++){
        now+=d[i].a,q.push(-d[i].a);
        if(q.size()>x)now+=q.top(),q.pop();
        if(q.size()==x)d1[i]=now;else d1[i]=-inf;
    }
    while(q.size())q.pop();now=0;d2[n+1]=y?-inf:0;
    for(int i=n;i;i--){
        now+=d[i].b;q.push(-d[i].b);
        if(q.size()>y)now+=q.top(),q.pop();
        if(q.size()==y)d2[i]=now;else d2[i]=-inf;
    }
    for(int i=0;i<=n;i++)anss=max(anss,d1[i]+d2[i+1]);
    cout<<ans+anss;
    return 0;
}

Measured memory_bytes: 3064
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		sc.close();

		System.out.println((int) Math.ceil((B - 1.0) / (A - 1.0)));
	}
}


Measured memory_bytes: 21844
import java.util.*;
public class Main {
  //公式解説見たバージョン
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int allcount = 0;
    for(int i = 1; i < N; i++){
      allcount += (N-1) / i;
    }

    System.out.println(allcount);	
  }
  //これは思いつかなかったです！！Cで回す必要すらないとは…
}

Measured memory_bytes: 35768
N,M = map(int,input().split())
H = list(map(int,input().split()))
memo = [[] for _ in range(N+1)]
for i in range(M):
    a,b = map(int,input().split())
    memo[a].append(b)
    memo[b].append(a)
    
count = 0
for i in range(1,N+1):
    mini = set(memo[i])
    if len(mini) > 0:
        for j in mini:
            if H[i-1] <= H[j-1]:
                break
        else:
            count += 1
    else:
        count += 1

print(count)

Measured memory_bytes: 100664
#include<iostream>
#include<deque>
using namespace std;
int main(){
	int a;
	deque<int>some;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		if(i%2==n%2){
			some.push_back(a);
		}
		else{
			some.push_front(a);
		}
	}
	for(int x:some){
		cout<<x<<endl;
	}
	return 0;
}

Measured memory_bytes: 2944
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0) {
				break;
			}
			int m = scanner.nextInt();

			int[][] map = new int[m][n];
			Integer[] start = new Integer[2];
			int island = 1;
			for (int i = 0; i < map.length; i++) {
				String line = scanner.next();
				for (int j = 0; j < line.length(); j++) {
					char place = line.charAt(j);
					if (place == '.') {
						map[i][j] = 1;
					} else if (place == '@') {
						start[0] = i;
						start[1] = j;
					}
				}
			}

			Deque<Integer[]> deque = new ArrayDeque<Integer[]>();
			deque.addFirst(start);
			while (deque.size() > 0) {
				Integer[] poll = deque.pollFirst();
				if (poll[0] > 0 && map[poll[0] - 1][poll[1]] == 1) {
					Integer[] push = { poll[0] - 1, poll[1] };
					deque.addFirst(push);
					map[poll[0] - 1][poll[1]] = 0;
					island++;
				}
				if (poll[0] < m - 1 && map[poll[0] + 1][poll[1]] == 1) {
					Integer[] push = { poll[0] + 1, poll[1] };
					deque.addFirst(push);
					map[poll[0] + 1][poll[1]] = 0;
					island++;
				}
				if (poll[1] > 0 && map[poll[0]][poll[1] - 1] == 1) {
					Integer[] push = { poll[0], poll[1] - 1 };
					deque.addFirst(push);
					map[poll[0]][poll[1] - 1] = 0;
					island++;
				}
				if (poll[1] < n - 1 && map[poll[0]][poll[1] + 1] == 1) {
					Integer[] push = { poll[0], poll[1] + 1 };
					deque.addFirst(push);
					map[poll[0]][poll[1] + 1] = 0;
					island++;
				}
			}

			System.out.println(island);

		}
	}

	static int nextInt() {
		int c;
		try {
			c = System.in.read();
			while (c != '-' && (c < '0' || c > '9'))
				c = System.in.read();
			if (c == '-')
				return -nextInt();
			int res = 0;
			while (c >= '0' && c <= '9') {
				res = res * 10 + c - '0';
				c = System.in.read();
			}
			return res;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return -1;
	}

	static char nextChar() {
		try {
			int b = System.in.read();
			while (b != -1 && (b == ' ' || b == '\r' || b == '\n'))
				;
			if (b == -1)
				return 0;
			return (char) b;
		} catch (IOException e) {
		}
		return 0;
	}

}

Measured memory_bytes: 34916
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 10010;

int n, m, a[N];

int main() {

	scanf("%d %d", &n, &m);

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

	sort(a, a + n);

	int res = 0;

	for (int i = 0; i < n; i++) {
		int k = min(a[i], m);
		m -= k;
		a[i] -= k;
		res += ((a[i] == 0) ? 1 : 0);
	}

	if (m > 0) {
		--res;
	}

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

	return 0;

}

Measured memory_bytes: 3836
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
#include <deque>
#include <queue>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int x, a, b;
    cin >> x >> a >> b;
    cout << (x - a) % b;
}

Measured memory_bytes: 3624
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n, d;
  cin >> n >> d;
  vector<vector<int> > x(n, vector<int>(d));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < d; ++j) {
      cin >> x[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int dist = 0;
      for (int k = 0; k < d; ++k) {
        dist += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
      }
      bool ok = false;
      for (int k = 1; k <= 300; ++k) {
        if (dist == k * k) ok = true;
      }
      if (ok) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstdint>
#include <numeric>
#include <vector>
#include <algorithm>
#include <utility>

int main() {
  int k;
  scanf("%d", &k);

  intmax_t res = 0;
  for (int a = 1; a <= k; ++a)
    for (int b = 1; b <= k; ++b)
      for (int c = 1; c <= k; ++c)
        res += std::gcd(std::gcd(a, b), c);

  printf("%jd\n", res);
}


Measured memory_bytes: 1728
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true)
        {
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H == 0 && W == 0)
                break;
            for(int i = 1 ; i <= H ; i++)
            {
                for(int j = 1; j <= W ; j++)
                {
                    if(i % 2 == 1)
                    {
                        if(j % 2 == 1)
                            System.out.print("#");
                        else
                            System.out.print(".");
                    }
                    else
                    {
                        if(j % 2 == 1)
                            System.out.print(".");
                        else
                            System.out.print("#");
                    }
                }
                System.out.println();
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 33368
// 2016-6-30 


#include<iostream>

using namespace std;

int main(){

int a=0,b=0;

cin >> a >> b; // ???????????°????????\???

if(a < b){
cout << "a" << " < " << "b" << endl;    //a?????????b???????????§????????¨???
}
else if(a > b){
cout << "a" << " > " << "b" << endl;    //b?????????a???????????§????????¨???
}
else{
cout << "a" << " == " << "b" << endl;   //a??¨b???????????¨???
}

return 0;

}

Measured memory_bytes: 1156
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  int N;
  cin>>N;
  string S;
  cin>>S;
  int ans=1;
  if(N%2) ans=0;
  else{
    rep(i,N/2){
      if(S[i]!=S[N/2+i]) ans=0;
    }
  }
  if(ans) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <inttypes.h>

#define MAX 12345678

int tomatu[MAX];

int kakutei[MAX], current_count[MAX], keturon[MAX];

int main(void) {
	int N;
	int i;
	uint64_t sum;
	if (scanf("%d", &N) != 1) return 1;
	if (N == 1) {
		puts("1");
		return 0;
	}
	for (i = 2; i * i <= N; i++) {
		int j;
		for (j = i; j <= N; j += i) {
			if (tomatu[j] == 0) tomatu[j] = i;
		}
	}
	for (i = 2; i <= N; i++) {
		if (tomatu[i] == 0) tomatu[i] = i;
	}
	keturon[1] = 1;
	for (i = 2; i <= N; i++) {
		int next = i / tomatu[i];
		if (tomatu[next] == tomatu[i]) {
			kakutei[i] = kakutei[next];
			current_count[i] = current_count[next] + 1;
		} else {
			kakutei[i] = keturon[next];
			current_count[i] = 1;
		}
		keturon[i] = kakutei[i] * (current_count[i] + 1);
	}
	sum = 0;
	for (i = 1; i <= N; i++) {
#if 0
		printf("%3d %3d\n", i, keturon[i]);
#endif
		sum += (uint64_t)i * keturon[i];
	}
	printf("%" PRIu64 "\n", sum);
	return 0;
}


Measured memory_bytes: 157988
N = int(input())
S = input()
front = ""
rangle = 0
langle = 0
for i in range(N):
    if S[i] == ")":
        if langle == 0:
            front = "("+front
        else:
            langle -= 1
    else:
        langle += 1
print(front+S+")"*langle)


Measured memory_bytes: 2940
import sys
import copy
import  math
import bisect
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

s = input()
ans = 1
for i in range(2, len(s), 2):
    c = s[:-i]
    l = len(c)
    if c[:l//2] == c[l//2:]:
        ans = max(l, ans)
print(ans)

Measured memory_bytes: 3444
import java.util.Scanner;

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

    String s = sc.next();
    
    if (s.endsWith("s")) {
      System.out.println(s + "es");
    } else {
      System.out.println(s + "s");
    }
  }
}


Measured memory_bytes: 38440
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
using namespace std;
int n;

int s[20];
int ans=10000000;
int a[100];
int l[100];

int myabs(int a)
{
    if (a<0) return -a;
    return a;
}
void prints()
{
    for (int i=1; i<=n; ++i)
        cout<<s[i]<<' ';
    cout<<endl;
}
void check()
{
    int num[4]={0,0,0,0};
    int sumL[4]={0,0,0,0};
    int tans=0;
    for (int j=1; j<=n; ++j)
    {
        num[s[j]]+=1;
        sumL[s[j]]+=l[j];
    }
    for (int j=1; j<=3; ++j)
    {
        if(num[j]==0) return;
        tans+=10*(num[j]-1);
    }
    for (int j=1; j<=3; ++j)
        tans+=myabs(sumL[j]-a[j]);
    if (tans<ans) 
    {
//        prints();
        ans=tans;
    }
}

void dfs(int now)
{
    if (now==n+1)
    {
        check();
    }else
    {
        for (int i=0; i<=3; ++i)
        {
            s[now]=i;
            dfs(now+1);
        }
    }
}

int main()
{
    cin>>n;
    for (int i=1; i<=3; ++i)
        cin>>a[i];
    for (int i=1; i<=n; ++i)
        cin>>l[i];
    dfs(1);
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
N = int(input())
S = [input() for _ in range(N)]
C0 = C1 = C2 = C3 = 0
for i in range(N):
    if S[i] == 'AC':
        C0 += 1
    elif S[i] == 'WA':
        C1 += 1
    elif S[i] == 'TLE':
        C2 += 1
    elif S[i] == 'RE':
        C3 += 1
print('AC x',C0)
print('WA x',C1)
print('TLE x',C2)
print('RE x',C3)

Measured memory_bytes: 16336
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

//# include <x86intrin.h>
# include <bits/stdc++.h>

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
 
template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
	// cin.exceptions(cin.failbit); 
	// throws exception when do smth illegal
	// ex. try to read letter into int
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9; 
const int N = 6e5+5;                                         
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
 
int rnd (int l, int r) {
	return uniform_int_distribution<int> (l, r)(gen);
}

int main () {
	SpeedForce;
	
	string s;
	cin >> s;
	int res = 0;
	for(auto it : s) {
		res *= 10;
		res += it - '0';
		res %= 9;
	}
	cout << (res == 0 ? "Yes\n" : "No\n") << '\n';
	
	return Accepted;
}

// B...a


Measured memory_bytes: 3744
#include<bits/stdc++.h>
#define ll long long
#define thekingisborn ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ld  long double
#define f first
#define se second
#define pb push_back
#define pf push_front
#define sz() size()
#define maxn 200005
#define mod 1000000007

using namespace std;

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

/*ll power(ll a,ll n)
{
    if(n == 1)return a%mod;
    if(n == 0)return 1;
    a = a%mod;
    if(n&1)return ((a%mod)*(power((a*a)%mod,n>>1))%mod)%mod;
    return power((a*a)%mod,n>>1)%mod;
}
ll gcd(int a,int b)
{
    if(a%b == 0)return b;
    return gcd(b,a%b);
}
int root(int x)
{
    while(par[x] != x)
    x = par[x];
    return x;
}
void dsu(int x,int y)
{
  if(root(x) == root(y))return;
  par[root(y)] = root(x);
  return;
}*/
/*bool done[maxn];
vector<int>adj[maxn];

void dfs(int x)
{
    stack<int>s;
    s.push(x);
    done[x]=true;
    while(!s.empty())
    {
        int y = s.top(),i;
        for(i=0;i<(int)adj[y].size();++i)
        if(!done[adj[y][i]])
        {
            done[adj[y][i]] = true;
            s.push(adj[y][i]);
            break;
        }
        if(i == (int)adj[y].size()){s.pop();}
    }
    return ;
}*/
int n;
vector<ll>v(2*maxn);
vector<pll>a(2*maxn);

int main()
{
    thekingisborn;
    cin >> n;
    for(int i=0;i<(1<<n);++i)
    cin >> v[i];
    for(int k=0;k<(1<<n);++k)
    a[k] = {v[k],0};
    for(int i=0;i<=n+5;++i)
    {
        for(int k=1;k<(1<<n);++k)
        {
            if(k&(1<<i))
            {
                ll x1 = a[k].f,x2 = a[k].se,x3 = a[k^(1<<i)].f,x4 = a[k^(1<<i)].se;
                vector<ll>b;
                b.pb(x1),b.pb(x2),b.pb(x3),b.pb(x4);
                sort(b.begin(),b.end(),greater<ll>());
                a[k] = {b[0],b[1]};
            }
        }
    }
    cout << a[1].f+a[1].se << "\n";
    pll ma = a[1];
    for(int k=2;k<(1<<n);++k)
    {
        if(ma.f+ma.se > a[k].f+a[k].se)
        cout << ma.f+ma.se << "\n";
        else
        {
            ma = a[k];
            cout << a[k].f+a[k].se << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 13696
#include <iostream>
#include<iomanip>
using namespace std;
int main(void){
    int a,b;
    cin >> a;
    cin >> b;
   int d = a/b;
   int r = a%b;
   double f = 1.0*double(a)/double(b);
   cout << d;
   cout << " ";
   cout << r;
   cout << " ";
   cout << fixed << setprecision(5) << f;
    cout << endl;
}


Measured memory_bytes: 3288
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	x := Scan()
	a := stringToInt(string(x[0]))
	b := stringToInt(string(x[1]))
	c := stringToInt(string(x[2]))
	d := stringToInt(string(x[3]))
	if a+b+c+d == 7 {
		p(a, b, c, d, []string{"+", "+", "+"})
	} else if a+b+c-d == 7 {
		p(a, b, c, d, []string{"+", "+", "-"})
	} else if a+b-c+d == 7 {
		p(a, b, c, d, []string{"+", "-", "+"})
	} else if a+b-c-d == 7 {
		p(a, b, c, d, []string{"+", "-", "-"})
	} else if a-b+c+d == 7 {
		p(a, b, c, d, []string{"-", "+", "+"})
	} else if a-b+c-d == 7 {
		p(a, b, c, d, []string{"-", "+", "-"})
	} else if a-b-c+d == 7 {
		p(a, b, c, d, []string{"-", "-", "+"})
	} else if a-b-c-d == 7 {
		p(a, b, c, d, []string{"-", "-", "-"})
	}
}
func p(a, b, c, d int, op []string) {
	fmt.Print(a)
	fmt.Print(op[0])
	fmt.Print(b)
	fmt.Print(op[1])
	fmt.Print(c)
	fmt.Print(op[2])
	fmt.Print(d)
	fmt.Println("=7")
}


Measured memory_bytes: 1776
#include <cstdio>
int main(){
    int in;
    int h=0;
    int m=0;
    int s=0;
    scanf("%d",&in);

    while(in>=3600){
    in -= 3600;
    h++;
    }

    while(in>=60){
    in -= 60;
    m++;
    }

    s = in;
    
    printf("%d:%d:%d\n",h,m,s);
}


Measured memory_bytes: 2732
import java.util.*;
class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int[] dx = {1,0,-1,0};
		int[] dy = {0,1,0,-1};
		int max = 0;
		String[][] maze = new String[h][w];
		for(int i = 0; i < h; i++) maze[i] = sc.next().split("");
		for (int sx = 0; sx < h; sx++) {
			for (int sy = 0; sy < w; sy++) {
				if(maze[sx][sy].equals("#")) continue;
				int[][] d = new int[h][w];
				for (int i = 0; i < h*w; i++) d[i%h][i/h] = 1000;
				d[sx][sy] = 0;
				Queue<point> que = new ArrayDeque<point>();
				que.add(new point(sx, sy));
				while(0 != que.size()) {
					point p = que.poll();
					for(int i = 0; i < 4; i++) {
						int cx = p.x + dx[i];
						int cy = p.y + dy[i];
						if(cx >= 0 && cx <= h-1 && cy >= 0 && cy <= w-1 && !maze[cx][cy].equals("#")  && d[cx][cy] == 1000) {
							d[cx][cy] = d[p.x][p.y] + 1;
							que.add(new point(cx, cy));
						}
					}
				}
				for (int i = 0; i < h*w; i++) {
					if(d[i%h][i/h] < 1000) max = Math.max(max,d[i%h][i/h]);
				}
			}
		}
		System.out.println(max);
	}
	public static class point{
		int x; int y;
		point(int x, int y){
			this.x = x; this.y = y;
		}
	}
}

Measured memory_bytes: 27564
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
 
int main()
{
    int H, W;
    int h, w;
 
    while (1) {
        scanf("%d%d", &H, &W);
        if (H == 0 && W == 0) break;
         
        for (w = 0; w < W; w++) putchar('#');
        putchar('\n');
 
        for (h = 2; h < H; h++) {
            putchar('#');
            for (w = 2; w < W; w++) putchar('.');
            putchar('#');
            putchar('\n');
        }
 
        for (w = 0; w < W; w++) putchar('#');
        putchar('\n');
 
        putchar('\n');
    }
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef map<ll, ll> mii;
const int MOD = 1e9 + 7;

#define fastIO \
ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define mp make_pair 

int main() {
    fastIO;
    int tt = 1;
    // cin >> tt;
    while (tt--) {
        int k, a, b;
        cin >> k >> a >> b;
        if ((a - 1) / k < b / k) {
            cout << "OK" << endl;
        }  else cout << "NG" << endl;
    }
    return 0;
}


Measured memory_bytes: 3652
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    string S; cin >> S;
    res = string(S.length(),'x');
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<string>() << endl;
    return 0;
}


Measured memory_bytes: 764
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>

using namespace std;

const int MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;i++)
#define rep2(i, m, n) for(int i=m;i<n;i++)
#define rrep(i, n, m) for(int i=n;i>=m;i--)
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

const int MAX = 510000;

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;
}

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

    int N, K ;
    cin >> N >> K;
    COMinit();

    rep2(i, 1, K + 1) {
        if (i == 1 || i == K) {
            cout << COM(N - K + 1, i)  % MOD << endl;
        }else{
            cout << COM(N - K + 1, i) * COM(K-1, i - 1) % MOD << endl;
        }
    }

}



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

A = [int(v) for v in input().split()]
m = {}
count = 0

for i, a in enumerate(A):
    j = i - a
    if j >= 0 and j in m:
        count += m[j]

    k = a + i
    if k in m:
        m[k] += 1
    else:
        m[k] = 1

print(count)


Measured memory_bytes: 40356
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};



signed main(){
  int X,Y,Z;cin>>X>>Y>>Z;

  int cont=0;
  while(true){
    if(X-Z<0){
      cont--;
      break;
    }
    if(X-Y-Z<0){
      break;
    }
    X-=Z+Y;
    cont++;
  }
  cout<<cont;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=1;i<=(ll)(n);i++)
ll a[200005];
int b[200005];
ll c[200005],d[200005];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    for(int i=0;i<=200002;i++)a[i]=0;
    ll n;
    ll tot=0;
    cin>>n;
    rep(i,n){
      int tmp;
      cin>>tmp;
      b[i]=tmp;
      a[tmp]++;
    }
    rep(i,n){
      c[i]=a[i]*(a[i]-1)/2;
      a[i]--;
      tot+=c[i];
      if(a[i]==-1)d[i]=0;
      else d[i]=a[i]*(a[i]-1)/2;
    }

    rep(i,n) cout<<tot+d[b[i]]-c[b[i]]<<endl;
    return 0;
}


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

using namespace std;

const double PI = 3.141592653589;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define int long long
#define all(c) (c).begin(),(c).end()
#define M 1000000007
#define INF LLONG_MAX
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ", "; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
// Use pr(a,b,c,d,e) or cerr<<anything or prc(v.begin(),v.end()) or prc(v,v+n)
//  


int32_t main()
{
    fastio;
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    string a, b;
    cin >> a >> b;
    int x, y;
    cin >> x >> y;
    string z;
    cin >> z;
    if(z == a) x--;
    else y--;
    cout << x << " "  << y << "\n"; 
    return 0;
}



Measured memory_bytes: 256
H, W = map(int, input().split())

A = [list(map(int, input().split())) for _ in range(H)]

cnt = 0
path = []

for h in range(H):
    for w in range(W-1):
        if A[h][w]%2:
            A[h][w+1] += 1
            cnt += 1
            path.append((h+1, w+1, h+1, w+2))

for h in range(H-1):
    if A[h][-1]%2:
        A[h+1][-1] += 1
        cnt += 1
        path.append((h+1, W, h+2, W))


print(cnt)
for p in path:
    print(*p)

Measured memory_bytes: 30432
n,x = map(int,input().split())
m = [int(input()) for _ in range(n)]
ans = 0
minm = 1000
for i in range(n):
    x -= m[i]
    minm = min(minm,m[i])
    ans += 1
while x >= minm:
    x -= minm
    ans += 1
print(ans)

Measured memory_bytes: 3064
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] h = new int[N+1];
    for(int i = 1; i <= N; i++) {
      h[i] = sc.nextInt();
    }
    int[] dp = new int[N+1];
    dp[1] = 0;
    dp[2] = Math.abs(h[2] - h[1]);
    for(int i = 3; i <= N; i++) {
      dp[i] = Math.min(dp[i - 1] + Math.abs(h[i] - h[i - 1]), dp[i - 2] + Math.abs(h[i] - h[i - 2]));
    }
    System.out.println(dp[N]);
  }
}


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

int main(){
  int n,cnt=0;
  string ip;
  cin >> n;
  for(int i=0;i<n;i++){char c;cin >> c;ip+=c;}
  int i=0,j=n-1;
  while(i < j)
  {    
      while(i<n&&ip[i] == 'R')i++;
      while(j>=0&&ip[j] == 'W')j--;
      if(i<j)swap(ip[j],ip[i]), cnt++;
     // cout << ip << endl;
   }
  cout << cnt << endl;
}


Measured memory_bytes: 3768
import sys,math
n,m=[int(x) for x in input().split()]
a = [int(x) for x in input().split()]
total = sum(a)
cnt = n
for i in range(0, n):
  if a[i] < math.ceil(total / (4 * m)):
    cnt -= 1
  if cnt < m:
    print("No")
    sys.exit()
print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
//#define kk
#define int long long
#define FOR(a, b) for(int i=a; i<=b; i++)
#define REP(i, a, b) for(int i=a; i<=b; i++)
#define ff first
#define ss second
#define ll long long
#define inf 1000000000
#define pb push_back
#define mod 1000000007
 
const ll INF=1e18+5;
const int maxN=2e5+5;
typedef pair<int, int> pi;

int dp[3005][3005];

int n;
string s;

void solve(){
	cin>>n;
	cin>>s;
	
	// dp[len][j] - no. of permutations in prefix of size "len" such that the last number
	// (or {len}-th number) is "j" 
	
	dp[1][1]=1;
	
	for(int len=2; len<=n; len++){
		for(int j=1; j<=len; j++){
			int L, R;
			
			if(s[len-2]=='<') L=1, R=j-1;
			else L=j, R=len-1;
			
			if(L<=R) dp[len][j]=(dp[len][j]+(dp[len-1][R]-dp[len-1][L-1]+mod))%mod;
		}
		
		if(len!=n){
			for(int j=1; j<=len; j++){
				dp[len][j]=(dp[len][j]+dp[len][j-1])%mod;
			}
		}
	}
	
	int ans=0;
	
	for(int i=1; i<=n; i++){
		ans=(ans+dp[n][i])%mod;
	}
	cout<<ans<<endl;
}
 
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cout<<fixed<<setprecision(6);
	
	#ifdef kk
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	
	int T=1;
	//cin>>T;
	
	while(T--){		
		solve();
	}
}


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

int main() {
	int n;
	cin >> n;
	bool p = true; // odd = true, even = false
	list<long long> a;
	long long m;
	for(int i = 0; i < n; i++){
		cin >> m;
		i % 2 ? a.push_back(m) : a.push_front(m);
	}
	if(n % 2) a.reverse();
	
	while(n--){
		cout << a.back() << ' ';
		a.pop_back();
	}
	
	return 0;
}

Measured memory_bytes: 8448
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pllll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int, int> > vii;
typedef vector< pair<long long, long long> > vllll;
typedef map<int, int> mii;
typedef map<long long, long long> mllll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0ll)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
#define bitsum(x) __builtin_popcount(x)
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
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(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  // ll n;
  // cin >> n;
  ll n, m;
  cin >> n >> m;
  // ll n, m, k;
  // cin >> n >> m >> k;
  ll sum = 0;
  fi(0, m) {
    int x;
    cin >>x;
    sum+=x;
  }
  n -= sum;
  if(n<0) {
    cout<<"-1\n";
    
  }
  else {
    cout << n << endl;
  }
  // cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3620
n = int(input())
s = input()
ans = []
if s[0] == 'I':
    ans.append(1)
else:
    ans.append(-1)
for i in range(1,n):
    if s[i] == 'I':
        ans.append(ans[i-1] +1)
    else:
        ans.append(ans[i-1] -1)
if max(ans) < 0:
    print('0')
else:
    print(max(ans))


Measured memory_bytes: 3060
# include <cstdio>
# include <iostream>
using namespace std;
typedef long long ll;
string s;
int N;
ll m, a, r, c, h;
ll D[5];
int P[10] = { 0 ,0 ,0 ,0 ,0 ,0 ,1 ,1 ,1 ,2 };
int Q[10] = { 1 ,1 ,1 ,2 ,2 ,3 ,2 ,2 ,3 ,3 };
int R[10] = { 2 ,3 ,4 ,3 ,4 ,4 ,3 ,4 ,4 ,4 };
int main()
{
	scanf("%d ", &N);
	for (int i = 0; i < N; i++)
	{
		cin >> s;
		if (s[0] == 'M') m++;
		if (s[0] == 'A') a++;
		if (s[0] == 'R') r++;
		if (s[0] == 'C') c++;
		if (s[0] == 'H') h++;
	}
	D[0] = m, D[1] = a, D[2] = r, D[3] = c, D[4] = h;
	ll res = 0;
	for (int d = 0; d < 10; d++)
		res += D[P[d]] * D[Q[d]] * D[R[d]];
	printf("%lld\n", res);
}


Measured memory_bytes: 256
a = %w(
大きさ  60cm以内    80cm以内    100cm以内   120cm以内   140cm以内   160cm以内
重さ    2kg以内     5kg以内     10kg以内    15kg以内    20kg以内    25kg以内
料金    600円   800円   1000円  1200円  1400円  1600円
).map(&:to_i).each_slice(7).to_a.transpose[1..-1]

loop do
    n = gets.to_i
    break if n == 0
    total = 0
    n.times do
        x, y, z, w0 = gets.split.map &:to_i
        s0 = x + y + z
        #p [s0, w0]
        total += (a.find{|s, w, _| s >= s0 && w >= w0} || [0]).last
    end
    p total
end

Measured memory_bytes: 8972
from copy import deepcopy
H,W=map(int,input().split())
c= [list(map(int,input().split())) for _ in range(10)]
A= [list(map(int,input().split())) for _ in range(H)]
d= deepcopy(c)

for k in range(10):
  for i in range(10):
    for j in range(10):
      d[i][j]=min(d[i][j],d[i][k]+d[k][j])
      
ans=0
for i in range(H):
  for j in range(W):
    if A[i][j]==-1 or A[i][j]==1:
      pass
    else:
      ans += d[A[i][j]][1]
      
print(ans)

Measured memory_bytes: 3828
import sys

x = int(input())
b = 2
p = 2

max_num = 1
if x == 1:
  print(1)
  sys.exit()
while b ** p <= x:
  while b ** p <= x:
    if b ** p > max_num:
      max_num = b ** p
    p += 1

  p = 2
  b += 1

print(max_num)



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

int main() {
	// your code goes here
	int ans = 0;
	string s;
	cin >> s;
	int len = s.size();
	for(int i = 0 ; i < len ; i++)
	{
	    if(s[i] == '+')ans++;
	    else ans--;
	}
	cout << ans ; 
	return 0;
}


Measured memory_bytes: 256
#line 2 "header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

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

// varibable settings
const long long INF = 1e18;
template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T> inline void chmax(T &a, const T &b) { if ((a) < (b)) (a) = (b); }
template <class T> inline void chmin(T &a, const T &b) { if ((a) > (b)) (a) = (b); }
template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); }

#define cdiv(a, b) (((a) + (b)-1) / (b))
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x) sort(all(x)); x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef long double ld;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
void check_input() { assert(cin.eof() == 0); int tmp; cin >> tmp; assert(cin.eof() == 1); }

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"
template<class T=ll> using vec = vector<T>;
struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast;


int solve() {
    ll n;cin>>n;
    vector<ll> a(n);
    rep(i, n) {
        cin>>a[i];
    }
    dump(a);

    ll ans = 0;
    rep(i, n){
        rep(j, i+1, n){
            rep(k, j+1, n){
                bool ok = true;
                if (a[i]+a[j] <= a[k]) {
                    ok = false;
                }
                if (a[i]+a[k] <= a[j]) {
                    ok = false;
                }
                if (a[j]+a[k] <= a[i]) {
                    ok = false;
                }
                if (a[i] == a[j] || a[j] == a[k] || a[i] == a[k]) {
                    ok = false;
                }
                if (ok) ans++;
            }
        }
    }
    cout << ans << endl;

    return 0; 
}


int main(){/*{{{*/
    solve();
    check_input();
    return 0;
}/*}}}*/


Measured memory_bytes: 3616
input_data=input()
N,D=map(int,input_data.split())
X=[] 
for n in range(N) :
    X_data=input() 
    X.append(list(map(int,X_data.split())))

output=0

for i in range(N):
    for j in range(N):
        if i>j:
            dist=0
            for y, z in zip(X[i],X[j]):
                dist=dist+(y-z)**2
            if int(dist**(1/2))==dist**(1/2):
                output=output+1
            else:
                output=output+0
        else: pass
print(output)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

void solve(){
	string s;
	cin>>s;
	int n = s.size();
	int ctr=0;
	for(int i=0;i<n;i++){
		if(i <= n-1-i && s[i]!=s[n-1-i])
			ctr++;
	}
	cout <<ctr<<"\n";
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	
	solve();
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define forinc(i,a,b) for(int i=a;i<=b;++i)
#define fordec(i,a,b) for(int i=a;i>=b;--i)
#define fi first
#define se second
#define pii pair<int,int>

string s;
bool check(string A)
{
    string tmp=A;
    reverse(tmp.begin(),tmp.end());
    return tmp==A;
}
main()
{
    cin>>s;
    int n=s.size();
    if(check(s)&&check(s.substr(0,(n-1)/2))&&check(s.substr((n+3)/2-1,(n-1)/2))) cout<<"Yes";
    else cout<<"No";

}


Measured memory_bytes: 256