akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main() {
    int n; cin >> n;  // ???????????????????????°
    
    while(n--){
        int balls[10] = {0};
        for(int i = 0; i < 10; i++) cin >> balls[i]; // ??????????????????????????\???
        
        bool isYES = true;  // ???10???????????????????????????????????????
        int topB = 0, topC = 0;  // ???B?????????C???????????¨????????????
        for(int i = 0; i < 10; i++){
            if (topB < balls[i]){
                topB = balls[i];
            } else if (topC < balls[i]) {
                topC = balls[i];
            } else {
                isYES = false;
                break;
            }
        }
        cout << (isYES ? "YES" : "NO") << endl;
    }
}

Measured memory_bytes: 3060
#!/usr/bin/env python3
import sys
import collections as cl


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    n, x, y = MI()
    ans = [0] * (n)

    for i in range(1, n + 1):
        for j in range(i + 1, n + 1):
            dis = min(j - i, abs(i - x) + abs(j - y) + 1)
            ans[dis] += 1

    for i in range(1, n):
        print(ans[i])


main()


Measured memory_bytes: 75392
#include <iostream>

using namespace std;

int main() {
    while(true){
    int N,M,pos=1,count=0;
    cin >> N >> M;
        if(N==0) break;
    int sugoroku[N],dice[M];
    for(int i=0;i<N;i++){
        int a;
        cin >> a;
        sugoroku[i] = a;
    }
    for (int j=0;j<M;j++){
        int b;
        cin >> b;
        dice[j] = b;
    }
    while(true){
        if(pos>=N) break;
        pos = pos + dice[count];
        pos = pos + sugoroku[pos-1];
        count++;
    }
    cout << count << endl;
    }
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define FUP(i, a, b) for(int i = a; i <= b; i++)
#define FDOWN(i, a, b) for(int i = a; i >= b; i--)
#define MS(a, b) memset(a, b, sizeof(a))
#define ALL(v) v.begin(), v.end()
#define CIN(a) cin >> a;
#define CIN2(a, b) cin >> a >> b
#define CIN3(a, b, c) cin >> a >> b >> c
#define COUT(a) cout << a
#define COUT2(a, b) cout << a << ' ' << b
#define COUT3(a, b, c) cout << a << ' ' << b << ' ' << c
#define ENDL cout << '\n'
int dy[4] = { -1, 1, 0, 0 };
int dx[4] = { 0, 0, 1, -1 };
#define MOD 1000000007

ll dp[1000001];
ll eight[1000001];
ll one[1000001];

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

	eight[0] = 1;
	one[1] = 1;
	FUP(i, 1, 1000000)
	{
		eight[i] = eight[i - 1] * 8 % MOD;
		one[i] = one[i - 1] * 9 + eight[i - 1];
		one[i] %= MOD;
	}
	dp[1] = 0;
	dp[2] = 2;
	FUP(i, 3, 1000000)
	{
		dp[i] = dp[i - 1] * 10 % MOD + 1LL * 2 * one[i - 1] % MOD;
		dp[i] %= MOD;
	}
	int N;
	CIN(N);
	COUT(dp[N]);

	return 0;
}

Measured memory_bytes: 27080
fn strcmp(s: &[char], t: &Vec<char>) -> bool {
    for i in 0..s.len() {
        if s[i] != t[i] && s[i] != '?' {
            return false;
        }
    }
    return true;
}
fn solve() {
    let s: Vec<char> = read::<String>().chars().collect();
    let t: Vec<char> = read::<String>().chars().collect();
    if s.len() < t.len() {
        println!("UNRESTORABLE");
        exit(0);
    }
    let mut cands = vec![];

    for i in 0..(s.len() - t.len() + 1) {
        let mut cand = String::new();
        if strcmp(&s[i..i + t.len()], &t) {
            for l in 0..i {
                if s[l] == '?' {
                    cand.push('a');
                } else {
                    cand.push(s[l]);
                }
            }
            for &c in &t {
                cand.push(c);
            }
            for l in i + t.len()..s.len() {
                if s[l] == '?' {
                    cand.push('a');
                } else {
                    cand.push(s[l]);
                }
            }
            cands.push(cand);
        }
    }
    cands.sort();
    if cands.len() == 0 {
        println!("UNRESTORABLE");
    } else {
        println!("{}", cands[0]);
    }
}

fn main() {
    let stack_size = 104_857_600;
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min, Reverse};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========


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

using namespace std;

const int nmax = 50;
const int mmax = 50;
char N_sq[nmax][nmax], M_sq[mmax][mmax];


bool judge_match(int x, int y, int M){
	for(int i=0;i<M;++i){
		for(int j=0;j<M;++j){
			if(N_sq[y+i][x+j] != M_sq[i][j]) return false;
		}
	}
	return true;
}


