akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
#include <complex>
#include <assert.h>
 
using namespace std;
 
typedef long long ll;
typedef pair <double,double> P;
 
static const int tx[] = {+0,+1,+0,-1};
static const int ty[] = {-1,+0,+1,+0};
 
static const double EPS = 1e-8;

int table[3][3];

bool check(int mod){
  set<int> result;
  for(int y = 0; y < 3; y++){
    int sum = 0;
    for(int x = 0; x < 3; x++){
      sum += table[y][x];
    }
    result.insert(sum % mod);
  }
  if(result.size() > 1) return false;

  for(int x = 0; x < 3; x++){
    int sum = 0;
    for(int y = 0; y < 3; y++){
      sum += table[y][x];
    }
    result.insert(sum % mod);
  }
  if(result.size() > 1) return false;

  result.insert((table[0][0] + table[1][1] + table[2][2]) % mod);
  result.insert((table[0][2] + table[1][1] + table[2][0]) % mod);
  return (result.size() == 1);
}

int dfs(int pos,int used,int mod){
  if(pos >= 9 && check(mod)){
    return 1;
  }
  else if(pos >= 9){
    return 0;
  }
  int res = 0;
  int x = pos % 3;
  int y = pos / 3;

  if(table[y][x] == 0){
    for(int i = 1; i <= 10; i++){
      if(used & (1<<i)) continue;
      table[y][x] = i;
      res += dfs(pos + 1, used | (1<<i),mod);
      table[y][x] = 0;
    }
  }
  else{
    res += dfs(pos + 1, used,mod);
  }
  return res;
}

