akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long i,n,c=0,k;
    cin>>n>>k;
    long long A[n];
    for(i=0;i<n;i++)
      cin>>A[i];
      sort(A,A+n);

    for(i=n-1;i>=(n-k);i--)
    {
      c+=A[i];
    
    }
  cout<<c<<endl;


  return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <utility>
#include <algorithm>

using namespace std;
int getbit(int x, int targ)
{

    int mask = 1;
    mask = mask << (targ - 1);
    if (x & mask)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}
int sum_of_on(vector<int> lists, int sws)
{
    int sum = 0;
    for (int i = 0; i < lists.size(); i++)
    {
        sum += getbit(sws, lists[i]);
    }
    return sum;
}

int main(void)
{

    int N, M;
    cin >> N >> M;
    vector<vector<int>> lamps;
    vector<int> check;
    for (int i = 0; i < M; i++)
    {
        int k = 0;
        cin >> k;
        int sum = 0;
        vector<int> switches;
        for (int j = 0; j < k; j++)
        {
            int tmp;
            cin >> tmp;
            switches.push_back(tmp);
        }
        lamps.push_back(switches);
    }
    for (int i = 0; i < M; i++)
    {
        int tmp;
        cin >> tmp;
        check.push_back(tmp);
    }

    int state = 0;
    for (int i = 0; i < pow(2, N); i++)
    {
        int flag = 1;
        for (int j = 0; j < M; j++)
        {
            int num = sum_of_on(lamps[j], i) % 2;

            if (num != check[j])
            {
                flag = 0;
            }
        }
        if (flag == 1)
        {

            state++;
        }
    }
    cout << state << std::endl;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(void)
{
    char s[5];
    cin>>s;
    if(s[0]==s[1] && s[2]==s[3] && s[0]!=s[2]) cout<<"Yes"<<endl;
    else if(s[0]==s[2] && s[1]==s[3] && s[0]!=s[1]) cout<<"Yes"<<endl;
    else if(s[0]==s[3] && s[1]==s[2] && s[0]!=s[1]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

num = 0
for i in range(N):
    if A[i] >= B[i]:
        num += B[i]
        A[i] -= B[i]
    else:
        num += A[i]
        remain = B[i] - A[i]
        A[i] = 0
        if remain > A[i + 1]:
            num += A[i + 1]
            A[i + 1] = 0
        else:
            num += remain
            A[i + 1] -= remain

print(num)

Measured memory_bytes: 18624
#include <iostream>
#define swap(type, x, y) do { type t = x; x = y; y = t; } while (0)
using namespace std;

void show(int arr[], int n)
{
	for (int i = 0; i < n; i++) {
		if (i == n - 1)
			cout << arr[i] << endl;
		else
			cout << arr[i] << ' ';
	}
}

int bubbleSort(int arr[], int n)
{
	int cnt = 0, flag = 1, i = 0;
	while (flag) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (arr[j] < arr[j - 1]) {
				swap(int, arr[j], arr[j - 1]);
				cnt++;
				flag = 1;
			}
		}
		i++;
	}
	return cnt;
}

int main()
{
	int n, *arr, cnt;

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

	cnt = bubbleSort(arr, n);
	show(arr, n);
	cout << cnt << endl;

	delete[] arr;
}


Measured memory_bytes: 3120
import sys
input = sys.stdin.readline
INF = 10**9
MOD = 10**9 + 7

def sieve(n):
    prime=[]
    limit=n**0.5
    data=[i+1 for i in range(1,n)]
    while True:
        p=data[0]
        if limit<=p:
            return prime+data
        prime.append(p)
        data=[e for e in data if e%p!=0]
   
primes = sieve(55556)

def main():
   n = int(input())
   
   ans = []
   for p in primes:
      if p%5 == 1:
         ans.append(p)
         if len(ans) == n:
            break
   
   print(*ans)
   
if __name__=='__main__':
    main()

Measured memory_bytes: 5528
s = input()
n = len(s)
s += "???"

i = 0
ans = 0

while i < n:
    abc = []
    if s[i] == "A":
        i += 1
        abc.append(0)
        while True:
            if s[i] == "A":
                i += 1
                abc.append(0)
            elif s[i:i+2] == "BC":
                i += 2
                ans += len(abc)
            else:
                break
    i += 1

print(ans)

Measured memory_bytes: 5096
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

int main()
{
    int N;

    cin >> N;

    for (int i = N; i >= 1; i--)
    {
        double a = sqrt(i);
        int b = a;
        if (fabs(a - b) < 0.00000001)
        {
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 888
using System;
using System.Collections.Generic;

namespace abc133_b
{
  class Program
  {
    static void Main(string[] args)
    {
      var n = CIn.ReadInt();
      var d = CIn.ReadInt();
      var x = new int[n, d];

      for (var i = 0; i < n; i++)
      {
        for (var j = 0; j < d; j++)
        {
          x[i, j] = CIn.ReadInt();
        }
      }

      var ans = 0;

      for (var i = 0; i < n - 1; i++)
      {
        for (var j = i + 1; j < n; j++)
        {
          var sum = 0;

          for (var k = 0; k < d; k++)
          {
            var diff = x[i, k] - x[j, k];
            sum += diff * diff;
          }

          var abs = Math.Sqrt(sum);
          if (abs == (int)abs) ans++;
        }
      }

      Console.WriteLine(ans);
    }
  }

  class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }

      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(long n)
    {
      var array = new string[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = Read();
      }

      return array;
    }

    public static int[] ReadIntArray(long n)
    {
      var array = new int[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadInt();
      }

      return array;
    }

    public static long[] ReadLongArray(long n)
    {
      var array = new long[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadLong();
      }

      return array;
    }
    public static double[] ReadDoubleArray(long n)
    {
      var array = new double[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadDouble();
      }

      return array;
    }
  }
}

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

int main(){
	
	int n;
	scanf("%d", &n);
	
	int num[n];
	int high = -101;
	int low = 101;
	
	for(int i = 0; i < n; i++){
		scanf("%d", &num[i]);
		if(high < num[i]){
			high = num[i];
		}
		if(low > num[i]){
			low = num[i];
		}
	}
		
	int bayar = 10000000;
	
	for(int i = low; i <= high; i++){
		int total = 0;
		for(int j = 0; j < n; j++){
			total += pow(i - num[j], 2);
		}
		if(total < bayar){
			bayar = total;
		}
	}
	
	printf("%d\n", bayar);
	
	return 0;
	
}

Measured memory_bytes: 1688
#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
#include <set>
#include <vector>
#include <cmath>
#include <bitset>
#include <functional>
#include <limits>
#include <map>
using namespace std;

typedef long long ll;
#define rep1(i, n) for(ll i = 1; i <=(ll)(n); i++)
#define rep0(i, n) for(ll i = 0; i <=(ll)(n); i++)

ll pow(ll a, ll n) { //compute a^n with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}

ll pow(ll a, ll n, ll mod) { //compute a^n (mod mod) with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    string s;
    cin >> s;
    int sum = 0;
    int max_sum = 0;
    rep0(i,s.length()-1){
        if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'){
            sum++;
            max_sum = max(max_sum, sum);
        }else{
            sum = 0;
        }
    }
    cout << max_sum << endl;
    return 0;
}

Measured memory_bytes: 3164
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
int main(void){
    int n;
    long long ans = 0;
    map<string, int> p;
    cin >> n;
    for(int i=0;i<n;i++){
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        p[s]++;
    }
    for(auto x=p.begin();x!=p.end();x++){
        long long y = x->second;
        ans += y*(y-1)/2;
    }
    cout << ans << endl;
}


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

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

#define rep(i,n) for (int i = 0; i < (n); i++)
#define ru(a,b) (((a)+((b)-1)) / (b))   //切り上げ(a/b)
#define dump(x)  cout << #x << " = " << (x) << endl;

int main()
{
	// 1～3桁
	// 0（成約なし）、1～5個の成約あり
	int n, m;
	cin >> n >> m;

	if (m == 0)
	{
		// n桁の最小数を出力
		if (n == 1) cout << 0;
		else cout << pow(10, n - 1);
	}
	else
	{
		// n桁で、Si...m桁目がCi...mであるもの
		map<int, int> se;
		int val = 0;
		rep(i, m) {
			int s, c;
			cin >> s >> c;
			if (se.find(s) == se.end()) {
				if (n != 1 && s == 1 && c == 0) {
					cout << -1;
					return 0;
				}
				val += c * pow(10, (n - s + 1) - 1);
				se[s] = c;
			}
			else if (se[s] != c)
			{
				cout << -1;
				return 0;
			}
		}

		if (n == 1) {
			cout << val;
		}
		else {
			if (val < pow(10, n - 1)) val += pow(10, n - 1);
			cout << val;
		}


	}

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll a,b,c,k; cin >> a >> b >> c >> k;
  if(k<=a){
    cout << k << endl;
    return 0;
  }
  if(a<k && k <=a+b){
    cout << a << endl;
    return 0;
  }
  cout << a-(k-(a+b)) << endl;
  return 0;
}

Measured memory_bytes: 3632
n, t = gets.chomp.split.map(&:to_i)

ary = []
n.times do
  ci, ti = gets.chomp.split.map(&:to_i)
  ary << [ci,ti]
end

min = Float::INFINITY
ary.each do |item|
  if item[1] <= t
    min = [min, item[0]].min
  end
end
if min == Float::INFINITY
  print('TLE')
else
  print(min)
end


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int n,num[13],a[55],x[25],ans=0;
void check(){
	int w[25],d[13],tmp=0,Min=1e9;
	memset(w,0,sizeof (w));
	for(int i=1;i<=24;i++){
		//cout<<"X["<<i<<"]="<<x[i]<<"\n";
		if(x[i]==1){
			//cout<<"IN\n";
			w[++tmp]=i;
		}else if(x[i]>=2){
			return;
		}
	}
	/*cout<<"TIME:\n";
	for(int i=1;i<=tmp;i++){
		printf("%d ",w[i]);
	}
	puts("");*/
	w[0]=0;
	for(int i=1;i<=tmp;i++){
		Min=min(Min,w[i]-w[i-1]);
		//cout<<"MIN "<<Min<<"\n";
	}
	Min=min(Min,min(24-w[tmp],w[tmp]));
	ans=max(ans,Min);
	//cout<<"ANS="<<ans<<"\n";
}
void dfs(int q){
	if(q==13){
	  check();
	  return ;
	}
	if(num[q]==1){
		x[q]++;
		//cout<<"INS "<<q<<"\n";
		dfs(q+1);
		x[q]--;
		//cout<<"ERA "<<q<<"\n";
		x[24-q]++;
		//cout<<"INS "<<24-q<<"\n";
		dfs(q+1);
		x[24-q]--;
		//cout<<"ERA "<<24-q<<"\n";
	}
	if(num[q]==2){
		x[q]++;
		//cout<<"INS "<<q<<"\n";
		x[24-q]++;
		//cout<<"INS "<<24-q<<"\n";
		dfs(q+1);
		x[q]--;
		//cout<<"ERA "<<q<<"\n";
		x[24-q]--;
		//cout<<"ERA "<<24-q<<"\n";
	}
	if(num[q]==0)
	  dfs(q+1);
}
int main(){
	memset(x,0,sizeof(x));
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
	  scanf("%d",&a[i]);
	  num[a[i]]++;
	  if(num[a[i]]>2){
	  	puts("0");
	  	return 0;
	  }
	}
	if(num[0]){
		puts("0");
		return 0;
	}
	dfs(1);
	printf("%d",ans>=1e9?0:ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define speed() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(x) (int)(x).size()
#define _USE_MATH_DEFINES
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
    speed();
    string s; cin >> s;
    bool is = true;
    sort(all(s));
    rep(i, 0, s.size()) {
        if (s[i] == s[i+1]) is = false;
    }
    (is) ? cout << "yes" << endl : cout << "no" << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = 1
c = int(1e18)
flag = 0
for i in range(n):
    if a[i]==0:
        flag = 1
if flag==1:
    print(0)
    exit()
for i in range(n):
    b *= a[i]
    if b>c:
        print(-1)
        exit()
print(b)

Measured memory_bytes: 84500
#include<stdio.h>
int main(){
  char c;
  scanf("%c",&c);
  if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'){
    printf("vowel");
  }else{
    printf("consonant");
  }
  return 0;
}

Measured memory_bytes: 128
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        String op = sc.next();
        int B = sc.nextInt();
        if (op.charAt(0) == '+') {
            System.out.println(A + B);
        } else {
            System.out.println(A - B);
        }
    }
}

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

