akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define Rep(var,init,cnt) for(int (var)=(init); (var)<(int)(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(rall(v))
#define SUM(v) accumulate(all(v),0)
#define tget(tp,idx) get<idx>(tp)
#define TF(flag) ((flag)?1:0)
#define YN(flag) cout<<(flag?"YES":"NO")<<endl;
#define Yn(flag) cout<<(flag?"Yes":"No")<<endl;
#define yn(flag) cout<<(flag?"yes":"no")<<endl;
#define Cout(v) cout<<(v)<<endl
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using ti = tuple<int,int,int>;
using tl = tuple<ll,ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

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

template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}

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

template<typename T>
istream &operator>>(istream &is, valarray<T> &v){
  for(T &in:v) is>>in;
  return is;
}

// Usual Template End ===================

// Template End =========================

int main(void){
  string s; cin>>s;
  int m=stoi(s.substr(5,2)),d=stoi(s.substr(8,2));
  Cout(m<=4?"Heisei":"TBD");
}












Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>
#include <bitset>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

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

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    ll n;
    cin >> n;
    vll s(n);
    rep(i, n) cin >> s[i];

    ll ans = 0;
    for(ll c = 0; c < n; c++) {
        ll score = 0;
        vb f(n, false);
        for(ll k = 0; (k + 1) * c < n - 1; k++) {
            if(f[k * c]) break;
            score += s[k * c];
            f[k * c] = true;
            if(f[n - 1 - k * c]) break;
            score += s[n - 1 - k * c];
            if(f[n - 1 - k * c]) break;
            chmax(ans, score);
        }
    }
    cout << ans << endl;
    return;
}

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

Measured memory_bytes: 3908
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);++i)
#define urep(i,a,n) for(ll i = (a);i>=(n);--i)
#define all(x) (x).begin(),(x).end()
#define INF 1e18
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N,M,X,Y,A,B,C,Q,K,R;
string S,T;
ll ans;
ll x[1000000];
ll y[1000000];
ll a[1000000];
ll b[1000000];
ll c[1000000];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
struct Edge{
	ll to,cost;
	 Edge(int to, int cost) : to(to), cost(cost) {}
};
typedef vector<vector<Edge> > AdjList;
AdjList graph;
vector<ll> dist;
int main() {
	cin>>S;
	S[3]='8';
	cout<<S<<endl;
	return 0;
}


Measured memory_bytes: 256
import sys,os
from collections import defaultdict, deque
from math import ceil, floor
if sys.version_info[1] >= 5:
    from math import gcd
else:
    from fractions import gcd
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    MOD = 10**9+7

    S,W = LMIIS()
    if S <= W:
        print('unsafe')
    else:
        print('safe')
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 65136
#!/usr/bin/env ruby

a, b, c, d = gets.strip.split().map(&:to_i)

def calc(s1, e1, s2, e2)
  return 0 if e1 <= s2
  e = e1 > e2 ? e2 : e1
  e - s2
end

if a < c then
  puts calc(a, b, c, d)
else
  puts calc(c, d, a, b)
end


Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { -1, 0, 0, 1 };
const ll dy[4] = { 0, -1, 1, 0 };
const ll INF = 1e9 + 7;
const ll inf = 1LL << 50;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
struct Accelerate_Cin {
	Accelerate_Cin() {
		cin.tie(0);
		ios::sync_with_stdio(0);
		cout << fixed << setprecision(20);
	};
};
///////////////////////////////////////


int main() {
	string s; cin >> s;
	ll k; cin >> k;
	set<char>se;
	for (int i = 0; i < s.size(); ++i) {
		se.insert(s[i]);
	}
	if (se.size() == 1) {
		cout << s.size()* k/ 2 << endl;
		return 0;
	}
	string S = s + s;
	ll sum = 0;
	ll Sum = 0;
	if (s.size() == 1) {
		cout << k / 2 << endl;
		return 0;
	}
	for (int i = 0; i < S.size()-1; ++i) {
		if (S[i] == S[i + 1]) {
			ll x = 1;
			while (S[i] == S[i + 1]) {
				x++;
				i++;
			}
			sum += (x / 2);
		}
	}
	for (int i = 0; i < s.size() - 1; ++i) {
		if (s[i] == s[i + 1]) {
			ll x = 1;
			while (s[i] == s[i + 1]) {
				x++;
				i++;
			}
			Sum += (x / 2);
		}
	}	
	if (sum == Sum * 2) {
		cout << Sum * k << endl;
	}
	else {
		cout << Sum * k + (k - 1) << endl;
	}
	return 0;
}


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

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    ll N;
    cin >> N;

    vector<ll> A(5);
    rep(i,5) cin >> A[i];

    ll min = *min_element(A.begin(), A.end());

    cout << (N + (min - 1LL)) / min + 4LL << endl;
    return 0;
}


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

