akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

int max(int a, int b){
	return a >= b ? a : b;
}

void output(int x, int y, int **dp, char *s, char *t){
	if(dp[x][y] == 0){
		return;
	}
	else if(dp[x][y] == dp[x - 1][y]){
		output(x - 1, y, dp, s, t);
	}
	else if(dp[x][y] == dp[x][y - 1]){
		output(x, y - 1, dp, s, t);
	}
	else{
		output(x - 1, y - 1, dp, s, t);
		printf("%c", s[x]);
	}
}

int main(){
	int N, M, i, j;
	char *s = (char *)malloc(sizeof(char) * 3002);
	char *t = (char *)malloc(sizeof(char) * 3002);
	scanf("%s", &s[1]);
	scanf("%s", &t[1]);
	for(N = 1; s[N] != '\0'; N++);
	N--;
	for(M = 1; t[M] != '\0'; M++);
	M--;
	int **dp = (int **)malloc(sizeof(int *) * (N + 1));
	for(i = 0; i <= N; i++){
		dp[i] = (int *)malloc(sizeof(int) * (M + 1));
		for(j = 0; j <= M; j++){
			dp[i][j] = 0;
		}
	}
	for(i = 1; i <= N; i++){
		for(j = 1; j <= M; j++){
			dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			if(s[i] == t[j]){
				dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
			}
		}
	}
	output(N, M, dp, s, t);
	printf("\n");
	return 0;
}

Measured memory_bytes: 35456
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	bool notPrime[1000001];
	fill(notPrime,notPrime+1000001,0);
	notPrime[0]=notPrime[1]=true;
	for(int i = 2; i < 1000001; ++i)
	{
		if(notPrime[i]) continue;
		for(int j = i*2; j < 1000001; j+=i)
		{
			notPrime[j]=true;
		}
	}

	int a,d,n;
	while(cin>>a>>d>>n,a) 
	{
		int ans,cnt=0;
		for(int i = a; i < 1000001; i+=d)
		{
			if(!notPrime[i])
			{
				cnt++;
				if(cnt==n)
				{
					ans=i;
					break;
				}
			}
		}
		cout<<ans<<endl;
	}
  return 0;
}

Measured memory_bytes: 2132
#include<iostream>
using namespace std;
int main(){
  int n;
  scanf("%d",&n);
  int lap[n],dist[n],t[n+1],x[n+1],y[n+1];
  x[0]=y[0]=t[0]=0;
  for(int i=1;i<=n;i++){
    scanf("%d%d%d",&t[i],&x[i],&y[i]);
    lap[i-1]=t[i]-t[i-1];
    dist[i-1]=abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);
    }
  for(int i=0;i<n;i++){
    if(dist[i]>lap[i]||(lap[i]-dist[i])%2==1){
      printf("No \n");
      return 0;
      }
    }
  printf("Yes \n");
  return 0;
  }

Measured memory_bytes: 2176
# -*- coding: utf-8 -*-
# C

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
# import numpy as np

input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

n = int(input()) - 1
n_ = n

cnt = 0
val = 0
while True:
    if n >= val:
        cnt += 1
        val += 26 ** cnt
        # print(val)
    else:
        break

keta = cnt
# print(keta)
cnt -= 1

if cnt > 0:
    for c in range(cnt):
        n_ -= 26**(c+1)
        # print(n_)
n = n_
# print(n)

ans = []
cnt = 0
while True:
    if (int(n / 26)):
        ans.append(chr(ord('a') + (n % 26)))
        n = n // 26
        cnt += 1
    else:
        ans.append(chr(ord('a') + (n % 26)))
        break

# print(ans)

diff = keta - len(ans)
# print('diff', diff)
ans = ans + ['a'] * diff

print(''.join(ans[::-1]))


Measured memory_bytes: 65184
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    int n; cin>>n;
    map<int,int> mp;
    pair<string,int> a[n];
    rep(i,n){
        string s; cin>>s;
        int p; cin>>p;
        mp[p]=i;
        a[i]={s,-p};
    }
    sort(a,a+n);
    rep(i,n){
        cout<<mp[-a[i].second]+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
n = int(input())
A = [0] + list(map(int, input().split())) + [0]

#普通に総和を出す
sum = 0
for i, a in enumerate(A):
  if i == n+1: break #n+1はゴールなので先に行かない
  sum += abs(a - A[i+1]) #a:A[i]
  
#引いて足す
for i in range(1, n+1, 1): #1～Nを省いたとき
  nowsum = sum
  nowsum -= abs(A[i-1]-A[i])
  nowsum -= abs(A[i]-A[i+1])
  nowsum += abs(A[i-1]-A[i+1])
  print(nowsum)

Measured memory_bytes: 13920
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define rrep(i,n) for (int i = (n - 1);i >= 0;i--)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    if(a <= 2*b) cout << 0 << endl;
    else cout << a-2*b << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <cassert>
 
using namespace std;
 
typedef long long ll;
typedef ll li;
typedef pair<int,int> PI;
#define EPS (1e-10L)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define REP(i, n) rep (i, n)
#define F first
#define S second
#define mp(a,b) make_pair((a),(b))
#define list3(a,b,c) mp((a),mp((b),(c)))
#define list4(a,b,c,d) mp((a),list3((b),(c),(d)))
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(),a.end()
#define CLR(a) memset((a),0,sizeof(a))
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)
template<typename T,typename U> ostream& operator<< (ostream& out, const pair<T,U>& val){return out << "(" << val.F << ", " << val.S << ")";}
template<class T> ostream& operator<< (ostream& out, const vector<T>& val){out << "{";rep(i,SZ(val)) out << (i?", ":"") << val[i];return out << "}";}
void pkuassert(bool t){t=1/t;};
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};

