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

using namespace std;

int main() {
    int n;

    cin >> n;
    vector<int> vec(n);

    for (int i = 0; i < n - 1; ++i) {
        int index;
        cin >> index;
        vec[index - 1] += 1;
    }

    for (int i = 0; i < n; ++i) {
        cout << vec[i] << endl; 
    }
}

Measured memory_bytes: 4052
n = int(input())
a = [int(i) for i in input().split()]

i = 0
person = []
for j in range(n):
    person.append(0)
ans = []
for k in a:
    i += 1
    person[k-1] = i

a.sort()
for l in a:
    ans.append(str(person[l-1]))

order = ' '.join(ans)
print(order)


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

int main()
{
    vector<vector<int>> a(3, vector<int>(3));
    for (auto &&i : a)
    {
        for (auto &&j : i)
        {
            cin >> j;
        }
    }
    int n;
    cin >> n;
    vector<int> b(n);
    for (auto &&i : b)
    {
        cin >> i;
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            for (int k = 0; k < 3; k++)
            {
                if (a.at(j).at(k) == b.at(i))
                {
                    a.at(j).at(k) = -1;
                }
            }
        }
    }
    bool flag = false;
    for (int i = 0; i < 3; i++)
    {
        if (a.at(i).at(1-1) == a.at(i).at(2-1) 
        && a.at(i).at(2-1) == a.at(i).at(3-1) 
        && a.at(i).at(3-1) == a.at(i).at(1-1))
        {
            flag = true;
        }
        if (a.at(1-1).at(i) == a.at(2-1).at(i) 
        && a.at(2-1).at(i) == a.at(3-1).at(i) 
        && a.at(3-1).at(i) == a.at(1-1).at(i))
        {
            flag = true;
        }
    }
    if (a.at(1-1).at(1-1) == a.at(2-1).at(2-1) 
    && a.at(2-1).at(2-1) == a.at(3-1).at(3-1) 
    && a.at(3-1).at(3-1) == a.at(1-1).at(1-1))
    {
        flag = true;
    }
    if (a.at(1-1).at(3-1) == a.at(2-1).at(2-1) 
    && a.at(2-1).at(2-1) == a.at(3-1).at(1-1) 
    && a.at(3-1).at(1-1) == a.at(1-1).at(3-1))
    {
        flag = true;
    }
    if (flag == true)
    {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  int N, K;
  scanf("%d %d", &N, &K);
  printf(N % K == 0 ? "0\n" : "1\n");
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int n,m=0,p=1,f=1;
int a[205];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	while (f){
		m++;p*=2;
		for(int i=1;i<=n and f;i++)
			if(a[i]%p!=0)f=0;
	}
	cout<<m-1<<endl;
	
}

Measured memory_bytes: 256
N, M = map(int, input().split())
H = list(map(int, input().split()))
ans = [1] * N
for i in range(M):
  A,B = map(int, input().split())
  A-=1
  B-=1
  if H[A] < H[B]:
    ans[A] *= 0
  elif H[A] > H[B]:
    ans[B] *= 0
  else:
    ans[A] *= 0
    ans[B] *= 0
print(sum(ans))