int main(void)
{
  int i,j;
  int n,m;
  int a[100],b[100];
  int sa,sb,dif;
  int aa,ab;

  while(1){
    scanf("%d %d",&n,&m);
    if(!n && !m)break;

    sa = 0;
    sb = 0;
    for(i=0;i<n;i++){
      scanf("%d",&a[i]);
      sa += a[i];
    }
    for(i=0;i<m;i++){
      scanf("%d",&b[i]);
      sb += b[i];
    }
 
    dif = sa-sb;

    aa = 0;
    ab = 0;
    for(i=0;i<n;i++){
      for(j=0;j<m;j++){
	if((a[i]-b[j])*2==dif){
	  aa = a[i];
	  ab = b[j]; 
	  break;
	}
      }
      if(aa && ab)break;
    }

    if(!aa && !ab)printf("-1\n");
    else printf("%d %d\n",aa,ab);
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vb=vector<bool>;
using vvb=vector<vb>;
using vc=vector<char>;
using vvc=vector<vc>;
using pii = pair<int,int>;
using pil = pair<int,ll>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using tiii = tuple<int,int,int>;
using vpii = vector<pii>;
using vpil = vector<pil>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#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++)
int INF=1e9+7;

int main() {
  int X;
  cin >> X;
  if(X>=30) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

signed main(){
    int n,m;
    cin >> n >> m;
    priority_queue<int > Q;

    REP(i,n){
        int tmp;
        cin >> tmp;
        Q.push(tmp);
    }

    REP(i,m){
        int tmp = Q.top();
        Q.pop();
        tmp /= 2;
        Q.push(tmp);
    }

    int ans = 0;
    REP(i,n){
        int tmp = Q.top();
        ans += tmp;
        Q.pop();
    }

    cout << ans << endl;

}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int n;
  cin >> n;
  vi d(n);
  REP(i, n) { cin >> d[i]; }

  vi c(13);
  REP(i, n) {
    c[d[i]]++;
    if (d[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }

  vi a;
  a.push_back(0);
  a.push_back(24);
  int use = 1;
  REP(i, 13) {
    if (c[i] >= 3) {
      cout << 0 << endl;
      return 0;
    }
    if (c[i] == 2) {
      a.push_back(i);
      a.push_back(24 - i);
      use = (use | (1 << i));
    }
  }

  int ans = 0;
  REP(i, (1 << 12)) {
    vi b;
    REP(j, a.size()) { b.push_back(a[j]); }

    FOR(j, 1, 13) {
      if (c[j] != 1)
        continue;
      if ((i >> (j - 1)) % 2 == 0) {
        b.push_back(j);
      } else {
        b.push_back(24 - j);
      }
    }

    sort(ALL(b));
    int tmp = 50;
    FOR(j, 1, b.size()) { tmp = min(tmp, b[j] - b[j - 1]); }
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn = 1e5 + 10;

int n, m;
int num[maxn];
bool ok[maxn];

int main() {
//    freopen("input.in", "r", stdin);
  //  freopen("output.out", "w", stdout);

    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i) num[i] = 1;
    ok[1] = 1;
    while (m--) {
        int u, v; scanf("%d%d", &u, &v);
        if (ok[u]) {
            ok[v] = 1;
            ok[u] = num[u] > 1;
        }
        num[u]--; num[v]++;
    }
    int cnt = 0;
    for (int i = 1; i <= n; ++i) cnt += ok[i];
    printf("%d\n", cnt);

    return 0;
}


Measured memory_bytes: 768
class UnionFind:
    def __init__(self, n):
        self.parent = [i for i in range(n + 1)]
        self.rank = [0 for _ in range(n + 1)]
        self.size = [1] * (n + 1)
        self.group = [[i] for i in range(n + 1)]

    def find(self, x):
        # If x is root
        if self.parent[x] == x:
            return x
        # If x is not root, search again by using x's parent
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        # Make an edge from the root of lower tree to the root of higher tree
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
            self.size[y] += self.size[x]
        else:
            self.parent[y] = x
            self.size[x] += self.size[y]
            # If the height of tree the tree is the same, increase one of the heights by 1
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def check_same(self, x, y):
        return self.find(x) == self.find(y)

    def get_size(self, x):
        return self.size[self.find(x)]

    def merge(self, x, y):
        """
        "データ構造をマージする一般的なテク"
        """
        x = self.find(x)
        y = self.find(y)
        if len(self.group[x]) < len(self.group[y]):
            x, y = y, x
        self.group[x].extend(self.group[y])
        self.group[y] = []
        self.parent[y] = x



N, M = map(int, input().split())

uf = UnionFind(N)
for i in range(M):
    x, y, z = map(int, input().split())
    uf.union(x, y)


se = set()
ans = 0
for i in range(1, N+1):
    tmp = uf.find(i)
    if tmp in se:
        continue
    else:
        ans += 1
        se.add(tmp)

print(ans)


Measured memory_bytes: 30976
#include <iostream>
#include <math.h>
#include <vector>
#include <stack>
#include <cstdio>
#include <string>
#include <bitset>
#include <list>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <functional>
#include <queue>
// #include "bits/stdc++.h"

using namespace std;
//debug

#define rep(i, N) for (int i = 0; i < N; i++)
#define rep2(i, N, M) for (int i = N; i < M; i++)
#define pb push_back



typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef priority_queue<pll, vector<pll>, greater<pll>> greater_pq ;


#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define vec(a) vector<a>

void f(string& str) {
	str.insert(str.begin(), str.back());
	str.pop_back();
}

int main() {
	int N;
	cin >> N;
	vll a(N);
	rep(i,N) cin >> a[i];

	cout<< accumulate(a.begin(), a.end(), 0) - N;

	return 0;
}



Measured memory_bytes: 256
import collections
N = int(input())
s = [0] * N
for i in range(N):
  s[i] = str(input())
  
#print(s)
t = collections.Counter(s)
u = list(t.items())
#print(u)
x = max(list(t.values()))
ans = []
#print(x)
#print(u)
for i in range(len(u)):
  #print(u[i][1], x)
  if u[i][1] == x:
    ans.append(u[i][0])
    
    
ans = sorted(ans)

for i in range(len(ans)):
  print(ans[i])
    

Measured memory_bytes: 49192
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
//typedef long long ll;
const int N=2000005;
int siz[N],ch[N][26],tot=0;
void ins(char *s)
{
	int n=strlen(s),now=0;
	for(int i=0;i<n;i++)
	{
		if(!ch[now][s[i]-'a'])ch[now][s[i]-'a']=++tot;
		now=ch[now][s[i]-'a'];
	}
}
void find(int k)
{
	int now=0;
	while(k>0)
	{
		//cout <<now<<' '<<k<<endl;
		for(int i=0;i<26;i++)
			if(ch[now][i])
			{
				/*if(siz[ch[now][i]]==k)
				{
					cout <<(char)(i+'a');
					return;	
				}*/
				if(siz[ch[now][i]]>=k)
				{
					cout <<(char)(i+'a');
					k--;
					now=ch[now][i];
					break;
				}
				else k-=siz[ch[now][i]];
			}
	}
}
char s[N];
int main()
{
	//freopen("input.txt","r",stdin);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >>(s+1);
	int n=strlen(s+1);
	//for(int i=1;i<=n;i++)ins(s+i);
	for(int i=0;i<26&&tot<10;i++)
	{
		for(int j=1;j<=n;j++)
			if(s[j]-'a'==i)
				ins(s+j);
	}
	for(int i=tot;i>=1;i--)
	{
		siz[i]=1;
		for(int j=0;j<26;j++)if(ch[i][j])siz[i]+=siz[ch[i][j]];
	}
	int k;
	cin >>k;
	find(k);
	cout <<endl;
	return 0;
}

Measured memory_bytes: 57728
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long  k,x;bool f=0;
    cin>>k>>x;
    for (long long i=x-k+1;i<=x+k-1;i++)
        if (i>=-1000000&&i<=1000000)
            if (f==0)cout<<i,f=1;
            else cout<<" "<<i;
	return 0;
}


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

enum state { New, Working, Done };

int main()
{
	int n;
	cin >> n;
	vector<vector<pair<int, int>>> al(n);
	for (int i = 0; i < n; i++) {
		int u, k;
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			int v, c;
			cin >> v >> c;
			al[u].push_back(make_pair(v, c));
		}
		sort(al[i].begin(), al[u].end());
	}

	vector<int> d(n, INT_MAX);
	vector<state> status(n);
	d[0] = 0;
	status[0] = Working;
	priority_queue<pair<int, int>> pq;  // pq.first: value, pq.second: node
	pq.push(make_pair(0, 0));
	while (!pq.empty()) {
		int node = pq.top().second;
		int value = pq.top().first;
		pq.pop();
		status[node] = Done;

		if (d[node] < value*(-1)) continue;

		for (int i = 0; i < al[node].size(); i++) {
			int nextNode = al[node][i].first;
			int nextValue = al[node][i].second;
			if (status[nextNode] == Done) continue;
			if (d[node] + nextValue < d[nextNode]) {
				d[nextNode] = d[node] + nextValue;
				pq.push(make_pair(d[nextNode] * (-1), nextNode));
				status[nextNode] = Working;
			}
		}
	}

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



Measured memory_bytes: 7812
# include <stdio.h>
 int main()
{ int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  if(a+b==c||b+c==a||a+c==b)
{
	printf("Yes");
}	
    else
{   printf("No");
}
 return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
using namespace std;
#define MAX_N 100000
int main(void) {
    int N;
    int a[MAX_N], b[MAX_N], dif[MAX_N];
    int i;
    scanf("%d", &N);
    for(i=0; i<N; i++) {
        scanf("%d", &a[i]);
    }
    for(i=0; i<N; i++) {
        scanf("%d", &b[i]);
    }
    int mincount = 0;
    long long minus = 0;
    long long plus = 0;
    for(i=0; i<N; i++) {
        dif[i] = a[i] -b[i];
        if (dif[i] < 0) {minus += dif[i]; mincount ++;}
        if (dif[i] > 0) plus += dif[i];
    }
    
    bool ans = true;
    if ((-1) * minus > plus) ans = false;
    sort(dif, dif+N, greater<int>());
    int count = 0;
    long long sum = 0;
    for(count =0; count < N; count++ ) {
       if (sum >= (-1) * minus) break;
       sum += dif[count];
    }
    if (!ans) printf("%d\n", -1);
    else printf("%d\n", count+mincount);
    
}


Measured memory_bytes: 1408
from collections import Counter

n = int(input())
a = list(map(lambda a: int(a) // 400, input().split()))
for i in range(n):
    if a[i] >= 8:
        a[i] = 8
c = Counter(a)
if 8 in c:
    print("{} {}".format(
        max(len(c) - 1, 1),
        len(c) - 1 + c[8]))
else:
    print("{} {}".format(
        len(c), len(c)))


Measured memory_bytes: 3316
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var ABCK = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var A = ABCK[0]; var B = ABCK[1]; var C = ABCK[2]; var K = ABCK[3];
            if ((A + B) >= K) Console.WriteLine(Math.Min(A, K));
            else Console.WriteLine(A - (K - (A + B)));
        }
    }
}


Measured memory_bytes: 27544
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void)
{
	int n, k, p[1001],i,j,temp,sum = 0;
	scanf("%d %d",&n,&k);
	for(i=0;i<n;i++){
		scanf("%d",&p[i]);
	}
	for(i=0;i<n-1;i++){
		for(j=0;j<n-1;j++){
			if(p[j]>p[j+1]){
				temp = p[j];
				p[j] = p[j+1];
				p[j+1] = temp;
			}
		}
	}
	for(i=0;i<k;i++){
		sum = sum + p[i];
	}
	printf("%d",sum);
	
	return 0;
}

Measured memory_bytes: 1704
# frozen_string_literal: true

def c_count(n)
  n * (n - 1) / 2
end

n = gets.to_i
a = gets.split.map(&:to_i)

a_count = Array.new(n, 0)
a.each do |x|
  a_count[x - 1] += 1
end
a_sum = a_count.inject(0) do |r, x|
  r + c_count(x)
end
n.times do |i|
  before = c_count(a_count[a[i] - 1])
  after = c_count(a_count[a[i] - 1] - 1)
  puts a_sum - before + after
end


Measured memory_bytes: 23684
use proconio::input;
use proconio::marker::Usize1;
use std::collections::VecDeque;

fn main()
{
    input! {
    n:usize,
    m:usize,
    edge:[(Usize1,Usize1);m],
    (s,t):(Usize1,Usize1),
    }
    let mut node = vec![vec![]; n];
    for (a, b) in edge {
        node[a].push(b);
    }

    let inf = 1i64 << 60;
    let mut cost = vec![vec![inf; 3]; n];
    cost[s][0] = 0;

    let mut q = VecDeque::new();
    q.push_back((s, 0, 0));

    while let Some((idx, dist, cnt)) = q.pop_front()
    {
        let cnt = (cnt + 1) % 3;
        let dist = if cnt == 1 {
            dist + 1
        } else {
            dist
        };

        for &nxt in node[idx].iter() {
            if cost[nxt][cnt] <= dist {
                continue;
            }
            cost[nxt][cnt] = dist;
            q.push_back((nxt, dist, cnt));
        }
    }

    let ans = if cost[t][0] == inf {
        -1
    } else {
        cost[t][0]
    };

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

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

int main(){
    string S;
    cin >> S;
    int n0 = 0;
    int n1 = 0;
    for(const auto s : S){
        if(s == '0'){
            n0++;
        }else{
            n1++;
        }
    }
    cout << (n0 <= n1 ? 2*n0 : 2*n1);
    return EXIT_SUCCESS;
}

Measured memory_bytes: 512
s=input()

s=s[::-1]

counts = [0] * 2019
counts[0] = 1

num=0
d = 1


for char in s:
    num += int(char) * d
    num %= 2019
    d *= 10
    d %= 2019
    counts[num] += 1
    
ans = 0
for cnt in counts:
    ans += cnt * (cnt - 1) // 2

print(ans) # 答えの出力   



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

vector<int> prime;
int prime_factor[110] = {};

void primeenumeration(int n) {
  FOR(i, 2, n+1) {
    bool flag = true;
    FOR(j, 2, i) {
      if (j*j > i) break;
      if (i%j == 0) {
        flag = false;
        break;
      }
    }
    if (flag) prime.push_back(i);
  }
}

void primefactorization(int n) {
  for (int i = 0; n >= prime[i];) {
    if (n%prime[i] == 0) {
      n /= prime[i];
      prime_factor[prime[i]]++;
    } else {
      i++;
    }
  }
}

int num(int n) {
  int cnt = 0;
  rep(i, 100) {
    if (prime_factor[i] >= n-1) cnt++;
  }
  return cnt;
}

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

  int n;
  cin >> n;

  primeenumeration(100);
  rep(i, n) {
    primefactorization(i+1);
  }

  rep(i, 101) {
    cerr << i << " " << prime_factor[i] << endl;
  }
  // 75
  // 25 * 3
  // 15 * 5
  // 5 * 5 * 3

  int ans = num(75)
          + num(25) * (num(3)-1)
          + num(15) * (num(5)-1)
          + num(5) * (num(5)-1) * (num(3)-2) / 2;

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

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

  ll ans=0;
  while(1){
    ll ma=0;
    int mat=0;
    for(int i=0;i<n;i++){
      if(ma<a[i]) mat=i;
      ma=max(ma,a[i]);
    }
    if(ma<n) break;

    ll z=ma/n;
    for(int i=0;i<n;i++){
      if(i==mat) a[i]=a[i]%n;
      else a[i]+=z;
    }
    ans+=z;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
int a[100010];
bool b[100010];
int main(){
	string y;
	int n,m,ans1,x;
	long long ans2;
	cin>>n>>m;
	for(int i=1;i<=n;i++) b[i]=false;
	for(int i=1;i<=m;i++){
		cin>>x>>y;
		if(y=="WA"&&b[x]==false) a[x]++;
		if(y=="AC") b[x]=true;
	}
	ans1=ans2=0;
	for(int i=1;i<=n;i++){
		if(b[i]==true){
			ans1++;
			ans2+=a[i];
		}
	}
	cout<<ans1<<" "<<ans2;
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ll dx[]={0,1,0,-1};
ll dy[]={1,0,-1,0};
const ll mx=200000;
ll m=1e9+7;
ll f[mx],inv[mx];
long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
void init()
{
    f[0]=1,inv[0]=1;
    for(int i=1;i<mx;i++)
    {
        f[i]=(f[i-1]%m * i%m)%m;
        inv[i]=binpow(f[i],m-2,m);
    }
}
ll nck(ll n,ll k)
{
    if(n<k)
        return 0;
    ll ans=f[n];
    ans=(ans%m * inv[k]%m)%m;
    ans=(ans%m * inv[n-k]%m)%m;
    return ans;
}
int main()
{
    init();
    ll n,k;
    cin>>n>>k;
    ll arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    sort(arr,arr+n);
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        ll p=(arr[i]%m * nck(i,k-1)%m)%m;
        ll q=(arr[i]%m * nck(n-i-1,k-1)%m)%m;
        ll r=(p-q+m)%m;
        ans=(ans + r)%m;
    }
    cout<<ans;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N, H, maxA = 0;
    cin >> N >> H;
    vector<int> A(N);
    vector<int> B(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i) >> B.at(i);
        maxA = max(A.at(i), maxA);
    }
    sort(B.begin(),B.end());
    reverse(B.begin(),B.end());
    int i = 0;
    int sumB = 0;
    while (B.at(i) > maxA) {
        sumB += B.at(i);
        if (sumB >= H) {
            cout << i + 1 << endl;
            return 0;
        }
        i++;
        if (i == N) {
            break;
        }
    }
    H -= sumB;
    cout << i + H / maxA + (H % maxA + maxA - 1) / maxA << endl;
}

Measured memory_bytes: 4024
n = int(input())
A = list(map(int, input().split()))

A.sort()
from itertools import accumulate
C = [0]+A
C = list(accumulate(C))

def is_ok(x):
    if x == n-1:
        return True
    y = C[x+1]
    flag = True
    for i in range(x+1, n):
        if A[i] > 2*y:
            flag = False
        y += A[i]
    if flag:
        return True
    else:
        return False

if is_ok(0):
    print(n)
    exit()

l = 0
r = n-1
while l+1 < r:
    c = (l+r)//2
    if is_ok(c):
        r = c
    else:
        l = c
print(n-r)


Measured memory_bytes: 14360
using System;
using System.Linq;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using static program.Input;
using static program.MyMath;
using static System.Console;

namespace program {
  class Program {
    static string Alp = "abcdefghijklmnopqrstuvwxyz";
    static void Main()
    {
      var s = ScanStr();
      var n = ScanLong();
      for(int i=0; i<n; i++){
        if(s[i] != '1'){
          WriteLine(s[i]);
          return;
        }
      }
      WriteLine(1);
    }
  }
  
  static class Input {
    static public int ScanInt() { return int.Parse(Console.ReadLine()); }
    static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
    static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
    static public long ScanLong() { return long.Parse(Console.ReadLine()); }
    static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
    static public int[] ScanIntArray() { return Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray(); }
    static public uint[] ScanUintArray() { return Console.ReadLine().Split().Select(x => uint.Parse(x)).ToArray(); }
    static public double[] ScanDoubleArray() { return Console.ReadLine().Split().Select(x => double.Parse(x)).ToArray(); }
    static public long[] ScanLongArray() { return Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray(); }
    static public ulong[] ScanUlongArray() { return Console.ReadLine().Split().Select(x => ulong.Parse(x)).ToArray(); }

    static public string ScanStr() { return Console.ReadLine(); }
    static public string[] ScanStrArray() { return ScanStr().Split(); }
    static public string RegaxReplace(this string arg1, string pattern, string replacement)
    {
      return Regex.Replace(arg1, pattern, replacement);
    }
  }
  
  static class MyMath {
    public static int GCD(int a, int b) {
        Func<int, int, int> gcd = null;
        gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
        return a > b ? gcd(a, b) : gcd(b, a);
    }
    public static long GCD(long a, long b) {
        Func<long, long, long> gcd = null;
        gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
        return a > b ? gcd(a, b) : gcd(b, a);
    }
    public static ulong extGCD(ulong a, ulong b, ref ulong x, ref ulong y) {
      if(b==0) {
        x=1; 
        y=0;
        return a;
      }
      var d = extGCD(b, a%b, ref y, ref x);
      y -= a/b *x;
      return d;
    }
    public static int LCM(int a, int b) { return a * b / GCD(a, b); }
    public static long LCM(long a, long b) { return a * b / GCD(a, b); }
  }
}


Measured memory_bytes: 11092
import sys

l1 = sys.stdin.readline().strip()
l1 = [int(x.strip()) for x in l1.split()]

A, B, C = sorted(l1)

rA, sA = divmod((C-A), 2)
rB, sB = divmod((C-B), 2)
s = [sA, sB]

res = rA + rB

if s == [0, 0]:
  res += 0
elif s == [1, 1]:
  res += 1
else:
  res += 2

print(res)



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


int main(void){
  vector<int> a(3);
  cin>>a.at(0)>>a.at(1)>>a.at(2);
  sort(a.begin(),a.end());
  int sum=0;
  r(i,a.size()-1)sum+=a.at(i);
  cout<<sum<<endl;;





return 0;

}


Measured memory_bytes: 256
import sys, io, os, re
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor, ceil
from copy import copy, deepcopy
from collections import deque, defaultdict
from fractions import gcd
from functools import reduce
from itertools import groupby, combinations
from heapq import heapify, heappush, heappop

# sys.setrecursionlimit(5000)

n1 = lambda: int(sys.stdin.readline().strip())
nn = lambda: list(map(int, sys.stdin.readline().strip().split()))
f1 = lambda: float(sys.stdin.readline().strip())
fn = lambda: list(map(float, sys.stdin.readline().strip().split()))
s1 = lambda: sys.stdin.readline().strip()
sn = lambda: list(sys.stdin.readline().strip().split())
nl = lambda n: [n1() for _ in range(n)]
fl = lambda n: [f1() for _ in range(n)]
sl = lambda n: [s1() for _ in range(n)]
nm = lambda n: [nn() for _ in range(n)]
fm = lambda n: [fn() for _ in range(n)]
sm = lambda n: [sn() for _ in range(n)]

def array1(n, d=0): return [d] * n
def array2(n, m, d=0): return [[d] * m for x in range(n)]
def array3(n, m, l, d=0): return [[[d] * l for y in xrange(m)] for x in xrange(n)]
def linc(A, d=1): return list(map(lambda x: x + d, A))
def ldec(A, d=1): return list(map(lambda x: x - d, A))


D, T, S = nn()

if D / S <= T:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 72804
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,v;
vector<int>pos[200005];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	{
		scanf("%d",&v);
		pos[v].push_back(i);	
	}
	if(pos[1].empty())puts("-1");
	else
	{
		int ans=1,now=pos[1][0];
		for(int i=2;i<=n;++i)
		{
			if(pos[i].empty())break;
			//printf("i:%d ans:%d\n",i,ans);
			auto x=lower_bound(pos[i].begin(),pos[i].end(),now);
			if(x==pos[i].end())break;
			else now=*x,ans++;
		}
		printf("%d\n",n-ans);
	}
	return 0;
} 

Measured memory_bytes: 11264
h,w = map(int,input().split())
if h%3 == 0 or w%3 == 0:
    print(0)
    exit()

ans = float('inf')
for i in range(1,w):
    s = []
    s.append(i*h)
    if h%2 == 1:
        s.append((w-i)*(h//2+1))
    s.append((w-i)*(h//2))
    ans = min(ans,max(s)-min(s))

for i in range(1,h):
    s = []
    s.append(i*w)
    if w%2 == 1:
        s.append((h-i)*(w//2+1))
    s.append((h-i)*(w//2))
    ans = min(ans,max(s)-min(s))

ans = min(ans, h*(w//2+1) - h*(w//2), w*(h//2+1) - w*(h//2))
print(ans)

Measured memory_bytes: 3064
s = input()
if 'W' in s and 'E' in s and 'N' in s and 'S' in s:
    print('Yes')
elif 'W' in s and 'E' in s and not 'N' in s and not 'S' in s:
    print('Yes')
elif not 'W' in s and not 'E' in s and 'N' in s and 'S' in s:
    print('Yes')
else:
    print('No')


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

signed main(){

    
    int N,answer = 0;
    cin>>N;
    
    std::list<int> A,B,C;
    
    for(int i = 0; i < N ;i++ ){
        int num;
        cin >> num;
        A.push_back(num);
    }
    for(int i = 0; i < N ;i++ ){
        int num;
        cin >> num;
        B.push_back(num);
        answer += num;
    }
    for(int i = 0; i < N-1 ;i++ ){
        int num;
        cin >> num;
        C.push_back(num);
    }
    
    for(int i = 0; i< N ; i++){
        
        if( *std::next(A.begin(), i+1) - *std::next(A.begin(), i) == 1){
            int t = *std::next(C.begin(), *std::next(A.begin(),i)-1) ;
            answer += t ;
        }
    }
    
    cout << answer;

    return 0;
}


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

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

using namespace std;
using ll = long long;


int main()
{
	int n, m;
	cin >> n >> m;
	vector<pair<int,int>> a(n); for(int i = 0; i < n; i++)cin >> a[i].first >> a[i].second;
	sort(a.begin(), a.end());
	ll sum = 0;

	for(int i = 0;m; i++) {
		sum += (ll)a[i].first * min(a[i].second, m);
		m = max(m - a[i].second, 0);
	}
	cout << sum << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
// #include <ctime>

using namespace std;
typedef unsigned long long ull;

int main(){
	ull v = 0;
	const int MAX_N = 50;
	int X1[MAX_N], Y1[MAX_N], D1[MAX_N], X2[MAX_N], Y2[MAX_N], D2[MAX_N];
	int N, K;

	cin >> N >> K;

	vector<int> X(2 * N), Y(2 * N), D(2 * N);

	for (int i = 0; i<N; i++){
		cin >> X1[i] >> Y1[i] >> D1[i] >> X2[i] >> Y2[i] >> D2[i];
		X[i]     = X1[i];
		X[i + N] = X2[i];
		Y[i]     = Y1[i];
		Y[i + N] = Y2[i];
		D[i]     = D1[i];
		D[i + N] = D2[i];
	}
//	clock_t st = clock();
	sort(X.begin(), X.end());
	sort(Y.begin(), Y.end());
	sort(D.begin(), D.end());

	for (int i = 0, n = 2*N - 1; i<n; i++){
	for (int j = 0; j<n; j++){
	for (int k = 0; k<n; k++){
		int kind = 0;
		for (int l = 0; l < N; l++){
			if (X1[l] <= X[i] && X[i+1] <= X2[l] && 
				Y1[l] <= Y[j] && Y[j+1] <= Y2[l] && 
				D1[l] <= D[k] && D[k+1] <= D2[l]) kind++;
		}
		if (kind >= K) v += (ull)(X[i+1] - X[i]) * (Y[j+1] - Y[j]) * (D[k+1] - D[k]);
	}
	}
	}

	cout << v << endl;
//	clock_t ed = clock();
//	cout << (double)(ed - st) / CLOCKS_PER_SEC << endl;
	return 0;
}

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

int main() {
	int64_t N, K;
	cin >> N >> K;

	int64_t answer = 0;

	for (int64_t i = K; i < N + 2; i++) {
		answer += ((N - i + 1) * i) + 1;
		answer = answer % 1000000007;
	}

	cout << answer << endl;

	return 0;
}


Measured memory_bytes: 3564
import sys

sys.setrecursionlimit(10 ** 5)


def dfs(v, parent, depth):
    parents[v] = parent
    self_depths[v] = depth
    sd = 0
    for u in links[v]:
        if u == parent:
            continue
        res = dfs(u, v, depth + 1)
        sd = max(sd, res + 1)

    subtree_depths[v] = sd
    return sd


def solve(u):
    ans = 0
    catch = self_depths[u] // 2
    while self_depths[u] > catch:
        ans = max(ans, self_depths[u] + subtree_depths[u] - 1)
        u = parents[u]
    return ans


n, u, v = map(int, input().split())
u -= 1
v -= 1
links = [set() for _ in range(n)]
for line in sys.stdin:
    a, b = map(int, line.split())
    a -= 1
    b -= 1
    links[a].add(b)
    links[b].add(a)

parents = [-1] * n
self_depths = [0] * n
subtree_depths = [0] * n
dfs(v, -1, 0)
# print(parents)
# print(self_depths)
# print(subtree_depths)
print(solve(u))


Measured memory_bytes: 111652
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		int ans=0;
		for(int i = s[0];i<=s[1];i++) {
			if(i%s[2]==0){ans++;}
		}
		Console.WriteLine("{0}",ans);
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public int[] Ia3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public long[] La3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

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

int main(void)
{
    int K, X;
    cin >> K >> X;

    int start;
    start = X - K + 1;
    for(int i=start;i<X+K-1;i++)
    {
        cout << i << " ";
    }
    cout << X+K-1;
    return 0;
}

Measured memory_bytes: 256
<?php
// 整数の入力
fscanf(STDIN, "%d", $n);

$data = array();

for ($i = 0; $i < $n; $i++) {
  $a = fscanf(STDIN, "%d");
  $data[] = $a[0];
}

//昇順に並べる
sort($data);

$left = 0;
$right = $n - 1;
$small = 0;
$large = $n - 1;
$sum = $data[$right] - $data[$left];

while (($large - $small) > 1) {
  $p = abs($data[$left] - $data[$small + 1]);
  $q = abs($data[$left] - $data[$large - 1]);
  $r = abs($data[$right] - $data[$small + 1]);
  $s = abs($data[$right] - $data[$large - 1]);

  //4つの中から最大のやつを選ぶ
  $max = max($p, $q, $r, $s);

  if ($max === $p) {
    $sum += $p;
    $small++;
    $left = $small;
  } elseif ($max === $q) {
    $sum += $q;
    $large--;
    $left = $large;
  } elseif ($max === $r) {
    $sum += $r;
    $small++;
    $right = $small;
  } elseif ($max === $s) {
    $sum += $s;
    $large--;
    $right = $large;
  }
}

echo $sum;
?>


Measured memory_bytes: 21028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define Y cout << "YES\n"
#define N cout << "NO\n"
#define REP(i, a, b) for (int i = a; i <= b; i++)
#define R(i,n) for(int i = 0 ; i < n ; i++)
#define RE(i, a, b) for (int i = a; i >= b; i--)

int main()
{
	ll mod , n , x , a[100010] , ans = 1 , flag = 0 ;
	cin >> n ;
	mod = 1000000000000000000 ;
	R(i,n)
	{
		cin >> a[i] ;
	}
	sort(a,a+n) ;
	R(i,n)
	{
		if(ans == 0)
		{
			break ;
		}
		x = (mod/ans) ;
		if( a[i] > x )
		{
			flag = 1 ;
			cout << "-1\n" ;
			break ;
		}
		ans *= a[i] ; 
	}
	if(flag == 0)
	{
		cout << ans << endl ;
	}
}

Measured memory_bytes: 4360
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
typedef long long ll;
using namespace std;

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

    int min = 1000000000;
    int ans = 0;

    for (int i = 0; i < n; i++) {
        if (abs(a[i]*n - ave) < min) {
            min = abs(a[i]*n - ave);
            ans = i;
        }
    }

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

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, q; string s;
	cin >>n >>s >>q;
	vector<set<int>> wd(26);
	rep(i, n) wd[s[i]-'a'].insert(i);
	
	while(q--){
		int ck, ps, l, r; char z;
		cin >>ck;
		if(ck==1){
			cin >>ps >>z;
			if(s[ps-1]==z) continue;
			wd[s[ps-1]-'a'].erase(ps-1);
			wd[z -'a'].insert(ps-1);
			s[ps-1] = z;
		}else{
			cin >>l >>r;
			int ans = 0;
			rep(i, 26){
				auto it = wd[i].lower_bound(l-1);
				for(; it!=wd[i].end();i++){
					if(*it > r-1) break;
					ans ++; break;
				}
			}
			cout << ans <<"\n";
		}
	}
	return 0;
}


Measured memory_bytes: 24220
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

ll nmax = 1000000000000001;

int main(){

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

    ll n; cin >> n;
    n--;

    string s = "";
    while(n >= 0){
        char c = 'a' + n % 26;
        s.push_back(c);

        if(n - 26 < 0) break;
        n = (n - 26) / 26;
    }

    reverse(s.begin(), s.end());
    cout << s << endl;

    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

template<class V, int ME> class BIT {
public:
	V bit[1<<ME],val[1<<ME];
	V total(int e) {V s=0;e++;while(e) s+=bit[e-1],e-=e&-e; return s;}
	V add(int e,V v) { val[e++]+=v; while(e<=1<<ME) bit[e-1]+=v,e+=e&-e;}
	V set(int e,V v) { add(e,v-val[e]);}
	int lower_bound(V val) {
		V tv=0; int i,ent=0;
		for(i=ME-1;i>=0;i--) if(tv+bit[ent+(1<<i)-1]<val) tv+=bit[ent+(1<<i)-1],ent+=(1<<i);
		return ent;
	}
};

int N,Q;
ll A,B;
BIT<ll,18> bit;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>Q;
	bit.add(N,2LL*10000000000001LL);
	FOR(i,Q) {
		cin>>A>>B;
		x=N-A;
		while(B) {
			ll xv=bit.total(x);
			y = bit.lower_bound(xv+1);
			ll yv=bit.total(y);
			
			
			if(B>=(yv-xv)*(y-x)) {
				B -= (yv-xv)*(y-x);
				bit.add(x,yv-xv);
				bit.add(y,-(yv-xv));
			}
			else {
				bit.add(x,B/(y-x));
				bit.add(y,-B/(y-x));
				B %= (y-x);
				bit.add(y-B,1);
				bit.add(y,-1);
				break;
			}
		}
	}
	
	FOR(i,N) cout<<bit.total(N-1-i)<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


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

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main(int argc, char const *argv[]) {
	string str;
	std::cin >> str;
	ull k;
	std::cin >> k;
	int place = 0;
	for (size_t i = 0; i < str.size(); i++) {
		if (str[i] != '1') {
			place = i;
			break;
		}
	}
	if (k <= place) {
		std::cout << 1 << '\n';
	}
	else {
		std::cout << str[place] << '\n';
	}
	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys

def main():
	tmp = input()
	nums = list(tmp)
	
	if nums[0] == nums[1] and nums[1] == nums[2]:
		print("Yes")
		sys.exit()
	if nums[1] == nums[2] and nums[2] == nums[3]:
		print("Yes")
		sys.exit()
	print("No")
	
if __name__ == "__main__":
	main()
	

Measured memory_bytes: 2940
import numpy as np

N = int(input())

V = input().split()
C = input().split()
for i in range(N):
  V[i] = int(V[i])
  C[i] = int(C[i])

profit = 0
for i in range(N):
  if V[i] > C[i]:
    profit = profit + V[i] - C[i]
print(profit)

Measured memory_bytes: 12424
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <memory.h>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;


int main() {
	char c;
	int sum = 0, all = 0, n = 0;
	for(int a, b; cin >> a >> c >> b; ) {
		sum += a * b;
		all += b;
		n++;
	}
	cout << sum << endl;
	cout << round(all / (double)n) << endl;
	
	return 0;
}

Measured memory_bytes: 0