int main(void){
	int N,M;

	cin >> N >> M;
	bool exist = false;

	for(int i=0;i < N;++i){
		cin >> N_sq[i];
	}

	for(int i=0;i < M;++i){
		cin >> M_sq[i];
	}

	for(int y=0;y <= N - M;++y){
		for(int x=0;x <= N - M;++x){
			if(judge_match(x, y, M)) exist=true;
		}
	}

	if(exist)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;

}

Measured memory_bytes: 256
#B-Coins
# -*- coding: utf-8 -*-

a, b, c, x = map(int, [input() for i in range(4)])
ans = 0

for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if (500*i+100*j+50*k)==x:
                ans += 1 

print(ans)


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

int main() {
	int n; cin >> n;
	vector<int> a(n), b(n), c(n - 1);
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) cin >> b[i];
	for (int i = 0; i < n - 1; i++) cin >> c[i];
	long long sum = 0;
	for (int i = 0; i < n; i++) {
		sum += b[a[i] - 1];
		if (a[i] + 1 == a[i + 1]) {
			sum += c[a[i] - 1];
		}
	}
	cout << sum << '\n';
}


Measured memory_bytes: 3628
import math

steps=[1, 1, 2, 4]+ [0]*27
for i in range(4, 31):
  steps[i] = steps[i-1] + steps[i-2] + steps[i-3]

while True:
  n = input()
  if n == 0: break
  print int(math.ceil(steps[n]/3650.0))

Measured memory_bytes: 4364
import bisect
num = 1000000
L = [True] * (num+1)
L[0] = False
L[1] = False
for i in range( 2, int(num**0.5)+ 2 ):
    if not L[i]:
        continue
    for j in range(i*2, num+1, i):
        L[j] = False

p = [ x for x in range(num+1) if L[x] ]

while True:
    try:
        n = int(input())
        k = bisect.bisect_left(p,n+1)
        print(k)
    except:
        break



Measured memory_bytes: 16644
#include <iostream>
using namespace std;
int a,b,c,d,A,B,C;
bool i;
int as(int x,int y){
	if(x-y>0) return x-y;
	else  return y-x;
}
int main(){
	cin>>a>>b>>c>>d;
	A=as(a,b);
	B=as(b,c);
	C=as(a,c);
	if(A<=d&&B<=d) i=1;
	if(i==1||C<=d){
		cout<<"Yes";
	}
	else cout<<"No";
	return 0;
} 

Measured memory_bytes: 256
// wake me up, wake me up inside. I cant wake up.
// save me , save me from the nothing ive become;

#include <bits/stdc++.h>

#define s second
#define f first
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define int int64_t

using namespace std;

const int MAX=1e6+20,INF=1e9+1,mod=1e9+7;

int n,m,d,ans,a[MAX],c,b,t[MAX],dis[MAX],del,x,cnt,c2,mn2=INF,mx1=-MAX,mx2=-MAX,l,r,color,sum2,fn,mx=-1,mn=INF,k,y,z;
string s,str,sans;
//set <int> st;
//vector <pii> adj[MAX];
bool mark,ark2;
vector <int> adj[MAX];
vector<int> vec;
queue <int> q;
long double a1,a2;
map <int,int> mp;

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

main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> x >> y >> z;
	if(z<=y && x<=z)
    {
        cout << "Yes";
        return -0;
    }
    cout << "No";
    return -0;
}




Measured memory_bytes: 24832
#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;

typedef long long LL;

LL gcd(LL a,LL b){
    while(b){
        auto t = a%b;
        a = b;
        b = t;
    }
    return a;
}

long long solve(){
    int n,m;
    cin>>n>>m;
    vector<int> table(n,0);
    for(int i = 0;i<n;i++){
        cin>>table[i];
        table[i] = table[i]/2;
    }
    LL x = table[0];
    for(int i = 0;i<n;i++){
        auto temp = gcd(x,table[i]);
        x = x * table[i]/temp;
    }
    LL ans = 0;
    // cout<<x<<endl;
    auto add = x;
    while(x<=m){
        // cout<<x<<endl;
        bool f = true;
        for(int i = 0;i<n;i++){
            int cnt = x/table[i];
            if(cnt%2==0){
                f = false;
                break;
            }
        }
        if(f) break;
        x=x+add;
    }
    ans = ((m/x)+1)/2;
    cout<<ans<<endl;
    return 0;
}

int main(){
    int T = 1;
    while(T--){
        solve();
    }
    return 0;
}

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