string in;
int pos;
int val;

int formula(){
  if(islower(in[pos]))
    return (val>>(in[pos++]-'a'))&1;
  if(isupper(in[pos]))
    return in[pos++]=='T';
  if(in[pos]=='-'){
    ++pos;
    return !formula();
  }

  ++pos;
  int a=formula();
  char op=in[pos++];
  if(op=='-') ++pos;
  int b=formula();
  int ret;
  if(op=='+') ret=a|b;
  else if(op=='*') ret=a&b;
  else ret = !a|b;
  ++pos;
  return ret;
}

void solve(){
  int p = in.find('=');
  string a=in.substr(0,p);
  string b=in.substr(p+1);
  rep(i,(1<<11)){
    val=i;
    pos=0;
    in=a;
    int va=formula();
    pos=0;
    in=b;
    int vb=formula();
    if(va!=vb){
      cout << "NO" << endl;
      return;
    }
  }
  cout << "YES" << endl;
}

int main(){
  while(cin >> in && in!="#") solve();
}

Measured memory_bytes: 1240
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int n,q;
char t[200001],d[200001];
string s;
int solve(int x,int y){
    rep(i,q){
        if(x==-1||x==n) break;
        if(s[x]==t[i]){
            if(d[i]=='L') x--;
            else x++;
        }
    }
    if(y==0&&x==-1) return 1;
    if(y==1&&x==n) return 1;
    return 0;
}
int ok,ng,mid;
int search(int x){
  while(abs(ok-ng)>1){
    int mid=(ok+ng)/2;
    if(solve(mid,x)) ok=mid;
    else ng=mid;
  }
}
int main(){
    cin>>n>>q>>s;
    rep(i,q) cin>>t[i]>>d[i];
    ok=-1,ng=n,search(0);
    int left=ok;
    ok=n,ng=-1,search(1);
    int right=ok;
    cout<<right-left-1;
}

Measured memory_bytes: 900
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
 
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
#define endl "\n"
using namespace std;
 
//constexpr int inf = 2147483647;
//constexpr int64_t inf64 = 9223372036854775807;
//constexpr int mod = 1e9+7;
 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string s, t;
  cin >> s >> t;
  
  int res = 0;
  rep(i,3) if (s[i] == t[i]) res++;
  
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int N = S.length();
		long ans = 0;
		for(int mask = 0 ; mask < (1 << N - 1) ; mask++) {
			String s = "";
			long total = 0;
			for(int i = 0 ; i < N - 1; i++) {
				s += String.valueOf(S.charAt(i));
				if((mask & 1 << i) != 0) {
					s += ",";
				}
			}
			s += String.valueOf(S.charAt(N - 1));
			if(s.contains(",")) {
				String[] c = s.split(",");
				for(int i = 0 ; i < c.length ; i++) {
					total += Long.valueOf(c[i]);
				}
			} else {
				total += Long.valueOf(s);
			}
			ans += total;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 24020
use proconio::input;

fn main() {
    input! { x: usize }
    let n_max = x / 100;
    let mut exists = false;
    'outer: for i in 0..=n_max {
        for j in 0..=n_max - i {
            for k in 0..=n_max - i - j {
                for l in 0..=n_max - i - j - k {
                    for m in 0..=n_max - i - j - k - l {
                        if (x - (i * 101 + j * 102 + k * 103 + l * 104 + m * 105)) % 100 == 0 {
                            exists = true;
                            break 'outer;
                        }
                    }
                }
            }
        }
    }
    println!("{}", if exists { 1 } else { 0 });
}


Measured memory_bytes: 2140
n,m=map(int,input().split())
h=list(map(int,input().split()))
h.insert(0,0)
s=set()
for i in range(m):
	a,b=map(int,input().split())
	if h[a]<=h[b]:s.add(a)
	if h[a]>=h[b]:s.add(b)
print(n-len(s))

Measured memory_bytes: 20112
N = int(input())
L = sorted([int(x) for x in input().split()])

ans = 0
for i in range(N):
    for j in range(i+1, N):
        for k in range(j+1, N):
            if L[i] == L[j] or L[j] == L[k] or L[k] == L[i]:
                continue
            if L[k] < L[i] + L[j]:
                ans += 1

print(ans)


Measured memory_bytes: 9116
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			int N = scan.nextInt();
			long count = 0;
			for(int i =1;i<=N;i++) {
				if(i%3!=0&&i%5!=0) {
					count+=i;
				}
			}
			
			System.out.println(count);
			
		}
		
		
	}
		
	

}

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

int n, k;
vector<string> v;
set<string> s;

void dfs(string str, int flag, int count) {
    if (count == k) {
        s.insert(str);
        return ;
    }
    for (int i = 0; i < n; i++) {
        if (flag & (1 << i)) continue;
        dfs(str + v[i], flag | (1 << i), count + 1);
    }
}

int main() {
    while (cin >> n >> k, n || k) {
        v.resize(0);
        for (int i = 0; i < n; i++) {
            string str;
            cin  >> str;
            v.push_back(str);
        }

        s.clear();
        dfs("", 0, 0);
        cout << s.size() << endl;
    }

    return 0;
}

Measured memory_bytes: 3268
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String num = br.readLine();

		double dnum = Double.parseDouble(num);

		String s = String.format("%.5f", dnum*dnum*Math.PI);
		String s2 = String.format("%.5f", dnum*2*Math.PI);

		System.out.println(s+" "+s2);



	}
}

Measured memory_bytes: 24812
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();

		System.out.println(Math.max(A * B, C * D));
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}
}


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

using ll = long long;

#define mod 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)

using namespace std;

