akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.A
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var S = ReadText();

            return "2018" + S.Substring(4);
        }

        #region Console

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 11092
class Node():
    def __init__(self, id, left, right, parent=-1, sibling=-1, degree=-1, depth=-1, height=-1, type=None):
        self.id = id
        self.left = left
        self.right = right
        self.parent = parent
        self.sibling = sibling
        self.degree = degree
        self.depth = depth
        self.height = height
        self.type = type
    def show(self):
        print 'node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s' % (self.id, self.parent, self.sibling, self.degree, self.depth, self.height, self.type)

def hasChild(x):
    if x == -1:
        return 0
    else:
        return 1

def calcDepth(node):
    if node.parent == -1:
        return 0
    return 1 + calcDepth(a[node.parent])

def calcHeight(node):
    if node.degree == 0:
        return 0
    return 1 + max(calcHeight(a[node.left]), calcHeight(a[node.right]))

n = int(raw_input())
a = []
dict = {}
for i in range(n):
    tmp = map(int, raw_input().split())
    if tmp[1] == -1 and tmp[2] == -1:
        dict[tmp[0]] = Node(tmp[0], tmp[1], tmp[2], degree=0)
    else:
        dict[tmp[0]] = Node(tmp[0], tmp[1], tmp[2], degree=hasChild(tmp[1])+hasChild(tmp[2]))

for i in range(n):
    a.append(dict[i])

for i in range(n):
    if a[i].right != -1:
        a[a[i].right].parent = a[i].id
    if a[i].left != -1:
        a[a[i].left].parent = a[i].id

for i in range(n):
    a[i].depth = calcDepth(a[i])
    a[i].height = calcHeight(a[i])
        
for i in range(n):
    if a[i].parent != -1 and a[i].degree != 0:
        a[i].type = 'internal node'
    elif a[i].parent != -1 and a[i].degree == 0:
        a[i].type = 'leaf'
    else:
        a[i].type = 'root'
        
    for j in range(n):
        if i == j:
            continue
        if a[i].depth == a[j].depth and a[i].parent == a[j].parent:
            a[i].sibling = j
        
for el in a:
    el.show()

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

int main() {
  string S ;
  cin >> S ;
  int counter = 0 ;
  int N = S.size();
  //cout << N << endl;
  while( counter != N ){
    
    if(S[counter] == 'd' && S[counter+1] == 'r' && S[counter+2] == 'e' && S[counter+3] == 'a'  && S[counter+4] == 'm'){
      if(S[counter+5] == 'e' && S[counter+6] == 'r'){
        if( S[counter+7] == 'a' && S[counter+8] == 's'  && S[counter+9] == 'e'){
           if(S[counter+10] == 'r' ) counter += 11 ;
           else counter += 10 ;
        }
        else counter += 7 ;
      }
      else counter += 5 ;
    }
    else if(S[counter] == 'e' && S[counter+1] == 'r' && S[counter+2] == 'a' && S[counter+3] == 's'  && S[counter+4] == 'e'){
      if(S[counter+5] == 'r' ) counter += 6 ;
      else counter += 5 ;
    }
    else {
      cout << "NO" << endl;
      return 0 ;
    }
  }
  cout << "YES" << endl;
}

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

int a[3000];

int main() {
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  #endif
  int l, r;
  cin >> l >> r;
  if (r - l >= 2018) {
    cout << 0;
    return 0;
  } else {
    long long ans = 0x3f3f3f3f;
    for (int i = l; i <= r; ++i) {
      for (int j = i + 1; j <= r; ++j) {
        ans = min((long long)i % 2019 * j % 2019, ans);
      }
    }
    cout << ans;
  }
  return 0;
}

Measured memory_bytes: 256
d = gets.to_i
xmas = "Christmas"
eve = "Eve"

if d == 25
    puts xmas
elsif d == 24
    puts xmas + " " + eve
elsif d == 23
    puts xmas + " " + eve+ " " + eve
elsif d == 22
    puts xmas + " " + eve+ " " + eve + " " + eve 
end

Measured memory_bytes: 1788
import bisect
def MI(): return map(int, input().split())
def II(): return int(input())
def IS(): return input()
def LI(): return list(map(int, input().split()))

n = II()
a, b, c = sorted(LI()), LI(), sorted(LI())
ans = 0
for _b in b:
    a_index = bisect.bisect_left(a,_b)
    c_index = bisect.bisect_right(c,_b)
    ans += a_index * (n - c_index)
print(ans)

    



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

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int N, A, B;
	cin >> N >> A >> B;
	int diff = B-A;
	if (diff%2 == 1) {
		cout << "Borys" << endl;
	}
	else {
		cout << "Alice" << endl;
	}
	cin >> N;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define fir first
