akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize ("Ofast")
//#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define pb push_back
#define all(_obj) _obj.begin(),_obj.end()
#define F first
#define S second
#define INF 1e18
#define pll pair<ll, ll> 
#define vll vector<ll>
ll n,m,a,b,c,k,temp,x,y;
const int MAXN=1e5+11,mod=1e9+7;
inline ll max(ll a,ll b) {return ((a>b)?a:b);}
inline ll min(ll a,ll b) {return ((a>b)?b:a);}
inline vll read(int n) {vll v(n);for (int i = 0; i < v.size(); i++)cin>>v[i];return v;}
ll maxAbsValExpr(vector<ll>& x, vector<ll>& y) {
        ll res = 0, n = x.size(), smallest, cur;
        for (int p : {1, -1}) {
            for (int q : {1, -1}) {
                smallest = p * x[0] + q * y[0];
                for (int i = 1; i < n; ++i) {
                    cur = p * x[i] + q * y[i];
                    res = max(res, cur - smallest);
                    smallest = min(smallest, cur);
                }
            }
        }
        return res;
    }
void sol(void)
{
cin>>n;
vector<ll> x,y;
for(int i=0;i<n;i++)
{
    cin>>a>>b;
    x.pb(a);
    y.pb(b);
}
cout<<maxAbsValExpr(x,y);
return ;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test=1;
    //cin>>test;
    for(int i=1;i<=test;i++)
    sol();
}


Measured memory_bytes: 6672
#include <bits/stdc++.h>
	  #define endl "\n"
	  #define ll long long int
	  #define mod 1000000007
	  #define inf 1000000000000000001;
	  using namespace std;
	  int main()
	  {
	
	    std::ios::sync_with_stdio(false);
	    cin.tie(NULL);
	    string s,t;
	    cin>>s>>t;
	    int c=0;
	    for (int i = 0; i < s.length(); ++i)
	    {
	    	if(s[i] != t[i]){
	    		c++;
	    	}
	    }

	    cout<<c<<endl;
	    return 0;
	  }



Measured memory_bytes: 3800
//できず

//再度just after

#include <iostream>
#include <algorithm>

using namespace std;

int main (){
    int k, s;
    cin >> k >> s;
    int count = 0;
    for (int x = 0; x <= k ; x++){
        for(int y = 0; y <= k; y ++){
            int z = s - x - y;
            if (0 <= z && z <= k){
                count ++;
            }
        }
    }


    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int a,count=0;
  char str[200010];
  int be[2019];
  int n[2019];
  cin >> str;
  for(int i=0;i<2019;i++){
    be[i] = 0;
    n[i] = 0;
  }
  for(int i=0;str[i] != '\0';i++){
    a = (int)str[i]-(int)'0';
    be[0] += 1;
    for(int j=0;j < 2019;j++){
      n[(j*10+a)%2019] = be[j];
    }
    for(int j=0;j<2019;j++){
	  be[j] = n[j];
      n[j] = 0;
    }
    count += be[0];
  }
  cout << count;
  return 0;
}

Measured memory_bytes: 3816
k, n = [int(i) for i in input().split(" ")]
a = [int(i) for i in input().split(" ")]

d = min(k - (a[0] - (a[-1] - k)), k - (a[1] - a[0]))
for i in range(1, n-1, 1):
  d = min(d, k - (a[i]-a[i-1]), k - (a[i+1]-a[i]) )
print(d)

