akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main() {
    char s[4];
    
    scanf("%s", s);
    int a = 0;
    for (int i = 0; i < 3; ++i){
        if (s[i] == '7')
            a = 1;
    }
    if (a == 0)
        printf("No\n");
    else
        printf("Yes\n");
    return 0;
}


Measured memory_bytes: 1644
#include <cstdio>
#include <queue>
#include <cmath>
using namespace std;
typedef long long ll;
const int N=200010;
const double DINF=1e40;
const double EPS=1e-6;
int n;
int pre[N];
int col[N];
int bel[N];
int c[N][2];
struct Data{
	int u;
	double x;
	Data(){}
	Data(int _u,double _x):u(_u),x(_x){}
	friend bool operator < (const Data &a,const Data &b){
		return a.x<b.x;
	}
};
priority_queue<Data> q;
void readData(){
	scanf("%d",&n);
	for(int v=2;v<=n;v++)
		scanf("%d",&pre[v]);
	for(int i=1;i<=n;i++) 
		scanf("%d",&col[i]);
}
int findBel(int u){
	return bel[u]==u?u:(bel[u]=findBel(bel[u]));
}
double getVal(int u){
	return c[u][1]?(1.0*c[u][0]/c[u][1]):DINF;
}
void init(){
	for(int i=1;i<=n;i++){
		bel[i]=i;
		c[i][0]=(col[i]==0);
		c[i][1]=(col[i]==1);
		if(i>1)
			q.push(Data(i,getVal(i)));
	}
}
bool legal(int u,double now){
	return fabs(now-getVal(u))<=EPS;
}
void solve(){
	ll ans=0;
	Data cur;
	int u,fp;
	while(!q.empty()){
		cur=q.top();
		q.pop();
		u=cur.u;
		if(findBel(u)!=u||!legal(u,cur.x))
			continue;
		fp=findBel(pre[u]);
		ans+=1ll*c[fp][1]*c[u][0];
		c[fp][0]+=c[u][0];
		c[fp][1]+=c[u][1];
		if(fp!=1)
			q.push(Data(fp,getVal(fp)));
		bel[u]=fp;
	}
	printf("%lld\n",ans);
}
int main(){
	readData();
	init();
	solve();
	return 0;
}

Measured memory_bytes: 9584
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    long a[n+1],cnt=0;
    long b[n];
    for(int i=0;i<n+1;i++)
        scanf("%li",&a[i]);
    for(int i=0;i<n;i++)
        scanf("%li",&b[i]);
    for(int i=0;i<n;i++)
    {
        if(b[i]>=a[i])
        {
            cnt+=a[i];
            b[i]-=a[i];
            if(a[i+1]>b[i])
            {
                cnt+=b[i];
                a[i+1]-=b[i];
            }
            else
            {
                cnt+=a[i+1];
                a[i+1]=0;
            }
        }
        else if(b[i]<a[i])
        {
            cnt+=b[i];
        }
    }
    printf("%li",cnt);
    return 0;

}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pb push_back
#define mp make_pair
#define mo 1000000007
#define MAX_N 500004
#define MAX 100005
#define INF 2000000000
#define MAXLOG 20

#define fast_io ios::sync_with_stdio(false)

int main()
{
	fast_io;
	cin.tie(0);
	int x, n;
	cin >> n;
	unordered_map<int, int> m1, m2;
	for(int i = 1; i <= n; ++i)
	{
		cin >> x;
		m1[x + i]++;
		if(i > x)
			m2[i - x]++;
	}
	ll ans = 0;
	for(auto x: m1)
		ans += 1ll * m1[x.first] * m2[x.first];
	cout << ans;


}

Measured memory_bytes: 19784
s = str(input())
q = int(input())
quer = [input().split() for i in range(q)]

k = 0
fo = ''
re = ''
for i in range(q):
    if quer[i][0] == '1':
        k += 1
    else:
        if quer[i][1] == '1':
            if k % 2 == 0:
                re = re + quer[i][2]
            else:
                fo = fo + quer[i][2]
        else:
            if k % 2 == 0:
                fo = fo + quer[i][2]
            else:
                re = re + quer[i][2]

if k % 2 ==0:
    print( ''.join(list(reversed(re))) + s + fo)
else:
    print(''.join(list(reversed(fo))) + ''.join(list(reversed(s))) + re)

Measured memory_bytes: 41076
def main():
    x, y = [int(ele) for ele in input().split()]
    a = [1, 3, 5, 7, 8, 10, 12]
    b = [4, 6, 9, 11]
    c = [2]
    ans = "No"
    if x in a and y in a:
        ans = "Yes"
    elif x in b and y in b:
        ans = "Yes"
    elif x in c and y in c:
        ans = "Yes"

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
from sys import stdin
import numpy as np

N = int(stdin.readline())
a = [int(x) for x in stdin.readline().rstrip().split()]

tmp = None
for i in range(N):
    if i == 0:
        tmp = a[i]
    else:
        tmp = tmp ^ a[i]

