akhauriyash/Code-Regression huggingface dataset:
#region using directives
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Convert;
#endregion

namespace for_contests
{
    class Program
    {
        static void Main()
        {
            long n = ToInt64(ReadLine());
            string[] strT= (ReadLine()).Split();
            List<long> first = new List<long>();
            for (long i = 0; i < n; i++)
                first.Add(ToInt64(strT[i]));
            first.Sort();

            strT = (ReadLine()).Split();
            List<long> second = new List<long>();
            for (long i = 0; i < n; i++)
                if(ToInt64(strT[i]) > first[0])
                    second.Add(ToInt64(strT[i]));
            second.Sort();

            strT = (ReadLine()).Split();
            List<long> third = new List<long>();
            for (long i = 0; i < n; i++)
                if(second.Count != 0)
                    if (ToInt64(strT[i]) > second[0])
                        third.Add(ToInt64(strT[i]));
            third.Sort();

            if (second.Count == 0 || third.Count == 0){
                WriteLine(0);
                return;
            }

            long answer = 0;

            List<long> forSecond= new List<long>();
            int st = 0;
            for (int i = 0; i < second.Count; i++)
            {
                long count = 0;
                if (i != 0)
                    count = forSecond[i-1];
                for (int j = st; j < first.Count; j++, st++)
                {
                    if (second[i] <= first[j])
                        break;
                    else
                        count++;
                }
                forSecond.Add(count);
            }

            List<long> forThird = new List<long>();
            st = 0;
            for (int i = 0; i < third.Count; i++)
            {
                long count = 0;
                if (i != 0)
                    count = forThird[i - 1];
                for (int j = st; j < second.Count; j++, st++)
                {
                    if (third[i] <= second[j])
                        break;
                    else
                    {
                        count += forSecond[j];
                    }
                }
                forThird.Add(count);
                answer += count;
            }
            WriteLine(answer);
        }
    }
}


Measured memory_bytes: 41756
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int n, ok[2][256];
char st[101];
int main() {
	cin >> (st + 1), n= strlen(st + 1);
	ok[1]['R']= ok[1]['U']= ok[1]['D']= 1;
	ok[0]['L']= ok[0]['U']= ok[0]['D']= 1;
	for(int i= 1; i <= n; i++) {
		if(!ok[i % 2][st[i]]) {
			cout << "No" << endl;
			return 0;
		}
	}
    cout << "Yes" << endl;
	return 0;
}

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

ll solve() {
    ll N, X;
    cin >> N >> X;
    vector<ll> A(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());

    ll ans = 0;
    for ( int i = 0; i < N; i++ ) {
        if ( X >= A[i] ) {
            X -= A[i];
            ans++;
        }
    }
    if ( ans == N && X > 0 ) ans--;
    return ans;
}

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

Measured memory_bytes: 256
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys
import string

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

sys.setrecursionlimit(2147483647)
INF = float("inf")

N, K = list(map(int, sys.stdin.readline().split()))
A = list(map(int, sys.stdin.readline().split()))


print(max(1, math.ceil((N - 1) / (K - 1))))


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

typedef pair<int,int> P;

#define INF 999999999

int n, start;
int t[1010][1010];
int hx[1000002], hy[1000002];
P dp[1010][1010];

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

bool prime[1000002];

void era(){
  fill(prime, prime + 1000002, true);
  prime[0] = prime[1] = false;

  for(int i = 2; i * i <= 1000000; i++){
    if(!prime[i]) continue;
    for(int j = i + i; j <= 1000000; j += i){
      prime[j] = false;
    }
  }
}

int main(){
  era();

  int x = 502, y = 502;
  int now = 1, len = 0;
  int dir = 0;

  for(int i = 0; i < 1010; i++){
    for(int j = 0; j < 1010; j++){
      t[i][j] = INF;
    }
  }

  while(now <= 1000000){
    if(dir % 2 == 0) len++;

    for(int i = 0; i < len; i++){
      hx[now] = x;
      hy[now] = y;

      t[y][x] = now++;
      x += dx[dir];
      y += dy[dir];
    }

    dir = (dir + 1) % 4;
  }

  while(cin >> n >> start, n || start){
    memset(dp, -1, sizeof(dp));

    int sx = hx[start];
    int sy = hy[start];
    dp[sy][sx] = P(prime[start], prime[start] ? start : 0);

    P ans = dp[sy][sx];

    for(int y = sy; y <= 1002; y++){
      for(int x = 0; x <= 1002; x++){
        if(dp[y][x] == P(-1, -1)) continue;

        for(int dx2 = -1; dx2 <= 1; dx2++){
          int nx = x + dx2;
          int ny = y + 1;
          if(nx < 0 || ny < 0) continue;
          if(n < t[ny][nx]) continue;

          P np = dp[y][x];
          if(prime[t[ny][nx]]){
            np.first++;
            np.second = t[ny][nx];
          }

          dp[ny][nx] = max(dp[ny][nx], np);
          ans = max(ans, np);
        }
      }
    }

    cout << ans.first << " " << ans.second << endl;
  }
}

