akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
template<class T>bool chmax(T &a,const T &b){if(a<b){ a=b; return 1;}}
template<class T>bool chmin(T &a,const T &b){if(b<a){ a=b; return 1;}}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF 4000000000000000037 //1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;

void Main(){

  string S,T;
  cin>>S>>T;

  int slen=S.length();
  int tlen=T.length();

  vector<string> ans;
  rep(i,slen-tlen+1){
    bool ok=true;
    string buff=S;
    rep(j,tlen){
      if(S[i+j]!=T[j] and S[i+j]!='?') ok=false;
      if(S[i+j]=='?') buff[i+j]=T[j];
    }
    if(ok){
      rep(j,slen){
        if(buff[j]=='?') buff[j]='a';
      }
      ans.emplace_back(buff);
    }
  }
  SORT(ans);

  cout<< ( ans.size()==0 ? "UNRESTORABLE" : ans[0] )<<"\n";
}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <functional>
#include <array>

using namespace std;

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

    int now = b - a;
    int64_t ans = (1 + now) * now / 2 - b;
    cout << ans << endl;
}

Measured memory_bytes: 256
def findSumOfDigits(n):
  sum = 0
  while n > 0:
    sum += n % 10
    n = int(n/10)
  return sum

N, A, B = list(map(int, input().split()))
total = 0
for i in range(1, N+1):
  if A <= findSumOfDigits(i) <= B:
    total += i

print(total)


Measured memory_bytes: 2940
import math

a,b,h,m = map(int, input().split())

h = h*30 + 0.5*m
m *= 6

deg =abs(m - h)

ab2 = a**2 + b**2 -2*a*b*math.cos(math.radians(deg))
ab = ab2**0.5

print(ab)

Measured memory_bytes: 9496
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

bool is_prime[100000];
int dp[100000];

signed main(){
	memset(is_prime,true,sizeof(is_prime));
	is_prime[0]=is_prime[1]=false;
	vector<int>prime;
	for(int i=2;i<100000;i++){
		if(is_prime[i]){
			if(i%5==1)prime.push_back(i);
			for(int j=2*i;j<100000;j+=i)is_prime[j]=false;
		}
	}
	int n;cin>>n;
	rep(i,n){
		if(i)printf(" ");
		printf("%d",prime[i]);
	}
	cout<<endl;
}

Measured memory_bytes: 384
book = {}
while True:
    a = b = 0
    try:
        a, b = input().split()
        b = int(b)
        if a in book:
            book[a].append(b)
        else:
            book[a] = [b]
    except:
        break
for i, m in sorted(book.items(), key = lambda x: x[0]):
    print(i)
    print(" ".join(str(j) for j in sorted(m)))


Measured memory_bytes: 5608
program  Rabbit_Exercise
  implicit none
  integer::N,M
  integer(16)::K
  integer(16),allocatable,dimension(:)::X,A

  integer(16),allocatable,dimension(:)::dE,dE_rep!期待値の差分
  integer,allocatable,dimension(:)::Rep!置換
  integer(16),allocatable,dimension(:)::ANS
  integer::i

  read*,N
  allocate(X(N))
  read*,X
  read*,M,K
  allocate(A(M))
  read*,A

  !期待値差分初期化
  allocate(dE(N-1))
  do i=1,N-1
    dE(i)=X(i+1)-X(i)
  end do

  !一セット分の置換を計算
    !置換初期化
    allocate(Rep(N-1))
    do i=1,N-1
      Rep(i)=i
    end do
    !一セット分の置換
    do i=1,M
      call swap(Rep(A(i)),Rep(A(i)-1))
    end do
  !Kセット分の置換を計算
    Rep=Rep_Pow(N-1,Rep,K)
  allocate(dE_Rep(N-1))
  dE_Rep=0
  do i=1,N-1
    dE_rep(I)=dE(rep(I))
  end do
  allocate(ANS(N))
  ANS(1)=X(1)
  do i=2,N
    ANS(I)=ANS(i-1)+dE_Rep(i-1)
  end do
  print"(I0)",ANS
contains
  
  subroutine swap(x,y)
    integer::x,y
    x=xor(x,y)
    y=xor(x,y)
    x=xor(x,y)
  end subroutine swap

  function Rep_Pow(si,Re,N)result(res)
    integer,intent(in)::si,Re(1:si)
    integer(16)::N
    integer::res(1:si),B(1:si)
    integer::i
    do i=1,si
      res(i)=i
    end do
    B=Re
    do i=1,bit_size(N)
      if(btest(N,i-1))res=rep_mul(si,res,B)
      B=rep_mul(si,B,B)
    end do
  end function
  function rep_mul(si,A,B)result(res)
    integer,intent(in)::si,A(si),B(si)
    integer::res(si)
    integer::i
    do i=1,SI 
      res(i)=A(B(i))
    end do
  end function
end program Rabbit_Exercise

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

const int N = 220;

int n;
char pan[N][N];
int vis[N], dp[N], que[N];