#define sec second
#define mod 998244353
#define ll long long
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
typedef pair<int,int> pii;
int add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
int sub(int x,int y){return x-y<0?x-y+mod:x-y;}
int mul(int x,int y){return 1LL*x*y%mod;}
#define N 500005
#define ls (u<<1)
#define rs (u<<1|1)
bitset<30> t[N*4];
char s[N];
void build(int u,int l,int r)
{
	if(l==r)
	{
		t[u][s[l]-'a']=1;
		return ;
	}
	int mid=(l+r)/2;
	build(ls,l,mid),build(rs,mid+1,r);
	t[u]=t[ls]|t[rs];
}
void update(int u,int l,int r,int p)
{
	if(l==r)
	{
		t[u].reset();
		t[u][s[l]-'a']=1;
		return ;
	}
	int mid=(l+r)/2;
	if(p<=mid) update(ls,l,mid,p);
	else update(rs,mid+1,r,p);
	t[u]=t[ls]|t[rs];
}
bitset<30> query(int u,int l,int r,int L,int R)
{
	if(L<=l&&r<=R) return t[u];
	int mid=(l+r)/2;
	bitset<30> ans; ans.reset();
	if(mid>=L) ans|=query(ls,l,mid,L,R);
	if(mid<R) ans|=query(rs,mid+1,r,L,R);
	return ans;
}
signed main()
{
	int n=read();
	scanf("%s",s+1);
	build(1,1,n);
	int Q=read();
	while(Q--)
	{
		int opt=read();
		if(opt==1)
		{
			int pl=read(); char q;
			cin>>q; s[pl]=q;
			update(1,1,n,pl);
		}
		else
		{
			int l=read(),r=read();
			bitset<30> R=query(1,1,n,l,r);
			int ans=0;
			for(int i=0;i<26;i++) if(R[i]) ans++;
			printf("%d\n",ans);
		}
	}
	return 0;
}



Measured memory_bytes: 16384
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
#define mod 1000000007
#define MOD 1000000037
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define INF 2e9

lli func(lli k)
{
    lli ans=1;
    for(lli i=0;i<k;i++)
        ans*=2;
    return ans;
}

bool ispos(lli nodes,lli i)
{
    lli a=ceil(log2(nodes));
    if(a>i)
        return false;
    return true;
}

int main()
{
    lli n;
    cin >> n;
    n+=1;
    vector<lli>v(n);
    for(lli i=0;i<n;i++)
        cin >> v[i];
    lli f=1;
    lli na=1e9;
    lli nodes=0;
    vector<lli>vn(n);
    lli lim=-1;
    for(lli i=n-1;i>-1 and f==1;i--)
    {
        nodes+=v[i];
        if(ispos(nodes,i))
        {
            vn[i]=nodes;
            continue;
        }
        else
        {
            nodes-=v[i];
            lli nn=func(i);
            nn-=v[i];
            if(2*nn>=nodes)
            {
                nodes=nn+v[i];
                vn[i]=nodes;
            }
            else
            {
                lim=i;
                nodes=nn+v[i];  
                vn[i]=nodes; 
            }
        }
    }
    // cout << lim << endl;
    // for(lli i=0;i<n;i++)
    //     cout << vn[i] << " ";
    // cout << endl;
    if(lim!=-1)
    {
        nodes=func(lim);
        for(lli i=lim;i<n and f==1;i++)
        {
            vn[i]=min(nodes,vn[i]);
            if(vn[i]<v[i])
                f=0;
            nodes=(vn[i]-v[i])*2;
        }
    }
    if(f==0)
        cout << "-1" << endl;
    else
    {
        lli ans=0;
        for(lli i=0;i<n;i++)
            ans+=vn[i];
        cout << ans << endl;   
    }
}

Measured memory_bytes: 4908
#include<stdio.h>
int getHour(int);
int getMinute(int);
int getSecond(int);
int main(void)
{
  int s;
  scanf("%d",&s);
  printf("%d:%d:%d\n",getHour(s),getMinute(s),getSecond(s));
  return 0;
}
int getHour(int s)
{
  return s/3600;
}
int getMinute(int s)
{
  return (s%3600)/60;
}
int getSecond(int s)
{
  return s%60;
}



Measured memory_bytes: 2124
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>
using namespace std;

struct node{
  int key;
  node *R, *L,*P;
};

node *rt,*nil;

node * trmin(node *x){
  while(x->L != nil) x = x->L;
  return x;
}

node * find(node *u,int k){
  while(u != nil && k != u->key){
    if(k < u->key) u = u->L;
    else u = u->R;
  }

  return u;
}

node * trsccr(node *x){
  if(x ->R != nil) return trmin(x->R);
  node *y = x->P;
  while(y != nil && x == y->R){
    x=y;
    y=y->P;
  }
  return y;
}

void trdt(node *z){
  node *y;
  node *x;

  if(z->L == nil || z->R == nil) y = z;
  else y =trsccr(z);

  if(y->L != nil){
    x = y->L;
  }else{
    x = y->R;
  }

  if(x != nil){
    x->P = y->P;
  }

  if(y->P == nil){
    rt = x;
  }else{
    if(y == y->P->L){
      y->P->L = x;
    }else {
      y->P->R = x;
    }
  }

  if(y != z){
    z->key = y->key;
  }

  free(y);
}

void inst(int k){
  node *y = nil;
  node *x = rt;
  node *z;

  z = (node *)malloc(sizeof(node));
  z->key = k;
  z->L = nil;
  z->R = nil;

  while(x != nil){
    y = x;
    if(z->key < x->key){
      x = x->L;
    }else{
      x = x->R;
    }
  }

  z->P = y;
  if(y == nil){
    rt = z;
  }else{
    if(z->key < y->key){
      y->L = z;
    }else {
      y->R = z;
    }
  }
}

void indr(node *u){
  if(u == nil) return;
  indr(u->L);
  printf(" %d",u->key);
  indr(u->R);
}

void prodr(node *u){
  if(u == nil) return;
  printf(" %d",u->key);
  prodr(u->L);
  prodr(u->R);
}

int main(){
  int n,i,x;
  string cm;

  scanf("%d",&n);

  for(i = 0;i<n;i++){
    cin >> cm;
    if(cm[0] == 'f'){
      scanf("%d",&x);
      node *t = find(rt,x);
      if(t != nil) printf("yes\n");
      else printf("no\n");
    }else if(cm == "insert"){
      scanf("%d",&x);
      inst(x);
    }else if(cm == "print"){
      indr(rt);
      printf("\n");
      prodr(rt);
      printf("\n");
    }else if(cm == "delete"){
      scanf("%d",&x);
      trdt(find(rt,x));
    }
  }

  return 0;
}



