akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if((A == B && B == C) || (A != B && B != C && C != A)) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
MAX_N = 10**6+1
over = [0] * MAX_N
for i in xrange(2, MAX_N):
    for j in xrange(i+i, MAX_N, i):
        over[j] += (i-1)-over[i]
ans = [0] * MAX_N
ans[0] = 1
ans[1] = 2
for i in xrange(2,MAX_N):
    ans[i] = ans[i-1] + (i - 1) - over[i]
for _ in xrange(input()):
    print ans[int(raw_input())]

Measured memory_bytes: 65832
#include <stdio.h>

int main() {
	int x,i=1,j=1;
	
	while(j || i<=10000){
		scanf("%d",&x);
		if(x==0) { j=0;
		}else{	printf("Case %d: %d\n",i,x);
				i++;
				j=1;
				continue;
		}
	}
}


Measured memory_bytes: 2592
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<utility>
#include<cmath>
#include<assert.h>
#include<set>

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int N;
string S[330];

bool check(int a) {
    rep(i, N) {
        for (int j = i + 1; j < N; ++j) {
            //S'[i][j]==S'[j][i]??
            if (S[(i + a) % N][j] != S[(j + a) % N][i])return false;
        }
    }
    return true;
}

signed main() {
    cin >> N;
    rep(i, N) {
        cin >> S[i];
    }
    int ans = 0;
    rep(A, N) {
        if (check(A))ans += N;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int x;
    cin >> x;
    int now = 0;
    for(int i = 1;; i++){
        now += i;
        if(now >= x){
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int H,N;
    

    scanf("%d", &H);
    scanf("%d", &N);

    int i=0;
  int A[N];
  int sum = 0;
  for(i=0;i<N;i++){
	scanf("%d", &A[i]);
    sum = sum + A[i];
  }
   
  if(sum >= H){
	printf("Yes");
    return 0;
  }

    printf("No");
    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 a, b;
  cin >> a >> b;

  bool ok = false;
  int r;
  rep(i,3) {
    if ((a*b*(i+1))%2 != 0) {
      ok = true;
      break;
    }
  }
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}

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

int main(){
    int X, Y;
    std::cin >> X >> Y;
    
    bool ok = true;
    if(Y < X * 2){
        ok = false;
    }
    if(Y > X * 4){
        ok = false;
    }
    if(Y % 2 == 1){
        ok = false;
    }

    if(ok){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }
    
    return 0;
}



Measured memory_bytes: 3636
#pragma GCC optimize("Ofast","unroll-loops")
#pragma GCC target("avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (__typeof(a) i=(a); i<(b); ++i)
#define iter(it,c) for (__typeof((c).begin()) \
  it = (c).begin(); it != (c).end(); ++it)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
const int INF = ~(1<<31);

const double EPS = 1e-9;
const double pi = acos(-1);
typedef unsigned long long ull;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
template <class T> T smod(T a, T b) {
  return (a % b + b) % b; }


int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  vi stones(n);
  for(int& x : stones) {
    scanf("%d", &x);
  }
  vi dp(n, INF);
  dp[0] = 0;
  for(int i = 0; i < n; ++i) {
    for(int j = i+1; j <= i+k; ++j) {
      if(j < n) {
        dp[j] = min(dp[j], dp[i] + abs(stones[i] - stones[j]));
      }
    }
  }
  printf("%d\n", dp[n-1]);
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#include<bitset>
#include<stdio.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

bool isOK(int a[],int index,int key){
    if(a[index] >= key){
        return true;
    }else{
        return false;
    }
}

int binary_search(int a[],int n,int key){
    int left = -1;
    int right = n;

    while(right-left>1){
        int mid = left + (right - left)/2;
        if(isOK(a,mid,key)){
            right = mid;
        }else{
            left = mid;
        }
    }
    return right;
}



int main(void){
    int n;
    string s;
    cin >> n >> s;
    int count = 0;

    for(int i=0;i<10;++i){
        for(int j=0;j<10;++j){
            for(int k=0;k<10;++k){
                char pw1 = '0'+i;
                char pw2 = '0'+j;
                char pw3 = '0'+k;
                int check = 0;
                vector<char> pw(3);
                pw[0] = pw1; 
                pw[0] = pw2; 
                pw[0] = pw3; 
                int p1=n;
                int p2=n;
                int p3=n;

                for(int x=0;x<n;++x){
                    if(s[x] == pw1 && p1>x){
                        p1 = x;
                        check++;
                    }
                    if(s[x] == pw2 && p1<x && p2>x){
                        p2 = x;
                        check++;
                    }
                    if(s[x] == pw3 && p2<x && p3>x){
                        p3 = x;
                        check++;
                    }
                }
                if(check==3){
                        count++;
                }
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,n) for(int i=0;i<n;i++)
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    ll m = 1000000007;
    if(n<=1)cout << 0 << endl;
    else{
    	ll a=1,b=1,c=1;
    	while(n--){
    		a = (a*10)%m;
    		b = (b*9)%m;
    		c = (c*8)%m;
    	}
    	cout << (a-2*b+c+4*m)%m << endl;
    }


	return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int n;
    cin>>n;
    ll res=0;
    vector<vector<ll>> num(10,vector<ll>(10,0));
    for(int i=1;i<=n;i++){
        vector<int> d;
        int nn=i;
        while(nn){
            d.push_back(nn%10);
            nn/=10;
        }
        int a=d[0];
        int b=d.back();
        if(!a || !b) continue;
        num[a][b]++;
    }
    for(int a=1;a<10;a++){
        for(int b=1;b<10;b++){
            res+=num[a][b]*num[b][a];
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
#include <iostream>

int main(){
	int a, b;

	std::cin >> a >> b;
	if (a > b){
		std::cout << "a > b\n";
	}
	else if (a < b){
		std::cout << "a < b\n";
	}
	else{
		std::cout << "a == b\n";
	}
	return 0;
}

Measured memory_bytes: 1124
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] a = new int[n][d];

        for(int i = 0; i<n; i++) {
            for(int j = 0; j<d; j++) {
                a[i][j] = sc.nextInt();
            }
        }
        long cnt = 0;
        for(int i = 0; i<n; i++) {
            for(int j = i+1; j<n; j++) {
                double x = 0;
                for(int k = 0; k<d; k++) {
                    x += Math.pow(a[i][k] - a[j][k],2);
                }
                x = Math.sqrt(x);
                if((x-(long)(x)) == 0) cnt++;
            }
        }


        System.out.println(cnt);
    }
}

Measured memory_bytes: 21844
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  int n, q;
  string s;

  cin >> n >> q >> s;

  int ans[100000] = {};
  REP(i,n-1){
    ans[i+1] = ans[i];
    if(s[i] == 'A' && s[i+1] == 'C'){
      ans[i+1]++;
    }
  }

  REP(i,q){
    int l, r;
    cin >> l >> r;
    l--; r--;
    cout << ans[r] - ans[l] << endl;
  }
  return 0;
}



Measured memory_bytes: 1408
#include<iostream>

using namespace std;

int big_small(int y1,int m1,int d1,int y2,int m2,int d2){ /*-1 hidari 1 migi 0 onazi*/
	if(y1>y2) return -1;
	else if(y1<y2) return 1;
	else if(m1>m2) return -1;
	else if(m1<m2) return 1;
	else if(d1>d2) return -1;
	else if(d1<d2) return 1;
	return 0;
}

bool uruu(int y){
	if(y%400==0) return true;
	else if(y%100==0) return false;
	else if(y%4==0) return true;
	return false;
}

int get_day(int y,int m){
	if(m==1) return 31;
	else if(m==2){
		if(uruu(y)) return 29;
		return 28;
	}
	else if(m==3) return 31;
	else if(m==4) return 30;
	else if(m==5) return 31;
	else if(m==6) return 30;
	else if(m==7) return 31;
	else if(m==8) return 31;
	else if(m==9) return 30;
	else if(m==10) return 31;
	else if(m==11) return 30;
	else if(m==12) return 31;
	return -1;
}

int main(){

	int y1,m1,d1,y2,m2,d2;
	int c;

	while(1){

		cin>>y1>>m1>>d1>>y2>>m2>>d2;

		if(y1<0||m1<0||d1<0||y2<0||m2<0||d2<0) break;

		c=0;

		while(1){
			int tmpy=y1+1,tmpm=m1,tmpd=d1;
			if(big_small(tmpy,tmpm,tmpd,y2,m2,d2)==-1) break;
			if(m1>=3){
				if(uruu(y1+1)) c+=366;
				else c+=365;
			}
			else{
				if(uruu(y1)) c+=366;
				else c+=365;
			}
			y1=tmpy,m1=tmpm,d1=tmpd;
		}


		while(1){
			int tmpy=y1,tmpm=m1+1,tmpd=d1;
			if(tmpm==13) tmpy++,tmpm=1;
			if(big_small(tmpy,tmpm,tmpd,y2,m2,d2)==-1) break;
			c+=get_day(y1,m1);
			y1=tmpy,m1=tmpm,d1=tmpd;
		}

		while(1){
			int tmpy=y1,tmpm=m1,tmpd=d1+1;
			if(tmpd>get_day(y1,m1)) tmpm++,tmpd=1;
			if(tmpm==13) tmpy++,tmpm=1;
			if(big_small(tmpy,tmpm,tmpd,y2,m2,d2)==-1) break;
			c++;
			y1=tmpy,m1=tmpm,d1=tmpd;
		}

		cout<<c<<endl;
	}
}

Measured memory_bytes: 1160
n, q = map(int, input().split())
par = list(range(n))
size = [1] * n
def find(x):
    """ 根のノードの値を見つけて返す """
    if x != par[x]:
        par[x] = find(par[x])
    return par[x]

def unite(x, y):
    """xとyを結合する"""
    rootx = find(x)
    rooty = find(y)

    if rootx == rooty:
        return False
    else:
        if size[rootx] < size[rooty]:
            par[rootx] = rooty
            size[rooty] += size[rootx]
        else:
            par[rooty] = rootx
            size[rootx] += size[rooty]
        return True

def same(x, y):
    """ xとyが同じ集合に属しているか """
    return find(x) == find(y)

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


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

int main() {
	char c;
	cin >> c;
	if (c == 'a'|| c== 'e'|| c=='i'||c== 'o'||c== 'u') {
		cout << "vowel" << endl;
	} else {
		cout << "consonant" << endl;
	}
}

Measured memory_bytes: 3640
#include<cstdio>
#include<cmath>
int main(){
	int a,b,wb=0,k;
	scanf("%d%d",&a,&b);k=b;
	while(k){wb++;k/=10;}
	int w=a*ceil(pow(10,wb))+b;
	for(int i=1;i<=sqrt(w)+10;i++)
		if(i*i==w){printf("Yes\n");return 0;}
	printf("No\n");
}


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


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

struct edge {int to; ll cost; };

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

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

ll LCM(ll a, ll b){
  if(a<b) swap(a,b);
  return a/GCD(a,b)*b;
}
 
int main(){
  int n;
  cin >> n;
  map<string, int> m;
  int MAX = 0;
  for(int i=0; i<n; i++){
    string s;
    cin >> s;
    m[s]++;
    MAX = max(MAX, m[s]);
  }
  for(const auto& [key, value] : m){
    if(value == MAX) cout << key << endl;
  }
  return 0;
}


Measured memory_bytes: 19204
import numpy as np
import sys

N, M = [int(_) for _ in input().split()]

if M == 0:
    print("0 0")
    sys.exit()

P, S = np.array([[_ for _ in input().split()] for i in range(M)]).T

dict = {}
for i in range(M):
    if not (P[i] in dict):
        dict.update({P[i]: {"AC": False, "WA": 0}})

    value = dict[P[i]]

    if not value["AC"]:
        if S[i] == "AC":
            dict[P[i]] = {"AC": True, "WA": value["WA"]}
        else:
            dict[P[i]] = {"AC": False, "WA": value["WA"] + 1}

ac = sum(value["AC"] for value in dict.values())
wa = sum(value["WA"] if value["AC"] else 0 for value in dict.values())

print(f"{ac} {wa}")


Measured memory_bytes: 70064
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <tuple>

using namespace std;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;

int main(){
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<vector<int>> conn(n);
	for(int i = 0; i < m; ++i){
		int a, b;
		cin >> a >> b;
		--a; --b;
		conn[a].push_back(b);
		conn[b].push_back(a);
	}
	int q;
	cin >> q;
	vector<vector<pii>> table(n, vector<pii>(11, pii(0, -1)));
	priority_queue<tiii> pq;
	for(int i = 0; i < q; ++i){
		int r, d, c;
		cin >> r >> d >> c;
		--r;
		table[r][d] = pii(c, i);
		pq.emplace(i, r, d);
	}
	while(!pq.empty()){
		const int i = get<0>(pq.top());
		const int u = get<1>(pq.top());
		const int d = get<2>(pq.top());
		pq.pop();
		if(d == 0 || table[u][d].second != i){ continue; }
		for(const auto v : conn[u]){
			if(i > table[v][d - 1].second){
				table[v][d - 1] = pii(table[u][d].first, i);
				pq.emplace(i, v, d - 1);
			}
		}
	}
	for(int v = 0; v < n; ++v){
		int max_c = 0, max_i = -1;
		for(const auto p : table[v]){
			if(p.second > max_i){
				max_c = p.first;
				max_i = p.second;
			}
		}
		cout << max_c << '\n';
	}
	return 0;
}



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

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    string s;
    int k;
    while(cin >> s >> k)
    {
        int n = s.size();
        priority_queue<string> pq;
        set<string> st;
        for(int i = 0; i < n; i++)
            for(int m = 1; i + m <= n; m++)
            {
                string t = s.substr(i, m);
                if(pq.size() < k && st.find(t) == st.end())
                {
                    pq.push(t);
                    st.insert(t);
                }
                else if(t < pq.top() && st.find(t) == st.end()) 
                {
                    pq.pop();
                    pq.push(t);
                    st.insert(t);
                }
            }
        cout << pq.top() << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
n, k = list(map(lambda x: int(x), input().split(' ')))
result = 0
data = set()

for i in range(k):
  d = int(input())
  a = list(map(lambda x: int(x), input().split(' ')))

  for s in a:
    data.add(s)

print(n - len(data))


Measured memory_bytes: 9188
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

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

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}"<<endl;
  return o;
}

//逆元　a/b の modをとるとき -> a*modinv(b)%mod
long long modinv(long long a, long long m = 1e9+7) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m; 
  if (u < 0) u += m;
  return u;
}
ll const mod = 1e9+7;

// combination
const int MAX = 510000;
const ll MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

// べき乗
ll modpow(ll x, ll n) {
    x = x%MOD;
    if(n==0) return 1;  //再帰の終了条件

    else if(n%2==1) {
        return (x*modpow(x, n-1))%MOD;  //nが奇数ならnを1ずらす
    }
    else return modpow((x*x)%MOD, n/2)%MOD;  //nが偶数ならnが半分になる
}

int main() {
  ll X,K,D;
  cin >> X >> K >> D;
  X = abs(X);
  ll t = X/D;
  if (t>=K) {
    cout << X - K*D << endl;
    return 0;
  }
  t = K - t;
  if (t%2==0) {
    cout << X%D << endl;
  }
  else {
    cout << abs(X%D - D) << endl;
  }
}


Measured memory_bytes: 3640
K = input()
K_1 = int(K[-1])
K = int(K) 

mod_ini = 7%K
mod = 0
cnt = 0

while True:
    if K%2 == 0 or K_1 == 5:
        print(-1)
        break
    
    cnt += 1
    mod = (mod*10 + 7)%K
    #print(mod)
    
    if mod == 0:
        print(cnt)
        break
    elif mod == mod_ini and cnt != 1:
        print(-1)
        break

Measured memory_bytes: 63328
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}