bool dfs(int u, int c) {
	vis[u] = c;
	for (int i = 1; i <= n; i++) if (pan[u][i] == '1') {
		if (vis[i] != -1 && vis[i] == c) return 0;
		if (vis[i] == -1 && !dfs(i, !c)) return 0;
	}
	return 1;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> pan[i] + 1;
	for (int i = 1; i <= n; i++) vis[i] = -1;
	if (!dfs(1, 0)) {
		cout << "-1\n";
		return 0;
	}
	int ans = 0;
	for (int s = 1; s <= n; s++) {
		for (int i = 1; i <= n; i++) dp[i] = 0;
		int hd = 0, tl = 0;
		dp[s] = 1, que[tl++] = s;
		while (hd < tl) {
			int cur = que[hd++];
			for (int i = 1; i <= n; i++) if (pan[cur][i] == '1' && !dp[i]) dp[i] = dp[cur] + 1, que[tl++] = i;
		}
		ans = max(ans, dp[que[tl - 1]]);
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main() {
    int n;  cin >> n;
    char *c = new char[n];
    for (int i = 0; i < n; i++)
        cin >> c[i];

    int i = 0, j = n-1;
    int ans = 0;
    while (i < j) {
        while (i < n && c[i] == 'R')
            i++;
        while (0 <= j && c[j] == 'W')
            j--;
        if (i < j) {
            ans++;
            c[i] = 'R';
            c[j] = 'W';
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3776
import sys
sys.setrecursionlimit(10 ** 5 * 2)
N, K = map(int, input().split())
A = [0] + list(map(int, input().split()))
top = -1
hist = []
finished = [True] + [False for _ in range(N)]
seen = [True] + [False for _ in range(N)]

def dfs(cur):
    global hist, finished, seen, top
    hist.append(cur)
    seen[cur] = True
    nex = A[cur]
    if seen[nex] and not finished[nex]:
        top = nex
        return
    dfs(nex)
    if not top == -1:
        return
    hist.pop()
    finished[cur] = True
    
dfs(1)
cycle = []
while not hist == []:
    i = hist.pop()
    cycle.append(i)
    if i == top:
        break

cycle.reverse()

cur = 1
while not cur == top and not K == 0:
    cur = A[cur]
    K -= 1

if cur == top:
    cur = cycle[K % len(cycle)]

print(cur)

Measured memory_bytes: 177576
import Data.List
import Data.Bool

main = do
    [h,w] <- map read . words <$> getLine
    as <- sort . map length . group . sort . concat . lines <$> getContents
    let c1 = bool 0 1 $ odd h && odd w
        c2 = (bool 0 (h `quot` 2) (odd w)) + (bool 0 (w `quot` 2) (odd h))
        as' = filter (/=0) $ map (`rem` 4) as
        r1 = length $ filter odd as'
        r2 = length as' - r1
    putStrLn $ bool "No" "Yes" (r1 == c1 && r2 <= c2)


Measured memory_bytes: 2428
import java.math.BigInteger;
import java.util.Scanner;

public class Main 
{
	static Ratio[][] dp; //water sugar
	
	
	
	static boolean[][] done; //water sugar
	static int h,w;
	static Ratio mm = new Ratio(999,0);
	
//	static long maxwat = 0;
//	static long maxsug = 0;
	
	static class Ratio implements Comparable<Ratio>
	{
		int w;
		int s;
		
		public Ratio(int w0, int s0)
		{
			w = w0;
			s = s0;
		}

		@Override
		public int compareTo(Ratio o) 
		{
			return s*o.w - o.s*w;
		}
	}
	
	static Ratio maxrat(Ratio a, Ratio b)
	{
		if(a.compareTo(b) > 0)return a;
		else return b;
	}
	
	static Ratio go(int wat, int sug)
	{
		Ratio an = new Ratio(wat,sug);
		if(wat*100 + sug > cap)return new Ratio(9999999,0);
		if(wat*e<sug)return new Ratio(9999999,0);
//		System.out.println(wat + " " + sug);
		if(done[wat][sug])return dp[wat][sug];
		
		
		if(an.compareTo(mm) > 0)
		{
			mm = an;
//			maxwat = wat;
//			maxsug = sug;
		}
		an = maxrat(an, go(wat+bot1, sug));
		an = maxrat(an, go(wat+bot2, sug));
		an = maxrat(an, go(wat, sug+sug1));
		an = maxrat(an, go(wat, sug+sug2));
		done[wat][sug]=true;
		dp[wat][sug]=an;
		return an;
	}
	static int bot1,bot2,sug1,sug2, e, cap;

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		bot1 = sc.nextInt();
		bot2 = sc.nextInt();
		
		sug1 = sc.nextInt();
		sug2 = sc.nextInt();
		
		e = sc.nextInt(); //how much sugar can disolve in 1 water
		
		cap = sc.nextInt(); //beaker cap. water is 100x bigger

		h = cap/100;
		w = cap;
		dp = new Ratio[h+1][w];
		done = new boolean[h+1][w];
		
//		System.out.println("HW " + h + " " + w);
		go(0,0);
//		System.out.println((maxwat*100)+maxsug + " " + maxsug);
		if(mm.s == 0)mm.w = bot1;
		System.out.println((mm.w*100)+mm.s+ " " + mm.s);
		
		for(int x = 0; x < w; x++)
		{
			for(int y = 0; y < h; y++)
			{
			}
		}
	}

}


Measured memory_bytes: 22484
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#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 srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

const int MAX_SIZE = 52;

int LCS(const string& a, const string& b){
    int n = (int)a.size(), m = (int)b.size();
    vector<int> x(n), y(m);
    rep(i,n){
        x[i] = a[i]-'a';
        if(x[i] < 0){
            x[i] = a[i]-'A'+26;
        }
    }
    rep(i,m){
        y[i] = b[i]-'a';
        if(y[i] < 0){
            y[i] = b[i]-'A'+26;
        }
    }
    vector<vector<int> > vec(MAX_SIZE);
    for(int j = m-1; j >= 0; --j){
        vec[y[j]].push_back(j);
    }
    vector<int> xs(n+1, INF);
    xs[0] = -1;
    vector<P> nx(n+1,P(-INF,-INF));
    rep(i,n){
        vector<int>& ys = vec[x[i]];
        rep(j,(int)ys.size()){
            int k = lower_bound(xs.begin(),xs.end(),ys[j]) - xs.begin();
            xs[k] = ys[j];
            nx[k] = P(y[ys[j]], k-1);
        }
    }
    int l = lower_bound(xs.begin(),xs.end(),INF-1) - xs.begin();
    int id = l-1;
    int ans = 0;
    while(true){
        id = nx[id].second;
        if(id == -INF) break;
        ans++;
    }
    return ans;
}


int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int q;
    cin >> q;
    rep(i,q){
        string a,b;
        cin >> a >> b;
        cout << LCS(a,b) << "\n";
    }
    return 0;
}



Measured memory_bytes: 3268
#include<iostream>
using namespace std;
#define ll long long
int main()
{
	ll n;
	cin>>n;
	int a[100001];
	int flag=1;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=n-1;i>0;i--)
	{
		if(a[i]<a[i-1])
		{
			a[i-1]--;
			if(a[i]<a[i-1])
			{
				flag=0;
				break;
			}
		}
	}
	if(flag==1)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 764
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath> 
#include <cstdlib> // abs(int), labs(long int), llabs(llint)

#define roundup(n,d) ( ((n) + ((d)-1)) / (d) )
#define ll long long

using namespace std;

int main(void){
    int n,x;
    cin >> n >> x;

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

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

    bool breaked = false;
    int ans = 0;
    for(int i = 0;i < n;i++){
        x -= a[i];
        if(x < 0) {
            ans = i;
            breaked = true;
            break;
        }
    }

    if(!breaked){
        if (x != 0){
            ans = n-1;
        } else {
            ans = n;
        }
    }

    cout << ans << endl;
    return 0;
}

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


public class Main {
	
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int m = Integer.parseInt(in.readLine());
		boolean okay = true;
		int t = 0;
		int x = 0;
		int y = 0;
		while(m-- > 0) {
			String[] r = in.readLine().split("\\s++");
			int tn = Integer.parseInt(r[0]);
			int xn = Integer.parseInt(r[1]);
			int yn = Integer.parseInt(r[2]);
			int dx = xn - x;
			int dy = yn - y;
			int dt = tn - t;
			if(dx < 0) dx = -dx;
			if(dy < 0) dy = -dy;
			int rem = dt - (dx + dy);
			if(rem < 0 || rem % 2 != 0) okay = false;
			t = tn;
			x = xn;
			y = yn;
		}
		System.out.println(okay ? "Yes" : "No");
	}
}

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

#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    ll N;
    scanf("%lld", &N);
    ll A;
    ll ans[N];
    REP(int,i,0,N){
        scanf("%lld", &A);
        ans[A - 1] = i+1;
    }
    REP(int,i,0,N) printf("%lld\n", ans[i]);
    return 0;
}

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

const int inf = 1e9;
const ll linf = 1e18;

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

    int n, k; cin >> n >> k;
    int ans = 1;
    for (int i = 0; i < n; i++) {
        if (ans * 2 < ans + k) ans *= 2;
        else ans += k;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
let S = stdin.ReadLine().ToCharArray()
let T = Array.zeroCreate<int> (S.Length + 1)
let MOD = 2019

let rec solver m n =
    if n = -1 then ()
    else
        T.[n] <- (T.[n + 1] + m * (int S.[n] - int '0')) % MOD
        solver (m * 10 % MOD) (n - 1)

solver 1 (T.Length - 2)

T
|> Array.countBy id
|> Array.sumBy (fun x -> snd x * (snd x - 1) / 2)
|> stdout.WriteLine


Measured memory_bytes: 30244
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <regex>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1000000007;

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

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

//myfuncs
//素数判定
template<class T> inline T isPrime(T x) {
	bool ret = true;
	if (x < 2) {
		ret = false;
	}
	for (LL i = 2; i <= sqrt(x); i++) {
		if (x%i == 0) {
			ret = false;
		}
	}
	return ret;
}

//Union FInd
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

//main code

int main(int argc, char const* argv[])
{
	int n,x;
	cin >> n >> x;
	int m[n];
	int mi = 100000;
	for (int i = 0; i < n; i++) {
		cin >> m[i];
		mi = min(mi,m[i]);
		x -= m[i];
	}
	cout << n + x / mi << endl;
	return 0;
}


Measured memory_bytes: 256
string = gets.chomp.split("")

flag = true
string.each.with_index do |char, index|
  if index % 2 == 0
    flag = false unless (char == 'R' || char == 'U' || char == 'D')
  else
    flag = false unless (char == 'L' || char == 'U' || char == 'D')
  end
end

if flag
  puts 'Yes'
else
  puts 'No'
end

Measured memory_bytes: 1788
using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Threading.Tasks;

class Program
{
	//Main
	static void Main(string[] args)
	{
		//読み込む
		string[] S = Console.ReadLine().Split(' ');
		int N = int.Parse(S[0]);
		int M = int.Parse(S[1]);
		int K = int.Parse(S[2]);
		long[] An = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
		long[] Bn = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

		long over= 1000000001;

		//各本を読むのにかかる時間
		//累積和で求める
		long[] timeA = new long[N];
		long[] timeB = new long[M];

		timeA[0] = An[0];
		for(int i=1; i<N; i++){
			timeA[i] = timeA[i-1] + An[i];
			//オーバーする場合
			if(timeA[i] >= over){
				timeA[i] = over;
			}
		}
		timeB[0] = Bn[0];
		for(int i=1; i<M; i++){
			timeB[i] = timeB[i-1] + Bn[i];
			//オーバーする場合
			if(timeB[i] >= over){
				timeB[i] = over;
			}
		}

		/*debug
		for(int i=0; i<N; i++){
			Console.WriteLine("An[{0}];{1}",i,timeA[i]);
		}
		for(int i=0; i<M; i++){
			Console.WriteLine("Bn[{0}];{1}",i,timeB[i]);
		}
		*/

		//Aを基準にみていく（左から）
		int max = 0;
		//右端（しゃくとり）
		int right = M-1;
		for(int i=0; i<N; i++){
			//Aを読むことができない場合、終了
			if(timeA[i] > K){
				break;
			}
			else{
				//取り敢えずAを必ずi+1冊読む
				int cnt = i+1;

				//ギリギリ読むことのできるBを探索
				int currentRight = right;
				for(int j=right; j>=0; j--){
					currentRight = j;
					if(timeA[i] + timeB[j] > K){
						continue;
					}
					//読むことができる場合
					else{
						cnt += (j+1);
						//Console.WriteLine("cnt:{0},right{1}",cnt,right);
						break;
					}
				}

				//最大値を更新
				if(cnt > max){
					max = cnt;
				}

				right = currentRight;
			}
		}

		//Aを全く読まない場合も考える
		int nonA = 0;
		for(int i=0; i<M; i++){
			if(timeB[i] > K){
				break;
			}
			else{
				nonA = i+1;
			}
		}
		if(nonA > max){
			max = nonA;
		}

		Console.WriteLine(max);
	}
}



Measured memory_bytes: 62316
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
#define ALL(a) (a).begin(), (a).end()
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

unsigned GetDigit(unsigned num) { return to_string(num).length(); }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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

ll nCr(int n, int r)
{
    if (n == r or n == 0)
        return 1;
    if (n < r)
        return 0;
    if (r == 1)
        return n;
    return nCr(n - 1, r - 1) + nCr(n - 1, r);
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int N, M;
using Graph = vector<vector<int>>;
vector<bool> visit(N, false);
bool flag;

int dfs(const Graph &G, int now_v)
{
    visit[now_v] = true;
    int res=0;
    REP(i,N){
        if(!visit[i]) break;
        else ++res;
        if(res==N) return res;
    }
    int field=0;
    for(auto next_v: G[now_v]){
        if(visit[next_v]) continue;
        visit[next_v] = true;
        field+=dfs(G, next_v);
        visit[next_v] = false;
    }

    return field;

}

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    cin >> N >> M;
    Graph G(N);
    REP(i, M){
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    int ans = 0;
    visit.assign(N + 1, false);
    ans += dfs(G, 0);

    cout << ans / N << endl;

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <bitset>
#include <cstdlib>
#include <cmath>
#include <set>
#include <list>
#include <deque>
#include <map>
#include <queue>
#include <fstream>
#include <cassert>
#include <cmath>
#include <sstream>
#include <time.h>
#include <complex>

#include <unordered_map>
#include <unordered_set>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define DFOR(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define rep(i,n) FOR(i,0,n)
#define repn(i,n) FORN(i,1,n)
#define drep(i,n) DFOR(i,n-1,0)
#define drepn(i,n) DFOR(i,n,1)
#define MAX(a,b) a = Max(a,b)
#define MIN(a,b) a = Min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define Reset(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(all(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)
#define forever for(;;)
#define PINF 1000000000000
#define newline '\n'

#define test if(1)if(0)cerr
using namespace std;

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<double,double> dd;
typedef pair<char,char> cc;
typedef vector<ii> vii;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l4;
const double pi = acos(-1.0);


const int maxn = 8e2+1;
string a[maxn];
int sx, sy, n, m, k;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int main()
{
    cin >> n >> m >> k;
    rep(i, n)
    {
        cin >> a[i];
    }
    rep(i, n)
    {
        rep(j, m)
        {
            if (a[i][j] == 'S')
            {
                sx = i, sy = j;
            }
        }
    }
    int ans = n*m;
    queue<ii> q;
    q.push(mp(sx, sy));
    for (int i = 0; i <= k; ++i)
    {
        int sz = q.size();
        for (int i = 0; i < sz; ++i)
        {
            int x = q.front().first, y = q.front().second;
            q.pop();
            MIN(ans, x);
            MIN(ans, n-x-1);
            MIN(ans, y);
            MIN(ans, m-y-1);
            rep(dir, 4)
            {
                int nx = x+dx[dir], ny = y+dy[dir];
                if (nx < 0 || ny < 0 || nx >= n || ny >= m || a[nx][ny] != '.')
                {
                    continue;
                }
                a[nx][ny] = '#';
                q.push(mp(nx, ny));
            }
        }
    }
    cout << (ans+k-1)/k+1 << newline;
    
}


Measured memory_bytes: 1152
#include<iostream>
#define D(x) cout<<"D:"<<#x<<'='<<x<<endl;
using namespace std;
typedef long long ll;
const ll p = 1e9+7;
inline int nextint(void)
{
	int k;
	cin>>k;
	return k;
}
ll qp(ll a,ll b)
{
    ll res = 1;
    while(b)
    {
        if(b & 1) res = res * a % p;
        a = a * a % p;
        b >>= 1;
    }
    return res % p;
}
ll qm(ll a, ll b)  
{  
    ll ans = 1;  
    a %= p;  
    while(b)  
    {  
        if(b & 1)  
        {  
            ans = ans * a % p;  
            b--;  
        }  
        b >>= 1;  
        a = a * a % p;  
    }  
    return ans;  
} 
ll C(ll n, ll m)
{  
    if(m > n) return 0;  
    ll ans = 1;  
    for(int i = 1; i <= m; i++)  
    {  
        ll a = (n + i - m) % p;  
        ll b = i % p;  
        ans = ans * (a * qm(b, p-2) % p) % p;  
    }  
    return ans;  
}
int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n = nextint(), a = nextint(), b = nextint();
	cout<<(qp(2, n)+2*p-1-C(n, a)-C(n, b))%p<<endl;
	return 0;
}

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

using namespace std;

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

	if (s[0] == s[1] || s[0] == s[2] || s[1] == s[2]){
		
		 cout << "No" << endl;
		}
		else {
		 cout << "Yes" << endl;
		}
	
	return 0;
}

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

#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 reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n;
  i64 k;
  cin >> n >> k;
  vi32 a(n);
  cin >> a;
  sort(all(a));
  auto f = [&](i64 x) {
    i64 ret = 0;
    rep(i, n) {
      auto g = [&](int y) {
        return (i64) y * a[i] >= x;
      };
      if (a[i] < 0) {
        ret += partition_point(a.begin() + i + 1, a.end(), g) - (a.begin() + i + 1);
      } else if (a[i] > 0) {
        ret += partition_point(a.rbegin(), a.rend() - i - 1, g) - a.rbegin();
      } else {
        if (x <= 0) ret += n - (i + 1);
      }
    }
    return ret;
  };
  i64 L = (i64) n * (n - 1) / 2 - k + 1;
  i64 ok = -2e18, ng = 2e18;
  while (abs(ok - ng) > 1) {
    i64 md = (ok + ng) / 2;
    (f(md) < L ? ng : ok) = md;
  }
  cout << ok << endl;
}


Measured memory_bytes: 1024
K = int(input())
def calcgcd(a, b):
  if a > b:
    a, b = b, a
  while a > 0:
    a, b = b%a, a
  return b
r = 0
for a in range(1, K+1):
  for b in range(1, K+1):
    ab = calcgcd(a, b)
    for c in range(1, K+1):
      g = calcgcd(ab, c)
      r += g
print(r)


Measured memory_bytes: 68616
import java.util.*;

public class Main{
	String name = "CYRMGB";
	
	//サイコロ	//dice is, 1 = south, 2 = east, 0 = top, 5 = bottom, 3 = west, 4 = north;
	class Dice{
		StringBuilder dice;
		public Dice(String dice) {
			this.dice = new StringBuilder(dice);
		}
		private void slide() {
			swap(1,3,4,2);
		}
		private void turn(char c) {
			switch(c){
			case 'n': swap(0,4,5,1); break;
			case 's': swap(0,1,5,4); break;
			case 'w': swap(0,3,5,2); break;
			case 'e': swap(0,2,5,3); break;
			}
		}
		private void swap(int i, int j, int k, int l) {
			char temp = dice.charAt(l);
			dice.setCharAt(l, dice.charAt(k));
			dice.setCharAt(k, dice.charAt(j));
			dice.setCharAt(j, dice.charAt(i));
			dice.setCharAt(i, temp);
		}
	}
	
	//サイコロが同じかどうか判定する
	private boolean isSame(Dice aa, Dice bb) {
		String [] order = {"", "n", "s", "w", "e", "nn"};
		String [] revorder = {"", "s", "n", "e", "w", "nn"};
		Dice a = new Dice(aa.dice.toString());
		Dice b = new Dice(bb.dice.toString());
		for(int i = 0; i < order.length ; i++){
			for(int j = 0; j < order[i].length(); j++){
				char c = order[i].charAt(j);
				b.turn(c);
			}
			for(int j = 0; j < 4; j++){
				b.slide();
				if(a.dice.toString().equals(b.dice.toString())){
					
					return true;
				}
			}
			for(int j = 0; j < revorder[i].length(); j++){
				char c = revorder[i].charAt(j);
				b.turn(c);
			}
		}
		return false;
	}
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n == 0) break;
			Dice [] d = new Dice[n];
			for(int i = 0; i < n; i++){
				StringBuilder tempdice = new StringBuilder();
				for(int j = 1; j <= 6; j++){
					String s = sc.next().charAt(0) + "";
					tempdice.append(name.indexOf(s));
				}
				d[i] = new Dice(tempdice.toString());
			}
			
			int count = 0;
			for(int i = 0; i < n; i++){
				for(int j = i + 1; j < n; j++){
					if(isSame(d[i], d[j])){
						count++;
						break;
					}
				}
			}
			System.out.println(count);
		}
	}

	private void debug(Object... o) { System.out.println("debug = " + Arrays.deepToString(o)); }

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

