akhauriyash/Code-Regression huggingface dataset:
n = gets.to_i
a = gets.split.map(&:to_i)

sum = ans = 0
n.times do |i|
    sum += a[i]
    if i.even? && sum <= 0
        ans += -sum + 1
        sum = 1
    elsif i.odd? && sum >= 0
        ans += sum + 1
        sum = -1
    end
end

sum = ans2 = 0
n.times do |i|
    sum += a[i]
    if i.even? && sum >= 0
        ans2 += sum + 1
        sum = -1
    elsif i.odd? && sum <= 0
        ans2 += -sum + 1
        sum = 1
    end
end

p [ans, ans2].min

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll dp[105][301010];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    REP(i, 105)REP(j, 101010) dp[i][j] = -1;
    dp[0][0] = 0;

    ll N, W;
    cin >> N >> W;
    vector<ll> w(N), v(N);
    REP(i, N) cin >> w[i] >> v[i];
 
    REP(i, N){
    	REP(j, W+1){
    		if(dp[i][j] == -1) continue;
    		dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
    		dp[i+1][j+w[i]] = max(dp[i+1][j+w[i]], dp[i][j]+v[i]);
    	}
    }

    ll res = -1;
    REP(i, W+1) res = max(res, dp[N][i]);
    cout << res << endl;
    return 0;
}

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

using namespace std;

int main(){
    char s[3];
    int nedan=700;
    for(int i=0;i<3;i++){
        cin>>s[i];

        if(s[i]=='o'){
        nedan+=100;
        }
    }
    
    cout<<nedan<<endl;
}

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

int main()
{
    int64_t a, b, c;
    cin >> a >> b >> c;
    
    int64_t left, right;
    left = c - a - b;
    right = 4 * a * b;

    if(left > 0 && left * left > right) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
h, w, m = map(int,input().split())
dic_h = dict()
dic_w = dict()
max_h = [0, 0]
max_w = [0, 0]
c = dict()
for _ in range(m):
    x, y = map(int,input().split())
    c[(x, y)] = 1
    
    if dic_h.get(x):
        dic_h[x] += 1
        if dic_h[x] > max_h[0]:max_h = [dic_h[x], x]
        elif dic_h[x] == max_h[0]:max_h.append(x)
    else:
        dic_h[x] = 1
        if max_h[0] == 0:max_h = [1, x]
        elif max_h[0] == 1:max_h.append(x)
    
    if dic_w.get(y):
        dic_w[y] += 1
        if dic_w[y] > max_w[0]:max_w = [dic_w[y], y]
        elif dic_w[y] == max_w[0]:max_w.append(y)
    else:
        dic_w[y] = 1
        if max_w[0] == 0:max_w = [1, y]
        elif max_w[0] == 1:max_w.append(y)
        
res = max_h[0] + max_w[0] - 1
#print(max_h, max_w)
for i in range(len(max_h) - 1):
    for j in range(len(max_w) - 1):
        temp = (max_h[i + 1], max_w[j + 1])
        if c.get(temp):continue
        res += 1
        print(res)
        exit()
print(res)

Measured memory_bytes: 85424
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

lint eq[1123456], gt[1123456];

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

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

    fill(begin(eq), end(eq), 1e18);
    fill(begin(gt), end(gt), 1e18);
    eq[0] = 0;
    gt[0] = 1 + 1;

    lint n = s.length();
    for(lint i=0; i<n; i++) {
        lint cur = s[i] - '0';
        for(lint d=0; d<10; d++) {
            if(d < cur) {
                chmin(gt[i+1], gt[i] + d + (-1) + (10 + d - cur));
            } else if(d == cur) {
                chmin(eq[i+1], eq[i] + cur + 0);
                chmin(eq[i+1], gt[i] + cur + 0);
            } else {
                chmin(gt[i+1], eq[i] + d + (d - cur));
                chmin(gt[i+1], gt[i] + d + (d - cur));
            }
        }
    }

    cout << min(eq[n], gt[n]) << endl;
}

Measured memory_bytes: 18948
#include<iostream>
#include<algorithm>
#include <string>
#include<cstdio>
#include<stack>
#include<cstring>
#include<vector>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EREP(i,n) for(int i=(n-1);i>=0;--i)
#define D(n,retu) REP(i,n){cin>>retu[i];}
#define mod 1000000007
using namespace std;
typedef long long ll;
template<typename T>
void fill_all(T& arr, const T& v) {
	arr = v;
}
template<typename T, typename ARR>
void fill_all(ARR& arr, const T& v) {
	for (auto& i : arr) { fill_all(i, v); }
}