int update(vector<vector<int> > &grid, vector<vector<bool> > &del){
  int h = grid.size();
  int res = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < 5; j++) {
      if(del[i][j]){
        res += grid[i][j];
      }
    }
  }
  for (int i = 0; i < 5; i++) {
    int drop = 0;
    for (int j = h - 1; j >= 0; j--) {
      if(del[j][i] == true){
        drop++; 
      }else{
        grid[j + drop][i] = grid[j][i];
      }
    }
    for (int j = 0; j < drop; j++) {
      grid[j][i] = -1;
    }
  }
  // for (int i = 0; i < h; i++) {
  //   for (int j = 0; j < 5; j++) {
  //     std::cout << grid[i][j];
  //   }
  //   std::cout << std::endl;
  // }
  //   std::cout << std::endl;
  //   std::cout << std::endl;
  return res;
}

int main(){
  int h;
  while(std::cin >> h, h){
    int ans = 0;
    vector<vector<int> > grid(h, vector<int>(5));
    for (int i = 0; i < h; i++) 
      for (int j = 0; j < 5; j++) 
        std::cin >> grid[i][j];
    bool flag = true;
    while(flag){
      vector<vector<bool> > del(h, vector<bool>(5, false));
      flag = false;
      for (int i = 0; i < h; i++) {
      int cnt = 0;
        for (int j = 0; j < 4; j++) {
          if(grid[i][j] == grid[i][j + 1] and grid[i][j] >= 0){
            cnt++; 
          }else{
            if(cnt >= 2){
              flag = true;
              for (int k = 0; k <= cnt; k++)del[i][j - k] = true;
            }
            cnt = 0; 
          }
        }
        if(cnt >= 2){
          flag = true;
          for (int k = 0; k <= cnt; k++)del[i][4 - k] = true; 
        }
      }
      ans += update(grid, del);
    }
    std::cout << ans << std::endl;
  }
  return 0;
}

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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const long double EPS = 0.0000000001;