signed main() {
  int n;
  cin >> n;
  int cs[100004] = {};
  int h[100001] = {};
  rep(i, 1, n) cs[i] = 1145141919;
  rep(i, 0, n) cin >> h[i];

  rep(i, 0, n) {
    cs[i + 1] = min(cs[i + 1], cs[i] + abs(h[i] - h[i + 1]));
    cs[i + 2] = min(cs[i + 2], cs[i] + abs(h[i] - h[i + 2]));
  }
  cout << cs[n - 1] << endl;
}


Measured memory_bytes: 1792
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 
 
	public static void main(String[] args) { 
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		long mod = 998244353;
		long[] depthCnt = new long[N+1]; 
		int max = 0;
		long START = -1;
		long numZero = 0;
		for (int i = 0; i < N; i++) {
			int x = input.nextInt();
			if (i==0) START=x;
			if (x==0) numZero++;
			depthCnt[x]++;
			max=Math.max(max, x);
		}
		if (START==0&&numZero==1) { //Vertex 1 cannot be treated generically since it is the root 
			//node in this problem AND V1 is the only allowed vertex with distance 0
			long ans = 1;
			for (int depth = 1; depth <= max; depth++){ //Starting from 1 since depth 0 must always 
				//be predecessor
				long numPrev = depthCnt[depth-1]; //Base of exponent
				long numCur = depthCnt[depth]; //Power of exponent
				long curans = FastExp(numPrev,numCur,mod);
				ans*=curans;
				ans%=mod;
			} 
			System.out.println(ans);
		}else System.out.println(0);
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans = 1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			base*=base;
			exp/=2;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
}