//------------------変数-----------------------//
ll n, cou = 1, kekka[200001] = { 0 }, mae = 1;
string a[60];
//-------------------関数----------------------//
int main() {
	cin >> n;
	REP(i, n) {
		ll gomi; cin >> gomi;
		kekka[gomi]++;
	}
	if (n % 2 == 1) { if (kekka[0] != 1) { cout << "0" << endl; return 0; } }
	if (n % 2 == 0) { if (kekka[0] != 0) { cout << "0" << endl; return 0; } }
	ll zz; if (n % 2 == 1) { zz = 0; }
	else { zz = 1; }
	for (int i = 1; i <n ; i++)
	{
		if (i%2==zz&&kekka[i] != 2) { cout << "0" << endl; return 0; }
	}
	REP(i, n / 2 + 1) { if (i == 0)continue; mae *= 2; mae %= mod; }

	cout << mae << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char c[100];

int main(){
	scanf("%s",c);
	int n=strlen(c);
	int ans=700;
	for(int i=0;i<n;i++) if(c[i]=='o') ans+=100;
	printf("%d",ans);
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(long long i=0;i<n;++i)
#define REPR(i,n) for(long long i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(v) {for(long long sitr=0;sitr<v.size();++sitr){cin>>v[sitr];}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  int l, n;
  cin >> l >> n;

  vector<int> x(n), w(n);
  vector<int> a, b;
  REP(i,n){
    cin >> x[i] >> w[i];
    if(x[i] != 0){
      a.pb(x[i] * -1);
      b.pb(w[i]);
    }
  }

  int m = a.size();
  cout << a.size() << endl;
  REP(i,m){
    cout << a[i] << " " << b[i] << endl;
  }


  return 0;
}




Measured memory_bytes: 3152
#include <stdio.h>
#include <stdlib.h>

int comp(const void *a, const void *b){
    if (*(int *)a < *(int *)b) return -1;
    if (*(int *)a > *(int *)b) return 1;
    if (*(int *)a == *(int *)b) return 0;
    }

int main(){
    int n;
    scanf("%d",&n);
    int a[n+5];
    for(int i = 0; i < n; ++i)
        scanf("%d", &a[i]);

    qsort(a,n,sizeof(a[0]),comp);

    printf("%d\n", a[n-1] - a[0]);
    
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <queue>
#include <cstdlib>
#include <vector>
using namespace std;

typedef long long ll;
int main(){
  int n;
  priority_queue<string>que[10];
  cin >> n;

  for(int i=0; i<n; i++){
    string in;
    cin >> in;
    int size = in.size();
    que[size].push(in);
    if(que[size].size() == 10) que[size].pop();
  }

  vector<string>v;

  for(int i=0; i<10; i++){
    while(!que[i].empty()){
      v.push_back(que[i].top());
      que[i].pop();
    }
  }

  priority_queue<ll>q;
  for(int i=0; i<v.size(); i++){
    for(int j=0; j<v.size(); j++){
      if(i == j)continue;
      string str = v[i] + v[j];
      q.push(atoll(str.c_str()));
      if(q.size() == 4){
	q.pop();
      }
    }
  }

  cout << q.top() << endl;

  return 0;
}

Measured memory_bytes: 1248
a, b, c = map(int, input().split())
k = int(input())
result = False

for i in range(k):
    if b <= a:
        b *= 2
    elif c <= b:
        c *= 2

    if a < b < c:
        result = True
        break

if (result):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9184
#include<iostream>
using namespace std;
int main()
{
int a,b,c;
while(cin>>a>>b)
{int k=0;
 c=a+b;

 while(c!=0) 
 {
 c=c/10;
 k++;

 }

 cout<<k<<endl;

}

return 0;

}

Measured memory_bytes: 1160
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func group(n int) int {
	if n == 2 {
		return 2
	}
	if n == 4 || n == 6 || n == 9 || n == 11 {
		return 1
	}
	return 0
}

func main() {
	sc.Split(bufio.ScanWords)

	x, y := getInt(), getInt()

	if group(x) == group(y) {
		out("Yes")
	} else {
		out("No")
	}

}


Measured memory_bytes: 640
#include<stdio.h>

int main(void){
  int n,m,max=0,ans=1,i,j;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    m=i;
    for(j=0;;j++){
      if(m%2==0) m/=2;
      else break;
    }
    if(max<j){
      max=j;
      ans=i;
    }
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
//written by newbiechd
#include <cstdio>
#include <algorithm>
using namespace std;
const int N = 200003;
char s[N];
int a[N], b[N];
int main() {
    register int n, i, ans;
    scanf("%d%s", &n, s + 1), ans = n;
    for (i = 1; i <= n; ++i)
        a[i] = s[i] == '.', b[i] = s[i] == '#';
    for (i = n; i; --i)
        a[i] += a[i + 1];
    for (i = 1; i <= n; ++i)
        b[i] += b[i - 1];
    for (i = 1; i <= n; ++i)
        ans = min(ans, a[i + 1] + b[i - 1]);
    printf("%d\n", ans);
    return 0;
}


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

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

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

using namespace std;

const int N = 100010;
const int MOD = 1e9 + 7;

int n, m;
long long f[N];

int main() {
  f[0] = 1;
  for (int i = 1; i < N; ++i) {
    f[i] = (i * 1LL * f[i - 1]) % MOD;
  }
  cin >> n >> m;
  if (abs(n - m) > 1) {
    puts("0");
    return 0;
  }
  long long ans = (f[n] * f[m]) % MOD;
  if (n == m) ans = (ans * 2LL) % MOD;
  printf("%lld\n", ans);
  return 0;
}



Measured memory_bytes: 1024
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def LcpByZ(target):
    len_t = len(target)
    lcp = [-1] * len_t
    top = 1  # 右の箱において、左の箱の0に対応する点
    left = 0  # 左の箱の左端(本当はここでので宣言は不要だけど理解の為)
    right = 0  # 左の箱の右端
    lcp[0] = 0
    while top < len_t:
        # 箱を右に広げていく
        while top + right < len_t and target[right] == target[top + right]:
            right += 1
        # 右の箱左端のlcpを記録
        lcp[top] = right
        left = 1
        # 箱の幅が0だったらtopを動かして、このターン終了
        if right == 0:
            top += 1
            continue
        # lcpを記録しながら箱を左に縮めていく（最初の条件重要）
        while left + lcp[left] < right and left < right:
            lcp[top + left] = lcp[left]
            left += 1
        # topを右の箱の左端にして、左の箱を0まで戻す
        top += left
        right -= left
        left = 0  # これも本当は不要
    return lcp

def dfs(i,si):
    dp[i]=0
    ni=(i+tn)%sn
    if lcp[tn+1+ni]!=tn:return False
    if ni==si:return True
    if dp[ni]==-1 and dfs(ni,si):return True
    dp[i]=dp[ni]+1

s=SI()
t=SI()
ss = s
while len(ss) < len(s) + len(t): ss += s
lcp = LcpByZ(t + "@" + ss)
sn = len(s)
tn = len(t)
dp=[-1]*sn
for i in range(sn):
    if dp[i]!=-1:continue
    if dfs(i,i):
        print(-1)
        exit()
print(max(dp))


Measured memory_bytes: 504360
#include <iostream>

#define SIZE 101

int r, c;
int sheet[SIZE][SIZE];

int main() {

    std::cin >> r >> c;
    for (int row=0; row<r; ++row) {
        for (int col=0; col<c; ++col) {
            std::cin >> sheet[row][col];
            sheet[row][c] += sheet[row][col];
            sheet[r][col] += sheet[row][col];
        }
    }
    for (int col=0; col<c; ++col) sheet[r][c] += sheet[r][col];

    for (int row=0; row<=r; ++row) {
        for (int col=0; col<c; ++col) {
            std::cout << sheet[row][col] << ' ';
        }
        std::cout << sheet[row][c] << std::endl;
    }
    return 0;
}



Measured memory_bytes: 3136
#include <iostream>

using namespace std;

int main() {
    string A, B;
    cin >> A >> B;
    string ans;
    if(A.size()>B.size()) {
        ans = "GREATER";
    } else if(A.size()<B.size()) {
        ans = "LESS";
    } else {
        int flag=0;
        for(int i=0; i<A.size(); i++) {
            if(A[i]==B[i]) {
                continue;
            } else if(A[i]>B[i]) {
                flag=1;
                break;
            } else {
                flag=-1;
                break;
            }
        }
        if(flag==0) {
            ans = "EQUAL";
        } else if(flag==1) {
            ans = "GREATER";
        } else {
            ans = "LESS";
        }
    }

    cout << ans << endl;


    return 0;
    
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mp(x,y) make_pair(x,y)
const int nax=2e5+5;
vector<vector<int>> v(nax);
int vis[nax]={0};
int a[nax];
set<pair<int,int>> s;
int ans[nax];
void dfs(int ci){
    vis[ci]=1;
    pair<int,int> ins={-1,-1},del={-1,-1};
    if(s.size()==0){
        ins={a[ci],1};
    }
    else{
        auto it=s.lower_bound(mp(a[ci],-1));
        if(it==s.end()){
            it--; ins={a[ci],it->second+1};
        }
        else if(it==s.begin()){
            if(it->first > a[ci]){
                ins={a[ci],1};
                if(it->second==1)
                    del=*it;
            }
        }
        else{
            if(it->first > a[ci]){
                it--;
                ins={a[ci],it->second+1};
                it++;
                if(it->second == ins.second){
                    del=*it;
                }
            }
        }
    }
    if(del.first != -1) s.erase(del);
    if(ins.first != -1) s.insert(ins);
    auto it=s.end();
    it--;
    ans[ci]=it->second;
    for(auto x : v[ci]){
        if(vis[x]==1) continue;
        dfs(x);
    }
    if(ins.first != -1) s.erase(ins);
    if(del.first != -1) s.insert(del);
    
}
void solve(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n-1;i++){
        int x,y; cin>>x>>y;
        x--; y--;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    dfs(0);
    for(int i=0;i<n;i++){
        cout<<ans[i]<<'\n';
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int tc;
 //   cin>>tc;
    tc=1;
    while(tc--){
        solve();
    }
return 0;
}


Measured memory_bytes: 30816
#include <iostream>
#include <queue>
#include <vector>
#define mx 3*200005
//#define mn -(1long long << 50)
using namespace std;
priority_queue <long long , vector<long long> , greater<long long> > q1;
priority_queue <long long> q2;
long long sum1[mx],sum2[mx];
long long arr[mx];
int main()
{
    int n;
    cin >> n;
    for(int i=0;i<3*n;i++)
        cin >> arr[i];
    for (int i=0 ; i<3*n-n ; i++)
    {
        sum1[i] = (i > 0 ? sum1[i-1] : 0)+arr[i];
        q1.push(arr[i]);
        if(q1.size() <= n) continue;
        sum1[i]-=q1.top();
        q1.pop();
    }

    for (int i=3*n-1 ; i >= n ; i--)
    {
        sum2[i] =arr[i]+ sum2[i+1];
        q2.push(arr[i]);
        if (q2.size() <= n) continue;
        sum2[i]-=q2.top();
        q2.pop();
    }
    long long ans=-(1LL << 50);

    for (int i=n-1 ; i < 2*n ; i++)
        ans=max(sum1[i]-sum2[i+1],ans);

    cout << ans << endl;
}


Measured memory_bytes: 14196
def getdata_input():
    while True:
        yield input()
def callFunc2(it):
    N=int(next(it))
    prime=[x for x in range(2,2*N+1)]
    a=[-1]*(2*N+1)
    lp=0
    for x in prime:
        if lp >= N:
            break
        if a[x]!=-1:
            continue
        c=1
        i=x*c

        while i < 2*N+1:
            lp=x
            a[i]=x
            c+=1
            i=x*c
    return(str(lp))   
it=getdata_input()
print(callFunc2(it))        

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

int main() {
    long long n; cin >> n;
    if (n & 1) return !(cout << 0 << endl);
    n /= 2;
    long long cnt = 0;
    while (n) cnt += (n /= 5);
    cout << cnt << endl;
    return 0;
}


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

int main() {
    int N; cin>>N;
     vector<bool> p(N, false);
     for(int i=0;i<N;i++){
         int a; cin>>a;
         if(a-1==i)p[i]=true;
     }
     int ans=0;
     for(int i=0;i<N-1;i++){
         if(p[i]==true){
             ans++;
             p[i]=false;
             p[i+1]=false;
         }
     }
     if(p[N-1]==true){
         ans++;
     }
     cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(long long i=a; i<b; i+=1)
#define repr(i,a,b) for(long long i=a; i<=b; i+=1)
#define vec vector<ll>
#define map map<char,int>
#define repa(p,A) for(auto p:A)
#define pb push_back
#define sort(a) sort(a.begin(),a.end())
//#define reverse(a) reverse(a.begin(),a.end())
const double PI=acos(-1);
using namespace std;

int main() {
    ll N;
    cin>>N;
    string S=" ";
    
    while(N) {
        --N;
        S+=char('a'+N%26);
        N/=26;
        }
        reverse(S.begin(), S.end());
        cout<<S<<endl;
}


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

n = int(input())
if n == 3:
    print(2)
    print(1,3)
    print(2,3)
else:
    res = [[1,3],[2,3]]
    cnt = 0
    for i in range(4,n+1):
        if i%2 == 0:
            for j in range(len(res)):
                res[j] = [res[j][0]+1,res[j][1]+1]
            for j in range(2,i):
                res.append([1,j])
        else:
            for j in range(1,i):
                res.append([i,j])
    print(len(res))
    for e in res:
        print(e[0],e[1])


Measured memory_bytes: 4084
#include <iostream>
#include <stdio.h>

#include <vector>

using namespace std;

int main()
{
    int m,n;
    cin >> n;
    
    vector<int> arrayInt(0);

    for (int i = 0; i < n ;i++) {
        cin >> m;
        arrayInt.push_back(m);
    }

    for (int j = 0; j < n / 2; j++) {
            int change = arrayInt[j];
            arrayInt[j] = arrayInt[n - j - 1];
            arrayInt[n - j - 1] = change;
        }
    
    for (int k = 0; k < n; k++) {
        cout << arrayInt[k];
        if (k != n-1) {
            cout << " ";
        }
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(iiii,nnnn) for (ll iiii=0,iiii##_len=(nnnn); iiii<iiii##_len;iiii++)
#define RANGE(i,is,ie) for (ll i=is,i##_end=(ie); i<=i##_end;i++)
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } else return false; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } else return false; }

int main() {

    for (ll n; cin >> n, n; ) {

        vector<ll> w(n);
        REP(i, n) cin >> w[i];
        vector<vector<ll>> dp(n, vector<ll>(n+1, 0));
        vector<vector<ll>> rm(n, vector<ll>(n+1, 0));
        REP(i, n) dp[i][i+1] = 0, rm[i][i+1] = w[i];
        RANGE(i, 2, n) {
            RANGE(l, 0, n-i) {
                ll r = l+i;
                RANGE(c, l+1, r-1) {
                    if (dp[l][c] == c-l && dp[c][r] == r-c) {
                        dp[l][r] = r-l;
                    } else if (dp[l][c] == c-l && dp[c][r] == r-c-1) {
                        dp[l][r] = c-l;
                        rm[l][r] = rm[c][r];
                    } else if (dp[c][r] == r-c && dp[l][c] == c-l-1) {
                        dp[l][r] = r-c;
                        rm[l][r] = rm[l][c];
                    } else if (dp[l][c] == c-l-1 && dp[c][r] == r-c-1 && abs(rm[l][c] - rm[c][r]) <= 1) {
                        dp[l][r] = r-l;
                    } else {
                        chmax(dp[l][r], dp[l][c] + dp[c][r]);
                    }
                }
            }
        }
        cout << dp[0][n] << endl;

    }

}


Measured memory_bytes: 4208
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


S = sys.stdin.buffer.readline().decode().rstrip()

a = 0
ab = 0
abc = 0
q = 0
for i, s in enumerate(S):
    if s == 'C':
        abc += ab
    if s == 'B':
        ab += a
    if s == 'A':
        a += pow(3, q, MOD)
    if s == '?':
        abc = abc * 3 + ab
        ab = ab * 3 + a
        a = a * 3 + pow(3, q, MOD)
        q += 1
    a %= MOD
    ab %= MOD
    abc %= MOD
    # print(s, a, ab, abc)
print(abc)


Measured memory_bytes: 3316
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			String[] s = new String[9];
			int[] num = new int[9];
			int[] sum = new int[9];
			for(int i=0;i<9;i++){
				s[i] = sc.next();
				int a = sc.nextInt();
				int b = sc.nextInt();
				num[i] = a + b;
				sum[i] = a*200 + b*300;
			}
			for(int i=0;i<9;i++){
				System.out.println(s[i] + " " + num[i] + " " + sum[i]);
			}
		}
		
	}	
}

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

typedef long long int ll;
typedef long double ld;

//****************************************************                
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define endl "\n" //comment it for interactive questions
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define sz(X) (ll)X.size()
    //*******************************************************
//Some Functions

const ll MOD = (ll)1e9+7; //change it for other mods

ll powmod(ll a,ll b)
{
   ll res = 1;
   while(b > 0) {
      if(b & 1) res = (res * a) % MOD;
      a = (a*a)%MOD;
      b = b >> 1; 
  }
  return res % MOD;
}

void solve(ll testnum)
{
    ll n,x,m;
    cin >> n >> x >> m;
    vll a;
    set<ll> vals;
    a.pb(x);
    vals.insert(x);
    ll sum = x;
    // cout << x << "\n";
    while(1) {
    	x = (x*x)%m;
    	if(vals.count(x) == 0) {
    		a.pb(x);
    		// cout << x << "\n";
    		vals.insert(x);
    	} else {
    		break;
    	}
    }
    ll ans = 0;
    ll tmpsum = 0, tmpcnt = 0;
    if(sz(a) > n) {
    	for(ll i = 0; i < n; i++) {
    		ans += a[i];
    	}
    	cout << ans << "\n";
    	return;
    }
    ll check = 1;
    for(ll i = 0; i < sz(a); i++) {
    	if(a[i] == x) {
    		check = 0;
    	}
    	if(check) ans += a[i];
    	else {
    		tmpcnt++;
    		tmpsum += a[i];
    	}
    }
    // cout << ans << " " << tmpcnt << " " << tmpsum << "\n";
    n = (n - (sz(a) - tmpcnt));
    ll tms = n / tmpcnt;
    ll rem = n % tmpcnt;
    ans += tms*tmpsum;
    for(ll i = 0; i < rem; i++) {
    	ans += a[sz(a) - tmpcnt + i];
    }
    cout << ans << "\n";
}

int main()
{
    FAST_IO;
    #ifdef STIO 
      freopen("input.txt" , "r", stdin);
      freopen("output.txt" , "w", stdout);
    #endif
    ll t = 1;
    // cin >> t;
    for (ll i = 1; i <= t; i++) {
        // cout << "Case #" << i << ": ";
        solve(i);
    }
}

Measured memory_bytes: 5908
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n;
	scanf("%lld",&n);
	ll a[n];
	ll best=0;
	ll sum=0;
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
		best<a[i]?best=a[i]:best=best;
		sum+=a[i];
	}
	if(best<sum-best){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	
}


Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
 
int main() {
	long long int a[6];
	int min = 1;
	for(int i = 0; i < 6; i++) {
		scanf("%Ld", &a[i]);
		if((i > 0) && (a[i]< a[min])) min = i;
	}
	long long int ans;
	ans = (a[0] + a[min] - 1)/a[min] + 4;
	cout << ans;
	return 0;
};

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

int N, X;
int sum = 0;
int res = 0;

int main(){
  cin >> N >> X;
  int m[N];
  int minm = 2000;
  for(int i = 0; i < N ; i++){
    cin >> m[i];
    minm = min(minm, m[i]);
    sum += m[i];
    res++;
  }
  while(true){
    bool sumX = false;
    if(sum + minm <= X){
      sum += minm;
      res++;
    }
    else if(sum + minm > X){
      sumX = true;
    }
    if(sumX)break;
  }
  cout << res << endl;
}
    
    
    
    

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

#define int long long

unsigned long long xor128() {
  static unsigned long long rx = 123456789, ry = 362436069, rz = 521288629, rw = 88675123;
    unsigned long long rt = (rx ^ (rx << 11));
    rx = ry;
    ry = rz;
    rz = rw;
    return (rw = (rw ^ (rw >> 19)) ^ (rt ^ (rt >> 8)));
}

typedef pair<int,int>P;
typedef pair<int,P>P2;

map<P2,int>dp;

signed main(){
  int n;
  cin>>n;
  int _9 = 1;
  for ( int i = 2; i <= 9; i++ ) _9 *= i;  
  while(n--){
    int a[9],b[9];    
    r(i,9)cin>>a[i];
    r(i,9)cin>>b[i];
    sort(a, a+9);    
    int cnt = 0;
    do{
      int sum = 0;
      for ( int i = 0; i < 9; i++ ) {
	if ( a[i] > b[i] ) sum += a[i]+b[i];
      }      
      if ( sum > 171-sum ) cnt++;			     
    }while(next_permutation(a,a+9));
    double ans = (double)cnt/_9;
    // cout << ans << " " << 1.0-ans << endl;
    printf("%.5f %.5f\n",ans,1.0-ans);    
  }
}



Measured memory_bytes: 3288
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <map>
const int MOD = 1e9+7;
using namespace std;


int main(){
	int a, b;
	cin >> a >> b;
	vector<string> str(2);
	for (int i = 0; i < b; i++){
		str[0] += to_string(a);
	}
	for (int i = 0; i < a; i++){
		str[1] += to_string(b);
	}
	sort(str.begin(), str.end());
	cout << str[0] << endl;
	return 0;
}


Measured memory_bytes: 256
n,k=map(int, input().split())
i=1
okashi_kazu=[]
okashi_hito=[]
okashi_hito2=[]
for i in range(1,2*k+1):
  if i%2==0:
    okashi_hito.extend(input().split())
  else:
    okashi_kazu.append(input().split())

okashi_hito2=set(okashi_hito)
print(n-len(okashi_hito2))







Measured memory_bytes: 9456
k=int(input())
s=len(input())

def cmb(n,r,mod):
  if r<0 or n<r:
    return 0
  r=min(r,n-r)
  return g1[n]*g2[r]*g2[n-r]%mod

mod=10**9+7

g1=[1,1]#元table
g2=[1,1]#逆元table
inv=[0,1]#逆元table計算用

for i in range(2,k+s+1):
  g1.append(g1[-1]*i%mod)
  inv.append(-inv[mod%i]*(mod//i)%mod)
  g2.append(g2[-1]*inv[-1]%mod)

ans=1
for i in range(1,k+1):
  ans=(ans*26+cmb(i+s-1,s-1,mod)*pow(25,i,mod))%mod
print(ans)

Measured memory_bytes: 183740
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

# 01ナップサック問題
N,W = map(int,readline().split())
AB = [list(map(int,readline().split())) for i in range(N)]
AB.sort(key=lambda x: x[0])
dp = [0]*(W+1)

for (w,v) in AB:
    dpnew = dp[::]
    for j in range(W):
        dpnew[min(j+w,W)] = max(dp[min(j+w,W)],dp[j] + v)
    dp = dpnew

print(max(dp))


Measured memory_bytes: 75268
#include <bits/stdc++.h>
using namespace std;
string N;
int main()
{
    cin >> N;
    if (N[0] == N[1] && N[1] == N[2])cout << "Yes" << endl;
    else if (N[1] == N[2] && N[2] == N[3])cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
#define debug(x) cerr << #x << ":" << x << endl;

int main()
{
  int64 a, b, x;
  cin >> a >> b >> x;
  if (a == 0) {
    cout << b / x + 1 <<  endl;
    return 0;
  }
  int64 ans = (b) / x - (a - 1) / x;
  cout << ans << endl;
  return 0;
}


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

typedef vector<string> vs;
#define rep(i, n) for(int i = 0; i < (n); i++)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_h(const vector<T>& c, int n=INT_MAX)
{ rep(i, min(n, (int)c.size())) cout << c[i] << (i==c.size()-1?"\n":" "); }

int main()
{
    int H,W; cin >>H>>W;
    vs grid(H); cin >> grid;

    vector<vs> ans(2, vs(grid)); 

    rep(h, H) {
        rep(w, W) {
            if (grid[h][w]=='#') continue;
            if (w == 0) {
                ans[0][h][w]='#';
            } else if (w==W-1) {
                ans[1][h][w]='#';
            } else {
                ans[h%2][h][w]='#';
            }
        }
    }

    rep(i,2) {
        rep(j,H) cout<<ans[i][j]<<endl;
        if (i==0) cout<<endl;
    }
}


Measured memory_bytes: 1536
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  ll n;
  cin >> n;
  set<ll> st;
  for(ll x = 1; x <= 1000000; x++) {
    if(n - x >= 0 && (n - x) % x == 0) {
      ll m = (n - x) / x;
      if(x < m) {
        st.emplace(m);
      }
    }
  }
  for(ll m = 1; m <= 1000000; m++) {
    if(n % (m + 1) == 0) {
      ll x = n / (m + 1);
      if(x < m) {
        st.emplace(m);
      }
    }
  }
  ll ans = 0;
  for(auto e : st) ans += e;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
func main() {
    var line = readLine()!
    let words = ["dream", "dreamer", "erase", "eraser"]
    while true {
        let s = words.first(where: { (word) -> Bool in
            line.hasSuffix(word)
        })
        if let s = s {
            line.removeLast(s.count)
        } else {
            break
        }
    }
    if line.count == 0 {
        print("YES")
    } else {
        print("NO")
    }
}

main()


Measured memory_bytes: 7656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  ll H, N;
  cin >> H >> N;
  for (int i = 0; i < (int)N; ++i) {
    int A;
    cin >> A;
    H -= A;
  }

  cout << (H <= 0 ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RF(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define MIN3(a,b,c) (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c))
#define MAX(a,b) (a)>(b)?(a):(b)
#define MIN2(a,b) (a)<(b)?(a):(b)
using namespace std;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
#define ull unsigned long long
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;
#define deb(x )     cerr << #x << " here "<< x << endl;
#define endl    "\n"
#define printCase() "Case #" << caseNum << ": "
inline bool is_palindrome(const string& s){ return std::equal(s.begin(), s.end(), s.rbegin()); }
const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
inline void debug_vi(vi a) {F(i, 0, a.size()) cout<<a[i]<<" ";}
inline void debug_vll(vll a) {F(i, 0, a.size()) cout<<a[i]<<" ";}
/*----------------------------------------------------------------------*/

const int N = 1e4+5;
int digs[N],n,d;
ll dp[N][105][2];

ll solve(int ind, int sofar, bool flag) {
	sofar %= d;

	if(ind == n) {
		if(sofar) return 0;
		return 1LL;
	}

	if(dp[ind][sofar][flag] != -1) {
		return dp[ind][sofar][flag];
	}

	ll ret = 0;

	F(i, 0, digs[ind]) {
		ret += solve(ind + 1, (sofar + i), false);
		ret %= MOD;
	}

	ret += solve(ind+1, (sofar + digs[ind]), flag);
	ret %= MOD;

	if(!flag) {
		F(i, digs[ind]+1, 10) {
			ret += solve(ind+1, (sofar + i), flag);
			ret %= MOD;
		}
	}

	return dp[ind][sofar][flag] = ret;
}

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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    string k;
    cin>>k>>d;

    n = k.size();
    F(i, 0, n) {
    	digs[i] = k[i]-'0';
    }

    memset(dp, -1, sizeof(dp));
    ll ans = (solve(0, 0, true) - 1LL + MOD) % MOD;
    cout<<ans;

    return 0;
}/*

*/

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

typedef long long ll;
typedef pair<int, int> P;

const ll mod =  1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;   // INFの値は1152921504606846976

int main()
{
    int n,k;
    cin >> n >> k;
    int l = 0;
    int r = inf;
    rep(i,n){
        int a,b;
        cin >> a >> b;
        l = max(l,a);
        r = min(r,b);
    }
    if(l <= r){
        cout << r - l + 1 << endl;
    }else{
        cout << 0 << endl;
    }
}


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

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

Measured memory_bytes: 3668
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            var pList = new List<int>();
            pList.Add(2);
            pList.Add(3);
            bool isPrime = true;
            for (int i = 5; i < 55555; i += 2)
            {
                isPrime = true;
                for (int j = 3; j <= Math.Sqrt(i); j += 2)
                {
                    if (i % j == 0)
                    {
                        isPrime = false;
                        break;
                    }
                }
                if (isPrime) pList.Add(i);
            }
            var ans = new int[n];
            pList = pList.OrderByDescending(x => x).ToList();
            for (int i = 0; i < n; i++)
            {
                while(pList[0]%10 != 1)
                {
                    pList.RemoveAt(0);
                }
                ans[i] = pList[0];
                pList.RemoveAt(0);
            }
            Console.WriteLine(string.Join(" ", ans));
        }
    }
}

Measured memory_bytes: 11488
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func vi(n int, args ...int) []int {
	res := make([]int, n)
	if len(args) == 0 {
		return res
	}
	v := args[0]
	if v == 0 {
		return res
	}
	for i := 0; i < n; i++ {
		res[i] = v
	}
	return res
}

func vvi(n int, args ...int) [][]int {
	res := make([][]int, n)
	m := n
	if len(args) > 0 {
		m = args[0]
	}
	v := 0
	if len(args) > 1 {
		v = args[1]
	}
	for i := 0; i < n; i++ {
		res[i] = vi(m, v)
	}
	return res
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()
	n := readInt()
	if n%2 == 0 {
		println(n)
	} else {
		println(2 * n)
	}
}


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

using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define inf 1000000100
int n, m;
bool foundsquare(int y, int x, vector<string> a, vector<string> b)
{
    for(int i = y; i < y + m; i++)
    {
        for(int j = x; j < x + m; j++)
        {
            if(a[i][j] != b[i-y][j-x])
            {
                return false;
            }
        }
    }

    return true;
}


int main()
{
    cin >> n >> m;
    vector<string> a(n), b(m);
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for(int i = 0; i < m; i++)
    {
        cin >> b[i];
    }
    bool solve = 0;

    for(int i = 0; i <= n-m; i++)
    {
        for(int j = 0; j <= n-m; j++)
        {
            if(foundsquare(i, j, a, b))
            {
                solve = 1;
                break;
            }
        }
    }

    if(solve) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
using System;
using static System.Console;
using static System.Math;
using System.Numerics;
using System.Collections.Generic;
using System.Linq;


namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int num = myRead.readInt();
            var s = myRead.reatStr();
            var rn = 0;
            var r = 0;
            var w = 0;
            for (int i = 0; i < num; i++)
            {
                rn += (s[i] == 'R') ? 1 : 0;
            }
            for (int i = 0; i < num; i++)
            {
                if (i < rn)
                    w += (s[i] == 'W') ? 1 : 0;
                else
                    r += (s[i] == 'R') ? 1 : 0;
            }
            WriteLine(2 * w - r);
            Out.Flush();
        }
    }
    public static class myRead
    {
        public static int readInt() { return int.Parse(ReadLine()); }
        public static long readLong() { return long.Parse(ReadLine()); }
        public static string reatStr() { return ReadLine(); }
        public static int[] readIntArray() { return ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        public static long[] readLongArray() { return ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        public static string[] readStrArray() { return ReadLine().Split(' '); }
    }


    public static class MyMath
    {
        public static long Factorical(long n)
        { return n <= 1 ? 1L : n * Factorical(n - 1); }
        public static long Permutation(long n, long m)
        { return m == 0 ? 1L : (m == n) ? Permutation(n, m - 1) : n * Permutation(n - 1, m - 1); }
        public static long Combination(long n, long m)
        { return n - m > m ? Permutation(n, m) / Factorical(m) : Permutation(n, n - m) / Factorical(n - m); }
        public static long Gcd(long n, long m)
        { return n % m == 0 ? m : Gcd(m, n % m); }
        public static long Lcm(long n, long m)
        { return n * m / Gcd(n, m); }
        public static long Pow(long n, long m)
        { return (m == 1 || m == 0) ? 1L : n * Pow(n, m - 1); }
    }


}

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

int main(){
    int n; cin >> n;
    vector<int> d(n); rep(i,n) cin >> d.at(i);

    int s = d.size();
    sort(d.begin(),d.end());

    cout << d[(s-1)/2+1] - d[(s-1)/2] << endl;
}

Measured memory_bytes: 640
n = int(input())
rs = [list(map(int, input().split())) for _ in range(n)]
bs = sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: x[0])
flgs = [False for _ in range(n)]

ans = 0
for b in bs:
    bx, by = b
    ty = -1
    tid = -1
    for j in range(n):
        rx, ry = rs[j]
        if flgs[j]: continue
        if bx > rx and by > ry:
            if ty < ry:
                ty = ry
                tid = j
    if tid != -1:
        flgs[tid] = True
        ans += 1

print(ans)

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

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

	double ans = 0;
	rep(i, n){
		double p = 1;
		int x = i+1;
		while(x < k){
			p *= 0.5;
			x *= 2;
		}
		ans += p/n;
	}
	
	cout << fixed << setprecision(10) << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
n,k=map(int,input().split())
a=list(map(int,input().split()))
ap,an=[],[]
zeronum=0
for i in range(n):
  if a[i]>0:
    ap.append(a[i])
  elif a[i]<0:
    an.append(-a[i])
  else:
    zeronum+=1
np,nn=len(ap),len(an)
def fminus(x):
  j=0
  cnt=0
  for i in range(np):
    cnt+=j
    while j<nn and an[j]*ap[i]>=x:
      j+=1
      cnt+=1
  return cnt
def fplus(x,length,lis):
  r=length-1
  cnt=0
  for l in range(length):
    while lis[r]*lis[l]>x:
      if r==l:
        break
      r-=1
    if r==l:
      break
    elif lis[r]*lis[l]<=x:
      cnt+=r-l
  return cnt
if np*nn<k<=np*nn+zeronum*(zeronum-1)//2+zeronum*(np+nn):
  print(0)
else:
  #print(ap)
  #print(an)
  if k<=np*nn:
    an.sort(reverse=True)
    ap.sort()
    ng=10**18
    ok=0
    while ng-ok>1:
      mid=(ok+ng)//2
      if fminus(mid)>=k:
        ok=mid
      else:
        ng=mid
    print(-ok)
  else:
    an.sort()
    ap.sort()
    k-=np*nn+zeronum*(zeronum-1)//2+zeronum*(np+nn)
    #print(k)
    ok=10**18
    ng=0
    #print(ok,ng)
    while ok-ng>1:
      mid=(ok+ng)//2
      if fplus(mid,nn,an)+fplus(mid,np,ap)>=k:
        ok=mid
      else:
        ng=mid
    print(ok)

Measured memory_bytes: 89300
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
// #include <regex> //正規表現
using namespace std;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007ll
#define INF 1000000000
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
// グリッドグラフの移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int N, K, Q; cin >> N >> K >> Q;
VI A(Q), correct(N, 0); rep(i, 0, Q) cin >> A[i];

rep(i, 0, Q){
    ++correct[A[i]-1]; //正解数のカウント
}

// 不正解数は Q - correct[i]
rep(i, 0, N){
    if (K <= (Q - correct[i])) cout << "No\n";
    else cout << "Yes\n";
}

}

