akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()



int main() {
  int n;
  cin >> n;
  vector<vector<int>> a(2, vector<int>(n));
  rep(i, 2) rep(j, n) cin >> a[i][j];
  
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int cnt = 0;
    for (int j = 0; j <= i; j++) {
      cnt += a[0][j];
    }
    for (int j = i; j < n; j++) {
      cnt += a[1][j];
    }
    ans = max(ans, cnt);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define Nlimit 100
#define Alimit 1000

int main()
{
  int N,A[Nlimit],i,v,j,k; 
  scanf("%d",&N);
  if(N>Nlimit)
    exit(1);
  for(i=0;i<N;i++)
    {
      scanf("%d",&A[i]);
      if(A[i]>Alimit)
	exit(2);
    }
  for(i=0;i<N;i++)
    {
      printf("%d",A[i]);
      if(i==N-1) break;
      printf(" ");
    }
  printf("\n");
  for(i=1;i<N;i++)
    {
      v=A[i];
      j=i-1;
      while(j>=0&&A[j]>v)
	{
	  A[j+1]=A[j];
	  j--;
	}
      A[j+1]=v;
      for(k=0;k<N;k++)
	{
	  printf("%d",A[k]);
	  if(k==N-1) break;
	  printf(" ");
	}
      printf("\n");
    }
  return 0;
}



Measured memory_bytes: 2140
#include <iostream>
#include <algorithm>
#include <cstring>
#include <map>
#include <stack>
#include <tuple>
#include <queue>
#include <vector>
#include <math.h>



#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define rREP(i, n) for(int (i) = (n) - 1; (i) >= 0; --(i))
#define ALL(TheArray) TheArray.begin(), TheArray.end()

using lli = long long int;
using pii = std::pair<int, int>;

template <class T> inline bool chmax(T& a, T b){
    if(a < b){a = b; return true;}
    return false;
}
template <class T> inline bool chmin(T& a, T b){
    if(a > b){a = b; return true;}
    return false;
}

using edge = std::vector<pii>;
std::vector<edge> Edge;
std::vector<lli> Dist;

 
int main(void){
    int n; scanf("%d", &n);
    Edge.resize(n, edge(0));
    REP(i, n-1){
        int u, v, d; scanf("%d%d%d", &u, &v, &d); u--; v--;
        Edge[u].push_back({v, d & 1});
        Edge[v].push_back({u, d & 1});
    }
    std::queue<int> Q; 
    Dist.resize(n, -1);
    Dist[0] = 0; Q.push(0);
    while(not Q.empty()){
        int V = Q.front(); Q.pop();
        for(pii eg : Edge[V]) if(Dist[eg.first] == -1) {
            Dist[eg.first] = Dist[V] + eg.second;
            Q.push(eg.first);
        }
    }
    REP(i, n) puts((Dist[i] & 1) ? "1" : "0");

    return 0;
}

Measured memory_bytes: 7168
#include <stdio.h>

int main(){
  int i, j, k, l;
  int num;
  int count = 0;
  int res;

  while(1){
  res = scanf("%d", &num);

  if(res == EOF) break;

  if(num <= 36){
    for(i = 0 ; i <= 9 ; i++){
      for(j = 0 ; j <= 9 ; j++){
        for(k = 0 ; k <= 9 ; k++){
          for(l = 0 ; l <= 9 ; l++){
            if(i + j + k + l == num){
              count++;
	    }
          }
        }
      }
    }
  }

  printf("%d\n", count);
  count = 0;
  }
  return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

template <typename T>
struct edge {
    int from, to;
    T cost;

    edge(int to, T cost) : from(-1), to(to), cost(cost) {}
    edge(int from, int to, T cost) : from(from), to(to), cost(cost) {}

    explicit operator int() const {return to;}
};

template <typename T>
vector<T> dijkstra(int s,vector<vector<edge<T>> > &G){
    int n=G.size();
    const T INF = numeric_limits<T>::max();
    using P = pair<T, int>;
    vector<T> d(n, INF);
    vector<int> b(n,-1);
    priority_queue<P,vector<P>,greater<> > Q;
    d[s]=0;
    Q.emplace(d[s],s);
    while(!Q.empty()){
        T cost;
        int i;
        tie(cost, i) = Q.top(); Q.pop();
        if(d[i] < cost) continue;
        for (auto &&e : G[i]) {
            auto cost2 = cost + e.cost;
            if(d[e.to] <= cost2) continue;
            d[e.to] = cost2;
            Q.emplace(d[e.to], e.to);
        }
    }
    return d;
}

int main() {
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    vector<vector<edge<ll>>> vy(n), vs(n);
    for (int i = 0; i < m; ++i) {
        ll u, v, a, b;
        scanf("%lld %lld %lld %lld", &u, &v, &a, &b);
        vy[u-1].emplace_back(v-1, a);
        vy[v-1].emplace_back(u-1, a);
        vs[u-1].emplace_back(v-1, b);
        vs[v-1].emplace_back(u-1, b);
    }
    vector<ll> cy = dijkstra(s-1, vy), cs = dijkstra(t-1, vs);
    for (int i = 0; i < n; ++i) {
        cy[i] += cs[i];
    }
    for (int i = n-2; i >= 0; --i) {
        cy[i] = min(cy[i], cy[i+1]);
    }
    for (int i = 0; i < n; ++i) {
        printf("%lld\n", 1000000000000000-cy[i]);
    }
    return 0;
}


Measured memory_bytes: 18684
from collections import deque
from bisect import bisect_right
INFTY = 10**6
N,M = map(int,input().split())
S = input().strip()
dp = [INFTY for _ in range(N+1)]
dp[N]=0
A = deque([])
B = {}
pre = N
flag = 0
for i in range(N-1,-1,-1):
    if S[i]=="0":
        ind = bisect_right(A,i+M)
        if ind>0:
            dp[i] = dp[A[ind-1]]+1
            B[i] = A[ind-1]
            if dp[i]>dp[pre]:
                A.appendleft(pre)
        else:
            if pre<=i+M:
                dp[i]=dp[pre]+1
                B[i] = pre
                A.appendleft(pre)
            else:
                flag = 1
                break
        pre = i
if flag==0:
    P = []
    k = 0
    while k<N:
        P.append(B[k]-k)
        k = B[k]
    print(*P)
else:
    print(-1)

Measured memory_bytes: 97936
def comb(n, k, mod):
    if k > (n // 2):
        k = n - k
    a = 1
    for i in range(k):
        a = (a * (n - i)) % mod
    b = 1
    for i in range(k - 1):
        b = (b *(k - i)) % mod
    a = (a * pow(b, mod - 2, mod)) % mod
    return a


X, Y = map(int, input().split())
ans = 0
mod = 10 ** 9 + 7
if X > Y:
    X, Y = Y, X
##Yのほうが大きいとして考える
if not (X + Y) % 3 == 0 or Y > 2 * X:
    ans = 0
else:
    n = (X + Y) // 3
    d = Y - X
    a = 2*n - X
    ans = comb(n, a, mod)
print(ans)


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

typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))
#define min3(x, y, z) min(x, min(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif

using namespace std;
int main() {
  string a,b;
  cin >> a >> b;
  rep(i, a.length()) {
    if (a[i] != b[i]) {
      cout << "No";
      return 0;
    }
  }
  if (a.length() + 1 != b.length()) {
    cout << "No";
    return 0;
  }
  cout << "Yes";
  return 0;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
rep(i,N) {
  cin >> list[i];
}
//配列(スタックとしても使える)
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
//ソート クイックだからO(NlogN)
sort(all(list));
sort(all(list), greater<int>());

//配列の最小最大(Nは要素数)
*min_element(all(c))
*max_element(all(c))

//a[0]からa[N]を逆順にする(計算量はO(N))
reverse(all(a));
//listの末尾に要素を追加
list.push_back(10);
//listの末尾から要素を削除
list.pop_back();
//空ですか？
list.empty()



//キュー(待ち行列)
//定義
queue<int> a;
//追加
a.push(x);
//取る
a.pop();
//チェック
a.front()
//サイズ
a.size()
//空ですか
a.empty()



//優先度付きキュー※全部計算量がO(NlogN)あるので注意
// int 型の要素を持ち、最も小さい値を取り出す形の priority_queue を定義
priority_queue<int, vector<int>, greater<int>> Q1;
// double 型の要素を持ち、最も大きい値を取り出す形の priority_queueを定義
priority_queue<double, vector<double>, less<double>> Q2;
//追加
a.push(x);
//取る
a.pop();
//一番小さいの教えて下さい
a.top()
//サイズ
a.size()
//空ですか
a.empty()



//配列の内容表示
dout << "====listの内容====\n";
for (int edp = 0; edp < N; edp++) dout << list[edp] << endl;
dout << "====ここまで====\n";



//部分文字列
//添字3から5文字
s.substr(3,5)
//添字3から全部
s.substr(3)

//入れ替え
swap(a,b);


*/


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
vector<vector<int>> graph(2*1e5);
vector<bool> visited(2*1e5);
vector<long long int> num(2);
 
void DFS(int v){
    if(visited[v] == true) return ;
 
    visited[v] = true;
    if(v < 1e5) num[0] += 1;
    else        num[1] += 1;
    for(int next_v : graph[v]) DFS(next_v);
}
 
int main(){
    int n;
    cin >> n;
 
    for(int i=0; i<n; i++){
        int x, y;
        cin >> x >> y;
        x -= 1;
        y -= 1;
        y += 1e5;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
 
    long long int ans = 0;
    for(int v=0; v<1e5; v++){
        if(visited[v] == true) continue;
        num.assign(2, 0);
        DFS(v);
        ans += num[0] * num[1];
    }
    cout << ans - n << endl;
    return 0;
}


Measured memory_bytes: 12800
import sys

def main():

	input = sys.stdin.readline

	N = int(input().strip())
	P = list(map(int,input().strip().split()))

	RR = [i+1 for i in range(N)]
	LL = [i-1 for i in range(N)]
	ips = [0]*(N)
	for i, val in enumerate(P):
		ips[val-1] = i
	P.sort()

	x = 0
	for i in range(N):
		target = ips[P[i]-1]
		R1ind = RR[target]
		R2ind = RR[ min(R1ind,N-1) ]
		L1ind = LL[target]
		L2ind = LL[ max(L1ind,0) ]

		x += ((L1ind-L2ind)*(R1ind-target) + (target-L1ind)*(R2ind-R1ind))*P[i]

		if L1ind!=-1:
			RR[L1ind] = R1ind
		if R1ind!=N:
			LL[R1ind] = L1ind

	print(x)

if __name__ == "__main__":
    main()


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

typedef pair<int, int> Pii;

void readint(int N, vector<int> &a);
void readdouble(int N, vector<double> &a);
void readindex(int N, vector<int> &a);



signed main(){

    int A, B;
    cin >> A >> B;

    int h = 100, w = 100;

    vector<vector<char> > s(h, vector<char>(w));

    FOR(i, 0, h / 2){
        REP(j, w){
            s[i][j] = '#';
        }
    }
    FOR(i, h / 2, h){
        REP(j, w){
            s[i][j] = '.';
        }
    }

    A--;
    B--;

    REP(i, h / 4){
        if(A == 0) break;
        REP(j, w / 2){
            if(A == 0) break;
            s[2 * i][2 * j] = '.';
            A--;
        }
    }

    REP(i, h / 4){
        if(B == 0) break;
        REP(j, w / 2){
            if(B == 0) break;
            s[2 * i + h / 2 + 1][2 * j] = '#';
            B--;
        }
    }

    cout << h << " " << w << endl;
    REP(i, h){
        REP(j, w){
            cout << s[i][j];
        }
        if(i != h - 1) cout << endl;
    }

    
    return 0;
}








void readint(int N, vector<int> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atoi(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atoi(s.c_str());
}
void readdouble(int N, vector<double> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atof(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atof(s.c_str());
}
void readindex(int N, vector<int> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atoi(s.c_str()) - 1;
    }
    getline(cin, s, '\n');
    a[N - 1] = atoi(s.c_str()) - 1;
}

Measured memory_bytes: 256
s=input()
d=[0]*(len(s)+1)
Z=[]
scount=0
ans=0

if s[0]=="<":
  d[1]=d[0]+1
for i in range(1,len(s)-1):
  if s[i]==">":
    d[i+1]=0
    scount+=1
    Q=scount
    X=i
    if s[i-1]=="<":
      Z.append(i)
  elif s[i]=="<":
    d[i+1]=d[i]+1
    for j in range(scount):
      d[i-scount+j]=(scount-j)
    scount=0

if s[-1]==">":
  d[-1]=0
  scount+=1
  Q=scount
  X=len(s)-1    
if scount>0:
  for j in range(scount):
    d[X-scount+j+1]=Q
    Q-=1
for i in Z:
  d[i]=max(d[i+1]+1,d[i-1]+1)
  if i==0 and s[0]=="<":
    d[i]=0
if s[-1]=="<":
  d[-1]=d[-2]+1
if s[0]==">":
  d[0]=d[1]+1

print(sum(d))

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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/
int main(){
    int n;cin>>n;
    bool three=true;
    rep(i,n){
        char tmp;
        cin>>tmp;
        if(tmp=='Y')three=false;
    }
    cout<<(three?"Three":"Four")<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
ll d1[8] = {1, -1, 0, 0, 1, 1, -1, -1};
ll d2[8] = {0, 0, 1, -1, 1, -1, 1, -1};
 
int main(){
    ll H, W;
    cin >> H >> W;
    VS s(H);
    rep(i, 0, H) cin >> s[i];
    rep(h, 0, H){
        rep(w, 0, W){
            if(s[h][w] == '#') continue;
            char cnt = '0';
            rep(i, 0, 8){
                ll nh = h + d1[i];
                ll nw = w + d2[i];
                if(nh < 0 || nw < 0 || nh >= H || nw >= W) continue;
                if(s[nh][nw] == '#') cnt++;
            }
            s[h][w] = cnt;
        }
    }
 
    rep(h, 0, H) cout << s[h] << endl;
    return 0;
}

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

int main() {
    int a, b;
    cin >> a >> b;

    // printf("%d %d %.5f\n", a/b, a%b, (double)a / b);
    cout << a / b << " " << a % b << " " << fixed << setprecision(5) << (double)a / b << endl;

    return 0;
}


Measured memory_bytes: 3284
import itertools
a,b,c,d,e,f = [int(_) for _ in input().split()]

water = []
i = 0
while True:
    j = 0
    if i * 100 * a + j * 100 * b > f:
        break
    while True:
        if i == 0 and j == 0:
            j += 1
            continue
        if i * 100 * a + j * 100 * b > f:
            break
        water.append(i * 100 * a + j * 100 * b)
        j += 1
    i += 1
set_water = sorted(set(water))

sugar = []
i = 0
while True:
    j = 0
    if i * c + j * d > f * e // 100:
        break
    while True:
        if i == 0 and j == 0:
            j += 1
            continue
        if i * c + j * d > f * e // 100:
            break
        sugar.append(i * c + j * d)
        j += 1
    i += 1
set_sugar = sorted(set(sugar))

most_dense = 0
final_total = 0
final_sugar = 0
for i, j in itertools.product(range(0,len(set_water)), range(0, len(set_sugar))):
    density = set_sugar[j] / (set_water[i] + set_sugar[j])
    if density > most_dense and set_water[i] * e // 100 >= set_sugar[j] and set_water[i] + set_sugar[j] <= f:
        most_dense = density
        final_total = set_water[i]+set_sugar[j]
        final_sugar = set_sugar[j]

if final_total == 0:
    final_total = a * 100
print(final_total, final_sugar)

Measured memory_bytes: 12520
using System;

namespace ConsoleApp_ITP1_5_B
{
    class Program
    {
        static void Main(string[] args)
        {
            for (; ; )
            {
                string[] input = Console.ReadLine().Split(' ');
                var h = Int32.Parse(input[0]);
                var w = Int32.Parse(input[1]);

                if (h == 0 && w == 0) break;
                else
                {
                    for (int j = 1; j <= h; j++)
                    {
                        for (int i = 1; i <= w; i++)
                        {
                            if (j == 1 || j == h)
                                Console.Write("#");
                            else
                            {
                                if (i == 1 || i == w)
                                    Console.Write("#");
                                else
                                    Console.Write(".");
                            }
                        }
                        Console.WriteLine();
                    }
                }
                Console.WriteLine();
            }
        }
    }
}


Measured memory_bytes: 8984
#include<bits/stdc++.h>
using namespace std;
#define forn(i, n)             for(int i = 0; i < n; i ++)
#define forn1(i, n)            for(long long int i = 1; i <= n; i ++)
#define loop(i, sta, end, inc) for(int i = sta; i <= end; i += inc)
#define itr(it, l)             for(auto it = l.begin(); it != l.end(); it ++)
#define in(a, b, c)            assert( b <= a && a <= c)
#define pb push_back
#define ll long long int
#define fi first
#define se second
#define ii  pair<long long int, long long int>
#define vi  vector <long long int>
#define vii vector <pair <long long int, long long int > >
#define all(cont)  cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define what_is(x) cerr<<#x<<" ="<<x<<" ";
#define error(args...)  { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define LINT_MAX  9223372036854775807
#define LINT_MIN -9223372036854775808
#define EPS 1e-9
#define MOD 1000000007
#define DEBUG 0

template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
void err(istream_iterator<string> it) { cerr<<endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    if(DEBUG == 0)return;
  cerr << *it << " = " << a <<" ";
  err(++it, args...);
}

ll dp[100][100001];
ll A[100][2];

int main(){
  //freopen("test.txt","r",stdin);
  ll n,w;cin>>n>>w;
  forn(i,n)cin>>A[i][0]>>A[i][1];
  forn1(i,w){
    if(A[0][0]>i)dp[0][i]=0;
    else dp[0][i]=A[0][1];
  }
  forn1(i,n-1){
    forn1(j,w){
      if(A[i][0]>j)dp[i][j]=dp[i-1][j];
      else {dp[i][j]=max(dp[i-1][j],(dp[i-1][j-A[i][0]]+A[i][1]));}
    }

  }
  /*forn(i,n){
    forn(j,w+1){
      cout<<dp[i][j]<<" ";
    }cout<<endl;
  }*/
  cout<<dp[n-1][w]<<endl;

}


Measured memory_bytes: 78336
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long ll;
int main() {
  int n, a;
  cin >> n;
  set<int> s;
  rep(i,n)
  {
    cin >> a;
    s.insert(a);
  }
  cout << s.size();
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) std::memset(arg,n,sizeof(arg))
#define mp std::make_pair
#define pb push_back
using std::cin;
typedef long long ll;
typedef std::pair<int,int> pi;
typedef std::pair<ll,ll> pll;
typedef std::pair<ll,pll> plll;
typedef std::vector<int> vi;
typedef std::set<int> si;
typedef std::string str;
const int INF=1e+9;
const ll INFLL=1e+17;
const ll MOD=1e+9+7;
int N;
ll X;
ll B[100010],L[100010],U[100010];
plll p[100010];
bool comp1(plll& a,plll& b){
  ll ab=a.first,al=a.second.first,au=a.second.second;
  ll bb=b.first,bl=b.second.first,bu=b.second.second;  
  return (X-ab)*au+ab*al>(X-bb)*bu+bb*bl;
}
bool C(ll mid){
  ll q=mid/X,r=mid%X;
  ll tkhs=0,aok=0;
  for(ll i=0;i<q;i++){
    ll b=p[i].first,u=p[i].second.second;
    tkhs+=u*X;aok+=u*b;
  }
  for(ll i=q;i<N;i++){
    ll b=p[i].first,l=p[i].second.first;
    aok+=l*b;
  }
  bool f=false;
  ll bq=p[q].first,lq=p[q].second.first,uq=p[q].second.second;
  for(ll i=0;i<N;i++){
    ll b=p[i].first,l=p[i].second.first,u=p[i].second.second;
    if(i<q){
      if(r>=b){
	if(tkhs-u*(X-r)+uq*X>=aok+(uq-lq)*bq){
	  f=true;
	  break;
	}
      }
      else{
	if(tkhs+l*r-u*X+uq*X>=aok+b*(l-u)+(uq-lq)*bq){
	  f=true;
	  break;
	}
      }
    }
    else{
      if(r>=b){
	if(tkhs+r*u>=aok+(u-l)*b){
	  f=true;
	  break;
	}
      }
      else{
	if(tkhs+r*l>=aok){
	  f=true;
	  break;
	}
      }
    }
  }
  return f;
}
ll upper(ll l,ll r){//条件を満たす中で最小のものを返す
  ll lb=l-1,ub=r+1;
  while(ub-lb>1){
    ll mid=(lb+ub)/2;
    if(C(mid)) ub=mid;
    else lb=mid;
  }
  return ub;
}


int main(){
  cin>>N>>X;
  ll sum=0;
  rep(i,N){
    cin>>B[i]>>L[i]>>U[i];
    sum+=B[i];
  }
  rep(i,N){
    p[i]=mp(B[i],mp(L[i],U[i]));
  }
  std::sort(p,p+N,comp1);
  ll res=upper(0,sum-1);
  prin(res);
  
  return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 200005
#define eps 1e-10
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
	res = 0;T f = 1;char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-') f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9') {
		res = res * 10 + c - '0';
		c = getchar();
	}
	res *= f;
}
template<class T>
void out(T x) {
	if(x < 0) {x = -x;putchar('-');}
	if(x >= 10) {
		out(x / 10);
	}
	putchar('0' + x % 10);
}
const int MOD = 1000000007;
int inc(int a,int b) {
	return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
	return 1LL * a * b % MOD;
}
int fpow(int x,int c) {
	int res = 1,t = x;
	while(c) {
		if(c & 1) res = mul(res,t);
		t = mul(t,t);
		c >>= 1;
	}
	return res;
}
int N,st[2],ed[2];
char s[5005],t[5005];
vector<int> a,b;
void Init() {
	read(N);
	scanf("%s%s",s + 1,t + 1);
	for(int i = 1 ; i <= 10010 ; ++i) {
		a.pb(0);b.pb(0);
	}
	if(s[1] == '0') a.pb(0);
	if(t[1] == '0') b.pb(0);
	st[0] = a.size() - 1;st[1] = b.size() - 1;
	for(int i = 1 ; i < N ; ++i) {
		if(s[i] != s[i + 1]) a.pb(i);
		if(t[i] != t[i + 1]) b.pb(i);
	}
	ed[1] = b.size();
	for(int i = 1 ; i <= 10010 ; ++i) {
		a.pb(N);b.pb(N);
	}
}
void Solve() {
	int p = st[0] - 2,q = ed[1] + 2;
	if((p & 1) != (q & 1)) ++q;
	int ans = N * N;
	while(q >= st[1] - N - 2) {
		int t0 = p + 1,t1 = q + 1;
		int res = abs(a[p] - b[q]);
		while(a[t0] != N || b[t1] != N) {
			res += abs(a[t0] - b[t1]);
			++t0;++t1;
		}
		t0 = p - 1,t1 = q - 1;
		while(a[t0] != 0 || b[t1] != 0) {
			res += abs(a[t0] - b[t1]);
			--t0;--t1;
		}
		ans = min(ans,res);
		q -= 2;
	}
	out(ans);enter;
}
int main() {
#ifdef ivorysi
	freopen("f1.in","r",stdin);
#endif
	Init();
	Solve();
}


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

int main(){
	int n,d,x;
	cin >> n >> d >> x;
	int a[n];
	REP(i,n) cin >> a[i];
	int sum = 0;
	REP(i,n){
		if(d % a[i] == 0) sum += d / a[i];
		else sum += d / a[i] + 1;
	}
	cout << sum + x << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
int nton[256];
int ston[256];
int point[4][13];
int rate[9];

int calc(vector<pair<int, int> > &a){
	int s[5], n[5];
	for(int i=0; i<5; i++){
		s[i] = a[i].second;
		n[i] = a[i].first;
	}
	bool samesuit = false;
	if(s[0]==s[1] && s[0]==s[2] && s[0]==s[3] && s[0]==s[4]){
		samesuit = true;
	}
	bool rstraight = false;
	bool straight = false;
	if(0 <= n[0] && n[0] <= 8){
		bool succ = true;
		for(int i=0; i<4; i++){
			if((n[i]+1)%13 != n[i+1]%13) succ = false;
		}
		if(succ){
			straight = true;
		}
	}
	if(n[0]==0 && n[1]==9 && n[2]==10 && n[3]==11 && n[4]==12) rstraight = true;
	if(samesuit && rstraight) return rate[8];
	if(samesuit && straight) return rate[7];
	if(straight || rstraight) return rate[3];
	if(samesuit) return rate[4];
	
	int pair1=0, pair2=0;
	for(int i=0; i<5; i++){
		int lim = 1;
		while(i+lim<5 && n[i]==n[i+lim]) lim++;
		if(lim>1){
			if(pair1!=0){
				pair2 = lim;
			}else{
				pair1 = lim;
			}
			i += lim-1;
		}
	}
	if(pair1 == 4) return rate[6];
	if(pair1 == 2 && pair2 == 3) return rate[5];
	if(pair1 == 3 && pair2 == 2) return rate[5];
	if(pair1 == 3) return rate[2];
	if(pair2 == 2) return rate[1];
	if(pair1 == 2) return rate[0];
	return 0;
}

int main(){
	for(int i=0; i<256; i++){
		nton[i] = i-'1';
	}
	nton['A'] = 0;
	nton['T'] = 9;
	nton['J'] = 10;
	nton['Q'] = 11;
	nton['K'] = 12;
	ston['S'] = 0;
	ston['C'] = 1;
	ston['H'] = 2;
	ston['D'] = 3;
	
	bool first = true;
	int n;
	while(cin >> n){
		if(!first){
			cout << endl;
		}else{
			first = false;
		}
		
		for(int i=0; i<4; i++){
			for(int j=0; j<13; j++){
				cin >> point[i][j];
			}
		}
		for(int i=0; i<9; i++){
			cin >> rate[i];
		}
		
		for(int i=0; i<n; i++){
			vector<pair<int, int> > a(5);
			int psum = 0;
			for(int j=0; j<5; j++){
				string s;
				cin >> s;
				a[j].first = nton[(int)s[0]];
				a[j].second = ston[(int)s[1]];
				psum += point[a[j].second][a[j].first];
			}
			sort(a.begin(), a.end());
			cout << psum *calc(a) << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3016
import java.util.Scanner;
public class Main{
    public static void main(String[]args){
        Scanner scan = new Scanner(System.in);
        int n,con,sum;
        con=1;
        sum=0;
        n=scan.nextInt();
        for(int i=0;i<n;i++){
            if(con==scan.nextInt()){
                con+=1;
            }
            else sum+=1;
        }
        if(con==1) System.out.println("-1");
        else System.out.println(sum);
    }
}

Measured memory_bytes: 63096
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    S = readline().strip()

    ans = 1
    for i in range(N - 1):
        if S[i] != S[i + 1]:
            ans += 1

    print(ans)
    return


if __name__ == '__main__':
    main()


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

#define rep(i, n) for(int i = 0; i < (n); ++i)

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

int main(){
    ll a, b, x;
    cin >> a >> b >> x;
    
    ll ans = 0;
    if (a > 0) {
        ans = b / x - (a - 1) / x;
    } else {
        ans = b / x + 1;
    }

    cout << ans << endl;
}

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

class Node{
public:
	int data;
	Node* Prev;
	Node* Next;
	Node(int x){
		data = x;
	}
};

class List{
private:
	Node* head;
public:
	List(){
		head = new Node(0);
		head->Next = head;
		head->Prev = head;
	}
	void Insert(int x){
		Node* p = new Node(x);
		p->Next = head->Next;
		p->Prev = head;
		head->Next = p;
		p->Next->Prev = p;
	}
	void Delete(int x){
		for(Node* p = head->Next;p != head; p = p->Next){
			if(p->data == x){
				p->Prev->Next = p->Next;
				p->Next->Prev = p->Prev;
				delete p;
				break;
			}
		}
	}
	void DeleteFirst(){
		Node* p = head->Next;
		p->Prev->Next = p->Next;
		p->Next->Prev = p->Prev;
		delete p;
	}
	void DeleteLast(){
		Node* p = head->Prev;
		p->Prev->Next = p->Next;
		p->Next->Prev = p->Prev;
		delete p;
	}
	void Show(){
		for(Node* p = head->Next;p != head; p = p->Next){
			cout << p->data;
			if(p->Next != head){
				cout << ' ';
			}
		}
		cout << endl;
	}
	~List(){
		Node* p = head->Next;
		while (p != head){
			Node* tmp = p;
			p = p->Next;
			delete tmp;
		}
		delete p;
	}	
};

int main(){
	int n;
	List list;
	cin >> n;
	for(int i = 0;i < n;i++){
		char str[16];
		cin >> str;
		if(str[0] == 'i'){
			int x;
			cin >> x;
			list.Insert(x);
		}
		else if(str[0] == 'd'){
			if(str[6] == 'F'){
				list.DeleteFirst();
			}
			else if(str[6] == 'L'){
				list.DeleteLast();
			}
			else{
				int x;
				cin >> x;
				list.Delete(x);
			}
		}
	}
	list.Show();
	return 0;
}


Measured memory_bytes: 32444
#include <stdio.h>

#define MAX 100

int main(){

    int A[MAX],N;
    int key;
    int i=0,j,k;

    scanf("%d",&N);

    while(i < N){
        scanf("%d",&A[i]);
        i++;
    }

    k = 0;
    while(k < (N -1)){
        printf("%d ",A[k]);
        k++;    
    }
    printf("%d\n",A[N-1]);

    // scanf("%d %d %d %d %d %d",&A[0],&A[1],&A[2],&A[3],&A[4],&A[5]);
    // printf("%d %d %d %d %d %d\n",A[0],A[1],A[2],A[3],A[4],A[5]);

    for(i=1; i<=(N-1);i++){
        key = A[i];
        
        /* insert A[i] into the sorted sequence A[0,...,i-1] */
        j = i - 1;
        while((j >= 0) & (A[j] > key)){
            A[j+1] = A[j];
            // printf("   j:A[j]:A[j+1] = %d,%d,%d\n",j,A[j],A[j+1]);
            j--;
        }

        A[j+1] = key;
        // printf("** j:A[j]:A[j+1] = %d,%d,%d\n",j,A[j],A[j+1]);
        
        /* output intermediate sequence for each step */
        k = 0;
        while(k < (N -1)){
            printf("%d ",A[k]);
            k++;    
        }
        printf("%d\n",A[N-1]);

    }

    // i = 0;
    // while(i < N){
    //     printf("%d ",A[i]);
    //     i++;    
    // }
    // printf("\n");

    return 0;

}


Measured memory_bytes: 2080
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <tuple>
#include <cmath>
using namespace std;
using Int = long long;
#define REP(i,n) for(decltype(n) i=0;i<n;i++)
#define FOR(i,n,m) for(decltype(n) i=n;i<m;i++)
int main()
{
    Int X, Y; cin >> X >> Y;
    Int T = X;
    int i = 0;
    for (i = 0; T <= Y; T *= 2, i++) {}
    cout << i << endl;
    return 0;
}

Measured memory_bytes: 256
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000


a = int(input())
b = int(input())
h = int(input())

print((a+b)*h//2)


Measured memory_bytes: 6604
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
         
        int odd = 0;
        for (int i=1; i<=n; i++) if (i % 2 == 1) odd++;
        
        double result = (double)odd / n;
        
        System.out.println(result);
    }
}


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

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

int L, K;
int memo[2][110];

int dfs(int kind, int len) {
    if (memo[kind][len] != -1) return memo[kind][len];
    int ret = 0;

    if (len == 0) {
	ret = 0;
    } else {
	if (kind == 1) ret = dfs(0, len - 1);
	else {
	    ret = dfs(1, len - 1) + 1;
	    if (len >= K) ret += dfs(1, len - K) + 1;
	}
    }

    memo[kind][len] = ret;
    return ret;
}

signed main() {
    cin >> L >> K;

    rep(i, 2) rep(j, 110) memo[i][j] = -1;

    cout << dfs(0, L) << endl;

    return 0;
}

Measured memory_bytes: 3120
fun main(args : Array<String>) {
    // 5000000000000000
    // 1000000000000000000
    // a number except 1 is exponencially going to grow.
    // n^5000000000000000 is enough bigger than max(K)
    // so, when there is a first number(that is not 1), the string will be like 111XXXXXXXXXXXXXXXXX(continues...almost inifinitly)

    val S = readLine()!!
    val K = readLine()!!.toLong()

    val index = S.indexOfFirst {
        it != '1'
    }
    if (index == -1) {
        println(S[0])
        return
    }

    if ((K-1) >= index) {
        println(S[index])
    } else {
        println(1)
    }
}

Measured memory_bytes: 31940
n, k = map(int, input().split())

MOD = 10**9 + 7
MAX = 2 * n + 1
fact = [1] * (MAX + 1)  # i!
finv = [1] * (MAX + 1)  # (i!)^{-1}
iinv = [1] * (MAX + 1)  # i^{-1}

for i in range(2, MAX + 1):
    fact[i] = fact[i - 1] * i % MOD
    iinv[i] = MOD - iinv[MOD % i] * (MOD // i) % MOD
    finv[i] = finv[i - 1] * iinv[i] % MOD


def comb(n: int, k: int) -> int:
    if n < k or n < 0 or k < 0:
        return 0
    return (fact[n] * finv[k] % MOD) * finv[n - k] % MOD


if k >= n - 1:
    ans = comb(n + (n - 1), n - 1)
else:
    ans = 0
    for i in range(k + 1):
        ans += (comb(n, i) * comb(n - 1, i)) % MOD
        ans %= MOD

print(ans)


Measured memory_bytes: 50468
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    vector<int> v;
    cin >> n;
    n *= 2;
    v.resize(n);
    for(int i = 0; i < n; ++i) cin >> v[i];
    sort(v.begin(), v.end());
    int ans = 0;
    for(int i = 0; i < n; ++i) if(i % 2 == 0) ans += v[i];
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define REP(i, n) for(LL i=0; i<(n); i++)
#define FOR(i, m, n) for(LL i=(m);i<(n);i++)
#define SZ(x) ((int)(x).size())
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define MP make_pair
#define PB push_back
#define INF INT_MAX

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	LL n, m;
	cin >> n >> m;
	cout << 1900 * m*(int)pow(2, m) + 100 * (n - m)*(int)pow(2, m) << endl;
}

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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MIN(a, b) ((a) < (b) ? (a) : (b))


int main(void){
    int N;
    scanf("%d",&N);

    //A[0]~A[N]に格納
    int* A;
    NEW(A,N+1);
    for(int i=0;i<=N;i++){
        scanf("%d",&A[i]);
    }
    //B[0]~B[N-1]に格納する
    int* B;
    NEW(B,N);
    for(int i=0;i<N;i++){
        scanf("%d",&B[i]);
    }

    long ans=0;
    //i番目の勇者が倒す数
    for(int i=0;i<N;i++){
        //i番目の勇者がi番目の街で倒す数
        if(A[i]>=B[i]){
            ans+=B[i];
            A[i]-=B[i];
            B[i]=0;
        }
        else{
            ans+=A[i];
            B[i]-=A[i];
            A[i]=0;
        }
        //i番目の勇者がi+1番目の街で倒す数
        if(A[i+1]>=B[i]){
            ans+=B[i];
            A[i+1]-=B[i];
            B[i]=0;
        }
        else{
            ans+=A[i+1];
            B[i]-=A[i+1];
            A[i+1]=0;
        }
    }

    printf("%ld\n",ans);

    return 0;
}

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

int main(){
  int a,b,c,d;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  if(abs(c-a)<=d){
    puts("Yes");
    return 0;
  }
  else if(abs(b-a)<=d && abs(c-b)<=d){
    puts("Yes");
    return 0;
  }
  puts("No");


  return 0;
}

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

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;
}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define INF 999999999

    /*Solve*/

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int ans = a*b/2;
    cout << ans;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int count = 0;
		for(int i = a;i < b + 1;i++)
		{
			if(c % i == 0)
			{
				count++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 17328
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define ZERO (1e-10)
#define INF int(1e9+1)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define DEB printf("DEB!\n");
#define D(X) cout<<"  "<<#X": "<<X<<endl;
#define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
#define IN(n) int n;scanf("%d",&n);
#define FOR(i, m, n) for (int i(m); i < n; i++)
#define F(n) FOR(i,0,n)
#define FF(n) FOR(j,0,n)
#define FT(m, n) FOR(k, m, n)
#define aa first
#define bb second
void ga(int N,int *A){F(N)scanf("%d",A+i);}
#define MX 111111
struct DSU{
    int C[MX],R[MX],W;
    int gc(int a){return C[a]=(a==C[a]?a:gc(C[a]));}
    bool con(int a,int b){
        if(gc(a)==gc(b))return 0;
        R[C[a]]+=R[gc(b)],C[C[b]]=C[a];
        return --W,1;
    }
    void CLR(int N){(iota(C,C+N,0),fill(R,R+N,1),W=N);}
}X,Y;
ll S;
int N,a,b;
vi U[MX],V[MX],u[MX],v[MX];
void sc(vi&a){sort(a.begin(),a.end()),a.resize(unique(a.begin(),a.end())-a.begin());}
int main(void){
    scanf("%d",&N),X.CLR(MX),Y.CLR(MX);
    F(N)scanf("%d%d",&a,&b),U[a].PB(b),V[b].PB(a);
    F(MX){
        FF(int(U[i].size())-1)Y.con(U[i][j],U[i][j+1]);
        FF(int(V[i].size())-1)X.con(V[i][j],V[i][j+1]);
    }
    F(MX){
        for(auto&h:U[i])u[X.gc(i)].PB(h);
        for(auto&h:V[i])v[Y.gc(i)].PB(h);
    }
    F(MX)sc(u[i]),sc(v[i]);
    F(MX)for(auto&h:u[i])if(Y.gc(h)==h)S+=X.R[i]*1ll*Y.R[h];
    printf("%lld\n",S-N);
    return 0;
}


Measured memory_bytes: 16768
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
class Program
{
    public static void Main()
    {
        String[] input = Console.ReadLine().Split();
        long N = long.Parse(input[0]);
        long M = long.Parse(input[1]);
        long[] H = new long[N];
        input = Console.ReadLine().Split();
        bool[] flag = new bool[N+1];
        for (int i = 0; i < N; i++)
        {
            H[i] = long.Parse(input[i]);
            flag[i] = true;
        }
        flag[N] = true;
        for (int i = 0; i < M; i++)
        {
            input = Console.ReadLine().Split();
            long first = long.Parse(input[0]);
            long second = long.Parse(input[1]);
            if (H[first-1] >= H[second-1]) { flag[second] = false; }
            if (H[first-1] <= H[second-1]) { flag[first] = false; }
        }
        long ans = 0;
        for(int i = 1; i < N+1; i++)
        {
            if (flag[i] == true) ans++;
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 48192
if __name__ == '__main__':
	x,n = map(int,input().split())
	p = [int(a) for a in input().split()]
	p.sort()
	if x in p:
		m = 100
		ans = 0
		for i in range(-10,200):
			if not i in p:
				v = abs(i-x)
				if m > v:
					m = v
					ans = i
		print(ans)
	else:
		print(x)

Measured memory_bytes: 61752
#include <iostream>
#include <string>
#include <bits/stdc++.h>

#define rep(i,z) for(int i = 0; i < (z); i++)

using namespace std;

typedef long long ll;

int main(){
    int n;
    cin >>n;
    int b[n-1];
    ll ans = 0;
    rep(i,n-1){
        cin >>b[i];
    }
    rep(i,n){
        if(i == 0){
            ans += b[i];
        }else if(i == n-1){
            ans += b[i-1];
        }else {
            ans += min(b[i-1],b[i]);
        }
    }
    cout << ans << endl;
}

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

#define MOD_1_000_000_007 (1000000007LL)
#define rep(i, n)   for (long long i = 0; i <  (long long)(n); i++)
#define rep1(i, n)  for (long long i = 1; i <  (long long)(n); i++)
#define rep2(i, n)  for (long long i = 2; i <  (long long)(n); i++)
#define rep0c(i, n) for (long long i = 0; i <= (long long)(n); i++)
#define rep1c(i, n) for (long long i = 1; i <= (long long)(n); i++)
#define rep2c(i, n) for (long long i = 2; i <= (long long)(n); i++)
#define repc0(n, i) for (long long i = (long long)(n); i >= 0; i--)
#define repc1(n, i) for (long long i = (long long)(n); i >= 1; i--)
#define repc2(n, i) for (long long i = (long long)(n); i >= 2; i--)

namespace solver {
  using namespace std;
  typedef long long ll;

  static const ll INF = 100010LL;
  ll H, W, ans = 1000LL;
  bool A[110][110];
  ll F[110][110];
  vector<int> di = {1, 0};
  vector<int> dj = {0, 1};
  // ll xs[MAX], ys[MAX];
  struct P {
    ll i;
    ll j;
    ll flip;
  };

  void init() {
    scanf("%lld %lld", &H, &W);
    string s;
    char c;
    rep(i, H) {
      cin >> s;
      rep(j, W) {
        c = s[j];
        if(c=='.') A[i][j] = true;
        else A[i][j] = false;
        F[i][j] = INF;
      }
    }
  }

  void solve() {
    queue<P> que;
    que.push({0, 0, !A[0][0]});
    F[0][0] = !A[0][0];
    while(!que.empty()) {
      P u = que.front(); que.pop();
      rep(k, 2) {
        ll ni = u.i+di[k];
        ll nj = u.j+dj[k];
        ll nf = u.flip%2==A[ni][nj]?u.flip+1:u.flip;
        if(nf < F[ni][nj]) {
          que.push({ni, nj, nf});
          F[ni][nj] = nf;
        }
      }
    }
    if(F[H-1][W-1]%2==0) printf("%lld\n", F[H-1][W-1]/2);
    else printf("%lld\n", F[H-1][W-1]/2+1);
  }
}

int main() {
  solver::init();
  solver::solve();
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <cmath>
#include <string>

using namespace std;

int main() {
    float n, m, a[100], s = 0, t = 0;

    cin >> n >> m;


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


    for(int i = 0; i < n; i++){
        if( (1/(4*m))*s <= a[i] ){
            t++;
        }
    }

    if(t >= m){
        cout << "Yes";
    }else{
        cout << "No";
    }

    return 0;
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
int gcd(int a,int b)
{
	if(a%b==0)
		return b;
	else
		return gcd(b,a%b);
}
int a[100007],b[100007],c[100007];
int dpa[100007],dpb[100007],dpc[100007];
void solve()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    dpa[0]=a[0],dpb[0]=b[0],dpc[0]=c[0];
    for(int i=1;i<n;i++)
    {
        dpa[i]=max(dpb[i-1],dpc[i-1])+a[i];
        dpb[i]=max(dpa[i-1],dpc[i-1])+b[i];
        dpc[i]=max(dpb[i-1],dpa[i-1])+c[i];
    }
    cout<<max(dpa[n-1],max(dpb[n-1],dpc[n-1]));
}
int main()
{
	int t=1;
	//cin>>t;
	while(t--)
		solve();
	return(0);
}


Measured memory_bytes: 2560
import java.nio.file.FileSystemLoopException;
import java.text.DecimalFormat;
import java.util.*;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static class P {
        int x;
        int y;

        public P(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            P p = (P) o;
            return x == p.x &&
                    y == p.y;
        }

        @Override
        public int hashCode() {
            return Objects.hash(x, y);
        }
    }

    static void solve(Scanner scanner) {
        int N = Integer.parseInt(scanner.next());
        Map<Integer, Integer> m1 = new HashMap<>();
        Map<Integer, Integer> m2 = new HashMap<>();
        for (int i = 0; i < N / 2; i++) {
            int key = Integer.parseInt(scanner.next());
            m1.put(key, m1.getOrDefault(key, 0) + 1);
            key = Integer.parseInt(scanner.next());
            m2.put(key, m2.getOrDefault(key, 0) + 1);
        }

        Map.Entry<Integer, Integer> m1Max = m1.entrySet().stream().max(Comparator.comparingInt(Map.Entry::getValue)).orElse(new AbstractMap.SimpleEntry<>(0, 0));
        m1.remove(m1Max.getKey());
        Map.Entry<Integer, Integer> m1Max2 = m1.entrySet().stream().max(Comparator.comparingInt(Map.Entry::getValue)).orElse(new AbstractMap.SimpleEntry<>(0, 0));

        Map.Entry<Integer, Integer> m2Max = m2.entrySet().stream().max(Comparator.comparingInt(Map.Entry::getValue)).orElse(new AbstractMap.SimpleEntry<>(0, 0));
        m2.remove(m2Max.getKey());
        Map.Entry<Integer, Integer> m2Max2 = m2.entrySet().stream().max(Comparator.comparingInt(Map.Entry::getValue)).orElse(new AbstractMap.SimpleEntry<>(0, 0));

        int ans = Integer.MAX_VALUE;
        if (!m1Max.getKey().equals(m2Max.getKey())) {
            ans = Math.min(ans, N - m1Max.getValue() - m2Max.getValue());
        }
        if (!m1Max.getKey().equals(m2Max2.getKey())) {
            ans = Math.min(ans, N - m1Max.getValue() - m2Max2.getValue());
        }
        if (!m1Max2.getKey().equals(m2Max.getKey())) {
            ans = Math.min(ans, N - m1Max2.getValue() - m2Max.getValue());
        }

        System.out.println(ans);
    }

}


Measured memory_bytes: 50456
def main():
    A, B, C, D = [int(i) for i in input().split()]
    while(True):
        C = C - B
        if C<=0:
            print("Yes")
            break
        A = A - D
        if A<=0:
            print("No")
            break

if __name__ == "__main__":
    main()

Measured memory_bytes: 9108
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string.h>
using namespace std;
int a[210000],b[210000],n;
int main()
{

memset(a,0,sizeof(a));	
	cin>>n;
	for(int i=1;i<=n;i++)
	   cin>>b[i];
	   int sum=0,s=0;
	   for(int i=n;i>=1;i--)
	    {
	    	sum=0;
	    	for(int j=i+i;j<=n;j+=i)
	    	{
	    		sum+=a[j];
			}
			if(sum%2==b[i])a[i]=0;
			  else 
			  {
			  a[i]=1;
			  s++;}
		}
	printf("%d\n",s);
	for(int i=1;i<=n;i++)
	  if(a[i]==1)printf("%d ",i);
	
}

Measured memory_bytes: 5284
import java.util.Scanner;

class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		
		while (sc.hasNextDouble())
		{
			double a = sc.nextDouble();
			double sum = 0.0;
			for (int i = 1; i <= 10; i++)
			{
				sum += a;
				if (i % 2 == 1)
				{
					a *= 2.0;
				}
				else
				{
					a /= 3.0;
				}
			}
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 12000
import std.algorithm;
import std.array;
import std.conv;
import std.container;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

immutable int bits = 20;

long solve (int n)
{
	readln;
	auto a = readln.splitter.map !(to !(int)).array;
	RedBlackTree !(int) [bits] t;
	foreach (i; 0..bits)
	{
		t[i] = redBlackTree !(int) ();
		t[i].insert (-1);
		t[i].insert (n);
		foreach (int j, ref c; a)
		{
			if (c & (1 << i))
			{
				t[i].insert (j);
			}
		}
	}

	auto b = new int [n];
	foreach (int j, ref c; a)
	{
		int lim = n;
		foreach (i; 0..bits)
		{
			if (c & (1 << i))
			{
				lim = min (lim, t[i].upperBound (j).front);
			}
		}
		b[j] = lim;
	}

	foreach_reverse (j; 1..n)
	{
		b[j - 1] = min (b[j - 1], b[j]);
	}

	long res = 0;
	foreach (j; 0..n)
	{
		res += b[j] - j;
	}
	return res;
}

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		writeln (solve (n));
	}
}


Measured memory_bytes: 69296