Measured memory_bytes: 62620
N = int(input())
A = [int(x) for x in input().split()]
A.sort(reverse=True)

ans = A[0]
N -= 2

for i in range(N // 2):
    ans += A[i + 1] * 2

if N & 1:
    ans += A[N // 2 + 1]

print(ans)

Measured memory_bytes: 31560
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
#include <cassert>
#include <unordered_map>
#include <chrono>
#include <random>
#include <ctime>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ld PI = 3.14159265358979323846;
const ll MOD = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());



int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	srand(time(0));
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int x, n;
	cin >> x >> n;
	map<int, int> p;
	for (int i = 0; i < n; i++) {
		int l;
		cin >> l;
		p[l] = 1;
	}
	int b = 1000, a = -1;
	for (int i = -100; i < 110; i++) {
		if (!p[i] && abs(i - x) < b) {
			b = abs(i - x);
			a = i;
		}
	}
	cout << a;
}

Measured memory_bytes: 3628
a=input()
while True:
    try:
        a+=(str(input()))
    except EOFError:
        break
b=str.lower(a)
for i in range(ord('a'),ord('z')+1):
    count=0
    print(chr(i),':',end=' ')
    for j in range(len(b)):
        c=ord(b[j])
        if i==c:
            count+=1
    print(count)


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