//long C(long n, long r);
//long long gcd(long long a, long long b);
//long long lcm(long long a, long long b);
 

void solve() {
    int N;
    cin >> N;
    int ans = 0;
    map<int, int> m;
    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        if(m.find(a) == m.end()){
            m[a] = 0;
        }
        m[a]++;
    }
    for(auto &x : m){
        if(x.second % 2 != 0) ans++;
    }
    cout << ans << endl;
}
 
int main() {
    solve();
    return 0;
}

Measured memory_bytes: 4992
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	
	n := nextInt()
	for i := 0; i < n; i++ {
		if num := nextInt(); num % 2 == 0 {
			if num % 3 != 0 && num % 5 != 0 {
				fmt.Println("DENIED")
				return
			}
		}
	}
	fmt.Println("APPROVED")
}

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}


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

typedef long long ll;

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

	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());

	int N = a[0] / 2, d=(int)1e9, k;

	for (int i = 1; i < n; i++) {
		if (d > abs(N - a[i])) {
			d = abs(N-a[i]);
			k = a[i];
		}
	}

	cout << a[0] <<" "<< k << endl;
}


Measured memory_bytes: 640
-- 135B 0 or 1 swap

main :: IO()
main = do
  n_str <- getLine
  let n = read n_str :: Int
  s_str <- getLine
  let source = take n (map read (words s_str) :: [Int])
  let hint = solve source 0
  if hint == 0
    then
    putStrLn("YES")
    else
    putStrLn("NO")

solve :: [Int] -> Int -> Int
solve (x:xs:xs2) c =
  if x > xs
  then
    solve (xs:xs2) (abs(c) - abs(x - xs))
  else
    solve (xs:xs2) c
solve x c = c


Measured memory_bytes: 764
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string> //文字列
#include <iomanip> //doubleの桁数指定 setprecision()
#include <list> //前後に数値を入れれる配列
#include <map> //map
#include <vector> //vecror

#define REP(i,m,n) for(ll i = (ll) (m);i < (ll) (n);i++) //forの短縮
#define rep(i,n) REP(i,0,n) //REPが0の時
#define ll long long int

using namespace std;

double PI = acos(-1); //円周率
ll mod = 1e9 + 7;


//提出コード↓

double r;

int main() {
	cin >> r;
	cout << 2 * r * 3.141592 << endl;



	return 0;
}



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

using namespace std;
typedef long long ll;
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)

int main(){
	ll a,b,c; cin>>a>>b>>c;
	set<ll> se;
	se.insert(a);
	se.insert(b);
	se.insert(c);
	cout<<se.sz;
}

Measured memory_bytes: 256
from itertools import product
from itertools import combinations
import numpy as np

def resolve():
  N, M, X = map(int, input().split(" "))

  books = []
  for i in range(N):
    CA = [int(x) for x in input().split(" ")]
    books.append(CA)

  books = np.array(books)


  if N == 1:
    if np.all(books[:, 1:] >= X):
      print(books[0][0])
    else:
      print(-1)
    return True
  books_index_pattarns = [list(x) for i in range(1, N+1) for x in combinations(range(0, N), i)]
  books_result = np.array([np.sum(books[x], axis=0) for x in books_index_pattarns])
  books_result = books_result[np.all(books_result[:,1:] >= X, axis=1)]

  if len(books_result) == 0:
    print(-1)
    return True
  elif len(books_result) == 1:
    print(books_result[0][0])
    return True
  else:
    # print(books_result)
    print(books_result[:,:1].min())
    return True

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 29108
n=int(input())
al=['a','b','c','d','e','f','g','h','i','j','k']
a=[['a',0]]
b=[]
for k in range(n-1):
    for i in a:
        for j in range(i[1]+2):
            b.append([i[0]+al[j],max(i[1],j)])
    a=b
    b=[]
a.sort(key=lambda x:x[0])
for i in a:
    print(i[0])

Measured memory_bytes: 29504
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector.Unboxed as VU
import qualified Data.Map.Strict as M

main = abc163d

abc163d = do
    [n,k] <- getIntList
    let len = fromIntegral n + 1 :: Int
    print $ mod (solveD len (fromIntegral k) 0) (10^9 + 7)

solveD len k ans
    | len == k = ans + 1
    | otherwise = solveD len (k + 1) (ans + max - min + 1)
    where min = k * (k - 1) `div` 2
          max = min + k * (len - k)

readInt = fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words
getIntList = readIntList <$> BS.getLine

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