Measured memory_bytes: 74496
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    LL n,a,b;
    cin >> n >> a >> b;
    LL d=b-a;
    if ( d&1 ) {
        // min(a-1,n-b) + 1 + (b-a-1)/2
        cout << min(a-1,n-b) + 1 + (b-a-1)/2 << '\n';
    } else {
        cout << d/2 << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int g[101][101];
int es[101][101];
int main() {
	int N, M; cin >> N >> M;
	rep(i, N) rep(j, N) g[i][j] = 1 << 29;
	rep(i, M) {
		int a, b, c; cin >> a >> b >> c;
		a--; b--;
		es[a][b] = es[b][a] = g[a][b] = g[b][a] = c;
	}
	rep(k, N) rep(i, N) rep(j, N) g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
	rep(i, N) rep(j, N) if (i < j && es[i][j] == g[i][j]) M--;
	cout << M << endl;
}

Measured memory_bytes: 764
local function getgcd(x, y)
  while 0 < x do
    x, y = y % x, x
  end
  return y
end
local r = 0
local k = io.read("*n")
for i = 1, k do
  for j = 1, k do
    local g = getgcd(i, j)
    for q = 1, k do
      r = r + getgcd(g, q)
    end
  end
end
print(r)


Measured memory_bytes: 2796
#include "bits/stdc++.h"
#define rep(i, a) for (ll i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define FORV(a, A) for (auto &a : A)

using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll MOD = 1000000007;

const ll MAX = 200000;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (ll 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(ll n, ll k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

void Main() {
  int n, k;
  cin >> n >> k;
  vector<ll> A(n);
  rep(i, n) cin >> A[i];
  sort(A.begin(), A.end());
  rep(i, n) if (A[i] < 0) A[i] += MOD;
  COMinit();
  ll add = 0;
  rep(i, n) {
    if (n - (i + 1) < k - 1) break;
    ll val = A[n - i - 1] % MOD;
    (val *= COM(n - (i + 1), k - 1)) %= MOD;
    (add += val) %= MOD;
  }
  ll sub = 0;
  rep(i, n) {
    if (n - (i + 1) < k - 1) break;
    ll val = A[i] % MOD;
    (val *= COM(n - (i + 1), k - 1)) %= MOD;
    (sub += val) %= MOD;
  }
  if (add < sub) add += MOD;
  cout << (add - sub) % MOD << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


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

int main(){
  char a;
  cin >> a;
  if (a=='A' || a=='B' || a=='C' || a=='D' || a=='E' || a=='F' || a=='G' || a=='H' || a=='I' || a=='J' || a=='K' || a=='L' || a=='M' || a=='N' || a=='O' || a=='P' || a=='Q' || a=='R' || a=='S' || a=='T' || a=='U' || a=='V' || a=='W' || a=='X' || a=='Y' || a=='Z'){
      cout << 'A' << endl;
  } else {
    cout << 'a' << endl;
  }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

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

struct mint {
  long long x;
  mint(long long x = 0) : x((x%mod+mod)%mod) {}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if((x -= a.x) < 0) x += mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint operator++() const { return mint(*this) += mint(1);}
  mint operator--() const { return mint(*this) -= mint(1);}
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
  int k;cin >> k;
  string s;cin >> s;
  int n = s.size();
  combination c(n+k);
  mint ans;
  rep(i,k+1) {
    ans += mint(26).pow(k-i) * c(i+n-1,n-1) * mint(25).pow(i);
  }
  cout << ans << endl;



  return 0;
}


Measured memory_bytes: 35572
local s = io.read()
local p = 0
local score = 0
for i=1,#s do
  local oh = s:sub(i,i) -- opponent hand
  if p == 0 then -- use 'g'
    score = score + (oh == 'g' and 0 or -1)
    p = 1
  else -- use 'p'
    score = score + (oh == 'g' and 1 or 0)
    p = 0
  end
end
print(score)

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
const double eps=1e-9;
typedef vector<int> vi;
typedef long long ll;
int N;
string X;
string ans;
int zerocount=0;
int D;
bool changed[1005];
int main(void)
{
  memset(changed,false,sizeof(changed));
  cin >> N >> X >> D;
  ans=X;
  for(int i=0;i<int(X.size());i++)
    {
      if(X[i]=='0') zerocount++;
    }
  if(zerocount>=D)
    {
      for(int i=0;i<int(ans.size());i++)
	{
	  if(D==0) break;
	  if(ans[i]=='0') 
	    {
	      ans[i]='1';
	      D--;
	    }
	}
    }
  else
    {
      for(int i=0;i<int(ans.size());i++)
	{
	  if(ans[i]=='0') 
	    {
	      changed[i]=true;
	      ans[i]='1';
	    }
	}
      D-=zerocount;
      int now=int(ans.size()-1);
      while(D>0)
	{
	  if(!changed[now] && ans[now]=='1')
	    {
	      ans[now]='0';
	      D--;
	    }
	  now--;
	}
    }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3212
#include <stdio.h>

int main(void){
	
	int n,k,p;
	int i,j;
	int dare;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%d %d",&k,&p);
		
		dare=0;
		while(k){
			dare++;
			if(dare>p)dare=1;
			k=k-1;
		}
		printf("%d\n",dare);
	}
		
		
	return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
def main():
    K = int(input())
    tmp = 7
    i = 0
    while i < 10**6:
        if tmp % K == 0:
            print(i+1)
            exit()
        else:
            tmp += 7 * pow(10,(i+1),K) % K
            tmp %= K
            i += 1 
    print(-1)

if __name__ == "__main__":
    main()


Measured memory_bytes: 63264
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int W = scan.nextInt();
		int H = scan.nextInt();
		int x = scan.nextInt();
		int y = scan.nextInt();
		int r = scan.nextInt();
		if(x + r <= W && x - r >= 0 && y + r <= H && y - r >= 0) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 26344
#include <bits/stdc++.h>
#include <math.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int ans = -1;
int main(){
    int a, b;
    cin >> a >> b;
    for(int i = 1; i <= 2000; i++){
        int pre = i*0.08;
        int cur = i*0.1;
        if(pre==a && cur==b){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
 
n = int(sys.stdin.readline().rstrip())
a = [int(x) for x in sys.stdin.readline().rstrip().split()]
 
counter = [0,0,0,0,0,0,0,0]
counter_wild = 0
 
for x in a:
    if x < 400:
        counter[0] += 1
    elif x < 800:
        counter[1] += 1
    elif x < 1200:
        counter[2] += 1
    elif x < 1600:
        counter[3] += 1
    elif x < 2000:
        counter[4] += 1
    elif x < 2400:
        counter[5] += 1
    elif x < 2800:
        counter[6] += 1
    elif x < 3200:
        counter[7] += 1
    else:
        counter_wild += 1
 
c = len(list(filter(lambda x: x != 0,counter)))
 
if counter_wild == 0:
    minimum_num = c
    maximum_num = c
else:
    minimum_num = max(1,c)
    maximum_num = c+counter_wild
 
print(minimum_num,maximum_num)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
int main(void){
  long long n, m;
  std::cin >> n >> m;
  if(n == 1 && m == 1) std::cout << 1 << std::endl;
  else if(n == 1) std::cout << m - 2 << std::endl;
  else if(m == 1) std::cout << n - 2 << std::endl;
  else std::cout << (m - 2) * (n - 2) << std::endl;
  return 0;
}

Measured memory_bytes: 256
import itertools
import fractions
def main():
  d = int(input())
  if d == 25:
    ans = "Christmas"
  elif d == 24:
    ans = "Christmas Eve"
  elif d == 23:
    ans = "Christmas Eve Eve"
  elif d == 22:
    ans = "Christmas Eve Eve Eve"
  
  print(ans)
if __name__ == '__main__':
  main()

Measured memory_bytes: 5048
import numpy as np
import collections
import sys
N  = int(input())
Ds = np.array(list(map(int, input().split(' '))))
if Ds[0] != 0:
    print(0)
    sys.exit()
if np.any(Ds[1:] == 0):
    print(0)
    sys.exit()

uniq = np.unique(Ds)
uniq.sort()

if not np.all(uniq == np.arange(uniq.min(), uniq.max() + 1)):
    print(0)
    sys.exit()
C = collections.Counter(Ds)
counts = 1
for i in range(1, uniq.max() + 1):
    counts *= C[i-1] ** C[i]
print(counts % 998244353)


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

int main(){
  int d, t, s;
  cin >> d >> t >> s;
  
  int run = t * s;
  
  if (d <= run){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

using P = pair<long long, long long>;
int n;
vector<P> v;

long long solve();

int main() {
  cin >> n;
  v.resize(n);
  for (auto& p : v) cin >> p.first >> p.second;
  sort(v.begin(), v.end());
  cout << solve() << endl;
  return 0;
}

long long solve() {
  priority_queue<long long> mi, pl;
  mi.push(-v[0].first - v[0].second);
  pl.push(v[0].second - v[0].first);
  long long res = 0;
  for (int i = 1; i < n; ++i) {
    long long now = v[i].first + v[i].second;
    res = max(res, now + mi.top());
    res = max(res, v[i].first - v[i].second + pl.top());
    mi.push(-v[i].second - v[i].first);
    pl.push(v[i].second - v[i].first);
  }
  return res;
}

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

using namespace std;
using ll = long long;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  string a, b;
  cin >> a >> b;
  b.pop_back();
  cout << (a == b ? "Yes" : "No") << '\n';
  return 0;
}


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

int main(void){
  int N;
  cin >> N;
  
  vector<int> blackboard(N);
  
  for (int i = 0; i < N; i++) {
    cin >> blackboard.at(i);
  }
  
  int count = 0;
  
  for  (int i = 0; i < N; i++) {
    if (blackboard.at(i) % 2 == 1) {
      count++;
    }
  }
  
  if (count % 2 == 0){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
  
}

Measured memory_bytes: 640
#include <cstdio>

template <class InputIterator, class T>
   T accumulate (InputIterator first, InputIterator last, T init)
{
  while (first!=last) {
    init = init + *first;  // or: init=binary_op(init,*first) for the binary_op version
    ++first;
  }
  return init;
}

int main(void)
{
	int i,N,sum,maxValue;
	int *a[2];
	scanf("%d",&N);
	a[0]=new int [N];
	a[1]=new int [N];

	for(i=0;i<N;i++)
		scanf("%d",a[0]+i);
	for(i=0;i<N;i++)
		scanf("%d",a[1]+i);

	for(i=0;i<N;i++)
	{
		sum=accumulate(a[0],a[0]+i+1,accumulate(a[1]+i,a[1]+N,0));
		if(sum>maxValue)
			maxValue=sum;
	}
	printf("%d\n",maxValue);

	return 0;
}

Measured memory_bytes: 256
s = str(input())
t = str(input())
s_list = []
t_list = list(t)
n = 0
#print(t_list)
while n < len(s):
    for i in range(0,len(s)):
        if n+i < len(s):
            s_list.append(s[n+i])
        else:
            s_list.append(s[n+i-len(s)])
    if t_list == s_list:
        print("Yes")
        break
    s_list = []
    n += 1
else:
    print("No")


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

 
int main() {
    int x,y,z;
    cin>>x>>y>>z;
    int ans=x/(z+y);
    if(x%(z+y)<z)cout<<ans-1<<endl;
    else cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x,y;
    cin>>x>>y;
    for(int i=0;i<=100;i++){
        for(int j=0;j<=100;j++){
            if(i+j>x) continue;
            if(((i*2+j*4)==y)&&(i+j==x)){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3620
#include<stdio.h>
 
int main(){
 
  int a, b, i;
  
  scanf("%d %d", &a, &b);
  
  if(a>b){
  for(i=0;i<a;i++){
  printf("%d",b);
  }
  }else{
   for(i=0;i<b;i++){
  printf("%d",a);
  } 
  }
  printf("\n");
  return 0;
 
}


Measured memory_bytes: 128
N, K = list(map(int, input().split()))
l = []
for i in range(N):
    l.append(int(input()))

sl = sorted(l)
mn = 10 ** 9
for i in range(N):
    if i + K - 1< N:
        if mn > sl[i + K - 1] - sl[i]:
            mn = sl[i + K - 1] - sl[i];

print(mn)



Measured memory_bytes: 8280
n,m = map(int,raw_input().split())
a = map(int,raw_input().split())
l = []
for i in xrange(m):
	bi,ci = map(int,raw_input().split())
	l.append((ci,bi))
for i in xrange(n):
	l.append((a[i],1))
l = sorted(l, reverse=True)
rem = n
res = 0
for x in l:
	quant = min(rem,x[1])
	res += quant*x[0]
	rem -= quant
	if rem == 0:
		break
print res

Measured memory_bytes: 29780
/*
Lionel Messi is such a player that you may catch him, you may touch him, you may feel him
and definitely you may Love him.
Lionel Messi is Messi. A little Magician in this World.

*/

#include<bits/stdc++.h>

using namespace std;

#define fast ios_base::sync_with_stdio(0)
#define bfast cin.tie(0)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf
#define nl puts("")
#define psb push_back

typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;
typedef unsigned long long ull;

const int mod = 1000007;
const int high = 100;

int main()
{
	fast;
	int k , s , x , y , z;
	while(cin >> k >> s)
	{
		int cnt=0;

		for(x=0; x<=k; x++)
		{
			for(y=0; y<=k; y++)
			{
				z = s - x - y;

				if(z>=0 and  z<= k)
				{
					//cout << x << " " << y << " " << z << "\n";
					cnt+=1;
				}
			}
		}

		outn(cnt);
	}

	return 0;
}


Measured memory_bytes: 256
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
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 [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()


def main():
  n=I()
  l=LI()

  l.sort()
  # center1=(l[0]+l[-1]+1)//2
  # center2=(l[0]+l[-1]-1)//2

  avg=sum(l)/len(l)
  center1=-(-avg//1)
  center2=int(avg)

  ans1=0
  ans2=0
  for x in l:
    ans1+=(x-center1)**2
    ans2+=(x-center2)**2

  # print(center1,center2,ans1,ans2)
  return int(min(ans1,ans2))

# main()
print(main())


Measured memory_bytes: 5712
#include<bits/stdc++.h> 
using namespace std;
const int maxn = 1e5+100;
int n,a[maxn];
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	int cnt = 0,i;
	for (i=1;i<=n;i++){
		if (a[i] == i) cnt++,i++;
	}
	printf("%d\n",cnt);
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <string.h>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
    int n, d;
    cin >> n >> d;
    int x[n][d];
    for (int i=0; i<n; i++) {
        for (int j=0; j<d; j++) cin >> x[i][j];
    }
    float dist; int cnt = 0;
    for (int k=0; k<n; k++) {
        for (int i=k+1; i<n; i++) {
            int sum = 0;
            for (int j=0; j<d; j++) {
                sum += pow(x[k][j] - x[i][j], 2);
            }
            dist = sqrt(sum);
            if (dist == (int)dist) cnt++;
        }
    }
    cout << cnt << '\n';
    return 0;
}

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

int main() {
    int n, c = 0;
    bool b = 1;
    cin >> n;
    vector<int> v(n);
    rep(i, n) cin >> v[i];
    while(b){
        rep(i, n){
            if(v[i] % 2 == 1){
                b = 0;
                break;
            }
            else v[i] /= 2;
        }
        if(b) ++c;
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };



signed main() {
	ll a, b, k;

	cin >> a >> b >> k;

	if (k >= a) {
		k -= a;
		a = 0;
		if (k >= b) {
			b = 0;
		}
		else if(k < b){
			b -= k;
		}
	}
	else if (k < a) {
		a -= k;
	}

	cout << a << " " << b << endl;


	return 0;
}

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

int main(){
  string s;
  cin >> s;
  bool ans[26] = {false};
  for(int i = 0;i < s.size();i++){
    ans[s[i] - 'a'] = true;
  }
  if(ans[0] && ans[1] && ans[2] && ans[3] && ans[4] && ans[5] && ans[6] && ans[7] && ans[8] && ans[9] && ans[10] && ans[11] && ans[12] && ans[13] && ans[14] && ans[15] && ans[16] && ans[17] && ans[18] && ans[19] && ans[20] && ans[21] && ans[22] && ans[23] && ans[24] && ans[25] && ans[26])
      cout << "None" << endl;
  for(int i = 0;i < 26;i++){
    if(!(ans[i])){
      cout << char('a' + i) << endl;
      break;
    }
  }
}


Measured memory_bytes: 3692
N = int(input())

q = list("357")


def dfs(X):
    if int(''.join(X)) > N:
        return 0

    res = 0
    if set(X) == set(q):
        res = 1

    for i in q:
        X.append(i)
        res += dfs(X)
        X.pop()
    
    return res



res = 0
for i in range(len(q)):
    res += dfs(list(q[i]))

print(res)


Measured memory_bytes: 3060
package main

import (
	"fmt"
)

func main() {
	var A, B, C int
	fmt.Scanf("%d%d%d", &A, &B, &C)
	max := 0
	o1 := 0
	o2 := 0
	if max < A {
		max = A
		o1 = B
		o2 = C
	}
	if max < B {
		max = B
		o1 = C
		o2 = A
	}
	if max < C {
		max = C
		o1 = A
		o2 = B
	}
	fmt.Printf("%d\n", max*10+o1+o2)
	return
}


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

using namespace std; 

int main()
{
    long long int n,k; 
    cin >> n >> k; 
    vector<long long int> a(n); 

    for(int i=0 ; i< n; i++) cin >> a[i] ;

    for(int i = k ; i< n ;i++){
        if(a[i] > a[i-k] ) cout <<"Yes"<<endl; 
        else cout <<"No"<<endl;  
    }


    return 0; 
}


Measured memory_bytes: 4760
#include<bits/stdc++.h>
#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 all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;

int main() {
  
  int a,b,c,d;
  string s,ss,sss;
  
  int ans = 0;
  string anss = "";
  
  int ab [] = {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
  
  cin >> ans;

  int result3 = std::max({a, b, c});
  

  cout << "ABC" << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
using namespace std;
#define A

#ifdef A
int main(void)
{
	int W, H;
	vector<pair<int, int> > arr(0);

	while (true)
	{
		cin >> H >> W;

		if (W == 0 || H == 0)
			break;
		arr.push_back(pair<int, int>(H, W));

	}

	for (auto a : arr) {
		for (size_t i = 0; i < a.first; i++)
		{
			for (size_t i = 0; i < a.second; i++)
			{
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}



	return 0;
}


#endif // A

#ifdef B
int main(void)
{
	return 0;
}
#endif // B


#ifdef C
int main(void)
{
	return 0;
}
#endif // C

#ifdef D
int main(void)
{

	return 0;
}

#endif // D

Measured memory_bytes: 3080
//
//  main.cpp
//  codeforces
//
//  Created by cfhaiteeh on 29/5/2018.
//  Copyright © 2018 cfhaiteeh. All rights reserved.
//

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#define  LL long long

using namespace  std;
const int maxn=123456;

void init(){
   
   
}





void play(){
   
   
}
void pri(){
   // printf("%lld\n",ans);
}
char ch[5];
int n,m;
int main() {
    while(scanf("%d%d",&n,&m)!=EOF){
        int u;
        for(int i=1;i<=n;i++)scanf("%d",&u);
        if(m==2){
            printf("%d\n",n-1);
            continue;
        }
        int t=n%(m-1);
        int a=n/(m-1);
        if(t>1)a++;
        printf("%d\n",a);
        
        //init();
       // play();
       // pri();
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
#define all(x) (x).begin(), (x).end()

/**ABC 164*/
int main(){
    int n,m; cin>>n>>m;
    if(m>=n)cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;
    return 0;
}


Measured memory_bytes: 3624
using System;

class ABC075D
{
	static public void Main(string[] args)
	{
		int N, K;
		string[] vals = Console.ReadLine().Split(' ');
		N = int.Parse(vals[0]);
		K = int.Parse(vals[1]);

		int[] x = new int[N+1];
		int[] y = new int[N+1];
		for(int i=1; i<=N; i++)
		{
			vals = Console.ReadLine().Split(' ');
			x[i] = int.Parse(vals[0]);
			y[i] = int.Parse(vals[1]);
		}

		long ans = long.MaxValue;;

		for(int l=1; l<=N; l++)
		{
			for(int r=1; r<=N; r++)
			{
				if(x[l] >= x[r])
					continue;
				for(int t=1; t<=N; t++)
				{
					for(int b=1; b<=N; b++)
					{
						if(y[t] >= y[b])
							continue;
						int count = 0;
						for(int i=1; i<=N; i++)
						{
							if(x[i] >= x[l] && x[i] <= x[r] && y[i] >= y[t] && y[i] <= y[b])
							{
								count++;
							}
						}
						if(count >= K)
						{
							long w = (long)x[r] - (long)x[l];
							long h = (long)y[b] - (long)y[t];
							long m = w * h;
							if(ans > m)
								ans = m;
						}
					}
				}
			}
		}
		Console.WriteLine(ans);
	}
}


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

typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const ll INF = 1001001001;
const ll MOD = 1e9 + 7;

int main(){
  int n, h;
  cin >> n >> h;
  priority_queue<P> pq;
  rep(i, n){
    int a, b;
    cin >> a >> b;
    P p(a, 0), q(b, 1);
    pq.push(p);pq.push(q);
  }
  int ans = 0;
  while(h > 0){
    P tmp = pq.top();
    h -= tmp.first;
    if(tmp.second) pq.pop();
    ans++;
    
  }
  cout << ans <<endl;
}
  
    

Measured memory_bytes: 2548
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;

int main(){
    string s;
    cin >> s;
    sort(s.begin() , s.end());
    if(s[0] != s[1] || s[1] != s[2]){
        puts("Yes");
    } else {
        puts("No");
    }
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back
 
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

int main(int argc, char const *argv[])
{
    int N;
    int i;
    cin >> N;
    int A[N];
    rep(i,N) cin >> A[i];
    int count = 0;
    int flag = 1;
    while(flag == 1) {
        flag = 0;
        for(int j = N - 2; j >= 0; j--) {
            if (A[j] > A[j + 1])
            {
                int tmp = A[j];
                A[j] = A[j + 1];
                A[j + 1] = tmp;
                flag = 1;
                count++;
            }
        }
    }

    rep(i,N - 1) cout << A[i] << " ";
    cout << A[N -1] << endl;
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3092
#include <cstdio>
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
	vector<int> p[3];
int main(){
	int n,t1,t2,t3;
	cin>>n;
	for(int i=0;i<n;i++){
		scanf("%d %d %d",&t1,&t2,&t3);
		p[0].push_back(t1);
		p[1].push_back(t2);
		p[2].push_back(t3);
	}
	int a[3],b[3];
	b[0]=a[0]=p[0][0];
	b[1]=a[1]=p[1][0];
	b[2]=a[2]=p[2][0];
	for(int i=1;i<n;i++){
		a[0]=p[0][i]+max(b[1],b[2]);
		a[1]=p[1][i]+max(b[0],b[2]);
		a[2]=p[2][i]+max(b[0],b[1]);
		b[0]=a[0];b[1]=a[1];b[2]=a[2];
	}
	cout<<max(a[0],max(a[1],a[2]));
	return 0;
}


Measured memory_bytes: 1644
n,m = map(int,input().split(" "))

shoplist= [tuple(map(int,input().split(" "))) for _ in range(n)]

shoplist.sort()


cost = 0

curr = 0


while(curr<m):

	for shop in shoplist:

		if(curr+shop[1] <= m):
			curr += shop[1]
			cost += shop[0]*shop[1]

		elif(curr+shop[1]>m):

			cost += (m-curr)*shop[0]
			curr = m

print(cost)



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

int main(){
  int n,m;
  cin >> n >> m;
  vector<bool> ones(n);
  vector<int> wa(n,0);
  int wacnt=0;
  int accnt=0;
  rep(i,m){
    int num;
    string str;
    cin >> num >> str;
    num--;
    if(ones[num])continue;
    if(str=="AC"){
      ones[num]=true;
      accnt++;
      wacnt +=wa[num];
    }
    else if (str=="WA")wa[num]++;
  }
  printf("%d %d\n",accnt,wacnt);
  return 0;
}


Measured memory_bytes: 3688
import java.util.*;

class Main{
	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		BitSet q=new BitSet(n+1),a=new BitSet(n+1);
		for(int i=1;i<=n;++i)
			q.set(i,s.nextInt()==1);

		for(int i=n;i>0;--i){
			boolean t=q.get(i);
			for(int j=i*2;j<=n;j+=i)
				t^=a.get(j);
			a.set(i,t);
		}

		System.out.println(a.cardinality());
		StringBuilder sb=new StringBuilder();
		for(int i=1;i<=n;++i)
			if(a.get(i))
				sb.append(i).append("\n");
		System.out.println(sb);
	}
}


Measured memory_bytes: 64716
import Text.Printf(printf)
import System.Exit

main = do
    cs <- getLine
    let (x:y:z:_) = words cs
    case y of "+" -> printf "%d\n" $ (ri x) + (ri z)
              "-" -> printf "%d\n" $ (ri x) - (ri z)
              "*" -> printf "%d\n" $ (ri x) * (ri z)
              "/" -> printf "%d\n" $ (ri x) `div` (ri z)
              "?" -> exitSuccess
              -- _   -> die "UNKNOWN PATTERN"
    main
    where ri = read :: String -> Int


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

int main() {
	long N;
	long M;
	cin >>N>>M;
	vector<long> A(M+1);
	for(int i=1 ; i<=M ; i++){
		cin >>A.at(i);
		N-=A.at(i);
	}
	if(N>=0){
		cout <<N;
	}
	else{
		cout <<-1;
	}


}

Measured memory_bytes: 3704
N, M, X = map(int, input().split())
B = [list(map(int, input().split())) for _ in range(N)]


cost = [B[i][0] for i in range(N)]

flag = False
min_ = float('inf')
for i in range(1 << N):
    cost_temp = 0
    cnt = 0
    skills = [0] * M
    while i > 0:
        if (1 & i):
            cost_temp += cost[cnt]
            for m in range(M):
                skills[m] += B[cnt][m + 1]

        cnt += 1
        i >>= 1

    flag2 = False

    for m in skills:
        if m < X:
            flag2 = True
            break

    if not flag2:
        flag = True
        min_ = min(min_, cost_temp)

if flag:
    print(min_)
else:
    print(-1)



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

int main(void) {
  ll H, W, N;
  cin >> H >> W >> N;
  vector<ll> X(N), Y(N);
  REP(i, 0, N) cin >> X[i] >> Y[i];

  vector<vector<ll>> y(H + 1);
  REP(i, 0, N) {
    y[X[i]].push_back(Y[i]);
  }

  ll yy = 1;
  REP(x, 2, H + 1) {
    bool ok = true;
    REP(i, 0, y[x].size()) {
      if (y[x][i] <= yy) {
        cout << x - 1 << endl;
        return 0;
      } else if (y[x][i] == yy + 1) {
        ok = false;
      }
    }
    if (ok) {
      yy++;
    }
  }
  cout << H << endl;
}

Measured memory_bytes: 14336
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {

    string s;

    vector<string> sub_str;
    int K;
    cin >> s;
    cin >> K;
    for(int i = 0; i < s.size(); ++i){
        for(int j = 1; j <= K; ++j){
            sub_str.push_back(s.substr(i,j));
        }
    }
    sort(sub_str.begin(), sub_str.end());
    sub_str.erase(unique(sub_str.begin(), sub_str.end()), sub_str.end());
    
    cout << sub_str[K-1] << endl;
    return 0;
}

Measured memory_bytes: 1660
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(int argc, char const *argv[]){
    vector<int> pages;
    map<string, vector<int> > books; 
    string name;
    int page, page_count;

    while (cin>>name>>page){
        auto it = books.find(name);
        if (it != books.end()){
            books[name].push_back(page);
        }
        else{
            vector<int> pages = {page};
            books.insert(make_pair(name, pages));
        }
    }

    for (auto& book : books){
        cout<<book.first<<endl;
        page_count=0;
        sort(book.second.begin(), book.second.end());
        for (int page : book.second){
            if (page_count) cout<<" "<<page;
            else cout<<page;
            page_count++;
        }
        cout<<'\n';
    }
    return 0;
}

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

const int N = 8;

int n, m;
int G[N][N];
int perm[N];

int main() {
  cin >> n >> m;
  rep(i, m) {
    int a, b;
    cin >> a >> b; a--; b--;
    G[a][b] = G[b][a] = 1;
  }
  rep(i, n) perm[i] = i;
  int ans = 0;
  do {
    bool exist = true;
    rep(i, n - 1) {
      if (G[perm[i]][perm[i + 1]] == 0) exist = false;
    }
    if (exist) ans++;
  } while (next_permutation(perm + 1, perm + n));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 100000000000000000
#define int long long
int a[300010];
int L[300010], R[300010];
int L2[300010], R2[300010];
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    
    rep(i, N * 3) cin >> a[i];
    int ans = -INF2;
    priority_queue<int, vector<int>, greater<int>> queL;
    rep(i, N) queL.push(0);
    rep(i, N * 2) {
        queL.push(a[i]);
        L[i] += L[max(0LL, i - 1)] + a[i] - queL.top();
        queL.pop();
    }
    priority_queue<int> queR;
    RREP(i, N * 3 - 1, N) {
        queR.push(a[i]);
        R[i] += R[i + 1] + a[i];
        if(queR.size() > N) {
            R[i] -= queR.top();
            queR.pop();
        }

    }

    rep(i, N + 1) {
        ans = max(ans, L[N - 1 + i] - R[N + i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 10520
#include <iostream>

int main(){
  int a,b;
  std::cin >> a >> b;
  if(a<6){
    std::cout << 0 << std::endl;
  }else if(a<13){
    std::cout << b/2 << std::endl;
  }else{
    std::cout << b << std::endl;
}
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int i,j,ver,hori;
    while(1){
        scanf("%d %d",&ver,&hori);
        if(ver  == 0)break;
        for(i=0;i<ver;i++){
            for(j=0;j<hori;j++){
                if(j==0 || i == 0 || j == hori -1 || i == ver -1 ){
                    printf("#");
                }
                else printf(".");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2120
n=int(input())

v=list(map(int,input().split()))

lisa=[0 for _ in range(10**5)]
lisb=[0 for _ in range(10**5)]

for i in range(n):
  if i%2==0:
    lisa[v[i]-1]+=1
  else:
    lisb[v[i]-1]+=1

maxnuma=-1
maxnumb=-1

maxa=max(lisa)
maxb=max(lisb)


for i in range(10**5):
  if lisa[i]==maxa:
    maxnuma=i
for i in range(10**5):
  if lisb[i]==maxb:
    maxnumb=i


if maxnuma!=maxnumb:
  print(n-maxa-maxb)
else:
  lisa.sort(reverse=True)
  lisb.sort(reverse=True)
  print(n-max(lisa[0]+lisb[1],lisa[1]+lisb[0]))



Measured memory_bytes: 20804
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1e9;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
//typedef pair<int, int> P;
/* struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
}; */

/** Problem1269 : Sum of Different Primes **/
const int MAX = 1200;
vector<int> prime;
int N, K;

int dp[MAX][15][200];

int solve(int n, int k, int idx)
{
	int res=0;
	
	if (n>N || idx>prime.size()) return 0;
	if (dp[n][k][idx]>=0) return dp[n][k][idx];
	
	//cerr << "solve(" << n << ", " << k << ", " << idx << ")" << endl;

	if (k==K) {
		return (n==N?1:0);
	}
	
	for (int i = idx; i<prime.size(); i++) {
		res += solve(n+prime[i], k+1, i+1);
	}
	
	return dp[n][k][idx] = res;
}

int main()
{
	REP(i, 2, MAX) {
		bool ok=true;
		for (int j=2; j*j<=i; j++) {
			if (i%j==0) ok=false;
		}
		if (ok) prime.push_back(i);
	}
	
	while (cin>>N>>K, N||K) {
		memset(dp, -1, sizeof(dp));
		cout << solve(0, 0, 0) << endl;
	}
}

Measured memory_bytes: 15280
use std::io::Read;
use std::cmp::max;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let a: usize = iterator.next().unwrap().parse().unwrap();
    let b: usize = iterator.next().unwrap().parse().unwrap();

    let a1: usize = (a as f64 / 0.08).ceil() as usize;
    let a2: usize = ((a + 1) as f64 / 0.08).ceil() as usize;

    let b1: usize = (b as f64 / 0.10).ceil() as usize;
    let b2: usize = ((b + 1) as f64 / 0.10).ceil() as usize;

    if b1 >= a2 || a1 >= b2 {
        return "-1".to_string()
    }

    let ans = max(a1, b1);

    return ans.to_string();
}


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

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

  if ( (n / 1000 == (n % 1000 / 100) && n / 1000 == (n % 100 / 10) ) || ( (n % 1000 / 100) == (n % 100 / 10) && (n % 1000 / 100) == (n % 10)) ){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A =[chr(i) for i in range(97, 97+26)]
# print(A)
L = []
while 1:
    a = N % 26
    N = N // 26
    # N -= 1
    if a == 0:
        N -= 1
    
    # print(a)
    # if a == 0:
    #     L.append(26)
    # else:
    L.append(a)
    if N <= 0:
        break
ans = ""
L.reverse()
for a in L:
    ans += A[a-1]
print(ans)





exit()
def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+","+out
        X_dumy = X_dumy//n
    return out
# while N:
# while N:
#     a = N % 26
#     N = N // 26
#     print(a)
ans = Base_10_to_n(N, 26)
l = ans.split(",")
print(l)
ans = ""
r = l[:-2]
if Counter(r)["1"]==len(r) and l[-2] == "0":
    # print(r)
    print("z" * (len(r)))
    exit()
#  == len(l[:-1]) and l[-1] == "0":
    # print(l)
    # exit()
for a in l:
    if len(a) != 0:
        a = int(a)
        # if a == 0:
        #     ans += "z"
        # else:

        tmp = A[a-1]
        ans += tmp

print(ans)

Measured memory_bytes: 10520
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int search(vector<string> &vec, int A){
    int N = vec.size();
    for (int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            if(vec[(i+A)%N][j]!=vec[(j+A)%N][i]){
                return 0;
            }
        }
    }
    return N;
}

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

    vector<string> vec(N);
    for(int i=0; i<N; i++){
        cin >> vec[i];
    }
    int ans=0;
    for(int i=0; i<N; i++){
        ans+=search(vec,i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <math.h>
#include <algorithm>
using namespace std;

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

int main()
{
	ll k;
	cin >> k;

	ll m = 7 % k;

	ll ans = 1;
	while (1)
	{
		if (m % k == 0) break;

		m *= 10;
		m += 7;
		m %= k;

		if (ans > k) {
			ans = -1;
			break;
		}
		
		ans++;
	}

	cout << ans << endl;

	return 0;
}

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

typedef long long int LLI;

int n;
vector<int> a;
vector<int> b;

void input() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int t;
    cin >> t;
    a.push_back(t);
  }
}

LLI sub2(int l, int m, int r) {
  for (int i = l; i < r; ++i) {
    b[i] = a[i];
  }
  int k = l;
  int p = l;
  int q = m;
  LLI t = 0;
  while (k < r) {
    if (p == m) {
      a[k++] = b[q++];
    } else if (q == r) {
      a[k++] = b[p++];
    } else if (b[q] < b[p]) {
      a[k++] = b[q++];
      t += m - p;
    } else {
      a[k++] = b[p++];
    }
  }
  return t;
}

LLI sub1(int l, int r) {
  if (r - l < 2) {
    return 0;
  }
  int m = (l + r) / 2;
  LLI t = 0;
  t += sub1(l, m);
  t += sub1(m, r);
  t += sub2(l, m, r);
  return t;
}

LLI solve() {
  b.resize(a.size());
  return sub1(0, n);
}

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

  input();
  LLI ans = solve();
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 4628
# include <bits/stdc++.h>
using namespace std;
void solve(){
	string s, t;
	cin >> s >> t;
	if(t.substr(0, s.size()) == s){
		cout << "Yes\n";
	}else{
		cout << "No\n";
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
}

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

int main(){
    ll l,r;
    int ans=2018;
    cin >> l >> r;
    r=min(r,l+4038);
    for(ll i=l;i<=r;i++){
        for(ll j=i+1;j<=r;j++){
            int a= i*j%2019;
            ans=min(ans,a);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256