using namespace std;

#define FOR(i,n) for(int i = 0 ;i < (n); i++) 
#define sz(c) ((int)c.size())

class UF {
public:
	int n; vector<int> a;
	UF(int n) : n(n), a(n, -1) {}
	int find(int x) {
		return a[x] < 0 ? x : (a[x] = find(a[x]));
	}
	bool unite(int x, int y) {
		x = find(x), y = find(y);
		if (x == y) return false;
		if (a[x] > a[y]) swap(x, y);
		a[x] += a[y];
		a[y] = x;
		n--;
		return true;
	}
	int size(int x) {
		return -a[find(x)];
	}
};

struct P {
	P() {}
	int x, y;
	P(int x, int y) : x(x), y(y) {}
	P operator+(const P& r) const {
		return P(x + r.x, y + r.y);
	}
	P operator-(const P& r) const {
		return P(x - r.x, y - r.y);
	}
};

int cross(P& l, P& r) {
	return l.x * r.y - l.y * r.x;
}
bool on(P a, P b, P c) {
	b = b - a;
	c = c - a;
	return cross(b, c) == 0;
}

P center(P& l, P& r) {
	return P((l.x + r.x) / 2, (l.y + r.y) / 2);
}

struct L {
	P o; P dir;
	L(){};
};

L l[8][8];
bool b[8][8][8][8];

map<vector<int>, int> mp;
int dfs(vector<int> f) {
	if (mp.count(f)) return mp[f];

	bool end = true;
	FOR(i, sz(f)) {
		if (f[i] != 0) end = false;
	}
	if (end) {
		return mp[f] = 0;
	}

	int ans = 100;
	FOR(i, sz(f)) {
		FOR(j, i) {
			if (f[i] == f[j]) continue;
			auto copyed = f;
			FOR(a, sz(f)) FOR(b, a) {
				if (f[b] == f[a]) continue;
				bool er = ::b[i][j][a][b];
				if (er) {
					int to = f[b];
					int from = f[a];
					FOR(c, sz(f)) if (f[c] == from) f[c] = to;
				}
			}
			ans = min(ans,dfs(f));
			f = copyed;
		}
	}

	return mp[f] = ans + 1;
}

int main() {
	int n; cin >> n;
	vector<P> vp;
	FOR(i, n) {
		int x, y; cin >> x >> y; vp.emplace_back(x * 2, y * 2);
	}
	FOR(i, n) FOR(j, n) {
		if (i == j) continue;
		l[i][j].o = center(vp[i], vp[j]);
		auto d = vp[i] - vp[j];
		l[i][j].dir = P(-d.y, d.x);
	}
	FOR(i, n) FOR(j, n) {
		if (i == j) continue;
		FOR(a, n) FOR(b, n) {
			if (a == b) continue;
			bool x = on(l[i][j].o, l[i][j].o + l[i][j].dir, l[a][b].o);
			bool y = on(l[i][j].o, l[i][j].o + l[i][j].dir, l[a][b].o + l[a][b].dir);
			::b[i][j][a][b] = x && y;
		}
	}

	vector<int> p(n);
	FOR(i, n) p[i] = i;

	int ans = dfs(p);
	cout << ans << endl;
}

Measured memory_bytes: 4560
# -*- coding: utf-8 -*-
from collections import deque
n,m = map(int, input().split())
edge = {}
for _ in range(m):
    l,r,d = map(int,input().split())
    if l not in edge:
        edge[l] = []
    edge[l].append([r,d])
    if r not in edge:
        edge[r] = []
    edge[r].append([l,-1*d])
# print(edge)
x = [None for _ in range(n+1)]