Measured memory_bytes: 22024
#include<stdio.h>
#include<bitset>
#include<iostream>
#include<set>
#include<string.h>
#include<stack>
#include<queue>
#include<map>
#include<unordered_map>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<limits>
#include<math.h>
#include<string.h>

using namespace std;
  
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
 
#define pb push_back
#define ii pair<int, int>       
#define iii pair<int, ii > 
#define vai freopen("in","r",stdin);
#define inf 0x3f3f3f3f
#define f first
#define s second

const ll INF = 1e18;
const double dinf = 12345678;       
const int mod = 1000000007;
const int maxn = 1e6;
const int MAX = 1e4 + 10;
 
 

 
 
int main (){
	
	ios_base::sync_with_stdio(false); cin.tie(nullptr);
	//~ vai
	int n;
	cin >> n;
	
	if ( n <= 999 ){
		cout <<"ABC"; 
	}else if ( n <= 1998){
		cout<<"ABD";
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef double dl;
#define mp make_pair
#define pb emplace_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define dst distance
#define INF 1000000000
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#define MAXN 200110
ll MOD = 1e9+7;

vi des;
ll A[MAXN];
ll B[MAXN];
ll N,a;
ll S[MAXN];
ll fw[MAXN];

void update(ll x, ll v) {
	++x;
    for (; x<=2*N+1; x+=x&(-x)) fw[x] += v; 
}

ll query(ll x) {
    ll res = 0;
    for(; x; x-=x&(-x)) res += fw[x];
    return res;
}

ll sum(ll x, ll y){
	++x;++y;
	return query(y) - query(x-1);
}

ll ask(ll x){
	for (ll i=1;i<=N;++i){
		if (B[i]>=x)S[i]=1;
		else S[i]=-1;
	}
	for (ll i=1;i<=N;++i){S[i]+=S[i-1];}
	for (ll i=1;i<=N;++i){update(S[i], 1);}
	ll ans = 0;
	for (ll i=1;i<=N;++i){
		ll t = sum(S[i-1], 2*N);
		// cout<<"Query "<<S[i-1]<<' '<<t<<'\n';
		update(S[i], -1);
		ans+=t;
	}
	return ans;
}

int main(){
	cin>>N;
	S[0]=N;
	for (ll i=1;i<=N;++i){
		cin>>A[i];
		des.pb(A[i]);
	}
	sort(ALL(des));
	des.resize(unique(ALL(des)) - des.begin());
	for (ll i=1;i<=N;++i)B[i] = lb(ALL(des), A[i]) - des.begin();
	ll T = N*(N+1)/2;

	// for (ll i=0;i<=SZ(des);++i){
	// 	cout<<"Ask "<<i<<'\n';
	// 	cout<<ask(i)<<'\n';
	// }
	// return 0;
	ll lower = 0;
	ll upper = SZ(des);
	while (upper - lower > 1){
		ll mid=(upper+lower)/2;
		ll t = ask(mid);
		if (t*2>=T)lower=mid;
		else upper=mid;
	}
	if (ask(upper) *2 >= T)lower = upper;
	cout<<des[lower]<<'\n';
	// cout<<lower<<' '<<upper<<'\n';
}

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

const int N = 1e6 + 100;

int main() {
    // freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);

    int h1, m1, h2, m2, K;
    cin >> h1 >> m1 >> h2 >> m2 >> K;
    int t1 = h1 * 60 + m1, t2 = h2 * 60 + m2;
    int d = t2-t1;
    if(d < 0) d += 24 * 60;
    cout << d - K << endl;

    return 0;
}



Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// たて a cm よこ b cm の長方形の面積と周の長さを求めるプログラム
		
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		System.out.println((a * b) + " " + ( 2 * a + 2 * b ));
	}

}



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

typedef long long ll;
#define PB push_back

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	int k, x; cin >> k >> x;
	int low = x - k + 1;
	int high = x + k - 1;
	for (int i = low; i <= high; ++i) {
		cout << i << " ";
	}
}

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

#define ll long long
#define rep(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

#define fi first
#define se second
#define all(A) A.begin(),A.end()

using namespace std;
using namespace atcoder;

/////////////////////////////////////////////////////


ll N, Q;

ll i, j, k;
int main(){
    //ios::sync_with_stdio(true);
	//cin.tie(nullptr);
 
    scanf("%lld%lld",&N, &Q);

    dsu d(N+3);
    while(Q--){
        ll t, u, v;
        scanf("%lld%lld%lld",&t , &u ,&v);
        if(t==0){
            d.merge(u, v);
        }else{
            printf("%lld\n", (d.same(u, v) ? 1ll : 0ll));
        }
    }

    return 0;
}

Measured memory_bytes: 3936
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int max = 0;
		int sum = 0;
		int[] map = new int[N];
		for (int i = 0; i < N; i++) {
			map[i] = sc.nextInt();
			max = Math.max(max, map[i]);
			sum += map[i];
		}
		
		sum -= max;
		System.out.println(max < sum ? "Yes": "No");
	}
}

Measured memory_bytes: 22228
#include<bits/stdc++.h>
using namespace std;
int n,tmp;
vector<int> a;
long long res,first=-1,second=-1;
int main(){
  scanf("%d", &n);
  for(int i=0;i<n;i++){
    scanf("%d", &tmp);
    a.push_back(tmp);
  }
  sort(a.begin(),a.end(),greater<int>());
  for(int i=1;i<n;i++){
    if(a[i]==a[i-1]){
      if(first==-1){first=a[i];i++;}
      else if(second=-1){second=a[i];printf("%lld", first*second);return 0;}
    }
  }
  puts("0");
  return 0;
}

