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

int main(void) {
    int n;
    scanf("%d", &n);
    int x[n], y[n];
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &x[i], &y[i]);
    }

    int fact = 1;   //n!
    for (int i = 1; i <= n; i++) {
        fact *= i;
    }

    double sum = 0;
    double dist = 0;

    for (int a = 0; a < n; a++) {
        sum += pow(pow(x[0]-x[a],2)+pow(y[0]-y[a],2), 0.5);
    }
    for (int b = 1; b < n; b++) {
        sum += pow(pow(x[1]-x[b],2)+pow(y[1]-y[b],2), 0.5);
    }
    for (int c = 2; c < n; c++) {
        sum += pow(pow(x[2]-x[c],2)+pow(y[2]-y[c],2), 0.5);
    }
    for (int d = 3; d < n; d++) {
        sum += pow(pow(x[3]-x[d],2)+pow(y[3]-y[d],2), 0.5);
    }
    for (int e = 4; e < n; e++) {
        sum += pow(pow(x[4]-x[e],2)+pow(y[4]-y[e],2), 0.5);
    }
    for (int f = 5; f < n; f++) {
        sum += pow(pow(x[5]-x[f],2)+pow(y[5]-y[f],2), 0.5);
    }
    for (int g = 6; g < n; g++) {
        sum += pow(pow(x[6]-x[g],2)+pow(y[6]-y[g],2), 0.5);
    }



    for (int i = 1; i <= n-1; i++) {
        sum *= i;
    }
    sum *= 2;

    printf("%.10lf\n", sum/fact);

    return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  rep(i,n) a[i]--;
  vector<int> s(n+1);
  rep(i,n) {
    s[i+1] = (s[i]+a[i])%k;
  }
  map<int,int> mp;
  ll ans = 0;
  queue<int> q;
  rep(j,n+1) {
    ans += mp[s[j]];
    mp[s[j]]++;
    q.push(s[j]);
    if (q.size() == k) {
      mp[q.front()]--;
      q.pop();
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n,x;cin>>n>>x;
  int res=1;
  int d=0;
  for(int i=0;i<n;i++){
    int l;cin>>l;
    d+=l;
    if(d<=x)res++;
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);

int main() {
    string T;
    cin>>S>>T;
    N = S.size();
    ll res = N;
    rep(i,N) res -= S[i] == T[i];
    cout<<res<<endl;
}


Measured memory_bytes: 3924
#include <iostream>

int main() {
  int A = 0;
  int B = 0;
  int H = 0;
  std::cin >> A;
  std::cin >> B;
  std::cin >> H;

  

  if (A == B && B == H) {
    std::cout << B * H << std::endl;
  } else {
    std::cout << (A + B) * H / 2 << std::endl;
  }
  
}

Measured memory_bytes: 256
using System;

namespace ITP1_8_A
{
    class Program
    {
        static void Main(string[] args)
        {
            char[] input = Console.ReadLine().ToCharArray();

            for (int j=0; j<input.Length; j++)
            {

                    if (char.IsUpper(input[j]))
                    {
                        input[j] = char.ToLower(input[j]);
                    }
                    else if (char.IsLower(input[j]))
                    {
                        input[j] = char.ToUpper(input[j]);
                    }
            }

            Console.WriteLine(input);
        }
    }
}

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

const int MOD = 1e9+7;

long long r1,r2,c1,c2;

long long ksm(long long x,long long y)
{
	x %= MOD;
	long long rt = 1LL;
	while ( y )
	{
		if ( y & 1 ) 
			rt = rt * x % MOD;
		x = x * x % MOD;
		y >>= 1;
	}
	return rt;
}

long long C(long long n,long long m)
{
	if ( n < m )
		return 0LL;
	long long rt = 1LL;
	for ( long long i = 0LL ; i < m ; i++ )
		rt = rt * (n-i) % MOD * ksm(i+1LL,MOD-2) % MOD;
	return rt;
}

long long u(long long x,long long y)
{
	return C(x+y,min(x,y));
}

long long s(long long x,long long y)
{
	return u(y+1,x+1)-1LL;
}

int main()
{
	scanf("%lld%lld%lld%lld",&r1,&c1,&r2,&c2);
	printf("%lld",(s(r2,c2)-s(r2,c1-1LL)-s(r1-1LL,c2)+s(r1-1LL,c1-1LL)+MOD)%MOD);
	printf("\n");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int a,b;
    cin >> a >> b;
    if(a<b){
        cout <<"a < b"<< endl;
    }
    else if(a>b){
        cout <<"a > b"<< endl;
    }
    else {
        cout <<"a == b"<< endl;
    }
}




Measured memory_bytes: 3088
#include <stdio.h>
void bubble_sort(int n,int a[])
{
    int i,j=0,h,flag=1,ans=0;
    while(flag)
    {
        flag=0;
        for(i=n-1;i>0;i--)
        {
            if(a[i]<a[i-1])
            {
                j=a[i];
                a[i]=a[i-1];
                a[i-1]=j;
                flag=1;
                ans++;
            }
        }
    }
        for(h=0;h<n;h++)
        {
            if(h>0)
                printf(" ");
            printf("%d",a[h]);
        }
        printf("\n");
        printf("%d\n",ans);
}
int main()
{
    int i,n,a[101];
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
        bubble_sort(n,a);
        return 0;
}


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

int main(){
  int n,x;
  cin >> n >> x;
  int a[n];
  
  for(int i=0;i<n ;i++){
    cin >> a[i];
  }
  int sum=0,count=0,min=111111;
  
  for(int i=0;i<n; i++){
    sum += a[i];
    if(min>a[i]) min = a[i];  
  }
  count = n + (x-sum) /min;
  cout << count << endl;  
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
mod vig {
    pub const MOD:u64 = 1_000_000_007;
    /// 0-indexed
    pub fn dfs(graph: &Vec<Vec<u64>>, k: u64, now: u64, from:i64) -> u64 {
        let mut color_number = k-2;
        if from ==-1 {
            color_number = k-1;
        }
        if k< graph[now as usize].len() as u64 {
            return 0;
        }
        let mut pp=1;
        for leaf in &graph[now as usize] {
            if *leaf as i64 == from {
                continue;
            }
            pp*=color_number;
            color_number-=1;
            pp%=MOD;
        }
        for leaf in &graph[now as usize] {
            if *leaf as i64 == from {
                continue;
            }
            pp*=dfs(graph,k, *leaf, now as i64);
            pp%=MOD;
        }
        pp
    }
}
fn main() {
    input!{
        n:usize,
        k:u64,
        ab: [(u64, u64); n-1]
    }
    let mut graph = vec![vec![];n];
    for i in 0..n-1 {
        graph[(ab[i].0 - 1)  as usize].push(ab[i].1 -1 );
        graph[(ab[i].1 -1)  as usize].push(ab[i].0 -1 );
    }
    let mut ans = (k%vig::MOD)*vig::dfs(&graph, k, 0, -1);
    ans%=vig::MOD;
    println!("{}", ans);
}

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

int main(){
	int n,sum;
    sum=0;
	cin>>n;
	vector<int>a(n);
	vector<int>b(n-1);
	for(int i=0;i<n-1;i++){
      cin>>b[i];
    }
  a[0]=b[0];
  for(int i=1;i<n;i++){
    if(b[i]>b[i-1]){
      a[i]=b[i-1];
    }else{
      a[i]=b[i];
    }
  }
  a[n-1]=b[n-2];
	for(int i=0;i<n;i++){
	sum+=a[i];
	}
	cout<<sum<<endl;
}


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

int main(){
	int n;
	while(1){
		cin>>n;
		if(n==0)break;
		int dt[n+1][n+1];
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cin>>dt[i][j];
			}
		}
		for(int x=0;x<n+1;x++){
			dt[x][n]=0;
		}
		for(int y=0;y<n;y++){
			dt[n][y]=0;
		}
		for(int k=0;k<n;k++){
			for(int l=0;l<n;l++){
				dt[k][n]+=dt[k][l];
			}
		}
		for(int x=0;x<=n;x++){
			for(int y=0;y<n;y++){
				dt[n][x]+=dt[y][x];
			}
		}
		for(int a=0;a<=n;a++){
			for(int b=0;b<=n;b++){
				if(dt[a][b]/10==0)cout<<"    "<<dt[a][b];
				else if(dt[a][b]/100==0)cout<<"   "<<dt[a][b];
				else if(dt[a][b]/1000==0)cout<<"  "<<dt[a][b];
				else if(dt[a][b]/10000==0)cout<<" "<<dt[a][b];
				else if(dt[a][b]/100000==0)cout<<dt[a][b];
			}
			cout<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
#define bit(k) (1LL<<(k))
const int INF = 1e9;

int mergecount(vector<int> &a) {
    int count = 0;
    int n = a.size();
    rep(i,n) rep(j,i) if(a[j]>a[i]) ++count;
    return count;
}

int main(void){
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    int res = INF;
    rep(mask, 1<<n){
        using P = pair<int,int>;
        vector<P> even, odd;
        rep(i,n){
            bool is_back = mask & bit(i);
            if ((i&1)^is_back) {
                odd.push_back({is_back ? b[i] : a[i], i});
            } else {
                even.push_back({is_back ? b[i] : a[i], i});
            }
        }
        if ((int)odd.size() != n/2) continue;
        if(__builtin_popcount(mask) & 1) continue;

        sort(all(even));
        sort(all(odd));
        {
            bool ng = false;
            rep(i,n-1){
                if (i % 2 == 0) {
                    if (even[i/2].first > odd[i/2].first) ng = true;
                } else {
                    if (odd[i/2].first > even[(i+1)/2].first) ng = true;
                }
            }
            if (ng) continue;
        }

        vector<int> v;
        rep(i,n){
            v.push_back((i&1) ? odd[i/2].second : even[i/2].second);
        }
        res = min(res, mergecount(v));
    }
    cout << (res == INF ? -1 : res) << endl;
    return 0;
}


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

long long n, x,ans;
ll gcdgcd(ll x,ll n)
{
    if(n%x==0)
        return n*2-x;
    ans=n/x*x*2+gcdgcd(n%x, x);
    return ans;
}
 
int main()
{
    cin>>n>>x;
    cout<<gcdgcd(x, n-x)+n<<endl;
    return 0;
}
 

Measured memory_bytes: 256
#include <queue>
#include <cstdio> 
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 1100000
#define M 2200000
using namespace std;
int n,m,dis[N],maxdis = 0;
queue<int>q,Empty;
char inq[N];
int fst[N],nxt[M],to[M],val[M],cnt = 0;
inline void addedge(int x,int y,int z){
	cnt++;
	nxt[cnt] = fst[x];
	fst[x] = cnt;
	to[cnt] = y;
	val[cnt] = z;
}
int spfa(int x){
	q = Empty;
	q.push(x);
	inq[x] = 1;
	dis[x] = 0;
	while(!q.empty()){
		int u = q.front();
		q.pop();
		inq[u] = 0;
		for(int i = fst[u];i != -1;i = nxt[i]){
			int v = to[i];
			if(dis[v] == 0x7f7f7f7f){
				dis[v] = dis[u] + val[i];
				if(!inq[v]){
					q.push(v);
					inq[v] = 1;
				}
			}
			else if(dis[v] != dis[u] + val[i])
				return 0;
			maxdis = max(maxdis,dis[v]);
		}
	}
	return 1;
}
int main()
{
//	freopen("line.in","r",stdin);
//	freopen("line.out","w",stdout);
	memset(dis,0x7f,sizeof dis);
	memset(inq,0,sizeof inq);
	memset(fst,-1,sizeof fst);
	cin>>n>>m;
	for(int i = 1;i <= m;i++){
		int x,y,z;
		scanf("%d %d %d",&x,&y,&z);
		addedge(x,y,z);
		addedge(y,x,-z);
	}
	for(int i = 1;i <= n;i++)
		if(dis[i] == 0x7f7f7f7f)
			if(!spfa(i))return puts("No"),0;
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 19200
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>

typedef long long ll;
using namespace std;

int main()
{
    int a, b, c, x, y;
    int ans = 0;
    cin >> a >> b >> c >> x >> y;
    ans = a*x + b*y;
    if (x > y) {
        ans = min(2*y*c + a*(x - y), ans);
        ans = min(ans, 2*x*c);
        cout << ans << endl;
        return 0;
    } else {
        ans = min(2*x*c + b*(y - x), ans);
        ans = min(ans, 2*y*c);
        cout << ans << endl;
        return 0;
    }
}

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

candidates = set([""])
keys = set()

for s in S:
    new_candidate = set()
    for cand in candidates:
        new = cand + s
        if len(new) == 3:
            keys.add(new)
        else:
            new_candidate.add(new)
    candidates = candidates.union(new_candidate)

print(len(keys))


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

int main() {
	int h, w;
	cin >> h >> w;
	string s[h][w];
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			cin >> s[i][j];
			if(s[i][j] == "snuke"){
				char k = 'A';
				k += j;
				cout << k << i + 1 << endl; 
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

#define bip(n) __builtin_popcount(n)//no of ones bit in binary!!
#define bictz(n) __builtin_ctz(n)//no of trailing zeroes in binary!!
#define biclz(n) __builtin_clz(n)//no of leading zeroes in binary!!
#define bffs(n) __builtin_ffs(n)//index of first one bit!!

typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;

//#define fi1 ifstream fin("input.txt")
//#define of1 ofstream fout("output.txt")
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

#define fi first
#define se second

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,k;
	cin>>n>>k;
	if(k==1)
		cout<<0;
	else
		cout<<n-k;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <tuple>
#include <cstring>
#include <map>
#include <iomanip>
#include <ctime>
#include <complex>
using namespace std;
typedef long long ll;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define len(X) (X).size()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Tlll tuple<ll, ll, ll>

ll inf = 5e18+7;
 
ll pw(ll x, ll y) {
    if (y == 0) return 1;
    else if (y == 1) return x % inf;
    else if (y % 2 == 0) {
        ll p = pw(x, y / 2);
        return p * p % inf;
    }
    else {
        ll p = pw(x, y / 2);
        return p * p % inf * x % inf;
    }
}

ll dv(ll x, ll y) {
    return x * pw(y, inf - 2) % inf;
}
 
ll comb(ll cn, ll cr) {
    ll v = 1;
    if (cn < cr || cn < 0 || cr < 0) return 0;
    for (int i = 1; i <= cr; i++) {
        v = v * (cn - i + 1);
        v = v / i;
    }
    return v;
}

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

    int d = n.size() - 1;
    if (k > n.size()) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = 0;
    ans += pw(9, k) * comb(d, k);
    if (k == 1) {
        ans += (n[0] - 48);
    }
    else if (k == 2) {
        cerr << ans << endl;
        ans += max(n[0] - 49, 0) * pw(9, k - 1) * comb(d, k - 1);
        cerr << ans << endl;
        if (n[1] != '0') {
            ans += pw(9, k - 1) * comb(d - 1, k - 1);
            ans += n[1] - 48;
        }
        else {
            int idx = 1;
            while (idx < n.size() && n[idx] == '0') idx++;
            if (idx != n.size()) {
                ans += pw(9, k - 1) * comb(d - idx, k - 1);
                ans += n[idx] - 48;
            }
        }
    }
    else if (k == 3) {
        cerr << ans << endl;
        ans += max(n[0] - 49, 0) * pw(9, k - 1) * comb(d, k - 1);
        cerr << ans << endl;
        int idx = 1, one;
        while (idx < n.size() && n[idx] == '0') idx++;
        if (idx != n.size()) {
            if (n.size() != k) ans += pw(9, k - 1) * comb(d - idx, k - 1);
            cerr << ans << endl;
            ans += (n[idx] - 49) * pw(9, k - 2) * comb(d - idx, k - 2);
            cerr << ans << endl;
            idx++;
        }
        while (idx < n.size() && n[idx] == '0') idx++;
        if (idx != n.size()) {
            if (n.size() != k) ans += pw(9, k - 2) * comb(d - idx, k - 2);
            cerr << ans << endl;
            ans += (n[idx] - 48) * pw(9, k - 3) * comb(d - idx, k - 3);
            cerr << ans << endl;
            idx++;
        }
    }
    
    cout << ans << endl;
}


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

int main() {
  string s; cin>>s;
  int n=s.size();
  string ans="Yes";
  rep(i,n){
    if(i%2==1){
      if(s.at(i)=='R'){ans="No"; break;}
    }
    if(i%2==0){
      if(s.at(i)=='L'){ans="No"; break;}
    }
  }
  cout<<ans;
}
      



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define int long long

int MOD(int a, int p){
	a %= p;
	return a >= 0 ? a : a + p;
}

signed main(){
	int N, i, ans = 0;
	scanf("%lld", &N);
	int *A = (int *)malloc(sizeof(int) * N);
	int *B = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%lld%lld", &A[i], &B[i]);
	}
	for(i = N - 1; i >= 0; i--){
		A[i] += ans;
		ans += MOD(-A[i], B[i]);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1792
def count(seq):
    seq = sorted(seq)
    arrived = {}
    arrived[seq[0]] = {}
    arrived[seq[0]][seq[1]] = True
    foo = 0
    s = sum(seq)
    while True:
        if (seq[0]&1==1) or (seq[1]&1==1) or (seq[2]&1==1):
            break
        seq = [(s-seq[i])>>1 for i in xrange(3)]
        seq = sorted(seq)
        if seq[0] in arrived.keys():
            if seq[1] in arrived[seq[0]].keys():
                foo = -1
                break
        else:
            arrived[seq[0]] = {}
        arrived[seq[0]][seq[1]] = True
        foo += 1
    return foo

def main():
    seq = [int(x) for x in raw_input().strip().split()]
    print count(seq)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2696
n = gets.chomp.to_i
nums = gets.chomp.split(' ').map(&:to_i)
a = nums.inject(0){|sum,num|sum+num**2}
b = nums.inject(0){|sum,num|sum+num}
axis = (b/n.to_f).round
ans = n*(axis**2)-2*b*axis+a
puts ans

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

#define mod 1000000007;

int main(){
  int n;
  string str, str2;
  cin >> n;
  cin >> str;
  cin >> str2;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    if (str[i] == str2[i]) {
      v.push_back(1);
    } else {
      v.push_back(2);
      i++;
    }
  }
  int l = v.size();
  long long ans;
  int prev = v[0];
  if (prev == 1) ans = 3;
  else if (prev == 2) ans = 6;
  for (int i = 1; i < l; i++) {
    if (prev == 1) {
      if (v[i] == 1) ans *= 2;
      if (v[i] == 2) ans *= 2;
    }
    else if (prev == 2) {
      if (v[i] == 1) ans *= 1;
      if (v[i] == 2) ans *= 3;
    }
    ans %= mod;
    prev = v[i];
  }

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

Measured memory_bytes: 256
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: u32 = read(&mut stdin_lock, &mut buf, b'\n');
    let ans = if n % 2 == 0 { n } else { n * 2 };
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 2e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    ll n;
    cin >> n;
    vector<pair<ll, ll>> pr;
    rep(i, 0, n) {
        ll a, b;
        cin >> a >> b;
        pr.push_back(make_pair(b, a));
    }
    sort(all(pr));

    ll sum = 0;
    rep(i, 0, n) {
        sum += pr[i].second;
        if (sum > pr[i].first) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }



int n, k;
void solve(){
	cin >> n >> k;
	
	i64 ans = 0, cnt = 0;
	if(k%2 == 0){
		cnt = (n+k/2)/k;
		ans += cnt*cnt*cnt;
	}
	cnt = n/k;
	ans += cnt*cnt*cnt;
	
	cout << ans << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

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

using namespace std;

using ll = long long;

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

  int n, W;
  cin >> n >> W;

  vector<ll> dp(W + 1);
  for (int i = 0; i < n; ++i) {
    ll w, v;
    cin >> w >> v;

    for (int j = W - w; j >= 0; --j) {
      dp[j + w] = max(dp[j + w], dp[j] + v);
    }
  }

  cout << *max_element(dp.begin(), dp.end()) << '\n';

  return 0;
}


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

int selection_sort(vector<int>& nums) {
    int cnt = 0;
    for (int i = 0; i < nums.size(); i++) {
        int mini = i;
        for (int j = i; j < nums.size(); j++) {
            if (nums[j] < nums[mini])
                mini = j;
        }
        swap(nums[i], nums[mini]);
        if (i != mini)
            cnt++;
    }
    return cnt;
}

int main() {
    int N;
    cin >> N;
    vector<int> nums(N);
    for (int i = 0; i < N; i++)
        cin >> nums[i];
    int cnt = selection_sort(nums);
    for (int i = 0; i < N; i++) {
        if (i > 0)
            cout << " ";
        cout << nums[i];
    }
    cout << endl;
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3080
#include<iostream>  
#include<cstring>  
#include<cstdio>  
#include<cmath>  
#include<algorithm>  
  
using namespace std;  
  
bool s[15][10005]= {0};  
  
int ans=0;  
int n, m;  
  
void dfs(int x)  
{  
    if(x==n+1)  
    {  
        int sum=0;  
        int term=0;  
        for(int j=1;j<=m;j++)  
        {  
            for(int i=1;i<=n;i++)  
                if(s[i][j]==1)term++;  
            sum += term > n-term ? term : n-term;  
            term=0;  
        }  
        ans=max(ans,sum);  
        return ;  
    }  
    dfs(x+1);  
    for(int i=1;i<=m;i++)  
        s[x][i]=!s[x][i];  
    dfs(x+1);  
}  
  
int main()  
{  
    //freopen("in.in","r",stdin);  
    while(scanf("%d%d",&n,&m)!=EOF)  
    {  
        if(n==0&&m==0)break;  
        ans=0;  
        for(int i=1; i<=n; i++)  
            for(int j=1; j<=m; j++)  
                scanf("%d",&s[i][j]);  
        dfs(1);  
        printf("%d\n",ans);  
    }  
    return 0;  
}  


Measured memory_bytes: 3200
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

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

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	vector<lint> A(N + 1), B(N);
	for (int i = 0; i < N + 1; i++) cin >> A[i];
	for (int i = 0; i < N; i++) cin >> B[i];

	lint tmp = 0, ans = 0;
	for (int i = 0; i < N; i++) {
		if (A[i] - tmp <= 0) {
			ans += A[i];
			tmp = B[i];
		}
		else if (A[i] - tmp - B[i] >= 0) {
			ans += tmp + B[i];
			tmp = 0;
		}
		else {
			ans += A[i];
			tmp = B[i] - (A[i] - tmp);
		}
	}

	if (tmp > 0)ans += min(tmp, A[N]);

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define ci(n) cin >> n
#define co(n) cout << n << endl
using namespace std;

int main(){
  long a, b=0, c=0;
  bool f=0;
  string s;
  cin >> s;
  rep(i,0,s.size()){
    if(s[i]!='A') b++;
    else break;
  }
  rep(i,0,s.size()){
    if(s[s.size()-i]!='Z') c++;
    else break;
  }
  co(s.size()-b-c+1);
         
         
    
    
  return 0;
}


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

int main() {
  int K,A,B,s;
  cin >> K >> A >> B;
  s = 0;
  for (int i = A; i <= B;i++) {
    if (i % K == 0) {
      cout << "OK" << endl;
      s = 1;
      break;
    }
  } 
  if (s == 0) cout << "NG" << endl;
}


Measured memory_bytes: 3636
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    k = int(input())
    dist = [INF] * k
    dist[1] = 1
    queue = [1]

    for v in queue:
        tmp = [v]
        for v in tmp:
            if dist[10 * v % k] > dist[v]:
                dist[10 * v % k] = dist[v]
                tmp.append(10 * v % k)
            if dist[(v + 1) % k] > dist[v] + 1:
                dist[(v + 1) % k] = dist[v] + 1
                queue.append((v + 1) % k)

    print(dist[0])
resolve()

Measured memory_bytes: 79792
#include <iostream>
#include <string.h>
#include <ctype.h>
using namespace std;

static const int MAX_LENGTH = 1200;

int main(void) {
    char* inputLine = new char[MAX_LENGTH];
    cin.getline(inputLine, MAX_LENGTH);

    for(int i=0; i <= strlen(inputLine); i++) {
        if(i == strlen(inputLine)) {
            cout << endl;
            break;
        }

        if(islower(inputLine[i])) {
            cout << (char)toupper(inputLine[i]);
            continue;
        }
        if(isupper(inputLine[i])) {
            cout << (char)tolower(inputLine[i]);
            continue;
        }
        cout << inputLine[i];
    }

    return 0;
}

Measured memory_bytes: 3088
n, m, x = map(int, input().split())
c, a = [], []
for i in range(n):
  s = input().split()
  c.append(int(s[0]))
  a.append(list(map(int, s[1:])))

min_ans = 1e12
for i in range(int(pow(2, n))):
  idx = 1
  ans = []
  for j in range(n):
    if i & (idx << j) > 0:
      ans.append(j)
  aes = [0]*m
  c_sum = 0
  for j in ans:
    c_sum += c[j]
    for k in range(m):
      aes[k] += a[j][k]
  if not False in list(i >= x for i in aes):
    min_ans = min(min_ans, c_sum)

if min_ans == 1e12:
  print(-1)
else:
  print(min_ans)

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

#define F first
#define S second
#define int long long
#define pb push_back
#define endl '\n'

using namespace std;

int n , W , dp[100001] , ok[100001] , ans ;
vector < pair < int , int > > v ;

int32_t main()
{
	ios_base :: sync_with_stdio(false) ;
	cin.tie(0); cout.tie(0) ; 
	cin >> n >> W ;
	for(int i = 0 ; i < n ; i++){
		int a , b; 
		cin >> a >> b ; 
		v.pb({a , b}) ;
	}
	ok[0] = 1;  
	sort(v.begin() , v.end()) ;
	for(auto i : v){
		int w = i.F ; 
		int val = i.S ;
		for(int j = W ; j >= w ; j--){
			if(ok[j - w]){
				ok[j] = 1 ;
				dp[j] = max(dp[j] , dp[j - w] + val) ; 
				ans = max(ans , dp[j]) ; 
			}
		}
	}
	cout << ans << endl ;
	return 0;  
}



Measured memory_bytes: 1920
import sys

A, B, C, X, Y = map(int, sys.stdin.readline().split(" "))

ans = 0
if A + B >= 2 * C:
    c_count = 2 * min(X, Y)
    ans = c_count * C
    X -= c_count // 2
    Y -= c_count // 2

ans += min(A * X, C * 2 * X)
ans += min(B * Y, C * 2 * Y)

print(ans)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define pb push_back
using namespace std;

const int mn=3e5+7;
int dis[mn];
vector<int> to[mn];

queue<int> q;
void bfs(int s)
{
	dis[s]=1;
	q.push(s);
	while(!q.empty()) {
		s=q.front();q.pop();
		for(int i=0;i<to[s].size();++i) {
			int t=to[s][i];
			if(dis[t]) continue;
			dis[t]=dis[s]+1;q.push(t);
		}
	}
}

int main()
{
	int n,m,s,t,u,v;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;++i) {scanf("%d%d",&u,&v);
		to[u*3].pb(v*3+1),to[u*3+1].pb(v*3+2),to[u*3+2].pb(v*3);
	}
	scanf("%d%d",&s,&t);
	bfs(s*3);
	printf("%d",((dis[t*3]-dis[s*3])%3==0)?(dis[t*3]-dis[s*3])/3:-1);
}

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

int main(){
    long long X;
    cin >> X;
    vector<long long> gojou;
    long long i, j;
    vector<long long>::iterator t;
    for(i=-1000; i<=1000; i++){
        gojou.push_back(i*i*i*i*i);
    }
    for(i=-1000; i<=1000; i++){
        t = lower_bound(gojou.begin(),gojou.end(),i*i*i*i*i-X);
        if(i*i*i*i*i-X==*t) break;
    }
    cout << i << " " << t-gojou.begin()-1000 << endl;
    system("pause");
    return 0;
}

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

using namespace std;
using ll =long long;
using db = double;
using vll = vector<long long>;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(a) {SORT(a);(a).erase(unique((a).begin(),(a).end()),(a).end());}
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
#define debug(x)  cout << #x << " = " << (x) << endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//グラフ用
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};	
//ここから書き始める

ll combination(ll n, ll i){
	ll count = 0;
	ll multi = 1;
	ll div =1;
	int limit = i;
	while(count < limit){
		multi *= n;
		n--;
		multi/= count+1;
		count ++ ;
	}
	return multi / div;
}

int main()
{
	cout <<setprecision(10);
	int c[3][3];
	rep(i,3){
		rep(j,3){
			cin >>c[i][j];
		}
	}
	rep(i,2){
		rep(j,2){
			if(c[i][j] - c[i+1][j] != c[i][j+1] - c[i+1][j+1]){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	rep(j,2){
		rep(i,2){
			if(c[i][j] - c[i+1][j] != c[i][j+1] - c[i+1][j+1]){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	coY();


}


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

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define lrp(i,n) for(long long i=0;i<n;i++)
#define lrep(i,m,n) for(long long i=m;i<=n;i++)
#define all(a) a.begin(),a.end()
#define pb push_back

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;

int main(){
    int h,w;
    cin >> h >> w;
    vs c(h);
    rp(i,h){
        cin >> c.at(i);
        cout << c.at(i) << endl;
        cout << c.at(i) << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <numeric>
#include <regex>
#include <climits>

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define RREP(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define forin(i, a) for(auto i: (a))
#define p(...) printf(__VA_ARGS__); cout << endl;
#define in(...) __VA_ARGS__; input__(__VA_ARGS__);
#define input(...) in(__VA_ARGS__)
#define out(...) output__(__VA_ARGS__);
#define output(...) out(__VA_ARGS__)
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](auto const &a, auto const &b){ return c ;}
#define key(t, x, compare) [](const t &a, const t &b){ return a x compare b x ;}
#define unless(a) if(!(a))

using namespace std;

using pii = pair<int, int>;

template <class... T>
void input__(T &...a) {
  for(auto v: {&a...}) {
    cin >> *v;
  }
}

void output__(){
  cout << endl;
}

template <class Head, class... T>
void output__(Head const &v, T const &...a) {
  if(sizeof...(a) == 0) {
    cout << v;
  } else {
    cout << v << " ";
  }
  output__(a...);
}

int main(){
  long in(n);
  string in(s);
  long counts = 0;
  FOR(i, 1, n) {
    if(s[i] == 'E') {
      counts++;
    }
  }

  vector<long> results;
  long minv = counts;
  FOR(i, 1, n) {
    if(s[i - 1] == 'W') {
      counts++;
    }
    if(s[i] == 'E') {
      counts--;
    }
    minv = min(minv, counts);
  }
  out(minv);
}


Measured memory_bytes: 900
import math

#入力
N = int(input())
minF = 100 #Fの最小値

#A = 1のとき
F = int(math.log10(N)) +1
if F < minF:
    minF = F
    
for A in range(2,int(math.sqrt(N)) + 1):
    #AがBの約数でなかったら飛ばす
    if N % A == 0:
        B = N / A
        #F = culculate_F(A,B)
        F = int(math.log10(B)) + 1
        #Fがこれまでで最小ならminFを更新
        if F < minF:
            minF = F

print(minF)

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	int x, sum = 0;
	for(int i = 0; i < m; i++){
		cin >> x;
		sum += x;
	}		
	if(sum > n) cout << "-1\n";
	else cout << n-sum << endl;
	return 0;
} 

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

int mintwo(int x)
{
    int ret=1;
    while(ret<=x)
        ret<<=1;
    return ret;
}
int main()
{
    int n;
    cin >> n;
    multiset<int> x;
    for(int i=0; i<n; i++)
    {
        int a;
        cin>>a;
        x.insert(a);
    }
    int ret=0;
    while(!x.empty())
    {
        auto itr=--x.end();
        auto now=*itr;
        x.erase(itr);
        int h=mintwo(now);
        h-=now;
        auto p=x.find(h);
        if(p!=x.end())
        {
            x.erase(p);
            ret++;
        }
    }
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 9600
#include<iostream>

using namespace std;

int main()
{
	int N,Q;
	int nAC[100001];
	string S;

	cin >> N >> Q >> S;

	for(int i=0;i<N+1;i++)
	{
		nAC[i] = 0;
	}
	nAC[0] = 0;
	nAC[1] = 0;
	int cnt = 0;
	for(int i=1;i<N;i++)
	{
		if(S.substr(i-1,2) == "AC")
		{
			cnt++;
			
		}
		nAC[i+1] = cnt;
	}

	/*for(int i=1;i<N+1;i++)
	{
		cout << i << ":" << nAC[i] << endl;
	}*/

	for(int i=0;i<Q;i++)
	{
		int l,r;
		cin >> l >> r;
		cout << nAC[r] - nAC[l] << endl;
	}



	return 0;
}

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

int main(){
    int second;

    cin >> second;

    int hour = second/3600;
    int minute = (second-hour*3600)/60;
    second = second-(hour*3600 + minute*60);

    cout << hour << ":" << minute << ":" << second << endl;

    return 0;
}


Measured memory_bytes: 3100
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	var s string
	fmt.Scan(&s)

	if n == 1 {
		fmt.Println("No")
		return
	}
	p := n / 2
	if s[0:p] == s[p:n] {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include<iostream>

const int mod = 1000000007;

struct mint {
	long long x;
	mint(long long x = 0) : x((x%mod + mod)%mod) {} 

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

	mint& operator += (const mint& a){
		if((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator -= (const mint& a){
		if ((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator *= (const mint& a) {
		(x *= a.x) %= mod;
		return *this;
	}

	mint operator + (const mint& a) const { return mint(*this) += a;}
	mint operator - (const mint& a) const { return mint(*this) -= a;}
	mint operator * (const mint& a) const { return mint(*this) *= a;}

	//べき乗
	mint pow(long long t) const{
		if(!t) return 1;
		mint a = pow(t >> 1); 
		a *= a;
		if(t&1) a *= *this;
		return a;
	}

	//逆元を求める
	mint inv() const {
		return pow(mod - 2);
	}
	//割り算　prime（素数）
	mint& operator /= (const mint a) { return (*this) *= a.inv(); }
	mint operator / (const mint a) const { return mint(*this) /= a; }
};
//入出力
std::istream& operator >> (std::istream& is, const mint& a) { return is >> a.x; }
std::ostream& operator << (std::ostream& os, const mint& a) { return os << a.x; }

long long sum(long long l, long long r){
	return (l + r)*(r - l + 1) / 2;
}

int main(){
	int n, k;
	std::cin >> n >> k;

	mint ans = 0;
	for(int i=k; i<=n+1; i++){
		long long mini = sum(0, i-1);
		long long maxi = sum(n-i+1, n);
		ans += maxi - mini + 1;
	}

	 std::cout << ans << std::endl;
	 return 0;

}

Measured memory_bytes: 3600
X, N = map(int,input().split())
p = list(map(int,input().split()))
hoge = {}
for i in p:
    hoge[i] = 1

m = X
while m in hoge:
    m -= 1
p = X
while p in hoge:
    p += 1
if p-X < X-m:
    print(p)
else:
    print(m)

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

int main(){
    string s;
    cin >> s;
    // int a=s.size(), z=0;
    // bool f = false;
    // rep(i, s.size()){
    //     if(!f && s[i]=='A'){
    //         a = i;
    //         f = true;
    //     }
    //     if(s[i]=='Z'){
    //         z = max(z, i);
    //     }
    // }
    // printf("%d\n", z-a+1);

    cout << s.rfind('Z') - s.find('A') +1 << endl; 
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
using namespace std;
int v[250005];
int sol[250005];
int pozitie[250005];
vector <int> c;
int main()
{
    int n;
    cin >> n;
    for(int i = 1; i <= n; i ++)
    {
        int a;
        cin >> a;
        v[a] = i;
        pozitie[i] = a;
    }
    int poz = 1;
    for(int i = 1; i <= n * n; i ++)
    {
        if(v[i] != 0)
        {
            int nr = v[i] - 1;
            while(poz < i && nr > 0)
            {
                if(v[poz] == 0)
                {
                    sol[poz] = v[i];
                    nr --;
                }
                poz ++;
            }
            if(nr > 0)
            {
                cout << "No";
                return 0;
            }
            sol[i] = v[i];
        }
    }
    for(int i = 1; i <= n * n; i++)
        if(v[i] > 0)
            for(int j = 1; j + v[i] <= n; j++)
                c.push_back(v[i]);
    poz = 0;
    for(int i = 1; i <= n * n; i ++)
    {
        if(sol[i] == 0)
        {
            if(i < pozitie[c[poz]])
            {
                cout << "No";
                return 0;
            }
            sol[i] = c[poz];
            poz++;
        }
    }
    cout << "Yes" << '\n';
    for(int i = 1; i <= n * n; i ++)
        cout << sol[i] << " ";
    return 0;
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int N; cin >> N;
    VI prime(N+1, 1); prime[0] = 0; prime[1] = 0;
    for(int i=2; i<sqrt(N)+1; i++){
        if(prime[i] == 0) continue;
        for(int j=i+i; j<=N; j+=i) prime[j] = 0;
    }

    VI factor(N+1,0);
    REP(i,N){
        if(prime[i+1]==0) continue;
        int n = i+1;
        while(n <= N){
            factor[i+1] += N/n;
            n *= i+1;
        }
    }

    VI cand(5,0);
    REP(i,N){
        if(factor[i+1] >= 74) cand[0]++;
        if(factor[i+1] >= 24) cand[1]++;
        if(factor[i+1] >= 14) cand[2]++;
        if(factor[i+1] >= 4) cand[3]++;
        if(factor[i+1] >= 2) cand[4]++;
    }

    int ans = 0;
    ans += cand[0];
    ans += cand[1]*(cand[4]-1);
    ans += cand[2]*(cand[3]-1);
    ans += cand[3]*(cand[3]-1)/2*(cand[4]-2);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

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

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    
    public void solve(){
        Scanner sc = new Scanner(System.in);
        int t;
        int n;
      for(int i=0;i<4;i++){
        t=sc.nextInt();
        n=sc.nextInt();
        if(t==1){
            System.out.println(6000*n);
        }else if(t==2){
            System.out.println(4000*n);
        }else if(t==3){
            System.out.println(3000*n);
        }else if(t==4){
            System.out.println(2000*n);
        }
    }
    }
  
   
    public static void main(String[] args){
        Main obj = new Main();
        obj.solve();
    }
}

Measured memory_bytes: 17292
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,q;
vector<int> G[200005];
ll sum[200005];

void dfs(int v,int p){
	for(int i=0;i<G[v].size();i++){
		if(G[v][i]==p)continue;
		sum[G[v][i]]+=sum[v];
		dfs(G[v][i],v);
	}
}

int main(void){
	scanf("%d%d",&n,&q);
	for(int i=0;i<n-1;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		a--;
		b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	for(int i=0;i<q;i++){
		int p,x;
		scanf("%d%d",&p,&x);
		p--;
		sum[p]+=x;
	}
	dfs(0,-1);
	for(int i=0;i<n;i++){
		printf("%lld%c",sum[i],i+1==n?'\n':' ');
	}
	return 0;
}


Measured memory_bytes: 27392
#include <cstdio>
#include <vector>
using namespace std;
vector <int> v[12];
int n,m,i,x,y,nr,sol;
bool s[12];
void  g (int x, int nr)
{
    int i;
    if (nr==n)
        sol++;
    for (i=0;i<v[x].size();i++)
    {
        if (s[v[x][i]]==false)
        {
            s[v[x][i]]=true;
            nr++;
            g(v[x][i],nr);
            nr--;
            s[v[x][i]]=false;
        }
    }
}
int main()
{
    scanf ("%d %d", &n, &m);
    for (i=1;i<=m;i++)
    {
        scanf ("%d %d", &x, &y);
        v[x].push_back(y);
        v[y].push_back(x);
    }
    for (i=2;i<=n;i++)
        s[i]=false;
    s[1]=true;
    g(1,1);
    printf ("%d", sol);
    return 0;
}


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

using namespace std;

int v[MAXN], dp[MAXN];

int res(int i, int n, int k){
	if(i == n-1) return 0;
	if(dp[i] != -1) return dp[i];
	int resp = INT_MAX;
	for(int j = i+1;j < i+k+1 && j < n;++j){
		// cout << j << " ";
		resp = min((int)fabs(v[j]-v[i]) + res(j, n, k), resp);
	}
	// cout << endl;
	return dp[i] = resp;
}

int main(){
	int n, k;
	cin >> n >> k;
	memset(dp, -1, sizeof(dp));
	for(int i = 0;i < n;++i){
		cin >> v[i];
	}
	cout << res(0, n, k) << endl;
}

Measured memory_bytes: 8832
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define ms multiset
#define pb push_back
#define pf push_front
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("board.in");ofstream out("board.out");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); //uid<int> u1(5, 10); u1(rnd);

int a,k,st,fn;
vec<vec<int>> l, was;
vec<int> o;
deque<int> m;

void dfs(int v, int step, int d){
    was[v][step] = 1;
    if(step==3){
        o[v] = d+1;
        m.pb(v);
        return;
    }
    for(int h : l[v]){
        if(!was[h][step+1]) dfs(h, step+1, d);
    }
}

int main() {
    fast;
    cin>>a>>k;
    m = deque<int>();
    l = vec<vec<int>>(a, vec<int>());
    was = vec<vec<int>>(a, vec<int>(4));
    o = vec<int>(a, 1e9);
    for(int q=0; q<k; q++){
        int x,y; cin>>x>>y; x--; y--;
        l[x].pb(y);
    }
    cin>>st>>fn; st--; fn--;
    o[st] = 0;
    was[st][3] = 1;
    m.pb(st);
    for(; m.size();){
        dfs(m.front(), 0, o[m.front()]);
        m.pop_front();
    }
    if(o[fn]==1e9) cout<<-1;
    else cout<<o[fn];
}

Measured memory_bytes: 11648