for i in range(1,n+1):
    if x[i] is None:
        x[i] = 0
        q = deque([i])
        while len(q)>0:
            v = q.popleft()
            if v not in edge:
                break
            for u,d in edge[v]:
                # print(v,u,d,x)
                if x[u] is None:
                    x[u] = x[v]+d
                    q.append(u)
                elif x[u]!=x[v]+d:
                    print("No")
                    exit()
        # print(x)

print("Yes")


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

using ll = long long;
using pii = pair<int, int>;

constexpr int INF = 1e9;
constexpr ll INFLL = 1e18;

int main() {
    int H, N; cin >> H >> N;
    vector<int> state(H + 1);
    for(int i = 0; i < N; ++i) {
        int x, y; cin >> x >> y;
        state[y] |= (1 << x);
    }
    state[H] = 0b1111;

    vector<vector<int>> dp(H + 1, vector<int>(1 << 4));
    for(int i = 0; i < H; ++i) {
        int no_put = 0;
        for(int S = 0; S < (1 << 4); ++S) {
            if((state[i] & S) != state[i]) continue;
            no_put = max(no_put, dp[i][S]);

            if(S == 0 && state[i + 1] == 0) { // put two
                dp[i + 1][0b1111] = max(dp[i + 1][0b1111], dp[i][S] + 2);
            }

            for(int j = 0; j < 3; ++j) { // put one
                if((S & (0b0011 << j)) == 0 && (state[i + 1] & (0b0011 << j)) == 0) {
                    int nS = state[i + 1] | (0b0011 << j);
                    dp[i + 1][nS] = max(dp[i + 1][nS], dp[i][S] + 1);
                }
            }
        }
        dp[i + 1][state[i + 1]] = max(dp[i + 1][state[i + 1]], no_put);
    }

    cout << dp[H].back() << endl;
}


Measured memory_bytes: 3912
#include <bits/stdc++.h>
using namespace std;
using LL = long long; using PII = pair<LL, LL>; using VI = vector<LL>; using VVI = vector<VI>;
using VB = vector<bool>; using VS = vector<string>; using VP = vector<PII>;
#define VV(T)        vector<vector<T>>
#define PB           push_back
#define MP           make_pair
#define SZ(a)        LL((a).size())
#define EACH(x, c)   for (auto x : (c))
#define ALL(c)       (c).begin(), (c).end()
#define REVERSE(c)   reverse(ALL(c))
#define SORT(c)      stable_sort(ALL(c))
#define RSORT(c)     stable_sort((c).rbegin(), (c).rend())
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n)    FOR(i, 0, n)
#define $(x)         {cout << #x << " = " << (x) << endl;}

const string YES = "Yes";
const string NO = "No";

void solve(LL N, vector<LL> a){
    LL sum = 0;
    unordered_map<LL, LL> m;
    REP(i, N) {
        sum += a[i];
        m[a[i]]++;
    }
    if (sum == 0) {
        cout << YES << endl;
        return;
    }
    VI e;
    EACH(mm, m) {
        e.PB(mm.first);
    }
    if (SZ(m) == 2) {
        if (e[0] == 0) {
            if (m[e[0]] * 2 == m[e[1]]) {
                cout << YES << endl;
                return;
            }
        } else if (e[1] == 0) {
            if (m[e[1]] * 2 == m[e[0]]) {
                cout << YES << endl;
                return;
            }
        }
    }
    if (SZ(m) == 3) {
        if ((e[0] ^ e[1] ^ e[2]) == 0 && m[e[0]] == m[e[1]] && m[e[1]] == m[e[2]]) {
            cout << YES << endl;
            return;
        }
    }
    cout << NO << endl;
}

int main(){
    LL N;
    scanf("%lld",&N);
    vector<LL> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, move(a));
    return 0;
}


Measured memory_bytes: 5796
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
	long long a,b,c,temp;
	cin>>a>>b>>c;
	temp = c-a-b;
	if(temp<=0)
		cout<<"No\n";
	else if(temp*temp>4*a*b){
		cout<<"Yes\n";
	}
	else
		cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
def gi; gets.to_i end
def gs; gets.chomp end
def gli; gets.split(' ').map(&:to_i) end
def d(n); Math.log10(n).to_i + 1 end

N = gi
coordinates = []
N.times do
  coordinates << gli
end

def dist(p1, p2)
  Math.sqrt((p1[0] - p2[0])**2 + (p1[1] - p2[1])**2)
end

total_dist = 0
permutations = coordinates.permutation(N).to_a
permutations.each do |coordinate|
  coordinate.each_cons(2) do |p1, p2|
    total_dist += dist(p1, p2)
  end
end

puts total_dist / permutations.length.to_f


Measured memory_bytes: 8700
def Factorial(A):
    MOD = 10**9+7
    X = 1
    for num in range(1, A+1):
        X *= num
        X %= MOD
    return X

n, m = map(int, input().split())
MOD = 10**9+7

if n == m+1:
    ans = Factorial(n)*Factorial(m)
elif n == m:
    ans = Factorial(n)*Factorial(m)*2
elif n+1 == m:
    ans = Factorial(n)*Factorial(m)
else:
    ans = 0
print(ans%MOD)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;

const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    n += 2;
    vector<ll> v(n, 0), sum(n + 1, 0);
    rep(i, n) cin >> v[i + 1];
    rep(i, n - 1) sum[i + 1] = sum[i] + labs(v[i + 1] - v[i]);
    //rep(i, n) cerr << sum[i] << endl;
    rep(i, 1, n - 1)
    {
        cout << sum[i - 1] + (sum[n - 1] - sum[i + 1]) + labs(v[i - 1] - v[i + 1]) << endl;
        ;
    }
    return 0;
}