Measured memory_bytes: 21912
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
	int N, K;
	long long ans = 0;
	cin >> N >> K;
	vector<int> H(N);
	for (int i = 0; i < N; i++){
		cin >> H[i];
	}
	sort(H.begin(), H.end());
	
	for (int i = 0; i < N - K; i++){
		ans += H[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
import java.io.*;
import java.util.*;

class Main
{
    public static void main (String[] args) throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        String s[]=bu.readLine().split(" ");
        int l=Integer.parseInt(s[0]),r=Integer.parseInt(s[1]),d=Integer.parseInt(s[2]),i,c=0;
        for(i=l;i<=r;i++)
        if(i%d==0) c++;
        System.out.print(c);
    }
}

Measured memory_bytes: 32432
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
#define NIL -2000000001
#define MAX 2000000000000

int main() {
  int a, b;
  scanf("%d", &a);
  scanf("%d", &b);
  printf("%d\n",(a-1)*(b-1));
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define pb push_back
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define cps CLOCKS_PER_SEC
#define tests(t) int t; cin >> t; while(t--)
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define ll long long
#define ld double
#define eb emplace_back
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define fi first
#define se second
#define bitcount(x) __builtin_popcount(x)
#define PI acos(-1.0)
#define EPS 1e-9
#define mod 1000000007

#define par pair<int, int>
#define maxn 505

using namespace std;
///All indexing is 0-based
using namespace __gnu_pbds;
template<class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
///methods: find_by_order(k); & order_of_key(k);
///To make it an ordered_multiset, use pairs of (value, time_of_insertion)
///to distinguish values which are similar

ll N,sol,n=10;
int main()
{
    #ifdef acm
    freopen("a.in","r",stdin);
    #endif // acm
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> N;

    if(N & 1)
        sol =0;
    else
        while(n <=N) sol+=N/n , n*=5;

    cout << sol;

}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void) {
  int a;
  cin >> a;
  if (a == 1) {
    cout << "Hello World" << endl;
  }
  else if (a == 2) {
    int x, y;
    cin >> x >> y;
    cout << x + y << endl;
  }
  return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <cstring>

using namespace std;

int L, K;
unsigned long long cache[128];

unsigned long long Solve(int l) {
  if (cache[l] > 0) return cache[l];
  long long r = 0;
  if (l >= 1) ++r;
  if (l > 2) r += Solve(l-2);
  if (l >= K) ++r;
  if (l > K+1) r += Solve(l-(K+1));
  return cache[l] = r;
}

int main() {
  while (cin >> L >> K) {
    memset(cache, 0, sizeof(cache));
    cout << Solve(L) << endl;
  }
}

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

int main(){
    int n,m,x;
    cin >> n >> m >> x;   
    int a;
    int left = 0;
    int right = 0;    

    for(int i=0;i<m;i++){
        cin >> a;
        if(a<x) left++;
        else right++;
    }
    
    if(left<right) cout << left;
    else cout << right;
}

Measured memory_bytes: 256
n = int(input())
d, order = {}, {}
for _ in range(n):
    a, num = input().split()
    d[a] = d[a] + int(num) if a in d else int(num)
    if len(a) in order:
        if a not in order[len(a)]:
            order[len(a)].append(a)
    else:
        order[len(a)] = []
        order[len(a)].append(a)
for k, v in sorted(order.items(), key=lambda x: x[0]):
    for a in sorted(v):
        print(a, d[a])

Measured memory_bytes: 7684
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
string ans="keyence";
int main()
{
	string s;cin>>s;int n=s.size();
	rep(i,8){
		//cout<<s.substr(0,i)+s.substr(n-(7-i))<<endl;
		if(s.substr(0,i)+s.substr(n-(7-i))==ans){
			cout<<"YES"<<endl;return 0;
		}
	}
	cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main( void ) {
	int i, j, tmp, cnt, nData, data[ 100 ];

	while ( cnt = 0, scanf( "%d", &nData ), nData ) {
		for ( i = 0; i < nData; i++ )
			scanf( "%d", &data[ i ] );

		for ( i = 0; i < nData - 1; i++ )
			for ( j = nData - 1; j > i; j-- )
				if ( data[ j - 1 ] > data[ j ] ) {
					tmp = data[ j - 1 ];
					data[ j - 1 ] = data[ j ];
					data[ j ] = tmp;

					cnt++;
				}

		printf( "%d\n", cnt );
	}

	return 0;
}

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

const int maxn = 1e5 + 5;
int n;
int a[maxn], b[maxn], c[maxn];
int f[maxn][4];
int ans = 0;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),	cout.tie(0);
	cin >> n;
	for(int i = 1; i <= n; ++i) cin >> a[i] >> b[i] >> c[i];
	f[1][1] = a[1], f[1][2] = b[1], f[1][3] = c[1];
	for(int i = 2; i <= n; ++i){
		f[i][1] = max(f[i-1][2] + a[i], f[i-1][3] + a[i]);
		f[i][2] = max(f[i-1][1] + b[i], f[i-1][3] + b[i]);
		f[i][3] = max(f[i-1][1] + c[i], f[i-1][2] + c[i]);
	}
	for(int j = 1; j <= 3; ++j) ans = max(ans, f[n][j]);
	cout << ans;
}

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

class Timer {
public:
    void start() {
        start_ = std::chrono::steady_clock::now();
    }
    int64_t elapsedMilliSec() {
        auto n = std::chrono::steady_clock::now();
        auto e = std::chrono::duration_cast<std::chrono::milliseconds>(n - start_);
        return e.count();
    }
private:
    std::chrono::steady_clock::time_point start_;
};

constexpr int64_t NUM = 26;
vector<int64_t> c(NUM);
vector<vector<int64_t>> s;

int64_t score(const vector<int64_t>& v) {
    vector<int64_t> last(NUM, -1);
    int64_t S = 0;
    for (int64_t i = 0; i < v.size(); i++) {
        //開催による満足度増加
        S += s[i][v[i]];

        //最終開催日更新
        last[v[i]] = i;

        //開催されないことによる満足度減少
        for (int64_t j = 0; j < NUM; j++) {
            S -= c[j] * (i - last[j]);
        }
    }

    return S;
}

int main() {
    //時間関連
    Timer timer;
    timer.start();
    constexpr int64_t LIMIT_MSEC = 1900;

    //入力
    int64_t D;
    cin >> D;
    for (int64_t& C : c) {
        cin >> C;
    }

    s.resize(D, vector<int64_t>(NUM));
    for (int64_t i = 0; i < D; i++) {
        for (int64_t j = 0; j < NUM; j++) {
            cin >> s[i][j];
        }
    }

    //乱数関連
    mt19937_64 engine(0);
    uniform_int_distribution<int64_t> day_dist(0, D - 1);
    uniform_int_distribution<int64_t> num_dist(0, NUM - 1);

    //初期化
    vector<int64_t> ans(D);
    vector<int64_t> last(NUM, -1);
    for (int64_t i = 0; i < D; i++) {
        vector<int64_t> scores(NUM);
        for (int64_t j = 0; j < NUM; j++) {
            scores[j] = - c[j] * (i - last[j]);
        }
        int64_t sum = accumulate(scores.begin(), scores.end(), (int64_t)0);
        for (int64_t j = 0; j < NUM; j++) {
            scores[j] = s[i][j] + c[j] * (i - last[j]) - sum;
        }

        ans[i] = max_element(scores.begin(), scores.end()) - scores.begin();

        //最終開催日更新
        last[ans[i]] = i;
    }

    int64_t best_score = score(ans);

    while (timer.elapsedMilliSec() < LIMIT_MSEC) {
        int64_t change_day = day_dist(engine);
        int64_t change_num = num_dist(engine);

        //変える
        int64_t before_num = ans[change_day];
        ans[change_day] = change_num;

        int64_t s = score(ans);

        if (s > best_score) {
            best_score = s;
        } else {
            //戻す
            ans[change_day] = before_num;
        }
    }

    for (int64_t& a : ans) {
        cout << a + 1 << endl;
    }
}

Measured memory_bytes: 3728
n=int(input())
d=list(map(int, input().split()))
#print(d)
sd = sorted(d)
#print(sd)
#print(sd[len(d)//2-1])
#print(sd[len(d)//2])


print(sd[len(d)//2]  -  sd[len(d)//2-1])

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

void fail(){
    cout << "No" << endl;
    exit(0);
}

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

    int N2 = N;
    while(N2 % 2 == 0) N2 /= 2;
    if(N2 == 1) fail();

    vector<pair<int, int>> ans;
    ans.emplace_back(1, 2);
    ans.emplace_back(2, 3);
    ans.emplace_back(3, 1+N);
    ans.emplace_back(1+N, 2+N);
    ans.emplace_back(2+N, 3+N);
    for(int i=4; i<N; i+=2){
        ans.emplace_back(1, i);
        ans.emplace_back(i, i+1);
        ans.emplace_back(1, i+1+N);
        ans.emplace_back(i+1+N, i+N);
    }
    if(N%2 == 0){
        int need = N ^ (N-1);
        need--;
        ans.emplace_back(N, 2*N-1);
        ans.emplace_back(need, 2*N);
    }
    cout << "Yes" << endl;
    for(auto& p : ans) cout << p.first << " " << p.second << endl;
    return 0;
}


Measured memory_bytes: 4080
#include <iostream>
#include <vector>
#include <queue>
#define INF (1 << 30)
using namespace std;
bool bfs(vector<vector<int>>& Graph,int s,int t,vector<int>& parent) {
	vector<bool> visited(t + 1, false);
	queue<int> q;
	q.push(s); visited[s] = true; parent[s] = -1;
	while (!q.empty()) {
		int u = q.front(); q.pop();
		for (int v = 0; v < t+1;v++) {
			if (visited[v] == false && Graph[u][v] > 0) {
				q.push(v);	parent[v] = u;	visited[v] = true;
			}
		}
	}
	return (visited[t] == true);
}
int fordFulkerson(vector<vector<int>>& Graph, int s, int t) { 
	int u, v;
	vector<int> parent(t + 1);
	int max_flow = 0;
	while (bfs(Graph, s, t, parent)) {
		int path_flow = INF;
		for (v = t; v != s; v = parent[v]) {
			u = parent[v];	path_flow = min(path_flow, Graph[u][v]);
		}

		for (v = t; v != s; v = parent[v]) {
			u = parent[v];
			Graph[u][v] -= path_flow;
			Graph[v][u] += path_flow;
		}

		max_flow += path_flow;
	}
	return max_flow;
}
int main() {
	int V, E; cin >> V >> E;
	vector<vector<int>> G(V,vector<int>(V,0));	//V x V   init:0
	for (int i = 0; i < E;i++) {
		int u, v, c; cin >> u >> v >> c;
		G[u][v] = c;
	}
	cout << fordFulkerson(G, 0, V - 1) << endl;
	return 0;
}

Measured memory_bytes: 3196
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int x = sc.nextInt();

        if (k * 500 >= x) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21332
#include<iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  int k;
  k=n%10;
  if(k==2||k==4||k==5||k==7||k==9) cout<<"hon"<<endl;
  if(k==0||k==1||k==6||k==8) cout<<"pon"<<endl;
  if(k==3) cout<<"bon"<<endl;
  return 0;
}

Measured memory_bytes: 3592
N = int( input() )
X = list( map( int, input().split() ) )

v_max = 10 ** 18
m = min( X )
M = max( X )
for i in range( m, M + 1 ):
  v = 0
  for x in X:
    v += ( x - i ) ** 2
  v_max = min( v, v_max )
print( v_max )

Measured memory_bytes: 3064
def main():
    n, x, y = map(int, input().split())

    x -= 1
    y -= 1

    ans_list = [0]*n

    for i in range(n):
        for j in range(i,n):
            ans_list[min(abs(i-j), abs(i-x)+abs(j-y)+1, abs(j-x)+abs(i-y)+1)] += 1

    for i in range(1,n):
        print(ans_list[i])

if __name__ == '__main__':
    main()

Measured memory_bytes: 45296
import java.util.Scanner;
import java.util.Stack;

public class Main {
	public static void main(String[] args) {
		//System.in
		Scanner scanner = new Scanner(System.in);
		//split tokens by space and create a stack
		String input = scanner.nextLine();
		String[] tokens = input.split(" ");
		Stack<Integer> polishStack = new Stack<Integer>();
		scanner.close();
		
		//go through all tokens
		for (int i = 0; i < tokens.length; i++) {
			//find out if it's a number or operation
			boolean operation = false;
			try {
				Integer.parseInt(tokens[i]);
			}
			catch(NumberFormatException e) {
				operation = true;
			}
			
			//push to stack if it's a number
			if (operation != true) {
				polishStack.push(Integer.parseInt(tokens[i]));
			}
			else {
				int first = polishStack.pop();
				int second = polishStack.pop();
				
				if (tokens[i].equals("+")) {
					polishStack.push(first + second);
				}
				else if (tokens[i].contentEquals("-")) {
					polishStack.push(second - first);
				}
				else if (tokens[i].contentEquals("*")) {
					polishStack.push(first * second);
				}
				else if (tokens[i].contentEquals("/")) {
					polishStack.push(second / first);
				}
			}
		}
		
		System.out.println(polishStack.pop());
	}
}


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


int main(){
	char c1[3];
	char c2[3];

	cin >> c1[0] >> c1[1] >> c1[2];
	cin >> c2[0] >> c2[1] >> c2[2];

	if(c1[0] == c2[2] && c1[1] == c2[1] && c1[2] == c2[0]) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
object Main extends App {
  val n = readLine.toInt

  for (i <- 0 until n) {
    val maxl = 80
    val a = readLine()
    val b = readLine()

    val res = if (a.length > maxl || b.length > maxl) {
      "overflow"
    } else {
      val c = BigInt(a) + BigInt(b)
      val strc = "%d".format(c)
      if (strc.length > maxl) {
        "overflow"
      } else {
        strc
      }
    }
    println(res)
  }
}


Measured memory_bytes: 44072
# ABC149 C
import numpy as np
X = int(input())
numList = np.arange(X*2)

for i in range(2,X):
    if numList[i] == False:
        continue
    numList[i:X*2:i] = 0

for i in numList[X:X*2]:
    if i != 0:
        print(i)
        break


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

int main()
{
    int k, n;
    cin >> n >> k;
    vector<int> h(n);
    for (int i = 0; i < n; i++)
    {
        cin >> h.at(i);
    }
    sort(h.begin(), h.end());
    long long ans = h.at(n - 1) - h.at(0);
    long long x;
    for (int i = 0; i < n - k + 1; i++)
    {
        x = h.at(i + k-1) - h.at(i);
        ans = min(x, ans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
s = gets.strip.to_s
t = gets.strip.to_s
sum = s.size
tum = t.size

i = 0
ary = []
while i <= sum-tum do
  k = 0
  po = 0
  while k < tum do
    if t[k]==s[i+k]
      po += 1
    end
    k += 1
  end
  ary << tum-po
  i += 1
end
puts ary.min

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

template<typename dtype>
class RMQ{
public:
  dtype initValue; //範囲外のときに返す値。
  int n,n_;
  vector<dtype> dat;
  int toMax;

  //初期化
  RMQ(){n=-1;}
  RMQ(int n_,dtype initValue,int toMax = 0):n_(n_),initValue(initValue),toMax(toMax){
    n=1;
    while(n<n_)n*=2;
    dat.resize(2*n-1,initValue);
  }

  inline dtype merge(dtype a,dtype b){return toMax? max(a, b):min(a, b); }

  //k番目の値をaに変更
  void update(int k,dtype a){
    k+=n-1;
    dat[k]=a;
    while(k>0){
      k=(k-1)/2;
      dat[k]=min(dat[k*2+1],dat[k*2+2]);
    }
  }
  
  //[a,b)の最小値を求める query(a,b,0,0,n)
  dtype find(int a,int b,int k,int l,int r){
    if(r<=a||b<=l)return initValue;
    if(a<=l&&r<=b)return dat[k];
    dtype vl = find(a,b,k*2+1,l,(l+r)/2);
    dtype vr = find(a,b,k*2+2,(l+r)/2,r);
    return merge(vl,vr);
  }

  dtype find(int a,int b){
    assert(a <= b), assert(a <= n_ && b <= n_), assert(a >= 0 && a >= 0);
    return find(a,b,0,0,n);
  }
};

int main(){
  int n,q;
  cin>>n>>q;
  typedef long long ll;
  RMQ <ll> A(n,INT_MAX,0);

  while(q--){
    int com,x,y;
    cin>>com>>x>>y;
    if(com == 0) A.update(x,y);
    if(com == 1) cout<<A.find(x,y+1)<<endl;
  }

  return 0;
}



Measured memory_bytes: 4960
#126
from math import ceil, log
n, k = list(map(int, input().split(' ')))
rate = 0
for i in range(1,n+1):
    x = ceil(log(k/i, 2))
    if x < 0:
        x = 0
    rate += (1/n)*(1/2)**x

print(rate)

Measured memory_bytes: 3060
R,G,B,N=map(int,input().split())

cnt=0
for r in range(N+1):
  for g in range(N+1):
    u=N-R*r-G*g
    if u<0:
      break
    if u%B!=0:
      continue
    if u//B>=0:
      cnt+=1
print(cnt)


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

using namespace std;

#define lli  long long int
#define pb   push_back

int main(){
    lli n, sum=0;
    cin >> n;
    for(int i=1; i<=n; i++){
        if(i%3 == 0 || i%5 ==0 || i%15 == 0){
            continue;
        }
        sum = sum+i;
    }
    cout << sum;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
using namespace std;
typedef long long ll;

int main(){
  int n,m;
  cin >> n >> m;
  int like[m+1];
  
  for (int i = 0; i <= m; i++){
    like[i] = 0;
  }
  
  for (int i = 0; i < n; i++){
    int k;
    cin >> k;
    
    for (int j = 0; j < k; j++){
      int a;
      cin >> a;
      like[a]++;
    }
  }
  
  int res = 0;
  
  for (int i = 0; i <= m; i++){
    if(like[i] == n) res++;
  }
  
  cout << res;
  
  return 0;
}

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

int main() {
  int X;
  cin >>X;
  if(X==7){
    cout <<"YES" <<endl;
    return 0;
  }
  if(X==5){
    cout <<"YES" <<endl;
    return 0;
  }
  if(X==3){
    cout <<"YES" <<endl;
    return 0;
  }
  cout <<"NO" <<endl;
  return 0;
}

Measured memory_bytes: 256
A, B = map(int, input().split())

ans = 0
for i in range(A, B+1):
    i = str(i)
    former = i[:2]
    latter = i[3:]
    if (int(former) % 11 == 0 and former == latter) or former == latter[::-1]:
        ans += 1
print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <bitset>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>
#include <limits>

using namespace std;
using ll=long long;
using vint=vector<int>;
using pint=pair<int,int>;

const double EPS = 1e-9;
const int inf = numeric_limits<int>::max();

#define rep(i,n) for(int i=0;i<int(n);++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;--i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,a,b) for(int i=int(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

void solve(){
  int h, w;
  cin >> h >> w;

  char s[51][51];

  rep(i,h) rep(j,w) cin >> s[i][j];


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

  bool ok=true;
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(s[i][j] == '#'){
        bool flag = false;
        for(int k=0; k < 4; k++){
          if(0 <= i+dx[k] && i+dx[k] < h && 0 <= j+dy[k] && j+dy[k] < w && s[i+dx[k]][j+dy[k]] == '#'){
            flag = true;
            break;
          }
        }
        if(!flag){
          ok=false;
          goto end;
        }
      }
    }
  }

  end:
  if(ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

int main(){
  solve();
  return 0;
}

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

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

const int MX = 105;
const int INF = 1e6;

char field[MX][MX];
int dp[MX][MX];

int is_free(int ax, int ay, int bx, int by) {
	if (field[ax][ay] == field[bx][by]) return 0;
	if (field[ax][ay] == '#') return 0;
	return 1;
}

int main() {
	int n, m;
	ignore = scanf("%d %d", &n, &m);
	for (int i = 0; i < n; i++) {
		ignore = scanf("%s", field[i]);
	}

	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			dp[i][j] = INF;

	dp[0][0] = (field[0][0] == '.') ? 0 : 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (i + 1 < n)
				dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + is_free(i, j, i + 1, j));
			if (j + 1 < m)
				dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + is_free(i, j, i, j + 1));
		}
	}

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


Measured memory_bytes: 892
#!/usr/bin/env python3
import sys
import math
sys.setrecursionlimit(10 ** 7)


def solve(N: int, D: int):
    print(math.ceil(N / (D * 2 + 1)))
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools
# (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(N, D)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
/*
　　　　　　 ＿＿
　　　　　／＞　　 フ
　　　　　|   _　 _l  
　 　　　／` ミ＿x ノ   Zzz..
　　 　 /　 　 　 |   コード見ちゃだめ！！
　　　 /　 ヽ　　  ﾉ
　 　 │　　|　|  |   
　／￣|　　 |　|  |
　| (￣ヽ＿_ヽ_)_ _)
　＼二つ
*/

#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) reverse((a).begin(),(a).end())
#define REP(i, n) for(int i = 0; i < n; i++)
const int MOD = 1e9+7;
typedef long long ll;

int main() { 

    queue<char> a,b,c;
    string s1,s2,s3;
    cin>>s1>>s2>>s3;

    for(int i=0;i<s1.size();i++){
      a.push(s1[i]);
      //cout<<a.front()<<'a'<<endl;
    }
    for(int i=0;i<s2.size();i++){
      b.push(s2[i]);
      //cout<<b.front()<<'b'<<endl;
    }
    for(int i=0;i<s3.size();i++){
      c.push(s3[i]);
      //cout<<c.front()<<'c'<<endl;
    }
    char now=a.front();
    a.pop();

    while(true){
      if(now=='a') {
        if(a.size()==0) {
          cout<<'A'<<endl; break;
        }
        now=a.front();
        a.pop();
      }
      else if(now=='b') {
        if(b.size()==0) {
          cout<<'B'<<endl; break;
        }
        now=b.front();
        b.pop();
      }
      else {
        if(c.size()==0) {
          cout<<'C'<<endl; break;
        }
        now=c.front();
        c.pop();
      }
    }
}     


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b;
int f[3];
int main(){
	cin>>a>>b;
	if(a>b)swap(a,b);
	if(a<=0&&b>=0){cout<<"Zero"<<endl;return 0;}
	if(a>0&&b>0){cout<<"Positive"<<endl;return 0;}
	if(a<0&&b<0){
		if((b-a+1)%2==0)cout<<"Positive"<<endl;
		else cout<<"Negative"<<endl;
	}
} 

Measured memory_bytes: 256
f=lambda:[*map(int,input().split())]
n,h=f()
A,B=[],[]
for _ in range(n):
  a,b=f()
  A+=[a]
  B+=[b]
m=max(A)
B.sort()
c=0
for b in sorted(B)[::-1]:
  if b>m:
    h-=b
    c+=1
    if h<1: break
print(c--h//m*(h>0))

Measured memory_bytes: 18508
#include<bits/stdc++.h>
using namespace std;
 
/* data type, special numbers, defines */
//#define int ll //use if ded
#define ll long long
#define ld long double
const ll inf=LLONG_MAX;
//const ll mod=1e9+7;
const ll mod=998244353;
const ld pi=acos(-1.0);
#define all(v) v.begin(), v.end()
/* end data type and special numbers */
 
/* fast input.output */
#define gc getchar//_unlocked
#define pc putchar//_unlocked
#define endl pc('\n')
int get_i(){
	char c=gc(); bool neg=false;
	for(; c<'0'||'9'<c; c=gc())
		if(c=='-') neg=true;
	int rs=c-'0'; c=gc();
	for(; '0'<=c && c<='9'; c=gc())
		rs=(rs<<1)+(rs<<3)+(c-'0');
	if(neg) rs=-rs;
	return rs;
}
ll get_l(){
	char c=gc(); bool neg=false;
	for(; c<'0'||'9'<c; c=gc())
		if(c=='-') neg=true;
	ll rs=c-'0'; c=gc();
	for(; '0'<=c && c<='9'; c=gc())
		rs=rs*10ll+(c-'0');
	if(neg) rs=-rs;
	return rs;
}
string get_s(){
	char c=gc();
	for(; c<33 || 126<c; c=gc());
	string s=""; s+=c; c=gc();
	for(; 33<=c && c<=126; c=gc())
		s+=c;
	return s;
}
char get_c(){
	char c=gc();
	for(; c<33 || 126<c; c=gc());
	return c;
}
void print_i(int _n){
	bool neg=false; if(_n<0) {neg=true; _n=-_n;}
	if(neg) pc('-');
	int N=_n, rev, count=0;
	rev=N;
	if(N==0) {pc('0'); return;}
	while((rev%10)==0) {count++; rev/=10;}
	rev=0;
	while(N!=0) {rev=(rev<<3)+(rev<<1)+N%10; N/=10;}
	while(rev!=0) {pc(rev%10+'0'); rev/=10;}
	while(count--) pc('0');
}
void print_l(ll _n){
	ll N=_n, rev, count=0;
	rev=N;
	if(N==0) {pc('0'); return;}
	while((rev%10)==0) {count++; rev/=10;}
	rev=0;
	while(N!=0) {rev=rev*10ll+N%10; N/=10;}
	while(rev!=0) {pc(rev%10+'0'); rev/=10;}
	while(count--) pc('0');
}
void print_s(string a){
	for(int i=0; i<a.size(); i++)
		pc(a[i]);
}
#define endline pc('\n');
#define space pc(' ');
/* end fast input/output */

/*   E N D   O F   T E M P L A T E   */

ll dp[3005][3005];
int n, s, a[3005];
int main(){
	n=get_i(); s=get_i();
	for(int i=1; i<=n; i++) a[i]=get_i();
	dp[0][0]=1;
	for(int i=1; i<=n; i++) for(int j=0; j<=s; j++){
		dp[i][j]=dp[i-1][j];
		if(j>=a[i]){
			if(j==a[i]) dp[i][j]=(dp[i][j]+(ll)i*dp[i-1][j-a[i]])%mod;
			else dp[i][j]=(dp[i][j]+dp[i-1][j-a[i]])%mod;
		}
	}
	ll ans=0ll;
	for(int i=1; i<=n; i++) ans=(ans+dp[i][s])%mod;
	print_l(ans); endline return 0;
}

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

int     main() {
        long N;
        string S;
        cin >>N >>S;
        vector<long> C(26, 1);
        for (int i=0; i<N; i++)
                C.at(S.at(i)-'a')++;
        long SS=1;
        for (int i=0; i<26; i++) {
                SS *= C.at(i);
                SS %= 1000000007;
        }
        SS--;
        cout <<SS <<endl;
        return 0;
}

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

int main(){
  string s,t;
  cin >> s >> t;
  int ans = 0;
  rep(i,0,s.size()){
    if(s[i]!=t[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
  const char tes = '-';
  string s, t;
  cin >> s >> t;
  vector<char> StoT(26, tes), TtoS(26, tes);
  for(int i = 0; i < s.length(); i++){
    if( StoT[int(t[i]-'a')] == tes ){
      StoT[int(t[i]-'a')] = s[i];
    }else{
      if( StoT[int(t[i]-'a')] != s[i] ){
        cout << "No\n";
        return 0;
      }
    }
    if( TtoS[int(s[i]-'a')] == tes ){
      TtoS[int(s[i]-'a')] = t[i];
    }else{
      if( TtoS[int(s[i]-'a')] != t[i] ){
        cout << "No\n";
        return 0;
      }
    }
  }
  cout << "Yes\n";
  return 0;
}


Measured memory_bytes: 776
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
/* #include <regex> */

using namespace std;

/* g++ -g -std=c++11 */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    string s,t;
    while (cin >> s >> t) {
        map<char,char> x,y;
        FOR(i,0,128)
            x[i] = y[i] = 0;
        const int n = s.size();
        bool good = true;
        FOR(i,0,n) {
            const char a = s[i];
            const char b = t[i];
            if (!x[a] && !y[b]) 
                x[a] = b, y[b] = a;
            if (x[a] && x[a] != b)
                good = false;
            if (y[b] && y[b] != a)
                good = false;
        }
        if (good)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
}


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

int main() {
	int a, b, c, d, ans = 0;
	cin>>a>>b>>c>>d;
	for (int i = 0; i <= 100; i++) {
		if (i >= a && i < b && i >= c && i < d) {
			ans++;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b, h = IR(3)
    print((a+b)*h//2)
    return

#B
def B():
    d = defaultdict(int)
    d["a"] = deque(S())
    d["b"] = deque(S())
    d["c"] = deque(S())
    tern = "a"
    while d[tern]:
        tern =  d[tern].popleft()
    print(str.capitalize(tern))
    return

#C
def C():
    return

#D
def D():
    return



#Solve
if __name__ == '__main__':
    B()


Measured memory_bytes: 41200
def resolve():
    import sys
    from operator import itemgetter
    
    readline = sys.stdin.readline    # 1行だけ文字列にする

    N, M = map(int, readline().split())
    AB = [list(map(int, readline().split())) for _ in [0] * M]
    AB.sort(key=itemgetter(1))
    islands = -float('inf')
    ans = 0
    for left, right in AB:
        if islands <= left:
            ans += 1
            islands = right
    print(ans)
    

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 28672
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int N = 2e4+2;
int f[N];
void init() {
	for (int a = 2; a * a < N ; ++a){
		for (int b = 2; a * a + b * b < N; ++b){
			for(int c = 2+ abs(a-b); a * a + b * b + c * c < N &&  c <= a + b - 2; ++c){
				++f[a*a+b*b+c*c];
			}
		}
	}
}
int main() {
	//freopen("in","r",stdin);
	std::ios::sync_with_stdio(false);std::cin.tie(nullptr);
	init();
	int n;
	cin >> n;
	for(int i=1;i<=n;++i){
		cout<<f[2*i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3724
import java.util.Scanner;

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

      int n;
      n = sc.nextInt();

      int x = (n+1000-1)/1000;
      int change = x*1000 - n;

      System.out.println(change);
      }
}


Measured memory_bytes: 35676
#include<cstdio>
#include<map>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

using namespace std;

int main(){
	string s;cin>>s;
	bool end = true;

	REP(i,2) s.pop_back();
	while(end){
		for(int i=0,j=s.size()/2;i<s.size()/2;i++,j++){
			if(s[i]!=s[j]){
				s.pop_back();
				s.pop_back();
				break;
			}
			if(i==s.size()/2 - 1) end = false;
		}
	}
	cout << s.size() << endl;
	return 0;
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//end

random_device rnd;
mt19937 mt(rnd());

void test(ll n){
   int cnt=0;
   rep(p,2,n+1){
      int cur=n;
      while(cur>1){
         if(cur%p==0)cur/=p;
         else cur-=p;
      }
      if(cur==1)cnt++;
   } cerr<<cnt<<endl;
}

int main(){
   ll n,cnt=0; cin>>n;
   vector<ll> ds;
   for(ll p=1;p*p<=n;p++)if(n%p==0){
      if(p!=1)ds.push_back(p);
      if(p*p!=n)ds.push_back(n/p);
   }
   for(ll d:ds){
      ll m=n;
      while(m%d==0)m/=d;
      if(m%d==1)cnt++;
   } n--;
   for(ll p=1;p*p<=n;p++)if(n%p==0){
      if(p!=1)cnt++; if(p*p!=n)cnt++;
   }
   printf("%lld\n",cnt);
   return 0;
}

Measured memory_bytes: 384
num = int(input())
target = input()

alphabet = ["A","B","C","D","E","F","G","H","I","J","K",
            "L","M","N","O","P","Q","R","S","T","U",
            "V","W","X","Y","Z"]
output = []        
for i in range(len(target)):
    tmp = alphabet.index(target[i])
    tmp = tmp + num
    while tmp >= 26:
        tmp = tmp - 26        
    output.append(alphabet[tmp])
print("".join(output))

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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 100;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<char> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

void print_line(vector<ll> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;
const int mod = 1000000007;

typedef pair<ll, ll> P;

int main() {

    stack<ll> s1;
    stack<P> s2;

    string s;
    cin >> s;

    ll sum = 0;
    for (ll i = 0; i < s.size(); i++) {
        char c = s[i];
        if (c == '\\') {
            s1.push(i);
        } else if (c == '/' && !s1.empty()) {
            ll j = s1.top();
            s1.pop();
            sum += (i - j);

            ll a = i - j;
            while (!s2.empty() && j < s2.top().first) {
                a += s2.top().second;
                s2.pop();
            }

            s2.push(P(j, a));
        }
    }

    vector<ll> ans;
    while (!s2.empty()) {
        ans.push_back(s2.top().second);
        s2.pop();
    }
    reverse(ans.begin(), ans.end());

    cout << sum << endl;
    if(ans.size() == 0) {
        cout << 0 << endl;
        return 0;
    }
    cout << ans.size() << ' ';
    print_line(ans);
}



Measured memory_bytes: 3296
import java.io.*;
import java.util.*;
public class Main {
	
	public static void main(String[] args) {
	
		MyScanner sc = new MyScanner();
		int n=sc.nextInt();
		int k=sc.nextInt();
	
		System.out.println(n>=2*k-1?"YES":"NO");
	
		
	}	
	
	
	
//----------------------------------------------------------
	static int l_min(int[] a) {
		Arrays.sort(a);
		return a[0];
	}
	static int l_max(int[] a) {
		int l=a.length;
		Arrays.sort(a);
		return a[l-1];
	}
	public static PrintWriter out;

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}
	

}





Measured memory_bytes: 22996
import java.util.Scanner;
public class Main {
	    double x;
	    double y;
	    public Main(double x,double y){
	        this.x = x;
	        this.y = y;
	        } 
	    public static boolean isInTriangle(Main A, Main B, Main C, Main P) {
	        /*利用叉乘法进行判断,假设P点就是M点*/  
	        double a = 0, b = 0, c = 0;  

	        Main MA = new Main(P.x - A.x,P.y - A.y);  
	        Main MB = new Main(P.x - B.x,P.y - B.y);  
	        Main MC = new Main(P.x - C.x,P.y - C.y);  

	        /*向量叉乘*/  
	        a = MA.x * MB.y - MA.y * MB.x;  
	        b = MB.x * MC.y - MB.y * MC.x;  
	        c = MC.x * MA.y - MC.y * MA.x;  

	        if((a <= 0 && b <= 0 && c <= 0)||  
	            (a > 0 && b > 0 && c > 0))  
	            return true;     
	        return false;  
	    }
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
				Scanner in =new Scanner(System.in);
				double x1,y1,x2,y2,x3,y3,x,y;
				while(in.hasNext())
				{
					x1=in.nextDouble();
					y1=in.nextDouble();
					x2=in.nextDouble();
					y2=in.nextDouble();
					x3=in.nextDouble();
					y3=in.nextDouble();
					x=in.nextDouble();
					y=in.nextDouble();
					
					boolean result=isInTriangle(new Main(x1, y1),new Main(x2, y2),new Main(x3, y3),new Main(x, y));
					if(!result){
						System.out.println("NO");
					}
					else
						System.out.println("YES");
					
					
				}
				in.close();
		}

}


Measured memory_bytes: 32152
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  string s;
  cin >> n >> s;
  int r = 0, b = 0;
  for(int i = 0; i < n; i++){
    if(s[i] == 'R') r++;
    else b++;
  }
  if(r > b) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C: Big Array
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

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

/* global variables */

pii ps[MAX_N];

/* subroutines */

/* main */

int main() {
  int n;
  ll k;
  scanf("%d%lld", &n, &k);

  for (int i = 0; i < n; i++) {
    int ai, bi;
    scanf("%d%d", &ai, &bi);
    ps[i] = pii(ai, bi);
  }
  sort(ps, ps + n);

  for (int i = 0; i < n; i++) {
    int &bi = ps[i].second;
    if (k <= bi) {
      printf("%d\n", ps[i].first);
      break;
    }
    k -= bi;
  }
  
  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

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

		int n = sc.nextInt();
		int x = sc.nextInt();
		int[] l = new int[n];

		int sum = 0;
		int ans = 1;
		for (int i = 0; i < n; i++) {
			sum += Integer.parseInt(sc.next());
			if (sum <= x)
				ans++;
		}

		System.out.println(ans);
	}

}


Measured memory_bytes: 21844
import bisect
cnt=0
n=int(input())
a= sorted(list(map(int, input().split())))
b= sorted(list(map(int, input().split())))
c= sorted(list(map(int, input().split())))
ab=[0]*n
bc=[0]*n
for i in range(n):
    bc[i]=bisect.bisect_left(b,c[i]-0.5)
for i in range(n):
    ab[i]=bisect.bisect_left(a,b[i]-0.5)
for i in range(1,n):
    ab[i]+=ab[i-1]
for i in range(n):
    if bc[i]!=0:
        cnt+=ab[bc[i]-1]
print(cnt)

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

#define deb(x) cout << #x << "=" << x << endl
#define ll long long

const int mod = 1000000007;
const int N = 3e5, M = N;



void solve() {
	ll a, b, n, m;
	ll input;
	cin >> n;
	vector<ll> arr(n);
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	ll cost = 0;
	ll dp[n + 1];
	dp[0] = 0;
	dp[1] = abs(arr[1] - arr[0]);
	for (int i = 2; i < n; i++)
	{
		dp[i] = min((dp[i - 1] + abs(arr[i] - arr[i - 1])), (dp[i - 2] + abs(arr[i] - arr[i - 2])));
	}
	cout << dp[n - 1] << endl;
}



int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}

	return 0;
}



Measured memory_bytes: 4752