int main() {

    int N;
    cin >> N;

    vector<int> A(N) ;
    vector<int> B(N) ;
        
    for (int &a : A)
        cin >> a;
    
    int chk=0;

    while (true)
    {
        for (int i =0;i<N;i++){
            B.at(i) = A.at(i) % 2;
        }
    
        if (accumulate(B.begin(),B.end(),0) ==0){
        
            chk++;
        
            for (int &a : A){
                a= a/2  ;
            }
        
        }else{
            break;
        } 
        

 
    }
    
 
    cout << chk <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX 1000000007
long long func(long long n);
int main(){
    long long n,m; cin >> n >> m;
    if(abs(n-m) > 1){
        cout << 0 << endl;
        return 0;
    }
    long long N,M;
    N = func(n); M = func(m);
    long long ans = N*M;
    if(n == m) ans *= 2;
    cout << ans % MAX << endl;
}

long long func(long long n){
    if(n == 1) return 1;
    return (n * func(n-1)) % MAX;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>

using namespace std;

int main(void) {
	int n;
	long t;
	long a;
	long sum_t, sum_a;
	long rate;
	cin >> n;
	cin >> sum_t >> sum_a;
	for (int i = 1; i < n; ++i) {
		cin >> t >> a;
		int rest_t, rest_a;
		rest_t = sum_t % t;
		rest_a = sum_a % a;
		if (rest_t == 0) rest_t = t;
		if (rest_a == 0) rest_a = a;
		rate = max((sum_t + t - rest_t) / t, (sum_a + a - rest_a) / a);
		sum_t = t*rate;
		sum_a = a*rate;
	}
	cout << sum_t + sum_a << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// スペース区切りの整数の入力
		String str = sc.next();
      	str = str.replace("0","");
		// 出力
		System.out.println(str.length());
	}
}

Measured memory_bytes: 21972
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
using namespace std;
struct Node {
    int left;
    int right;
};
 
Node T[100];
int PreOrder[100], InOrder[100];
int NumOfNode;
 
 
 
void printPost(int node) {
    if (node == -1) {
        ;
    }
    else {
        printPost(T[node].left);
        printPost(T[node].right);
        if (NumOfNode-- != 1) {
            printf("%d ", node);
        }
        else {
            printf("%d\n", node);
        }
    }
}
 
 
 
void makeTree(int PreBegin, int PreEnd, int InBegin, int InEnd) {
    int root = PreOrder[PreBegin];
    int PreLeftSubtreeBegin, PreLeftSubtreeEnd, PreRightSubtreeBegin, PreRightSubtreeEnd, InLeftSubtreeBegin, InLeftSubtreeEnd, InRightSubtreeBegin, InRightSubtreeEnd;
    for (int i = InBegin; i <= InEnd; ++i) {
        if (InOrder[i] == root) {
            PreLeftSubtreeBegin = PreBegin + 1;
            PreLeftSubtreeEnd = PreBegin + i - InBegin;
            PreRightSubtreeBegin = PreLeftSubtreeEnd + 1;
            PreRightSubtreeEnd = PreEnd;
            InLeftSubtreeBegin = InBegin;
            InLeftSubtreeEnd = i - 1;
            InRightSubtreeBegin = i + 1;
            InRightSubtreeEnd = InEnd;
            break;
        }
    }
    if (PreLeftSubtreeBegin > PreLeftSubtreeEnd) {
        //the left subtree is empty
        T[root].left = -1;
    }
    else {
        //the left subtree is not empty
        T[root].left = PreOrder[PreLeftSubtreeBegin];
        makeTree(PreLeftSubtreeBegin, PreLeftSubtreeEnd, InLeftSubtreeBegin, InLeftSubtreeEnd);
    }
 
    if (PreRightSubtreeBegin > PreRightSubtreeEnd) {
        //the right subtree is empty
        T[root].right = -1;
    }
    else {
        //the right subtree is not empty
        T[root].right = PreOrder[PreRightSubtreeBegin];
        makeTree(PreRightSubtreeBegin, PreRightSubtreeEnd, InRightSubtreeBegin, InRightSubtreeEnd);
    }
}
 
int main() {
    int n;
    scanf("%d", &n);
    NumOfNode = n;
 
    for (int i = 0; i < n; i++) {
        scanf("%d", &PreOrder[i]);
    }
    for (int i = 0; i < n; i++) {
        scanf("%d", &InOrder[i]);
    }
 
    makeTree(0, n - 1, 0, n - 1);
    printPost(PreOrder[0]);
 
    return 0;
}


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

#define rng(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define urng(i, a, b) for(int i = int(b) - 1; i >= int(a); i--)
#define urep(i, b) urng(i, 0, b)
#define pb push_back
#define eb emplace_back
#define F first
#define S second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed

int main() {
  //int n, a, b, ans = 0;
  //string s, t;
  ll a, b, k;
  cin >> a >> b >> k;
  //vector<int> v(n), c(n);
  if(k >= a + b) cout << "0 0\n";
  else if(k >= a) cout << "0 " << b - k + a << endl;
  else cout << a - k << " " << b << endl;
  //for(int i = 0; i < n; i++){}
}

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

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;
}

ll gcf(ll a, ll b){
    if(b == 0) return a;
    return gcf(b, a%b);
}

ll lcm(ll a, ll b){
    ll g = gcf(a, b);
    return a/g * b;
}
int main(void){
    ll A,B,C,D; cin >> A >> B >> C >> D;
    ll ans = B-(A-1);
    
    ans -= (B/C - (A-1)/C);
    ans -= (B/D - (A-1)/D);
    
    ll lc = lcm(C,D);
    ans += (B/lc - (A-1)/lc);

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >>S;
  if(S.at(5)=='1'){cout<<"TBD"<<endl;
                }else if(S.at(5)=='0'&&(S.at(6)=='1'||S.at(6)=='2'||S.at(6)=='3'||S.at(6)=='4')){
    cout<<"Heisei"<<endl;
  }
  else{cout<<"TBD"<<endl;
       }
}


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

int N, A, B;

int measure(int n) {
  int m = 0;
  while (n) {
    m += n % 10;
    n /= 10;
  }
  return m;
}

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

  int res = 0;
  for (int n = 1; n <= N; ++n) {
    int m = measure(n);
    if (m >= A && m <= B) res += n;
  }
  cout << res << '\n';
}

Measured memory_bytes: 256
N,M = map(int,input().split())
L = []
for _ in range(M):
  k = list(map(int,input().split()))
  L.append(k)

sup = []
inf = []
  
for i in range(len(L)):
  sup.append(L[i][1])
  inf.append(L[i][0])
  
sup = min(sup)
inf = max(inf)

if sup - inf < 0:
  print(0)
else:
  print(sup - inf + 1)

Measured memory_bytes: 29076
# 2入力
H, W = map(int, input().split())

if H == 1 or W == 1:
    print(1)
