akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
using namespace std;
int main(){
    int x,y,z,k;
    cin >> x >> y >> z >> k;
    long long a[x];
    long long b[y];
    long long c[z];
    for(int i = 0;i<x;i++){
        cin >> a[i];
    }
    for(int i = 0;i<y;i++){
        cin >> b[i];
    }
    for(int i = 0;i<z;i++){
        cin >> c[i];
    }
    sort(a,a+x,greater<long long>());
    sort(b,b+y,greater<long long>());
    sort(c,c+z,greater<long long>());
    long long tem = a[0] + b[0] + c[0];
    vector<vector<int>> sett;
    vector<int> temvec = {0,0,0};
    int temv;
    for(int i = 0;i<k;i++){
        cout << tem << endl;
        if(temvec[0] < x-1){
        sett.push_back({temvec[0] + 1,temvec[1],temvec[2]});
        }
        if(temvec[1] < y-1){
        sett.push_back({temvec[0],temvec[1] + 1,temvec[2]});
        }
        if(temvec[2] < z-1){
        sett.push_back({temvec[0],temvec[1],temvec[2] + 1});
        }
        if(sett.size() != 0){
        sort(sett.begin(), sett.end());
        sett.erase(unique(sett.begin(), sett.end()), sett.end());
        tem = a[sett[0][0]]+b[sett[0][1]] + c[sett[0][2]];
        temv = 0;
        temvec = sett[0];
        for(int i = 1;i<sett.size();i++){
            if(a[sett[i][0]]+b[sett[i][1]] + c[sett[i][2]] > tem){
                tem = a[sett[i][0]]+b[sett[i][1]] + c[sett[i][2]];
                temv = i;
                temvec = sett[i];
            }
        }
        sett.erase(sett.begin() + temv); 
        }
    } 
}

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

int main() {
  int h,w;
  cin>>h>>w;
  vector<vector<char>>c(h,vector<char>(w));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++) cin>>c[i][j];
  }
  for(int i=0;i<2*h;i++){
    for(int j=0;j<w;j++){
      cout<<c[i/2][j];
      if(j==w-1) cout<<endl;
    }
  } 
}

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