int n;
int main(){
	cin >> n;
	int ans = 0;
	for(int i = 1; i <= n; i=i+2){
		int count = 0;
		for(int j = 1; j <= i; j++){
			if(i % j == 0)count++;
		}
		if(count == 8)ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
 
typedef struct dice{
    int face[6];
}dice;
 
void rotate(dice *d, char dir)
{
    int temp;
    switch(dir) {
    case 'N':
        temp=d->face[0];
        d->face[0]=d->face[1];
        d->face[1]=d->face[5];
        d->face[5]=d->face[4];
        d->face[4]=temp;
        break;
    case 'E':
        temp=d->face[0];
        d->face[0]=d->face[3];
        d->face[3]=d->face[5];
        d->face[5]=d->face[2];
        d->face[2]=temp;
        break;
    case 'W':
        temp=d->face[0];
        d->face[0]=d->face[2];
        d->face[2]=d->face[5];
        d->face[5]=d->face[3];
        d->face[3]=temp;
        break;
    case 'S':
        temp=d->face[0];
        d->face[0]=d->face[4];
        d->face[4]=d->face[5];
        d->face[5]=d->face[1];
        d->face[1]=temp;
        break;
    }
}
 
int isSame(dice d1, dice d2)
{
    static const char dir[]="NNNESSSWNNNESSSWNNNESSSW";
    int i, j;
    for(i=0; i<24; i++) {
        for(j=0; j<6 && d1.face[j]==d2.face[j]; j++);
        if(j==6) return 1;
        rotate(&d2, dir[i]);
    }
    return 0;
}
 
int main()
{
    dice d[100];
    int i, j, n;
    scanf("%d", &n);
    for(i=0; i<n; i++) {
        for(j=0; j<6; j++) {
            scanf("%d", &d[i].face[j]);
        }
        for(j=0; j<i; j++) {
            if(isSame(d[i], d[j])) {
                puts("No");
                return 0;
            }
        }
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <cstdlib>
#include <cmath>

using namespace std;
typedef long long ll;

int main() {
	int n, m;
	int ans[60] = {};
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		ans[a]++; ans[b]++;
	}
	for (int i = 1; i <= n; i++) {
		cout << ans[i] << endl;
	}
	return 0;
}

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

#define MAX 500000
#define NIL -1

struct node {
	int location, l, r;
};

struct point {
	int id, x, y;
	bool operator <(const point &p) const {
		return id < p.id;
	}
	void print() {
		printf("%d\n", id);
	}
};

point P[MAX];
node T[MAX];
int np;

bool lessX(const point &p1, const point &p2) {
	return p1.x < p2.x;
}
bool lessY(const point &p1, const point &p2) {
	return p1.y < p2.y;
}

int make2dtree(int l, int r, int d) {
	if (!(l < r))
		return NIL;
	if (d % 2 == 0)
		sort(&P[l], &P[r], lessX);
	else
		sort(&P[l], &P[r], lessY);
	int mid = (l + r) / 2;
	int t = np++;
	T[t].location = mid;
	T[t].l = make2dtree(l, mid, d + 1);
	T[t].r = make2dtree(mid + 1, r, d + 1);
	return t;
}

void find(int v, int sx, int tx, int sy, int ty, int d, vector<point> &ans) {
	int x = P[T[v].location].x;
	int y = P[T[v].location].y;
	if (sx <= x && x <= tx && sy <= y && y <= ty)
		ans.push_back(P[T[v].location]);
	if (d % 2 == 0) {
		if (T[v].l != NIL && sx <= x)
			find(T[v].l, sx, tx, sy, ty, d + 1, ans);
		if (T[v].r != NIL && x <= tx)
			find(T[v].r, sx, tx, sy, ty, d + 1, ans);
	} else {
		if (T[v].l != NIL && sy <= y)
			find(T[v].l, sx, tx, sy, ty, d + 1, ans);
		if (T[v].r != NIL && y <= ty)
			find(T[v].r, sx, tx, sy, ty, d + 1, ans);
	}
}

int main() {
	np = 0;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		P[i].id = i;
		scanf("%d %d", &P[i].x, &P[i].y);
		T[i].l = T[i].r = T[i].location = NIL;
	}
	int r = make2dtree(0, n, 0);
	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int sx, tx, sy, ty;
		scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
		vector<point> ans;
		find(r, sx, tx, sy, ty, 0, ans);
		sort(ans.begin(), ans.end());
		for (int j = 0; j < ans.size(); j++) {
			ans[j].print();
		}
		printf("\n");
	}
	return 0;
}



Measured memory_bytes: 14604
n = gets.to_i
lines = gets.chomp.split("")

cusum  = [[0,lines[1..n].count("E")]]

1.upto(n-1) do |i|
  cusum << [cusum[i-1][0] + (lines[i-1]=="W"?1:0), cusum[i-1][1]-(lines[i]=="E"?1:0)]
end

puts cusum.min_by{|arr| arr[0]+arr[1]}.inject(:+)

Measured memory_bytes: 46468
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int A,B;
    cin >> A >> B;
    cout << A*B - A - B + 1<< endl;
}