else:
    mass = 0
    if W % 2 != 0:
        if H % 2 != 0:
            mass += (int(H / 2) + 1) * (int(W / 2) + 1)
            mass += (int(H / 2)) * (int(W / 2))
            print(mass)
        else:
            mass += (int(H / 2)) * (int(W / 2) + 1)
            mass += (int(H / 2)) * (int(W / 2))
            print(mass)

    else:
        if H % 2 != 0:
            mass += (int(H / 2) + 1) * (int(W / 2))
            mass += (int(H / 2)) * (int(W / 2))
            print(mass)
        else:
            mass += (int(H / 2)) * (int(W / 2))
            mass += (int(H / 2)) * (int(W / 2))
            print(mass)

Measured memory_bytes: 38384
#include<cstdio>
#include<cstring>
int s[2][2]={0,1,1,0},m,n,bbb,sum,maxx;
char a[10000][10000];
void dfs(int x,int y)
{
    int xx,yy;
    if(x==m-1&&y==n-1){bbb=1;return;}
    for(int i=0;i<2;i++)
    {if(x==m-1&&y==n-1){bbb=1;return;}
         xx=x+s[i][0];
         yy=y+s[i][1];
         if(a[xx][yy]=='#'&&xx>=0&&xx<m&&yy>=0&&yy<n)
          {
               a[xx][yy]='*';sum=sum+1;//printf("%d %d\n",xx,yy);
               dfs(xx,yy);
          }
    }
}
int main()
{
     while(scanf("%d%d",&m,&n)==2)
     {
          sum=1;bbb=0;maxx=0;
          for(int i=0;i<m;i++)
               scanf("%s",a[i]);
          for(int i=0;i<m;i++)
               for(int j=0;j<n;j++)
               if(a[i][j]=='#')
               maxx=maxx+1;
          dfs(0,0);
          a[0][0]='*';
          //printf("%d %d",maxx,sum);
          if(bbb==1&&maxx==m+n-1)
          printf("Possible\n");
          else printf("Impossible\n");
     }
     return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cassert>
#include <cmath>
#include <map>

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 200000;
int v[1 + nmax], st[1 + nmax], dr[1 + nmax];

int main() {
  int n;
  std::cin >> n;
  for(int i = 1;i <= n; i++)
    std::cin >> v[i];
  v[0] = v[n + 1] = 0;
  for(int i = 1;i <= n; i++) {
    st[i] = i - 1;
    while(v[i] < v[st[i]])
      st[i] = st[st[i]];
  }
  for(int i = n; 1 <= i; i--) {
    dr[i] = i + 1;
    while(v[i] < v[dr[i]])
      dr[i] = dr[dr[i]];
  }
  ll result = 0;
  for(int i = 1;i <= n; i++)
    result += 1LL * v[i] * (i - st[i]) * (dr[i] - i);
  std::cout << result;
  return 0;
}


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

int main(){
	string s;
	cin >> s;
	stack<char> st;
	rep(i,s.size()){
		if(s[i] == '1'){
			st.push('1');
		}
		if(s[i] == '0'){
			st.push('0');
		}
		if(s[i] == 'B'){
			if(!st.empty()){
				st.pop();
			}
		}
	}
	
	string ans = "";
	while(!st.empty()){
		ans.push_back(st.top());
		st.pop();
	}
	
	reverse(ans.begin(),ans.end());
	
	cout << ans << endl;
    return 0;
}



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

void hord(char& a, char& b){
    if (a == 'H' && b == 'H'){
        cout << 'H' << endl;
    }else if (a == 'H' && b == 'D'){
        cout << 'D' << endl;
    }else if (a == 'D' && b == 'H'){
        cout << 'D' << endl;
    }else {
        cout << 'H' << endl;
    }
}

int main() {
    char a,b;
    cin >> a >> b;
    hord(a,b);
    return 0;
}

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define dump(x)
#define debug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

signed main(){
    int q;
    cin >> q;
    rep(_,0,q) {
        string x, y;
        cin >> x >> y;
        vector<vector<int>> dp(x.size()+1, vector<int>(y.size()+1));
        rep(i,1,x.size()+1) {
            rep(j,1,y.size()+1) {
                dp[i][j] = ((x[i-1] == y[j-1]) ? (dp[i-1][j-1] + 1) : max(dp[i][j-1], dp[i-1][j]));
            }
        }
        cout << dp.back().back() << endl;
    }
}



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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  string k; cin >> k;
  int d; cin >> d;
  int sz = SZ(k);
  
  if(d == 1) {
    reverse(k.begin(), k.end());
    ll ans = 0;
    ll mul = 1;
    for(int i=0;i<sz;++i) {
      ans += mul * (k[i] - '0') % MOD;
      ans %= MOD;
      mul *= 10;
      mul %= MOD;
    }
    cout << ans << endl;
    return 0;
  }

  vvll dp(sz+1, vll(d, 0));
  for(int i=0;i<=9;++i) {
    dp[sz][i%d] += 1;
  }
  for(int i=sz-1;i>=0;--i) {
    for(int j=0;j<d;++j) {
      for(int k=0;k<=9;++k) {
        dp[i][(j+k)%d] += dp[i+1][j];
        dp[i][(j+k)%d] %= MOD;
      }
    }
  }

  vvll dp2(sz+1, vll(d, 0));
  for(int i=0;i<=k[sz-1]-'0';++i) {
    dp2[sz][i%d] += 1;
  }
  for(int i=sz-1;i>=1;--i) {
    int now = k[i-1] - '0';
    for(int j=0;j<now;++j) {
      for(int k=0;k<d;++k) {
        dp2[i][(j+k)%d] += dp[i+1][k];
        dp2[i][(j+k)%d] %= MOD;
      }
    }
    for(int k=0;k<d;++k) {
      dp2[i][(now+k)%d] += dp2[i+1][k];
      dp2[i][(now+k)%d] %= MOD;
    }
  }
  


  cout << (dp2[1][0] + MOD - 1) % MOD << endl;

}