using namespace std;
using ll = long long;


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

    for(int i = 0; i < n; i++) {
        if(k - a[i].second <= 0) {
            cout << a[i].first << endl;
            return 0;
        }else {
            k -= a[i].second;
        }
    }
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main() {
	int N; cin >> N;
	int H[N];
	for(int i = 0; i < N; i++) cin >> H[i];
	int max = 0, sea = 0;
	for (int i = 0; i < N; i++)
	{
		if(max <= H[i]) {
			max = H[i];
			sea++;
		}
	}
	cout << sea << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
 
a,b = map(int,input().split())
low = int(min(a//0.08,b//0.1))
high = int(max((a+1)//0.08,(b+1)//0.1))
for i in range(low,high+1):
  if int(i*0.08)==a and int(i*0.1)==b:
    print(i)
    sys.exit()
print(-1)

Measured memory_bytes: 9196
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fu(i,r,t) for(int i=r;i<=t;i++)
#define fd(i,r,t) for(int i=r;i>=t;i--)
#define Set set<int>
#define int long long
#define P pair<int,int>
const int maxn = 3e5+5;
const int INF = 1e17 +6;
using namespace std;
int n,m,a[maxn],b[maxn],c[maxn];
priority_queue<int,vector<int>,greater<int> >R;
priority_queue<int>L;
int X,Y,llen,rlen,rsum,lsum;
void update(int x,int y)
{
    Y+=y;
    if(x>X)
    {
        R.push(x);
        rlen++;
        rsum+=x;
    }else{
        L.push(x);
        llen++;
        lsum+=x;
    }
    if(llen<rlen) {
        int out = R.top();
        R.pop();
        rsum -= out;
        L.push(out);
        lsum += out;
        llen++;
        rlen--;
    }
    if(llen>rlen+1)
    {
        int out=L.top();
        L.pop();
        rsum+=out;
        R.push(out);
        lsum-=out;
        llen--;
        rlen++;
    }
    X=L.top();
}
int ans()
{
    cout<<X<<" ";
    cout<<rsum-X*rlen+X*llen-lsum+Y<<endl;
}
int32_t main() {
    IOS;
    cin>>n;
    fu(i,1,n)
    {
        int o;
        cin>>o;
        if(o==1)
        {
            int x,y;
            cin>>x>>y;
            update(x,y);
        }else{
            ans();
        }

    }
    return 0;
}


Measured memory_bytes: 3828
s = input()
t = input()
c = -1
for i in range(len(s)-len(t)+1):
    sw = 1
    for j in range(len(t)):
        if s[i+j] == "?":
            pass
        elif s[i+j] == t[j]:
            pass
        else:
            sw = 0
            break
    if sw == 1:
        c = i
if c == -1:
    ans = "UNRESTORABLE"
else:
    a = []
    i = 0
    j = 0
    while i < len(s):
        if c <= i < c+len(t):
            a.append(t[j])
            j += 1
        elif s[i] != "?":
            a.append(s[i])
        else:
            a.append("a")
        i += 1
    ans = "".join(a)
print(ans)

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



int main(){
    int N;
    int A[100]={0};
    while (cin >> N && N!=0) {
        int mi_num=10000,ma_num=-1,ave=0,sum=0;
        for (int i=0; i<N; i++) cin >> A[i];
        for (int i=0; i<N; i++) {
            mi_num=min(mi_num,A[i]);
            ma_num=max(ma_num,A[i]);
            sum+=A[i];
        }
        ave=(sum-mi_num-ma_num)/(N-2);
        cout << ave << endl;
    }
}



Measured memory_bytes: 3000
#include <iostream> // C++の入出力
#include <stdio.h> // C の入出力
#include <algorithm> // sort などのアルゴリズム 
#include <string.h> // C の文字列用
#include <ctype.h> // C の文字種用
#include <string> // C++の文字列
using namespace std; // std 名前空間を使用する
const int MAX=10000;
bool prime[MAX+1];
void make_prime(){
    for(int i=0;i<=MAX;i++){
        prime[i]=true;
    }
    prime[0]=false;
    prime[1]=false;
    for(int p=2;p<=MAX;p++){
        if(prime[p]){
            for(int n=p+p;n<=MAX;n+=p){
                prime[n]=false;
            }
        }
    }
}
int main(void){
    make_prime();
    while(1){
        int n;
        scanf("%d",&n);
        if(n==0)break;
        for(int i=n;i>=2;i--){
            if(prime[i]&&prime[i-2]){
                printf("%d %d\n",i-2,i);
                break;
            }
        }
    }
}

Measured memory_bytes: 1192
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#define ll long long
int main()
{
    ll N,X,Y,D,a=0;
    scanf("%lld%lld",&N,&D);
    D=D*D;
    for(int i=0;i<N;i++){
        scanf("%lld%lld",&X,&Y);
        if(D>=X*X+Y*Y) a++;
    }
    printf("%lld",a);
}


Measured memory_bytes: 1716
#include <iostream>
#include <algorithm>
#include <float.h>
#include <stdio.h>
#include <math.h>
#define REP(i,n) for (int i = 0; i < n; i++)
using namespace std;

int main() {
    int W, H, R[1000][1000], count = 0;
    while (true) { 
        cin >> H >> W;
        if (H == 0 && W == 0) break;
        R[count][0] = W;
        R[count][1] = H;
        count++;
    }
    
    REP(i,count) {
        for (int j = 0; j < R[i][1]; j++) {
            for ( int k = 0; k < R[i][0]; k++) {
                if ((j + k)%2 == 0) cout << '#';
                else cout << '.';
            }
            cout <<endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3144
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

N, *D = mi()
S = [sys.stdin.readline()[:2] for _ in range(N)]
ans = [0]*N

def cv(m):
    if m == 'A':
        return 0
    if m == 'B':
        return 1
    if m == 'C':
        return 2

def dfs(i, A, B, C, ans):
    if A<0 or B<0 or C<0:
        return
    if i == N:
        print('Yes')
        for m in ans:
            print(m)
        exit()
    #s, t = cv(S[i][0]), cv(S[i][1])
    '''
    D[s] += 1
    D[t] -= 1
    ans[i] = S[i][0]
    dfs(i+1, D, ans)
    D_[s] -= 1
    D_[t] += 1
    ans_[i] = S[i][1]
    dfs(i+1, D_, ans_)
    '''
    if S[i] == 'AB':
        ans[i] = 'A'
        dfs(i+1, A+1, B-1, C, ans)
        ans[i] = 'B'
        dfs(i+1, A-1, B+1, C, ans)
    if S[i] == 'BC':
        ans[i] = 'B'
        dfs(i+1, A, B+1, C-1, ans)
        ans[i] = 'C'
        dfs(i+1, A, B-1, C+1, ans)
    if S[i] == 'AC':
        ans[i] = 'A'
        dfs(i+1, A+1, B, C-1, ans)
        ans[i] = 'C'
        dfs(i+1, A-1, B, C+1, ans)

dfs(0, D[0], D[1], D[2], ans)
print('No')

Measured memory_bytes: 117076
# coding: utf-8
# Your code here!
N,M  = map(int,input().split(" "))
num = input().split(" ")
ans = 0
for i, x in enumerate(num):
    t = int(x)
    num[i] = t
num.sort()
kyori = []
for i in range(M-1):
    x = num[i+1]-num[i]
    kyori.append(x)
kyori.sort()
l = len(kyori)-(N-1)
for i in range(l):
    ans +=kyori[i]
print(ans)
    

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

using namespace std;
typedef long long ll;
int main() {
  int N, K;
  cin >> N >> K;

  ll sum = 0;
  for (int i = K + 1; i <= N; i++) {
    ll a = (N  / i) * (i - K);
    ll b = max(N % i - K + 1, 0);
    sum += a + b;
    if (K == 0) sum--;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
s=input()
n=len(s)
p=0
if n%2==1:
    p=1
else:
    n2=n//2
    for i in range(n2):
        if s[i*2]!='h':
            p=1
        if s[i*2+1]!='i':
            p=1
if p==0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<functional>
//#include<bits/stdc++.h>
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;

/*bool IsPrime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) { // 素数ではない
			return false;
		}
	}
	// 素数である
	return true;
}*/
/*ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}*/
/*ll keta(ll n) {
	ll res = 0;
	while (n >= 1) {
		res += n % 10; n /= 10;
	}
	return res;
}*/
/*ll modpow(ll x, ll y) {
	ll res = 1;
	while (y) {
		if (y % 2) { res *= x; res %= mod; }
		x = x * x % mod; y /= 2;
	}
	return res;
}*/
/*ll nCk(ll n, ll k) {
	ll a = 1, b = 1;
	for (int h = n - k + 1; h <= n; h++) { a *= h; a %= mod; }
	for (int h = 1; h <= k; h++) { b *= h; b %= mod; }
	return a * modpow(b, mod - 2) % mod;
}*/
//printf("%.10f\n", n);

ll go[12345678], cost[12345678], visit[12345678];
signed main() {
	//4
	ll n, k; cin >> n >> k;
	rep2(i, n) {
		cin >> go[i];
	}
	rep2(i, n) {
		cin >> cost[i];
	}

	ll ansans = 0 - INF;
	rep2(h, n) {
		if (visit[h] != 0) { continue; }

		//ループの個数
		ll aaa = h, ko = 0;
		while (true) {
			aaa = go[aaa]; ko++;
			if (aaa == h) { break; }
		}
		//end

		ll karik = 0;
		if (ko > k) { karik = k; }
		else { karik = (k % ko); }

		ll ima = h, cnt = 0, z = 1; vector<ll> rui(123456);
		while (true) {
			if (visit[ima] == 5) { break; }
			ima = go[ima]; cnt += cost[ima]; visit[ima]++;
			rui[z] = cnt; z++;
		}

		ll ans = 0 - INF;
		if (ko > k) {//karik
			rep2(i, ko) {
				rep(j, karik) {
					ans = max(rui[i + j] - rui[i - 1], ans);
				}
			}
		}
		else {
			if (rui[ko] > 0) {//karik
				karik = (k % ko) + ko;
				rep2(i, ko) {
					rep(j, karik) {
						ans = max(rui[i + j] - rui[i - 1], ans);
					}
				}
				
				ans += (((k / ko) - 1) * rui[ko]);
			}
			else {//not karik
				rep2(i, ko) {
					rep(j, min(k, ko + 2)) {
						ans = max(rui[i + j] - rui[i - 1], ans);
					}
				}
			}
		}
		ansans = max(ansans, ans);
	}
	cout << ansans << endl;
	return 0;
}

Measured memory_bytes: 4692
// C++ 14
#include <bits/stdc++.h>
using namespace std;
template <typename T>  ostream& operator<<(ostream& os, const vector<T>& v)  {  os << "[";  for (int i = 0; i < v.size(); ++i) {  os << v[i];  if (i != v.size() - 1)  os << ", ";  }  os << "]";  return os;  }
template <typename T> void print(T v, string s = "\n") { cout << v << s; }
template <typename T> void in(T &v) { cin >> v; }
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

vector<int> B { 400, 800, 1200, 1600, 2000, 2400, 2800, 3200, 5000 };

int main() {
  int n;in(n);
  vector<int> C(9, 0);
  int a, j;
  loop(i,0,n) {
    in(a);
    j=0;
    while (a >= B[j]) j++;
    C[j]++;
  }
  
  int ans1 = 0;
  loop(i,0,8) ans1 += C[i] > 0;
  int ans2 = ans1 + C[8];
  cout << max(ans1, 1) << " " << ans2 << endl;
  return 0;
}


Measured memory_bytes: 3596
N, M = map(int, input().split())
p = {}
for _ in range(M):
    a, b = map(int, input().split())
    if a in p:
        p[a].append(b)
    else:
        p[a] = [b]
    if b in p:
        p[b].append(a)
    else:
        p[b] = [a]
cnt = 0
def func(q, l, n):
    if n == N:
        global cnt
        cnt += 1
    for i in p[q]:
        if i not in l:
            func(i, l+[i], n+1)
func(1, [1], 1)
print(cnt)

Measured memory_bytes: 3064
N = int(input())
S = input()
w_list = [0] * (N + 2) 
e_list = [0] * (N + 2) 
cnt = 0
for i in range(N):
  if S[i] == "W":
    cnt += 1
  w_list[i + 1] = cnt
cnt = 0
for i in range(N - 1, -1, -1):
  if S[i] == "E":
    cnt += 1
  e_list[i + 1] = cnt
ans = 10 ** 9
for i in range(1, N + 1):
  ans = min(ans, w_list[i - 1] + e_list[i + 1])
print(ans)

Measured memory_bytes: 17628
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace arc087_b
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split('T');
            int[] n = new int[s.Count()];
            for (int i = 0; i < s.Count(); i++) n[i] = s[i].Length;
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            x[0] -= n[0];
            int xmove = 0; bool[] canx = new bool[100000]; canx[0] = true;
            int ymove = 0; bool[] cany = new bool[100000]; cany[0] = true;
            for (int i = 1; i < s.Count(); i++)
            {
                if (i % 2 == 0)
                {
                    xmove += n[i];
                    for (int j = 9999; j >= 0; j--)
                    {
                        if (canx[j]) canx[j + n[i] * 2] = true;
                    }
                }
                else
                {
                    ymove += n[i];
                    for (int j = 9999; j >= 0; j--)
                    {
                        if (cany[j]) cany[j + n[i] * 2] = true;
                    }
                }
            }
            Console.WriteLine(x[0] + xmove >= 0 && x[1] + ymove >= 0 && canx[x[0] + xmove] && cany[x[1] + ymove] ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 13408
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<v<<"\n";
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<62;
const ll MOD=1000000007;


signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<vector<ll>> A(N, vector<ll>(N, 0));
    for(ll i=0;i<N;++i)
        for(ll j=0;j<N;++j)cin>>A[i][j];
    vvl &d=A;
    ll ans=0;
    for(ll i=0;i<N;++i){
        for(ll j=i+1;j<N;++j){
            bool need=1;
            for(ll k=0;k<N;++k){
                if(k==i||k==j)continue;
                //矛盾
                if(d[i][k]+d[k][j]<d[i][j]){
                    prt(-1)return 0;
                }
                //不要
                if(d[i][k]+d[k][j]==d[i][j]){
                    need=0;
                }
            }
            if(need)ans+=d[i][j];
        }
    }
    prt(ans)
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using std::cin;
using std::cout;

int n, i;
long long v, s, a;
const long long m = 1e9 + 7;

int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (i = 0; i != n; ++i) {
    cin >> v;
    a = (a + v * s) % m;
    s = (s + v) % m;
  }
  cout << a;
  return 0;
}


Measured memory_bytes: 3640
import bisect,copy,heapq,string
from collections import *
from math import *
from itertools import *
import sys
sys.setrecursionlimit(10 ** 6)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = LIST()
b = LIST()

if sum(a) < sum(b):
    print(-1)
else:
    c = sorted([a[i]-b[i] for i in range(n)])
    ans = 0
    reg = 0

    for x in c:
        if x < 0:
            ans += 1
            reg += x
        else:
            break

    for x in c[::-1]:
        if reg < 0:
            reg += x
            ans += 1
        else:
            break

    print(ans)

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

int main(){
  int N;
  cin >> N;
  vector<long> data(N);
  long counter = 0;
  for(int i = 0;i < N;i++){
    cin >> data[i];
    data[i] -= i;
  } 
  long central;

  //中央値を求める
  //まずソート
  sort(data.begin(),data.end());
  //奇数の場合
  /*if(N % 2 != 0){
    central = data[N / 2];
  }else{
    //偶数の場合
    double j = (data[(N - 1) / 2] + data[N / 2]) / 2;
    int k = j * 10;
    if(k % 10 < 5)central = j + 1;
    else central = j;
  }
  */
  
  central = data[N / 2];
  
  //全部たす
  for(int i = 0;i < N;i++){
    long j = data[i] - central;
    if(j > 0)counter += j;
    else counter -= j;
  }

  cout << counter << endl;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        long h = sc.nextInt();
        
        List<Long> a = new ArrayList<Long>();
        List<Long> b = new ArrayList<Long>();
        
        for(int i = 0; i < n; i++){
            a.add(sc.nextLong());
            b.add(sc.nextLong());
        }
        
        long res = 0;
        
        Collections.sort(a, Comparator.reverseOrder());
        Collections.sort(b, Comparator.reverseOrder());
        
        for(int i = 0; i < n; i++){
            if(h <= 0 || a.get(0) > b.get(i)) break;
            h-=b.get(i);
            res++;
        }
        
        while(true){
            if(h <= 0) break;
            h-=a.get(0);
            res++;
        }
        
        System.out.println(res);
    }
}


Measured memory_bytes: 82772
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip> //setprecision
using namespace std;

double koch(double x0, double y0, double x1, double y1, int n)
{
    if (n == 0)
    {
        cout << setprecision(8) << x0 << " " << y0 << endl;
    }
    else
    {
        double c1[2] = {(x0 * 2 + x1) / 3, (y0 * 2 + y1) / 3};
        double c2[2] = {(x0 + x1) / 2 + (y0 - y1) * sqrt(3) / 6, (y0 + y1) / 2 + (x1 - x0) * sqrt(3) / 6};
        double c3[2] = {(x0 + x1 * 2) / 3, (y0 + y1 * 2) / 3};
        koch(x0, y0, c1[0], c1[1], n - 1);
        koch(c1[0], c1[1], c2[0], c2[1], n - 1);
        koch(c2[0], c2[1], c3[0], c3[1], n - 1);
        koch(c3[0], c3[1], x1, y1, n - 1);
    }
}

int main()
{
    int n;
    cin >> n;
    koch(0, 0, 100, 0, n);
    cout << 100 << " " << 0 << endl;
    return 0;
}



Measured memory_bytes: 3276
#include<iostream>
#include<cstdio>
#include<string>
#include<string.h>
#include<functional>
#include<algorithm>
#include<math.h>
#include<unordered_map>
#include<string.h>
#include<limits.h>
#include<list>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<unordered_set>
#include<deque>
using namespace std;

signed main(){
	int a; cin >> a;
	map<int, int>b;
	for (int c = 0; c < a; c++) {
		int d; cin >> d;
		b[d]++;
	}
	if (b.size() == 1) {
		int c = b.begin()->first;
		if (c == a-1 || c <= a / 2) {
			puts("Yes");
		}
		else {
			puts("No");
		}
	}
	else {
		if (b.size() > 2 || b.rbegin()->first - b.begin()->first != 1|| b.rbegin()->second==1) { puts("No"); return 0; }
		int sum = b.rbegin()->first;
		int MIN = b.begin()->second + 1, MAX = b.begin()->second + b.rbegin()->second / 2;
		if (MIN <= sum&&sum <= MAX)puts("Yes");
		else puts("No");
	}
}

Measured memory_bytes: 4992
# B - Multiplication 2
def main():
    _, *A = map(int, open(0).read().split())
    if 0 in A:
        print(0)
        return 
    prod = 1
    LIM = 10 ** 18
    for i in A:
        prod *= i
        if prod > LIM:
            print(-1)
            return
    print(prod)


if __name__ == "__main__":
    main()


Measured memory_bytes: 21584
import sys
input = sys.stdin.readline
H, W = map(int, input().split())
a = [list(input())[: -1] for _ in range(H)]
b = []
c = set()
#print(a)
for i in range(H):
  f = 1
  for j in range(W):
    if a[i][j] == ".":
      f = 0
    else:
      f = 1
      break
  if f: b.append(a[i])
#print(b)
for j in range(W):
  f = 0
  for i in range(len(b)):
    if b[i][j] == ".":
      f = 1
    else:
      f = 0
      break
  if f: c.add(j)
#print(c)
for i in range(len(b)):
  res = ""
  for j in range(W):
    if j in c:
      continue
    res += b[i][j]
  print(res)

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

int main()
{
    string S;
    cin >> S;
    long long N = S.size() + 1;
    vector<long long> x(N, 0);
    for (long long i = 0; i < S.size(); i++)
    {
        if (S[i] == '<')
        {
            x[i + 1] = max(x[i + 1], x[i] + 1);
        }
    }
    for (long long i = S.size() - 1; i >= 0; i--)
    {
        if (S[i] == '>')
        {
            x[i] = max(x[i], x[i + 1] + 1);
        }
    }
    long long ans = 0;
    for (long long a : x)
    {
        ans += a;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4740
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N = in(), K = in();
    vector<int> l(N);
    REP(i,N)l[i] = in();
    sort(ALL(l),greater<>());
    int answer = 0;
    REP(i,K)answer += l[i];
    cout << answer << "\n";
}

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

def alpha(num):
    if num<=26:
        return chr(96+num)
    elif num%26==0:
        return alpha(num//26-1)+chr(122)
    else:
        return alpha(num//26)+chr(96+num%26)

if __name__ == '__main__': 
    print(alpha(N))

Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* struct for mod Calculation*/
struct mint {
    ll x;
    mint(ll x = 0):x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll 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 {
        mint res(*this);
        return res /= a;
    }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
/* global variables */
/* function */
/* main */
int main(){
    string S;
    cin >> S;
    int L = S.size();
    int mod13 = 13;

    // dp[i桁目][(sum(i桁目まで)%13]
    vector<vector<mint> > dp(L + 1, vector<mint>(mod13));
    dp[0][0] = 1;

    for (int i = 0; i < L; i++) {
        for (int j = 0; j < mod13; j++) {
            for (int k = 0; k <= 9; k++) {
                // S[i] == '?' -> 0 ~ 9
                // S[i] == x -> only x
                if (S[i] != '?' && (S[i] - '0') != k) continue;
                // Dpの遷移
                dp[i+1][(j * 10 + k) % mod13] += dp[i][j];
            }
        }
    }
    cout << dp[L][5] << '\n';
}

Measured memory_bytes: 13568
//--- pD ---//
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
	public static void main (String[] args) throws java.lang.Exception {
		new Solution();
	}
}
class Solution {
	int mod = (int)1e9+7;
	Reader reader;
	public Solution () {
		reader = new Reader();
		while (reader.hasNext()) {
			run_case();
		}
	}

	private void run_case() {
		List<StringBuilder> sb = new ArrayList<>();
		sb.add(new StringBuilder());
		sb.add(new StringBuilder());
		// StringBuilder sb_e = new StringBuilder();
		int dir = 0;

		String str = reader.ns();
		int q_num = reader.ni();
		for (;q_num-->0;) {
			int q = reader.ni();
			if (q == 1) {
				dir = (dir + 1) % 2;
			} else {
				q = reader.ni();
				char c = reader.ns().charAt(0);
				if (q == 1) { // add f
					sb.get(dir).append(c);
				} else {
					int t = (dir + 1) % 2;
					sb.get(t).append(c);
				}
			}
		}

		String res = "";
		if (dir == 0) {
			String str_f = sb.get(0).reverse().toString();
			String str_e = sb.get(1).toString();
			res = str_f + str + str_e;
		} else {
			String str_f = sb.get(1).reverse().toString();
			String str_e = sb.get(0).toString();
			res = str_f + new StringBuilder(str).reverse().toString() + str_e;
		}

		System.out.println(res);

		return;
	}
}

class Reader {
	BufferedReader br;
	StringTokenizer st;
	public Reader(){
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public String next() {
		if (st.hasMoreTokens()) return st.nextToken();
		try {
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return st.nextToken();
	}
	public boolean hasNext() {
		try {
			if (!st.hasMoreTokens() && !br.ready()) return false;
			else return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
	public int ni() {return Integer.parseInt(this.next());}
	public String ns() {return this.next();}
}


Measured memory_bytes: 49512
#include <iostream>
#include <vector>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

int main(){
  ll q, h, s, d;
  ll n;
  cin >> q >> h >> s >> d;
  cin >> n;
  h = min(q*2, h);
  s = min(h*2, s);
  d = min(s*2, d);
  cout << (n/2) * d + (n%2) * s << endl;
  return 0;
}


Measured memory_bytes: 256
let () = Scanf.scanf "%d %d" @@ fun k s ->
  Printf.printf "%d\n" @@
  if 3 * k < s
  then 0
  else
    Array.fold_left ( + ) 0 @@
    Array.init (1 + min s k) @@ fun x ->
      Array.fold_left ( + ) 0 @@ Array.init (1 + min (s - x) k) @@ fun y ->
        if s - x - y <= k then 1 else 0




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



int main(){

	int a[100][100] = {};
	int b[100] = {};
	int n, m;
	int ans = 0;

	cin >> n >> m;

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

	}
	for (int i = 0; i < m; i++)
	{
		cin >> b[i];
	}


	for (int i = 0; i <n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			ans += a[i][j] * b[j];
		}
		cout << ans << endl;
		ans = 0;
	}


}


Measured memory_bytes: 3136
s = input()
for i in range(int(input())):
    q = input().split()
    op, a, b = q[0], int(q[1]), int(q[2])
    if op == 'print':
        print(s[a : b+1])
    elif op == 'reverse':
        t = s[a : b+1]
        s = s[:a] + t[::-1] + s[b+1:]
    elif op == 'replace':
        s = s[:a] + q[3] + s[b+1:]

Measured memory_bytes: 7728
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define Reverse(x) reverse(all(x));
#define Sort(x) sort(all(x));
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    cout << std::fixed << std::setprecision(10);
    lli n;
    cin >> n;
    vec(pii) recp(n), recm(n);
    rep(i,n){
        lli x, y;
        cin >> x >> y;
        recp[i] = pii(x + y,i);
        recm[i] = pii(x - y, i);
    }
    Sort(recp);
    Sort(recm);
    lli ansp = recp[n - 1].first - recp[0].first;
    lli ansm = recm[n - 1].first - recm[0].first;
    out(max(ansp,ansm)) ;
}

Measured memory_bytes: 9648
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef map<int, int> MII;
typedef pair<int, int> PII;

int D[11];
string s;
int ns;
int k;

bool isNumber( char c ) {
    return c >= '0' && c <= '9';
}

int toInt( char c ) {
    return c - '0';
}

MII solve() {
    MII res;
    
    if ( isNumber( s[k] ) ) {
        res[D[toInt(s[k++])-1]] ++;
        return res;
    }

    k ++;
    MII left = solve();
    k ++;
    MII right = solve();
    k ++;

    for ( MII::iterator it_i = left.begin(); it_i != left.end(); ++ it_i ) {
        for ( MII::iterator it_j = right.begin(); it_j != right.end(); ++ it_j ) {
            PII l = *it_i;
            PII r = *it_j;
            int num = l.second * r.second;
            res[l.first & r.first] += num;
            res[l.first | r.first] += num;
            res[l.first ^ r.first] += num;
        }
    }
    
    return res;
}

int main() {
    while ( getline( cin, s ) ) {
        if ( s == "END" ) break;
        ns = s.size();
        
        int n;
        cin >> n;
        for ( int i = 0; i < n; ++ i ) {
            D[i] = 0;
        }
        for ( int i = 0; i < n; ++ i ) {
            for ( int j = 0; j < 4; ++ j ) {
                int d;
                cin >> d;
                if ( d ) D[i] |= 1 << j;
            }
        }
        cin.ignore();
        cin.clear();

        k = 0;
        MII res = solve();
        cout << res[15] << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

int main(void){
    std::string s, t;
    std::cin >> s >> t;
    for(int i = 0; i < s.size(); ++i){
        if(s[i] != t[i]){
            std::cout << "No" << std::endl;
            return 0;
        }
    }
    std::cout << "Yes" << std::endl;

    return 0;
}

Measured memory_bytes: 3628
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;

bool cmp(pair<int,int> x, pair<int,int> y){
	return x.first < y.first;
}

void Main()
{
	int N;
  	cin >> N;
  	vector<int> B(N-1);
  	rep(i,N-1) cin >> B[i];
  
	int sum = B[0] + B[N-2];
  	rep(i,N-2) sum += min(B[i],B[i+1]);
  	cout << sum << endl;
	return;
}

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

Measured memory_bytes: 256
#include <stdio.h>
#define rep(i,n)for(int i=0;i<(int)(n);i++)
int main(){
	int n,color,a[100002],b[100002];
	scanf("%d",&n);
	rep(i,n) scanf("%d",&a[i]);//入力終
	rep(i,n+1) b[i]=-1;
	rep(i,n){
		color=0;
		while(a[i]<=b[color]){color++;}
		b[color]=a[i];
	}
	rep(i,n+1){
		if(b[i]==-1){printf("%d",i); return 0;}
	}
}

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

using namespace std;

int main(){
	
	char ch;
	
	scanf("%c",&ch);
	
	if(ch=='A'){
		printf("T\n");
	}
	else if(ch=='G') printf("C\n");
	else if(ch=='T') printf("A\n");
	else if(ch=='C') printf("G\n");
	
	
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
def main():
    import sys

    input = sys.stdin.readline

    N, K = map(int, input().split())
    res = [False for _ in range(N)]
    for _ in range(K):
        _ = int(input())
        A = [int(x) for x in input().split()]
        for i in A:
            res[i - 1] = True
    print(res.count(False))



if __name__ == '__main__':
    main()


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


int main(void) {
    using namespace std;

    long n;
    cin >> n;
    vector<long> v(n);
    for(auto &x: v) cin >> x;

    map<long,long> o, e;
    for(int i=0; i<n; i+=2)
        e[v[i]]++;
    for(int i=1; i<n; i+=2)
        o[v[i]]++;

    long e1=1e9, e1c=0, e2=2e9, e2c=0;
    for(auto &t: e)
        if(e1c < t.second) e2c = e1c, e2 = e1, e1c = t.second, e1 = t.first;
        else if(e2c < t.second) e2c = t.second, e2 = t.first;

    long o1=3e9, o1c=0, o2=4e9, o2c=0;
    for(auto &t: o)
        if(o1c < t.second) o2c = o1c, o2 = o1, o1c = t.second, o1 = t.first;
        else if(o2c < t.second) o2c = t.second, o2 = t.first;

    long r = 1e9;
    {
        long oo = o1;
        long ee = o1==e1 ? e2 : e1;

        r = min(r, (n/2 - e[ee]) + (n/2 - o[oo]));
    }
    {
        long ee = e1;
        long oo = e1==o1 ? o2 : o1;

        r = min(r, (n/2 - e[ee]) + (n/2 - o[oo]));
    }

    cout << r << endl;

    return 0;
}


Measured memory_bytes: 7296
while True:
    n = int(input())
    if n == 0:break
    edges = [[] for _ in range(n)]
    for _ in range(n - 1):
        a, b, t = map(int, input().split())
        a -= 1
        b -= 1
        edges[a].append([b, t])
        edges[b].append([a, t])
    used = [False] * n
    is_leaf = [False] * n
    for i in range(1, n):
        if len(edges[i]) == 1:is_leaf[i] = True


    def check(x):
        used[x] = True
        times = [0]
        max_path = 0
        for to, t in edges[x]:
            if not used[to] and not is_leaf[to]:
                time, path = check(to)
                times.append(time + t * 2)
                max_path = max(max_path, path + t)
        return sum(times), max_path


    total_time, max_path = check(0)
    print(total_time - max_path)


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

int main(){
	char s[4];
  	scanf("%s",s);
  	if(strcmp(s,"RRR") == 0)
      	puts("3");
  	else if((s[0] == 'R' && s[1] == 'R') || (s[1] == 'R' && s[2] == 'R'))
      	puts("2");
  	else if(s[0] == 'R' || s[1] == 'R' || s[2] == 'R')
      	puts("1");
 	else
      	puts("0");
  	return 0;
}

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

#define X first
#define Y second
#define LL long long
#define ULL unsigned long long
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define IN freopen("in", "r", stdin);
#define OUT freopen("out", "w", stdout);

int nn,ss,w,e;

int main()
{
	char s[2000];
	scanf("%s",s);
	int n=strlen(s);
	for (int j=0;j<n;++j)
	{
		if (s[j]=='N') nn=1;
		if (s[j]=='S') ss=1;
		if (s[j]=='W') w=1;
		if (s[j]=='E') e=1;
	}
	if (nn+ss==1||w+e==1) cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff(i,a,b) for(i=a;i<=b;i++)
#define fb(i,a,b) for(i=a;i>=b;i--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define c 1000000007
ll power(ll a,ll b)
{
  ll ans=1;
  while(b>0)
  {
    if(b & 1)
      ans=(ans*a)%c;
    b=b>>1;
    a=(a*a)%c;
  }
  return ans;
}
int main()
{
    fast;
    ll n,i,total=0;
    bool ans=false;
    cin>>n;
    ll a[n+1];
    unordered_map<ll,ll> m;
    ff(i,1,n)
    {
        cin>>a[i];
        if(n & 1)
        {
            if(a[i] & 1)
                ans=true;
        }
        else
        {
            if(a[i]%2==0)
                ans=true;
        }
        if(a[i]>=n)
            ans=true;
        m[a[i]]++;
    }
    for(auto x : m)
    {
        if(n & 1)
        {
            if(m[0]!=1)
            {
                ans=true;
                break;
            }
            else if(x.second!=2 && x.first!=0)
            {
                ans=true;
                break;
            }
        }
        else
        {
            if(x.second!=2)
            {
                ans=true;
                break;
            }
        }

    }
    if(ans)
    {
        cout<<"0"<<endl;
    }
    else
    {
        if(n & 1)
        {
            total=power(2,n/2);
            cout<<total%c<<endl;
        }
        else
        {
            total=(power(2,n/2));
            cout<<total%c<<endl;
        }
    }
    return 0;
}


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

typedef long long int lli;
typedef long int li;

void solve(){
    int X, Y, x, y;
    bool ans = 0;
    cin >> X >> Y;
    if(Y % 2 == 0){
        y = Y / 2 - X;
        if(X - y >= 0 && y >= 0) ans = 1;
    }
    cout << (ans == 1 ? "Yes" : "No") << '\n';
}

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

/*
  check for corner cases.
  When using log check for zeros.
  Use queues and stacks if they are helping.

    (___)
    . . )____________
   _|__/\           |\
  (o_o_) \__________| \
           /|     ||   )
          < |     ||
*/


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



int main(){
  int K;
  string s;
  cin>>K>>s;
  int S=s.size();
  
  if(K>=S) cout<<s<<endl;
  else{
    for(int i=0;i<K;i++){
      cout<<s.at(i);
    }
    cout<<"..."<<endl;
  }
}

Measured memory_bytes: 3612
import sys
sys.setrecursionlimit(10**9)

n, m = map(int, input().split())
s = input()


def solve(t):
    if len(t) <= m + 1:
        return [len(t) - 1]
    for i in reversed(range(1, m + 1)):
        if t[len(t) - 1 - i] == '0':
            cand = solve(t[:-i])
            if len(cand) != 0:
                cand.append(i)
                return cand

    return []


cnt1_continuous = 0
cnt = 0
for i in range(n + 1):
    if s[i] == '1':
        cnt += 1
        if i == n:
            cnt1_continuous = max(cnt1_continuous, cnt)
    else:
        cnt1_continuous = max(cnt1_continuous, cnt)
        cnt = 0

if cnt1_continuous >= m:
    print(-1)
else:
    if m == 1:
        ans = [1] * n
    else:
        ans = solve(s)
    print(*ans)


Measured memory_bytes: 710004
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.Remoting.Messaging;
using System.Security.Principal;
using System.Text;
class Simple {
    private string S;
    void Solve() {
        //input
        S = io.String;
        //cal
        var ans = S.Length == S.Distinct().Count();
        //ret
        Console.WriteLine(ans?"yes":"no");
    }
    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) { new Simple().Stream(); }
    void Stream() {
        Solve();
        io.writeFlush();
    }
}
class SimpleIO {
    string[] nextBuffer;
    int BufferCnt;
    char[] cs = new char[] {' '};
    StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
    public SimpleIO() {
        nextBuffer = new string[0];
        BufferCnt = 0;
        Console.SetOut(sw);
    }
    public string Next() {
        if(BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++];
        string st = Console.ReadLine();
        while(st == "") st = Console.ReadLine();
        nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        BufferCnt = 0;
        return nextBuffer[BufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void writeFlush() { Console.Out.Flush(); }
}

Measured memory_bytes: 13152
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ut i=(a);i<(ut)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define FF first
#define SS second
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef complex<int> cli;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr,Vpr> PQ;
typedef priority_queue<ut,VI,greater<ut> > PPQ;
const int SIZE=5+1e5;
const LL INF=1<<30;
const LL p=7+(1e9);
int A[SIZE],D[SIZE];
int main(){
	int N;
	cin >> N;
	REP(i,N){
		cin >> A[i];
		D[A[i]]++;
	}
	FOR(i,0,N){
		if(N%2==i%2) continue;
		if((D[i]==2 && i!=0) or (D[i]==1 && i==0)){
			continue;
		}
		cout << 0 << endl;
		return 0;
	}
	LL ans=1;
	REP(i,N/2){
		ans<<=1;
		ans%=p;
	}
	cout << ans << endl;
	return 0;
}


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

const int N = 1e5+5;
vector<int> sieve(N,0);
vector<int> give(N,0);
void pre(){
	for(int i=2; i<N; ++i){
		if( sieve[i] == 0 ){
			for(int j=i+i; j<N; j+=i){
				sieve[j] = 1;
			}
		}
	}
	for(int i=3; i<N; i+=2){
		if( sieve[i] == 0 and sieve[(i+1)/2] == 0 ){
			give[i] = 1;
		}
	}
	for(int i=1; i<N; ++i){
		give[i] += give[i-1];
	}
}

int ans(int l, int r){
	return give[r] - give[l-1];
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	pre();
	int q;
	cin>>q;
	while(q--){
		int a,b;
		cin>>a>>b;
		cout<<ans(a,b)<<'\n';
	}

	return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
int main(){
	ll x,y,z,ans=10000000000000000;
	vector<ll> a(3);
	cin >> a[0] >> a[1] >> a[2];
	if(a[0]%2==0||a[1]%2==0||a[2]%2==0)	ans = 0;
	else{
		sort(a.begin(),a.end());
		ans = a[0]*a[1];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<string>
#include<iostream>

using namespace std;

bool isCross(int l,int r){
	if(l==1 || l==4 || l==7)	return false;
	if(l==2 || l==8)	return (r==1 || r==4 || r==7);
	return !(r==3 || r==6 || r==9);
}

const int INF=1<<30;

int main(){
	for(string s;cin>>s,s!="#";){
		int len=s.length();
		for(int i=0;i<len;i++)	s[i]-='0';

		int memo[10][10][2],next[10][10][2];
		for(int l=1;l<10;l++)for(int r=1;r<10;r++)for(int b=0;b<2;b++){
			memo[l][r][b]=(l==5 || r==5 || l==r)?INF:0;
		}
		for(int i=0;i<len;i++){
			int a=s[i];
			for(int l=1;l<10;l++)for(int r=1;r<10;r++)for(int b=0;b<2;b++){
				next[l][r][b]=INF;
				if(l==5 || r==5 || l==r || (l!=a && r!=a) || isCross(l,r))	continue;
				else{
					if(l==a){
						for(int bef=1;bef<10;bef++){
							if(bef!=5 && !isCross(bef,r)){
								next[a][r][0]=min(next[a][r][0],memo[bef][r][0]+1);
								next[a][r][0]=min(next[a][r][0],memo[bef][r][1]);
							}
						}
					}
					else{	// r==a
						for(int bef=1;bef<10;bef++){
							if(bef!=5 && !isCross(l,bef)){
								next[l][a][1]=min(next[l][a][1],memo[l][bef][0]);
								next[l][a][1]=min(next[l][a][1],memo[l][bef][1]+1);
							}
						}
						if(r!=a)puts("exception");
					}
				}
			}

			for(int l=1;l<10;l++)for(int r=1;r<10;r++)for(int b=0;b<2;b++){	// update
				memo[l][r][b]=next[l][r][b];
			}
		}

		int ans=INF;
		for(int l=1;l<10;l++)for(int r=1;r<10;r++)for(int b=0;b<2;b++)	ans=min(ans,memo[l][r][b]);
		cout<<ans<<endl;
	}

	return 0;
}

Measured memory_bytes: 1136
n = int(input())
#a,b = map(int,input().split())
a_L = list(map(int,input().split()))

from collections import Counter

a_L = Counter(a_L)

dic = {}
for i,v in a_L.items():
    dic[i] = v

for i in range(n):
    try:
        print(dic[i+1])
    except:
        print(0)
        

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

char c, p;
int l, lp;
long long r;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  for(; (c = cin.get()) != char_traits<char>::eof() && c > ' '; r += ++l) {
    if(c != p) { 
      if(c == '<')
        r -= l < lp ? l : lp;
      p = c, lp = l, l = 0;
    }
  }
  if(p == '>')
    r -= l < lp ? l : lp;
  cout << r << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

ll MOD = 1000000007;
ll INF =1<<30;

int main(){
    int n;
    cin >>n;
    vector<ll>l(n);
    rep(i,n) cin >> l[i];
    sort(l.begin(),l.end());
    int ans = 0;
    rep(i,n){
        for(int j = i+1;j<n;j++){
            for(int k = j+1;k<n;++k){
                if(l[i]==l[j]||l[i]==l[k]||l[j]==l[k]) continue;
                    if(l[k]<l[i]+l[j]) ans++;
            }
        }
    }
    cout << ans <<endl;
}

Measured memory_bytes: 3636
import sys
input = sys.stdin.buffer.readline
INF = 0

class MaxSegTree:
    """
    0-indexed
    query : [L, R)
    """
    def __init__(self, size):
        self.size = 1 << (size.bit_length())  # 完全二分木にする
        self.data = [-INF] * (2 * self.size - 1)

    def build(self, rawData):
        self.data[self.size - 1: self.size - 1 + len(rawData)] = rawData
        for i in range(self.size - 1)[:: -1]:
            self.data[i] = max(self.data[2 * i + 1], self.data[2 * i + 2])

    def update(self, index, value):
        index += self.size - 1
        if self.data[index] >= value:
            return
        self.data[index] = value
        while index >= 0:
            index = (index - 1) // 2
            self.data[index] = max(self.data[2 * index + 1], self.data[2 * index + 2])

    def query(self, left, right):
        L = left + self.size
        R = right + self.size
        ret = -INF
        while L < R:
            if R & 1:
                R -= 1
                ret = max(ret, self.data[R - 1])
            if L & 1:
                ret = max(ret, self.data[L - 1])
                L += 1
            L >>= 1
            R >>= 1
        return ret

N, K = map(int, input().split())
A = [int(input()) for _ in range(N)]
mxA = max(A)
tree = MaxSegTree(mxA + 10)

for a in A:
    nx = tree.query(max(0, a - K), min(mxA, a + K) + 1)
    tree.update(a, nx + 1)

print(tree.query(0, mxA + 1))


Measured memory_bytes: 118716