Measured memory_bytes: 256
import math
n,m=map(int,input().split())
a=list(map(int,input().split()))
s=sum(a)
t=math.ceil(s/4/m)
a.sort()

cnt=0
for i in a:
  if i>=t:
    cnt+=1

if cnt>=m:
  print('Yes')
  
else:
  print('No')

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

int N;

int main() {
    cin >> N;
    vector<int> a(N);
    int sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        sum += a[i];
    }
    int average = sum < 0? (sum - N / 2) / N: (sum + N / 2) / N;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        ans += (a[i] - average) * (a[i] - average);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
use proconio::input;
// use proconio::marker::{Bytes, Chars};
// use std::collections::hash_set::HashSet;

fn main() {
    input! {
        n: usize,
        l: [i32; n],
    }

    let mut count = 0;

    for i in 0..l.len() {
        for j in i+1..l.len() {
            for k in j+1..l.len() {
                if l[i] < l[k] + l[j] && l[j] < l[i] + l[k] && l[k] < l[i] + l[j] 
                    && l[i] != l[k] && l[j] != l[k] && l[j] != l[i] {
                    count += 1;
                }
            }
        }
    }
    println!("{}", count);
}

Measured memory_bytes: 2128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#include <cassert>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define Cout(x) cout << x << endl;
#define check(v) rep(i,v.size()) cout << v[i] << endl;
#define vint(x) vector<int> x
#define vll(x) vector<long long> x
#define vstr(x) vector<string> x
const long long LLINF = 1LL<<60;
const int INF = 1e9;
const long long MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
#define pint pair<int,int>
#define pll pair<ll,ll>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    vector<int> v(n);
    rep(i,n) cin >> v[i];
    int ans = INF;
    rep(i,101) {
        int num = 0;
        rep(j,n) {
            num += (v[j]-i)*(v[j]-i);
        }
        ans = min(ans,num);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {

	var ex int64

	//入力
	var N int
	fmt.Scan(&N)

	monster := make([]int64, N + 1 )
	brave := make([]int64, N )

	for i := 0 ; i < N + 1 ; i++ {
		fmt.Scan(&monster[i])
	}
	for i := 0 ; i < N ; i++ {
		fmt.Scan(&brave[i])
	}

	for i := N - 1 ; i >= 0 ; i-- {
		//一ターン目
		if brave[i] > monster[i+1] {
			brave[i] -= monster[i+1]
			ex += monster[i+1]
		}else if brave[i] == monster[i+1] {
			brave[i] = 0
			ex += monster[i+1]
		}else {
			ex += brave[i]
			brave[i] = 0
		}
		//2ターン目
		if brave[i] > monster[i] {
			brave[i] -= monster[i]
			ex += monster[i]
			monster[i] = 0
		}else if brave[i] == monster[i] {
			brave[i] = 0
			ex += monster[i]
			monster[i] = 0

		}else {
			monster[i] -= brave[i]
			ex += brave[i]
			brave[i] = 0
		}


	}

	fmt.Println(ex)
	
}



Measured memory_bytes: 6528
K, N = map(int, input().split())
A = list(map(int, input().split()))
B = sorted(A)
C = [] * N
L = 0
for i in range(N):
    if i == 0:
        x = K - B[N - 1] + B[0]
    else:
        x = B[i - 1] - B[i]
    y = abs(x)
    if L < y:
        L = y
ans = K - L
print(ans)

Measured memory_bytes: 26444
#include<iostream>
#include<cstdio>
#define MN 100
#define mod 1000000007
#define pa pair<int,int>
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
pa q[MN+5];
int head[MN+5],n,m,cnt=0,K,ans=1,dfn[MN+5],now,top,dn,low[MN+5],p[205],inv[205],vis[MN+5];
struct edge{int to,next;}e[MN*2+5];
inline void ins(int f,int t)
{
    e[++cnt]=(edge){t,head[f]};head[f]=cnt;
    e[++cnt]=(edge){f,head[t]};head[t]=cnt;
}
inline int gcd(int x,int y){return y?gcd(y,x%y):x;}
inline int C(int n,int m){return 1LL*p[n]*inv[m]%mod*inv[n-m]%mod;}
inline int pow(int x,int k)
{
    int sum=1;
    for(;k;k>>=1,x=1LL*x*x%mod) if(k&1) sum=1LL*sum*x%mod;
    return sum;
}
void dfs(int x,int fa)
{
    dfn[x]=low[x]=++dn;
    for(int i=head[x];i;i=e[i].next)
        if(!dfn[e[i].to])
        {
            q[++top]=make_pair(x,e[i].to);dfs(e[i].to,x);
            low[x]=min(low[x],low[e[i].to]);
            if(low[e[i].to]>=dfn[x])
            {
                ++now;int V=0,E=0;
                for(;q[top+1]!=make_pair(x,e[i].to);--top)
                {
                    ++E;
                    if(vis[q[top].first]!=now) vis[q[top].first]=now,++V;
                    if(vis[q[top].second]!=now) vis[q[top].second]=now,++V;
                }
               // cout<<V<<" "<<E<<endl;
                if(V>E) ans=1LL*ans*K%mod;
                else if(V==E)
                {
                    int res=0;
                    for(int j=0;j<V;++j) res=(res+pow(K,gcd(V,j)))%mod;
                    ans=1LL*ans*res%mod*inv[V]%mod*p[V-1]%mod;
                }
                else ans=1LL*ans*C(E+K-1,K-1)%mod;
            }
        }
        else
        {
            if(e[i].to!=fa&&dfn[e[i].to]<dfn[x]) q[++top]=make_pair(x,e[i].to);
            low[x]=min(low[x],dfn[e[i].to]);
        }
}
int main()
{
    n=read();m=read();K=read();p[0]=p[1]=inv[0]=inv[1]=1;
    for(int i=2;i<=200;++i) p[i]=1LL*p[i-1]*i%mod,inv[i]=1LL*(mod-mod/i)*inv[mod%i]%mod;
    for(int i=2;i<=200;++i) inv[i]=1LL*inv[i-1]*inv[i]%mod;
    for(int i=1;i<=m;++i) ins(read(),read());
    for(int i=1;i<=n;++i) if(!dfn[i]) dfs(i,0);
    cout<<ans;
    return 0;
}



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

# define fori(i,n)          for(int i=0;i<n;i++)
# define forl(i,n)          for (ll i=0;i<n;i++)
# define pb                 push_back
# define mp                 make_pair
# define X                  first
# define Y                  second
# define all(v)             v.begin(),v.end()
# define in_ar_int(arr,n)   int arr[n]; fori(i,n) cin >> arr[i];
# define in_ar_ll(arr,n)    ll arr[n]; fori(i,n) cin >> arr[i];
# define endl               "\n"
# define R0                 return 0
# define mod                1000000007
# define pi                 3.1415926536


typedef long long ll;
typedef string str;

 
ll power (ll a, ll b){
    ll ans=1;
    while(b){
		if (b & 1) ans*=a;
		a*=a;
		b/=2;
    }
    return ans;
}

bool isprime(int n) { 
    if (n <= 1) return false; 
    if (n <= 3) return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
    for (int i=5; i*i<=n; i=i+6){
		if (n%i == 0 || n%(i+2) == 0) 
		return false; 
	}
    return true; 
} 

long long nCr(int n,int r){
    if(n==r) return 1;
    else if (r==0) return 1;
    else return nCr(n-1,r-1)+nCr(n-1,r);
}

int sdigit(int x){
    int ans=0;
    while(x){
		ans+=x%10;
		x/=10;
    }
    return ans;
}

int bs(int a[],int b,int l,int r){
    int mid=l + (r-l)/2;
    if(l>r) return -1;
    if(a[mid]==b||l==r)	return mid;
    if(a[mid]>b)	return bs(a,b,l,mid-1);
    else return bs(a,b,mid+1,r);
}

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


void solve(){
    int n; cin >> n;
    in_ar_ll(a,n);
    sort(a,a+n);
    ll sum=a[n-1];
    for (int i=0;i<n-2;i++){
        sum+=a[n-2-(i/2)];
    }
    cout << sum;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int chill=1;
    // cin >> chill;
    while(chill--){
	solve();
    }
}



Measured memory_bytes: 5172
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int a[100005],b[100005];

int main()
{
    //printf("%d",int(ceil(double(45/9))));
int n,total;
    scanf("%d%d",&n,&total);
    for (int i=0; i<n; i++)
    {
        scanf("%d%d",&a[i],&b[i]);
    }

    sort(a,a+n);
    sort(b,b+n);
    int pos = upper_bound(b,b+n,a[n-1])-b;
    //cout<<pos<<endl;
    int pos2 = n-1;
    int ans = 0;
    while(total>0 && pos2>=pos)
    {
        total -=b[pos2];
        pos2--;
        ans++;
    }
    //cout<<total<<endl;
    //int cnt = ceil(total*1.0/a[n-1]);
    if(total >0)
    {
        int cnt = total / a[n-1];
        if(cnt * a[n-1] != total)
            cnt++;
    ans += cnt;
    }

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


    return 0;
}


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

ll mod = 998244353;

struct segtree{
    int size;
    vector<ll> dat;
    ll init = -1;

    segtree (int N) {
        size = 1;
        while (size < N) size *= 2;
        dat = vector<ll>(2*size-1, init);
    }

    ll op(ll a, ll b) {
        return max(a, b);
    }

    void update(int i, ll x) { 
        i += size-1;
        dat[i] = x;
        while (i > 0) {
            i = (i-1)/2;
            dat[i] = op(dat[2*i+1], dat[2*i+2]);
        }
        return;
    }

    ll query(int a, int b) {
        return query(a, b, 0, 0, size);
    }

    ll query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return init;
        if (a <= l && r <= b) return dat[k];
        ll lv, rv;
        lv = query(a, b, 2*k+1, l, (l+r)/2);
        rv = query(a, b, 2*k+2, (l+r)/2, r);
        return op(lv, rv);
    }
};