// 境界，出力文字列 チェック



Measured memory_bytes: 1408
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0
for i in range(A+1):
  for j in range(B+1):
    for k in range(C+1):
      if 500 * i + 100 * j + 50 * k == X:
        ans += 1
print(ans)

Measured memory_bytes: 9204
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,x,y;
  cin>>a>>b>>c>>x>>y;
  cout<<min({a*x+b*y,max(x,y)*2*c,(x<y?x*2*c+(y-x)*b:y*2*c+(x-y)*a)});
}

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

void read(int &x)
{
	char c=getchar(); x=0;
	while (c<'0'||c>'9') c=getchar();
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
}

const int maxn=3e5+10;

int n,m,Ans[maxn],vis[maxn];

int main()
{
	long long ST=clock();
#ifdef h10
	freopen("E.in","r",stdin);
	freopen("E.out","w",stdout);
#endif
	int i,j,l,r,x;
	read(n); read(m);
	for (i=1;i<=n;i++)
	{
		read(l); read(r);
		if (!l) {Ans[1]++; continue;}
		int last=m+1,len=r-l+1;
		Ans[1]++;
		Ans[len+1]--;
		for (x=1;x*x<=r;x++)
		{
			int u=(l+x-1)/x,v=r/x;
			u=max(u,len+1);
			if (v<=len) break;
			if (u<=v)
			{
				if (v<last) Ans[u]++,Ans[v+1]--;
				else Ans[u]++,Ans[last]--;
				last=u;
				for (j=u;j<=v&&j*j<=r&&vis[j]!=i;j++) vis[j]=i;
			}
		}
		for (x=len+1;x*x<=r;x++)
		{
			int u=(l+x-1)/x,v=r/x;
			if (u<=v&&vis[x]!=i)
				vis[x]=i,Ans[x]++,Ans[x+1]--;
		}
	}
	for (i=1;i<=m;i++)
		Ans[i]+=Ans[i-1],printf("%d\n",Ans[i]);
//	printf("using time = %lld\n",clock()-ST);
}



Measured memory_bytes: 1408
#include<bits/stdc++.h>
 using namespace std;
 
 int main(){
 	int k;
 	string s;
 	cin >> k >> s;
 	if(s.size()<=k){
 		cout << s << "\n";
 	}else{
 		for(int i=0;i<k;++i){
 			cout << s[i];
 		}cout << "...\n";
 	}
 	return 0;
 }

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

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(int argc, const char * argv[]) {
    
   
    
    string s; cin >> s;
    int ans = 0;
    for (int i = 0; i < 3; i++) {
        if(s[i]=='1') ans++;
    }
    
    cout << ans << endl;
    
}


Measured memory_bytes: 256