Measured memory_bytes: 20116
#include <iostream>
#include <algorithm>
using namespace std;
long long n,ans,p;
int main(void){
    scanf("%lld",&n);
    for(int i=0;i<n;i++){
        int a;
        scanf("%d",&a);
        ans+=(a+p)/2;
        if(a!=0&&(a+p)%2)p=1;
        else p=0;
        
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define Return(ans) { cout << (ans) << endl; return 0; }
#define pb push_back
#define fi first
#define se second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using v_bool = vector<bool>;
using v_Pii = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;



signed main(){

    int N; cin >> N;
    vec A(N); cin >> A;

    REP(i, N) if(A[i] == 0){
        Out(0);
        return 0;
    }

    double S = 0.0;
    REP(i, N) S += log(A[i]);
    if(S > log(5.0e18)){
        Out(-1);
        return 0;
    }

    int ans = 1;
    REP(i, N) ans *= A[i];
    Ans(ans <= INF, ans, -1);

    return 0;
}


Measured memory_bytes: 3992
fn main() {
    let n = readln();
    let a: Vec<usize> = readln();
    let l = (1<<n) as usize;
    let mut dp = vec![Vec::new(); l];
    for s in 0..l {
        dp[s].push((a[s], s));
    }
    for s in 0..l {
        for i in 0..n {
            if (s >> i & 1) == 1 {
                let ns = s ^ (1<<i);
                let values: Vec<(usize, usize)> = dp[ns].iter().cloned().collect();
                for value in values {
                    dp[s].push(value);
                }
            }
        }
        let sets: HashSet<_> = dp[s].iter().cloned().collect();
        let mut vals: Vec<_> = sets.iter().cloned().collect();
        vals.sort();
        vals.reverse();
        let p = min(2, vals.len());
        dp[s] = vals[0..p].iter().cloned().collect();
    }
    let mut cur = 0;
    for s in 1..l {
        let mut iter = dp[s].iter();
        let a = (*iter.next().unwrap()).0;
        let b = (*iter.next().unwrap()).0;
        cur = max(cur, a + b);
        println!("{}", cur);
    }
}


#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque, BinaryHeap};

pub trait FromLn {
    fn fromln(s: &str) -> Self;
}
pub fn readln<T: FromLn>() -> T {
    let mut buf = String::new();
    let _ = ::std::io::stdin().read_line(&mut buf).unwrap();
    T::fromln(buf.trim())
}
pub fn readlns<T: FromLn>(n: usize) -> Vec<T> {
    let mut vs = vec![];
    for _ in 0..n {
        vs.push(readln());
    }
    vs
}
macro_rules! fromln_primitives {
    ($($t:ty),*) => { $(
        impl FromLn for $t {
            fn fromln(s: &str) -> $t {
                s.parse().unwrap()
            }
        }
    )* }
}
fromln_primitives!(
    String,
    bool,
    f32,
    f64,
    isize,
    i8,
    i16,
    i32,
    i64,
    usize,
    u8,
    u16,
    u32,
    u64
);
impl<T> FromLn for Vec<T>
where
    T: FromLn,
{
    fn fromln(s: &str) -> Vec<T> {
        s.split_whitespace().map(T::fromln).collect()
    }
}
impl FromLn for Vec<char> {
    fn fromln(s: &str) -> Vec<char> {
        s.chars().collect()
    }
}
macro_rules! fromln_tuple {
    ($($t:ident),*) => {
        impl<$($t),*> FromLn for ($($t),*) where $($t: FromLn),* {
            fn fromln(s: &str) -> ($($t),*) {
                let mut it = s.split_whitespace();
                let t = ($($t::fromln(it.next().unwrap())),*);
                assert_eq!(it.next(), None);
                t
            }
        }
    }
}
fromln_tuple!(A, B);
fromln_tuple!(A, B, C);
fromln_tuple!(A, B, C, D);
fromln_tuple!(A, B, C, D, E);
fromln_tuple!(A, B, C, D, E, F);


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

using namespace std;

int main()
{
   int r, g, b;
   cin>>r>>g>>b;
   int x = (r*100)+(g*10)+b;
   if(x%4==0)
   {
       cout<<"YES"<<endl;
   }
   else
   {
       cout<<"NO"<<endl;
   }
   return 0;
}


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

const int N = 500009;

long long a[N] = {};
string st;

int main() {
    cin >> st;
    int n = st.length();
    a[0] = 0;
    for (int i = 0, j = 1; i < n; i++, j++) {
        if (st[i] == '<') {
            a[j] = a[j - 1] + 1;
        }
        else {
            a[j] = a[j - 1] - 1;
        }

        if (i > 0 && st[i] != st[i - 1] && a[j - 1] != 0) {
            a[j] = 0;
        }
    }

    for (int i = 1; i <= n; i++) {
        if (a[i] < 0 && a[i - 1] > a[i] && a[i] < a[i + 1]) {
            int offset_left = -a[i];
            int offset_right = 0;
            int left_limit = i;
            int right_limit = i;

            for (int j = i - 1; j >= 0 && st[j] == '>' && a[j] <= a[j + 1] + offset_left; j--) {
                left_limit--;
            }

            if (a[i] + offset_left >= a[i + 1]) {
                offset_right = (a[i] + offset_left) - a[i + 1] + 1;
                for (int j = i + 1; j <= n && st[j - 1] == '<'; j++) {
                    right_limit++;
                }
            }

            for (int j = i; j >= left_limit; j--) {
                a[j] += min((long long) offset_left, a[j + 1] + 1 - a[j]);
            }

            for (int j = i + 1; j <= right_limit; j++) {
                a[j] +=  offset_right;
            }

            i = right_limit;
        }
    }

    long long ans = 0;
    for (int i = 0; i <= n; i++) {
        ans += a[i];
    }

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


Measured memory_bytes: 4740
/**
*    created: 12.05.2020 09:39:04
**/

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int inf =1000000000;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    //aの要素で奇数個おなじものがあるものの個数
    sort(a.begin(), a.end());
    int ans = 0,f=0;

    rep(i,n){
        if(i==0)
        {
            ans++;
            continue;
        }
        
        if(a[i]==a[i-1]){
            if(f==0){
                ans--;
                f = 1;
            }else{
                ans++;
                f = 0;
            }
        }else{
            ans++;
            f = 0;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1152
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <vector>
using namespace std;

#define bll long long
#define dou double
#define For(i,a,b) for (int i=(a),_##i=(b); i<=_##i; ++i)
#define Rof(i,a,b) for (int i=(a),_##i=(b); i>=_##i; --i)
#define Mem(a,b) memset(a,b,sizeof(a))
#define Cpy(a,b) memcpy(a,b,sizeof(b))

const int maxn=1e5+100;
int N,M,u[maxn],link[maxn];
int dlt[maxn];

int get_u(int x,int &ret)
{
    if (x==u[x]) return x;
    u[x]=get_u(u[x],ret);
    ret+=dlt[x];
    dlt[x]=ret;
    return u[x];
}

bool check(int x,int y,int d)
{
    int rx=0,ry=0;
    int a=get_u(x,rx),b=get_u(y,ry);
    if (a==b) return (dlt[y]-dlt[x]==d);
    if (link[a]<link[b]) swap(a,b),swap(x,y),d=-d;
    u[b]=a;
    link[a]+=(link[a]==link[b]);
    dlt[b]=dlt[x]-dlt[y]+d;
    return 1;
}

int main()
{
    for (; scanf("%d%d",&N,&M)!=EOF; )
    {
        bool flag=1;
        For(i,1,N) u[i]=i,link[i]=0,dlt[i]=0;
        For(i,1,M)
        {
            int x,y,d;
            scanf("%d%d%d",&x,&y,&d);
            if (flag) flag=check(x,y,d);
        }
        if (flag)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 1536
import java.util.*;

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

        long count = 0;
        long value = 100;
        while (true)
        {
            value *= 1.01;
            //System.out.println(value);
            ++count;
            if (value >= x) break;
        }
        System.out.println(count);
        sc.close();
    }
}

Measured memory_bytes: 35772
#include <bits/stdc++.h>
using namespace std;
const int N=100010;
int n,m,it,cur,ans,kq;
int dd[N],x[N],f[N];
vector<int> ad[N];
void dfs(int u)
{
    dd[u]=1;
    for(auto v:ad[u]) if(!dd[v]) dfs(v);
    x[--it]=u;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("lp.inp","r",stdin);
    cin>>n>>m;
    for(int i=1;i<=m;++i)
    {
        int u,v;cin>>u>>v;
        ad[u].push_back(v);
    }
    it=n+1;
    for(int i=1;i<=n;++i) if(!dd[i]) dfs(i);
    for(int i=1;i<=n;++i)
    {
        int u=x[i];
        for(auto v:ad[u]) f[v]=max(f[v],f[u]+1);
    }
    cout<<*max_element(f+1,f+n+1);

}


Measured memory_bytes: 8320
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var nums = cin.ReadIntArray(3);
            var ans = nums.Sum() >= 22 ? "bust" : "win";
            Console.WriteLine(ans);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}


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

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(){
  ll n;
  cin >> n;
  ll ans = n%1000;
  if(ans == 0){
    cout << 0 << endl;
  }else{
    cout << 1000 -  ans << endl;
  }

  return 0;
} 



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

int main() {
  int A,B;
  cin >> A >> B;
  int C = 0;
  
  for (int i = A; i <= B; i++) {
    if(i%100000/10000==i%10 && i%10000/1000==i%100/10) {
      C++;
    }
  }
  cout << C << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{   int A,B,C;
    cin >> A >> B >> C;
    if((A==B && B!=C) || (B==C && A!=C) || (A==C && B!=C))
    cout<< "Yes" << endl;
    else
    cout<< "No" ;
 
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
int a,b,k,n,ans;

scanf("%d",&a); scanf("%d",&b);
if(a>b){
k=a; a=b; b=k;}

n=b%a;
while(n!=0){
b=a; a=n; n=b%a;
}

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

return 0;
}



Measured memory_bytes: 2064
import java.util.*;

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

		String s=sc.next();
		if(s.matches("A[a-z]{1}[a-z]*C[a-z]*[a-z]{1}")){
			System.out.println("AC");
		}else{
			System.out.println("WA");
		}


	}
}


Measured memory_bytes: 21332
import java.util.*;
 
public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
 

        
        String s = stdIn.next();
        char c[] = s.toCharArray();
        //int c = stdIn.nextInt();
        //int x = stdIn.nextInt();
        //boolean flag = true;
        
        // for(int i = 0; i < s.length(); i++){
        //     a[i] = c[i] - 48;
        //     System.out.println(a[i]);
        // }
        //int sum = 0;
        //boolean flag = true;
        //for(int i = 0; i < s.length(); i++){
        //}
        
        if(c[2] == c[3] && c[4] == c[5]){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
 
        //System.out.println();
        //System.out.print();
 
        stdIn.close();
    }
}


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

int main() {
	// 코틀린 ,문자열 알고리즘 보기, 앳코더, (시간되면 코드포스까지)
	ios_base::sync_with_stdio(false); cin.tie(NULL); //9 90 900 
	int a[3];
	for (int i = 0; i < 3; i++)cin >> a[i];
	sort(a, a + 3);
	if (a[0] == 5 && a[1] == 5 && a[2] == 7) {
		cout << "YES" << '\n';
	}
	else {
		cout << "NO" << '\n';
	}





}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
def input():
    return sys.stdin.readline()[:-1]

def main():
    N = int(input())
    a = list(map(int, input().split()))

    ans = 0
    for i in range(N):
        while a[i] % 2 == 0:
            a[i] = a[i] // 2
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 70376
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef complex<double> xy_t;

lint powmod(lint x, lint n, lint mod){
  lint ret = 1;
  while(n > 0){
    if(n&1) ret *= x, ret %= mod, n -= 1;
    else x *= x, x %= mod, n >>= 1;
  }
  return ret;
}

int n;
string s;

lint b[3] = {1009, 1007, 997};
lint h[3] = {1000000007, 1000000009, 998244353};

bool check(int len){
    lint rh[3][n-len+1];
    lint t[3];
    
    rep(i, 3) t[i] = 0;
    rep(i, len)rep(j, 3) t[j] = (t[j]*b[j] + (s[i]-'a')) % h[j];
    rep(i, 3) rh[i][0] = t[i];
    
    lint p[3];
    rep(i, 3) p[i] = powmod(b[i], len, h[i]);
    
    rep(i, n-len)rep(j, 3){
        t[j] = (t[j]*b[j] - p[j]*(s[i]-'a') % h[j] + (s[i+len]-'a') + h[j]) % h[j];
        rh[j][i+1] = t[j];
    }
    
    rep(i, n-len+1){
        for(int j=i+len; j+len-1<n; ++j){
            bool flag = true;
            rep(k, 3){
                if(rh[k][i] != rh[k][j]){
                    flag = false;
                    break;
                }
            }
            if(flag) return true;
        }
    }
    
    return false;
}

int main(){
    cin >> n >> s;
    
    bool flag = false;
    rep(i, n)For(j, i+1, n){
        if(s[i] == s[j]){
            flag = true;
            break;
        }
    }
    if(!flag){
        printf("0\n");
        return 0;
    }
    
    int low = 0;
    int high = n/2 + 1;
    while(high - low > 1){
        int mid = (high + low) / 2;
        if(check(mid)) low = mid;
        else high = mid;
    }
    
    printf("%d\n", low);
}

Measured memory_bytes: 512
import sys
input=sys.stdin.readline
k=int(input())
ans=0
import math
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            d=math.gcd(a,b)
            e=math.gcd(c,d)
            ans+=e
print(ans)




Measured memory_bytes: 67712
n=int(input())
v=[int(i) for i in input().split()]
v=sorted(v)

for i in range(n-2):
    check=0
    check=(v[0]+v[1])/2
    v.pop(0)
    v.pop(0)

    v.append(check)
    v=sorted(v)
ans=(v[0]+v[1])/2
print(ans)

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

int main() {
    
    int a,b,c;
    
    cin >> a >> b >> c;
    
    map<int,int> m;
    
    m[a]++;
    m[b]++;
    m[c]++;
    
    if(m[5] == 2 && m[7] == 1){
        cout << "YES" << endl;
        return 0;
    }
    
    cout << "NO" << endl;
    
    return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

int N, M;
vector<int> E[100010];
int C[100010];
int num[100010];

void dfs(int cur, int col) {
	if (C[cur] != -1) {
		if (C[cur] != col) {
			//完全グラフからM引いた値
			cout << 1LL * N * (N - 1LL) / 2 - M << endl;
			exit(0);
		}
	}
	else {
		C[cur] = col;
		num[col]++;
		for (auto e : E[cur]) {
			dfs(e, col ^ 1);
		}
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	cin >> N >> M;

	rep(i, M) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		E[x].push_back(y);
		E[y].push_back(x);
	}

	for (int i = 0; i < 100010; i++) {
		C[i] = -1;
	}

	dfs(0, 0);

	cout << 1LL * num[0] * num[1] - M << endl;

	return 0;
}

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

bitset<26> bi;

int main(){
    string w;
    cin >> w;

    bi.set();
    int a;
    for(int i=0;i<w.length();i++){
        a = w[i] -'a';
        bi.flip(a);
    }
    if(bi.all()) cout << "Yes" << endl;
    else cout << "No" << endl;


}

Measured memory_bytes: 256
fun judge(ret: Boolean, ok: String, ng: String) = if (ret) println(ok) else println(ng)
fun isProduct4(a: Int, b: Int): Boolean = if ((a*10+b) % 4 == 0) true else false

fun main(args: Array<String>) {
  val (x,a,b) = readLine()!!.split(' ').map(String::toInt)
  judge(isProduct4(a,b),"YES","NO")
}


Measured memory_bytes: 36340
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    N = int(input())
    word = []
    time = []
    for _ in range(N):
        a,b = input().split()
        word.append(a)
        time.append(int(b))
    X = input()
    s = -1
    for i in range(N):
        if word[i] == X:
            s = i + 1
    ans = sum(time[s:])
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
fun main(args:Array<String>){
    val n = readLine()!!.split(" ").map { it.toInt() }
    val s = readLine()!!.split(" ").map { it.toInt() }

    val t = s.sum()
    if(n[0] <= t){
        println("Yes")
    }else{
        println("No")
    }
}


Measured memory_bytes: 48976
#include<iostream>
#include<climits>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;

int main(){

	int n;
	cin >> n;
	// char S[100][11];
	vector< string > S;
	
	for(int i = 0; i < n; i++)
	{
		string s;
		cin >> s;
		S.push_back(s);
	}
	
	for(int i = 0; i < n-1; i++)
	{
		// cout << S[i][0] << "," << S[i-1][S[i-1].size()-1] << "," << S[i][S[i].size()-1] << "," << S[i+1][0] << endl;
		// if(S[i][0] == S[i-1][S[i-1].size()-1] && S[i][S[i].size()-1] == S[i+1][0]){
		if (S[i].back() == S[i+1].front()){
			continue;
		}else{
			cout << "No" << endl;
			return 0;
		}
	}
	
	
	for(int i = 0; i < n; i++)
	{
		
		for(int j = i+1; j < n; j++)
		{
			// cout << i << "," << j << endl;
			if(S[i] == S[j] && i!=j){
				cout << "No" << endl;
				return 0;
			}
		}
		
	}
	cout << "Yes" << endl;
	
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

int main(){
    int N;
    cin >> N;
    ll A[100001], B[100001], C[100001];
    for(int i=0;i<N;i++) cin >> A[i];
    sort(A,A+N);

    if(N%2==0){
        bool f=true;
        int l=N/2-1, r=N/2;
        for(int i=0;i<N/2;i++){
            B[i]=A[f?l:r];
            B[N-1-i]=A[f?r:l];
            f=!f;
            l--;
            r++;
        }
        ll ans=0;
        for(int i=0;i<N-1;i++) ans+=abs(B[i+1]-B[i]);
        cout << ans << endl;
    }else{
        B[N/2]=A[0];
        C[N/2]=A[N-1];
        bool f=true;
        for(int i=1;i<=N/2;i++){
            if(f){
                B[N/2+i]=A[N-i];
                B[N/2-i]=A[N-i-1];
                C[N/2+i]=A[i-1];
                C[N/2-i]=A[i];
            }else{
                C[N/2+i]=A[N-i];
                C[N/2-i]=A[N-i-1];
                B[N/2+i]=A[i-1];
                B[N/2-i]=A[i];
            }
            f=!f;
        }
        ll ans1=0, ans2=0;
        for(int i=0;i<N-1;i++){
            ans1+=abs(B[i+1]-B[i]);
            ans2+=abs(C[i+1]-C[i]);
        }

        cout << max(ans1,ans2) << endl;
    }
    return 0;
}

Measured memory_bytes: 2560
from collections import deque

def main():
  h,w=map(int,input().split())
  cy,cx=map(int,input().split())
  dy,dx=map(int,input().split())

  M=["##"+input()+"##" for x in range(h)]
  for i in range(2):
    M.insert(0,"#"*(w+4))
    M.append("#"*(w+4))

  C=[[-1 if M[j][i]=="." else -2 for i in range(w+4)] for j in range(h+4)]
  C[-~cy][-~cx]=0
  QA,QB=deque(),deque()
  QA.append((-~cy,-~cx,0))
  W=[[i,j] for i in range(-2,3) for j in range(-2,3) if abs(i)+abs(j)>1]

  while QA:
    h,w,c=QA.popleft()
    QB.append((h,w,c))

    for i,j in [[1,0],[0,1],[-1,0],[0,-1]]:
      dh,dw=h+i,w+j
      if C[dh][dw]==-1:
        C[dh][dw]=c
        QA.appendleft((dh,dw,c))

    if QA:
      continue

    while QB:
      h,w,c=QB.popleft()
      for i,j in W:
        dh,dw=h+i,w+j
        if C[dh][dw]==-1:
          C[dh][dw]=-~c
          QA.append((dh,dw,-~c))

    if C[-~dy][-~dx]!=-1:
      print(C[-~dy][-~dx])
      exit()

  print(C[-~dy][-~dx])

if __name__ == "__main__":
  main()


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

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

  string s;

  int sen = n / 1000;
  int hyaku = n % 1000 / 100;
  int juu = n % 100 / 10;
  int ichi = n % 10;

  if (sen == hyaku && hyaku == juu)
    s = "Yes";
  else if (hyaku == juu && juu == ichi)
    s = "Yes";
  else
    s = "No";

  cout << s << endl;
}


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

long long N, K;
vector<long long> sumV(100001);

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;

  string s;
  cin >> s;
  for(int i = 0; i < 19; i++){
    if(i == 5 || i == 13){
      cout << " ";
    } else{
      cout << s[i];
    }
  }
}


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

#define SZ(a) int((a).size())
#define _REP(_1,_2,_3,_4,name,...) name
#define _REP4(i,b,e,s) for(decltype(e) _b=(b),_e=(e),i=_b+(0<(s)?0:(s));(0<(s)?i<_e:_e<=i);i+=(s))
#define _REP3(i,b,e) for(decltype(e) _b=(b),_e=(e),i=(_b<_e?_b:_b-1);(_b<_e?i<_e:_e<=i);(_b<_e?i++:i--))
#define _REP2(i,n) for(decltype(n) i=0,_n=(n);i<_n;i++)
#define _REP1(n) for(decltype(n) _i=0,_n=(n);_i<_n;_i++)
#define REP(...) _REP(__VA_ARGS__,_REP4,_REP3,_REP2,_REP1)(__VA_ARGS__)
#define FOR(it,c) for(auto&& it=begin(c);it!=end(c);it++)
#define ROF(it,c) for(auto&& it=rbegin(c);it!=rend(c);it++)
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define INT(n) int n;assert(0<scanf("%d",&n))

template <typename T> bool next_combination(const T first, const T last, int k) {
    const T subset = first + k;
    // empty container | k = 0 | k == n
    if (first == last || first == subset || last == subset) {
        return false;
    }
    T src = subset;
    while (first != src) {
        src--;
        if (*src < *(last - 1)) {
            T dest = subset;
            while (*src >= *dest) {
                dest++;
            }
            iter_swap(src, dest);
            rotate(src + 1, dest + 1, last);
            rotate(subset, subset + (last - dest) - 1, last);
            return true;
        }
    }
    // restore
    rotate(first, subset, last);
    return false;
}

int main() {
  INT(n); INT(m); INT(q);
  int ans = 0;
  vector<vector<int>> qs;
  REP(q){
    INT(a); INT(b); INT(c); INT(d);
    qs.PB({a, b, c, d});
  }
  vector<int> v; REP(i, n + m - 1){v.PB(i);}
  do {
    vector<int> w(n + m - 1, 0), as;
    REP(i, m - 1){
      w[v[i]] = 1;
    }
    int ai = 1;
    for(int e: w){
      if (e == 0){
        as.PB(ai);
      } else {
        ai++;
      }
    }
    int s = 0;
    for(vector<int> qi: qs){
      if (as[qi[1] - 1] - as[qi[0] - 1] == qi[2]){s += qi[3];}
    }
    ans = max(ans, s);
  } while(next_combination(v.begin(), v.end(), m - 1));
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 3760
import java.util.Scanner;

public class Main {


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] x = new int[n];
		int[] y = new int[n];
		double[][] distance = new double[n][n];
		double ans = 0;
		int cnt = 0;
		for(int i = 0 ; i < n; i++) {
			x[i] = Integer.parseInt(sc.next());
			y[i] = Integer.parseInt(sc.next());
		}
		
		for(int i = 0 ; i < n -1; i++) {
			for(int j = i + 1 ; j < n; j++) {
				double tmp_x = Math.pow((x[j] - x[i]), 2);
				double tmp_y = Math.pow((y[j] - y[i]), 2);
				double tmp = Math.sqrt(tmp_x + tmp_y);
				distance[i][j] = tmp;
				ans += tmp;
				cnt ++;
			}
		}
		
		
		System.out.println(ans*2/n);
		
		
	}

}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define bug1( x ) {cerr << (#x) <<"="<< x << endl;}
#define bug2( x , y ) {cerr << (#x) <<"="<< (x) << "    " << (#y) << "="<< (y) << endl;}
#define bug3( x , y , z ) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << endl;}
#define bug4( x , y , z , w) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << endl;}
#define bug5( x , y , z , w ,p) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << endl;}
#define bug6( x , y , z , w ,p , q) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << "    " << (#q) <<"="<< q << endl;}
#define bugn( x , n ) {cerr << (#x) <<":";for(int i=0;i<n;i++)cerr << x[i] <<"  "; cerr << endl;}
#define bugnm( x , n , m ) {cerr << (#x)<<endl;for(int i=0;i<n;i++){cerr << "Row #" << i<< ":";for(int j=0;j<m;j++)cerr << x[i][j] << "   ";cerr << endl;}}
typedef long long ll;
typedef long double ld;
using namespace std;

const int maxn = 1e5+5;
vector<pair<int,int>>g[maxn];
int w[maxn][2];
int n,m,s,t;

vector<int>spfa(int s,int p){
	vector<int>dis(n+1,1e15);
	vector<int>inq(n+1);
	queue<int>q;
	dis[s]=0;
	q.push(s);
	inq[s]=1;
	while( q.size() ){
		int u = q.front(); q.pop(); inq[u]=0;
		for(auto [v,i]:g[u]){
			if( dis[v] > dis[u] + w[i][p] ){
				dis[v] = dis[u] + w[i][p];
				if( !inq[v] ){
					q.push(v);
					inq[v]=1;
				}
			}
		}
	}
	return dis;
}
int32_t main(){
	IOS
	cin>>n>>m>>s>>t;
	for(int i=1;i<=m;i++){
		int u,v;cin>>u>>v>>w[i][0]>>w[i][1];
		g[u].push_back({v,i});
		g[v].push_back({u,i});
	}
	vector<int>d0 = spfa(s,0);
	vector<int>d1 = spfa(t,1);
	vector<pair<int,int>>ans;
	ans.push_back({1e18,1e18});
	for(int i=n;i>=1;i--){
		int cur = d0[i] + d1[i] ;
		if( cur < ans.back().second ){
			ans.push_back({i,cur});
		}
	}
	for(int i=1;i<=n;i++){
		while( ans.back().first < i ){
			ans.pop_back();
		}
		cout << (int)(1e15-ans.back().second) << endl;
	}


}
/*
 * long long or int?
 * index out of bound?
 * Tested on own test case?corner?
 * Make more general solution.
 * Read Read Read Read ....
 */


Measured memory_bytes: 16352
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
import numpy as np
mod = 10 ** 9 + 7
H, W, K = MAP()
L = [input() for i in range(H)]
S = [[0] * W for i in range(H)]
for i in range(H):
    for j in range(W):
        if L[i][j] == "#":
            S[i][j] = 1
S_n = np.array(S)

import itertools
L = [0, 1] #生成する数字


h_b = list(itertools.product([0, 1], repeat=H))
w_b = list(itertools.product([0, 1], repeat=W))


mask = [[0] * W for i in range(H)]

cnt = 0

for h_t in h_b:
    for w_t in w_b:
        for i, h_ in enumerate(h_t):
            for j, w_ in enumerate(w_t):
                mask[i][j] = h_ * w_
        m_n = np.array(mask)
        ada = np.sum(m_n * S_n)
        if ada == K:
            cnt += 1
print(cnt)        
                

Measured memory_bytes: 27332
//
//  main.cpp
//  Atcoder1
//
//  Created by Hamske on 2020/09/17.
//  Copyright © 2020 Author. All rights reserved.
//

#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>

using namespace std;

//#define pb push_back
//#define mp make_pair
//
//#define F first
//#define S second

typedef long long ll;

#define rept(_i,iv,n,type) for(type _i=(type)(iv);_i<(type)(n);++_i)
//#define repi(_i,iv,n) rept(_i,iv,n,int)
//#define repl(_i,iv,n) rept(_i,iv,n,ll)

#define rept0(_i,n,type) rept(_i,0,n,type)
#define repi0(_i,n) rept(_i,0,n,int)
#define repl0(_i,n) rept(_i,0,n,ll)

//#define repst(_i,iv,n,type) for(type _i=iv;_i<=(type)(n);++_i)
//#define repsi1(_i,n) repst(_i,1,n,int)

#define REPT(_i,iv,_l,n,type) for(type _i=(type)(iv),_l=(type)(n);_i<_l;++_i)
//#define REPI(_i,iv,_l,n) REPT(_i,iv,_l,n,int)
//#define REPL(_i,iv,_l,n) REPT(_i,iv,_l,n,ll)
//
#define REPT0(_i,_l,n,type) REPT(_i,0,_l,n,type)
#define REPI0(_i,_l,n) REPT(_i,0,_l,n,int)
#define REPL0(_i,_l,n) REPT(_i,0,_l,n,ll)


//#define rrept(_i,x,e,type) for(type _i=((type)(x)-1);_i>=e;--_i)
//
//#define rrept0(_i,x,type) rrept(_i,x,0,type)
//
//#define RREPT(_i,x,_e,e,type) for(type _i=((type)(x)-1),_e=(type)(e);_i>=_e;--_i)
//
//#define RREPT0(_i,x,_e,type) RREPT(_i,x,_e,0,type)
//
//#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

//#define all(x) (x).begin(),(x).end()
#define REPV(v,_itr,_end) for(auto _itr=(v).begin(),_end=(v).end();_itr!=_end;++_itr)
#define REPVC(v,_itr,_end) for(auto _itr=(v).cbegin(),_end=(v).cend();_itr!=_end;++_itr)

#define td typedef
//#define tds(stl,type,name) typedef stl<type > name;
#define tdv(type,name) typedef vector<type > name;


typedef vector<bool> vb;
typedef vector<vb > vvb;
typedef vector<int> vi;
typedef vector<vi > vvi;
typedef vector<ll> vll;
//typedef vector<vll > vvll;
tdv(string, vs)

int main(int argc, const char * argv[]) {
    int N,M,X;
    cin>>N>>M>>X;
    
    vi C(N);
    vvi A(N);
    repi0(i, N){
        int c1;
        cin>>c1;
        C[i]=c1;
        A[i].resize(M);
        repi0(j, M){
            int a1;
            cin>>a1;
            A[i][j]=a1;
        }
    }
    
    int min=INT32_MAX;
    REPI0(s, l,1<<N){
        int mn=0;
        bool fail=false;
        repi0(j, M){
            int u=0;
            repi0(i, N){
                if(((s>>i)&1)==0){
                    continue;
                }
                if(j==0){
                    mn+=C[i];
                }
                u+=A[i][j];
            }
            if(u<X){
                fail=true;
                break;
            }
        }
        if(!fail){
            if(min>mn){
                min=mn;
            }
        }
    }
    
    cout<<(min==INT32_MAX?-1:min)<<endl;
    
    return 0;
}


Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(int i=0;i<n;i++)
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
const int N=1e5+5;
 
 
int pa[N];
int n,m;
 
ll szz[N];
ll ans[N];
struct edge{
    int u,v;
}edges[N];
 
int find(int x){
    if(pa[x]==x) return pa[x];
    else{
        pa[x]=find(pa[x]);
        return pa[x];
    }

}


 
int main(){
    IOS
    cin>>n>>m;
    int a,b;
    
    for(int i=1;i<=m;++i){
        cin>>edges[i].u>>edges[i].v;
 
    }
    //cout<<"hre"<<endl;
    
    for(int i=1;i<=n;++i){
        //raank[i]=0;
        pa[i]=i;
        szz[i]=1;
    }
    ans[m]=(ll)n*(ll)(n-1)/(ll)2;
    //cout<<"herew   df  "<<endl;
    for(int i=m;i>=1;--i){
 
          a=find(edges[i].u);
          b=find(edges[i].v);
          
         
          if(a==b){
               ans[i-1]=ans[i];
          }
          else{
               ans[i-1]=ans[i]-(szz[a]*szz[b]);
               szz[a]+=szz[b];
               pa[b]=a;
          }
          //cout<<szz[a]<<endl;
     
 
 
     }
     for(int i=1;i<=m;i++) 
         cout<<ans[i]<<endl;
      
    
     return 0;
}

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

int main() {
    int N, M;
    std::cin >> N >> M;

    int cnt[N+1] = {0};
    int a, b;
    for (int i = 0; i < M; ++i) {
        std::cin >> a >> b;
        cnt[a] += 1; 
        cnt[b] += 1;
    }

    for (int i = 1; i <= N; ++i) {
        std::cout << cnt[i] << std::endl;
    }

    return 0;
}



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

int main(){
  string s, ans = "";
  cin >> s;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == 'B'){
      if(ans.size() > 0) ans.pop_back();
    }else{
      ans.push_back(s[i]);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <map>
#include <vector>
#include <string>
#include <vector>
#include <cassert>
#include <cmath>
#include <stack>
#include <cctype>
#include <queue>
#include <algorithm>
#include <memory>
#include <memory.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int INF = 1 << 30;
const double EPS = 1e-10;
const double PI = 3.14159;

int dis[100001];
int ord;

int main(){
	int d, n, m;
	while(cin >> d && d){
		cin >> n >> m;
		dis[0] = 0, dis[n] = d;
		ll res = 0;
		for(int i = 1; i < n; i++) cin >> dis[i];
		sort(dis, dis + n + 1);
		for(int i = 0; i < m; i++){
			cin >> ord;
			int d1 = *lower_bound(dis, dis + n + 1, ord);
			int d2 = *(upper_bound(dis, dis + n + 1, ord)-1);
			res += min(d1 - ord, ord - d2);
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 1256
import numpy as np


def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]


N = int(input())
prime_list = np.array(primes(55555))
five_one_list = prime_list[prime_list % 5 == 1]

choice = map(str, five_one_list[:N])
ans = ' '.join(choice)

print(ans)

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

#define ms(a,x) memset(a,x,sizeof(a))
using namespace std;

typedef long long ll;

int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);}
int lcm(int a,int b){
	return a/gcd(a,b)*b;}

int n,a[101];
int print(int a[],int n){
	for(int i=0;i<n;i++){
		if(i>0)cout<<' ';
		cout<<a[i];
	}
	cout<<endl;
}
int bsort(int a[],int n){
	int flag=1;
	int sw=0;
	while(flag){
		flag=0;
		for(int j=n-1;j>=1;j--){
			if(a[j]<a[j-1]){
				swap(a[j],a[j-1]);
				flag=1;
				sw++;
			}
		}	
	}
	print(a,n);
	printf("%d\n",sw);
}

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




Measured memory_bytes: 3228
import java.util.*;

class Main {
  static int H, W;
  static String[][] map;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    H = sc.nextInt();
    W = sc.nextInt();
    map = new String[H][W];
    Deque<Integer[]> que = new ArrayDeque<>();
    for (int i = 0; i < H; i++) {
      map[i] = sc.next().split("");
      for (int j = 0; j < W; j++) {
        if (map[i][j].equals("#")) que.add(new Integer[]{i, j}); 
      }
    }
    int ans = 0;
    while (true) {
      int n = que.size();
      for (int i = 0; i < n; i++) {
        Integer[] p = que.poll();
        change(que, p[0]-1, p[1]);
        change(que, p[0], p[1]+1);
        change(que, p[0], p[1]-1);
        change(que, p[0]+1, p[1]);
      }
      if (que.isEmpty()) break;
      ans++;
    }
    System.out.println(ans);
  }
  
  static void change(Deque<Integer[]> que, int h, int w) {
    if (h < 0 | h >= H | w < 0 | w >= W) return;
    if (map[h][w].equals("#")) return;
    que.add(new Integer[]{h, w});
    map[h][w] = "#";
  }
}

Measured memory_bytes: 183380
#include<stdio.h>

int left(int i){
  return 2*i;
}
int right(int i){
  return 2*i+1;
}

void maxHeapify(int A[],int i,int n){
  int l = left(i);
  int r = right(i);
  int large;
  int tmp;

  if(l <= n && A[l] > A[i]){
    large = l;
  }else{
    large = i;
  }
  if(r <=n && A[r] > A[large]){
    large = r;
  }

  if(large != i){
    tmp = A[i];
    A[i] = A[large];
    A[large] = tmp;
    maxHeapify(A,large,n);
  }
}


void buildMaxHeap(int A[],int n){
  int i;
  for(i=n/2;i>0;i--){
    maxHeapify(A,i,n);
  }
}

int main(){
  int i;
  int n;
  int A[500000];

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

  for(i=1;i<=n;i++){
    printf(" %d",A[i]);
  }
 puts("");
  return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <string>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> R(N);
  for(int i=0;i<N;i++){
    cin >> R.at(i);
  }
  sort(R.begin(),R.end());
  reverse(R.begin(), R.end());
  int A=0;
  int B=0;
  for(int k=0;k<N;k++){
    if(k%2==0){
      A += R.at(k);
    }else{
      B += R.at(k);
    }
  }
  
  cout << A-B << endl;
  
}
      

Measured memory_bytes: 256
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <iomanip>

typedef long double ld;
typedef long long ll;

using namespace std;


/* TEMPLATE ENDS HERE */

#define MAXN (1 << 20)


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

struct mod {
	ll x;

	mod(ll tx = 0) {
		x = tx;
		x %= MOD;
	}
	
	mod& operator=(const ll & tx) {
		x = tx % MOD;
		return *this;
	}
	
	mod& operator=(const mod & m2) {
		x = m2.x;
		return *this;
	}

	mod operator+(const mod& m2) const {
		return mod((x + m2.x) % MOD);
	}

	mod& operator+=(const mod& m2) {
		x += m2.x;
		x %= MOD;
		return *this;
	}

	mod operator-(const mod & m2) const {
		return mod((x - m2.x + MOD) % MOD);
	}

	mod& operator-=(const mod & m2) {
		x -= m2.x;
		x = (x + MOD) % MOD;
		return *this;
	}

	mod operator*(const mod & m2) const {
		return mod((x * m2.x) % MOD);
	}

	mod& operator*=(const mod & m2) {
		x *= m2.x;
		x %= MOD;
		return *this;
	}

	mod mypow(ll k) const {
		mod ret = 1;
		mod cur = x;
		while (k) {
			if (k & 1) {
				ret *= cur;
			}
			cur *= cur;
			k >>= 1;
		}
		return ret;
	}

	mod inv() const {
		return mypow(MOD - 2);
	}

	mod operator/(const mod & m2) const {
		return (*this) * m2.inv();
	}

	mod& operator/=(const mod & m2) {
		x *= m2.inv().x;
		x %= MOD;
		return *this;
	}

	bool operator<(const mod & m2) const {
		return x < m2.x;
	}
};

ostream &operator<<(ostream & os, const mod & m) {
	return os << m.x;
}


int b, w;
mod a[MAXN];
mod pb[MAXN];
mod pw[MAXN];
mod cb(0), cw(0);
ld lpb[MAXN];
ld lpw[MAXN];

mod f(int c, int i, mod & cc, mod two) {	
	if (i == c) {
		cc = 1;
	} else if (i > c) {
		cc *= i - 1;
		cc *= mod(i - c).inv();
	}
	return cc * two.inv();
}

ld lf(int c, int i, ld & cc, ld two) {
	if (i == c) {
		cc = 1;
	} else if (i > c) {
		cc *= i - 1;
		cc /= i - c;
	}
	return cc / two;
}

int main() {
	cout << fixed << setprecision(12);	
	cin >> b >> w;
/*	ld ltwo = 2;
	ld lcb = 0, lcw = 0;
	for (int i = 1; i <= b + w; i++) {
		ld lppb = lpb[i - 1];
		ld lppw = lpw[i - 1];
		ld ret = (1 - lppw + lppb) / 2.0;
		cout << ret << endl;
		ld lpbcur = lf(b, i, lcb, ltwo);
		ld lpwcur = lf(w, i, lcw, ltwo);
		lpb[i] = lpb[i - 1] + lpbcur;
		lpw[i] = lpw[i - 1] + lpwcur;
		ltwo *= 2;
	}*/
	

	mod two(2);
	for (int i = 1; i <= b + w; i++) {
		mod ppb = pb[i - 1];
		mod ppw = pw[i - 1];
		mod ret = (mod(1) - ppb + ppw) * mod(2).inv();
		cout << ret << endl;
		mod pbcur(0), pwcur(0);
		pbcur = f(b, i, cb, two);
		pwcur = f(w, i, cw, two);
		pb[i] = pb[i - 1] + pbcur;
		pw[i] = pw[i - 1] + pwcur;
		two *= 2;
	}

	return 0;
}




Measured memory_bytes: 28196
S = input()
 
if S == 'SUN':
  print(7)
if S == 'MON':
  print(6)
if S == 'TUE':
  print(5)
if S == 'WED':
  print(4)
if S == 'THU':
  print(3)
if S == 'FRI':
  print(2)
if S == 'SAT':
  print(1)

Measured memory_bytes: 3060
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n;
  cin >> n;
  ll ans = 0;
  for(int i = 1; i <= n; ++i){
    ans += n / i - ((n % i == 0) ? 1 : 0);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3628