int main() {
    int N;
    cin >> N;
    vector<pair<ll, ll>> robo(N);
    for (int i = 0; i < N; i++) cin >> robo[i].first >> robo[i].second;
    sort(robo.begin(), robo.end());
    
    segtree st(N+10);
    
    vector<vector<ll>> dp(N, vector<ll>(2, 0));
    dp[N-1][0] = 1;
    dp[N-1][1] = 1;
    st.update(N-1, N-1);
    
    for (int i = N-2; i >= 0; i--) {
        dp[i][0] = (dp[i+1][0] + dp[i+1][1])%mod;
        pair<ll, ll> rm = {robo[i].first + robo[i].second, 0};
        auto it = lower_bound(robo.begin(), robo.end(), rm);
        int pos = distance(robo.begin(), it);
        if (pos == i+1) {
            st.update(i, i);
            dp[i][1] = dp[i][0];
        }else {
            ll h = st.query(i+1, pos);
            st.update(i, h);
            dp[i][1] = dp[h][1];
        }
    }
    cout << (dp[0][0] + dp[0][1])%mod << endl;
    return 0;
}

Measured memory_bytes: 18432
#include <stdio.h>

int main(){

  int i,j,A[1000],N,v;

  scanf("%d",&N);

  for(i=0;i<=N-1;i++){
    scanf("%d",&A[i]);
  }

  for(i=0;i<=N-1;i++){
    v = A[i];
    j = i - 1;

    while(j >= 0 && A[j] > v){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;

    for(j=0;j<N-1;j++){
      printf("%d ",A[j]);
    }
    printf("%d",A[N-1]);
    printf("\n");

  }
  return 0;
}

Measured memory_bytes: 608
#include<iostream>
#define N 32768
long a[N],b[N],n,k,i=N,j;int main(){for(std::cin>>n>>k;--i;b[i]=i<n?i:n)a[i]=n/i;while(--k){for(std::swap(a,b);++i<N;)b[i]+=b[i-1];for(j=b[n/--i];--i;a[i]=j%=0x3B9ACA07)j+=a[i]*=n/i-n/(i+1);}std::cout<<j;}

Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<(b)?(a=b,1):0)
#define chmin(a,b) (a>(b)?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
const int INF = 1<<29;
const double EPS = 1e-8;
typedef pair<int,int> pii;
typedef long long ll;