Measured memory_bytes: 2816
A, B, C = map(int, input().split())
dA, dB, dC = B - C, C - A, A - B
Ex = 0
if A % 2 == 1 or B % 2 == 1 or C % 2 == 1:
  Ex = 0
elif A == B and B == C:
  Ex = -1
else:
  while dA % 2 == 0 and dB % 2 == 0 and dC % 2 == 0:
    dA //= 2
    dB //= 2
    dC //= 2
    Ex += 1
print(Ex)

Measured memory_bytes: 3064
N,K=gets.split.map(&:to_i)
S=gets.strip
cnt=0
seq=0
cur=S[0]
for i in 0..S.size-1
    seq+=1
    if S[i]!=cur
        cnt+=seq-1
        seq=0
        cur=S[i]
    end
end
cnt+=seq-1
puts [S.size-1,cnt+K*2].min


Measured memory_bytes: 1916
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const int nax=1000*1007;

int n;
ll tab[nax];

ll s;

ll pre[nax];
ll suf[nax];

ll dp[nax];

void wypisz(ll v)
{
	debug() << imie(v);
	printf("%lld %lld\n", (s+v)/2, (s-v)/2);
	exit(0);
}

int main()
{
	scanf("%d", &n);
	for (int i=1; i<=n; i++)
	{
		scanf("%lld", &tab[i]);
		s+=tab[i];
	}
	ll x=0;
	for (int i=2; i<=n; i+=2)
		x+=tab[i];
	if (!(n&1))
		wypisz(max(x, s-x)-min(x, s-x));
	//~ ll wyn=max(x, s-x)-min(x, s-x);
	for (int i=1; i<=n; i++)
		pre[i]=tab[i]-pre[i-1];
	//~ for (int i=n; i; i--)
		//~ suf[i]=tab[i]-suf[i+1];
	//~ for (int i=2; i<=n; i+=2)
		//~ wyn=max(wyn, min(pre[i]+abs(suf[i+1]), abs(pre[i-1])+suf[i]));
	//~ wypisz(wyn);
	ll wyn=x-(s-x);
	
	ll bsa=-1e9;
	ll bsb=1e9;
	ll bss;
	while(bsa<bsb)
	{
		bss=(bsa+bsb+2)>>1;
		
		ll naj=0;
		for (int i=1; i<=n; i++)
			dp[i]=0;
		dp[0]=1;
		for (int i=1; i<=n; i+=2)
		{
			if (pre[i]-bss>=naj)
			{
				dp[i]=1;
				naj=min(naj, -pre[i+1]);
			}
		}
		
		
		
		if (dp[n])
			bsa=bss;
		else
			bsb=bss-1;
	}
	debug() << imie(bsa);
	
	wyn+=2*bsa;
	
	wypisz(wyn);
	return 0;
}


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

void printAll(std::vector<int> A) {
    for (int i = 0; i < (A.size()-1); i++) {
        std::cout << A[i] << " ";
    }
    std::cout << A.back() << std::endl;
}

int main()
{
    int N;
    std::cin >> N;
    std::vector<int> A(N);
    for (int i = 0; i < N; i++) {
        std::cin >> A[i];
    }
    printAll(A);

    int v, j;
    for (int i = 1; i < N; i++) {
        v = A[i];
        j = i - 1;
        while (j >= 0 & A[j] > v) {
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        printAll(A);
    }

}


Measured memory_bytes: 3100
#include "bits/stdc++.h"
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
const int MOD=1000000007;
#define endl "\n"
#define fst first
#define snd second
const ll UNDEF = -1;
const ll INF=1e18;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int mn=1e5+4;

ll getk(ll ab) {
  ll imin=0,imax=1e9+2;
  while(imin<imax) {
    ll imid=(imin+imax)>>1;
    if (imid*(imid+1)<ab-1) imin=imid+1;
    else imax=imid;
  }
  return imin;
}

ll solve(ll a, ll b) {
  if (a==1) {
    return 0;
  }
  ll ab=a*(ll)b;
  ll k=getk(ab);
  ll alim=min(a-1,(ab-1)/(b+1));
  if (alim<=0) return 0;
  ll L=min(k,alim);
  ll R=0;
  //if  (k+1<=alim) {
  {
    ll hib=(ab-1)/k - 1;
    ll lob=max(b+1,((ab-1)/alim));
    if (lob<=hib) R=hib-lob+1;
    //printf("a:%lld b:%lld lob:%lld hib:%lld L:%lld R:%lld k:%lld alim:%lld\n"
    //  ,a,b,lob,hib,L,R,k,alim);

  }
  return L+R;
}

int main()
{
  ios_base::sync_with_stdio(false); cin.tie(0);
  int q; scanf("%d",&q);
  for (int qi=0;qi<q;qi++) {
    int a,b; scanf("%d%d",&a,&b);
    ll ans=solve(a,b)+solve(b,a);
    printf("%lld\n",ans);

  }
}

Measured memory_bytes: 256
#include <chrono>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    return a;
}

#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 10;
//    const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 179;
//    const ld PI = 3.1415926535;
#endif

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,sse3,sse4")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("fast-math")
//#pragma GCC target("avx2")
//#pragma GCC optimize("section-anchors")
//#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
//#pragma GCC optimize("vpt")
//#pragma GCC optimize("rename-registers")
//#pragma GCC optimize("move-loop-invariants")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC optimize("function-sections")
//#pragma GCC optimize("data-sections")

const int mod = 1e9 + 7;

int powmod(int a, int p) {
    if (p == 1) return a % mod;
    int k = powmod(a, p / 2);
    if (p & 1) return (((k * k) % mod) * a) % mod;
    else return (k * k) % mod;
}

const int MAXN = 1e5 + 1;