if tmp == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 23172
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e5+5;
const int mod=1e9+7;
ll f[maxn],n,k,ans;
ll fast(ll m,ll c){
    ll a=1;
    while(c)
	{
        if(c%2==1) a=a*m%mod;
        m=m*m%mod;
        c=c/2;
    }
    return a;
}
int main(){
    cin>>n>>k;
    for(int i=k;i>=1;i--)
	{
        f[i]=fast(k/i,n);
        for(int j=i*2;j<=k;j+=i)
            f[i]=(f[i]-f[j]+mod)%mod;
        ans=(ans+f[i]*i)%mod;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 4412
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

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

	auto prev = 0ll;
	auto begin = -1;
	for (auto i = 1; i <= N; ++i)
	{
		auto a = 0ll;
		cin >> a;
		if (i > 1)
		{
			if (a + prev >= L)
			{
				begin = i - 1;
			}
		}
		prev = a;
	}

	if (begin >= 0)
	{
		cout << "Possible" << endl;
		for (auto i = 1; i < begin; ++i)
		{
			cout << i << endl;
		}
		for (auto i = N - 1; i > begin; --i)
		{
			cout << i << endl;
		}
		cout << begin << endl;
	}
	else
	{
		cout << "Impossible" << endl;
	}

	return 0;
}

Measured memory_bytes: 768
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

typedef long long ll;

using namespace std;

int main() {
    ll h, w;
    cin >> h >> w;
    ll count = 0LL;
    if (h == 1 || w == 1) {
        cout << 1 << "\n";
        return 0;
    }

    // think 3 * 3 matrix.
    cout << (h * w + 1) / 2 << "\n";

    return 0;
}

Measured memory_bytes: 256
// Why am I so dumb? :c
#include<bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

const int MAXN = (int)2e4 + 5;
const int MLT = (int)5e4;

int arr[MAXN];

int C[MAXN];

int n;

void solve() {
    scanf("%d", &n);

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

    for (int i = 2; i <= n; ++i) {
        int cur = max(0, C[i] - C[i - 1]) + 1;
        arr[i] = cur;
    }

    arr[1] = 1;

    for (int i = 2; i <= n; ++i) {
        arr[i] += arr[i - 1];
    }

    for (int i = 1; i <= n; ++i) {
        printf("%d", arr[i]);
        printf(i == n ? "\n" : " ");
    }

    for (int i = 1, P = (int)5e8; i <= n; ++i) {
        printf("%d", C[i] - arr[i] + P);
        printf(i == n ? "\n" : " ");
    }
}

int main() {
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 768
#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::iter::*;
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;
// -----------------------------------------------
// Framework
// -----------------------------------------------

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($arg:expr),*) => {
        #[cfg(debug_assertions)]
        $(writeln!(stderr(), "{} = {:?}", stringify!($arg), $arg).unwrap());*
    };
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

// -----------------------------------------------
// Solution
// -----------------------------------------------
fn abs(num: i32) -> i32 {
    if num >= 0 {
        num
    } else {
        -num
    }
}
fn sign(num: i32) -> i32 {
    if num >= 0 {
        1
    } else {
        -1
    }
}
fn main() {
    let (n, k) = read!(usize, usize);
    let candles = read!([i32]);
    let mut answer = 2000000007i32;
    for i in 0..n {
        if i + k > n {
            break;
        }
        if sign(candles[i]) * sign(candles[i + k - 1]) < 0 {
            answer = min(
                answer,
                min(
                    abs(candles[i]) * 2 + abs(candles[i + k - 1]),
                    abs(candles[i + k - 1]) * 2 + abs(candles[i]),
                ),
            );
        } else {
            answer = min(answer, max(abs(candles[i]), abs(candles[i + k - 1])));
        }
    }
    println!("{}", answer);
}


Measured memory_bytes: 6396
#import sys
MOD = 10 ** 9 + 7
#input = sys.stdin.readline
import math

#import bisect

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

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

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

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

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default


def main():
#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]
    n=int(input())
    s=list(map(int,input()))

    count=0
    temp=0
    keta=[0,0,0]
    for i in range(1000):
        temp = 0
        if i <10:
            keta[0]=0
            keta[1]=0
            keta[2]=i
        elif i >=10 and i<100:
            keta[0]=0
            keta[1]=int(str(i)[0])
            keta[2]=int(str(i)[1])
        else:
            keta[0] = int(str(i)[0])
            keta[1] = int(str(i)[1])
            keta[2] = int(str(i)[2])
        for j in range(n):
            if keta[temp]==s[j]:
                 if temp<=1:
                    temp+=1
                 else:
                    count+=1
                    temp=0
                    break




    print(count)

#  print(c)




            #    print(n,kingaku(a,b,x))

if __name__ == "__main__":
    main()

Measured memory_bytes: 3700
from collections import Counter
from typing import List

n = int(input())
s = [input() for _ in range(n)]
# print(s)
count = Counter(s)
'''
c0 = count['AC']
c1 = count['WA']
c2 = count['TLE']
c3 = count['RE']
'''


def ans(result: str):
    num = count[result]
    print(result, ' x ', str(int(num)))


ans('AC')
ans('WA')
ans('TLE')
ans('RE')


Measured memory_bytes: 17212
#include <stdio.h>
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2],R[MAX/2+2];
int cnt;

void merge(int A[],int n, int left, int mid, int right)
{
	int n1 = mid -left;
	int n2 = right - mid;
	for(int i=0; i<n1;i++)
	{
		L[i] = A[left+i];
	}
	for(int i=0;i<n2;i++)
	{
		R[i] = A[mid+i];
	}
	L[n1]=R[n2]=SENTINEL;
	int i=0,j=0;
	for(int k=left;k<right;k++)
	{
		cnt++;
		if(L[i]<=R[j])
		{
			A[k]=L[i++];
		}
		else
		{
			A[k]=R[j++];
		}
	}

}

void mergeSort(int A[],int n,int left,int right)
{
	if(left+1<right)
	{
		int mid = (left+right)/2;
		mergeSort(A,n,left,mid);
		mergeSort(A,n,mid,right);
		merge(A,n,left,mid,right);
		
	}
}

int main()
{
	int A[MAX],n,i;
	cnt=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&A[i]);
	}
	mergeSort(A,n,0,n);
	for(i=0;i<n;i++)
	{
	if(i)
		{
			printf(" ");
		}
		printf("%d",A[i]);
	}
	printf("\n");
	printf("%d\n",cnt);

}


Measured memory_bytes: 5668
use std::io;