int main(){
  int N, L;
  cin >> N >> L;
  vector<string> letter(N);
  for(int i = 0; i < N; i++){
    cin >> letter.at(i);
  }
  sort(letter.begin(), letter.end());
  
  for(int i = 0; i < N; i++){
    cout << letter.at(i);
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
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;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    int n;
    cin >> n;
    int ma = 1e6 + 10;
    VI ok(ma, 1), cnt(ma);
    REP(i,n){
        cnt[in()]++;
    }
    int ans = 0;
    FOR(x,1,ma-1){
        if (!ok[x]) continue;
        if (cnt[x] == 1) ans++;
        if (cnt[x] > 0){
            for (int y = 2 * x; y < ma; y += x) ok[y] = 0;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 11176
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <utility>
using namespace std;

int main()
{
    long long N;
    cin >> N;
    long long A[N];
    for (long long i = 0; i < N; ++i)
        cin >> A[i];
    
    long long ans = 0;
    long long TMP[N];
    long long bN = 0;
    long long divid = 0;
    for (long long i = 0; i < N; ++i) {
        long long tmp = A[i] - (i+1);
        TMP[i] = tmp;
    }

    sort(TMP, TMP + N);
    long long b = TMP[(N - 1)/2];

    for (long long i = 0; i < N; ++i) {
        ans += abs(TMP[i] - b);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <list>
#include <deque>
using namespace std;
typedef pair<int, int> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

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

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    int n, q; cin >> n >> q;
    
    list<int> L[n];
    
    REP(i, q){
        int a, b, c; cin >> a;
        if(a==0){
            cin >> b >> c;
            L[b].push_back(c);
        }
        if(a==1){
            cin >> b;
            for(auto itr=L[b].begin(); itr!=L[b].end(); ++itr) {
                if(itr!=L[b].begin()) cout << " ";
                cout << *itr;
            }
            cout << endl;
        }
        if(a==2){
            cin >> b >> c;
            L[c].splice(L[c].end(), L[b]);
        }
    }
	return 0;
}


Measured memory_bytes: 18792
#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)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define bit(k) (1LL<<(k))
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int INF = 1e9;
const ll INFLL = 1e18;
const ll MOD = 1e9+7;
const double PI = acos(-1.0);

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

/*------------------------------------/
for library*/

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    double a,b,c,d,e,f;
    cin>>a>>b>>c>>d>>e>>f;
    a *= 100;
    b *= 100;
    int ans_all = 0;
    int ans_s = 0;
    double tmp = -1;
    for(int i = 0; i*a <= f; i++){
        for(int j = 0; i*a + j*b <= f;j++){
            int w = i*a + j*b;
            if(w == 0)continue;
            for(int k = 0;w + k*c <= f;k++){
                for(int l = 0; w + k*c + l*d <= f;l++){
                    int s = k*c + l*d;
                    if(s > (w / 100) * e)continue;
                    double noudo = 100*s/double(w + s);
                    if(tmp < noudo){
                        tmp = noudo;
                        ans_s = s;
                        ans_all = w + s;
                    }
                }
            }
        }
    }
    cout<<ans_all<<" "<<ans_s<<endl;
}



Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	/*/TODO:!!!!!!!テスト用!!!!!!!!!
	sc = bufio.NewScanner(strings.NewReader(`

										`))
	//TODO:!!!!!!!テスト用!!!!!!!!!*/

	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!caution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	//fmt.Fprintln(out, "[DEBUG]", time.Now())

	x := nextInt()
	y := nextInt()

	ans := "No"
	if y-2*x >= 0 && (y-2*x)%2 == 0 && 4*x-y >= 0 && (4*x-y)%2 == 0 {
		ans = "Yes"
	}

	//fmt.Fprintln(out, "[DEBUG]", a)
	fmt.Fprintln(out, ans)

}

//------------------------------------------------------------------------------

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

func printArray(a []int) {
	for i := 0; i < len(a); i++ {
		if i >= 1 {
			fmt.Fprint(out, " ")
		}
		fmt.Fprint(out, a[i])
	}
	fmt.Fprintln(out)
}

func absInt(x int) int {
	return int(math.Abs(float64(x)))
}
func minInt(x, y int) int {
	if x < y {
		return x
	}
	return y
}
func maxInt(x, y int) int {
	if x > y {
		return x
	}
	return y
}
func log10(x int) float64 {
	return math.Log10(float64(x))
}


Measured memory_bytes: 1796
s = input()
sl = len(s)
l = [0]*sl
c = 0
ans = 0

for i in range(sl):
    if s[i] == "A" or s[i] == "C" or s[i] == "G" or s[i] == "T":
        l[i] = 1

for i in range(sl):
    if l[i] == 1:
        c += 1
    else:
        ans = max(ans, c)
        c = 0

ans = max(ans, c)
print(ans)

Measured memory_bytes: 3064
#include    <iostream>

using namespace std;

int main() {
    int n, mn = 1000000, mx = -1000000;
    long long sum = 0;
    auto min = [](int a, int b) { return a<b ? a : b; };
    auto max = [](int a, int b) { return a>b ? a : b; };
    
    cin >> n;
    for(int i = 0; i < n; i++) {
        int buff;

        cin >> buff;
        mn = min(mn, buff);
        mx = max(mx, buff);
        sum += buff;
    }

    cout << mn << ' ' << mx << ' ' << sum << endl;

    return 0;
}


Measured memory_bytes: 3116
def main():

    N = int(input())
    A = list(map(int, input().split()))

    ans = []
    if min(A) >= 0:
        v = float('-inf')
        max_i = None
        for i in range(N):
            if A[i] > v:
                max_i = i
                v = A[i]

        ans.append([max_i, 0])
        for i in range(1, N):
            ans.append([i-1, i])
    elif max(A) <= 0:
        v = float('inf')
        min_i = None
        for i in range(N):
            if A[i] < v:
                min_i = i
                v = A[i]
        ans.append([min_i, N-1])
        for i in range(N-2, -1, -1):
            ans.append([i+1, i])
    elif abs(max(A)) >= abs(min(A)):
        v = float('-inf')
        max_i = None
        for i in range(N):
            if A[i] > v:
                max_i = i
                v = A[i]
        for i in range(N):
            if i != max_i:
                ans.append([max_i, i])
        ans.append([max_i, max_i])
        ans.append([max_i, 0])
        for i in range(1, N):
            ans.append([i-1, i])
    else:
        v = float('inf')
        min_i = None
        for i in range(N):
            if A[i] < v:
                min_i = i
                v = A[i]
        for i in range(N):
            if i != min_i:
                ans.append([min_i, i])
        ans.append([min_i, min_i])
        ans.append([min_i, N-1])
        for i in range(N-2, -1, -1):
            ans.append([i+1, i])

    print(len(ans))
    for i, j in ans:
        print(str(i+1) + " " + str(j+1))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3192
package main

import "fmt"

func main() {
	var k int
	fmt.Scan(&k)

	arr := [...]int{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5,
		1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}

	fmt.Println(arr[k-1])
}

Measured memory_bytes: 512
N, Y = map(int, input().split())
for i in range(N+1):
    for j in range(N+1):
        if i + j > N:
            break
        k = N - i - j
        if i * 10000 + j * 5000 + k * 1000 == Y:
            print(i, j, k)
            import sys
            sys.exit()
print(-1, -1, -1)


Measured memory_bytes: 2940
using System;
using System.IO;
using System.Linq;

class Program{
    static void Main(string[] args)
    {
        var HW = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
        long answer = HW[0] == 1 || HW[1] == 1 ? 1 : (HW[0] * HW[1] + 1) / 2;
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();}}

Measured memory_bytes: 27520
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int a, b;
    cin >> a >> b;
    string as = "", bs = "";
    rep(i, b) { as += (char)(a + '0'); }
    rep(i, a) { bs += (char)(b + '0'); }
    if(as > bs) {
        cout << bs << endl;
    } else {
        cout << as << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll N;
    cin >> N;

    vector<ll> A(N);
    FOR(i, 0, N){
        cin >> A.at(i);
    }

    ll pair_num = 0;
    FOR(i, 0, N){
        ll love = A[i];
        if(A[love-1]==i+1){
            pair_num++;
        }
    }
    p(pair_num/2);
    
    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i = 0;i < n; i++)
#define REP(i,n) for(int i = 1;i <= n; i++)
// ----GCC ONLY---- //
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// ----        ---- //
#define ll long long
#define MOD 10000007
#define PB push_back
 
using namespace std;

int main(){

    int a[32] ={ 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;

    cin >> k;


    cout << a[k - 1] <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;
struct edge {int to,costa,costb;};

signed main() {
int n;
cin>>n;
vector<int> p;
if(n==1){
    cout<<0;return 0;
}
for(int i=2;i<=n;i++){
    p.push_back(i);
    for(int j=2;j<i;j++){
        if(i%j==0){
            p.pop_back();
            break;
        }
    }
}
//cerr<<p.size();
int a[p.size()]={};
for(int i=0;i<p.size();i++)a[i]=0;
int m;
for(int i=0;i<p.size();i++){
    m=n;
    while(m){
        a[i]+=m/p[i];
        m/=p[i];
        //cerr<<a[i]<<endl;
    }
}
int x[5]={};
for(int i=0;i<p.size();i++){
    if(a[i]+1>=3)x[0]++;
    if(a[i]+1>=5)x[1]++;
    if(a[i]+1>=15)x[2]++;
    if(a[i]+1>=25)x[3]++;
    if(a[i]+1>=75)x[4]++;
    
}
//for(int i=0;i<4;i++)cerr<<a[i]<<endl;
cout<<x[1]*(x[1]-1)*(x[0]-2)/2+x[2]*(x[1]-1)+x[3]*(x[0]-1)+x[4];
return 0;
}


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

// Loops
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define _rrep(i, n) rrepi(i, n, 0)
#define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)

#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(xi, x) for (auto &&xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)

// typedef
template <class T> using vec = vector<T>;
using ll = long long;
using vi = vec<ll>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<ll, ll>;

// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define mp make_pair

// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase(unique(all(v)), v.end())
#define perm(c)                                                                \
  sort(all(c));                                                                \
  for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))

template <class T> pair<T, size_t> max(vector<T> &x) {
  auto it = max_element(all(x));
  return mp(*it, it - x.begin());
}
template <class T> pair<T, size_t> min(vector<T> &x) {
  auto it = min_element(all(x));
  return mp(*it, it - x.begin());
}

template <class T> inline bool chmax(T &maxval, const T &newval) {
  if (maxval < newval) {
    maxval = newval;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &minval, const T &newval) {
  if (minval > newval) {
    minval = newval;
    return 1;
  }
  return 0;
}

// Utilities
// Grid world utilities
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
#define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H)

// Debug
#ifdef LOCAL
#include "dump.hpp"
#define debug(x) cerr << #x << ": " << x << '\n'
#else
#define dump(...)
#define debug(x)
#endif

// Yes or No
void yesno(bool ok, string yes = "Yes", string no = "No") {
  cout << (ok ? yes : no) << endl;
}


void solve(long long N) {
  ll ret = 0;
  rep(i,1,N+1){
    ret += i*(N/i)*(N/i+1)/2;
  }
  cout << ret << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); // Magic for faster cin
  cout.precision(12);
  long long N;
  std::cin >> N;
  solve(N);
  return 0;
}


Measured memory_bytes: 3624
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define st first
#define nd second

using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set =
	tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
#define shandom_ruffle random_shuffle
 
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;

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

	vll nums(n);
	for (auto &x : nums) { cin >> x; }

	string order;
	cin >> order;

	const int B = 61;
	vll basis(B);

	for (int i = n - 1; i >= 0; --i) {
		ll x = nums[i];
		for (int bit = B - 1; bit >= 0; --bit) {
			if (((x >> bit) & 1) && basis[bit]) {
				x ^= basis[bit];
			}
		}
		if (!x) { continue; }
		if (order[i] == '1') {
			return 1;
		}
		for (int bit = B - 1; bit >= 0; --bit) {
			if ((x >> bit) & 1) {
				basis[bit] = x;
				break;
			} 
		}
	}

	return 0;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(11);
	cerr << fixed << setprecision(6);

	int t
	;cin >> t;
	while (t--) cout << Test() << "\n";
}


Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <array>
#include <utility>
#include <queue>
#include <tuple>
#include <map>
#include <cmath>
using namespace std;
using ll = long long;
using VI = vector<int>;

constexpr ll INF = 1000000007;

int main() {
    int k;
    cin >> k;
    int a, b;
    cin >> a >> b;
    bool ans = false;
    for (int i = a; i <= b; i++) {
        if (i % k == 0) { ans = true; break; }
    }
    if (ans) cout << "OK\n";
    else cout << "NG\n";
    return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


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

  ll a,b;
  cin >> a >> b;
  if((b-1)%(a-1) == 0)
    cout << (b-1)/(a-1) << endl;
  else
    cout << (b-1)/(a-1)+1 << endl;

}


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

int main()
{
  int n;
  cin >> n;
  int ans=0;
  for(;n>0;--n){
    if((0<n&&n<10)||(100<=n&&n<1000)||(10000<=n&&n<100000)){
      ++ans;
    }
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k, tmp int
	fmt.Scan(&n, &k)

	min := 0
	counts := make([]int, 200000)

	for i := 0; i < n; i++ {
		fmt.Scan(&tmp)
		counts[tmp]++

		if tmp < min {
			min = tmp
		}
	}

	counts = counts[min:]
	sort.Ints(counts)

	count := 0
	for _, v := range counts[:len(counts)-k] {
		count += v
	}

	fmt.Println(count)
}


Measured memory_bytes: 7264
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */
//codeforces
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define mp make_pair
#define pb push_back
#define sz(v) ((int)v.size())
#define all(v) v.begin(), v.end()
void parseArray(ll* A,ll n){ for ( ll K = 0; K < n; K++){ cin >> A[K]; } }
ll modInverse(ll a, ll b){ return 1<a ? b - modInverse(b%a, a)*b/a : 1; }
ll gcd(ll a, ll b){ return b?gcd(b, a % b):a; }
ll lcm(ll a, ll b){ return (a*b)/gcd(a, b); }
ld dist(ld x, ld y, ld a, ld b){ return sqrt((x-a)*(x-a) + (y-b)*(y-b)); }
void debug(ll* a, ll n) { for ( ll k = 0; k < n; k++ ){ cerr << a[k] << " ";} cerr << "\n"; }
#define PI 3.14159265358979323846

int main(){
	FASTIO;
	ll x, y, n, m, p; cin >> x >> y >> n >> m >> p;
	ll a[n]; parseArray(a, n);
	ll b[m]; parseArray(b, m);
	ll c[p]; parseArray(c, p);
	sort(a, a + n); reverse(a, a + n);
	sort(b, b + m); reverse(b, b + m);
	sort(c, c + p); reverse(c, c + p);
	ll ans = 0;
	priority_queue<ll> pq;
	for ( int k = 0; k < x; k++ )
		pq.push(-a[k]), ans += a[k];
	for ( int k = 0; k < y; k++ )
		pq.push(-b[k]), ans += b[k];
	for ( int k = 0; k < p; k++ ){
		if (c[k] > -pq.top()) {
			ans -= -pq.top();
			pq.pop();
			pq.push(-c[k]);
			ans += c[k];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4852
#include <bits/stdc++.h>
#define endl '\n'
#define x first
#define y second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define ll long long
#define ld long double
using namespace std;

int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll a, b;
  cin>>a>>b;
  if(a<=9 && b<=9){
      cout<<a*b<<endl;
  }else{
      cout<<-1<<endl;
  }
  
}

Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>

////多倍長整数, cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;

//#pragma GCC target ("avx2")
//#pragma GCC optimization ("Ofast")
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define repeat(i, n, m) for(int i = n; i < (m); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

using ll = long long;
using ull = unsigned long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr ll mod = 998244353;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}


double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

template<typename T>
inline T chmin(T& a, const T& b) {
	if (a > b)a = b;
	return a;
}

template<typename T>
inline T chmax(T& a, const T& b) {
	if (a < b)a = b;
	return a;
}

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	cpp_int a;
	cin >> a;
	printyn(not (a % 9));

	Please AC;
}


Measured memory_bytes: 3856
s = input()
cnt = len(s)
R = s[1::2]
L = s[::2]

cntL = L.count("0")
cntR = R.count("0")

paintL0 = 0 - -cnt//2 - cntL
paintR0 = cnt//2 - cntR

paintLR0 = paintL0 + cntR
paintLR1 = cntL + paintR0

print(min(paintLR0, paintLR1))

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

int main(int argc, char const *argv[]) {
  stack<int> S;
  for (string s; cin >> s;) {
    if (s == "+" || s == "-" || s == "*" || s == "/") {
      int b = S.top();
      S.pop();
      int a = S.top();
      S.pop();
      int ans;
      switch (s[0]) {
      case '+':
        ans = a + b;
        break;
      case '-':
        ans = a - b;
        break;
      case '*':
        ans = a * b;
        break;
      case '/':
        ans = a / b;
        break;
      }
      S.push(ans);
    } else {
      istringstream iss(s);
      int c;
      iss >> c;
      S.push(c);
    }
  }
  cout << S.top() << endl;
  return 0;
}



Measured memory_bytes: 3180
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;

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

        String[] s = new String[3];
        for (int i = 0; i < s.length; ++i) {
            s[i] = sc.next();
        }

        System.out.println(solve(s));

        sc.close();
    }

    static String solve(String[] s) {
        return Arrays.stream(s).map(si -> String.valueOf(Character.toUpperCase(si.charAt(0))))
                .collect(Collectors.joining());
    }
}

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

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

  if (A >= 500) {
    cout << "Yes" << endl;
  }
  else if ( A >= N%500 ) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


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

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


int main2() {
  int K; cin >> K;
  string S; cin >> S;

  if ((int)S.size() <= K) {
    cout << S << endl;
  } else {
    cout << S.substr(0, K) << "..." << endl;
  }
  return 0;
}

int main() {

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

Measured memory_bytes: 3616
#include <stdio.h>
#include <ctype.h>
#include <string.h>

int main(){
	char serch[21], word[21];
	int i, count = 0;
	
	scanf("%s", serch);
	
	while(1){
		scanf("%s", word);
		if(strcmp(word, "END_OF_TEXT") == 0){
			break;
		}
		
		for(i=0; word[i]!='\0'; i++){
			word[i] = tolower(word[i]);
		}
		
		if(strcmp(word, serch) == 0){
			count++;
		}
	}
	
	printf("%d\n", count);
	
    return 0;
}

Measured memory_bytes: 548
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define x first
#define y second
using namespace std;
using ll = long long;
using ld = long double;

int main() {
#ifdef LC
    assert(freopen("input.txt", "r", stdin));
#endif
    ios::sync_with_stdio(0), cin.tie(0);

	string s, t;
	ll a, b;
	cin >> s >> t >> a >> b;
	string x;
	cin >> x;
	a -= s == x;
	b -= t == x;
	cout << a << " " << b << endl;
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func round(f float64) float64 {
	return math.Floor(f + .5)
}

func main() {
	var N int
	fmt.Scan(&N)

	X := make([]int, N)
	sum := 0
	for i, _ := range X {
		fmt.Scan(&X[i])
		sum += X[i]
	}
  avg := int(round(float64(sum) / float64(N)))

	result := 0
	for _, x := range X {
		result += (x - avg) * (x - avg)
	}

	fmt.Println(result)
}


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

using namespace std;
typedef long long LL;
const LL mod = 1e9 + 7;
string s;
LL a[30],res = 0;
int vis[30];
void dfs(int pos,int len,LL val)
{
    if(!len){
        res = (res + val) % mod;
        return ;
    }
    for(int i = pos;i <= 26 - len; ++i){
        if(!a[i]) continue;
        dfs(i+1,len-1,val*a[i]%mod);
    }
    return ;
}
int main()
{
    int n,k = 0;
    cin>>n>>s;
    for(int i = 0;i < n; ++i){
        int t = s[i] - 'a';
        if(!a[t]) k++;
        a[t]++;
    }
    for(int i = 1;i <= k; ++i)
        dfs(0,i,1);
    cout<<res;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>


using namespace std;
using namespace __gnu_pbds;


#define INF (1<<30)
#define INFll (1ll<<62)
#define F first
#define S second
#define MOD 1000000007
#define mkp(a, b) make_pair(a, b)


typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;


#define FOR(I, A, B) for(int (I) = (A); (I) < (B); (I)++)
#define ROF(I, A, B) for(int (I) = (A); (I) >= (B); (I)--)
#define SQR(A) 1ll*(A)*(A)


typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


const char array_sep[] = " ";
const char array_end[] = "";


const char pair_sep[] = " ";
const char pair_end[] = "";


const char map_sep[] = "->";
const char map_end[] = "\n";


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


template<typename A> ostream & operator<<(ostream & os, const vector<A> & x)
{
    for(int i = 0; i < x.size(); i++)
      os << x[i] << array_sep;
    os << array_end;
    return os;
}


template<typename A, typename B> ostream & operator<<(ostream & os, const pair<A, B> & x)
{
    os << x.first << pair_sep << x.second << pair_end;
    return os;
}


template<typename A> istream & operator>>(istream & is, vector<A> & x)
{
    for(int i = 0; i < x.size(); i++)
        is >> x[i];
    return is;
}


template<typename A, typename B> istream & operator>>(istream & is, pair<A, B> & x)
{
    is >> x.first >> x.second;
    return is;
}


template<typename _key, typename _val> ostream & operator<<(ostream & os, map<_key, _val> & mp)
{
    for(auto it : mp)   // not for C++98 or earlier
        os << it->F << map_sep << it->S << map_end;
    return os;
}


template<typename _response> void die(_response ans)
{
	cout << ans << endl;
	exit(0);
}

//typedef pair<pair<int, int >, int > query;

vector<int> a;
int ans = INF;
int n;


int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//	freopen("errlog.log", "w", stderr);
	ios_base::sync_with_stdio(0);
//	cout << fixed << setprecision(10);
//	srand(time(0));
    cin >> n;
    a.resize(n);
    cin >> a;
    for(int i = -100; i <= 100; i++)
    {
        int cur = 0;
        for(int j = 0; j < n; j++)
            cur += SQR(i - a[j]);
        ans = min(ans, cur);
    }
    cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.string;
import std.conv;
import std.range;

void main(){

    int[] primes = [2,3,5];
    for(int i=7;i<60000;i++){
	bool flg = true;
	for(int j=0;primes[j]*primes[j]<=i;j++){
	    if(i % primes[j] == 0){
		flg = false;
		break;
	    }
	}
	if(flg) primes ~= i;
    }
    while(true){
	auto s = readln();
	if(stdin.eof()) break;
	int n = to!int(chomp(s));
	auto a = assumeSorted(primes);
	auto p = a.lowerBound(n);
	if(primes[p.length-1] == n) writef("%d %d\n",primes[p.length-1],primes[p.length+1]);
	else{
	    auto p1 = a.upperBound(n);
	    writef("%d %d\n",primes[p.length-1],p1[0]);
	}
    }
}

Measured memory_bytes: 2440
n,m=map(int, input().split())
a=[False]*(n+1)
for i in range(m):
    A=int(input())
    a[A]=True
mod=10**9+7
dp=[0]*(n+1)

if not a[1]:
    dp[1]=1

if n>1:
    if not a[2]:
        dp[2]=dp[1]+1

for i in range(3,n+1):
    if not a[i-2]:
        dp[i]+=dp[i-2]
        dp[i]%=mod
    if not a[i-1]:
        dp[i]+=dp[i-1]
        dp[i]%=mod
    if a[i]:
        dp[i]=0

print(dp[n]%mod)

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

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

	vector<vector<int>> x(n, vector<int>(d));
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < d; j++)
		{
			cin >> x.at(i).at(j);
		}
	}

	int count = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			int delta = 0;
			for (int k = 0; k < d; k++)
			{
				delta += (x.at(j).at(k) - x.at(i).at(k)) * (x.at(j).at(k) - x.at(i).at(k));
			}

			for (int k = 1; k <= delta; k++)
			{
				if (k * k == delta)
				{
					count++;
					break;
				}
			}
		}
	}

	cout << count << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int big,mid,sml;
    big=max(max(a,b),c);
    sml=min(min(a,b),c);
    mid=a+b+c-big-sml;
    cout<<sml<<" "<<mid<<" "<<big<<endl;
}


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