int f[MAXN];

int c(int n, int k) {
    return (f[n] * ((powmod(f[k], mod - 2) * powmod(f[n - k], mod - 2)) % mod)) % mod;
}

void sub(int& ans, int k) {
    if (k <= 0) {
        k = abs(k);
        k %= mod;
        ans += k;
        ans %= mod;
    } else {
        k %= mod;
        k = mod - k;
        ans += k;
        ans %= mod;
    }
}

void add(int& ans, int k) {
    sub(ans, -k);
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef LOCAL
    #else
//        freopen("capitals.in", "r", stdin);
//        freopen("capitals.out", "w", stdout);
    #endif
    f[0] = 1;
    for (int i = 1; i < MAXN; i++) f[i] = (f[i - 1] * i) % mod;
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(all(a));
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (i >= k - 1) {
            add(ans, (a[i] * c(i, k - 1)) % mod);
        }
        if (n - i >= k) {
            sub(ans, (a[i] * c(n - i - 1, k - 1)) % mod);
        }
    }
    cout << ans;
}
/*
3 2
*/


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

#define INF 2e9

#define REP(i,n) for(int i = 0; i < n;++i)
#define REPA(i,a,n) for(int i = a; i < n; ++i)
#define REPR(i,a) for(int i = a; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;

int gcd(int a, int b){ return b ? gcd(b, a % b) : a; }
template<typename A> void psn(A a){ cout << a << endl; }
template<typename A, typename... B> void psn(A a, B... b){ cout << a << ' '; psn(b...); }

int main(void) {
    
    int N;
    
    cin >> N;
    
    if(N % 2 == 0){
        psn((N / 2) - 1);
    } else {
        psn((N / 2));
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll n,m,a,r,c,h;
  string s;
  cin>>n;
  map<char,ll> mp;
  for(int i=0;i<n;i++){
    cin>>s;
    mp[s[0]]++;
  }
  m=mp['M'],a=mp['A'],r=mp['R'],c=mp['C'],h=mp['H'];
  cout<<m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h;
}

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


int main(){
  int h;
  int w;
  cin >> h >> w;
  vector<vector<int>> c(10,vector<int>(10));
  vector<int> numcnt(10);
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      cin >> c.at(i).at(j);
    }
  }
  vector<vector<int>> a(h,vector<int>(w));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> a.at(i).at(j);
      if(a.at(i).at(j) != -1){
        numcnt.at(a.at(i).at(j))++;
      }
    }
  }
  vector<vector<int>> shortest(10,vector<int>(10));
  //shortest.at(i).at(j)はiからjにいくまでの経路のvector (i含まない
  //WF INITIAL
  rep(i,10){
    rep(j,10){
      shortest.at(i).at(j) = c.at(i).at(j);
    }
  }
  //WF CORE
  rep(k,10){
    rep(i,10){
      rep(j,10){
        if(shortest.at(i).at(k) + shortest.at(k).at(j) < shortest.at(i).at(j)){
          shortest.at(i).at(j) =shortest.at(i).at(k) + shortest.at(k).at(j);
        }
      }
    }
  }
  //cout << shortest.at(8).at(1);
  int64_t sum = 0;
  rep(i,10){
    if(i != 1){
      sum += shortest.at(i).at(1) * numcnt.at(i);
    }
  }
  
  cout << sum << endl;
  
}
  

Measured memory_bytes: 384
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    s,t = input().rstrip().split()
    res = ''
    for i in range(n):
        res += s[i]
        res += t[i]
    print(res)

if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    long long INF = 1e18;
    cin >> N;
    long long d[N][N];
    vector<long long> a[N];
    for(int i = 0; i < N; i++){
        string s;
        cin >> s;
        for(int j = 0; j < s.size(); j++){
            d[i][j] = INF;
            if(s[j] == '1'){
                a[i].push_back(j);
                d[i][j] = 1;
                d[j][i] = 1;
            }
        }
        d[i][i] = 0;
    }
    for(int k = 0; k < N; k++){
        for(int i = 0; i < N; i++){
            for(int j = 0; j < N; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        }
    }
    int flag = 0;
    vector<int> co(N, 0);
    for(int i = 0; i < N; i++){
        if(d[0][i] % 2 == 0) co[i] = -1;
        else co[i] = 1;
    }
    for(int i = 0; i < N; i++){
        for(int j: a[i]){
            if(co[j] == co[i]){
                flag = 1;
                break;
            }
        }
    }
    if(flag == 1) cout << -1 << endl;
    else{
        long long ans = 0;
        for(int i = 0; i < N; i++){
            for(int j = 0; j < N; j++){
                if(d[i][j] != INF && ans < d[i][j]) ans = d[i][j];
            }
        }
        cout << ans + 1 << endl;
    }
}

Measured memory_bytes: 1024
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using vi = vector<int>;
using vl = vector<int64_t>;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;
const int64_t INF64 = (1LL<<62) - 1;
const int MOD = 1000000007;
char in[1<<21];
char const*o;

inline void init_in() { 
  o = in;
  in[fread(in,1,sizeof(in)-4,stdin)] = 0;
}