Measured memory_bytes: 892
N = int(input())
ans = []
alp = 'abcdefghijklmnopqrstuvwxyz'

def dfs(N):
    n, r = divmod(N-1, 26)
    ans.append(alp[r])
    if N <= 26:
        return (n, r)
    return dfs(n)

dfs(N)
print("".join(ans[::-1]))


Measured memory_bytes: 9036
#include <cstdio>
#include <iostream>

int main(void) {
  int v[3][3];
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      std::cin >> v[i][j];
    }
  }
  int n;
  std::cin >> n;
  for (int t = 0; t < n; t++) {
    int x;
    std::cin >> x;
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if (v[i][j] == x) {
          v[i][j] = 0;
        }
      }
    }
  }
  if (v[0][0] + v[0][1] + v[0][2] == 0 || v[1][0] + v[1][1] + v[1][2] == 0 ||
      v[2][0] + v[2][1] + v[2][2] == 0 || v[0][0] + v[1][0] + v[2][0] == 0 ||
      v[0][1] + v[1][1] + v[2][1] == 0 || v[0][2] + v[1][2] + v[2][2] == 0 ||
      v[0][0] + v[1][1] + v[2][2] == 0 || v[2][0] + v[1][1] + v[0][2] == 0) {
    std::cout << "Yes\n";
  } else {
    std::cout << "No\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  string S;
  cin >> S;
  long long cnt[3] = {0, 0, 0};
  for (int i = 0; i < N; i++) {
    if (S[i] == 'R') cnt[0]++;
    if (S[i] == 'G') cnt[1]++;
    if (S[i] == 'B') cnt[2]++;
  }
  long long ans = 0;
  for (int j = 1; j + 1 < N; j++) {
    for (int d = 1; j - d >= 0 && j + d < N; d++) {
      int i = j - d, k = j + d;
      if (S[i] != S[j] && S[j] != S[k] && S[k] != S[i]) ans--;
    }
  }
  ans += cnt[0] * cnt[1] * cnt[2];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3600
//ABC171_B

#include <stdio.h>
#include <stdlib.h>

int cmp( const void *p, const void *q ) {
    return *(int*)p - *(int*)q;
	}

int main(){
	int n,k;
	int p[1005];
	int sum=0;
	
	scanf("%d %d",&n,&k);
	
	for(int i=0;i<n;i++){
		scanf("%d",&p[i]);
	}
	
	qsort( p, n, sizeof(int), cmp );

//テスト出力
//	for(int i=0;i<n;i++){
//		printf("%d ",p[i]);
//	}

	for(int i=0;i<k;i++){
		sum = sum + p[i];
	}
	
	printf("%d",sum);

	return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> v(n), c(n);
    int ans = 0;
    for(int i = 0; i < n; i++){
        cin >> v.at(i);
    }
    for(int i = 0; i < n; i++){
        cin >> c.at(i);
    }
    for(int i = 0; i < n; i++){
        if(v.at(i) - c.at(i) > 0){
            ans += (v.at(i) - c.at(i));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 1000011
#define mod 1000000007

int n, i;
ll dp[maxN], sum[maxN];
ll ans;

int main()
{
  //  freopen("test.in","r",stdin);

    scanf("%d", &n);

    if (n == 1) {
        printf("1");
        return 0;
    }

    if (n == 2) {
        printf("4");
        return 0;
    }

    dp[0] = dp[1] = 1;
    sum[0] = 1; sum[1] = 2;

    for (i = 2; i <= n; i++) {
        dp[i] = mod + sum[i - 1] - dp[i - 2];
        dp[i] %= mod;

        sum[i] = sum[i - 1] + dp[i];
        sum[i] %= mod;
    }

    for (i = 0; i <= n - 2; i++) {
        // put an infinite loop
        ans += dp[i] * ((1LL * (n - 1) * (n - 1)) % mod);
        ans %= mod;

        // put an unfininished group
        ans += dp[i] * (i + 1);
        ans %= mod;
    }

    ans += dp[n - 1] * ((1LL * (n - 1)) % mod);
    ans %= mod;

    ans += dp[n];
    ans %= mod;

    printf("%lld", ans);


    return 0;
}


Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a[3][3];
	cin>>a[0][0]>>a[0][1]>>a[1][1];
	int k=3*a[1][1];
	a[0][2]=k-a[0][0]-a[0][1];
	a[2][2]=k-a[0][0]-a[1][1];
	a[2][1]=k-a[0][1]-a[1][1];
	a[2][0]=k-a[2][1]-a[2][2];
	a[1][2]=k-a[0][2]-a[2][2];
	a[1][0]=k-a[1][1]-a[1][2];
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			cout<<a[i][j]<<' ';
		}
		cout<<endl;
	}
	return 0;
}

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

signed main(){
  double N,M;
  cin>>N>>M;
  vector<int> A(N);
  rep(i,N)cin>>A[i];
  int sum=0;
  rep(i,N)sum+=A[i];
  double border=sum/(4*M);
  string ans="No";
  int co=0;
  rep(i,N){
    if(A[i]>=border)co+=1;
  }
  if(co>=M)ans="Yes";
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;

int main(){
        int N,i,cnt=0;
        double dist;
        cin >> N;
        vector<int> x(N);
        vector<int> y(N);
        vector<int> idx(N);
        for(i=0;i<N;i++){
                cin >> x[i] >> y[i];
                idx[i] = i;
        }
        do{
                for(i=0;i<N-1;i++){
                        dist += sqrt(pow((x[idx[i+1]]-x[idx[i]]),2.0) + pow(y[idx[i+1]]-y[idx[i]],2.0));
                }
                cnt++;
        }while(next_permutation(idx.begin(),idx.end()));
        cout << fixed;
        cout << setprecision(7) << dist/cnt << endl;
        return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True

    @staticmethod
    def fact(N):
        res = {}
        tmp = N
        for i in range(2, int(N ** 0.5 + 1) + 1):
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            if cnt > 0:
                res[i] = cnt
        if tmp != 1:
            res[tmp] = 1
        if res == {}:
            res[N] = 1
        return res


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    N, K = Scanner.map_int()
    P = Scanner.map_int()
    P.sort()
    print(sum(P[0:K]))


def main():
    # sys.stdin = open("sample.txt")
    # T = Scanner.int()
    # for _ in range(T):
    #     solve()
    # print('YNeos'[not solve()::2])
    solve()


if __name__ == "__main__":
    main()


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

using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    if(a%3==0 || b%3==0 || (a+b)%3==0) {
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    }
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  cout << n*n*n << endl;

  

}


Measured memory_bytes: 3552
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <set>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()

int b;
vector<int> c;

bool dfs(int i, int sum, int m) { // from ith
    if (i == b) return sum == m;
    if (dfs(i+1, sum+c[i], m) && sum <= m) return true;
    else return dfs(i+1, sum, m);
}

int main() {
    cin >> b;
    PUSH(b,c);
    
    int m;
    cin >> m;
    REP(i,m) {
        int j;
        cin >> j;
        if (dfs(0, 0, j)) cout << "yes" << endl;
        else cout << "no" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1208
a, b, x = map(int, input().split())

if a % x == 0:
    first = a + a % x
else:
    first = a + (x - (a % x))

last = b - (b % x)

if first == last:
    ans = 1
else:
    ans = (last - first - 1) // x + 2
print(ans)

Measured memory_bytes: 3060
package main

import (
	"fmt"
)

const MOD = 1000000007

func ModAdd(a, b int64) int64 {
	return (a + b) % MOD
}

func ModMul(a, b int64) int64 {
	return a * b % MOD
}

func ModSub(a, b int64) int64 {
	r := (a%MOD - b%MOD) % MOD
	if r < 0 {
		r += MOD
	}
	return r
}

func ModDiv(a, b int64) int64 {
	return a % MOD * ModInv(b) % MOD
}

func ModPow(a, n int64) int64 {
	var r int64 = 1
	for n > 0 {
		if n&1 == 1 {
			r = r * a % MOD
		}
		a = a * a % MOD
		n >>= 1
	}
	return r
}

func ModInv(a int64) int64 {
	var b, u, v int64 = MOD, 1, 0
	for b > 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	u %= MOD
	if u < 0 {
		u += MOD
	}
	return u
}

func main() {
	var N int
	fmt.Scanf("%d\n", &N)

	cnt := 0
	for i := 1; i <= N; i++ {
		if i%2 != 0 {
			cnt++
		}
	}
	fmt.Println(float64(cnt) / float64(N))

}


Measured memory_bytes: 512
N = gets.to_i
P = Hash.new{|h, k| h[k] = 0}
N.times{
  P[gets.chomp] += 1
}

c_m = P.max_by{|k, v| v}[1]
P.sort_by{|k, v| k}.each{|k, v|
  puts k if v == c_m
}


Measured memory_bytes: 44280
from copy import deepcopy
from itertools import combinations


N = int(input())
ppp = list(map(int, input().split()))
ppp_sorted = sorted(ppp)

combis = list(combinations(ppp, 2))

if ppp == ppp_sorted:
    print('YES')
    exit()
if N == 2:
    print('YES')
    exit()

for combi in combis:
    i = ppp.index(combi[0])
    j = ppp.index(combi[1])
    ppp_copy = deepcopy(ppp)
    ppp_copy[i], ppp_copy[j] = ppp[j], ppp[i]
    if ppp_copy == ppp_sorted:
        print('YES')
        exit()

print('NO')


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

int main()
{
    string O,E,ans;
    int o_size,e_size,mini;
    cin>>O>>E;
    o_size=O.size();
    e_size=E.size();
    mini=min(o_size,e_size);
    for(int i=0;i<mini;i++){
        ans+=O.at(i);
        ans+=E.at(i);
    }
    if(o_size==e_size){
        cout<<ans<<endl;
        exit(0);
    }
    if(mini==O.size()){
        ans+=E.at(mini);
    }else{
        ans+=O.at(mini);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import math
n, h = map(int, input().split())
sl = 0
th = []
for i in range(n):
    a, b = map(int, input().split())
    sl = max(sl, a)
    th.append(b)

th.sort()
th_damage = th.pop()
turn = 0
while (h > 0):
    if th_damage > sl:
        h -= th_damage
        if len(th) != 0:
            th_damage = th.pop()
        else:
            th_damage = 0
    else:
        turn += math.ceil(h / sl)
        break
    turn += 1

print(turn)


Measured memory_bytes: 7512
N,M,K = map(int,input().split())

ans = "No"
for i in range(N+1):
    for j in range(M+1):
        black = i*M + j*N -2*i*j
        if black == K:
            ans = "Yes"
            break
    if ans == "Yes":
        break

print(ans)


Measured memory_bytes: 2940
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let t = read::<f64>();
    let x = read::<f64>();
    println!("{:.8}", t / x)
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int H,W; cin>>H>>W;
	int c[10][10];
	for (int i=0; i<10; i++)
		for (int j=0; j<10; j++)
			cin>>c[i][j];
	ll dist[10][10]{INT_MAX};
	for (int i=0; i<10; i++)
		for (int j=0; j<10; j++)
				dist[i][j]=c[i][j];
	for (int k=0; k<10; k++)
		for (int i=0; i<10; i++)
			for (int j=0; j<10; j++)
				dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
	int ret=0;
	for (int i=0; i<H; i++) {
		for (int j=0; j<W; j++) {
			int x; cin>>x;
			if(x==-1) continue;
			ret+=dist[x][1];
		}
	}
	cout<<ret<<"\n";
	return 0;
}

Measured memory_bytes: 256
import math

N = int(input())
C, S, F = [], [], []

for _ in range(N - 1):
	c, s, f = map(int, input().split())
	C.append(c)
	S.append(s)
	F.append(f)
	
S.append(0)
C.append(0)
F.append(1)
	
for i in range(N):
	time = S[i] + C[i] # 必ず始発に乗れる
	for j in range(i + 1, N):
		if time > S[j]:
			time = F[j] * (math.ceil(time / F[j])) # かかる待ち時間を足す
		else:
			time = S[j] # 開通まで待つ
		time += C[j] # 移動にかかる時間を足す
	print(time)

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

ll solve() {
    string S, T;
    cin >> S >> T;
    ll ans = 0;
    for ( int i = 0; i < S.size(); i++ ) {
        if ( S[i] != T[i]) ans++;
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3912
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.nextLine().toCharArray();
		char[] t = sc.nextLine().toCharArray();

		Map<Character, List<Integer>> s_map = new HashMap<>();
		for (int i = 0; i < s.length; i++) {
			s_map.putIfAbsent(s[i], new ArrayList<>());
			s_map.get(s[i]).add(i);
		}

		for (char ti : t) {
			if (!s_map.containsKey(ti)) {
				System.out.println(-1);
				return;
			}
		}

		int s_idx = 0, t_idx = 0, next_idx;
		long ans = 0;
		List<Integer> idx_list;
		while (true) {
			if (t_idx == t.length) break;
			if (s[s_idx] == t[t_idx]) {
				t_idx++;
				s_idx = (s_idx + 1) % s.length;
				ans++;
			}
			else {
				idx_list = s_map.get(t[t_idx]);
				if (s_idx > idx_list.get(idx_list.size() - 1) || s_idx < idx_list.get(0) || idx_list.size() == 1) {
					next_idx = idx_list.get(0);
				}
				else {
					int idx_list_idx = -Collections.binarySearch(idx_list, s_idx);
					next_idx = idx_list.get(idx_list_idx - 1);
				}

				ans += next_idx > s_idx ? next_idx - s_idx : s.length - s_idx + next_idx;
				s_idx = next_idx;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 34856
using System;
using System.Collections.Generic;
class Program
{
    static void Main()
    {
        bool flag = true;
        List<string> x = new List<string>();

        while (flag)
        {
            string s = Console.ReadLine();
            if (s == "0")
                flag = false;
            else
                x.Add(s);
        }

        for (int i = 0; i < x.Count; i++) 
        {
            int sum = 0;
            string number = x[i];
            char[] digits = new char[number.Length];
            for (int j = 0; j < number.Length; j++)
            {
                digits[j] = number[j];
            }
            for (int j = 0; j < digits.Length; j++)
            {
                sum += (int)digits[j] - 48;
            }
            Console.WriteLine(sum);
        }

    }
}

Measured memory_bytes: 9092
#include <iostream>
#include <cmath>
#define N 1000+1
using namespace std;


int main()
{
    int a[N];
    int i, n;
    double average, s;
    while(cin >> n && n) {
        average = s = 0;
        for (i = 0; i < n; i++) {
             cin >> a[i];
             average += a[i];
        }
        average /= n;
        for (i = 0; i < n; i++)
            s += pow((a[i]-average), 2);
        s /= n;
        cout << sqrt(s) << endl;
    }
    return 0;
}


Measured memory_bytes: 3220
#include "bits/stdc++.h"

#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=n-1;i>=m;--i)
#define ALL(v) v.begin(),v.end()
#define PB(a) push_back(a)
#define INF 1000000001
#define MOD 1000000007
#define EPS 1e-9

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

typedef long long ll;
using namespace std;


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int o = 0, e = 0;
	int n;
	cin >> n;
	REP(i, n) {
		int a;
		cin >> a;
		if (a % 2 == 0) e++;
		else o++;
	}
	if (o % 2 == 0 || (o == 1 && e == 0))cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n,k = map(int,input().split())
l = list(map(int,input().split()))
#print(l)
cnt = l[k-1]
p = 1
g = 0
g = g+1
pr = l[g-1]
while(k < n):
    if l[k] > pr:
        sys.stdout.write("Yes")
        print("")

    else:
        sys.stdout.write("No")
        print("")

    g = g+1
    pr = l[g-1]
    k = k+1


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

const ll mod = 1e+9 + 7;

int main(){
    int n, m;
    cin >> n >> m;
    int a[n] = {};
    rep(i, m){
        int b;
        cin >> b;
        a[b - 1] ++;
    }

    ll fib[n + 2];
    fib[0] = 1;
    fib[1] = 1;
    rep(i, n){
        fib[i + 2] = fib[i + 1] + fib[i];
        fib[i + 2] %= mod;
    }

    int cnt = 1;
    ll ans = 1;
    bool flag = true;
    rep(i, n){
        if (a[i] == 0){
            cnt ++;
        }
        else{
            if (cnt == 0){
                flag = false;
                break;
            }
            ans *= fib[cnt - 1];
            ans %= mod;
            cnt = 0;
        }
    }
    if (cnt == n) cout << fib[n] << endl;
    else if (cnt != 0) cout << (ans * fib[cnt - 1]) % mod << endl;
    else if (!flag) cout << 0 << endl;
    else cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vst;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;


const ll mod=(1e+9)+7;
const ll inf=1e+16; 

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)

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

 ll n;
 cin >> n;
  vll a(n);
  vvll x(n),y(n);
  rep(i,0,n){
   cin >> a[i];
    x[i].resize(a[i]);
    y[i].resize(a[i]);
   rep(j,0,a[i]) {
     cin >> x[i][j] >> y[i][j];
    x[i][j]--;
  }
  }
  
  
  ll res=0;
  rep(i,1,(1<<n)){ 
    bool flag=true;
    rep(j,0,n){
      if(!((i>>j)&1)) continue;
      rep(k,0,a[j]) if(y[j][k]^((i>>x[j][k])&1)) flag=false;
    }
   if(flag) {
     ll cnt=0;
     rep(j,0,n) cnt+=((i>>j)&1);
     res=max(res,cnt);
   }
    
   }
  
  cout << res << endl;
  
}


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

int main() {
  int N;
  cin >> N;
  map<string, vector<pair<int, int>>> mp;

  for (int i = 1; i <= N; i++) {
    string city;
    int point;
    cin >> city >> point;
    mp[city].push_back(make_pair(point, i));
  }

  for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
    auto q = itr->second;
    sort(q.begin(), q.end());
    for (int i = q.size() - 1; i >= 0 ; i--) {
      auto p = q[i];
      cout << p.second << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
import bisect
import collections
import copy
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
MOD = 10**9+7

N,M,P = map(int,(input().split()))
line = []
for i in range(M):
    a,b,c = map(int,(input().split()))
    line.append([a-1,b-1,-c+P])

min_distance = [float("inf")]*N # min_distance[i] は始点から街iまでの最短距離
min_distance[0] = 0 # 始点から始点への最短距離は0とする

def Bellman_Ford(S,V,E,distance):
    
    flag = 0
    for _ in range(V):
        update = False
        for s,g,d in distance: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る
            if min_distance[s] != float("inf") and min_distance[s] + d < min_distance[g]: # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、
                min_distance[g] = min_distance[s] + d # 最短距離を上書きする
                update = True
        if not update:
            flag = 1
            break
    return min_distance,flag

def Bellman_Ford2(S,V,E,distance):
    for _ in range(V):
        for s,g,d in distance: # [s,g,d] = [道路の始点,道路の終点,道路の長さ] について、すべての道路を見る
            if min_distance[s] != float("inf") and min_distance[s] + d < min_distance[g]: # 最短経路が確立されている街から伸びる道路を通ることで、距離を短くできるならば、
                min_distance[g] = -float("inf")
                if g == N-1:
                    print(-1)
                    exit()
                    break
        else:
            continue
        break
    return min_distance

min_distance,flag = Bellman_Ford(1,N,M,line)

if flag == 1:
    ans = min_distance[N-1]
    print(max(-ans,0))
else:
    min_distance = Bellman_Ford2(1,N,M,line)
    ans = min_distance[N-1]
    if ans == -float("inf"):
        print(-1)
    else:
        print(max(-ans,0))

#print(min_distance)


Measured memory_bytes: 75812
#include<stdio.h>
int main(void){
   int a,b,c;
  scanf("%d %d",&a,&b);
  
  if(a<b){
    c=2*b-1;
  }else if(a>b){
    c=2*a-1;
  }else{
    c=2*a;
  }
  printf("%d",c);
  return 0;
}

Measured memory_bytes: 128
#include<iostream>

void printData(int data[], int lineCnt ) {
	for( int i = 0; i < lineCnt; i++ ) {
		if ( i > 0 ) {
			std::cout << " ";
		}
		std::cout << data[i];
	}
	std::cout << std::endl;
}

int main(void) {
    int lineCnt;
    std::cin >> lineCnt;

    int data[lineCnt];
    for( int i = 0; i < lineCnt; i++ ) {
        std::cin >> data[i];
    }

    for( int i = 0; i < lineCnt; i++ ) {
        int val = data[i];
        int j = i -1;
        while ( j >= 0 && val < data[j] ) {
            data[j+1] = data[j];
            j--;
        }
        data[j+1] = val;
        printData(data,lineCnt);
    }

    return 0;
}



Measured memory_bytes: 3112
#include <iostream>
#include <cstdio>
#include <cassert>
#include <ctime>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define all(x) (x).begin(), (x).end()

#ifdef LOCAL
#define dbg(x) cerr << #x " = " << x << endl;
#define idbg(x) #x " = " << x
#include "pretty_print.h"
#else
#define dbg(x)
#define idbg(x) ""
#endif

#ifdef _WIN32
#  define LLD "%I64d"
#else
#  define LLD "%lld"
#endif

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

template <typename T> T sqr(T x) { return x * x; }
template <typename T> T abs(T x) { return x < 0? -x : x; }
template <typename T> T gcd(T a, T b) { return b? gcd(b, a % b) : a; }
template <typename T> bool chmin(T &x, const T& y) { if (x > y) { x = y; return true; } return false; }
template <typename T> bool chmax(T &x, const T& y) { if (x < y) { x = y; return true; } return false; }


int main(int /* argc */, char** /* argv */)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifdef LOCAL
    assert(freopen("inp", "r", stdin));
    assert(freopen("out", "w", stdout));
    #endif

    string s;
    while (cin >> s) {
    // for (;;) {
    //     s.resize(10);
        int n = s.size();
    //     for (int i = 0; i < n; ++i) {
    //         if (rand() % 5 == 0) {
    //             s[i] = '?';
    //         } else {
    //             s[i] = rand() % 2? '1' : '0';
    //         }

    //     }
        int ans = 1e+9;
        for (int iter = 0; iter < 2; ++iter) {
            string c = s;
            vector<int> f(n + 1, 0);
            vector<int> g(n + 1, 0);
            for (int i = n - 1; i >= 0; --i) {
                f[i] = max(0, f[i + 1] + 2 * (c[i] == '0') - 1);
                g[i] = max(0, g[i + 1] + 2 * (c[i] == '1') - 1);
            }


            int x, y;
            x = y = 0;
            int res = 0;
            for (int i = 0; i < n; ++i) {
                if (c[i] == '?') {
                    if (x + f[i + 1] > y + g[i + 1]) {
                        c[i] = '1';
                    } else {
                        c[i] = '0';
                    }
                }
                x = max(0, x + 2 * (c[i] == '0') - 1);
                y = max(0, y + 2 * (c[i] == '1') - 1);
                res = max(res, max(x, y));
            }
            ans = min(ans, res);
            // if (iter && ans != res) {
            //     cout << ans << endl;
            //     cout << res << endl;
            //     cout << s << endl;
            //     exit(0);
            // }
            reverse(all(s));
        }
        cout << ans << "\n";
    }

    cerr << "Time execute: " << clock() / (double)CLOCKS_PER_SEC << " sec" << endl;
    return 0;
}


Measured memory_bytes: 13256
n=int(input())
a=list(map(int,input().split()))
b=[0]*(max(a)+2)

for i in range(n):
  if a[i]!=0:
    b[a[i]]+=1
    b[a[i]-1]+=1
    b[a[i]+1]+=1
  else:
    b[a[i]]+=1
    b[a[i]-1]+=0
    b[a[i]+1]+=1
print(max(b))

Measured memory_bytes: 13964
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define ALL(N) (N.begin(),N.end())

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> v(3);
  REP(i,3) cin >> v[i];
  sort ALL(v);
  int m;
  m=v[2];
  int K;
  cin >> K;
  REP(i,K) m*=2;
  cout << v[0]+v[1]+m << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(i=0;i<n;i++)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max(a,b)-min(a,b))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1; rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define fact(n) nPr((int)n,(int)n)
#define nHr(n,r) nCr((int)(n+r+1),(int)r)
#define sankaku(x) ((1+x)*x)/2
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
void initialize(){
  
}
int main(void){
  initialize();
  ll n,m,i,j,result=0;
  int d[LIMIT2]={0};
  char s[LIMIT1];

  scanf("%lld",&n);
  rep(i,n) scanf("%d",&d[i]);
  
  qsort(d,n,sizeof(int),upint);
  
  printf("%d",d[n/2]-d[n/2-1]);

  return 0;
}



Measured memory_bytes: 2556
import java.util.Scanner;

class Main {
 
    public static final String LIGHT = "light";
    public static final String FLY = "fly";
    public static final String BANTAM = "bantam";
    public static final String FETHER = "feather";
    public static final String WELTER = "welter";
    public static final String MIDDLE = "middle";
    public static final String HEAVY = "heavy";
 
    public static void main(String[] args) {
 
        Scanner scanner = null;
        try {
            scanner = new Scanner(System.in);
            while (scanner.hasNextDouble()) {
                double weight = scanner.nextDouble();
 
                System.out.println(getClassName(weight));
            }
 
        } finally {
            scanner.close();
        }
    }
 
    private static String getClassName(double num) {
        StringBuilder sb = new StringBuilder();
 
        if (num <= 48.00 || (57.00 < num && num <= 64.00)
                || (69.00 < num && num <= 75.00)
                || (81.00 < num && num <= 91.00)) {
            sb.append(LIGHT);
            sb.append(" ");
        }
        if (num <= 51.00) {
            sb.append(FLY);
        } else if (num <= 54.00) {
            sb.append(BANTAM);
        } else if (num <= 57.00) {
            sb.append(FETHER);
        } else if (num <= 60.00) {
            // Light
        } else if (num <= 69.00) {
            sb.append(WELTER);
        } else if (num <= 81.00) {
            sb.append(MIDDLE);
        } else {
            sb.append(HEAVY);
        }
 
        return sb.toString().trim();
 
    }
 
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    long long n, a, p = 1;
    double r = 0;
    cin >> n;

    for(int i = 0; i < n; i++) {
        cin >> a;
        if(a == 0) {
            cout << 0;
            return 0;
        }
        else
            r += log10(a), p *= a;
    }

    if(r > 18.1)
        cout << -1;
    else if(p <= 1000000000000000000)
        cout << p;
    else
        cout << -1;

    return 0;
}


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

int main() {
    int n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];

    if(a[0]!=0){
        cout<<-1<<endl;
        return 0;
    }

    ll ans=0;
    rep(i,n-1){
        if(a[i+1]-a[i]>1){
            cout<<-1<<endl;
            return 0;
        }

        if(a[i]==a[i+1]) ans+=a[i+1];
        else if(a[i]>a[i+1]) ans+=a[i+1];
        else ans++;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 4848
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
const int N = 2e6+5;
void solve(){
    int n;
    cin>>n;
    cout<<(1000-n%1000)%1000<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
  //  cin>>t;
    while(t--){
        solve();
    }
    return 0;
}



Measured memory_bytes: 3644