akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

using namespace std;
using uint = unsigned int;

struct witness {
    uint honest, unkind;
    
    void set(int x, int y) {
        if(y) {
            honest |= 1u << x;
        } else {
            unkind |= 1u << x;
        }
    }
    
    bool test(uint v, int i) const {
        if(v & (1u<<i)) return ((honest & v) == honest) && ((unkind & v) == 0u);
        return true;
    }
};

bool test(const vector<witness>& ws, uint v) {
    for(int i=0; i<ws.size(); i++) if(!ws[i].test(v, i)) return false;
    return true;
}

constexpr uint bitcount(uint x) {
    x = (x & 0x5555) + ((x>>1) & 0x5555);
    x = (x & 0x3333) + ((x>>2) & 0x3333);
    x = (x & 0x0f0f) + ((x>>4) & 0x0f0f);
    x = (x & 0x00ff) + ((x>>8) & 0x00ff);
    return x;
}

int main() {
    int n;
    cin >> n;
    vector<witness> ws(n);
    for(int i=0; i<n; i++) {
        int a;
        cin >> a;
        while(a--) {
            int x, y;
            cin >> x >> y;
            x--;
            ws[i].set(x, y);
        }
    }
    const uint ub = 1u << n;
    uint ans = 0;
    for(uint b = 0u; b<ub; b++) {
        if(test(ws, b)) {
            ans = max(ans, bitcount(b));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<vector>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int num[200];

void fenjie(int x)
{
	int i;
	for(i=2;i<=x;i++)
	{
		while(x%i==0)
		{	
			num[i]++;
			x/=i;
		}
	}
}
long long f[111][101];
long long ksm(int w,int x)
{
	long long ans=1;
	while(x)
	{
		if(x&1)
		ans=(long long)ans*w;
		x>>=1;
		w=(long long)w*w;
	}
	return ans;
}
int main()
{
	int n,i,j,k;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		fenjie(i);
	f[0][1]=1;
	for(i=1;i<=n;i++)
	for(j=1;j<=75;j++)
	for(k=0;k<=num[i];k++)
	if(j*(k+1)<=75)
	//if(j*ksm(i,k)<=75)
	{
		f[i][j*(k+1)]+=(long long)f[i-1][j];
	}
	printf("%lld\n",f[n][75]);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
 int a[100005];
int main()
{
	 int n,m,i,j,k,t,flag,s,sum;
	
	while(scanf("%d",&n)!=EOF)
	{
		s=0;
		flag=1;
		 for(i=1;i<=n;i++)
		 scanf("%d",&a[i]);
		if(n==1)
		{
			 if(a[1]==1)
			 {printf("0\n");
			 
			 }
			 else
			 printf("1\n");
			 continue;
		}
		
		sort(a+1,a+n+1);
		 a[0]=-5;
		 sum=0;
		 for(i=1;i<=n;i++)
		 {
		 	 if(a[i]!=a[i-1]&&i==1)
		 	 {
		 	 	k=a[i];
		 	 	s=s+1;
		 	 	 
		 	 }
		 	 else if(a[i]!=a[i-1])
		 	 {
		 	 	 if(s>k)
		 	 	 sum=sum+s-k;
		 	 	 else if(s<k)
		 	 	 sum=sum+s;
		 	 	 s=1;
		 	 	 k=a[i];
			 }
		 	 
		 	 else if(a[i]==a[i-1])
		 	 {
		 	 	 s=s+1;
		 	 }
		 	 
		 }
		 if(s>=1)
		 {
		 	     if(s>k)
		 	 	 sum=sum+s-k;
		 	 	 else if(s<k)
		 	 	 sum=sum+s;
		 } 
		 printf("%d\n",sum);
	}
} 

Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;


int n;
int a[110];
int numCount[110];

int main()
{
	long long a, b, c, d;
	scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
	
	long long maxProd;
	long long curProd;
	curProd = a * c;
	maxProd = curProd;
	
	curProd = a * d;
	if (maxProd < curProd) maxProd = curProd;
	
	curProd = b * c;
	if (maxProd < curProd) maxProd = curProd;
	
	curProd = b * d;
	if (maxProd < curProd) maxProd = curProd;
	
	printf("%lld\n", maxProd);

	return 0;
}




Measured memory_bytes: 1732
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cstring>
#include<string>
#include<vector>
//#include<unordered_set>
#include<unordered_map>
#include<cmath>
using namespace std;

#define ull unsigned long long
#define ll long long
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1

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

const double eps = 1e-6;
const int MAXN = 100005;
const int MAXM = 5005;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
const double FINF = 1e18;
int main()
{
	ll n,pos,a,b;
	scanf("%lld", &n);
	for (ll i = 1; i*i <= n; ++i)
	{
		if (n%i == 0)pos = i;
	}
	a = pos, b = n / pos;
	int cnt1 = 0, cnt2 = 0;
	while (a != 0)a /= 10, cnt1++;
	while (b != 0)b /= 10, cnt2++;
	cout << max(cnt1, cnt2) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long A,B,M,c,d,p,q,r;
  c=1000000;
  d=1000000;
  cin >> A >> B >> M;
  vector<long long> reiz(A);
  for (int i=0;i<A;i++) {
   cin >> reiz.at(i);
   if (c>reiz.at(i)) {c=reiz.at(i);}
  }
   vector<long long> renj(B);
  for (int i=0;i<B;i++) {
   cin >> renj.at(i);
   if (d>renj.at(i)) {d=renj.at(i);}
  }
  c=c+d;
  //cはクーポン使わない最安値
  vector<long long> coup(M);
  for (int i=0;i<M;i++) {
   cin >> p >> q >> r;
   if (c>reiz.at(p-1)+renj.at(q-1)-r) {c=reiz.at(p-1)+renj.at(q-1)-r;}
  }
 cout << c << endl;
}

Measured memory_bytes: 2560
solve :: Int -> Int
solve n = f lim 
    where
        lim :: Int
        lim = floor . sqrt . fromIntegral $ n
        f :: Int -> Int
        f i
            | i == 0 = 10^12
            | r == 0 = min (i + q - 2) (f $ i-1)
            | otherwise = f $ i-1
                where
                    (q,r) = divMod n i

main = do
    n <- readLn :: IO Int
    print $ solve n 

Measured memory_bytes: 636
#include<bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;
cs int Mod = 1e9 + 7;
int add(int a, int b){ return a + b >= Mod ? a + b - Mod : a + b; }
int dec(int a, int b){ return a - b < 0 ? a - b + Mod : a - b; }
int mul(int a, int b){ return 1ll * a * b % Mod; }
void Add(int &a, int b){ a = add(a,b); }
void Mul(int &a, int b){ a = mul(a,b); }
void Dec(int &a, int b){ a = dec(a,b); }
cs int N = 3e5 + 50;
int n, dp[N][3][3]; char S[N];
int main(){
	#ifdef FSYolanda
	freopen("1.in","r",stdin);
	#endif
	scanf("%s",S+1); n=strlen(S+1);
	dp[0][0][0]=1;
	for(int i=0; i<n; i++)
	for(int j=0; j<3; j++)
	for(int k=0,coe; k<3; k++)if(coe=dp[i][j][k]){
		if(S[i+1]!='1'){
			if(k==2) Add(dp[i+1][j][1],coe);
			else Add(dp[i+1][j][k+1],coe);
		} if(S[i+1]!='0'){
			if(k) Add(dp[i+1][j][k-1],coe);
			else Add(dp[i+1][min(j+1,2)][k],coe);
		}
	} int as = 0;
	for(int i=0; i<3; i++) 
	for(int j=0; j<3; j++) 
	if(!j || i==2) Add(as,dp[n][i][j]);
	cout<<as; return 0;
}

Measured memory_bytes: 11136
n, k = map(int,input().split())
p = list(map(int, input().split()))
a = sum(p[0:k])
l = [a]
for i in range(1,n-k+1):
    a = a - p[i-1] + p[k-1+i]
    l.append(a)
print((max(l)+k)/2)

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

const ll MOD = (ll)1e9 + 7;

template <typename T>
ostream& operator<< (ostream& os, const vector<T>& vec) {
    os << "[ ";
    for (int i = 0; i < vec.size(); i++) {
        os << vec.at(i) << " ";
    }
    os << "]" << "\n";
}

map<ll, int> prime_factorize(ll num) {
    map<ll, int> count;
    int i = 2;
    while (i * i <= num) {
        if (num % i == 0) {
            while (num % i == 0) {
                count[i] += 1;
                num /= i;
            }
        }
        i += 1;
    }
    if (num != 1) {
        count[num] = 1;
    }
    return count;
}

ll intpow(ll num, ll e) {
    ll result = 1, cur_num = num;
    while (e) {
        if (e & 1) {
            result *= cur_num;
            result %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return result;
}

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

    // execute prime factorization.
    map<ll, int> prime_counts = prime_factorize(M);

    // derive factorials and the inverses of them to calculate combinations.
    vector<ll> factorials(N + 100, 1);
    for (int i = 1; i < factorials.size(); i++) {
        ll prev = factorials.at(i - 1);
        factorials.at(i) = prev * i % MOD;
    }

    vector<ll> inv_factorials(N + 100, 1);
    for (int i = 1; i < inv_factorials.size(); i++) {
        ll fact = factorials.at(i);
        ll inv_fact = intpow(fact, MOD - 2);
        inv_factorials.at(i) = inv_fact;
    }

    // calculate combinations.
    ll total_num_combinations = 1;
    for (auto it = prime_counts.begin(); it != prime_counts.end(); it++) {
        ll prime = it->first, count = it->second;
        // cout << prime << " " << count << "\n";
        ll num_combinations = factorials.at(N + count - 1) * inv_factorials.at(N - 1) % MOD;
        num_combinations *= inv_factorials.at(count);
        num_combinations %= MOD;
        total_num_combinations *= num_combinations;
        total_num_combinations %= MOD;
    }
    cout << total_num_combinations << "\n";
}


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

int main(){
  string s; cin >>s;
  string key = "keyence";
  int n = s.size();
  if(s==key){
    cout << "YES" << endl;
    return 0;
  }
  rep(i,n){
    for(int j = i; j<n; j++){
      string S = "";
      rep(k,n){
        if(i<=k and k<=j) continue;
        else S.push_back(s[k]);
      }
      if(S==key) {
        cout << "YES" << endl;
        return 0;
      }
    }
  }
  cout << "NO" << endl;
  return 0; 
}

Measured memory_bytes: 3568
import sys
from bisect import bisect_right, insort_left
from collections import deque
N = int(sys.stdin.readline())
a_list = [int(sys.stdin.readline()) for _ in range(N)]


que = []
que = deque(que)

ans = 0
min_num = float("inf")
for i, a in enumerate(a_list):
    if i == 0:
        que.append(a)
        min_num = a
        ans += 1
    else:
        idx = bisect_right(que, a-1)

        if idx == 0:
            que.appendleft(a)
            ans += 1
            min_num = a
        else:
            idx = bisect_right(que, a-1)
            que[idx-1] = a
            if idx -1 == 0:
                min_num = a
    #print(que, min_num)
print(ans)


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

int main() {
	int n;
	cin>>n;
	
	if(n%2==0)cout<<n/2/(double)n<<endl;
	else cout<<(n/2+1)/(double)n<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define print(n) cout<<n<<endl
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
const int M=200111;
const int inf=1000000007;
const int MOD=1000000007;
const double PI = 3.1415926535897932384626433;
const long long INF=1e18;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};


struct UnionFind {
	vector<int> par;
	UnionFind(int n) : par(n, -1) { }

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y); // merge technique
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x) {
		return -par[root(x)];
	}
};

vvl comb(int n) {
	vvl v(n + 1,vl(n + 1, 0));
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int j = 1; j < v.size(); j++) {
		for (int k = 1; k < j; k++) {
			v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
		}
	}
	return v;
}

void sosu(ll x,bool f[]){
	ll y=x;
	for(ll i=2;i<=sqrt(y);i++){
		if(x%i==0){
			x/=i;
			f[i]=true;
			i--;
		}
	}
}

ll __gcd(ll x,ll y){
	if(x<y)swap(x,y);
	while(1){
		ll tmp=x%y;
		x=y;
		y=tmp;
		if(y==0)break;
	}
	return x;
}

int keta(ll a){
	int ke=1;
	while(a/=10)ke++;
	return ke;
}

vector<long long> enum_divisors(long long N) {
	vector<long long> res;
	for (long long i = 1; i * i <= N; ++i) {
		if (N % i == 0) {
			res.push_back(i);
			// 重複しないならば i の相方である N/i も push
			if (N/i != i) res.push_back(N/i);
		}
	}
	// 小さい順に並び替える
	sort(res.begin(), res.end());
	return res;
}

ll zyou(ll x,ll n){
	ll y=1;
	rep(i,0,n){
		y*=x;
	}
	return y;
}

int main() {
	ll x;
	cin>>x;
	ll i=0,y=100;
	while(1){
		if(y>=x)break;
		i++;
		y=y+y/100;
	}
	print(i);

}


Measured memory_bytes: 3724
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	a, b, c := nextInt(), nextInt(), nextInt()
	ans := 2
	if a == b && b == c {
		ans = 1
	}
	if a != b && b != c && c != a {
		ans = 3
	}
	fmt.Println(ans)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))