Measured memory_bytes: 49160
class Entry
  attr_reader :spell, :nodes

  def initialize(spell, nodes)
    @spell = spell
    @nodes = nodes
  end
end
 
class Arrow
  attr_reader :source, :sink, :label

  def initialize(source, sink, label)
    @source = source
    @sink = sink
    @label = label
  end
end

def push(queue, spell)
  size = queue.size
  index = queue.index{|entry| entry.spell >= spell} || size
  return queue[index].nodes if index < size && queue[index].spell == spell

  return nil if index > 0 && !spell.start_with?(queue[index - 1].spell)
  queue.slice!(index..-1) if index < size && !queue[index].spell.start_with?(spell)

  nodes = {}
  queue.insert(index, Entry.new(spell, nodes))
  nodes
end

def calc(n, arrows, start, goal)
  ins = Array.new(n){[]}
  arrows.each do |arrow|
    ins[arrow.sink] << arrow.source
  end

  reachable_from = {}
  stack = [goal]
  until stack.empty?
    node = stack.pop
    reachable_from[node] = true
    ins[node].each do |source|
      stack << source unless reachable_from[source]
    end
  end

  return nil unless reachable_from[start]
  arrows.select!{|arrow| reachable_from[arrow.sink]}

  outs = Array.new(n){[]}
  arrows.each do |arrow|
    outs[arrow.source] << arrow
  end

  limit = n * arrows.map{|arrow| arrow.label.size}.max

  queue = [Entry.new('', {start => true})]
  until queue.empty?
    entry = queue.shift
    spell = entry.spell
    nodes = entry.nodes
    return spell if nodes[goal]
    return nil if spell.size > limit

    nodes.each do |node, _|
      outs[node].each do |arrow|
        new_nodes = push(queue, spell + arrow.label)
        new_nodes[arrow.sink] = true if new_nodes
      end
    end
  end
  nil