int readInt(){ 
  unsigned u = 0, s = 0;
  while(*o && *o <= 32){
    ++o;
  }
  if (*o == '-'){
    s = ~s, ++o;
  } else if (*o == '+'){
    ++o;
  }
   
  while(*o>='0' && *o<='9'){
    u = (u<<3) + (u << 1) + (*o++ - '0');
  }

  return static_cast<int>((u^s) + !!s) ;
}
template<typename T> void fastin(T &num) {
  bool negative = false;
  T c;
  num = 0;
  c = getchar_unlocked();
  if (c == '-') {
    negative = true;
    c = getchar_unlocked();
  }
  for (; (c > 47 && c < 58); c = getchar_unlocked()) num = (num << 3) + (num << 1) + c - 48;
  if (negative) num *= -1;
}
int main(){
  //ios_base::sync_with_stdio(false);
  //cin.tie(nullptr);

  //it_in();
  int n; fastin(n);
  vector<int> a(n);
  rep(i, n) fastin(a[i]);

  for (int i = n - 1; i >= 1; --i) {
    if (a[i] < a[i - 1]) {
      --a[i - 1];
    }
  }

  for (int i = 0; i < n - 1; ++i) {
    if (a[i] > a[i + 1]) {
      print("No"); return 0;
    }
  }

  print("Yes");

  return 0;
}


Measured memory_bytes: 640
import java.io.*;
import java.util.*;

class Main{
	static boolean[] arr;
	public static void main(String[] args) throws Exception{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		char[] str = reader.readLine().toCharArray();
		arr = new boolean[n];
		for(int i = 0; i < n; i++) arr[i] = str[i]=='o';
		boolean[] animal = new boolean[n+1];
		animal[0] = true;	animal[1] = true;
		if(calc(animal)) return;
		animal[0] = false;	animal[1] = false;
		if(calc(animal)) return;
		animal[0] = true;	animal[1] = false;
		if(calc(animal)) return;
		animal[0] = false;	animal[1] = true;
		if(calc(animal)) return;
		System.out.println(-1);
	}

	static boolean calc(boolean[] animal) {
		for(int i = 0; i < animal.length-2; i++) {
			animal[i+2] = !(animal[i+1]^!(animal[i]^arr[i+1]));
		}
		boolean result = animal[animal.length-1]==animal[0];
		boolean last = !(animal[0]^!(animal[1]^arr[0]));
		result &= last==animal[animal.length-2];
		if(result) {
			StringBuilder sb = new StringBuilder();
			for(int i = 0; i < animal.length-1; i++) sb.append((animal[i])?'S':'W');
			System.out.println(sb.toString());
		}
		return result;
	}
}


Measured memory_bytes: 27828
#include <bits/stdc++.h>
#include<chrono>
using namespace std;
using ll = long long;
 
int main() {
  string N;
  cin >> N;
  bool a = false;
  for (int i = 0; i < 3; i++) {
    if (N.at(i) == '7') {
      a = true;
    }
  }
  if (a) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}
 

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

int main() {
  int n;
  cin >> n;
  vector<int> A(n + 1);
  vector<int> B(n);
  for (int i = 0; i < n + 1; i++) cin >> A[i];
  for (int i = 0; i < n; i++) cin >> B[i];

  long long cnt = 0;
  for (int i = 0; i < n; i++) {
    if (A[i] <= B[i]) {
      cnt += A[i];
      if (A[i + 1] + A[i] - B[i] >= 0) {
        A[i + 1] -= B[i] - A[i];
        cnt += B[i] - A[i];
      }
      else {
        cnt +=  A[i + 1];
        A[i + 1] = 0;
      }
    }
    else cnt += B[i];
  }
  cout << cnt << endl;
}


Measured memory_bytes: 1024
#!/usr/bin/perl
use List::Util qw(min);
my ($n) = map { $_ - 0 } split(/\s+/,<STDIN>);
my @h = map { $_ - 0 } split(/\s+/,<STDIN>);

my @m = ();
$m[0] = 0;
$m[1] = abs($h[0] - $h[1]);
for(my $i=2;$i<$n;$i++){
  $m[$i] = min ( $m[$i-2] + abs($h[$i-2]-$h[$i]) , $m[$i-1] + abs($h[$i-1]-$h[$i]) );
}
print "$m[$n-1]\n";

exit(0);



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

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

  int minV = 100000000, sum;
  for ( int i = 1; i <= 100; i++){
    sum = 0;
    for ( int j = 0; j < n; j++){
      sum += pow(x[j]-i, 2);
    }

    minV = min(minV,sum);
  }

  cout << minV << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void){
 int N;
  cin>>N;
  
  int n=1000;
  int t = N/n;
  int m = N%n;
  if(m!=0){
    cout<<n*(t+1)-N<<endl;
  }else{
    cout<<n*t-N<<endl;
  }
  return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<functional>
//#define test
using namespace std;
typedef long long ll;
int n,m;
ll p[3][1000];
ll sot[2][2][2][1000];
ll res;
int main()
{
#ifdef test
  freopen("in.txt","r",stdin);
  freopen("out.txt","w",stdout);
#endif
  cin>>n>>m;
  for (int i=0;i<n;i++)
    for (int j=0;j<3;j++)
      cin>>p[j][i];
  for (int i=0;i<2;i++)
    for (int j=0;j<2;j++)
      for (int k=0;k<2;k++)
      {
        for (int s=0;s<n;s++)
        {
          ll x=p[0][s];
          if (i==1)
            x*=-1;
          sot[i][j][k][s]+=x;
          x=p[1][s];
          if (j==1)
            x*=-1;
          sot[i][j][k][s]+=x;
          x=p[2][s];
          if (k==1)
            x*=-1;
          sot[i][j][k][s]+=x;
        }
        sort(sot[i][j][k],sot[i][j][k]+n,greater<ll>());
  }
  for (int i=0;i<2;i++)
    for (int j=0;j<2;j++)
      for (int k=0;k<2;k++)
      {
        ll ans=0;
        for (int s=0;s<m;s++)
          ans+=sot[i][j][k][s];
        if (ans>res) res=ans;
      }  
  cout<<res<<endl;
  //system("pause");
  return 0;
}


Measured memory_bytes: 384