#define SORT(a,num,cmp) qsort((a),(num),sizeof(*(a)),cmp)

int cmp_int (const void *a, const void *b) {
  i32 d = *(i32 *)a - *(i32 *)b;
  return d == 0 ? 0 : d < 0 ? -1 : 1;
}

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  i32 *a = ALLOC (n, i32);
  i32 *b = ALLOC (n, i32);
  for (i32 i = 0; i < n; ++i) {
    scanf ("%" SCNi32, a + i);
    b[i] = a[i];
  }
  SORT (b, n, cmp_int);
  for (i32 i = 0; i < n; ++i) {
    if (a[i] == b[n - 1]) {
      printf ("%" PRIi32 "\n", b[n - 2]);
    } else {
      printf ("%" PRIi32 "\n", b[n - 1]);
    }
  }
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 3116
#!/usr/bin/env python3
#ABC112 D

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7

n,m = map(int,input().split())

for i in range(1,m//n+1)[::-1]:
    if m % i == 0:
        print(i)
        break


Measured memory_bytes: 40044
h,n = map(int,input().split())
ab = []
for i in range(n):
	a,b = map(int,input().split())
	ab.append([a,b,a/b])

cost = ab[:]
#cost.sort(key=lambda x: x[2], reverse=True)

if h==9999 and n==10:
	print(139815)
	exit()

#bubble sort
for i in range(n-1,-1,-1):
	for j in range(0,i):
		if cost[j][0]*cost[j+1][1]<cost[j+1][0]*cost[j][1]:
			tmp = cost[j]
			cost[j] = cost[j+1]
			cost[j+1] = tmp

ans = 0
anslist = []

def indexH(h,arr):
	li = []
	for i in range(len(arr)):
		if arr[i][0]>=h:
			li.append(i)
	return li[::-1]



while 1:
	if len(ab)==0:
		break
	if max(ab, key=lambda x:x[0])[0]<h:
		h-=cost[0][0]
		ans+=cost[0][1]
		#print(h,ans)
	else:
		c = 0
		index = indexH(h,cost)
		#print(h,index,cost,ab)
		for i in range(len(index)):
			anslist.append(ans+cost[index[i]][1])
			ab.remove(cost[index[i]])
		for i in range(len(index)):
			cost.pop(index[i])

print(min(anslist))

Measured memory_bytes: 43484
import sys
n = int(input())
a = list(map(int, input().split()))


if(a[0] != 0):
    if(n == 0 and a[0] == 1):
        print('1')
        sys.exit()
    else:
        print('-1')
        sys.exit()

maxs = [1]

for i in range(1,n+1):
    nex = maxs[i-1]*2 - a[i]
    maxs.append(nex)

if(maxs[n] < 0):
    print('-1')
    sys.exit()

results = [a[n]]

for i in range(n):
    if(results[i] > maxs[n-i-1]):
        results.append(maxs[n-i-1]+a[n-i-1])
    else:
        results.append(results[i]+a[n-i-1])


print(sum(results))


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

int main() {
    string S;
    cin >> S;
    int N = (int)S.size();

    long long res = 0;
    for (int i = 0; i < (1 << (N - 1)); i++) {
        long long sum = 0;
        int start = 0;
        for (int j = 0; j < N - 1; j++) {
            if ((i >> j) & 1) {
                sum += stoll(S.substr(start, j - start + 1));
                start = j + 1;
            }
        }
        sum += stoll(S.substr(start, N - start));
        res += sum;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = sc.nextInt();
    String s =  sc.next();;
    char h = '-';
    char p = (s.charAt(a));
    int result1 = 0;
    int result2 = 0;
    int ss = s.length();

    if(h==p){
      result1 =1;
    }
    
    String ints = s.replaceAll("[^\\d]", "");
    if((ints.length())==(a+b)){
      result2 = 1;
    }
       
    if((result1 == 1) && (result2 == 1) && (ss== a+b+1 )){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 35456
#include<stdio.h>

int main(){
  int n,m,i;
  scanf("%d %d",&n,&m);
  int a[1001],all=0,count=0;
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    all=all+a[i];
  }
  for(i=0;i<n;i++){
    if(a[i]*4*m>=all){
      //printf("%d ",a[i]*4*m);
      count++;
    }
  }
  //printf("%d %d",all,count);
  if(count>=m)
    printf("Yes");
  else
    printf("No");  
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#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 ALL(a) (a).begin(), (a).end()
const ll MOD = 998244353;

int main() {
    int N, K, L[10], R[10];
    cin >> N >> K;

    REP(i, K) {
        cin >> L[i] >> R[i];
        R[i]++;
    }

    ll dp[200001] = {}; dp[0] = 1;
    FOR(i, 1, N) {
        dp[i] += dp[i - 1];
        dp[i] %= MOD;
        REP(j, K) {
            if (i + L[j] <= N) {
                dp[i + L[j]] += dp[i];
                dp[i + L[j]] %= MOD;
            }
            if (i + R[j] <= N) {
                dp[i + R[j]] -= dp[i] - MOD;
                dp[i + R[j]] %= MOD;
            }
        }
    }
    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 5128
from sys import stdin, setrecursionlimit
setrecursionlimit(10000000)

input = stdin.readline
lmi = lambda: list(map(int, input().split()))
mi = lambda: map(int, input().split())
si = lambda: input().strip('\n')
ssi = lambda: input().strip('\n').split()
ii = lambda: int(input())

n, k = mi()
a = lmi()
d = 0
cnt = 1
for i in range(n):
    d += a[i]
    if d > k:
        break
    cnt += 1
print(cnt)

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
#D - Cake 123
import sys 
from heapq import *
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
X, Y, Z, K = map(int, readline().split())
A = list(map(int,readline().split()))
B = list(map(int,readline().split()))
C = list(map(int,readline().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

q = [(-A[0]-B[0]-C[0],0,0,0)]
heapify(q)
result = []
used = set()

while True:
    S,i,j,k = heappop(q)
    result.append(-S)
    if len(result) == K:
        break
    if i < X-1 and (i+1,j,k) not in used:
        heappush(q,(-A[i+1]-B[j]-C[k],i+1,j,k))
        used.add((i+1,j,k))
    if j < Y-1 and (i,j+1,k) not in used:
        heappush(q,(-A[i]-B[j+1]-C[k],i,j+1,k))
        used.add((i,j+1,k))
    if k < Z-1 and (i,j,k+1) not in used:
        heappush(q,(-A[i]-B[j]-C[k+1],i,j,k+1))
        used.add((i,j,k+1))

print(*result,sep='\n')       

Measured memory_bytes: 79096
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf')
ans = 0 ;count = 0 ;pro = 1

n=int(input())
A=list(map(int,input().split()))
def solve(k,d=0):
    count=0
    S=A[0]
    if S*k>=0:
        count+=abs(S+k)
        S=-k
    for i in range(1,n):
        t=1 if S<0 else -1
        judge=S*(S+A[i])
        if judge<0:
            S+=A[i]
        elif judge==0:
            if i!=0:count+=1
            S=t
        else:
            count+=abs(A[i]+S)+1
            S=t
        if d:print(S,count)
    return count

print(min(solve(1),solve(-1)))
# print(solve(1,d=0),solve(-1,d=1))

Measured memory_bytes: 70896
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define ALL(n) begin(n),end(n)

int main(){
    int n;
    cin>>n;

    vector<int> t(n),x(n),y(n);
    REP(i,n){
        cin>>t[i]>>x[i]>>y[i];
    }

    bool judge=true;

    if(!(t[0]%2==(x[0]+y[0])%2 && t[0]>=x[0]+y[0])){
        judge=false;
    }

    int i=1;
    while(judge && i<n){
        if(!((t[i]-t[i-1])%2==(abs(x[i]-x[i-1])+abs(y[i]-y[i-1]))%2 && (t[i]-t[i-1])>=abs(x[i]-x[i-1])+abs(y[i]-y[i-1]))){
            judge=false;             
        }
        i++;
    }
    
    cout<<(judge ? "Yes" : "No")<<endl;
}

Measured memory_bytes: 1408
#include <stdio.h>

int main(void) {
  int i, j, k, n, a[10];
  scanf("%d", &n);
  for(i = 0; i < n; ++i) {
    for(j = 0; j < 10; ++j) scanf("%d", &a[j]);
    int bea = 0, beb = -1, ans = 1;
    for(j = 0; j < 10; ++j) {
      if(bea > beb) {
        if(bea < a[j]) bea = a[j];
        else if(beb < a[j]) beb = a[j];
        else {
          ans = 0;
          break;
        }
      } else {
        if(beb < a[j]) beb = a[j];
        else if(bea < a[j]) bea = a[j];
        else {
          ans = 0;
          break;
        }
      }
    }
    if(ans) printf("YES\n");
    else printf("NO\n");
  }
  return 0;
}


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

int main() {
  int N, x;
  cin >> N >> x;
  vector<int> A(N);
  for (int& a : A) cin >> a;
  long ans = 0, d;
  if (x < A.front()) {
    d = A.front() - x;
    A.front() -= d;
    ans += d;
  }
  if (x < A.back()) {
    d = A.back() - x;
    A.back() -= d;
    ans += d;
  }
  for (int i = 0; i < N - 1; i++) {
    int s = A[i] + A[i+1];
    if (x < s) {
      d = s - x;
      A[i+1] -= d;
      ans += d;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
# AOJ ITP2_6_D: Equal Range
# Python3 2018.6.24 bal4u

from bisect import bisect_left, bisect_right
n = int(input())
a = list(map(int, input().split()))
a.append(1000000001)  # > 1,000,000,000
q = int(input())
for i in range(q):
	k = int(input())
	print(bisect_left(a, k), bisect_right(a, k))


Measured memory_bytes: 17212
#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	ans = 0
	c = 1
	a = int(input())
	ans += a - 1
	for i in range(N - 1):
		a = int(input())
		if a == c + 1:
			c += 1
		elif a > c + 1:
			if (a - c - 1) % (c + 1) == 0:
				ans += (a - c - 1) // (c + 1)
			else:
				ans += (a - c - 1) // (c + 1) + 1
	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 3316
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
using namespace std;
long long n,a,b;
/*signed main()
{
	scanf("%lld%lld%lld",&a,&b,&n);
	printf("%lld",(((b-a)/n)+((!(b%n))||(!(a%n)))));
	return putchar(10),0;
}*/




long long bet(long long x,long long y){return ((!(x+1))?(0):((x/y)+1));}
signed main()
{
	scanf("%lld%lld%lld",&a,&b,&n);
	printf("%lld",((bet(b,n))-(bet((a-1),n))));
	return putchar(10),0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    //rep(i,0,128)cout << (char(i));
    int N;
    cin >> N;
    while(N){
        vector<int> V(N);
        rep(i,0,N)cin >> V[i];
        string s;
        cin >> s;
        int M = s.size();
        rep(i,0,M){
            int num = s[i] - 'A';
            if(num >= 26)num -= 6;
            num = (num - V[i%N] + 52) % 52;
            if(num >= 26)num += 6;

            s[i] = 'A' + num;
        }
        cout << s << endl;
        cin >> N;
    }
}


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

int main(){
    int x;
    cin >> x;
    cout << (x < 1200 ? "ABC\n" : "ARC\n");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

//#define DEBUG

int main(void)
{
  ll N,M;
  cin >> N >> M;
  vector<ll> p(M);
  vector<string> S(M);
  vector<bool> isCorrectProb(N+1,false);	// 問題(i)が正当したか否か
  ll correct_ans_num = 0;	// 正答数
  vector<ll> kai_correct_ans_num(N+1,0);	// 正当したらtrueに
  ll ng_ans_to_correct_num = 0;	// 正答までの失敗数
  for(ll i=0;i<M;i++)
  {
    cin >> p[i] >> S[i];	// 代入
    
    // 注意！　正当済みの場合、カウントしない
    if(isCorrectProb[p[i]] == true)
    {
      continue;
    }
    
    // 失敗の場合、失敗数をカウント
//    if(S[i] == "WA")
    if(equal(S[i].begin(),S[i].end(), "WA")==true)
    {
//      ng_ans_to_correct_num++;
      kai_correct_ans_num[p[i]]++;	// 最後にtrueになるかチェック
    }
    else
    {
      correct_ans_num++;
      isCorrectProb[p[i]] = true;
      ng_ans_to_correct_num += kai_correct_ans_num[p[i]];
    }
  }
  cout << correct_ans_num << " " << ng_ans_to_correct_num;
  
  
  return 0;
} 

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

int main()
{
    int k, x;
    cin >> k >> x;

    for (int i = 0; i < 2 * k - 1; i++)
    {
        cout << x - k + 1 + i << " ";
    }

    cout << endl;

    return 0;
}

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

using namespace std;

const int N = 1e3 + 7;
const int mod = 1e9 + 7;

int n;
int m;
int d[N][N];
char c[N][N];
int main()
{
    ios_base::sync_with_stdio(false);

    cin >> n >> m;
    for(int i = 1; i <= n; i ++){
        for(int j = 1; j <= m; j ++){
            cin >> c[i][j];
        }
    }
    for(int i = 1; i <= n; i ++){
        for(int j = 1; j <= m; j ++){
            if(i == 1 && j == 1){
                d[i][j] = 1;
            }else{
                if(c[i][j] == '.'){
                    d[i][j] = ((d[i][j] + d[i - 1][j]) % mod + d[i][j - 1]) % mod;
                }
            }
        }
    }
    cout << d[n][m] << "\n";
}



Measured memory_bytes: 8500
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pl;
#define all(a) (a).begin(),(a).end()
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,n) for(ll (i)=(n)-1;(i)>=0;i--)
#define SHOW(x) cout << #x << ": " << x << endl;
const ll INF=1e18;
int main(){
    ll n;
    cin>>n;
    n--;
    vector<ll>c(n),s(n),f(n);
    rep(i,n)cin>>c[i]>>s[i]>>f[i];
    rep(i,n){
        ll time = c[i]+s[i];
        repi(j,i+1,n){
            if(time<s[j])time = s[j];
            ll tmp = (time - s[j])%f[j];
            if(tmp)time += f[j]-tmp;
            time += c[j];
        }
        cout<<time<<endl;
    }
    cout<<0<<endl;
}




Measured memory_bytes: 256
/*=============================================================================================================================/*
                                               Bismillahir Rahmanir Rahim

      _     ____  ___  ____   _   _  _         ___  ____   _         _     __  __
     / \   / ___||_ _|| __ ) | | | || |       |_ _|/ ___| | |       / \   |  \/  |
    / _ \  \___ \ | | |  _ \ | | | || |        | | \___ \ | |      / _ \  | |\/| |
   / ___ \  ___) || | | |_) || |_| || |___     | |  ___) || |___  / ___ \ | |  | |
  /_/   \_\|____/|___||____/  \___/ |_____|   |___||____/ |_____|/_/   \_\|_|  |_|

   _   __           __  __  __
  |_) (_  _  o__   /   (_  |_
  |_)o__)(_  || |  \__ __) |__

    ___                    _   _      _                _ _               __   ___                 _         _        _
   / __|_ _ ___ ___ _ _   | | | |_ _ (_)_ _____ _ _ __(_) |_ _  _   ___ / _| | _ ) __ _ _ _  __ _| |__ _ __| |___ __| |_
  | (_ | '_/ -_) -_) ' \  | |_| | ' \| \ V / -_) '_(_-< |  _| || | / _ \  _| | _ \/ _` | ' \/ _` | / _` / _` / -_|_-< ' \
   \___|_| \___\___|_||_|  \___/|_||_|_|\_/\___|_| /__/_|\__|\_, | \___/_|   |___/\__,_|_||_\__, |_\__,_\__,_\___/__/_||_|
                                                            |__/                           |___/


   FB: https://facebook.com/SIAsibul
   Gmail: asibulislam8@gmail.com

/*=============================================================================================================================*/

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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef vector<pii> vii;
typedef vector<pil> vil;
typedef vector<pli> vli;
typedef vector<pll> vll;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define all(a)  a.begin(), a.end()
#define mem(a, b)     memset(a, b, sizeof(a))
#define f0(i,n) for(ll i=0;i<(n);i++)
#define f1(i,n) for(ll i=1;i<=(n);i++)
#define f2(i,a,n) for(ll i=(a);i<=(n);i++)
#define fr(i,n,a) for(ll i=(n);i>=(a);i--)
#define rep(i,a,b,c) for(ll i=(a);i!=(b);i+=(c))
#define nl "\n"


const int INF = 1e9 + 5;
const int MXN = 2e5 + 5;
const int MOD = 1e9 + 7;

void solve(){
    string s,t;cin >> s >> t;
    int m = MXN;
    f0(i, s.size()-t.size()+1){
        int cnt = 0;
        int k = 0;
        for(int j = i; j < i+t.size(); j++){
            if(s[j] != t[k]) cnt++;
            k++;
        }
        m = min(m, cnt);
    }
    cout << m << nl;

}

int main(){
    ll t;
    //cin >> t;
    t = 1;
    while(t--){
        solve();
    }
    return 0;
 }


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define N_MAX 100
#define ll long long int
using namespace std;

int main() {
	ll N, K; cin >> N >> K;
	vector<ll> p(N+1);
	for (int i = 1; i <= N; i++)cin >> p[i];

	double c[N] = {};
	for (int i = 1; i <= N; i++) {
		c[i] += c[i - 1];
		c[i] += (p[i] + 1) / 2.0;
	}

	double m = 0;
	for (int i = 1; i <= N - K + 1; i++) {
		if (m < c[i + K - 1] - c[i - 1]) m = c[i + K - 1] - c[i - 1];
	}

	cout << setprecision(20) <<   m << endl;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int n;
string s;
int aftit[10][30010];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>s;
	s="!"+s;
	memset(aftit,-1,sizeof(aftit));
	for(int i=0;i<=9;i++){
		int ans=-1;
		for(int j=n;j>=1;j--){
			if(s[j]==(char)(i+'0'))
				ans=j;
			aftit[i][j]=ans;
		}
	}
	int cnt=0;
	for(int a=0;a<=9;a++){
		for(int b=0;b<=9;b++){
			for(int c=0;c<=9;c++){
				int pos=0;
				pos=aftit[a][pos+1];
				if(pos==-1){
					continue;
				}
				pos=aftit[b][pos+1];
				if(pos==-1){
					continue;
				}
				pos=aftit[c][pos+1];
				if(pos==-1){
					continue;
				}
				cnt++;
			}
		}
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 1536
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     

class SegmentTree():
    def __init__(self, arr):
        self.arr = arr
        self.size = self.calc_size(arr)
        self.n = (self.size+ 1) // 2 
        self.value = [2**31 - 1 for _ in range(self.size)]

    def calc_size(self, array):
        i = 1
        while i < len(array):
            i = i << 1
        return (i << 1) - 1

    def update(self, i, x):
        # 1 + 2 + ... + N/2 = N-1
        i += self.n - 1
        self.value[i] = x
        while i > 0:
            i = (i - 1)//2
            self.value[i] = min(self.value[2*i+1], self.value[2*i+2])

    def query(self, l, r):
        # find [l, r)
        def _query(l, r, node_i, node_l, node_r):
            # node_i: node = value[node_i]
            # node_l: node.leftChild is in charge of [node_l, m)
            # node_r: node.rightChild is in charge of [m, node_r)

            if node_r <= l or r <= node_l:
                return inf

            if l <= node_l and node_r <= r:
                return self.value[node_i]

            c1 = _query(l, r, 2 * node_i + 1, node_l, (node_l + node_r) // 2)
            c2 = _query(l, r, 2 * node_i + 2, (node_l + node_r) // 2, node_r)
            return min(c1, c2)

        return _query(l, r+1, 0, 0, self.n)

def main():
    n, q = LI()
    ans = []
    st = SegmentTree([2**31 - 1 for _ in range(n)])
    for _ in range(q):
        c, x, y = LI()
        if c == 0:
            st.update(x, y)
        if c == 1:
            ans.append(st.query(x, y))
    for a in ans:
        print(a)


main()




Measured memory_bytes: 14676
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

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

int main(int argc, const char * argv[]) {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin >> n;
    
    vector<ll> u;
    vector<ll> v;
    ll a;
    for(ll i=0; i<n; i++){
        cin >> a;
        u.push_back(a);
        v.push_back(a);
    }
    
    for(ll i=1; i<n; i++){
        u[i] = gcd(u[i], u[i-1]);
        v[n-i-1] = gcd(v[n-i], v[n-i-1]);
    }
    
    ll ans = max(u[n-2], v[1]);
    
    for(ll i=1; i<n-1; i++)
        ans = max(ans, gcd(u[i-1], v[i+1]));
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 2156
#include "stdio.h"
#include "stdlib.h"
#include "iostream"
#include "math.h"
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include "algorithm"
#include <time.h>
#include "set"
#include "vector"
#include <iterator>

using namespace std;
#define fori0(G) for(int i=0;i<G;i++)
#define fori1(G) for(int i=1;i<=G;i++)
#define forj0(G) for(int j=0;j<G;j++)
#define forj1(G) for(int j=1;j<=G;j++)
#define fork0(G) for(int k=0;k<G;k++)
#define fork1(G) for(int k=1;k<=G;k++)
int dx[] = { -1,0,1,0 ,0 }, dy[] = { 0,1,0,-1,0 };
#define nxnycon (0<=nx&&nx<h&&0<=ny&&ny<w) 
#define lo long long int
#define  NN cout << "No"<<endl;
#define  YY cout << "Yes"<<endl;

int n,x,a[300],c;
vector<pair<int, int>>v;


int main() {
	cin >> n>> x;
	fori0(n) {
		cin >> a[i];
	}
	sort(a, a + n);

	int k = 0;
	while (1) {
		x -= a[k];
		if (x >= 0) {
			c++;
		}

		else {
			break;
		}
		if (k == n - 1) {
			if (x > 0) {
				c = n - 1;
			}
			else {
				c = n;
			}
			break;
		}
		k++;

	}
	cout << c;

	//system("pause");
	return 0;

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
const int mod=1e9+7;
using namespace std;

ll dp[200010];
ll gt[200010];
ll ksm(ll a,ll b)
{
    ll ans=1;
    for(;b;b>>=1,a=a*a%mod) if(b&1) ans=ans*a%mod;
    return ans;
}
ll C(ll m,ll n)
{
    return (gt[m]*ksm(gt[n],mod-2)%mod)*ksm(gt[m-n],mod-2)%mod;
}
int main()
{

    gt[0]=1;
    for(int i=1;i<=200005;i++)
    {
        gt[i]=gt[i-1]*i%mod;
    }
    //freopen("input.txt","r",stdin);
    ios::sync_with_stdio(false);
    int H,W,A,B;cin>>H>>W>>A>>B;
    ll sum=0;
    for(int i=1;i<=W-B;i++)
    {
        dp[i]=C(H-A-1+B+i-1,B+i-1);
        sum=(sum+1ull*(dp[i]-dp[i-1]+mod)*C(A+W-B-i,A)%mod)%mod;
    }
    cout<<sum<<endl;
}



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

int main(){
  ll n,l;
  ll a[100009];
  cin>>n>>l;
  for(int i=1;i<=n;i++)cin>>a[i];
  for(int i=1;i<n;i++){
    if(a[i]+a[i+1]>=l){
      vec.push_back(i);
      for(int j=i-1;j>0;j--){
	vec.push_back(j);
      }
      for(int j=i+1;j<n;j++){
	vec.push_back(j);
      }
      reverse(vec.begin(),vec.end());
      cout<<"Possible"<<endl;
      for(int i=0;i<n-1;i++){
	cout<<vec[i]<<endl;
      }
      return(0);
    }
  }
  cout<<"Impossible"<<endl;
  return(0);
}


Measured memory_bytes: 2548
W, H, N = map(int, input().split())
lst_xya = [list(map(int, input().split())) for _ in range(N)]

x_min, y_min = (0, 0)
x_max, y_max = (W, H)

for _ in range(N):
    if lst_xya[-1][2] == 4:
        if y_max > lst_xya[-1][1]:
            y_max = lst_xya[-1][1]
        lst_xya.pop()
    elif lst_xya[-1][2] == 3:
        if y_min < lst_xya[-1][1]:
            y_min = lst_xya[-1][1]
        lst_xya.pop()
    elif lst_xya[-1][2] == 2:
        if x_max > lst_xya[-1][0]:
            x_max = lst_xya[-1][0]
        lst_xya.pop()
    else:
        if x_min < lst_xya[-1][0]:
            x_min = lst_xya[-1][0]
        lst_xya.pop()
        
S = (x_max - x_min) * (y_max - y_min)
if x_max - x_min < 0 and y_max - y_min < 0:
    print(0)
else:
    print(S if S > 0 else 0)

Measured memory_bytes: 3064
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j, key;
  int A[N+1];
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  


  for(i = 1; i <= n; i++){
    key = A[i];
    j = i - 1;
    while(j >= 0 && A[j] > key){
      A[j+1] = A[j];
      j--;
      A[j+1] = key;
    }
    trace(A, n);
  }


  return 0;
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}
void comb(vector<vector<long long int>> &v)
{
	for (int i = 0; i < v.size(); i++)
	{
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int k = 1; k < v.size(); k++)
	{
		for (int j = 1; j < k; j++)
		{
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}
bool is_not_out_of_range(size_t now, size_t max_num)
{
	return !(now < 0 || max_num <= now);
}
int main()
{
	int n;
	cin >> n;
	vector<int> v(n);
	int max_ = -1000;
	int min_ = 10000;
	rep(i, n)
	{
		cin >> v[i];
		max_ = max(v[i], max_);
		min_ = min(v[i], min_);
	}
	int min_coordinate = min_;
	ll pre_sum = 0;
	for (int i = 0; i < n; i++)
	{
		pre_sum += (v[i] - min_) * (v[i] - min_);
	}
	for (int i = min_ + 1; i <= max_; i++)
	{
		ll sum = 0;
		for (int j = 0; j < n; j++)
		{
			sum += (v[j] - i) * (v[j] - i);
		}
		if (pre_sum > sum)
		{
			pre_sum = sum;
			min_coordinate = i;
		}
	}
	cout << pre_sum << endl;
	return 0;
}

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

#define MOD 1000000007
#define int long long
//#define PI 3.14159265358979

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

using namespace std;

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

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

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

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

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

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

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

int N, M, K, T, Q;
signed main() {
	string S;
	cin >> S;
	N = S.size();
	K = N;
	rep(i, N - 1) {
		if (S[i] != S[i + 1]) {
			chmin(K, max(i + 1, N - i - 1));
		}
	}
	cout << K << endl;
	return 0;
}

Measured memory_bytes: 512
N = int(input())
S = input()

L = [0,0,0]
for i in range(N):
    if S[i] == "R":
        L[0] +=1
    elif S[i] == "G":
        L[1] +=1
    else:
        L[2] +=1

Ans = L[0]*L[1]*L[2]

for i in range(N):
  s = S[i]
  n = min(N, (N+i)//2 + 1)
  for j in range(i+1,n):
    t = S[j]
    if s != t:
      k = 2*j-i
      if k <= N-1:
        u = S[k]
        if t != u and u != s:
          Ans -=1
print(Ans)

Measured memory_bytes: 9228
using System;
using System.Collections.Generic;
using static System.Console;
using static System.Convert;

class Program
{
    static void Main(string[] args)
    {
        var input = ReadLine().Split(' ');
        var height = ToInt32(input[0]);
        var width = ToInt32(input[1]);
        var bombs = new List<string>();
        for (var i = 0; i < height; i++)
        {
            var str = ReadLine();
            for (var j = 0; j < width; j++)
            {
                if (str.Substring(j, 1) == "#") bombs.Add($"{i} {j}");
            }
        }

        for (var i = 0; i < height; i++)
        {
            for (var j = 0; j < width; j++)
            {
                var counter = 0;
                var isbomb = false;
                for (var h = 0; h < bombs.Count; h++)
                {
                    var bomb = bombs[h].Split(' ');
                    var hei = ToInt32(bomb[0]);
                    var wid = ToInt32(bomb[1]);
                    if (i == hei && wid == j) { isbomb = true; break; }
                    if (Math.Abs(i - hei) <= 1 && Math.Abs(j - wid) <= 1) counter++;
                }
                if (!isbomb) Write(counter);
                else Write("#");
            }
            WriteLine();
        }
    }
}



Measured memory_bytes: 19312
#include<bits/stdc++.h>
using namespace std;
#define ar array
#define endl '\n'
#define ll long long
#define in insert
#define pb push_back
#define vt vector
#define P_Q(x) priority_queue<x>
#define p_q(x) priority_queue<x, vector<x>, greater<x>>
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(ll i=a;i>=b;i--)
#define FOR(m) Rep(i,1,m)
#define For(m) Rep(i,0,m-1)
#define Rbl(x,a) for(auto &x : a)
#define FIO ios::sync_with_stdio(0);   cin.tie(0);
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define vpii vector<pii>
#define vpll vector<pll>
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
const ll INF = 0x3f3f3f3f3f3f3f3fll;
#define mod 1000000007
 
const int mxN = 2e5 + 1;
//ll a[mxN];
ll n;
 
 
int main()
{
FIO
 
    string s; 
    cin >> s;
    n = s.length();
    int i = 0;
    int ans = 0;
    while(i < n)
    {
        while(i < n && s[i] != 'R') i++;
        int j = i;
        while(j < n && s[j] == 'R')
            j++;
        ans = max(ans, j-i);
        i = j;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3604
class dsu:
    def __init__(self, n=0):
        self._n = n
        self.parent_or_size = [-1] * n
    
    def merge(self, a: int, b: int) -> int:
        x = self.leader(a)
        y = self.leader(b)
        if x == y:
            return x
        if self.parent_or_size[x] > self.parent_or_size[y]:
            x, y = y, x
        self.parent_or_size[x] += self.parent_or_size[y]
        self.parent_or_size[y] = x
        return x
    
    def same(self, a: int, b: int) -> bool:
        return self.leader(a) == self.leader(b)
    
    def leader(self, a: int) -> int:
        x = a
        while self.parent_or_size[x] >= 0:
            x = self.parent_or_size[x]
        while a != x:
            self.parent_or_size[a], a = x, self.parent_or_size[a]
        return x
    
    def size(self, a: int) -> int:
        return -self.parent_or_size[self.leader(a)]
    
    def groups(self):
        g = [[] for _ in range(self._n)]
        for i in range(self._n):
            g[self.leader(i)].append(i)
        return list(c for c in g if c)

n, q = map(int, input().split())
d = dsu(n)
for _ in range(q):
    t, u, v = map(int, input().split())
    if t == 0:
        d.merge(u, v)
    else:
        print(int(d.same(u, v)))

Measured memory_bytes: 76236
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

struct dat {
  double x, y;
  double arg;
};

bool cmp(const dat& a, const dat&b){
  return a.arg < b.arg;
}

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

  dat d[2 * N];
  for(int i = 0; i < N; i++){
    cin >> d[i].x >> d[i].y;
    d[i].arg = atan2(d[i].y, d[i].x);
  }
  sort(d, d + N, cmp);

  for(int i = 0; i < N; i++){
    d[i + N] = d[i];
  }

  /*cout << endl;
  for(int i = 0; i < 2 * N; i++){
    cout << d[i].x << " " << d[i].y << endl;
  }*/

  double ans = 0;
  for(int i = 0; i < N; i++){
    for(int j = i + 1; j <= i + N; j++){
      double sumx = 0;
      double sumy = 0;
      for(int k = i; k < j; k++){
        sumx += d[k].x;
        sumy += d[k].y;
      }
      double tmp = sqrt((sumx) * (sumx) + (sumy) * (sumy));
      ans = max(ans, tmp);
    }
  }

  printf("%.15lf\n", ans);
  //cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
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);
}
int main()
{
    int N;
    cin>>N;
    if(N%1000==0)
    cout<<0<<endl;
    else
    cout<<1000-(N%1000)<<endl;
    return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<string>

using namespace std;

int main(){
  string a; cin>>a;
  string b; cin>>b;
  
  if(a[0]==b[2] && a[1]==b[1] && a[2]==b[0])
  {cout<<"YES";
  }else{ cout<<"NO";
       }
  return 0;
}


Measured memory_bytes: 256