vector<int> compress(vector<int> &x) {
  vector<int> v(x);
  sort(ALL(v));
  v.erase(unique(ALL(v)), v.end());
  FOR(it, x) {
    *it = find(ALL(v), *it) - v.begin();
  }
  return v;
}

int x1[50],y1[50],z1[50];
int x2[50],y2[50],z2[50];
int imos[100][100][100];

int main() {
  int n,k;
  while(cin>>n>>k) {
    vector<int> xs,ys,zs;
    REP(i,n) {
      cin >> x1[i] >> y1[i] >> z1[i];
      cin >> x2[i] >> y2[i] >> z2[i];
      xs.push_back(x1[i]); xs.push_back(x2[i]);
      ys.push_back(y1[i]); ys.push_back(y2[i]);
      zs.push_back(z1[i]); zs.push_back(z2[i]);
    }
    vector<int> cxs = compress(xs);
    vector<int> cys = compress(ys);
    vector<int> czs = compress(zs);
    memset(imos,0,sizeof(imos));
    REP(i,n) {
      int p1 = i*2;
      int p2 = i*2+1;
      for (int x=xs[p1]; x<xs[p2]; ++x) {
        for (int y=ys[p1]; y<ys[p2]; ++y) {
          imos[x][y][zs[p1]]++;
          imos[x][y][zs[p2]]--;
        }
      }
    }
    ll ans = 0;
    REP(x,cxs.size()) {
      REP(y,cys.size()) {
        int c = 0;
        REP(z,czs.size()) {
          c += imos[x][y][z];
          if (c >= k) {
            ans += (ll)(cxs[x+1]-cxs[x])*(cys[y+1]-cys[y])*(czs[z+1]-czs[z]);
          }
        }
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 5128
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define MOD (long long int)(1e9+7)
#define INF (int)(1e9)
#define LINF (long long int)(1e18)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}



int main(void){
  fast_io
  cout<<fixed<<setprecision(15);
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  rep(i,k){
	  if(a >= b){
		  b *= 2;
	  }else if(b >= c){
		  c*=2;
	  }else{
		  break;
	  }
  }
  if(a < b && b < c){
	  cout << "Yes" << endl;
  }else{
	  cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 3640
#include <iostream>
using namespace std;
#define MARK 4
#define RANK 13
#define CHECK 1	
int main(void)
{
	int n,rank,a,i,k;
	char mark;
	int card[4]={0};
	char mk[4]={'S','H','C','D'};
	cin >> n;
	for(i=0; i<n; i++){
		cin >> mark >> rank;
		if(mark == 'S'){
			a=1;
			a <<= rank;
			card[0] += a;
		}else if(mark == 'H'){
			a=1;
			a <<= rank;
			card[1] += a;
		}else if(mark == 'C'){
			a=1;
			a <<= rank;
			card[2] += a;
		}else if(mark == 'D'){
			a=1; 
			a <<= rank;
			card[3] += a;
		}
	}
	for(i=0; i<MARK; i++){
		for(k=1; k<=RANK; k++){
			card[i] >>= 1;
			if((card[i] & CHECK) == 0){
				cout << mk[i]<< " " << k << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1160
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
     
using namespace std;
     
typedef long long ll;
typedef pair<int, int> pii;
     
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
     
mt19937 rnd(chrono::steady_clock().now().time_since_epoch().count());


int main(){
    fastIO;
    int a, p;
    cin >> a >> p;
    int r = a * 3 + p;
    cout << r/2;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

#define MOD 1000000007LL;

uint64_t dp[123456][13];

int main(int argc, char** argv) {
  int i, j, k;
  uint64_t res = 0;

  string s;
  cin >> s;
  int n = s.size();

  dp[0][0] = 1;
  rep(i, n) {
    int c;
    if (s[i] == '?') {
      c = -1;
    } else {
      c = s[i] - '0';
    }

    rep(j, 10) {
      if (c != -1 && j != c) {
        // If c is not '?', only the specified number must be summed.
        continue;
      }
      rep(k, 13) {
        dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
      }
    }

    // MOD
    rep(k, 13) {
      dp[i + 1][k] %= MOD;
    }
  }
  res = dp[n][5];

  cout << res << endl;
  return 0;
}


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

int main() {
  int64_t N, K, Q;
  cin >> N >> K >> Q;
  vector<int64_t> A(Q);
  vector<int64_t> P(N, 0);
  
  rep(i, Q) cin >> A[i];
  
  rep(i, Q){
  	P[A[i]-1]++;
  }
  
  rep(i, N){
  	if(K - (Q - P[i]) > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }

}

Measured memory_bytes: 2176
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

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

	ll n;
	string s;
	cin >>n>> s;
	if (n % 2 == 0) {
		ll nn = n / 2;
		if (s.substr(0, nn) == s.substr(nn, nn)) {
			cout << "Yes" << endl;
			return 0;
		}

	}

	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

// BEGIN CUT HERE
template<class T> struct PrimalDual {
  struct Edge { int to, rev; T cap, cost; };
  const T inf = numeric_limits<T>::max();
  const int n;
  VV<Edge> g;
  V<T> pot, dist;
  V<> pv, pe;
  PrimalDual(int n) : n(n), g(n), pot(n), dist(n), pv(n), pe(n) {}
  void add_edge(int from, int to, T cap, T cost) {
    assert(from != to);
    assert(cap >= 0);
    if (!cap) return;
    assert(cost >= 0);
    g[from].emplace_back(Edge{to, (int) g[to].size(), cap, cost});
    g[to].emplace_back(Edge{from, (int) g[from].size() - 1, 0, -cost});
  }
  void dijkstra(int s) {
    using P = pair<T, int>;
    priority_queue< P, V<P>, greater<P> > pque;
    fill(begin(dist), end(dist), inf);
    pque.emplace(dist[s] = 0, s);
    while (!pque.empty()) {
      T d; int v;
      tie(d, v) = pque.top(); pque.pop();
      if (d > dist[v]) continue;
      for (int i = 0; i < (int) g[v].size(); ++i) {
        const Edge& e = g[v][i];
        if (!e.cap or dist[e.to] <= dist[v] + e.cost - (pot[e.to] - pot[v])) continue;
        pv[e.to] = v, pe[e.to] = i;
        pque.emplace(dist[e.to] = dist[v] + e.cost - (pot[e.to] - pot[v]), e.to);
      }
    }
  }
  T min_cost_flow(int s, int t, T f) {
    assert(s != t);
    assert(f >= 0);
    T res = 0;
    fill(begin(pot), end(pot), 0);
    while (f > 0) {
      dijkstra(s);
      if (dist[t] == inf) return -1;
      for (int v = 0; v < n; ++v) pot[v] += dist[v];
      T d = f;
      for (int v = t; v != s; v = pv[v]) {
        d = min(d, g[pv[v]][pe[v]].cap);
      }
      f -= d;
      res += d * pot[t];
      for (int v = t; v != s; v = pv[v]) {
        Edge& e = g[pv[v]][pe[v]];
        e.cap -= d;
        g[v][e.rev].cap += d;
      }
    }
    return res;
  }
};
// END CUT HERE

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, m, f; cin >> n >> m >> f;
  PrimalDual<int> g(n);
  while (m--) {
    int u, v, c, d; cin >> u >> v >> c >> d;
    g.add_edge(u, v, c, d);
  }
  cout << g.min_cost_flow(0, n - 1, f) << '\n';
}


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

int main(){
  int K,S,ans=0;
  cin>>K>>S;
  for(int x=0;x<=K;x++){
    for(int y=0;y<=K;y++){
      int z=S-x-y;
      if(0<=z&&z<=K)ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

template<typename T> istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

template<typename T> bool chmin(T& a, T b) {return a > b ? a = b, true : false;}

template<typename T> bool chmax(T& a, T b) {return a < b ? a = b, true : false;}

int main() {
  int64_t n, r = numeric_limits<int64_t>::max();
  cin >> n;
  for (int64_t a = 1; a * a <= n; ++a) {
    if (n % a) continue;
    chmin(r, int64_t(log10(n / a)) + 1);
  }
  cout << r << endl;
}



Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define FORCLS(i,a,b) for(int i = (a); i <= (b); i++)
#define REPCLS(i,n) FORCLS(i,1,n)

using Int = long long int;

Int  n,x;

void solve() {
    cin >> n >> x;
    Int ans = 0;
    Int a0, a1;
    cin >> a0;
    
    REP(i, n - 1) {
        cin >> a1;
        Int d = (a0 + a1) - x;
        if (d <= 0) {
            a0 = a1;
            continue;
        }
        ans += d;
        d = min(d, a1);
        a0 = a1 - d;
    }
    cout << ans << endl;
}


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


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

struct UnionFind{
    vector<int>parent;//親の番号
    UnionFind(int N):parent(N){
        rep(i,N){
            parent[i]=i;
        }
    }//全て根であるとして初期化
    int root(int x){
        if(parent[x]==x){
            return x;
        }
        return parent[x]=root(parent[x]);
    }//根を探す
    void unite(int x,int y){
        int rx=root(x);
        int ry=root(y);
        if(rx==ry){
            return;
        }
        parent[rx]=ry;
    }//xの根をyの根にくっつける
    bool same(int x,int y){
        int rx=root(x);
        int ry=root(y);
        return rx==ry;
    }//x,yの属する木が同じならtrue
};

int Renketucount(int N,int A,UnionFind tree){
    int count=0;
    rep(i,N){
        if(tree.same(A,i)){
            count++;
        }
    }
    return count;
}

void make_UF(int M,int k,const vector<pair<int,int>>A,UnionFind &tree){
    rep(i,M){
        if(i!=k){
            tree.unite(A[i].first,A[i].second);
        }
    }
}

int main(){
    int N,M;cin>>N>>M;
    vector<pair<int,int>>HEN(M);
    int cnt=0;
    rep(i,M){
        int a,b;cin>>a>>b;
        a--;b--;
        HEN[i].first=a;
        HEN[i].second=b;
    }
    rep(k,M){
        UnionFind tree(N);
        make_UF(M,k,HEN,tree);
        if(N!=Renketucount(N,0,tree)){
            cnt++;
        }
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;

int main() {
	int N;
	cin >> N;
	vector<long long>A(N), B(N), C(N);
	for (size_t i = 0; i < N; i++)
	{
		cin >> A.at(i);
	}
	for (size_t i = 0; i < N; i++)
	{
		cin >> B.at(i);
	}
	for (size_t i = 0; i < N; i++)
	{
		cin >> C.at(i);
	}
	sort(A.begin(), A.end());
	sort(B.begin(), B.end());
	sort(C.begin(), C.end());
	vector<long long> ABpile(N);//A.at(j)<B.at(i)となるようなAの個数
	for (size_t i = 0; i < N; i++)
	{
		auto it = lower_bound(A.begin(), A.end(), B.at(i));
		ABpile.at(i) += distance(A.begin(), it);
		if (i != N - 1)ABpile.at(i + 1) += ABpile.at(i);
	}
	long long ans=0;
	for (size_t i = 0; i < N; i++)
	{
		auto it = lower_bound(B.begin(), B.end(), C.at(i));
		if(it!=B.begin())ans += ABpile.at(distance(B.begin(), it)-1);
	}
	cout << ans;

}

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

int main(){
  int A,B,K;
  cin >> A >> B >> K;
  vector<int> ans;
  rep(i,100){
    if(0 == A%(i+1) && 0 == B%(i+1)){
      ans.push_back(i+1);
    }
  }
  reverse(ans.begin(),ans.end());
  cout << ans.at(K-1) << endl;
}

Measured memory_bytes: 256
/**
 *    author:  FromDihPout
 *    created: 2020-08-25
**/

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


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, x, t;
    cin >> n >> x >> t;
    int ans = (n / x) + (n % x != 0);
    ans *= t;
    cout << ans << '\n';
    return 0;
}

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

using namespace std;

const int N = 2e5 + 5;

int n;
int a[N];
long long sum[N];

inline long long getsum(int l, int r) {
  if (l > r) {
    return 0;
  }
  return l == 0 ? sum[r] : sum[r] - sum[l - 1];
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  long long ans = 0;
  if (a[0] != 0) {
    puts("-1");
    return 0;
  }
  for (int i = 1; i < n; ++i) {
    if (a[i] > i) {
      puts("-1");
      return 0;
    }
    if (a[i + 1] != a[i] + 1) {
      ans += a[i];
    }
    if (a[i + 1] > a[i] && a[i + 1] > a[i] + 1) {
      puts("-1");
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int N,K;
  cin >> N >> K;
  vector<long long> vec(N);
  for (int i = 0; i< N; i++) {
    cin >> vec.at(i);
  }
  
  sort(vec.begin(),vec.end());
  
  long long ans = 1000000000;
  for (int i = 0; i < N-K+1; i++) {
    ans = min(ans,vec.at(i+K-1)-vec.at(i));
  }
  cout << ans << endl; 
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <utility>
using namespace std;

#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i > b; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)

int n, k;

int p;

int main() {
  k = 38;
  n = 1407;
  cout << n << " " << k << endl;

  p = k-1;

  REP(col, k) {
    cout << n;
    REP(row, p) { cout << " " << 1+row+col*p; }
    cout << endl;
  }

  REP(i, p) {
    REP(s, p) {
      cout << p*p+1+i;
      REP(col, k-1) { cout << " " << 1 + (s + i*col)%p+ col*p; }
      cout << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 512
n = int(input())
A = list(map(int, input().split()))

total = sum(A)

s = 0
for a in A:
	s += a
	if 2 * s >= total:
		break

B = A[::-1]
t = 0
for b in B:
	t += b
	if 2 * t >= total:
		break

print(min(2*s-total, 2*t-total))

Measured memory_bytes: 89164