Measured memory_bytes: 16640
n=int(input())
dic={}
ans=0
d=input().split(" ")
for i in range(0,len(d)):
    k=int(d[i])
    if i-k in dic:
        ans+=dic[i-k]
    if i+k in dic:
        dic[i+k]+=1
    else:
        dic[i+k]=1
print(ans)


Measured memory_bytes: 46312
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll x[101000] , w[101000] , n , c , ans , Max1[101000] ,Max2[101000], sum;
ll read()
{
	ll x=0; ll f=1;char s=getchar();
	for(;s<'0'||s>'9';s=getchar()) if(s=='-') f=-1;
	for(;s>='0'&&s<='9';s=getchar()) x=(x<<3)+(x<<1)+s-48;
	x*=f;
    return x;
}

int main()
{
	n = read();c = read();
	for(int i = 1;i <= n;++i) 
	 x[i] = read() , w[i] = read();
	for(int i = 1;i <= n;++i)
	 sum += w[i] , Max1[i] = max( Max1[i-1] , sum - x[i]);
	sum = 0;
	ans = Max1[n];
	for(int i = n;i >= 1;--i)
	 sum += w[i] , Max2[i] = max ( Max2[i+1] , sum - (c - x[i]));
	sum = 0;ans = max(ans , Max2[1]);
	for(int i = 1;i <= n;++i)
	 sum += w[i],ans = max ( ans , Max2[i + 1] + sum - x[i] * 2);
    sum = 0;
    for(int i = n;i >= 1;--i)
     sum += w[i],ans = max ( ans , Max1[i - 1] + sum - (c - x[i]) * 2);
    printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define REP(i,n)for (int i=0;i<(n);i++)
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ll long long
using namespace std;
int main(){
    int n,a,rest;
    char c[100];
    while(1){
        string ans = "TIE";
        int ans_num;
        cin>>n;
        if(n==0)break;
        REP(i,n)cin>>c[i];
        vector<pair<int,int> > cnt(26);
        REP(i,26)cnt[i].second = i;
        REP(i,n){
            a = c[i] - 'A';
            REP(j,26)if(cnt[j].second == a)cnt[j].first--;
            sort(ALL(cnt));
            rest = n-i-1;
            //cout<<cnt[0].first<<" "<<cnt[1].first<<endl;
            if(cnt[0].first * (-1) - cnt[1].first * (-1) > rest){
                ans = cnt[0].second + 'A';
                ans_num = i + 1;
                break;
            }
        }
        cout<<ans;
        if(ans!="TIE"){
            cout<<" "<<ans_num;
        }
        cout<<endl;
    }
}

Measured memory_bytes: 3168
S = input()

a = "01"*(10**5)
b = "10"*(10**5)
acnt = 0
bcnt = 0
for i in range(len(S)):
  if a[i] != S[i]:
    acnt += 1
  if b[i] != S[i]:
    bcnt += 1
print(min(acnt, bcnt))

Measured memory_bytes: 3504
import collections

L = [3,5,7]
Q = collections.deque(L)
A = []


for i in range (0, 40000):
	V = Q.popleft()
	A.append(V)
	Q.append(V*10+3)
	Q.append(V*10+5)
	Q.append(V*10+7)

import bisect

D = []

for i in range (0, 40000):
	V = str(A[i])
	if V.count('3') > 0 and V.count('5') > 0 and V.count('7') > 0:
		D.append(int(V))

N = int(input())
print(bisect.bisect_right(D, N))

Measured memory_bytes: 17128
from fractions import gcd

n = int(input())
aaa = list(map(int, input().split()))
p = aaa[0]
f = [p]
for a in aaa[1:-1]:
    p = gcd(p, a)
    f.append(p)
aaa.reverse()
p = aaa[0]
b = [p]
for a in aaa[1:-1]:
    p = gcd(p, a)
    b.append(p)
b.reverse()

f = [b[0]] + f
b = b + [f[-1]]

print(max(gcd(p, q) for p, q in zip(f, b)))


Measured memory_bytes: 16152
#include <bits/stdc++.h>
 
using namespace std;
 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define debug(x) cerr << #x << ": " << x << endl
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
 
template <typename T1, typename T2> bool chkmin(T1 &x, T2 y) { return y < x ? (x = y, true) : false; }
template <typename T1, typename T2> bool chkmax(T1 &x, T2 y) { return y > x ? (x = y, true) : false; }

bool good(char c1, char c2) {
  return c1 == c2 || c1 == '?' || c2 == '?';
}

const int maxN = 6003;
bool can[3][3][maxN];

signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifdef DEBUG
  freopen("in", "r", stdin);
#endif

  vector<string> s(3, "");
  for (int i = 0; i < 3; ++i) {
    cin >> s[i];
  }
  vector<int> ord(3);
  iota(all(ord), 0);
  int ans = s[0].size() + s[1].size() + s[2].size();
  do {
    for (int p = 0; p < 3; ++p) {
      for (int q = p + 1; q < 3; ++q) {
        fill(can[p][q], can[p][q] + maxN, 1);
        for (int i = 0; i < s[ord[p]].size(); ++i) {
          bool &ok = can[p][q][i];
          for (int u = 0; u < s[ord[q]].size() && i + u < s[ord[p]].size(); ++u) {
            ok &= good(s[ord[q]][u], s[ord[p]][i + u]);
          }
        }
      }
    }
    for (int i = 0; i <= s[ord[0]].size(); ++i) {
      for (int j = i; j <= i + s[ord[1]].size() || j <= s[ord[0]].size(); ++j) {
        if (can[0][1][i] && can[0][2][j] && can[1][2][j - i]) {
          chkmin(ans, max(s[ord[0]].size(), max(i + s[ord[1]].size(), j + s[ord[2]].size())));
        }
      }
    }
  } while (next_permutation(all(ord)));
  cout << ans << '\n';

  return 0;
}




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

