akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

int N;
LL ga, sa, ba;
LL gb, sb, bb;

LL dp1[15500];
LL dp2[25005100];

int main() {
	cin >> N;
	cin >> ga >> sa >> ba;
	cin >> gb >> sb >> bb;
	LL M = N;
	dp1[0] = N;
	for (int i = 0; i <= N; ++i) {
		dp1[i + ga] = max(dp1[i + ga], dp1[i] + gb - ga);
		dp1[i + sa] = max(dp1[i + sa], dp1[i] + sb - sa);
		dp1[i + ba] = max(dp1[i + ba], dp1[i] + bb - ba);
		M = max(M, dp1[i]);
	}
	LL ans = M;
	dp2[0] = M;
	for (int i = 0; i <= M; ++i) {
		dp2[i + gb] = max(dp2[i + gb], dp2[i] + ga - gb);
		dp2[i + sb] = max(dp2[i + sb], dp2[i] + sa - sb);
		dp2[i + bb] = max(dp2[i + bb], dp2[i] + ba - bb);
		ans = max(ans, dp2[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 195712
N = int(input())
A = []
B = []

for _ in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
A.sort()
B.sort()
if N%2 == 0:
    n = N//2
    MIN = (A[n-1] + A[n])/2
    MAX = (B[n-1] + B[n])/2
    print(int(2*(MAX-MIN)+1))
else:
    n = N//2
    MIN = A[n]
    MAX = B[n]
    print(MAX-MIN+1)


Measured memory_bytes: 25528
def triangle_check(a, b, c):
  if a>b+c:
    return False
  elif b>a+c:
    return False
  elif c>a+b:
    return False
  else:
    return True

def count_triangles(n, sticks):
  assert len(sticks) == n, "lenght of sticks does not match `n`"
  count = 0

  for i in range(len(sticks)):
    for j in range(i+1, len(sticks)):
      for k in range(j+1, len(sticks)):
        count += triangle_check(sticks[i], sticks[j] , sticks[k])

  return count

def findnumberofTriangles(arr): 
  
    # Sort array and initialize count as 0 
    n = len(arr) 
    arr.sort() 
    count = 0
  
    # Fix the first element. We need to run till n-3 as 
    # the other two elements are selected from arr[i+1...n-1] 
    for i in range(0,n-2): 
  
        # Initialize index of the rightmost third element 
        k = i + 2
  
        # Fix the second element 
        for j in range(i+1,n): 
  
            # Find the rightmost element which is smaller 
            # than the sum of two fixed elements 
            # The important thing to note here is, we use 
            # the previous value of k. If value of arr[i] + 
            # arr[j-1] was greater than arr[k], then arr[i] + 
            # arr[j] must be greater than k, because the array 
            # is sorted. 
            while (k < n and arr[i] + arr[j] > arr[k]): 
                k += 1
  
            # Total number of possible triangles that can be 
            # formed with the two fixed elements is k - j - 1. 
            # The two fixed elements are arr[i] and arr[j]. All 
            # elements between arr[j+1] to arr[k-1] can form a 
            # triangle with arr[i] and arr[j]. One is subtracted 
            # from k because k is incremented one extra in above 
            # while loop. k will always be greater than j. If j 
            # becomes equal to k, then above loop will increment k, 
            # because arr[k] + arr[i] is always greater than arr[k] 
            if(k>j): 
                count += k - j - 1
  
    return count 

if __name__ == "__main__":

  n = int(input())
  sticks = sorted(list(map(int, input().split(" "))))
  # num_triangles = count_triangles(n, sticks)
  num_triangles = findnumberofTriangles(sticks)
  print(num_triangles)

Measured memory_bytes: 3316
package main

import "fmt"

func main() {
  var w, h, x, y, r int
  
  fmt.Scanf("%d %d %d %d %d", &w, &h, &x, &y, &r)

 if (x -r < 0 || x + r  > w  ||  y - r < 0|| y + r > h) {
  fmt.Println("No")
 }else {
  fmt.Println("Yes")
}

 
}


Measured memory_bytes: 1148
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

long long gcd(long long a, long long b) {
  if (a % b == 0)
    return b;
  return gcd(b, a % b);
}

int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a < b) {
      cout << "No" << endl;
    } else if (b > d) {
      cout << "No" << endl;
    } else if (b < c) {
      cout << "Yes" << endl;
    } else if (b == d) {
      long long rest = a - (a / b) * b;
      if (rest <= c) {
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    } else {
      long long rest = a - (a / b) * b;
      if (rest > c) {
        cout << "No" << endl;
      } else {
        if (gcd(d - b, b) >= b - c)
          cout << "Yes" << endl;
        else
          cout << "No" << endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long x = sc.nextLong();

		for (long i = -1000; i<= 1000; i++){
			for (long j = -1000; j<=1000; j++){
				long ans = (long) (Math.pow(i, 5) - Math.pow(j, 5));
				if (x == ans){
					System.out.println(i + " " + j);
					return;
				}
			}
		}

	}


}

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

using namespace std;

#define Rep(i,a,b)  for (int i=(a);i<(b);i++)
#define rep(i,n)    for (int i=0;i<(n);i++)
#define all(x)      (x).begin(), (x).end()

#define ll long long

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

	if (r < 1200)
		cout << "ABC" << endl;
	else if (r < 2800)
		cout << "ARC" << endl;
	else
		cout << "AGC" << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define eps 1e-6
#define ll long long
#define IOS cin.sync_with_stdio(false);cin.tie(0);cout.tie(0);
//#define int long long
#define MEM(x,y) memset(x,y,sizeof(x))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define fi first
#define se second
#define endl "\n"
const ll mod=1000000007;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
ll qpow(ll a,ll b){ll s=1;while(b>0){if(b%2==1){s=s*a;}a=a*a;b=b>>1;}return s;}
ll qpowmod(ll a, ll b, ll c){ll res, t;res=1;t=a%c;while(b){if(b & 1){res=res*t%c;}t=t*t%c;b>>=1;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline long long read(){long long k=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}return k*f;}
inline void write(long long x){if(x<0)x=-x,putchar('-');if(x>9)write(x/10);putchar(x%10+'0');}
using namespace std;
int main()
{
    int n;
    cin>>n;
    ll sum=0;
    rep(i,1,n+1)
    {
        if(i%5==0||i%3==0)
        continue;
        else sum+=i;
    }
    cout<<sum;
    return 0;
}


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

bool C(ll X,ll A,ll B){
	for(ll i=max(1LL,X/2-3);i<=min(X,X/2+3);i++){
		ll k=i;
		if(k>=A)k++;
		ll j=X+1-i;
		if(j>=B)j++;
		if(k*j>=A*B)return 0;
	}
	return 1;
}
int main(){
	int q;cin>>q;
	rep(i,q){
		ll a,b;scanf("%lld%lld",&a,&b);
		ll l=0,r=INT_MAX;
		while(r-l>1){
			ll t=(l+r)/2;
			if(C(t,a,b))l=t;
			else r=t;
		}
		printf("%lld\n",l);
	}
}

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

int main() {
  ll n, a, ans;
  cin >> n;
  vector<ll> v(1000000 + 10);
  for (int i = 0; i < 1000010; i++) {
    v[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    cin >> a;
    v[a]++;
  }
  ans = 0LL;
  for (int i = 1; i <= 1000000; i++) {
    if (v[i]) {
      if (v[i] == 1) {
        ans++;
      }
      for (int j = i + i; j <= 1000000; j += i) {
        v[j] = 0;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 11180
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};



int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    string s;
    cin>>s;
    int n=s.size();
    bool f=1;
    rep(i,n/2){
        if(s[i]!=s[n-1-i]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    rep(i,(n-1)/2/2){
        if(s[i]!=s[(n-1)/2-i-1]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    rep(i,(n-1)/2/2){
        if(s[(n+3)/2-1+i]!=s[n-i-1]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
'use strict';
process.stdin.on('data', function(chunk) {
  var inputs = chunk.toString().trim();
  var expressions = inputs.split('\n');
  
  for (var i = 0; i < expressions.length; i++) {
    if (expressions[i] === '0 ? 0') {
      break;
    }
    var expression = expressions[i].split(' ');
    var left = parseFloat(expression[0]);
    var right = parseFloat(expression[2]);
    var op = expression[1];
  
    if (op === '+') {
      console.log(left + right);
    } else if (op === '-') {
      console.log(left - right);
    } else if (op === '*') {
      console.log(left * right);
    } else if (op === '/') {
      console.log(Math.floor(left / right));
    }
  }
  
});
process.stdin.resume();
process.stdin.setEncoding('utf8');

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

int main(){
  string s;
  cin >> s;
  int n = s.size();
  int nam0 = 0;
  for(int i=0; i<n; ++i){
    if(s[i] == '0') ++nam0;
  }
  int ans = min(nam0, n-nam0) * 2;
  cout << ans << endl;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    // 最小値を見つける -> その周囲から攻めていけばK-1個ずつ減る
    ll N, K; cin >> N >> K;
    vector<ll> A(N); rep(i, N){cin >> A.at(i);}

    vector<int> indices(N);
    iota(indices.begin(), indices.end(), 0);
    sort(indices.begin(), indices.end(), [&A](ll i1, ll i2) {
        return A[i1] < A[i2]; // これは昇順
    });
    cout << (ll)(ceilf((N - 1) / (double)(K-1))) << endl;
}

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


Measured memory_bytes: 1408
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
using namespace std;

static size_t N, A;
static vector<int32_t> x;
static vector<vector<vector<int64_t>>> memo;
static int64_t dp(int32_t index, int32_t sum, int32_t used) {
	if (memo[index][sum][used] > -1)
		return memo[index][sum][used];

	memo[index][sum][used] = dp(index + 1, sum, used) + dp(index + 1, sum + x[index], used + 1);
	return memo[index][sum][used];
}

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

	x.resize(N);
	for (size_t i = 0; i < N; i++)
		cin >> x[i];

	memo.resize(N + 1);
	for (size_t index = 0; index < memo.size(); index++) {
		memo[index].resize(N * 50 + 1);
		for (size_t sum = 0; sum < memo[index].size(); sum++) {
			memo[index][sum].resize(N + 1);
			for (size_t used = 0; used < memo[index][sum].size(); used++)
				memo[index][sum][used] = (index == N) ?
					((used != 0 && (sum % used == 0) && sum / used == A) ? 1 : 0) : -1;
		}
	}

	cout << dp(0, 0, 0) << endl;

	return 0;
}

Measured memory_bytes: 55040
class SEGTree:
    def __init__(self,n):
        self.Unit=0
        i=1
        while(i<n):
            i*=2
        self.SEG=[self.Unit]*(2*i-1)
        self.d=i
    def update(self,i,x):
        i+=self.d-1
        self.SEG[i]=1<<x
        while i>0:
            i=(i-1)//2
            self.SEG[i]=self.SEG[i*2+1]|self.SEG[i*2+2]
    def find(self,a,b,k,l,r):
        if r<=a or b<=l:
            return self.Unit
        if a<=l and r<=b:
            return self.SEG[k]
        else:
            c1=self.find(a,b,2*k+1,l,(l+r)//2)
            c2=self.find(a,b,2*k+2,(l+r)//2,r)
            return c1|c2
    def get(self,a,b):
        return self.find(a,b,0,0,self.d)
def bitcnt(x):
    res=0
    while x>0:
        if x&1:
            res+=1
        x//=2
    return res

n=int(input())
s=input()
q=int(input())
seg=SEGTree(n)
for i in range(n):
    seg.update(i,ord(s[i])-97)
for i in range(q):
    q,x,y=input().split()
    if q=='1':
        seg.update(int(x)-1,ord(y)-97)
    else:
        x,y=int(x)-1,int(y)
        bit=seg.get(x,y)
        print(bitcnt(bit))

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

using namespace std;

#define endl '\n'


int main(){

  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;

  int k = (n+999)/1000;

  cout << k*1000-n << endl;
 
  return 0;
}

Measured memory_bytes: 3644
import sys
a, b, c, d = list(input())

bit = 4

for i in range(8):
  calc_list = []
  for j in range(3):
    if((i >> j) & 1):
      calc_list.append("+")
    else:
      calc_list.append("-")
  calc_str = a + calc_list[0] + b + calc_list[1] + c + calc_list[2] + d
  if eval(calc_str) == 7:
    print(calc_str + "=7")
    sys.exit()

Measured memory_bytes: 9088
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------


int main() {
    int A,B,C;
    cin >> A >> B >> C;
    cout << B+min(A+B+1,C) << endl;

    return 0;
}



Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N, A, B;
ll solve() {
	if (A > B) return 0;
	if (N == 1) {
		if (A == B) return 1;
		else return 0;
	} else {
		ll x = A*(N-2);
		ll y = B*(N-2);
		return y-x+1;
	}
}
int main() {
	cin >> N >> A >> B;
	cout << solve() << endl;
}


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 = 1e8;
const ll INF = 1LL << 60;
typedef pair<int, int> P;

ll N, Q;
string S;

int main() {
    cin >> N >> S >> Q;
    vector<set<int>> is(26);
    rep(i, N) is[S[i] - 'a'].insert(i);

    rep(k, Q) {
        ll q;
        cin >> q;
        if (q == 1) {
            ll i;
            char c;
            cin >> i >> c;
            i--;
            is[S[i] - 'a'].erase(i);
            S[i] = c;
            is[S[i] - 'a'].insert(i);
        } else {
            ll l, r;
            cin >> l >> r;
            l--;

            // 文字の種類数を求める
            int ans = 0;
            rep(j, 26) {
                // auto it = lower_bound(is[j].begin(), is[j].end(), l);
                auto it = is[j].lower_bound(l);
                if (it != is[j].end() && *it < r) ans++;
            }
            cout << ans << endl;
        }
    }
}

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

int main() {
  string s;
  cin >> s;

  bool no = (s[0] == 'A' && s[1] == 'A' && s[2] == 'A') ||
            (s[0] == 'B' && s[1] == 'B' && s[2] == 'B');
  if (!no)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
from collections import defaultdict, deque
sq = [i for i in range(200)]
for i in range(199):
    sq[i + 1] += sq[i]
for i in range(199):
    sq[i + 1] += sq[i]
ss = []
for s in sq:
    if s % 2:
        ss.append(s)

dp = defaultdict(lambda: False)
check = defaultdict(lambda: False)
for s in sq:
    dp[s] = True
    check[s] = True
dps = defaultdict(lambda: False)
checks = defaultdict(lambda: False)
for s in ss:
    dps[s] = True
    checks[s] = True

def main(n, ss, check, dp):
    q = deque()
    q.append((n, 1))
    check[n] = True
    if dp[n]:
        return 1
    while q:
        a, i = q.pop()
        for s in ss:
            aa = a - s
            if aa <= 0:
                break
            if not check[aa]:
                check[aa] = True
                q.appendleft((aa, i + 1))
            else:
                if dp[aa]:
                    return i + 1

while 1:
    n = int(input())
    if n == 0:
        break
    check = defaultdict(lambda: False)
    for s in sq:
        check[s] = True
    checks = defaultdict(lambda: False)
    for s in ss:
        checks[s] = True
    print(main(n, sq, check, dp), main(n, ss, checks,dps))



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

using namespace std;

int main(void){
    string s;
    cin >> s;
    bool flag = true;
    for(int i=0;i<s.size()-1;i++){
        if(s[i]==s[i+1]){
            flag = false;
        }
    }
    if(flag){
        cout << "Good" << endl;
    } else {
        cout << "Bad" << endl;
    }
}

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

int main(){
	ios::sync_with_stdio(0);
	cout << setprecision(10) << fixed;
	long long n;
	cin >> n;
	vector<pli> a(n + 1);
	for (int i = 1; i <= n; ++i){
		cin >> a[i].first;
		a[i].second = i;
	}
	sort(a.begin() + 1, a.end());
	reverse(a.begin() + 1, a.end());
	vector<vector<long long>> dp(n + 2, vector<long long>(n + 2, -2e18));
	dp[0][0] = 0;
	for (long long i = 1; i <= n; ++i){
		for (long long j = 0; j < i; ++j){
			long long x = a[i].first;
			long long l = abs(a[i].second - (i - j));
			long long r = abs((n - j) - a[i].second);
			dp[i][j] = max(dp[i][j], dp[i - 1][j] + x * l);
			dp[i][j + 1] = max(dp[i][j + 1], dp[i - 1][j] + x * r);
		}
	}
	long long ans = 0;
	for (int i = 0; i <= n; ++i){
		ans = max(ans, dp[n][i]);
	}
	cout << ans;
	return 0;
}



Measured memory_bytes: 34676
#include <cstdio>
#include <cstring>

#define MAX_N 100001

/* -----------------------------------------------------------------------------
	大域データ
----------------------------------------------------------------------------- */
int N;			// 文字列の長さ(2≦N≦10^5)
char S[MAX_N];	// 文字列
int children[MAX_N];


int main () {

	int i, l, r;
	int cntL, cntR; 

	// 整数の数の読込み
	scanf("%s", S);


	// 初期化
	N = strlen(S);
	memset(children, 0, sizeof(children));
	cntL = cntR = i = 0;

	// 
	while(i < N) {
		//
		while(S[i] == 'R') {i++; cntR ++;}
		while(S[i] == 'L') {i++; cntL ++;}

		// 集計
		r = i - cntL; l = r - 1;
		if(cntR % 2 == 0) {
			children[r] += (cntR + 1) / 2;
			children[l] += cntR / 2;
		} else {
			children[r] += cntR / 2;
			children[l] += (cntR + 1) / 2;
		}
		if(cntL % 2 == 0) {
			children[r] += cntL / 2;
			children[l] += (cntL + 1) / 2;
		} else {
			children[r] += (cntL + 1) / 2;
			children[l] += cntL / 2;
		}
		cntL = cntR = 0;
	}

	for(i = 0; i < N - 1; i++) 
		printf("%d ", children[i]);
	printf("%d\n", children[i]);

	return 0;
}


Measured memory_bytes: 896
#include <cstdio>

int main()
{
  int h, w, a, b;
  scanf("%d%d%d%d", &h, &w, &a, &b);
  for (int i = 0; i < h; ++i)
  {
    for (int j = 0; j < w; ++j)
    {
      putchar((i < b) ^ (j < a) ? '1' : '0');
    }
    putchar('\n');
  }
  return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
int cost[100][100];
int dp[100];
int main(){
	int n,k;
	while(1){
		cin>>n>>k;
		if(n==0)	return 0;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++)	cost[i][j]=1<<30;
		}
		while(k--){
			int f;	cin>>f;
			if(f){
				int c,d,e;	cin>>c>>d>>e;
				c--;	d--;
				cost[c][d]=min(cost[c][d],e);	cost[d][c]=cost[c][d];
			}
			else{
				int a,b;	cin>>a>>b;
				a--;	b--;
				for(int i=0;i<n;i++)	dp[i]=1<<30;
				priority_queue<pair<int,int> > pq;
				pq.push(make_pair(0,a));
				dp[a]=0;
				while(!pq.empty()){
					pair<int,int> cur=pq.top();	pq.pop();
					int use=-1*cur.first,now=cur.second;
					for(int i=0;i<n;i++){
						if(dp[i]>use+cost[now][i]){
							dp[i]=dp[now]+cost[now][i];
							pq.push(make_pair(-dp[i],i));
						}
					}
				}
				if(dp[b]==1<<30)	cout<<-1<<endl;
				else 	cout<<dp[b]<<endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1244
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve(args);
    }

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();

        String a = scanner.next();
        String[] array = a.split("");
        int tmp = 0;
        if((array[0].equals(array[1])&&array[2].equals(array[3])&&!array[0].equals(array[2]))||
        	(array[0].equals(array[2])&&array[1].equals(array[3])&&!array[0].equals(array[1]))||
        	(array[0].equals(array[3])&&array[1].equals(array[2])&&!array[0].equals(array[2]))){
        	System.out.println("Yes");
        }else {
        	System.out.println("No");
        }

    }

    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }

    private static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}

Measured memory_bytes: 22612
#include <iostream>
#include <string>
#include <math.h>

using namespace std;

int main()
{
	int n;
	int num;
	int ans=0;
	int i;
	cin >> n;
	
	num = to_string(n).length();



	for (i = 1; i < num; i += 2)
	{
		ans += 9 * (int)(pow(10, i-1) + 0.5);
	}

	if (num % 2 != 0)
	{
		n -= (int)(pow(10, num - 1) + 0.5);
		n++;
	}
	else
	{
		n = 0;
	}

	cout << ans + n << endl;

	return 0;
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

  int k,n;cin>>k>>n;
  vector<int> A(n);
  for(int i=0;i<n;i++){
    cin>>A[i];
  }
  int ans=A[n-1]-A[0];
  for(int i=1;i<n;i++){
    ans = min(ans, k - (A[i]-A[i-1]));
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 1024
import sys
w = list(input())
w = sorted(w)
counter = 1
for i in range(len(w)-1):
    if w[i] == w[i+1]:
        counter = counter + 1
    else:
        if counter % 2 != 0:
            print("No")
            sys.exit()
        counter = 1
if counter % 2 == 0 :
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
using System;
using System.Linq;
using System.Collections.Generic;
class P
{
    static void Main()
    {
        string n = long.Parse(Console.ReadLine()).ToString();
        int res = 0;
        if (n.Length == 1)
        {
            res = n[0] - '0';
        }
        else if (n[0] != '9')
        {
            if (n.Count(x => x != '9') == 1)
            {
                res = 9 * (n.Length - 1) + (n[0] - '0');
            }
            else
            {
                res = 9 * (n.Length - 1) + (n[0] - '0' - 1);
            }
        }
        else if (n.Count(x => x != '9') != 0)
        {
            res = 9 * (n.Length - 1) + 8;
        }
        else
        {
            res = 9 * (n.Length - 1) + 9;
        }
        Console.WriteLine(res);
    }
}


Measured memory_bytes: 11220
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <string>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <vector>
#include <set>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <numeric>


using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

const ll mod=1000000007ll;
const ll inf=1000000000000000ll;

const ll nmax=50;


int main(){
    ll n,m,x,y,xmax,ymin,xa,ya;
    bool fl=false;
    cin>>n>>m>>xa>>ya;
    xmax=xa;
    ymin=ya;
    if (ya<=xa){
        fl=true;
    }

    else{
        for(ll i=0;i<n;i++){
        cin>>x;
        if(x>xmax)xmax=x;
        }
        for(ll i=0;i<m;i++){
        cin>>y;
        if(y<ymin)ymin=y;
        }
        if(xmax>=ymin){
            fl=true;
        }
    }
    //cout<<xmax<<","<<ymin<<endl;

    if(fl) {cout<<"War"<<endl;}
    else {cout<<"No War"<<endl;}
    return 0;
}


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

int main(){
  int N, M;
  cin >> N >> M;
  
  vector<pair<int, int>> a;
  int x, y;
  for(int i = 0; i != M; i++){
    cin >> x >> y;
    a.push_back(make_pair(x, y));
  }
  
  sort(begin(a), end(a), [](const auto & x, const auto & y){ return x.second < y.second; });
  
  int cnt = 1;
  int last = a[0].second;
  for(auto i = begin(a)+1; i != end(a); i++){
    if(i->first < last){
      continue;
    }
    else{
      cnt++;
      last = i->second;
    }
  }
  
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 1400
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GI2(H, W);
  vector<string> mp(H);
  FOR(i, H) cin >> mp[i];
  vector<vector<int>> dp(H, vector<int>(W));
  dp[0][0] = 1;
  FOR(i, H) {
    FOR(j, W) {
      if (mp[i][j] == '#')
        continue;
      if (i > 0)
        dp[i][j] += dp[i - 1][j];
      if (j > 0)
        dp[i][j] += dp[i][j - 1];
      dp[i][j] %= MOD;
    }
  }
  print(dp[H - 1][W - 1]);
  return 0;
}

Measured memory_bytes: 5248
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>


int main() {
	int number = 0;
	int oddnumber = 0;
	long long int tmp = 0;

	scanf("%d", &number);
	for (int i = 1; i <= number; i++) {
		tmp = 0;
		scanf("%lld", &tmp);
		if (tmp % 2 == 1) { oddnumber++; }
	}

	if (oddnumber % 2 == 0) {
		printf("YES");
	}
	else{
		printf("NO");
	}


	//while (1) {}
	return 0;
}

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

using namespace std;

typedef long long ll;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

const int inf = 1e9 + 7;
const int mod = 1e9 + 7;

inline void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
  if (a < 0) a += mod;
}

inline int mul(int a, int b) {
  return (a * (ll) b) % mod;
}

inline int pw(int x, int n) {
  int res = 1;
  while (n > 0) {
    if (n % 2) {
      res = mul(res, x);
      n--; 
    } else {
      x = mul(x, x);
      n /= 2;
    }
  }
  return res;
}

const int N = 1e5 + 7;

int a[N][3];
int dp[N][3];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i][0] >> a[i][1] >> a[i][2];
  }
  for (int i = 0; i < n; i++) {
    for (int me = 0; me < 3; me++) {
      for (int was = 0; was < 3; was++) {
        if (me != was) {
          int prev = (i > 0 ? dp[i - 1][was] : 0);
          dp[i][me] = max(dp[i][me], prev + a[i][me]);
        }
      }
    }
  }
  cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}) << '\n';
  return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LINF = 9223372036854775807;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	VI a(3); REP(i, 3)cin >> a[i];
	sort(ALL(a));
	if ((a[0] == a[1] || a[2] == a[1]) && a[0] != a[2])
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1LL << 60;
constexpr int INF = 1000000007;
const double INFD = 1e100;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
  ll N;
  cin >> N;
  ll ans=0;
  if(N%2 == 1){
    cout << 0 << endl;
    return 0;
  }
  N /= 2;
  while(N>0){
    N /= 5;
    ans += N;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
code = r"""
# distutils: language=c++
# distutils: include_dirs=/home/contestant/.local/lib/python3.8/site-packages/numpy/core/include
from libcpp cimport *
from libcpp.vector cimport vector


cdef extern from "/opt/atcoder-stl/atcoder/dsu.hpp" namespace "atcoder":
    cdef cppclass dsu:
        dsu()
        dsu(int n)
        int merge(int a, int b)
        bool same(int a, int b)
        int leader(int a)
        int size(int a)
        vector[vector[int]] groups()


N, Q = map(int, input().split())
cdef dsu uf = dsu(N)
for _ in range(Q):
    t, u, v = map(int, input().split())
    if t == 0:
        uf.merge(u, v)
    else:
        if uf.same(u, v):
            print(1)
        else:
            print(0)

"""
import os
import sys
if sys.argv[-1] == 'ONLINE_JUDGE':
    open('solve.pyx', 'w').write(code)
    os.system('cythonize -i -3 -b solve.pyx')
import solve

Measured memory_bytes: 10360
#include<bits/stdc++.h>
#define ll long long int
ll v[1000000+9];
using namespace std;
int main()
{
    ll i,j,ans=0,x,p,n,k;

    map<ll,ll>m;
    map<ll,ll> :: iterator it;

    cin>>n>>k;

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

    x=m.size();
    //cout<<x<<endl;
    if(x<=k)
    {
        cout<<0<<endl;
    }
    else
    {

        j=0;
        for(it=m.begin(); it!=m.end(); it++)
        {
            v[j]=it->second;
            j++;
        }
        x=m.size();
        sort(v,v+x);

        ll s=m.size()-k;

        for(i=0; i<s; i++)
        {
            ans+=v[i];
        }
        cout<<ans<<endl;
    }
    return 0;
}


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

using namespace std;
typedef long long ll;

const int N = 2e5 + 10;
typedef pair<ll, ll> pll;
pll d[N];
set<pll> red;
set<pll> blue;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        ll x, y;
        cin >> x >> y;
        d[i] = pll(min(x, y), max(x, y));
    }
    sort(d, d + n);
    for (int i = 0; i < n; i++) {
        red.insert(pll(d[i].first, i));
        blue.insert(pll(d[i].second, i));
    }
    ll res = (red.rbegin()->first - red.begin()->first) * (blue.rbegin()->first - blue.begin()->first);
    for (int i = 0; i < n; i++) {
        red.erase(pll(d[i].first, i));
        blue.erase(pll(d[i].second, i));
        red.insert(pll(d[i].second, i));
        blue.insert(pll(d[i].first, i));
        res = min(res, (red.rbegin()->first - red.begin()->first) * (blue.rbegin()->first - blue.begin()->first));
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 30464
#include<stdio.h>
int main(void)
{
    int a,b,c,d,count=0,i=0;
    while(scanf("%d",&a)!=EOF){
    scanf("%d",&b);
    c=a+b;
    for(;;){
    c=c/10;
    count++;
    if(c<1)break;
    }
    printf("%d\n",count);
    count=0;
    i++;
    }
    return 0;
}

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

ll a[50];
int main(){
	ll k;scanf("%lld",&k);
	rep(i,50){
		ll b=k/50+(k%50>i);
		a[i]=49+50*b-(k-b);
	}
	puts("50");
	rep(i,50){
		if(i)printf(" ");
		printf("%lld",a[i]);
	}
	puts("");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    ll ans=1;
    ll mod = pow(10, 9) + 7;
    for (int i=1; i<=n; i++){
        ans = ans * i % mod;
    }
    out(ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    unsigned long long n, X, x[200005], sum[200005];
    x[0] = 0;
    sum[0] = 0;
    cin >> n >> X;
    for(int i = 1; i <= n; i++){
        cin >> x[i];
        sum[i] = sum[i - 1] + x[i];
    }
    unsigned long long ans = 18000000000000000000;
    for(ull i = 1; i <= n; i++){
        ull now = X * n + X * i;
        ull number = (n + i - 1) / i;
        for(ull index = 1; index <= number; index++){
            ull mini = n - (i * (index - 1)) - i + 1; 
            ull maxi = n - (i * (index - 1));
            if(mini > n) mini = 1;
            if(mini == 0) mini = 1;
            if(maxi > n) maxi = 0;
            //mini = max(mini, (ull)1);
            //cout << i << " " << index << " " << mini << " " << maxi << endl;
            ull cost = 2 * index + 1;
            if(index == 1) cost = 5;
            now += (sum[maxi] - sum[mini - 1]) * cost; 
        }
        //cout << i << " " << now << endl;
        ans = min(ans, now);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  string s;
  string ans = "";

  cin >> s;
  for(ll i = 0; i < ll(s.size()); i += 2) ans += s[i];

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3696
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <set>
using namespace std;

#define N 300010
#define M 500010

typedef long long ll;
const int INF = 1 << 30;
const int Mod = 1000000007;

int n;
priority_queue<ll, vector<ll>, greater<ll> > Q;
priority_queue<ll> q;
ll f[N], g[N];
ll a[N];

int main()
{
	//freopen("in.in", "r", stdin);
	//freopen("out.out", "w", stdout);
	
	int n; scanf("%d", &n);
	
	for (int i = 1; i <= 3 * n; ++i) scanf("%lld", &a[i]);
	
	ll s = 0;
	for (int i = 1; i <= n; ++i) Q.push(a[i]), s += a[i];
	f[n] = s;
	for (int i = n + 1; i <= 2 * n; ++i)
	{
		if (a[i] > Q.top()) 
		{
			s = s - Q.top() + a[i];
			Q.pop(), Q.push(a[i]);
		}
		f[i] = max(f[i - 1], s);
	}
	
	s = 0;
	for (int i = 3 * n; i >= 2 * n + 1; --i) q.push(a[i]), s += a[i];
	g[2 * n + 1] = s;
	for (int i = 2 * n; i > n; --i)
	{
		if (a[i] < q.top())
		{
			s = s - q.top() + a[i];
			q.pop(), q.push(a[i]);
		}
		g[i] = min(g[i + 1], s);
	}
	
	ll res = -1ll << 60;
	for (int i = n; i <= 2 * n; ++i) res = max(res, f[i] - g[i + 1]);
	cout << res << endl;
	return 0; 
}


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

int main() {
  ll N;
  cin >> N;
  ll X = N;
  ll fx = 0;
  for (int i = 8; 0 <= i; --i) {
    ll div = X / pow(10, i);
    if (div == 0) {
      continue;
    }
    fx += div;
    X -= div * pow(10, i);
  }
  if (N % fx == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int L, R;
    int i, j, k;
    int mod1=3300, mod2=3300;
    int tmp2;
    long long tmp;

    scanf("%d %d", &L, &R);

    if(R-L < 2019){
        tmp2 = R-L;
    }else{
        tmp2 = 2019;
    }

    for(i=L; i<L+tmp2; i++){
        for(j=L+1; j<=L+tmp2; j++){
            tmp = (i%2019) * (j%2019);
            //printf("%d ", tmp);
            tmp = tmp%2019;
            if(tmp<mod1){
                mod1=tmp;
            }
        }        
    }
    //printf("%d\n", i);

    printf("%d", mod1);

    return 0;
}

Measured memory_bytes: 128
from collections import deque
def main(k):
    q = deque([])
    for i in range(1, 10):
        q.append(i)
    
    count = 0
    top = -1
    
    while True:
        top = q.popleft()
 
        count += 1
        if count == k:
            return top
 
        if top%10 != 0:
            q.append(top*10 + top%10-1)
        q.append(top*10 + top%10)
        if top%10 != 9:
            q.append(top*10 + top%10 + 1)
 
    return top
k = int(input())
print(main(k))

Measured memory_bytes: 11904
#include <bits/stdc++.h>
 
#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;
 
/* DSU 
int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}
void make_set(int v) {
    parent[v] = v;
    rank[v] = 0;
}
void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (rank[a] < rank[b])
            swap(a, b);
        parent[b] = a;
        if (rank[a] == rank[b])
            rank[a]++;
    }
}
*/ 
ll power(ll base, ll exp) 
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}
 
ll mod(ll a, ll b) {return (a % b + b) % b;}
 
ll powerm(ll base,ll exp,ll mod) 
{ll ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
 
using namespace std;

int main()
{
	fast;
	ll n; cin>>n; ll arr[n]; for(ll i = 0; i < n; i++) cin>>arr[i];
	ll sum = 0; sort(arr,arr+n);
	for(ll i = 1; i < n; i++) sum += (arr[i] - arr[i-1]);
	cout << sum << endl;
	return 0;
}

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

using namespace std;

bool cmp(pair<int, int> a, pair<int, int> b){
  return a.second > b.second;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  map<int, int> mp;
  for(int i=0; i<n; i++){
    int x;
    cin >> x;
    mp[x]++;
  }
  vector< pair<int, int> > v;
  for(auto x : mp) v.push_back({x.first, x.second});
  sort(v.begin(), v.end(), cmp);
  int ans = 0;
  for(int i=k; i<v.size(); i++) ans += v[i].second;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 11764
n = int(input())
a = list(map(int, input().split()))

dup=[0]*n
for num in a:
    dup[num-1]+=1
    if dup[num-1]>1:
        break

A=-1
B=-1
for i in range(len(a)):
    if a[i]==num:
        if A==-1:
            A=i
        else:
            B=i
B=n-B

def find_power(n,mod=10**9+7):
    powlist=[0]*(n+1)
    powlist[0]=1
    powlist[1]=1
    for i in range(2,n+1):
        powlist[i]=powlist[i-1]*i%(mod)
    return powlist
  
def find_inv_power(n,mod=10**9+7):
    powlist=find_power(n)
    check=powlist[-1]
    first=1
    uselist=[0]*(n+1)
    secondlist=[0]*30
    secondlist[0]=check
    secondlist[1]=check**2
    for i in range(28):
        secondlist[i+2]=(secondlist[i+1]**2)%(10**9+7)
    a=format(10**9+5,"b")
    for j in range(30):
        if a[29-j]=="1":
            first=(first*secondlist[j])%(10**9+7)
    uselist[n]=first
    for i in range(n,0,-1):
        uselist[i-1]=(uselist[i]*i)%(10**9+7)
    return uselist

mod = 10**9+7
NUM = (10**5)+100
p_lis=find_power(NUM,mod)
ip_lis=find_inv_power(NUM,mod)

def comb(n,r,mod=10**9+7):
    if n<r:
        return 0
    elif n>=r:
        return (p_lis[n]*ip_lis[r]*ip_lis[n-r])%(mod)

print(n)
for k in range(2,n+2):
    base=comb(n+1,k) - comb(A+B,k-1)

    print(base%mod)

Measured memory_bytes: 69612
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace ConsoleApp6
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var As = new List<A>();
            for (int i = 0; i < N; i++)
            {
                var a = new A();
                var shougenCount = int.Parse(Console.ReadLine());
                for (int j = 0; j < shougenCount; j++)
                {
                    var xy = Console.ReadLine().Split(' ');
                    a.Shougens.Add(new Shougen
                    {
                        X = int.Parse(xy[0]),
                        Y = int.Parse(xy[1]) == 1,
                    });
                }

                As.Add(a);
            }

            var patterns = Get(N).ToList();
            var valids = patterns.Where(x => IsValid(As, x));

            if (!valids.Any())
            {
                Debug.WriteLine(0);
                Console.WriteLine(0);
            }
            var max = valids.Max(x => x.Count(y => y));
            Debug.WriteLine(max);
            Console.WriteLine(max);
        }

        private static bool IsValid(List<A> As, List<bool> pattern)
        {
            foreach (var a in As.Select((a, i) => new { A = a, Index = i }))
            {
                // 信用しないので無視
                if (pattern[a.Index] == false) continue;

                // 矛盾するかどうかの判定
                if (a.A.Shougens.Any(x => pattern[x.X - 1] != x.Y))
                {
                    return false;
                }
            }

            return true;
        }

        private static IEnumerable<List<bool>> Get(int n)
        {
            for (int i = 0; i < Math.Pow(2, n); i++)
            {
                yield return Convert.ToString(i, 2).PadLeft(n, '0').Select(x => x == '1').ToList();
            }
        }

        class A
        {
            public List<Shougen> Shougens { get; set; } = new List<Shougen>();
        }
        class Shougen
        {
            public int X { get; set; }
            public bool Y { get; set; }
        }
    }
}


Measured memory_bytes: 23112
'use strict'
const inputs = require('fs').readFileSync(0, 'utf8').split('\n')
const N = parseInt(inputs[0], 10)
const K = parseInt(inputs[1], 10)
let ans = 1
for (let i = 0;i < N;i++) {
  ans = Math.min(ans + K, ans * 2)
}
console.log(ans)

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

int v[10][10];
int n, m, ans;

void dfs(int from, int visited) {
  visited |= (1 << from);
  for (int i = 0; i < n; i++)
    if (v[from][i] == 1 && !((1 << i) & visited)) dfs(i, visited);
  if (visited == (1 << n) - 1) ans++;
}

int main() {
  cin >> n >> m;
  int a, b;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    a--;
    b--;
    v[a][b] = 1;
    v[b][a] = 1;
  }
  dfs(0, 0);
  cout << ans << endl;
}


Measured memory_bytes: 256
N, T = map(int, input().split())
min_cost = 1001

for i in range(N):
    cost, time = map(int, input().split())

    if time <= T:
        min_cost = min(cost, min_cost)

if min_cost <= 1000:
    print(min_cost)
else:
    print('TLE')

Measured memory_bytes: 2940