int main()
{
    string S,T;
    cin>>S>>T;
    const int LETTER=26;
    vector<vector<long long int>>location(LETTER);
    for(int i=0;i<S.length();i++)
    {
        location[S[i]-'a'].push_back(i);
    }
    long long int cnt=1 , last_loc=-1;
    for(int i=0;i<T.length();i++)
    {
        if(location[T[i]-'a'].size()==0)
        {
            cout<<"-1";
            return 0;
        }
        auto itr=upper_bound(location[T[i]-'a'].begin(),location[T[i]-'a'].end(),last_loc);
        if(itr==location[T[i]-'a'].end())
        {
            cnt++;
            last_loc=location[T[i]-'a'][0];
        }
        else
        {
            last_loc=*itr;
        }
    }
    long long total_length=(cnt-1)*(S.length()*1LL)+(last_loc+1);
    cout<<total_length<<endl;
    return 0;
}





Measured memory_bytes: 1724
n = int(input())
a = sorted(list(map(int,input().split())),reverse=True)
alice = 0
bob = 0

while True:
  alice += a[0]
  del a[0]
  if a == []:
    break
  bob += a[0]
  del a[0]
  if a == []:
    break

print(alice - bob)

Measured memory_bytes: 9180
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
#define debug(...) cout << "[" << #__VA_ARGS__ << ": " << __VA_ARGS__ << "]\n"
#define rd() abs((int)rng())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn = 2e3 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int n;
bitset<maxn>dpl[maxn], dpr[maxn], wins[maxn];
int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	for(int i = 2; i <= n; i++)
	{
		string s;
		cin >> s;
		for(int j = 1; j <= sz(s); j++)
		{
			if(s[j - 1] == '0')
			{
				wins[i][j] = 0;
				wins[j][i] = 1;
			}
			else
			{
				wins[i][j] = 1;
				wins[j][i] = 0;
			}
		}
	}
	for(int i = 1; i <= n; i++)
		dpl[i][i] = dpr[i][i] = 1;
	for(int len = 2; len <= n; len++)
	{
		for(int i = len; i <= n; i++)
		{
			if((dpr[i - 1] & dpl[i - len + 1] & wins[i]).any())
				dpl[i - len + 1][i] = 1;
		}
		for(int i = n - len + 1; i >= 1; i--)
		{
			if((dpl[i + 1] & dpr[i + len - 1] & wins[i]).any())
				dpr[i + len - 1][i] = 1;
		}
	}
	int ans = 0;
	for(int i = 1; i <= n; i++)
		if(dpl[1][i] && dpr[n][i])
			++ans;
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef pair<ll, ll> P;

int main(){
    ll n, sum=0;
    cin >> n;
    vec v(n); 
        for(int i=0; i<n; i++){
            cin >>  v.at(i);
            sum += v.at(i);
        }
    ll tmp=0, mini=sum;
        for(int i=0; i<n; i++){
            tmp += v.at(i);
            sum -= v.at(i);
            mini = min(abs(tmp-sum), mini);
        }

    cout << mini << endl;


    
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String inputStr = sc.next();
        int input = Integer.parseInt(inputStr);
        
        int oddCount = input % 2 == 0 ? input / 2 : (input / 2) + 1;
        String oddCountStr = Integer.toString(oddCount);
        
        double rate = (Double.parseDouble(oddCountStr) / Double.parseDouble(inputStr));

        System.out.println(rate);
    }
}

Measured memory_bytes: 21844