fn main() {
    let mut S = String::new();
    io::stdin().read_line(&mut S);
    let vec :Vec<&str> = S.trim().split_whitespace().collect();
    let A :i32 = vec[0].parse().unwrap();
    let B :i32 = vec[1].parse().unwrap();
    let C :i32 = vec[2].parse().unwrap();
    let mut K :i32 = vec[3].parse().unwrap();
    let mut total :i32 = 0;
    if K >= A {
        total = A;
        K -= A;
    }else{
        total = K;
        println!("{}",total);
        return ();
    }
    if K >= B {
        K -= B;
    }else{
        println!("{}",total);
        return ();
    }
    if K >= C {
        total -= C;
    }else{
        total -= K;
    }
    println!("{}",total);
}


Measured memory_bytes: 2084
# B - Can you solve this?

N, M, C = map(int, input().split())
B = list(int(b) for b in input().split())

ans = 0
for i in range(N):
    A = list(int(a) for a in input().split())
    s = C
    for j in range(M):
        s += A[j]*B[j]
    if s > 0:
        ans += 1
    else:
        continue

print(ans)

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


int main(){ 
    int N, K, C; string S;
    cin >> N >> K >> C >> S;

    vector<int> L, R;
    rep(i,S.size()){
        if(L.size() == K) break;

        if(S[i] == 'o'){
            L.push_back(i);
            i += C;
        }
    }

    rep(i, S.size()){
        if(R.size() == K) break;

        if(S[N-1-i] == 'o'){
            R.push_back(N-1-i);
            i += C;
        }
    }
    reverse(R.begin(), R.end());

    rep(i,K){
        if(L[i] == R[i]) cout << L[i]+1 << endl;
    }
}

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

ans = []
num = 0
while True:
    if N % (2**(num + 1)) == 0:
        b = 0
    else:
        b = 1
    ans.append(str(b))
    N = N - ((-2)**num) * b
    num += 1
    if N == 0:
        break
print(''.join(ans[::-1]))