end

loop do
  n, a, s, g = gets.split.map(&:to_i)
  break if n == 0

  arrows = (0...a).map do |i|
    x, y, lab = gets.split
    Arrow.new(x.to_i, y.to_i, lab)
  end

  puts calc(n, arrows, s, g) || 'NO'
end

Measured memory_bytes: 10760
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define co(a) cout<<a<<endl
#define sz size()
#define bgn begin()
#define en end()
#define pb(a) push_back(a)
#define pp() pop_back()
#define V vector
#define P pair
#define V2(a,b,c) V<V<int>> a(b,V<int>(c))
#define V2a(a,b,c,d) V<V<int>> a(b,V<int>(c,d))
#define incin(a) int a; cin>>a
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())


signed main(){
  int a,b;
  cin>>a>>b;
  V<int> c(a);
  fo(i,a)
  cin>>c[i];
  int d=0;
  fo(i,a)
  d+=(c[i]>=b);
  cout<<d<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main()
{
  string S, T;
  cin >> S >> T;

  int count = 0;
  rep(i, S.size())
  {
    if (S[i] == T[i])
      count++;
  }
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

constexpr int N = 2048;
char s[3][N];
int a[3];
bool *x[3] = {
	new bool[8*N] + 4*N,
	new bool[8*N] + 4*N,
	new bool[8*N] + 4*N,
};

int main(){
	REP(i, 3) scanf("%s", s[i]);
	REP(i, 3) a[i] = strlen(s[i]);
	REP(i, 3){
		int j = (i+1)%3;
		char *u = s[i], *v = s[j];
		int n = a[i], m = a[j];
		FOR(k, -2*N, 2*N){
			bool ok = true;
			REP(h, m){
				int g = k + h;
				if(g < 0 || n <= g) continue;
				if(u[g] == '?' || v[h] == '?') continue;
				if(u[g] != v[h]) ok = false;
			}
			if(ok) x[i][k] = true;
		}
	}
	DEBUG("%d %d %d\n", x[0][4], x[1][-2], x[2][-2]);
	int ans = INT_MAX;
	FOR(i, -2*N, 2*N){
		FOR(j, -2*N, 2*N){
			if(x[0][i] && x[1][j] && x[2][-i-j]){
				SML(ans,
						max({a[0], i+a[1], i+j+a[2]}) - 
						min({0,    i,      i+j}));
			}
		}
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 256
N=int(input())
d=list(map(int,input().split()))
l=[]
for i in range(N):
    for j in range(i+1,N):
        l.append([i,j])
sum_0=0
for i in range(len(l)):
    sum_0+=d[l[i][0]]*d[l[i][1]]
print(sum_0)

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

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

int main()
{
    int n, m, c;
    scanf("%d %d %d", &n, &m, &c);

    int b[m];
    for (int i = 0; i < m; i++)
        scanf("%d", &b[i]);

    int ans = 0;
    for (int i = 0; i < n; i++) {
        int sum = c;
        for (int j = 0; j < m; j++) {
            int num;
            scanf("%d", &num);
            sum += num * b[j];
        }

        if (sum > 0)
            ans++;
    }

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

    return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "limits.h"
#include "bitset"
#define lp(n) for (int i = 0; i < n; i++)
#define lop(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define ll long long int
#define sp ' '
using namespace std;


ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	ll g = gcd(x, y);
	return x / g * y;
}

int main(){
	int c[9];
	lp(9)
		cin >> c[i];
	if (c[1] - c[0] == c[4] - c[3] && c[4] - c[3] == c[7] - c[6] && c[2] - c[1] == c[5] - c[4] && c[5] - c[4] == c[8] - c[7]) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e,i,j,ii,jj,zx,xc,f[100009],dp[100009],pas;
int main(){
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>a;
    for(i=0; i<=a; i++) cin>>f[i];
    //f[a]>=1
    if(a==0){
        if(f[a]==1){
            cout<<1;
        }else{
            cout<<-1;
        }
        return 0;
    }
    if(f[0]!=0){
        cout<<-1;
        return 0;
    }
    dp[0]=1;
    zx=1;
    for(i=1; i<a; i++){
        zx*=2;
        if(zx>=4000000000000000000LL) zx/=2;
        if(f[i]>=zx){
            cout<<-1;
            return 0;
        }
        zx-=f[i];
        dp[i]=zx;
    }
    zx*=2;
    if(zx>=4000000000000000000LL) zx/=2;
    if(f[a]>zx){
        cout<<-1;
        return 0;
    }
    pas=f[a];
    if(f[a]>=zx/2){
        zx=zx/2;
    }else{
        zx=f[a];
    }
    for(i=a-1; i>0; i--){
        zx+=f[i];
        pas+=zx;
        if(zx>=dp[i-1]){
            zx=dp[i-1];
        }else{
            zx=zx;
        }
    }
    pas++;
    cout<<pas;
    return 0;
}


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

struct Node{
  Node *right;
  Node *left;
  Node *parent;
  int key;
};

Node *root, *NIL;

Node *treeMinimum(Node *x){
  while(x->left != NIL) x=x->left;
  return x;
}



Node *Search(Node *u, int k){
  while(u!=NIL && k!=u->key){
    if(k < u->key) u=u->left;
    else u = u->right;
  }
    return u;
}
Node *treeSuccessor(Node *x){
  if(x->right != NIL) return treeMinimum(x->right);
  Node *y = x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}

void Delete(Node *z){
  Node *y; // node to be deleted
  Node *x; // child of y
  if(z->left==NIL||z->right==NIL) y=z;
  else y=treeSuccessor(z);
  if(y->left!=NIL){
    x=y->left;
  }else{
    x=y->right;
  }
  if(x!=NIL)  x->parent=y->parent;
  if(y->parent==NIL) root=x;
  else{
    if(y==y->parent->left) y->parent->left=x;
    else y->parent->right=x;
  }
  if(y!=z) z->key=y->key;
  free(y);
}

void insert(int k){
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x!=NIL){
    y=x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent=y;
  if(y==NIL) root=z;
  else{
    if(z->key < y->key) y->left=z;
    else y->right=z;
  }
}

void inorder(Node *u){
  if(u==NIL) return;
  inorder(u->left);
  cout<<" "<<u->key;
  inorder(u->right);
}
void preorder(Node *u){
  if(u==NIL) return;
  cout<<" "<<u->key;
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n,x;
  string s;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>s;
    if(s[0]=='f'){
      cin>>x;
      Node *t=Search(root,x);
      if(t!=NIL) cout<<"yes"<<endl;
      else cout<<"no"<<endl;
    }else if(s[0]=='i'){
      cin>>x;
      insert(x);
    }
    else if(s[0]=='p'){
      inorder(root);
      cout<<endl;
      preorder(root);
      cout<<endl;
    }
    else if(s[0]=='d'){
      cin>>x;
      Delete(Search(root,x));
      
    }
  }
  
  return 0;
}



Measured memory_bytes: 21932
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main(){
    int n,x,y;
    scanf("%d%d%d",&n,&x,&y);
    int f,min,a[n];
    for(int i=0;i<n;i++) a[i]=0;
    for(int i=1;i<n;i++){
        for(int j=i+1;j<=n;j++){
            min=fmin(abs(i-x)+abs(y-j)+1,j-i);
            a[min]++;
        }        
    }
    for(int i=1;i<n;i++) printf("%d\n",a[i]);
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void){
	int x,y;
	int temp;
	while(scanf("%d%d",&x,&y)==2){
		if(!x&&!y) return 0;
		if(x>y){
			temp = x;
			x = y;
			y = temp;
		}
		printf("%d %d\n",x,y);
	}
	return 0;
}

Measured memory_bytes: 600
// Ver19.02
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  int a, b;
  scanf("%d%d", &a, &b);
  if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)
    puts("Possible");
  else
    puts("Impossible");
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
int a, b;
cin >> a >> b;
  a = a - 1;
  b = b - 1;
  cout << a * b << "\n";
}


Measured memory_bytes: 3636
'use strict'

const main = input => {
	const args = input.trim().split('\n')
	const n = parseInt(args[0], 10)
	let cnt = 0

	for (let i = 0; i < n; i++) {
		const t1 = args[i + 1].split(' ').map(Number)
		cnt += t1[1] - t1[0] + 1
	}

	console.log(cnt)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


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

typedef long long int ll;

int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> p(n);
    for(ll i = 0;i < n;i++){
        cin >> p[i];
    }

    sort(p.begin(),p.end());

    ll ans = 0;
    for(ll i = 0;i < k;i++){
        ans += p[i];
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

ll dist[10][10];
ll n, m, w, t;
ll shpdp[10][1111];
ll knapdp[555][11111];

ll shp(int v, int used)
{
	if (used == (1 << n) - 1) return dist[v][n];
	if (shpdp[v][used] >= 0) return shpdp[v][used];
	ll res = INF;
	REP(i, n)
	{
		if ((used >> i) & 1) continue;
		chmin(res, shp(i, used | (1 << i)) + dist[v][i]);
	}
	return shpdp[v][used] = res;
}

ll knapsack(int i, int wei, vi& weight, vi& value)
{
	if (i == weight.size()) return 0;
	if (knapdp[i][wei] >= 0) return knapdp[i][wei];
	ll res = 0;
	if (weight[i] == 0) res = knapsack(i + 1, wei, weight, value);
	else
	{
		if (wei >= weight[i])
		{
			chmax(res, knapsack(i, wei - weight[i], weight, value) + value[i]);
			chmax(res, knapsack(i + 1, wei - weight[i], weight, value) + value[i]);
		}
		chmax(res, knapsack(i + 1, wei, weight, value));
	}
	return knapdp[i][wei] = res;
}

int main()
{
	cin.sync_with_stdio(false);
	map<string, pii> mp;
	cin >> n >> m >> w >> t;
	REP(i, m)
	{
		string s; int v, p;
		cin >> s >> v >> p;
		mp[s] = pii(v, p);
	}
	vi x(n), y(n);
	vector<vi> weight(n), value(n);
	REP(i, n)
	{
		int l;
		cin >> l >> x[i] >> y[i];
		REP(j, l)
		{
			string r; int q;
			cin >> r >> q;
			weight[i].push_back(mp[r].first);
			value[i].push_back(mp[r].second - q);
		}
	}
	x.push_back(0), y.push_back(0);
	REP(i, n+1)REP(j, n+1)
	{
		dist[i][j] = abs(x[i] - x[j]) + abs(y[i] - y[j]);
	}
	vi cost(1 << n), val(1<<n);
	REP(i, 1 << n)
	{
		MS(shpdp, -1);
		cost[i] = shp(n, i);
		vi tw, tv;
		REP(j, n)
		{
			if ((i >> j) & 1) continue;
			REP(k, weight[j].size())
			{
				tw.push_back(weight[j][k]);
				tv.push_back(value[j][k]);
			}
		}
		MS(knapdp, -1);
		val[i] = knapsack(0, w, tw, tv);
	}
	MS(knapdp, -1);
	cout << knapsack(0, t, cost, val) << endl;
	return 0;
}

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

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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  
  vector<int> a(n + 1);
  long long ans = 0;
  for (int i = 0; i < n; i++)
    if (s.at(i) == '<') chmax(a.at(i + 1), a.at(i) + 1);
  for (int i = n; i > 0; i--)
    if (s.at(i - 1) == '>') chmax(a.at(i - 1), a.at(i) + 1);
  for (int i = 0; i <= n; i++) ans += a.at(i);

  cout << ans << endl;
}

Measured memory_bytes: 2820
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define int long long
using namespace std;
const int MOD=1e9+7;
const int INF=1e10;
template<typename T> void cmax(T &a, T b) {a = max(a, b);}
template<typename T> void cmin(T &a, T b) {a = min(a, b);}

const int MAX_N=3e5+1;
bool MSNum[MAX_N]={};
bool MSPrime[MAX_N]={};

bool isPrime[MAX_N];
void eratos(){
  for(int i=0;i<MAX_N;i++)isPrime[i]=true;
  isPrime[0]=isPrime[1]=false;
  for(int i=0;i<MAX_N;i++){
    if(isPrime[i]){
      for(int j=i+i;j<MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
}
void make_num(){
  int N=0;
  while(1){
    if(7*N+1<MAX_N){
      MSNum[7*N+1]=true;
    }else{
      break;
    }
    if(7*N+6<MAX_N){
      MSNum[7*N+6]=true;
    }else{
      break;
    }
    N++;
  }
  rep(i,MAX_N)MSPrime[i]=true;
  loop(i,2, MAX_N){
    if(MSNum[i]){
      for(int j=i+i;j<MAX_N;j+=i){
        MSPrime[j]=false;
      }
    }
  }
}

signed main(){
  make_num();
  int n;
  while(cin>>n){
    if(n==1)break;
    cout<<n<<':';
    loop(i,2,n+1){
      if(MSNum[i]&&n%i==0&&MSPrime[i]){
        cout<<' '<<i;
      }
    }
    cout<<endl;
  }
  return 0;
}



Measured memory_bytes: 3660
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(x) cout << fixed << setprecision(x);
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;


int main(){
  ll a,b,c; cin >> a >> b >> c;
  cout << c << ' ' << a << ' ' << b << endl;
}

Measured memory_bytes: 256
// C - Back and Forth
#include <bits/stdc++.h>
using namespace std;

int main(){
	int sx,sy,tx,ty; cin>>sx>>sy>>tx>>ty;
	int dx = tx-sx, dy = ty-sy;
	cout<< string(dy,'U') << string(dx,'R');
	cout<< string(dy,'D') << string(dx,'L');
	cout<< 'L' << string(dy+1,'U') << string(dx+1,'R') << 'D';
	cout<< 'R' << string(dy+1,'D') << string(dx+1,'L') << 'U';
	// cout<< '\n';
}

Measured memory_bytes: 256