void disp (char x) {
    cout << x;
}

int main() {
    vector<char> s;
    string l;
    cin >> l;
    for (int i = 0; i < l.length(); i++) {
        if (l[i] == 'B' && s.size() != 0) s.erase(s.end()-1);
        else if (l[i] == 'B' && s.size() == 0) continue;
        else s.push_back(l[i]);
    }
    for_each(s.begin(), s.end(), disp);
    cout << endl;
}

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

n, k = map(int, input().split())

a = [1] * (n + 1)
a[0] = 0

for _ in range(k):
    d = int(input())
    b = [int(x) for x in input().split()]

    for x in b:
        a[x] = 0

print(sum(a))

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    ll y;
    cin >> n >> y;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n - i; j++) {
            if (y == 10000 * i + 5000 * j + 1000 * (n - j - i)) {
                cout << i << " " << j << " " << n - i - j << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<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;}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N; cin >> N;
    vc<pi> v;
    rep(i,N){
        int a,b; cin >> a >> b;
        v.eb(a+b,a-b);
    }
    sort(all(v));
    int ans=0,t=-1000000010;
    rep(i,N){
        if(t<=v[i].se){
            ans++;
            t=v[i].fi;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
int main() {
    int K;
    cin >> K;
    queue<long long> Q;
    for(int i=1;i<10;i++) Q.push(i);
            long long x;
    for(int i=0;i<K;i++){
        x = Q.front();
        Q.pop();
        if(x%10 !=0) Q.push(10*x+(x%10)-1);
        Q.push(10*x+(x%10));
        if(x%10 !=9) Q.push(10*x+(x%10)+1);
    }
    cout << x << endl;
}

Measured memory_bytes: 1792
// ABC157E - Simple String Queries

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

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

	vector< set<int> > alpha(26);

	for (int i = 0; i < N; i++) {
		char c;
		cin >> c;
		alpha.at(c - 'a').insert(i + 1);
	}

	int Q;
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		int op;
		cin >> op;
		if (op == 1) {
			int iq;
			char cq;
			cin >> iq >> cq;

			for (int j = 0; j < 26; j++) {
				alpha.at(j).erase(iq);
			}
			alpha.at(cq - 'a').insert(iq);
		} else if (op == 2) {
			int l, r;
			cin >> l >> r;

			int answer = 0;
			for (int j = 0; j < 26; j++) {
				set<int>::iterator it;
				it = alpha.at(j).lower_bound(l);
				if ((it != alpha.at(j).end())&&(*it <= r)) {
					answer++;
				}
			}
			cout << answer << endl;
		}
	}
}


Measured memory_bytes: 23680
def main():
    h,w=map(int,input().split())
    grid=[list(map(int,input().split())) for i in range(h)]
    
    ans=[]
    for i in range(h):
        for j in range(w-1):
            if grid[i][j]%2!=0:
                grid[i][j+1]+=1
                ans.append([i+1,j+1,i+1,j+2])
    for i in range(h-1):
        if grid[i][w-1]%2!=0:
            grid[i+1][w-1]+=1
            ans.append([i+1,w,i+2,w])
    n=len(ans)
    print(n)
    for i in range(n):
        print(*ans[i])
if __name__=='__main__':
    main()

Measured memory_bytes: 30280
import numpy as np
import math
S = input()
ans = np.zeros(len(S))
len_r = 0
len_l = 0
for i in range(len(S)):
  if S[i] == "R":
    if S[(i+1)%len(S)] == "L":
      r_idx = i
      l_idx = i+1
    len_r += 1
  else:
    len_l += 1
    if S[(i+1)%len(S)] == "R":
      ans[r_idx] = math.ceil(len_r/2)+math.ceil((len_l-1)/2)
      ans[l_idx] = math.ceil(len_l/2)+math.ceil((len_r-1)/2)
      #print (len_r,len_l)
      len_r = 0
      len_l = 0
print (" ".join(ans.astype(np.int).astype(np.str)))


Measured memory_bytes: 33336
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
    double n,m,a,atotal=0;
    cin >> n >> m;
    vector<double> v;
    rep(i,n){
        cin >>a;
        atotal +=a;

        v.push_back(a);
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    if(v[m-1]>=atotal/(4*m)){
        cout << "Yes" << endl;
    }else{
         cout <<"No"<<endl;
    }
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
using namespace std;
const int N=405,P=998244353;
void upd(int&a,int b){ a=a+b>=P?a+b-P:a+b; }
char s[N]; 
int ans,n,f[N][N][N],g[N][N][N]; 
int main(int argc,char *argv[]){
	scanf("%s",s+1); 
	n=strlen(s+1); 
	f[0][0][0]=1;
	rep(i,0,n)rep(j,0,i)rep(k,0,i)if(f[i][j][k]){
		int c0=(s[i+1]=='0')+(s[i+2]=='0'); 
		int c1=(s[i+1]=='1')+(s[i+2]=='1'); 
		if(i+2<=n&&c0)f[i+2][j+1][k]|=f[i][j][k]; 
		if(i+1<=n&&s[i+1]=='1'&&j>=1)f[i+1][j-1][k+1]|=f[i][j][k];
		if(i+2<=n&&c1)f[i+2][j][k+1]|=f[i][j][k];
		if(i+1<=n&&s[i+1]=='0'&&k>=1)f[i+1][j+1][k-1]|=f[i][j][k];
		f[i+1][j][k]|=f[i][j][k];
	}
	g[n+1][0][0]=1;
	dec(i,n+1,1)rep(j,0,n)rep(k,0,n-j){
		if(s[i-1]=='0'){
			upd(g[i-1][j][k],g[i][j][k]);
			upd(g[i][j][k+1],g[i][j][k]); 
		}else{
			upd(g[i][j+1][k],g[i][j][k]); 
			upd(g[i-1][j][k],g[i][j][k]); 
		}
		if(f[i-1][j][k]&&g[i][j][k])upd(ans,g[i][j][k]);
	}
	printf("%d\n",(ans-1+P)%P); 
	return 0; 
}


Measured memory_bytes: 185492
H, W, A, B = map(int, input().split())

MOD = 10 ** 9 + 7


def get_fact_list(n: int) -> list:
    result_list = [1]
    tmp = 1
    for i in range(n):
        tmp = (tmp * (i + 1)) % MOD
        result_list.append(tmp)

    return result_list


def get_inv_list(n: int, fact_lit: list) -> list:
    result_list = [1]

    for i in range(n):
        result_list.append(pow(fact_lit[i + 1], MOD - 2, MOD))

    return result_list


def comb(n: int, m: int, fact_list: list, inv_list: list) -> int:
    return (fact_list[n] * inv_list[m] * inv_list[n - m]) % MOD


h = H - A
w = W - B
ways = 0
fact = get_fact_list(H + W)
inv = get_inv_list(H + W, fact)

while h > 0 and w > 0:
    h -= 1
    w -= 1
    ways += (comb(H - A + B - 1, h, fact, inv) * comb(W + A - B - 1, w, fact, inv)) % MOD

print(ways % MOD)

Measured memory_bytes: 18924
// Problem : A - Payment
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

inline int gi()
{
    int f = 1, x = 0; char c = getchar();
    while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return f * x;
}

inline LL gl()
{
    LL f = 1, x = 0; char c = getchar();
    while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return f * x;
}

const int INF = 0x3f3f3f3f, N = 100003, M = N << 1;

int n, m;

int main()
{
    //File("");
    n = gi();
    int now = n / 1000;
    if (n % 1000 == 0) puts("0");
    else cout << (now + 1) * 1000 - n << endl;
    return 0;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,m;
const int maxn=101000;
typedef long long ll;
const int N=1e5+100;
const int mod=1e9+7;
ll qpow(ll x,ll y)
{
    ll sum=1;
    while(y)
    {
        if(y&1)
            sum=sum*x%mod;
        y/=2;
        x=x*x%mod;
    }
    return sum;
}
ll fac[N];
ll C(ll m,ll n)
{
    return fac[n]*qpow(fac[m],mod-2)%mod*qpow(fac[n-m],mod-2)%mod;
}
ll a[N];
int main()
{
    int n,m,k;
    cin>>n>>m>>k;
    printf("%d",k/max(n,m)+(k%max(m,n)==0?0:1));
    return 0;
}
/*
    fac[0]=1;
    for(int i=1; i<=n; i++)
    {
        fac[i]=fac[i-1]*i%mod;
    }
*/



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
int cnt(int x) {
  int ret = 0;
  while (x) {
    ret += x % 10;
    x /= 10;
  }
  return ret;
}
int main() {
  cin >> n;
  int ans = 0x3f3f3f3f;
  for (int i = 1; i <= n / 2; i++) {
    int a = i, b = n - i;
    ans = min(cnt(a) + cnt(b), ans);
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
  int N;
  cin>>N;
  int a[N+1];
  vector<int> v;
  int mx=-1000010,mn=1000010;

  for(int i=1;i<=N;i++){
    cin>>a[i];
    mx=max(mx,a[i]);
    mn=min(mn,a[i]);
  }
  int mx_n,mn_n;
  for(int i=1;i<=N;i++){
    if(mx==a[i]) mx_n=i;
    if(mn==a[i]) mn_n=i;
  }
  cout<<2*N-1<<endl;
  if(abs(mx)>abs(mn)){
    for(int i=1;i<=N;i++){
      cout<<mx_n<<" "<<i<<endl;
    }
    for(int i=1;i<N;i++){
      cout<<i<<" "<<i+1<<endl;
    }
  }else{
    for(int i=1;i<=N;i++){
      cout<<mn_n<<" "<<i<<endl;
    }
    for(int i=N;i>1;i--){
      cout<<i<<" "<<i-1<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int h = in.nextInt();
            int w = in.nextInt();
            int a = in.nextInt();
            int b = in.nextInt();
            for (int na = 0; na <= h; ++na) {
                for (int nb = 0; nb <= w; ++nb) {
                    if (na * a + (h - na) * (w - a) == nb * b + (w - nb) * (h - b)) {
                        long[] togo = new long[w];
                        Arrays.fill(togo, h - b);
                        for (int i = 0; i < nb; ++i) togo[i] = b;
                        for (int i = 0; i < w; ++i) togo[i] = togo[i] * w + i;
                        char[] res = new char[w];
                        for (int r = 0; r < h; ++r) {
                            int need = (r < na) ? a : w - a;
                            Arrays.sort(togo);
                            Arrays.fill(res, '0');
                            for (int i = 0; i < need; ++i) {
                                int at = (int) (togo[w - 1 - i] % w);
                                res[at] = '1';
                                togo[w - 1 - i] -= w;
                            }
                            out.println(new String(res));
                        }
                        return;
                    }
                }
            }
            out.println(-1);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



Measured memory_bytes: 31828