int main(){
  while(~scanf("%d",&table[0][0])){
    int used = 0;
    if(table[0][0] != 0){
      used |= (1<<table[0][0]);
    }

    for(int y = 0; y < 3; y++){
      for(int x = 0; x < 3; x++){
        if(y == 0 && x == 0) continue;
        scanf("%d",&table[y][x]);
        if(table[y][x] != 0){
          used |= (1<<table[y][x]);
        }
      }
    }
    int mod;
    scanf("%d",&mod);
    if(mod == -1) break;

    used |= (1<<mod);
    int res = 0;
    if(mod == 0){
      int prev = used;
      for(int i = 1; i <= 10; i++){
        if(used & (1<<i)) continue;
        used |= (1<<i);
        mod = i;
        res += dfs(0,used,mod);
        used = prev;
      }
    }
    else{
      res += dfs(0,used,mod);
    }
    printf("%d\n",res);
  }
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  string a;
  cin >> n >> k;
  char d[k];
  for(int i=0; i<k; i++){
    cin >> d[i];
  }
  while(1){
    a = to_string(n);
    for(int i=0; i<a.size(); i++){
      for(int j=0; j<k; j++){
        if(a[i] == d[j]){
          n++;
          i=a.size()-1;
          j=k-1;
        }else{
          if(i==a.size()-1 && j==k-1){
            cout << n << endl;
            return 0;
          }
        }
      }
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iomanip>
#include<sstream>
#include<map>
#include<cmath>
using namespace std;
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1;i <=n;i++)
#define rrep(i,n) for(int i = n -1;i >= 1;i--)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
typedef long double ld;
const ll MOD =  1000000007;
const ll INF =  1LL << 60;
ll n, m, x = 0, y,z,w,h, sum= 0, ans = 0;
int main(void) {
    cin >> n >> m;
    if (n > 9 || m > 9) {
        cout << -1 << endl;
    }
    else {
        cout << n * m << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long ll;

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}

ll calc(ll n, int x, int y) {
    return n - n / x - n / y + n / (1ll * x / gcd(x, y) * y);
}

int main() {
    ll a, b;
    int c, d;
    cin >> a >> b >> c >> d;

    cout << calc(b, c, d) - calc(a - 1, c, d) << endl;

    return 0;
}

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

int main() {
  string S, T; cin >> S >> T;
  vector<int> table1(30, 0);
  vector<int> table2(30, 0);

  for(int i=0; i<S.size(); ++i) {
    char si = S[i]-'a';
    char ti = T[i]-'a';
    table1[ti]++;
    table2[si]++;
    if(table1[ti] != table2[si]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 776
/*
 * 3000_The_Mean_of_Angle.c
 *
 *  Created on: 2019/05/25
 *      Author: nagashima
 */

#include <stdio.h>

int main(void){
	double s1,s2;
	double t;
	double res;

	scanf("%lf",&s1);
	scanf("%lf",&s2);
	if(s1>s2){
		t=s2;
		s2=s1;
		s1=t;
	}

	res = s1+(s2-s1)/2;
	if(s2-s1>180)res+=180;
	if(res>360)res-=360;

	printf("%f\n",res);

	return 0;
}



Measured memory_bytes: 2104
s = list(input())
q = int(input())
l1 = []
l2 = []
rev = False
for i in range(q):
    inp = input()
    if inp[0] == "1":
        if rev:
            rev = False
        else:
            rev = True
    elif inp[2] == "1":
        a = inp[4]
        if rev:
            l2.append(a)
        else:
            l1.append(a)
    else:
        a = inp[4]
        if rev:
            l1.append(a)
        else:
            l2.append(a)
l1.reverse()
ans = l1 + s + l2
if rev:
    ans.reverse()
print("".join(ans))

Measured memory_bytes: 106200
import re
def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    array_result.append(data.split(" "))

    flg = 1

    try:

        while flg:

            data = input()
            if(data != ""):
                
                array_result.append(data.split(" "))

            else:

                flg = 0
    finally:


        return array_result

arr_data = getinputdata()

s = arr_data[0][0]

pattern="^(erase|eraser|dream|dreamer){1,}$"

if(re.search(pattern,s)):
    
    print("YES")

else:
    
    print("NO")


Measured memory_bytes: 6516
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N, K, Q;
    cin >> N >> K >> Q;

    int P[N+1], A;
    for(int i=1;i<=N;i++)
        P[i] = K - Q;
    for(int i=0;i<Q;i++){
        cin >> A;
        P[A]++;
    }

    int ans = 0;
    for(int i=1;i<=N;i++){
        if(P[i] > 0)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>

int main(){
	int multiples,low,high;
	scanf("%d",&multiples);
	getchar();
	scanf("%d%d",&low,&high);
	bool found = true;
	for(int i=low;i<=high;i++){
		if(i%multiples == 0){
			printf("OK\n");
			found=false;
			break;
		}
	}
	if (found) printf("NG\n");
	return 0;
}

Measured memory_bytes: 1660
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
#define fs first
#define se second

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;
typedef pair<ld, ld> pdd;

int n;
pii P[200001];
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    int mn = 1e9, mx = 0, mxx = 0, mny = 1e9;
    for (int i = 1; i <= n; ++i) {
        cin >> P[i].fs >> P[i].se;
        if (P[i].fs > P[i].se) swap(P[i].fs, P[i].se);
        mn = min(mn, P[i].fs);
        mxx = max(mxx, P[i].fs);
        mx = max(mx, P[i].se);
        mny = min(mny, P[i].se);
    }
    sort(P + 1, P + (n + 1));
    llong ans = (llong)(mxx - mn) * (mx - mny);
    multiset<int> sp;
    for (int i = 1; i <= n; ++i) sp.insert(P[i].fs);
    for (int i = 0; i <= n; ++i) {
        if (i) {
            sp.insert(P[i].se);
            sp.erase(sp.find(P[i].fs));
        }
        ans = min(ans, (llong)(mx - mn) * (*sp.rbegin() - *sp.begin()));
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 12544
#include <iostream>
#include <cstring>

using namespace std;

int main(){
  string s1, s2, s3;
  
  cin >> s1 >> s2 >> s3;
  cout << (char)('A'+s1[0]-'a') << (char)('A'+s2[0]-'a') << (char)('A'+s3[0]-'a') << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

map<string, int>mp;

int main(){
  int n;
  cin>>n;
  rep(i,n){
    string s;
    cin>>s;
    mp[s]++;
  }
  cout<<"AC"<<" x "<<mp["AC"]<<endl;
  cout<<"WA"<<" x "<<mp["WA"]<<endl;
  cout<<"TLE"<<" x "<<mp["TLE"]<<endl;
  cout<<"RE"<<" x "<<mp["RE"]<<endl;
}

Measured memory_bytes: 3624
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string.h>
#include<set>
#include<map>
#include<list>
#include<vector>
#include<algorithm>
#define ll long long
using namespace std;
int  main()
{
    int n,ans=0;
    set<int>qq;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        int x;
        cin>>x;
        if(qq.find(x)==qq.end())
            qq.insert(x);
        else
            qq.erase(x);
    }
    cout<<qq.size()<<endl;

    return 0;
}


Measured memory_bytes: 4864
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner reader = new Scanner(System.in);
    String W = reader.next().toLowerCase();
    int count = 0;
    while(true) {
      String T = reader.next();
      if (T.equals("END_OF_TEXT"))  break;
      T = T.toLowerCase();
      if (T.equals(W)) count++;
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 26184
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <string.h> 
#include <stack>
#include <bitset>
#include <map>
#include <cmath>
#include <climits>
#include <queue>

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

using namespace std;

int main() {
	string str;
	cin >> str;
	if (str == "ABC") printf("ARC\n");
	else printf("ABC\n");
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define MMS(x, y) memset((x), (y), sizeof(x))
#define ll long long
#define vi vector <int>
#define pii pair <int, int>
#define EPS 1e-9
#define EPSS 1e-10

#define MAXN 310
#define SEGN 300030
using namespace std;

int N;
ll adj[MAXN][MAXN];
int main() {
    cin >> N;
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            cin >> adj[i][j];
        }
    }
    ll total;
    for (int i = 1; i <= N; i++) {
        for (int j = i + 1; j <= N; j++) {
            bool flag = false;
            for (int k = 1; k <= N; k++) {
                if (k == i || k == j) continue;
                if (adj[i][k] + adj[j][k] < adj[i][j]) {
                    return cout << "-1\n", 0;
                } else if (adj[i][k] + adj[j][k] == adj[i][j]) {
                    flag = true;
                }
            }
            if (!flag) {
                total += adj[i][j];
            }
        }
    }
    cout << total << "\n";
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

ll dp[50][410][410];  // dp[i+1][j][k] : i番目(iは0-index)までの薬品でAをjグラム,Bをkグラムとするときに必要な予算の最小値

int main() {
    ll n, mA, mB;
    cin >> n >> mA >> mB;
 
    vl a(n), b(n), c(n);
    ll sumA = 0, sumB = 0; 
    rep(i, n) {
        cin >> a[i] >> b[i] >> c[i];
        sumA += a[i];
        sumB += b[i];
    }
 
    rep(i, n+1) {
        rep(j, sumA+1) {
            rep(k, sumB+1) {
                dp[i][j][k] = INF;
            }
        }
    }
 
    dp[0][0][0] = 0;
    rep(i, n) {
        rep(j, sumA+1) {
            rep(k, sumB+1) {
                if(j >= a[i] && k >= b[i]) {
                    dp[i+1][j][k] = min(dp[i][j][k], dp[i][j - a[i]][k - b[i]] + c[i]);
                }
                else {
                    dp[i+1][j][k] = dp[i][j][k];
                }
            }
        }
    }
    
    ll ans = INF;
    exrep(j, 1, sumA) {
        exrep(k, 1, sumB) {
            if(mB*j == mA*k) {
                chmin(ans, dp[n][j][k]);
            }
        }
    }
 
    if(ans == INF) {
        out(-1);
    }
    else {
        out(ans);
    }
 
    re0;
}

Measured memory_bytes: 55040
x,y=map(int,input().split())
a=[1,3,5,7,8,10,12]
b=[4,6,9,11]
c=[2]
if (x in a and y in a) or (x in b and y in b) or (x in c and y in c):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    //エラトステネスの篩
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        //最小素因数がかかれるようにしている
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  //素因数列挙
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  //頻度を集計したもの
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      //小さい順に出てくるので前回と同じなら足す作業でmapが作れる
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};


int main(){
  Sieve sieve(1e5 + 1);
  vector<ll> res(1e5 + 1);
  ll cnt = 0;
  for(ll i = 2; i < 1e5 + 1; i++){
    if(sieve.isPrime(i) and sieve.isPrime((i + 1) / 2)){
      cnt++;
    }
    res[i] = cnt;
  }

  ll N; cin >> N;
  vector<ll> ans;
  rep(i, N){
    ll a, b; cin >> a >> b;
    ans.pb(res[b] - res[a - 1]);
  }
  rep(i,N) cout << ans[i] << endl;
}


Measured memory_bytes: 2872
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i = n; i < (int) N; i++)
#define p(s)		cout<<(s)<<endl
typedef long long ll;
using namespace std;

int main() {
	ll N,T,A;
	cin>>N;
	T = A = 1;
	REP(i,0,N){
		ll t,a;
		cin>>t>>a;
		ll tmp= max( (T-1)/t +1, (A-1)/a +1 );
		T=t*tmp;
		A=a*tmp;
	}
	p(A+T);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int vals_compare(const void *a, const void *b)
{
  int *vals_a, *vals_b;
  vals_a = (int *)a;
  vals_b = (int *)b;
  if ( vals_a[0] < vals_b[0] )
    return -1;
  if ( vals_a[0] > vals_b[0] )
    return 1;
  if ( vals_b[0] < vals_b[0] )
    return -1;
  if ( vals_b[0] > vals_b[0] )
    return 1;
  return 0;
}

int main()
{
  char line[256];
  int i, j, n, i2, j2, x, y, x2, y2, *vals, min, min2, mint;

  /* Input */
  fgets(line, 256, stdin);
  sscanf(line, "%d", &n);
  vals = (int *)malloc(sizeof(int) * n * 2);
  for (i = 0; i < n; i ++) {
    fgets(line, 256, stdin);
    sscanf(line, "%d %d", vals+i*2, vals+i*2+1);
  }
  /* sort */
  qsort(vals, n, sizeof(int)*2, vals_compare);
  /* Calculate */
  min = 100000000;
  mint = 10000;
  for (i = 0; i < n-1; i ++) {
    i2 = i * 2;
    x = vals[i2];
    y = vals[i2+1];
    for (j = i + 1; j < n; j ++) {
      j2 = j * 2;
      x2 = vals[j2];
      y2 = vals[j2+1];
      if ( x2-x >= mint ) break;
      x2 -= x;
      y2 -= y;
      min2 = x2 * x2 + y2 * y2;
      if ( min > min2 ) {
	min = min2;
	mint = (int)sqrt(min2);
      }
    }
  }
  printf("%d\n", min);

  /* Finish */
  free(vals);
  return 0;
}



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

int main () {
  int a,b;cin>>a>>b;
  int nb[b]; int maxv=0;
  map<int,vector<int> > pos;
  for(int i=0;i<a;++i){int v;cin>>v;pos[v].push_back(i);}
  for(int i=0;i<b;++i)cin>>nb[i];
  for(int i=0;i<b;++i){
    int f=-1;
    for(int k=i;k<b;++k){
      auto p=pos[nb[k]];
      auto itr=upper_bound(p.begin(),p.end(),f);
      if(itr==p.end())break;
      f=*itr;
      maxv=max(maxv,k-i+1);
    }
  }
  cout<<maxv<<endl;
}

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

typedef long long ll;
#define pa pair<int, int> 
#define pal pair<long long, long long>
#define pali pair<long long, int>
#define pad pair<double, double>
#define pb push_back
#define mp make_pair 
#define COUT(v) for(int64_t i=0;i<(v).size();i++){ cout << v.at(i) << endl;}
#define REP(i, n) for(int64_t i=0;i<n;i++)
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}

typedef vector<bool> bvec;
typedef vector<int> ivec;
typedef vector<long long> lvec;
typedef vector<double> dvec;
typedef vector<pa> pavec;
typedef vector<pali> palivec;
typedef vector<pal>palvec;


typedef vector< vector<bool> > bmat;
typedef vector< vector<int> > imat;
typedef vector< vector<long long> > lmat;

typedef vector<string> svec;
typedef vector< vector<string> > smat;
const ll infll = (1LL << 60) - 1;
const int inf = (1 << 30) - 1;
const int MOD = 1000000007;


ll gcd(ll x, ll y){
    ll r = x%y;
    if(r == 0) return y;
    else return gcd(y, r);
} 

ll lcm(ll x, ll y){
    return x*y/gcd(x,y);
}

lvec mfactor(ll n){
    bvec ip(n, true);
    lvec mf(n, -1);
    ip[0]=false; ip[1]=false; mf[0]=0; mf[1]=1;
    REP(i, n){
        if(ip[i]){
            mf[i] = i;
            for(ll j=i*i; j<n; j+=i){
                ip[j] = false;
                if(mf[j] == -1) mf[j]=i;
            }
        }
    }
    return mf;
}

palivec get_prime(ll n, const lvec &mf){
    palivec plist;
    while(n != 1){
        int cnt=0;
        ll m=mf[n];
        while(mf[n] == m){
            cnt++;
            n/=m;
        }
        plist.pb(pali(m, cnt));
    }
    return plist;
}

void COMinit(int m, lvec &fac, lvec &finv){
    lvec inv(m);
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < m; 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;
    }
}
ll pow_mod(ll a, ll n){
  ll x = 1;
  while(n > 0){
    if(n&1){
      x = x*a % MOD;
    }
    a = a*a %MOD;
    n >>= 1;
  }
  return x;
}
ll COM(int n, int k, const lvec& fac, const lvec &finv){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll 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 P(ll n, ll m){
    ll s = 1;
    ll cnt=n;
    REP(i, n-m){
        s*=cnt % MOD;
        s%=MOD;
        --cnt;
    }
    return s;    
}

ll delta(const lvec &x, ll p, int d){
    ll s=0;
    REP(i, x.size()){
        s+= -2*(x[i]-p)*d + d*d;
    }
    return s;
}

ll delta(const lvec &x, ll p){
    ll s=0;
    REP(i, x.size()) s+= (x[i]-p)*(x[i]-p);
    return s;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    lvec x(n);
    VIN(x);
    ll p=1;

    while(1){
        if(delta(x, p, 1) < 0) p++;
        else if(delta(x, p, -1) < 0)p--;
        else break;
    }
    cout << delta(x, p) << endl;
}


Measured memory_bytes: 256
class Stack:
    MAX = 101

    def __init__(self):
        self.S = [None] * self.__class__.MAX
        self.top = 0

    def is_empty(self):
        return self.top == 0

    def is_full(self):
        return self.top >= self.__class__.MAX - 1

    def push(self, x):
        self.top += 1
        self.S[self.top] = x
        return x

    def pop(self):
        self.top -= 1
        return self.S[self.top + 1]


stack = Stack()
print([stack.push(eval("".join(map(str, [stack.pop(), s, stack.pop()][::-1]))))
       if s in["+", "-", "*"]else stack.push(int(s))for s in input().split()][-1])



Measured memory_bytes: 5612
#include<stdio.h>
int main(){
	int H,W,tate,yoko;
	for(;;){
		scanf("%d %d",&H,&W);if(H==0&&W==0){break;}
	for(tate=1;tate<=H;tate++){
		for(yoko=1;yoko<=W;yoko++){
			printf("#");
		}
		printf("\n");
	}
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 572
#include <stdio.h>
#include <string.h>

#define N 100000

typedef struct {
    char name[11];
    int time;
} Process;

Process queue[N];
int top = 0;
int tail = 0;
int num = 0;

void enqueue(char *name, int time) {
    if (tail == N) {
        tail = 0;
    }
    strcpy(queue[tail].name, name);
    queue[tail].time = time;
    tail++;
    num++;
}

Process dequeue() {
    if (top == N) {
        top = 0;
    }
    num--;
    return queue[top++];
}

int main() {
    int p = 0, time, n, q, i, nowtime = 0;
    char name[11];
    Process result[N], tmp;
    
    scanf("%d %d", &n, &q);
    
    for(i = 0; i < n; i++) {
        scanf("%s %d", name, &time);
        enqueue(name, time);
    }
    
    while (num > 0) {
        tmp = dequeue();
        time = tmp.time - q;
        if (time <= 0) {
            strcpy(result[p].name, tmp.name);
            result[p].time = nowtime + tmp.time;
            p++;
            nowtime += tmp.time;
        } else {
            enqueue(tmp.name, time);
            nowtime += q;
        }
    }
    
    for (i = 0; i < p; i++) {
        printf("%s %d\n", result[i].name, result[i].time);
    }
    return 0;
}


Measured memory_bytes: 4196
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }

bool is_reachable(const vint& O, int t, int s) {
    vector<vector<bool>> dp(O.size() + 1, vector<bool>(16001, false));
    t = t + 8000;
    s = s + 8000;
    dp[0][s] = true;
    REP(i, 0, O.size()) {
        rep(j, 16001) {
            if (dp[i][j] == true) {
                if (j + O[i] <= 16000 && j + O[i] >= 0)
                    dp[i + 1][j + O[i]] = true;
                if (j - O[i] <= 16000 && j - O[i] >= 0)
                    dp[i + 1][j - O[i]] = true;
            }
        }
    }

    return dp[O.size()][t];
}

int main() {
    string S;
    int x, y;
    cin >> S;
    cin >> x >> y;
    vint X_F(0);
    vint Y_F(0);
    bool is_x = true;
    int f_count = 0;
    bool is_first = true;
    int init;
    for (auto& s : S) {
        if (s == 'F') {
            f_count++;
        }
        else {
            if (is_x) {
                if (is_first == true) {
                    init = f_count;
                }
                else {
                    X_F.push_back(f_count);
                }
                is_x = false;
            }
            else {
                Y_F.push_back(f_count);
                is_x = true;
            }
            f_count = 0;
            is_first = false;
        }
 
    }
    if (f_count > 0) {
        if (is_x) {
            if (is_first == true) {
                init = f_count;
            }
            else {
                X_F.push_back(f_count);
            }
            is_x = false;
        }
        else {
            Y_F.push_back(f_count);
            is_x = true;
        }
        f_count = 0;
        is_first = false;

    }
    if (is_reachable(X_F, x, init) && is_reachable(Y_F, y, 0)) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 8192
S = input()

if S == 'RRR':
    print(3)
elif S == 'RRS':
    print(2)
elif S == 'SRR':
    print(2)
elif S == 'RSS':
    print(1)
elif S == 'SRS':
    print(1)
elif S == 'SSR':
    print(1)
elif S == 'RSR':
    print(1)
else:
    print(0)

Measured memory_bytes: 9136
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000
	

int main(){
	
	int A,B;
	cin>>A>>B;
	
	if(A>B)swap(A,B);
	
	if(A==1&&B==2)cout<<3<<endl;
	else if(A==2)cout<<1<<endl;
	else cout<<2<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
import numpy as np
A=int(input())
B=int(input())
C=int(input())
D=int(input())
E=int(input())
X = np.asarray([A,B,C,D,E])
X_div = X%10
X_sort = np.sort(X_div)
min=0
for i in range(5):
	if X_sort[i]!=0:
		min=X_sort[i]
		break
if min==0:
	min=10
X=10*((X-1)//10)+10

sum=0
for i in range(5):
	sum+=X[i]
print(sum-10+min)

Measured memory_bytes: 13304
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
//#define int long long int
#define pb push_back
#define vec vector<int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define foo(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define deb(x) cout << #x << " --> " << x << endl;
#define deb1a(v) cout << #v << "--->" << endl; for (auto it : v)  cout << it << " "; cout << endl;
#define deb2a(v) cout << #v << "--->" << endl;for (auto it:v){for(auto it1 : it){cout << it1 << " ";}cout<< endl;}
#define deb3a(v) cout << #v << "-->" << endl; for(auto it:v){cout << it.fi << " " << it.se << endl;}
#define mod 1000000007
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second
#define db1(x) cout<<#x<<"="<<x<<endl
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl
int power(int x, unsigned int y, int p){ int res = 1;x = x % p;while (y > 0)  { if (y & 1)res = (res*x) % p;y = y>>1;  x = (x*x)% p;} return res;}
// int mI(int a, int m)  {return power(a, m - 2, m);}
vector<vector<int>> dir = {{2, 1}, {2, -1}, {-2, 1}, {-2, -1},{1,2},{1,-2},{-1,2},{-1,-2}};

void solve(){
    int n;
    cin >> n;
    vec v(n);
    map<int, int> m;
    fo(i,n){
        cin >> v[i];
        m[v[i]] ++;
    }
    int ans = 0;
    fo(i,n){
        int g = 1;
        if(m[v[i]]>1){
            continue;
        }
        m[v[i]]--;
        foo(j,1,sqrt(v[i])+1){
            if(v[i]%j==0){
                if(j*j==v[i]){
                    if(m[j])
                        g = 0;
                }
                else{
                   if(m[j])
                       g = 0;
                    if(m[v[i]/j])
                        g = 0;
                }
            }
        }
        if(g){
            ans++;
        }
        m[v[i]]++;
    }
    //deb3a(m);
    // int ans = 0;
    // fo(i,n){
    //     if(m[v[i]]==1){
    //         ans++;
    //     }
    // }
    cout << ans;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t = 1;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 32944
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
typedef long long ll;
typedef long double ld;
#define trace(x)  cerr << #x << ": " << x << endl;
const int N=1e6+5;
ll n,k;vector<ll> a(N);
int main()
{
	fast;
	char a;cin>>a;if(a<'a')cout<<"A";else cout<<"a";
	
	
}

Measured memory_bytes: 10960
#include<stdio.h>
#define N 100

int main(){
  int n,i,j,v,u,k;
  int adj[N+1][N+1]={0};
  
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      adj[i][v-1]=1;
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      printf("%d",adj[i][j]);
      if(j<n-1){
	printf(" ");
      }
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 652
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


def main():
    S = input().rstrip()

    if S[-1] == 's':
        res = S + 'es'
    else:
        res = S + 's'

    print(res)



main()


Measured memory_bytes: 9020
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;


int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};



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

	string s;
	cin >> n >> s;
	vector<int> w(n+1);
	vector<int> e(n+1);

	rep(i, 0, n) {
		if (s[i] == 'W') {
			w[i + 1] = w[i] + 1;
		}
		else
		{
			w[i + 1] = w[i];
		}
	}

	rep(i, 0, n) {
		if (s[i] == 'E') {
			e[i + 1] = e[i] + 1;
		}
		else
		{
			e[i + 1] = e[i];
		}
	}
	int ans = n;

	rep(i, 0, n) {

		ans = min(ans, w[i] + e[n] - e[i + 1]);
	}

		
	cout << ans << endl;

	
	
}
	

Measured memory_bytes: 2964
N, M = (int(s) for s in input().split())

broken = {int(input()) for _ in range(M)}

dp = [1 for _ in range(N+1)]

for k in range(1, N+1):
  if k in broken:
    dp[k] = 0
  elif k > 1:
    dp[k] = dp[k-1] + dp[k-2]

print(dp[N] % 1000000007)

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

int main()
{
  string s;
  cin >> s;
  int l = s.length();
  char c[] = {'L', 'R'};
  string ans = "Yes";
  for (int i = 0; i < l; i++) {
    if (s[i] == c[i % 2]) {
      ans = "No";
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    static final long MOD = 1000000007;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
		    arr[i] = sc.nextInt();
		}
		Arrays.sort(arr);
		Combination cmb = new Combination(n + 1);
		long ans = 0;
		for (int i = 0; n - i >= k; i++) {
		    ans += ((MOD * 10 + arr[n - 1 - i]) % MOD * cmb.getComb(n - 1 - i, k - 1)) % MOD;
		    ans %= MOD;
		    ans += (((MOD * 10 - arr[i]) % MOD) * cmb.getComb(n - 1 - i, k - 1)) % MOD;
		    ans %= MOD;
		}
		System.out.println(ans);
   }

}

class Combination {
    static final int MOD = 1000000007;
    long[] fac;
    long[] finv;
    long[] inv;
    
    public Combination (int size) {
        fac = new long [size];
        finv = new long [size];
        inv = new long [size];
        fac[0] = 1;
        fac[1] = 1;
        finv[0] = 1;
        finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < size; 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;
        }
    }
    
    
    public long getComb(int n, int k) {
        if (n < k || n < 0 || k < 0) {
            return 0;
        }
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
    
}



Measured memory_bytes: 50640
#include<bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];

unsigned long long power(unsigned long long x, 
                         int y, int p) 
{ 
    unsigned long long res = 1; // Initialize result 
  
    x = x % p; // Update x if it is more than or 
    // equal to p 
  
    while (y > 0) { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res * x) % p; 
  
        // y must be even now 
        y = y >> 1; // y = y/2 
        x = (x * x) % p; 
    } 
    return res; 
} 
  
// Returns n^(-1) mod p 
unsigned long long modInverse(unsigned long long n, int p) 
{ 
    return power(n, p - 2, p); 
} 
  
// Returns nCr % p using Fermat's little 
// theorem. 
unsigned long long nCrModPFermat(unsigned long long n, 
                                 int r, int p) 
{ 
    // Base case 
    if (r == 0) 
        return 1; 
  
    // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r 
    unsigned long long fac[n + 1]; 
    fac[0] = 1; 
    for (int i = 1; i <= n; i++) 
        fac[i] = (fac[i - 1] * i) % p; 
  
    return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; 
} 

void solve(){
	ll i, j, k, p, q, r, x, y, u, v, n, m;
    cin>>n;
    ll ans=0;
    for(i=1;3*i<=n;i++){
        ans=(ans%mod+nCrModPFermat(n-2*i-1, i-1, mod)%mod+mod)%mod;
        //deb(ans);
    }
    cout<<ans<<endl;

}

int main() {
	ios_base::sync_with_stdio(0);
	int i,t=1;
	//cin>>t;
	for(i=1;i<=t;i++){
		solve();
	}
	return 0;
}

int mpow(int base, int exp) {
	base %= mod;
	int result = 1;
	while (exp > 0) {
		if (exp & 1) result = ((ll)result * base) % mod;
		base = ((ll)base * base) % mod;
		exp >>= 1;
	}
	return result;
}

void ipgraph(int n, int m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}




Measured memory_bytes: 10688
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int count=0;
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='7')
        {
            cout<<"Yes"<<endl;
            break;
        }
        else
            count++;
    }
    if(count==3)
        cout<<"No"<<endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, m;
  string s, t;
  cin >> n >> m >> s >> t;
  ll l = n / gcd(n, m) * m;
  map<ll, char> mp;
  rep(i, n) mp[i * l / n + 1] = s[i];
  bool ok = true;
  rep(i, m) {
    ll j = i * l / m + 1;
    if(mp.count(j) && mp[j] != t[i]) ok = false;
  }
  cout << (ok ? l : -1) << endl;
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    int2(h, w);
    Int(d);
    map<int, pii> funami;

    rep(i, h) rep(j, w) {
        Int(tmp);
        funami[tmp] = {i, j};
    }

    vector<int> yui(h * w + 1, -1);

    Rep(i, yui.size()) {
        if (yui[i] == -1) {
            yui[i] = 0;
            int nxt = i + d, now = i;
            while (nxt < h * w + 1) {
                yui[nxt] = yui[now] + abs(funami[now].fir-funami[nxt].fir) + 
                    abs(funami[now].sec-funami[nxt].sec);
                now += d; nxt += d;
            }
        }
    }

    Int(q);
    while (q--) {
        int2(a, b);
        cout << yui[b] - yui[a] << endl;
    }

    return 0;
}


Measured memory_bytes: 7424
import numpy as np
N,D = map(int,input().split(' '))
X = np.array([list(map(int,input().split(' '))) for i in [0]*N])

M = int(np.sqrt(20000))
squares = [i**2 for i in range(0,M)]
ans = 0
for i in range(N):
	for j in range(i+1,N):
		a = np.sum(np.square(X[i]-X[j]))
		if a in squares:
			ans += 1

print(ans)



Measured memory_bytes: 21816
#include<bits/stdc++.h>
#define pii pair<int,int>
#define F first
#define S second
#define vi vector<pii>
#define pb push_back
using namespace std;
const int N=6e5+5;
vi v[N];
int n,m,id;
map<pair<int,int>,int>mp;
void add_edge(int a,int b,int c,int d)
{
	v[a].pb(make_pair(b,c));
	v[b].pb(make_pair(a,d));
}
int getid(int a,int pos)
{
	if(mp[make_pair(a,pos)])return mp[make_pair(a,pos)];
	int res=id++;
	add_edge(a,res,1,0);
	return (mp[make_pair(a,pos)]=res);
}
priority_queue<pii,vi,greater<pii> >pq;
bool visit[N];
int main()
{
	cin>>n>>m;
	id = n;
	for(int i=0;i<m;i++)
	{
		int a,b,c;
		cin>>a>>b>>c;
		a--,b--;
		int x=getid(a,c);
		int y=getid(b,c);
		add_edge(x,y,0,0);
	}
/*	for(int i=0;i<id;++i)
	{
		cout<<"Vertex "<<i<<" connact:  ";
		for(int j=0;j<v[i].size();j++)cout<<v[i][j].F<<' '<<v[i][j].S<<'\n';
		cout<<endl;
	}*/
	pq.push(make_pair(0,0));
	while(!pq.empty())
	{
		int move=pq.top().F;
		int now=pq.top().S;
		pq.pop();
		if(visit[now])continue;
		visit[now]=true;
		if(now==n-1)
		{
			cout<<move<<endl;
			return 0;
		}
		for(int i=0;i<v[now].size();i++)
		{
			int to=v[now][i].F;
			pq.push(make_pair(move+v[now][i].S,to));
		}
	}
	cout<<"-1\n";
	return 0;
}

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

using namespace std;

int a[1001];

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort (a, a + n);
    int ans = 0, cnt = 0, c = -1, b = -1;
    for (int i = 0; i < n; ++i) {
        if (a[i] < 3200) {
            b = a[i] / 400;
            if (b != c) {
                ans++;
            }
            c = b;
        } else {
            cnt = n - i;
            break;
        }
    }
    cout << max(ans, 1) << ' ' << ans + cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;loop(test,1,t+1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define MOD 1000000007
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

int main() 
{
    fastio();

    ll n,m;
    cin>>n>>m;
    ll ans = 0;
    priority_queue<ll>pq;
    for(int i=0;i<n;i++)
    {
        ll x;
        cin>>x;
        pq.push(x);
        ans += x;
    }
    for(int i=31;i>=0;i--)
    {
        ll mask = (1ll<<i);
        ll sub = ans, cnt = 0;
        priority_queue<ll>temp;
        while( !pq.empty() )
        {
            ll now = pq.top();
            pq.pop();
            // cout<<now<<" "<<(now&mask)<<" "<<mask,nl;
            if( (now&mask) == mask )
            {
                // cout<<i<<" "<<now,nl;
                cnt++;
                sub -= now;
                sub += (now/2);
                temp.push(now/2);
            }
            else
                temp.push(now);
            if( cnt == m )
                break;
        }
        // cout<<m<<" "<<cnt<<" "<<sub,nl;
        if( cnt && m >= cnt )
        {
            m -= cnt;
            ans = sub;
        }
        if( m == 0 )
            break;
        while( !pq.empty() )
        {
            temp.push(pq.top());
            pq.pop();
        }
        pq = temp;
    }
    cout<<ans,nl;
    return 0;
}

Measured memory_bytes: 2916
#標準入力
x,y = map(int,input().split())
num_list = []

#数値を入力して2次元リストに、
for _ in range(x):
    line = list(map(int,input().split()))
    line.append(sum(line))
    num_list.append(line)
#出力
    line1 = [str(a) for a in line]
    line1 = " ".join(line1)
    print(line1)
line = []
#縦の合計を計算
for num in range(0,y + 1):
    kei = 0
    for num1 in range(0,x):
        kei += num_list[num1][num]
    line.append(kei)
#出力
line1 = [str(a) for a in line]
line1 = " ".join(line1)
print(line1)


Measured memory_bytes: 5680
// 2020-08-02 21:01:20
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  ll n, d;
  cin >> n >> d;
  ll d2 = d * d;
  ll ans = 0;
  rep(i, n) {
    ll x, y;
    cin >> x >> y;
    ans += x * x + y * y <= d2;
  }
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <string>
using namespace std;
int main(){

  string s;
  int a[4],r;
  cin>>s;
  for(int i=0;i<4;i++) a[i]=s[i]-'0';

  for(int i=0;i<2;i++) for(int j=0;j<2;j++) for(int k=0;k<2;k++){
        r=a[0];
        if(i) r-=a[1];
        else r+=a[1];
	if(j) r-=a[2];
        else r+=a[2];
	if(k) r-=a[3];
        else r+=a[3];
        if(r==7){
          cout<<a[0];
          if(i) cout<<"-";
          else cout<<"+";
          cout<<a[1];
          if(j) cout<<"-";
          else cout<<"+";
          cout<<a[2];
          if(k) cout<<"-";
          else cout<<"+";
          cout<<a[3]<<"=7"<<endl;
          return 0;
        }
      }
}





Measured memory_bytes: 256
k,x =map(int,input().split())
cons=2000001
mn_cons=int(-1000000)
mx_cons=1000000


mn=x-k+1
mx=x+k

if mn<=mn_cons:
    mn=mn_cons
if mx>=mx_cons:
    mx=mx_cons+1

r=range(mn,mx)
print(" ".join(list(map(str,r))))

Measured memory_bytes: 38384
#!/usr/bin/env python3

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    A.sort()
    B.sort()
    C.sort()
    S = [0]

    s = 0
    i = 0
    for b in B:
        while i < N:
            if b <= A[i]:
                break
            i += 1
        s += i
        S.append(s)

    t = 0
    i = 0
    for c in C:
        while i < N:
            if c <= B[i]:
                break
            i += 1
        t += S[i]


    print(t)


if __name__ == '__main__':
    main()



Measured memory_bytes: 23328
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n = I()
    a = LI_()
    r = [0] * n
    for c in a:
        r[c] += 1

    return JA(r, "\n")


print(main())





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

#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define eb emplace_back
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;
using ull = unsigned long long;
using Vi = vector<int>;

void run() {
    int n;
    cin >> n;
    // long long n = 1;
    queue<ll> answer;
    for (int i = 1; i < 10; ++i) {
        answer.push(i);
    }
    ll ans;
    for (int i = 0; i < n; ++i) {
        ll temp = answer.front();
        answer.pop();
        if(temp%10) {
            answer.push((10*temp) + (temp%10) - 1);
        }
        answer.push((10*temp) + (temp%10));
        if(temp%10!=9) {
            answer.push((10*temp) + (temp%10) + 1);
        }
        ans = temp;
    }
    cout << ans <<endl;
}

int main() 
{
    IO;
    double st = clock();
    run();
    cerr << "\n" << "time = " << (clock() - st) / CLOCKS_PER_SEC << "\n";
    return 0;
}

Measured memory_bytes: 4816