Measured memory_bytes: 2940
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
	string S;
	cin>>S;
	map<char,int> myMap;
	map<char,int>::iterator mit;
	for (int i=0;i<S.size();i++){
		mit=myMap.find(S[i]);
		if (mit==myMap.end()){
			myMap[S[i]]=1;
		}else{
			(*mit).second++;
		}
	}
	if (myMap.size()==2){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[100001];
int main(){
        int n;
        scanf("%d", &n);
        for(int i=1; i<=n; i++) scanf("%d", a+i);
        sort(a+1, a+n+1);
        int x=0, y=0;
        for(int i=n; i>=1; i--){
                if(a[i] == a[i-1]){
                        if(x==0) x = a[i];
                        else if(y==0) y = a[i];
                        i--;
                }
        }
        printf("%lld", 1ll*x*y);
        return 0;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
  int N;
  cin >>N;
  int H[N];
  for(int i=0;i<N;i++){
    cin >> H[i];
  }
  int tempcnt=0;
  int maxlen=0;
  for(int k=0;k<N-1;k++){
    if(H[k]>=H[k+1]){
      tempcnt++;
      if(k+1==N-1 && maxlen<tempcnt){
        maxlen=tempcnt;
        break;
      }
    }else{
      if(maxlen<tempcnt){
        maxlen=tempcnt;
       
      }
       tempcnt=0;
      continue;
    }
  }
  cout<<maxlen;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;

const int OPEN_TIME = 10;
const int OPEN_COUNT = 11;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<VI> f(n, VI(OPEN_TIME));
    REP(i, n)REP(j, OPEN_TIME) cin >> f[i][j];
    vector<VI> p(n, VI(OPEN_COUNT));
    REP(i, n)REP(j, OPEN_COUNT) cin >> p[i][j];

    int ans = -(int)1e9;
    FOR(open, 1, 1023) {
        int profit = 0;
        REP(i, n) {
            int open_cnt = 0;
            REP(j, OPEN_TIME)if(f[i][j] == 1 and ((open >> j) & 1) == 1)
                open_cnt++;
            profit += p[i][open_cnt];
        }
        ans = max(ans, profit);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <map>
using namespace std;
#define pi 3.14159265358979323846

#define mii map<int, int>
 
int main(){
  ios_base::sync_with_stdio(false);
  int n;
  cin>>n;
  mii table;
  for(int i = 1; i <= n; i++) table[i] = 0;
  for(int i = 1; i < n; i++){
    int x;
    cin>>x;
    table[x] += 1;
  }

  for(auto i = table.begin(); i != table.end(); i++){
    cout<<i->second<<endl;
  }

  
}

Measured memory_bytes: 12540
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <complex>
#include <numeric>
#include <string.h>
#include <random>
#include <cmath>
#include <unordered_map>
#include <unordered_set>
#include <chrono>
#include <cassert>
#define rep(i,n) for (ll i = 0; i < (ll)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
//const ll MOD = 1000000007;
const ll MOD = 998244353;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template< int mod >
struct ModInt {
    int x;

    ModInt() : x(0) {}

    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    ModInt &operator+=(const ModInt &p) {
        if((x += p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt &operator-=(const ModInt &p) {
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt &operator*=(const ModInt &p) {
        x = (int) (1LL * x * p.x % mod);
        return *this;
    }

    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }

    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

    bool operator==(const ModInt &p) const { return x == p.x; }

    bool operator!=(const ModInt &p) const { return x != p.x; }

    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const {
        ModInt ret(1), mul(x);
        while(n > 0) {
            if(n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ModInt &p) {
         return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a) {
        int64_t t;
        is >> t;
        a = ModInt< mod >(t);
        return (is);
    }

    static int get_mod() { return mod; }
};

using mint = ModInt< MOD >;

int n, s;
int a[3000];
mint dp[3001];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> s;
    rep(i,n) cin >> a[i];
    mint ans = 0;
    dp[0] = 1;
    rep(i,n) {
        if (a[i] <= s) ans += dp[s-a[i]]*(n-i);

        for (int j = s; j >= a[i]; j--) {
            dp[j] += dp[j-a[i]];
        }
        dp[0] += 1;
    }
    cout << ans << endl;
}

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

const int MAX = 10000;
const int INFTY = (1<<29);

int V, E;
class DisjointSet {
    public:
        vector<int> rank, p;
        
        DisjointSet() {}
        DisjointSet(int size){
            rank.resize(size, 0);
            p.resize(size, 0);
            for(int i = 0; i < size; i++) makeSet(i);
        }
        
        void makeSet(int x){
            p[x] = x;
            rank[x] = 0;
        }
        
        bool same(int x, int y){
            return findSet(x) == findSet(y);
        }
        
        int findSet(int x){
            if(x != p[x]){
                p[x] = findSet(p[x]);
            }
            
            return p[x];
        }
        
        void unite(int x, int y){
            link(findSet(x), findSet(y));
        }
        
        void link(int x, int y){
            if(rank[x] > rank[y]){
                p[y] = x;
            } else {
                p[x] = y;
                if(rank[x] == rank[y]){
                    rank[y]++;
                }
            }
        }
};

class Edge{
public:
    int source, target, cost;
 
    Edge(int source=0, int target=0, int cost=0):
    source(source), target(target), cost(cost) {}
 
    bool operator < (const Edge &e) const {
        return cost < e.cost;
    }
};

int kruskal(int N, vector<Edge> edges){
    int totalCost = 0;
    sort(edges.begin(), edges.end());
    DisjointSet dset = DisjointSet(N + 1);
    for(int i = 0; i < N; i++){
        dset.makeSet(i);
    }
    
    int source, target;
    for(int i = 0; i < edges.size(); i++){
        Edge e = edges[i];
        if(!dset.same(e.source, e.target)){
            totalCost += e.cost;
            dset.unite(e.source, e.target);
        }
    }
    
    return totalCost;
}

int main(void){
    // Your code here!
    cin >> V >> E;
    vector<Edge> edges (E);
    int source, target, cost;
    for(int i = 0; i < E; i++){
        cin >> edges[i].source >> edges[i].target >> edges[i].cost;
    }
    
    cout << kruskal(V, edges) << endl;
    
}



Measured memory_bytes: 5184
N=int(input())
a=0
b=0
c=0
d=0
for _ in range(N):
    S=input()
    if S=='AC':
        a+=1
    elif S=='WA':
        b+=1
    elif S=='TLE':
        c+=1
    else:
        d+=1
print('AC x '+str(a))
print('WA x '+str(b))
print('TLE x '+str(c))
print('RE x '+str(d))

Measured memory_bytes: 9228
n = int(input())
a = [0] + list(map(int,input().split())) + [0]
tot = 0
for i in range(1,n+2):
  tot += abs(a[i] - a[i-1])
for i in range(1,n+1):
  print(tot - abs(a[i]-a[i-1]) - abs(a[i+1]-a[i]) + abs(a[i+1]-a[i-1]))

Measured memory_bytes: 14176
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

char buf[55];

int main(void) {
  int n;
  cin >> n >> buf;
  int res = 0;
  REP(i, n) {
    if(buf[i] == 'A' && buf[i+1] == 'B' && buf[i+2] == 'C') {
      ++res;
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>
#include<utility>
#include<numeric>

#define PB push_back
#define all(a)  (a).begin(),(a).end()
#define ALL(v) begin(v), end(v)
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define V vector<int>
#define VV vector<V>
#define VVV vector<VV>

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int inf = (int)1e9;
const ll INF = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };
const long double EPS = 1e-10;

string s;
int ans = 100;
int now, mx;

int main() {

	cin >> s;

	for (int i = 0; i < 26; i++) {
		now = 0;
		mx = 0;
		for (char c : s) {
			if (c == (char)('a' + i)) {
				now = 0;
			}
			else {
				mx = max(mx, ++now);
			}
		}
		ans = min(ans, mx);
	}

	cout << ans << '\n';

	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    long long ans1 = 0, sum1 = 0;

    //先頭が正であるとしたときの答え
    for (int i = 0; i < n; i++) {
        sum1 += a[i];
        if (i % 2 == 0) {
            if (sum1 <= 0) {
                ans1 += -sum1 + 1;
                sum1 = 1;
            }
        } else {
            if (sum1 >= 0) {
                ans1 += sum1 + 1;
                sum1 = -1;
            }
        }
    }

    long long ans2 = 0, sum2 = 0;

    //先頭が負であるとしたときの答え
    for (int i = 0; i < n; i++) {
        sum2 += a[i];
        if (i % 2 == 1) {
            if (sum2 <= 0) {
                ans2 += -sum2 + 1;
                sum2 = 1;
            }
        } else {
            if (sum2 >= 0) {
                ans2 += sum2 + 1;
                sum2 = -1;
            }
        }
    }

    cout << min(ans1, ans2) << endl;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;



public class Main
{	
	public static void main(String args[]) throws IOException
	{
		FastScanner fs = new FastScanner();
			int N = fs.nextInt(),count[] = new int[10000];
			for(int i=1; i<=100; i++)
			{
				for(int j=1; j<=100; j++)
				{
					for(int k=1; k<=100; k++)
					{
						int n =i*i+j*j+k*k+i*j+j*k+k*i;
						if(n<=10000)
						count[n-1]++;
					}
				}
					
			}
			for(int i=0; i<N; i++)
			System.out.println(count[i]);
	}

}
class FastScanner
{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	StringTokenizer str = new StringTokenizer("");
	
	String next() throws IOException
	{
		while(!str.hasMoreTokens())
			str = new StringTokenizer(br.readLine());
		
		return str.nextToken();
	}
	
	int nextInt() throws IOException
	{
		return Integer.parseInt(next());
	}
	
	float nextfloat() throws IOException
	{
		return Float.parseFloat(next());
	}
	
	double nextDouble() throws IOException
	{
		return Double.parseDouble(next());
	}
	long nextLong() throws IOException
	{
		return Long.parseLong(next());
	}
	int[] arrayIn(int n) throws IOException
	{
		int arr[] = new int[n];
		for(int i=0; i<n; i++)
		{
			arr[i] = nextInt();
		}
		return arr;
	}
}



	

Measured memory_bytes: 35732
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N,M,S;
//i->jに運賃a、b分でいけるなら
//集合adj[i]は要素として(j,a,b)を持つ
vector<vector<tuple<LL,LL,LL>>> adj;
LL C[51],D[51];

LL ans[51];

void solve(){
	S = min(S,2500LL);
	//ダイクストラ 
	//tuple<コスト、残り銀貨、頂点番号>
	priority_queue<tuple<LL,LL,LL>,vector<tuple<LL,LL,LL>>,greater<tuple<LL,LL,LL>>> q;
	//頂点iに、残り銀貨j枚で最短k分で行けるならcost[i][j] = k;
	vector<vector<LL>> cost(N+1,vector<LL>(2501,INF));
	cost[1][S] = 0;
	q.push(tuple<LL,LL,LL>(0,S,1));
	while(!q.empty()){
		LL now_cost = get<0>(q.top());
		LL remain = get<1>(q.top());
		LL now_vertex = get<2>(q.top());
		q.pop();
		if(cost[now_vertex][remain]<now_cost) continue;
		if(remain+C[now_vertex]<=2500){
			if(cost[now_vertex][remain+C[now_vertex]]>cost[now_vertex][remain]+D[now_vertex]){
				cost[now_vertex][remain+C[now_vertex]] = cost[now_vertex][remain]+D[now_vertex];
				q.push(tuple<LL,LL,LL>(cost[now_vertex][remain+C[now_vertex]],remain+C[now_vertex],now_vertex));
			}
		}
		for(auto next:adj[now_vertex]){
			LL cost_required = get<2>(next);
			LL silver_required = get<1>(next);
			LL next_vertex = get<0>(next);
			if(remain-silver_required<0) continue;
			if(cost[next_vertex][remain-silver_required]<=cost[now_vertex][remain]+cost_required) continue;
			cost[next_vertex][remain-silver_required] = cost[now_vertex][remain]+cost_required;
			q.push(tuple<LL,LL,LL>(cost[next_vertex][remain-silver_required],remain-silver_required,next_vertex));
		}
	}

	for(int i=2;i<=N;i++){
		ans[i] = INF;
		for(int j=0;j<=2500;j++){
			ans[i] = min(ans[i],cost[i][j]);
		}
	}
}

int main(){
    cin >> N >> M >> S;
    adj = vector<vector<tuple<LL,LL,LL>>>(N+1);
    for(int i=0;i<M;i++){
    	LL u,v,a,b;cin >> u >> v >> a >> b;
    	adj[u].push_back(tuple<LL,LL,LL>(v,a,b));
    	adj[v].push_back(tuple<LL,LL,LL>(u,a,b));
    }
    for(int i=1;i<=N;i++) cin >> C[i] >> D[i];

    solve();
    
    for(int i=2;i<=N;i++)cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 6888
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(all(x));
#define RSORT(x) sort(rall(x));
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using vb = vector<bool>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;
const ll inf = 1ll<<29;
const ll mod = 1000000007;
const double eps = 1e-9;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  int N, M; cin >> N >> M;
  vector<pii> X(N);
  rep(i,N) {
    int A,B; cin >> A >> B;
    X.at(i) = make_pair(A,B);
  }
  SORT(X);
  
  int cnt = 0;
  ll ans = 0ll;
  for(int i = 0;; i++) {
    for(int j = 0; j < X.at(i).second; j++) {
      cnt++;
      ans += X.at(i).first;
      if(cnt == M) {
        cout << ans << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 1024
N = int(input())
X = []
Y = []
P = []
for _ in range(N):
    x, y, p = map(int, input().split())
    X.append(x)
    Y.append(y)
    P.append(p)

DX = [[0] * (1 << N) for _ in range(N)]
DY = [[0] * (1 << N) for _ in range(N)]

for i, x in enumerate(X):
    for k in range(1 << N):
        d = abs(x)
        for j, xx in enumerate(X):
            if k & (1 << j):
                d = min(d, abs(xx - x))
        DX[i][k] = d * P[i]
for i, y in enumerate(Y):
    for k in range(1 << N):
        d = abs(y)
        for j, yy in enumerate(Y):
            if k & (1 << j):
                d = min(d, abs(yy - y))
        DY[i][k] = d * P[i]

ANS = [1 << 100] * (N + 1)
PC = [0] * (1 << N)
for i in range(1, 1 << N):
    j = i ^ (i & (-i))
    PC[i] = PC[j] + 1

RA = []
for i in range(1 << N):
    t = []
    for j in range(N):
        if i & (1 << j):
            t.append(j)
    RA.append(tuple(t))


mm = (1 << N) - 1
for i in range(1 << N):
    m = i ^ mm
    j = m
    while 1:
        ans = 0
        for k in RA[i^j^mm]:
            ans += min(DX[k][i], DY[k][j])
        
        pc = PC[i] + PC[j]
        ANS[pc] = min(ANS[pc], ans)
        
        if not j:
            break
        j = m & (j - 1)

print(*ANS, sep = "\n")


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

typedef double frac;
const double EPS=1e-10;
double add(double l, double r){
    if(abs(l+r)<EPS*(abs(l)+abs(r))) return 0;
    return l+r;
}
typedef double frac;
struct Pt{
    frac x, y;
    Pt(frac xx=0, frac yy=0){x=xx; y=yy;}
    Pt& operator=(const Pt &rhs){
        x=rhs.x; y=rhs.y; return *this;
    }
    Pt& operator+=(const Pt &rhs){
        x = add(x,rhs.x); y = add(y,rhs.y); return *this;
    }
    Pt& operator-=(const Pt &rhs){
        x = add(x,-rhs.x); y = add(y,-rhs.y); return *this;
    }
    Pt& operator*=(const frac &rhs){
        x *= rhs; y *= rhs; return *this;
    }
    Pt& operator/=(const frac &rhs){
        x /= rhs; y /= rhs; return *this;
    }
};
Pt operator+(const Pt &lhs, const Pt &rhs){
    Pt sum=lhs; sum += rhs; return sum;
}
Pt operator-(const Pt &lhs, const Pt &rhs){
    Pt sum=lhs; sum -= rhs; return sum;
}
Pt operator*(const Pt &lhs, const frac &rhs){
    Pt sum=lhs; sum *= rhs; return sum;
}
Pt operator*(const frac &lhs, const Pt &rhs){
    Pt sum=rhs; sum *= lhs; return sum;
}
Pt operator/(const Pt &lhs, const frac &rhs){
    Pt sum=lhs; sum /= rhs; return sum;
}
bool operator==(const Pt &lhs, const Pt &rhs){return lhs.x==rhs.x && lhs.y==rhs.y;}
bool operator!=(const Pt &lhs, const Pt &rhs){return !(lhs==rhs);}
bool operator<(const Pt &lhs, const Pt &rhs){return lhs.x!=rhs.x ? lhs.x<rhs.x : lhs.y<rhs.y;}
bool operator>(const Pt &lhs, const Pt &rhs){return rhs<lhs;}
bool operator<=(const Pt &lhs, const Pt &rhs){return !(lhs>rhs);}
bool operator>=(const Pt &lhs, const Pt &rhs){return !(lhs<rhs);}
bool operator<(Pt lhs, Pt rhs){
    return lhs.x!=rhs.x ? lhs.x<rhs.x : lhs.y<rhs.y;
}
istream& operator>>(istream &is, Pt &rhs){
    double x, y;
    is >> x >> y;
    rhs=Pt(x,y);
    return is;
}
ostream& operator<<(ostream &os, Pt rhs){
    os << rhs.x << " " << rhs.y;
    return os;
}
frac dot(Pt a, Pt b){return a.x*b.x+a.y*b.y;}//内積
frac cross(Pt a, Pt b){return a.x*b.y-a.y*b.x;}//外積
//qが線分p1-p2上にあればtrue
bool on_seg(Pt p1, Pt p2, Pt q){
    return cross(p1-q,p2-q)==0 && dot(p1-q,p2-q)<=0;
}
//intersection　交点を求める
Pt insec(Pt p1, Pt p2, Pt q1, Pt q2){
    return p1+(cross(q2-q1,q1-p1)/cross(q2-q1,p2-p1))*(p2-p1);
}
int main(){
	int n;  cin >> n;
    vector<Pt> p(n+1);
    for(int i=0; i<n; i++) cin >> p[i];
    p[n]=p[0];

    bool flg=1;
    if(n%2==1){
        flg=0;
    }else{
        for(int i=0, j=n/2; i<n/2; ++i,++j){
            if(p[i]-p[i+1]!=-1*(p[j]-p[j+1])){
                flg=0;
                break;
            }
        }
    }

    if(flg){
        cout << fixed << setprecision(5);
        cout << (p[0]+p[n/2])/2 << endl;
    }else{
        cout << "NA" << endl;
    }
}


Measured memory_bytes: 3276
from collections import defaultdict


def main():
    high, width, goal = map(int, input().split())

    move_dic = [defaultdict(int) for i in range(width + 2)]
    for i in range(2 ** (width - 1)):
        data = bin(i)[2:]
        if '11' in data:
            continue
        data = [0 for j in range(width - 1 - len(data))] + list(map(int, list(data)))
        # print(data)
        for j in range(width - 1):
            if data[j]:
                move_dic[j + 1][j + 2] += 1
                move_dic[j + 2][j + 1] += 1
            elif j < width - 2:
                if data[j + 1] == 0:
                    move_dic[j + 2][j + 2] += 1
                if j == 0:
                    move_dic[j + 1][j + 1] += 1
            else:
                move_dic[j + 2][j + 2] += 1
            # print(move_dic)

    dp = [[0 for i in range(width + 2)] for j in range(high + 2)]
    dp[1][1] = 1

    for i in range(2, high + 2):
        for j in range(1, width + 1):
            dp[i][j] = dp[i - 1][j - 1] * move_dic[j - 1][j] + dp[i - 1][j] * move_dic[j][j] + dp[i - 1][j + 1] * move_dic[j + 1][j]

    if width == 1:
        dp[high + 1][goal] = 1
    mod = 10 ** 9 + 7
    print(dp[high + 1][goal] % mod)



if __name__ == '__main__':
    main()


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



int main() {
    char C1[3];
    char C2[3];
    scanf("%s", C1);
    scanf("%s", C2);
    int s = 0;
    for (int i=0;i<3;i++) {
        if (C1[i]==C2[i]) s++;
    }
    cout << s << '\n';
}


Measured memory_bytes: 256
from fractions import gcd
n = int(input())
a = [int(i) for i in input().split()]

mx = 0
l = [0] * (n+1)
r = [0] * (n+1)
for i in range(1, n+1):
    l[i] = gcd(l[i-1], a[i-1])
    r[i] = gcd(r[i-1], a[-i])

mx = 0
for i in range(n):
    mx = max(mx,gcd(l[i], r[n-i-1]))

print(mx)


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

int main() {
	string s;
	cin>>s;
	
		if(s=="SUN") cout<<"7"<<endl;
		if(s=="MON") cout<<"6"<<endl;
		if(s=="TUE") cout<<"5"<<endl;
		if(s=="WED") cout<<"4"<<endl;
		if(s=="THU") cout<<"3"<<endl;
		if(s=="FRI") cout<<"2"<<endl;
		if(s=="SAT") cout<<"1"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
const int mod=1000000007;
ll dp[100005][2];
int main(){
    string s;cin >> s;
    dp[0][0]=1;
    int n=s.size();
    for(int i=0;i<n;i++){
        {
            if(s[i]=='0'){
                dp[i+1][0]=dp[i][0];
                dp[i+1][1]=dp[i][1];
            }
            else{
                dp[i+1][1]=(dp[i][1]+dp[i][0])%mod;
            }
        }
        {
            if(s[i]=='0'){
                (dp[i+1][1]+=dp[i][1]*2%mod)%=mod;
            }
            else{
                (dp[i+1][0]+=dp[i][0]*2%mod)%=mod;
                (dp[i+1][1]+=dp[i][1]*2%mod)%=mod;
            }
        }
    }
    ll ans=(dp[n][0]+dp[n][1])%mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char a[5];
    scanf("%s",a);
    int ans=0;
    for(int i=0;a[i]!='\0';i++)
    {
        if(a[i]=='+') ans++;
        else ans--;
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
 
const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
}
ll lcm(ll x,ll y){
  ll g=gcd(x,y);
  return x/g*y;
}

using Graph=vector<vector<int>>;
Graph G;

int main(){
  int m,d;
  cin >> m >> d;
  if(m==1 && d==31) cout<<1<<endl;
  else if(m==2 && d==28) cout<<1<<endl;
  else if(m==3 && d==31) cout<<1<<endl;
  else if(m==4 && d==30) cout<<1<<endl;
  else if(m==5 && d==31) cout<<1<<endl;
  else if(m==6 && d==30) cout<<1<<endl;
  else if(m==7 && d==31) cout<<1<<endl;
  else if(m==8 && d==31) cout<<1<<endl;
  else if(m==9 && d==30) cout<<1<<endl;
  else if(m==10 && d==31) cout<<1<<endl;
  else if(m==11 && d==30) cout<<1<<endl;
  else if(m==12 && d==31) cout<<1<<endl;
  else cout<<0<<endl;
  
}
    

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

#define pb 		push_back
#define mp 		make_pair
#define prior   priority_queue
#define MOD 	1000000007
#define INF64 	(long long)1e18
#define INF 	(int)1e9
#define PI 		3.1415926535897932384626433832795 
#define ll      long long
#define ld		long double
#define ret     return
#define NUM 	1000001
const int SIZE = 2e5+4;
void fastio(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

void input(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
}

int di[] = {-1,1,0,0}, dj[] = {0,0,-1,1};

void dfs(int i, int j, vector<string>& grid, vector<vector<bool>>& visited){
	if(grid[i][j]!='#')
		visited[i][j]=true;
	else
		return;
	for(int d=0;d<4;d++){
		int ni=i+di[d],nj=j+dj[d];
		if(ni>=0&&nj>=0&&ni<grid.size()&&nj<grid[0].size()&&grid[ni][nj]!='#'&&!visited[ni][nj]){
			visited[ni][nj]=true;
			dfs(ni,nj,grid,visited);
		}
	}
}



void solveTest(){
}

int main(){
	fastio();
	//input();

	/*int t;
	cin>>t;
	while(t--){
		solveTest();
	}*/

	int n;
	cin>>n;
	int a[n+1];
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	ll ans = INF64;
	for(int i=1;i<=4*n+1;i++){
		ll sum=0;
		for(int j=1;j<=n;j++){
			sum += abs(i-a[j])*abs(i-a[j]);
		}
		//cout<<sum<<endl;
		ans = min(ans,sum);
	}
	cout<<ans<<endl;



	return 0;
}
     

Measured memory_bytes: 256
n=input()
a,b="keyence",0
for i,j in zip(a,n):
    if i==j:
        b+=1
    else:break
for i,j in zip(a[::-1],n[::-1]):
    if i==j:
        b+=1
    else:break
print("YES" if b>=7 else "NO")

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

using namespace std;
typedef long long ll;
typedef pair<int,ll> pil;
typedef pair<int,int> pii;
const int maxN = 100010;
const int maxC = 1e6 + 10;
const int INF = 1e9; 
int n,k;
struct node
{
	int t;
	ll d;
	bool operator <(const node& tmp)const
	{
		return d>tmp.d;	
	}	
};
node a[maxN];
set<int> st;
int use[maxN];
priority_queue<ll, vector<ll>, greater<ll> > Q; 

int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%lld",&a[i].t,&a[i].d);
	}
	sort(a+1,a+1+n);
	ll ans = 0;
	ll sum = 0;
	ll cnt = 0;
	int pos = 0;
	for(int i=1;i<=n;i++)
	{
		if(!use[a[i].t])
		{
			ans += a[i].d;
			cnt += 1;
			use[a[i].t] = 1;
			k--;
			if(k == 0)
			{
				pos = i+1;
				break;
			}
		}
		else
		{
			Q.push(a[i].d);
			ans += a[i].d;
			k--;
			if(k == 0)
			{
				pos = i+1;
				break;
			}
		}
	}
	sum = cnt*cnt + ans;
	for(int i=pos;i<=n;i++)
	{
		if(use[a[i].t] == 0)
		{
			cnt ++;
			use[a[i].t] = 1;
			if(Q.empty()) break;
			ll x = Q.top();
			Q.pop();
			ans = ans - x + a[i].d;
			
		}
		sum = max(sum,cnt*cnt + ans);
	}
	cout<<sum<<endl;
    return 0;
}

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

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

typedef long long ll;
const ll mod = 1e9 + 7;

ll inv[200010];
ll fact[200010];
ll factinv[200010];

void init(int size){
    fact[0] = fact[1] = inv[1] = 1;
    factinv[0] = factinv[1] = 1;
    for(int i=2; i<=size; i++){
        inv[i] = (mod - mod/i) * inv[mod % i] % mod;
        fact[i] = fact[i-1] * i % mod;
        factinv[i] = factinv[i-1] * inv[i] % mod;
    }
}

ll comb(int n, int k){
    return fact[n] * factinv[k] % mod * factinv[n-k] % mod;
}

int main(){
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    init(200000);

    ll ans = comb(h-1 + w-1, h-1);
    rep(i, a){
        ans -= comb(h-1-i + b-1, h-1-i) * comb(i+w-b-1, i) % mod;
        if(ans < 0) ans += mod;
    }

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


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

int main()
{
    int a, b, c, sum ,cont = 0;

    cin >> a >> b >> c;

    sum = a;
    for(int i = 0; i < c; i++)
    {
        if(sum <= b){
            cont++;
            sum += a;
        }
    }

    cout << cont << endl;


    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
from functools import reduce
import sys
try:
    from typing import List
except ImportError:
    pass


def gcd(a: int, b: int):
    while b != 0:
        a, b = b, a % b
    return a


def lcm(a: int, b: int):
    g = gcd(a, b)
    return a // g * b


def solve(N: int, T: "List[int]"):
    print(reduce(lcm, T))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    T = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, T)


if __name__ == '__main__':
    main()


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

#define BLESS_ME
#define ORZ_EVERYBODY

vector<int> g[200000 + 5];
int n;

bool ok = false;
void dfs(int step, int cur) {
    if (cur == n) ok = true;
    if (step == 2) return ;
    if (ok) return ;
    for (int& x : g[cur]) dfs(step + 1, x);
}

int main() {
    int m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
    }
    dfs(0, 1);
    if (ok) puts("POSSIBLE"); else puts("IMPOSSIBLE");
    return 0;
}

Measured memory_bytes: 8576
Scanf.scanf "%d %d %d %d" (fun x1 y1 x2 y2 ->
    let rot_x cx cy x y =  y + cx - cy in
    let rot_y cx cy x y = -x + cy + cx in
    let x3 = rot_x x2 y2 x1 y1 in
    let y3 = rot_y x2 y2 x1 y1 in
    let x4 = rot_x x3 y3 x2 y2 in
    let y4 = rot_y x3 y3 x2 y2 in
    Printf.printf "%d %d %d %d\n" x3 y3 x4 y4
)

Measured memory_bytes: 3868
n=int(input())
l=[list(map(int, input().split())) for i in range(n)]
l=[[0,0,0]]+l
for i in range(n):
    if abs(l[i+1][1]-l[i][1])+abs(l[i+1][2]-l[i][2])>l[i+1][0]-l[i][0]:
        print('No')
        break
    elif abs(l[i+1][1]-l[i][1])+abs(l[i+1][2]-l[i][2])==0:
        if (l[i+1][0]-l[i][0])%2!=0:
            print('No')
            break
    elif (l[i+1][0]-l[i][0])%2!=(abs(l[i+1][1]-l[i][1])+abs(l[i+1][2]-l[i][2]))%2:
        print('No')
        break
else:
    print('Yes')

Measured memory_bytes: 28068
n,x,y=map(int,input().split())
k=[0]*(n-1)
for i in range(1,n):
	for j in range(i+1,n+1):
		if i<=x and y<=j:
			k[j-i-y+x] += 1
		elif x<j and j<y and i<=x:
			unta = min(j-i-1, x+y-i-j)
			k[unta] += 1
		elif x<i and i<y and y<=j:
			unta = min(j-i-1, i+j-x-y)
			k[unta] += 1
		elif x<i and x<j and i<y and j<y:
			unta = min(j-i-1, i-x+y-j)
			k[unta] += 1
		else:
			k[j-i-1] += 1
for i in range(n-1):
	print(k[i]) 

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

int main()
{
    int n, m, a[100], b[100];

    while( cin >> n >> m )
    {
        if( n + m == 0 )
            break;

        int suma = 0;
        for( int i = 0; i < n; i++ )
        {
            cin >> a[i];
            suma += a[i];
        }

        int sumb = 0;
        for( int i = 0; i < m; i++ )
        {
            cin >> b[i];
            sumb += b[i];
        }

        int s = 0, t = 0, u = 10000000;
        for( int i = 0; i < n; i++ )
            for( int j = 0; j < m; j++ )
                if( suma - a[i] + b[j] == sumb - b[j] + a[i] && u > a[i] + b[j] )
                {
                    s = a[i];
                    t = b[j];
                    u = a[i] + b[j];
                }
        if( u == 10000000 )
            cout << -1 << endl;
        else
            cout << s << " " << t << endl;

    }
    return 0;
}


Measured memory_bytes: 3008
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        long[] a = new long[n];
        long[][] bc = new long[m][2];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextLong();
        }
        for (int i = 0; i < m; i++) {
            bc[i][1] = sc.nextInt();
            bc[i][0] = sc.nextLong();
        }

        Arrays.sort(a);
        Arrays.sort(bc, Comparator.comparingLong((long[] b) -> b[0]).reversed());
        int j = 0;
        for (int i = 0; i < n; i++) {
            if (j >= m || a[i] >= bc[j][0]) {
                break;
            }
            a[i] = bc[j][0];
            bc[j][1]--;
            if (bc[j][1] <= 0) {
                j++;
            }
        }
        long ans = 0;
        for (int i = 0; i < n; i++) {
            ans += a[i];
        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 101408