akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>

#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>

#include <algorithm>

using namespace std;

int main(int argc, char *argv[]) {
	const int mod = 1000000007;
	
	vector<long long int> step(100001, 0);
	step[1] = 1;
	step[0] = 1;
	for (int i = 2; i <= 100000; i++) {
		step[i] = (step[i-1] + step[i-2]) % mod;
	}

	int start = 0;
	int n, m;
	vector<int> v;
	cin >> n;
	cin >> m;
	for (int i = 0; i < m; i++) {
		int t;
		cin >> t;
		v.push_back(t);
	}
	v.push_back(n+1);
	long long int res = 1;
	for (int i = 0; i < v.size(); i++) {
		if (start == v[i]) {
			cout << 0 << endl;
			return 0;
		}
		// cout << v[i] - 1 - start << endl;
		res *= step[v[i] - 1 - start];
		res %= mod;
		start = v[i] + 1;
	}
	cout << res << endl;
}














Measured memory_bytes: 1660
#include<iostream>
using namespace std;
int main(){
  while(1){
    int n,m,b,c,cnt=0,a[101]={};
    cin>>n>>m;
    if(n+m==0)break;
    for(int i=0;i<n;i++){
      cin>>b;
      for(int j=0;j<b;j++){
	cin>>c;
	a[c]++;
      }
    }
    int x=0,max=0;
    for(int i=0;i<101;i++){
      if(max<a[i]&&m<=a[i]){
	max=a[i];
	x=i;
      }
    }
    cout<<x<<endl;
  }
  return 0; 
}

Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <map>
#include <queue>
#include <sstream>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define mp(a,b) make_pair(a,b)
#define SZ(a) ((int)(a).size())
typedef pair<int,int> PI;

int a,l;

string i2s(int a){
  stringstream ss;
  ss << a;
  string r=ss.str();
  while(SZ(r)<l) r="0"+r;
  return r;
}

int s2i(string a){
  int r;
  stringstream ss(a);
  ss >> r;
  return r;
}


int next(int a){
  string b=i2s(a);

  sort(b.begin(),b.end());
  int bs=s2i(b);
  reverse(b.begin(),b.end());  

  int as = s2i(b);
  return max(as,bs) - min(as,bs);
}


void solve(){
  map<int,int> ai;
  int i=0;
  while(true){
    if(ai.count(a)){
      cout << ai[a] << " " << a << " " << i-ai[a] << endl;
      return;
    }
    ai[a]=i;
    ++i;
    a=next(a);
  }
}


int main(){

  while(cin >> a >> l && l) solve();
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAXN 2015
ll a[MAXN];
int main()
{
    ll n, z, w;
    scanf("%lld %lld %lld", &n, &z, &w);
    for(int i=1;i<=n;++i)
        scanf("%lld", &a[i]);
    ll ans;
    ans=abs(w-a[n]);
    if(n!=1)
        ans=max(ans, abs(a[n]-a[n-1]));
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[] args)
	{
		Scanner sc =new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		int d=sc.nextInt();

		a=Math.min(a,b);
		c=Math.min(c,d);

		//結果を出力
		System.out.println(a+c);
	}
} 

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int t[100000];
int main(void)
{
	int n;
	int max;
	int i,j;
	int sum;
	int cnt,cnt2,MC[1000];
	cin>>n;
	max=-1;
	for(i=0;i<n;i++){
		cin>>t[i];
		if(max<t[i]) max=t[i];
	}
	cnt=1; cnt2=0;
	while(cnt!=max){
		if(max%cnt==0){
			MC[cnt2]=cnt;
			cnt2++;
		}
		cnt++;
	}
	MC[cnt2]=max;
	cnt2++;
/*	cout<<MC[cnt2]<<endl;
	for(i=0;i<cnt2;i++) cout<<MC[i]<<" ";
	cout<<endl;*/
	
	sum=0;
	for(i=0;i<n;i++){
		if(max%t[i]!=0){
			for(j=0;j<cnt2;j++){
				if(MC[j]>t[i]){
					sum+=MC[j]-t[i];
					break;
				}
			}
		}
	}
	
	cout<<sum<<endl;
	
	return 0;
}


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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define All(v) (v).begin(), (v).end()
#define Pb push_back

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

    double n,x[11],ans=0;
    string u[11];
    cin >> n;
    rep(i,n) cin >> x[i] >> u[i];
    rep(i,n){
        if(u[i]=="BTC"){
            x[i] *= 380000.0;
        }
        ans += x[i];
    }
    cout << ans << "\n";
    return 0;
}

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

int main() {
	int a[3];
	for (int i = 0; i < 3; i++) {
		cin >> a[i];
	}
	sort(a, a + 3);
	reverse(a, a + 3);
	cout << a[0] * 10 + a[1] + a[2] << endl;
	return 0;
}

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

using namespace std;

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

    int count = 0;

    for (int i = 0; i < N; ++i) {
        string substr;
        substr = S.substr(i, 3);
        if (substr == "ABC") {
            count++;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 256
use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let it = s.trim().split_whitespace();
    let ans = 6 - it.map(|s| s.parse::<usize>().unwrap()).fold(0, |s, a| s + a);
    println!("{}", ans);
}

fn main() {
    run();
}

Measured memory_bytes: 4352
#include <bits/stdc++.h> // Tomasz Nowak
using namespace std;     // XIII LO Szczecin
using LL = long long;
 
constexpr int mod = int(1e9) + 7;

int add(int a, int b) {
	a += b;
	return a >= mod ? a - mod : a;
}
int mult(int a, int b) {
	return a * LL(b) % mod;
}
int pot(int a, int b) {
	if(b == 0)
		return 1;
	int x = pot(a, b / 2);
	x = mult(x, x);
	if(b & 1)
		x = mult(x, a);
	return x;
}
int inverse(int x) {
	return pot(x, mod - 2);
}

vector<int> factorial, revfact;

void calc_factorial(int n) {
	factorial.resize(n + 1, 1);
	revfact = factorial;
	for(int i = 2; i <= n; ++i)
		factorial[i] = mult(factorial[i - 1], i);
	revfact[n] = inverse(factorial[n]);
	for(int i = n - 1; i >= 1; --i)
		revfact[i] = mult(revfact[i + 1], i + 1);
}

int newton_grid(int n, int m) {
	return mult(factorial[n + m], mult(revfact[n], revfact[m]));
}

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

	int n, m, k;
	cin >> n >> m >> k;
	calc_factorial(n + m);
	vector<pair<int, int>> in(k);
	for(auto &p : in) {
		cin >> p.first >> p.second;
		--p.first, --p.second;
	}
	in.emplace_back(n - 1, m - 1);

	sort(in.begin(), in.end());
	vector<int> dp(k + 1);

	for(int i = 0; i <= k; ++i) {
		dp[i] = newton_grid(in[i].first, in[i].second);
		for(int j = 0; j < i; ++j)
			if(in[j].second <= in[i].second) {
				int rest_of_path = newton_grid(in[i].first - in[j].first, in[i].second - in[j].second);
				dp[i] = add(dp[i], mod - mult(dp[j], rest_of_path));
			}
	}
	cout << dp[k] << '\n';
}


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

long long cnt = 0;
vector<int> G;

void insertionSort(int A[], int n, int g)
{
	for (int i = g; i < n; i++)
	{
		int v = A[i];
		int sorted = i - g;
		while (sorted >= 0 && A[sorted] > v)
		{
			A[sorted + g] = A[sorted];
			sorted -= g;
			cnt++;
		}
		A[sorted + g] = v;
	}
}

void shellSort(int A[], int n)
{
	for (int h = 1;; h = 3 * h + 1)
	{
		if (h > n) break;
		G.push_back(h);
	}
	for (int i = G.size() - 1; i >= 0; i--)
		insertionSort(A, n, G[i]);
}

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

	int A[1000000];
	for (int i = 0; i < n; i++) cin >> A[i];

	shellSort(A, n);

	cout << G.size() << endl;
	for (int i = G.size() - 1; i >= 0; i--)
	{
		cout << G[i];
		if (i) cout << " ";
	}
	cout << endl;
	cout << cnt << endl;
	for (int i = 0; i < n; i++)
		cout << A[i] << endl;

	return 0;
}


Measured memory_bytes: 7024
import java.util.*;

public class Main{
  
  public static void main (String[] args){
  
  	Scanner scanner = new Scanner (System.in);
  
 	String number = scanner.nextLine();
    
  	int count = 0;
    
  	for (int i=0; i<3; i++){
  		char temp = number.charAt(i);
  		
      	if (temp == '1'){
          count++;
        }
    }
    System.out.println(count);
  }
}

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

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    lli ans = 0;
    string s, t;
    cin >> s >> t;
    rep(i,s.size()){
        if(s[i]!=t[i]){
            ans++;
        }
    }
    out(ans);
}

Measured memory_bytes: 3848
# 3.4.3

import re
from collections import deque
from functools import reduce
from heapq import heappop
from heapq import heappush
from itertools import permutations
from math import pi
from operator import itemgetter
from operator import mul
from operator import xor
from os import linesep
from sys import stdin


def rline() -> str:
    return stdin.readline().strip()


def rlines(hint: int = 1):
    ret = ['' for i in range(hint)]
    for i in range(hint):
        ret[i] = rline()
    return ret


def htokens(hint: int = 1):
    lns = rlines(hint)
    ret = list(map(lambda ln: ln.split(), lns))
    return ret


def vtokens(hint: int = 1):
    m, _ = htokens()
    wint = len(m)
    ret = [[None] * hint for i in range(wint)]
    for y in range(hint):
        if y != 0:
            m, _ = htokens()
        # convert horizontal to vertical
        x = 0
        for v in m:
            ret[x][y] = v
            x += 1
    # if return value has one and only one element(list),
    if wint == 1:
        # then add an empty list.
        ret.append([])
    return ret


def rint(radix: int = 10) -> int:
    return int(rline(), radix)


def hints(hint: int = 1, radix: int = 10):
    ret = htokens(hint)
    for i in range(len(ret)):
        ret[i] = list(map(lambda v: int(v, radix), ret[i]))
    return ret


def vints(hint: int = 1, radix: int = 10):
    ret = vtokens(hint)
    for i in range(len(ret)):
        ret[i] = list(map(lambda v: int(v, radix), ret[i]))
    return ret


def mat(hint: int, wint: int):
    return [[None]*wint for i in range(hint)]


def filllist(lst, value: int) -> None:
    # destructive.
    for i in range(len(lst)):
        lst[i] = value


def isprime(n: int) -> bool:
    if n <= 1:
        return False
    if n in (2, 3, 5):
        return True
    if n % 2 == 0:
        return False
    if n % 3 == 0:
        return False
    lst = int(n**0.5)
    f = 5
    while f <= lst:
        if n % f == 0:
            return False
        if n % (f + 2) == 0:
            return False
        f += 6
    return True


def strmat(matrix, lnsep: str = linesep, fieldsep: str = ' ') -> str:
    return lnsep.join(map(lambda row: fieldsep.join(map(str, row)), matrix))


def strbool(boolval: int) -> str:
    return ['No', 'Yes'][boolval]


def solve() -> None:
    # read here
    (n, m) = hints()[0]
    ab_s = hints(n)

    # solve here

    # delay asc, prize desc
    ab_s.sort(key=itemgetter(1), reverse=True)
    ab_s.sort(key=itemgetter(0), reverse=False)

    ans = 0
    tasks = []
    for t in range(m + 1):
        # from (m days after) to today
        while ab_s and ab_s[0][0] == t:
            a, b = ab_s.pop(0)
            heappush(tasks, -b)
        if tasks:
            # do task
            ans -= heappop(tasks)

    # print here
    print(ans)


if __name__ == '__main__':
    solve()


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  string s;
  cin >> s;
  int sl = s.size();

  rep(i, sl) cout << 'x';
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <math.h>
#include <cmath>
#include <stdio.h>
#include <iomanip>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
typedef long long int ll;
#define INF 1000000000

using namespace std;
int main() {

	ll n; cin >> n;
	vector<ll> l(n);
	for (ll i = 0; i < n; i++) { cin >> l[i]; }
	sort(l.begin(), l.end());

	ll ans = 0;
	for (int i = 0; i < n - 2; i++) {
		for (int j = i + 1; j < n - 1; j++) {
		
			ll left = j, right = n;
			while (right - left > 1) {
				ll ave = (left + right) / 2;
				if (l[ave] < l[i] + l[j]) { left = ave; }
				else { right = ave; }
			}
			ans += left - j;

		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


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

    ll H, N; cin >> H >> N;
    vector<ll> a(N, 0), b(N, 0);
    rep(i, N) cin >> a[i] >> b[i];
    
    ll const inf = 1LL<<60;
    vector<vector<ll>> dp(N+5, vector<ll>(H+5, inf));
    dp[1][0] = 0;

    repr(i, 1, N+1) rep(j, H+1) {
        if (dp[i][j]==inf) continue;
        if (i<N) chmin(dp[i+1][j], dp[i][j]);
        chmin(dp[i][min(H, j+a[i-1])], dp[i][j]+b[i-1]);
    }
    cout << dp[N][H] << endl;
    
    return 0;
}




Measured memory_bytes: 78976
#include <iostream>

using namespace std;

int main()
{
	int a, b,len,bt;
	cin >> a >> b;
	for (len = 0, bt = b; bt > 0; len++,bt /= 10);
	for (int i = 0; i < len;i++, a *= 10);
	a = a + b;
	for (int i = 1; i*i <= a; i++)
		if (i*i == a)
		{
			cout << "Yes" << endl;
			return 0;
		}
	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	k := nextInt()

	for i := 1; i < 10; i++ {
		enq(i)
	}

	lidx := 0
	for queue.Len() > 0 {
		ei := deq()
		lidx++
		if lidx == k {
			fmt.Println(ei)
			return
		}

		eis := fmt.Sprintf("%d", ei)
		base := ei*10 + ei%10
		if eis[len(eis)-1] != '0' {
			enq(base - 1)
		}
		enq(base)
		if eis[len(eis)-1] != '9' {
			enq(base + 1)
		}
	}
}

// 正数の桁数を返す
func keta(n int) int {
	keta := 0
	if n == 0 {
		return 1
	}
	for n > 0 {
		keta++
		n /= 10
	}
	return keta
}

var queue = list.New()

func enq(a int) {
	queue.PushBack(a)
}
func deq() int {
	e := queue.Front()
	queue.Remove(e)
	return e.Value.(int) // 明示的キャストが必要
}

// DBGprintqueue print the queue
//! DBG
func DBGprintqueue() {
	fmt.Printf("DBGqueue: [")
	now := queue.Front()
	for now != nil {
		fmt.Printf("%d ", now.Value.(int))
		now = now.Next()
	}
	fmt.Printf(" ]")
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 16928
N, M = map(int, input().split())
drink = []
cost = 0
d_count = 0


for _ in range(N):
    drink.append(list(map(int, input().split())))
    
drink = sorted(drink)

for i in range(N):
    cost += drink[i][0] * drink[i][1]
    d_count += drink[i][1] 
    if d_count > M:
      cost -= drink[i][0] * (d_count - M)
      break
      

print(cost)
    


Measured memory_bytes: 28656
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
#     combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<50

def readInt():
    return list(map(int,input().split()))

def main():
    n = int(input())
    x = n % 1000
    if x:
        print(1000-x)
    else:
        print(0)
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 9156
s=list(input())
t=list(input())
n=len(s)
a=[s.count(chr(97+i)) for i in range(26)]
b=[t.count(chr(97+i)) for i in range(26)]
if all(a[ord(s[i])-97]==b[ord(t[i])-97] for i in range(n)):
    print("Yes")
else:
    print("No")



Measured memory_bytes: 12412
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define all(x) x.begin(),x.end()
#define sz(s) (int) s.size()
#define pb push_back
#define rc(x) return cout<<x<<"\n",0

using namespace std;
    void solve()
    {
     int r;
     cin >> r;
     cout << 3 * r * r;
 }
               
    int main()
    {
        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
        int t=1;
      // cin>>t;
        while(t--)
        {
            solve();
        }
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  int a, b, c;
  cin>>a>>b>>c;
  int k;
  cin>>k;
  int cnt = 0;
  while(a >= b){
    b *= 2;
    cnt++;
  }
  while(b >= c){
    c *= 2;
    cnt++;
  }
  if(cnt <= k){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3676
using System;

namespace E
{
    class Program
    {
        static void Main(string[] args)
        {
            var HW = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var H = HW[0]; var W = HW[1];
            var A = new int[H, W];
            var B = new int[H, W];
            for (int i = 0; i < H; i++)
            {
                var aw = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                for (int j = 0; j < W; j++) A[i, j] = aw[j];
            }
            for (int i = 0; i < H; i++)
            {
                var bw = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
                for (int j = 0; j < W; j++) B[i, j] = bw[j];
            }

            var N = new int[H + 1, W + 1];
            var max = 0;
            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    N[i + 1, j + 1] = Math.Abs(A[i, j] - B[i, j]);
                    max = Math.Max(N[i + 1, j + 1], max);
                }
            }

            max *= H + W;

            bool[,,] map = new bool[max + 1, H + 1, W + 1];
            map[N[1, 1], 1, 1] = true;

            for (int h = 1; h < H + 1; h++)
            {
                for (int w = 1; w < W + 1; w++)
                {
                    for (int n = 0; n <= max; n++)
                    {
                        if (map[n, h - 1, w] || map[n, h, w - 1])
                        {
                            map[Math.Abs(N[h, w] - n), h, w] = true;
                            map[N[h, w] + n, h, w] = true;
                        }
                    }
                }
            }
            for (int n = 0; n <= max; n++)
            {
                if (map[n, H, W])
                {
                    Console.WriteLine(n);
                    break;
                }
            }
        }
    }
}


Measured memory_bytes: 93024
fn main(){
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).expect("failed to read");
    buf.clear();

    std::io::stdin().read_line(&mut buf).expect("failed to read");
    let va: Vec<usize> = buf.split_whitespace().map(|e| e.parse().unwrap()).collect();
    
    let (tc, _): (usize, usize) = va.iter().fold((0, 0), |(tc, mh), &a| if mh <= a {(tc, a)} else {(tc + mh - a, mh)});
        
    println!("{}", tc)
}


Measured memory_bytes: 5836
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[][] = new int[2][N];
		for (int i = 0; i < N; i++) {
			A[0][i] = sc.nextInt();
			if (0 < i) A[0][i] += A[0][i-1];
		}
		for (int i = 0; i < N; i++) {
			A[1][i] = sc.nextInt();
			if (i == 0) A[1][i] += A[0][i];
			else A[1][i] += Math.max(A[0][i], A[1][i-1]);
		}
		System.out.println(A[1][N-1]);
	}
}

Measured memory_bytes: 22228
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

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

    int n;
    cin >> n;

    for(int i=1; i<=n; ++i){
        vector<string> plane(8);
        for(int j=0; j<8; ++j)
            cin >> plane[j];

        int y, x;
        cin >> x >> y;
        -- y;
        -- x;
        plane[y][x] = '0';
        queue<pair<int, int> > q;
        q.push(make_pair(y, x));
        while(!q.empty()){
            y = q.front().first;
            x = q.front().second;
            q.pop();
            for(int j=0; j<4; ++j){
                for(int k=1; k<=3; ++k){
                    int y1 = y + dy[j] * k;
                    int x1 = x + dx[j] * k;
                    if(0 <= y1 && y1 < 8 && 0 <= x1 && x1 < 8 && plane[y1][x1] == '1'){
                        plane[y1][x1] = '0';
                        q.push(make_pair(y1, x1));
                    }
                }
            }
        }

        cout << "Data " << i << ':' << endl;
        for(int j=0; j<8; ++j)
            cout << plane[j] << endl;
    }
}

Measured memory_bytes: 0
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace AtCoder
{
	public class ABC
	{
		static public void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
			Solve(args);
			Console.Out.Flush();
		}

		private const int mod = 1000000007;  // 10^9+7

		static public void Solve(string[] args)
		{
			//string s = Console.ReadLine();
			//int x = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
			long a = vs[0];
			long b = vs[1];
			long n = vs[2];

			long ans = 0;
			//for (long j = 0; j <= n; j++) {
			//	System.Diagnostics.Debug.WriteLine($"{a * j / b - a * (j / b)} = {a} * {j} / {b} - {a} * ({j} / {b})");
			//	ans = Math.Max(ans, a * j / b - a * (j / b));
			//}
			if (n / b == 0) {
				ans = a * n / b - a * (n / b);
			} else {
				ans = a * (b-1) / b - a * ((b-1) / b);
			}
			Console.WriteLine(ans);

		}
	}
}


Measured memory_bytes: 28120
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

typedef long long int64;

int main(void){
    int N,K;
    cin>>N>>K;
    string s;
    cin>>s;
    K--;
    if(s[K]=='A'){
        s[K]='a';
    }else if(s[K]=='B'){
        s[K]='b';
    }else if(s[K]=='C'){
        s[K]='c';
    }

    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
<?php 

$n = trim(fgets(STDIN));

$zoro = false;
$count=0;
for($i=0; $i<$n; $i++){
    $d = explode(" ", trim(fgets(STDIN)) );
    if($d[0] == $d[1]){
        $count++;
    } else {
        $count = 0;
    }
    if($count == 3){
        $zoro = true;
        break;
    }
}

if($zoro){
    echo 'Yes';
}else{
    echo 'No';
}



Measured memory_bytes: 16248
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define print(A,n) for(ll i=0;i<n;++i)cout<<A[i]<<' ';cout<<endl;
#define take(A,n) for(ll i=0;i<n;++i)cin>>A[i];
ll mulmod(ll a,ll b,ll c) 
{ 
    if (b==0) 
        return 0; 
    ll s = mulmod(a, b/2, c); 
    if (b%2==1) 
        return (a%c+2*(s%c)) % c; 
 
    else
        return (2*(s%c)) % c; 
} 

  
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);}
int main()
{ll int t;

t=1;

while(t--)
{

ll int n,count=1,i;
cin>>n;
map<int,vector<string>> m;
string s[n];
for(i=0;i<n;i++)cin>>s[i];
sort(s,s+n);
ll int ma=-1;
for(i=0;i<n-1;i++)
{
    if(s[i]==s[i+1])
    count++;
    else
    {
        m[count].push_back(s[i]);
        ma=max(count,ma);
       count=1;
    }
}
  m[count].push_back(s[i]);ma=max(count,ma);
       count=1;
//auto it = m.end();it--;
vector<string> te;te= m[ma];sort(te.begin(),te.end());
for(i=0;i<te.size();i++)
cout<<te[i]<<endl;





}
 
    return 0;
}

Measured memory_bytes: 17524
/*********************************************JMD**********************************************/
//                                  |\  |     | |   |   /\                                   //
    //                              | \ |     | |---|  /--\                              //
        //                          |  \| |___| |   | /    \1999                     //
/*******************************************************************************************/
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ss second
#define ff first
#define mem(x,val) memset(x,val,sizeof(x))
#define forr(i,a,b) for(ll i=a;i<b;i++)
#define f(i,n) forr(i,0,n)
#define sz(x) ll((x).size())
#define all(x) ((x).begin(),(x).end())
#define asc(x) ((int)(x))
#define precision(x) cout<<fixed<<setprecision((x));

const ll mod=1e9 + 7;

/*******************************************************************************************/

void solve()
{
    ll n;
    cin>>n;
    ll a[n];
    ll m1=-1,m2=-1;

    f(i,n)
    {
        cin>>a[i];

        if(a[i]>=m1)
        {
            m2=m1;
            m1=a[i];
        }
        else if(a[i]>m2)
        {
            m2=a[i];
        }
    }

    f(i,n)
    {
        if(a[i]!=m1) cout<<m1<<"\n";
        else cout<<m2<<"\n";
    }

    return;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll t=1;
    //cin>>t;
    clock_t launch=clock();

    while(t--)
    {
        solve();
    }

    clog<<((long double)(clock()-launch)/CLOCKS_PER_SEC)<<"\n";
}


Measured memory_bytes: 3200
#include <cstdio>
#include <iostream>
#include <cstring>

using namespace std;

char s[100];

int main() {
	scanf("%s",s);
	for(int i = 0; i < strlen(s)-1; i++)
		if(s[i] == 'A' && s[i+1] == 'C') { printf("Yes"); return 0; }
	printf("No");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <utility>
#include <cstdlib>
#define llint long long

using namespace std;
typedef pair<llint, llint> P;

llint n;
llint l[100005], r[100005];
multiset<P> S, T;
llint a, b;

int main(void)
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> l[i] >> r[i];
	
	llint ans = 0;
	S.insert(P(l[1], -1)), T.insert(P(l[1], 1));
	for(int i = 2; i <= n; i++){
		a += r[i]-l[i];
		b += r[i-1]-l[i-1];
		
		auto it = S.end(); it--;
		llint x = it->first - a, y = T.begin()->first + b;
		
		if(l[i] <= x){
			S.insert(P(l[i]+a, -1));
			S.insert(P(l[i]+a, 1));
			auto it = S.end(); it--;
			llint v = it->first - a;
			T.insert(P(v-b, it->second));
			S.erase(it);
			ans += abs(x-l[i]);
		}
		else if(y <= l[i]){
			T.insert(P(l[i]-b, -1));
			T.insert(P(l[i]-b, 1));
			auto it = T.begin();
			llint v = it->first + b;
			S.insert(P(v+a, it->second));
			T.erase(it);
			ans += abs(y-l[i]);
		}
		else{
			S.insert(P(l[i]+a, -1));
			T.insert(P(l[i]-b, 1));
		}
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 14336
//#define _USE_MATH_DEFINES
//#include <math.h>
#include <iostream>
//#include <iomanip>
//#include <bits/stdc++.h>

using namespace std;

int main() {
    
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        if(i % 3 == 0) cout << " " << i;
        else {
            int x = i;
            while(x != 0){
                if(x % 10 == 3){
                    cout << " " << i;
                    break;
                }
                x /= 10;
            }
        }
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3084
using System;
using System.Linq;
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
    string[] str=Console.ReadLine().Split(' ');
      int A=int.Parse(str[0]);
      int B=int.Parse(str[1]);
      int ans=0;
      for(int i=1;i<=2;i++){
       if(A>=B){
         ans+=A;
         A=A-1;
      }else{
         ans+=B;
         B=B-1;
       }
      }
      Console.WriteLine(ans);
    }
    
  }

}


Measured memory_bytes: 27472
from __future__ import division
from collections import namedtuple
import math
Vector=namedtuple('Vector','x y')

def size(H):
    return math.sqrt(pow(H.x,2)+pow(H.y,2))

def inner(A,B):
    return A.x*B.x+A.y*B.y

def collision(tx,ty,sx,sy,px,py,r):
    #if collision: return True
    #else: return False
    S=Vector(x=tx-sx,y=ty-sy)
    A=Vector(x=px-sx,y=py-sy)
    B=Vector(x=px-tx,y=py-ty)
    d=abs(S.x*A.y-A.x*S.y)/size(S)
#    print d,r,inner(A,S)*inner(B,S),size(A),size(B),px,py,r
    if d>r:
        return False
    elif r>size(A) and r>size(B):
        return False
    elif inner(A,S)*inner(B,S)<=0:
        return True
    elif r>size(A) or r>size(B):
        return True
    else:
        return False

while True:
    n=input()
    if n==0:break
    wall=[map(int,raw_input().split()) for i in range(n)]
    m=input()
    for i in range(m):
        tx,ty,sx,sy=map(int,raw_input().split())
        for wx,wy,r in wall:
            if collision(tx,ty,sx,sy,wx,wy,r):
                print 'Safe'
                break
        else:
            print 'Danger'

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

int main(){
  int n,x;
  cin >> n >> x;
  vector<int> a(n);
  long long ans=0;
  for(int i=0;i<n;i++){
    cin >> a[i];
    if(x<a[i]){
      ans+=a[i]-x;
      a[i]=x;
    }
  }
  for(int i=1;i<n;i++){
    if(x<a[i-1]+a[i]){
      ans+=a[i-1]+a[i]-x;
      a[i]=x-a[i-1];
    }
  }
  cout << ans << endl;
}

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

 int main(){
 	string s;
   cin >> s;
	if(s == "RRR") cout << 3 <<endl;
   else if(s == "RRS" || s == "SRR") cout << 2 << endl;
   else if(s == "RSR" || s == "RSS"|| s == "SRS"|| s =="SSR") cout << 1 << endl;
   else cout << 0 << endl;
   
 }

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define IOS ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);

using namespace std;

map<int,vector<int>> mp;
multiset<int> s;

int main()
{
    IOS;
    int n,q;
    cin>>n>>q;
    for(int i=0;i<n;i++)
    {
        int s,t,x;
        cin>>s>>t>>x;
        s-=x;
        t-=x;
        mp[s].pb(x);
        mp[t].pb(-x);
    }
    auto it=mp.begin();
    for(int i=0;i<q;i++)
    {
        int d;
        cin>>d;
        while(it!=mp.end() && (*it).fi<=d)
        {
            for(auto i:(*it).se)
            {
                if(i>0) s.insert(i);
                else s.erase(s.find(-i));
            }
            ++it;
        }
        if(s.size()) cout<<*(s.begin())<<endl;
        else cout<<-1<<endl;
    }
    return 0;
}


Measured memory_bytes: 54400
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);	
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll qw(ll x,ll y){ll res = 1;while(y){if(y & 1) res *= x;x = x * x;y >>= 1;}return res;}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){if(x < 2) return 0; for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
int h1,h2,m1,m2,k;
int main(){
//	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	if(h2 < h1) h2 += 24;
	cout << h2 * 60 + m2 - h1 * 60 - m1 - k << endl;
	return 0;
}
//do smt instead of nothing! never give up!


Measured memory_bytes: 3632
#include<stdio.h>
int n;
long long m;
main()
{
    int i;
    long long x,now,t,ans = 0;
    scanf("%d%lld",&n,&m);
    now = 0;
    for(i=0;i<n;i++)
    {
        scanf("%lld",&x);
        if(now+x>m)
        {
            t = now+x-m;
            ans += t;
            now = x-t;
        }
        else now = x;
    }
    printf("%lld",ans);
}


Measured memory_bytes: 128
N = int(input())

sum = 0
for i in range(N):
    L = list(map(int, input().split()))
    if int(L[0]) == int(L[1]):
        sum += 1
    else:
        sum = 0
    if sum == 3:
        break



if sum >= 3:
    print("Yes")
else:
    print("No")

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

#define Bye return 0
#define ll long long

void solve(){
    string str; cin>>str;
    for (int i=0; i<str.size(); i++)
        printf("%c", str[i] == ',' ? ' ': str[i]);
    printf("\n");
}

int main()
{
    solve();
    Bye;
}

Measured memory_bytes: 3596
# n = gets.chomp.to_i
# a = gets.chomp.split(" ").map(&:to_i)
# arr = Array.new(100000,0)
# ar = arr.size
# #p arr
# a.each do |i|
#     arr[i] = arr[i] + 1
# end

# q = gets.chomp.to_i
# q.times do |j|
#     all = 0
#     b,c = gets.chomp.split(" ").map(&:to_i)
#     until arr[b] == 0
#     arr[b] = arr[b] - 1
#     arr[c] = arr[c] + 1
#     end
#     #p arr
#     (0..ar-1).each do |o|
#         all += arr[o] * o
#     end
#     puts all
# end

n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
ans = a.inject(:+)
hash = Hash.new(0)
aa = a.size
#(0..10001).each do |i|
    #hash[*0..100] = 0
#end
(0..aa-1).each do |i|
    hash[a[i]] += 1
end
#p hash
q = gets.chomp.to_i
q.times do 
    all = []
    b,c = gets.chomp.split(" ").map(&:to_i)
    
    hash[c] += hash[b]
    kari = hash[b]
    hash[b] = 0
    # puts "YY"
    # p ans
    # p kari
    # p hash
    # p hash[c]
    # p hash[b]
    # puts "TTT"
    #p hash
    #hash.each {|i,j| all <<  i*j }
    ans = ans + kari * c -  kari * b
    puts ans
end

Measured memory_bytes: 26500
#include<iostream>
#include<cmath>
#include<string.h>
#include<stdio.h>
#include<algorithm>
using namespace std;

long long x,y;
long long a,b,c;
long long ans=0;
int main()
{
    int i,j,k;
    long long tmp;
    cin>>a>>b>>c>>x>>y;
    c*=2;
    if(x>y)
    {
        swap(x,y);
        swap(a,b);
    }
    
    if(a+b>c)
    {
        tmp=min(x,y);
        ans+=tmp*c;
        x-=tmp;y-=tmp;
    }
    
    tmp=min(a,c);
    ans+=tmp*x;
    
    tmp=min(b,c);
    ans+=tmp*y;
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=1e5+4;
const ull base=263;
char ss[N][10];
int n;
ull f[N];
ll ans;
int main() {
	scanf("%d",&n);
	for (register int i=1;i<=n;++i) {
		scanf("%s",ss[i]);
		sort(ss[i],ss[i]+10);
		for (int j=0;j<10;++j)
			f[i]=f[i]*base+ss[i][j];
	}
	sort(f+1,f+n+1);
	int l=1,r=1;
	while (l<=n) {
		while (r<n&&f[r+1]==f[r]) ++r;
		int len=r-l+1;
		ans+=1ll*len*(len-1)/2;
		l=r+1,++r;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 2048
s = input()
if s[0] == 'R' and s[1] == 'R' and s[2] == 'R':
    print('3')

elif s[0] == 'S' and s[1] == 'S' and s[2] == 'S':
    print('0')
    
elif s.count('R') == 2 and (s[0] == 'S' or s[2] == 'S'):
    print('2')

else:
    print('1')

Measured memory_bytes: 8936
/*input

*/
#include <bits/stdc++.h>
#define up(i,a,b) for(int (i) = (a);(i)<=(b);++(i))
#define down(i,b,a) for(int (i) = (b);i>=(a);--i)
#define debug(x) cerr << (x) << '\n';
#define bits(x,i) ((x >> i) & 1)
#define mid ((l+r)/2)
#define pr pair<int,int>
using namespace std;
const int N = 200005;
#define int long long
int a[N], n, ans;
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	up(i,1,n) cin >> a[i];
	int maxVal = 0, cnt = 0;
	for(int i=1;i<=n;++i){
		if (maxVal < a[i]) {
			ans += maxVal * cnt;
			cnt = 1;
			maxVal = a[i];
		}
		else cnt++;
	}
	ans += maxVal * cnt;
	for(int i=1;i<=n;++i) ans-=a[i];
	cout << ans;	
}

Measured memory_bytes: 5168
a = [list(map(int, input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]
ans = "No"

for i in b:
    for num, j in enumerate(a):
        if i in j:
            a[num][a[num].index(i)] = True
tmp = []
for i in a:
    tmp.extend(i)

tmp2 = []
for i, num in enumerate(tmp):
    if num is True:
        tmp2.append(i + 1)

ans_arr = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9],
    [1, 4, 7],
    [2, 5, 8],
    [3, 6, 9],
    [1, 5, 9],
    [3, 5, 7],
]
for i in ans_arr:
    count = 0
    for j in tmp2:
        if j not in i:
            pass
        else:
            count += 1
    if count == 3:
        ans = "Yes"
        break

print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<60;
double pi=3.141592653589793238462643383279L;
double eps=1e-8;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(int i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    pll han[31];
    ll y=1;
    rep(i,1,31){
        han[i]={y+1,y*2};
        y*=3;
    }
    int q;cin>>q;
    rep(i,0,q){
        ll a,b,c,d;cin>>a>>b>>c>>d;
        a--;b--;c--;d--;
        if(a>c){
            swap(a,c);
            swap(b,d);
        }
        if(b>d){
            b=y-1-b;
            d=y-1-d;
        }
        
        ll ans=c-a+d-b;
        ll yy=y;
        rrep(j,30,1){
            yy/=3;
            //if(j==2)cout<<aa<<" "<<bb<<" "<<cc<<" "<<dd<<endl;
            if(a/yy==c/yy&&(a/yy)%3==1&&abs(b/yy-d/yy)>=2){
                ll aa=a%yy,cc=c%yy;
                Max(ans,abs(b-d)+min(1+aa+1+cc,yy-aa+yy-cc));
            }
            if(b/yy==d/yy&&(b/yy)%3==1&&abs(a/yy-c/yy)>=2){
                ll bb=b%yy,dd=d%yy;
                Max(ans,abs(a-c)+min(1+bb+1+dd,yy-bb+yy-dd));
            }
        }
        cout<<ans<<endl;
    }
}






Measured memory_bytes: 384
#include <iostream>
#include <numeric>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
using namespace std;
#define INF 100000000
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define rep(i, n) for(int (i)=1; (i)<=(n); (i)++)
typedef pair<int, int> P;
typedef long long ll;
int main(){
    string S;
    ll K;
    cin >> S;
    cin >> K;
    for(int i=0; i<K; i++){
        if(S[i] != '1'){
            cout << S[i] << endl;
            return 0;
        }
    }
    cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 256
// Code By Keju
/*
      :::    ::: :::::::::: ::::::::::: :::    :::   :::     :::    ::::::::   :::::::: 
     :+:   :+:  :+:            :+:     :+:    :+: :+:+:   :+:+:   :+:    :+: :+:    :+: 
    +:+  +:+   +:+            +:+     +:+    +:+   +:+     +:+         +:+         +:+  
   +#++:++    +#++:++#       +#+     +#+    +:+   +#+     +#+       +#+        +#++:    
  +#+  +#+   +#+            +#+     +#+    +#+   +#+     +#+     +#+             +#+    
 #+#   #+#  #+#        #+# #+#     #+#    #+#   #+#     #+#    #+#       #+#    #+#     
###    ### ##########  #####       ########  ####### ####### ##########  ########  
*/
#include <bits/stdc++.h>
#include <iomanip>

#define debug(x) cout<<'>'<<#x<<"="<<x<<'\n'
#define debug2(x,y) cout<<'>'<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define debug3(x,y,z) cout<<'>'<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define pb                    push_back
#define _FastIO ios::sync_with_stdio(false); cin.tie(nullptr);
using namespace std;
using ll = long long;
#define loop(i,a,b)           for(int i=(int)a;i<(int)b;++i)
#define mset(a,b,c)           loop(i,0,b) a[i]=c   //name, size, value
//Convert int to string
template <typename T>
string to_str(T str)
{
    stringstream stream;
    stream << str;
    return stream.str();
}
//Convert string to int
template <typename T>
int to_int(T num)
{
    int val;
    stringstream stream;
    stream << num;
    stream >> val;
    return val;
}


//////////////////////////////////////FUNCTIONS////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////////////////


int main()
{
    _FastIO;

    int a,b;
    cin >> a >> b;
    string aa,bb;
    for(int i=0;i<b;i++)
    {
    	aa+=to_str(a);
    }
    for(int i=0;i<a;i++)
    {
    	bb+=to_str(b);
    }
    (aa<=bb)?cout << aa << endl:cout << bb << endl;
}

Measured memory_bytes: 256
def main():
    N, M = map(int, input().split())
    A, B = ['']*N, ['']*M
    for i in range(N):
        A[i] = input()
    for i in range(M):
        B[i] = input()
    ans = False
    len_a = len(A[0])
    len_b = len(B[0])
    for i in range(N - M + 1):
        for j in range(len_a - len_b + 1):
            match = True
            for k in range(M):
                a = A[i + k]
                b = B[k]
                if a[j:j+len_b] != b:
                    match = False
            if match:
                ans = True
                break
        if ans:
            break
    print('Yes' if ans else 'No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#define NDEBUG

#include <unordered_map>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <utility>
#include <numeric>
#include <string>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <tuple>
#include <set>
#include <map>

// [0, max)
#define FOR0(var, max) for (sl (var) = 0; (var) < (max); ++(var))
// [min, max)
#define FORi(var, min, max) for (sl (var) = (min); (var) < (max); ++(var))
// [min, max)
#define FORi_INV(var, min, max) for (sl (var) = (max) - 1; (var) + 1 > (min); --(var))

#define FORITER(var, iter) for (auto (iter) = (var).begin(); (iter) != (var).end(); (iter)++)
#define FORITER_INV(var, iter) for (auto (iter) = (var).rbegin(); (iter) != (var).rend(); (iter)++)

// a < b < c
#define LTLT(a, b, c) (((a) < (b)) && ((b) < (c)))
// a <= b < c
#define LELT(a, b, c) (((a) <= (b)) && ((b) < (c)))
// a < b <= c
#define LTLE(a, b, c) (((a) < (b)) && ((b) <= (c)))
// a <= b <= c
#define LELE(a, b, c) (((a) <= (b)) && ((b) <= (c)))

#ifndef NDEBUG
#  define MASSERT(cond) m_assert(cond, __LINE__, #cond);
#else
#  define MASSERT(...)
#endif

using namespace std;

using uc = unsigned char;
using ui = unsigned int;
using ul = unsigned long long int;

using sc = signed char;
using si = signed int;
using sl = signed long long int;

using ld = long double;

void m_assert(const bool& cond, const sl& line, const char *condstr) {
  if (!cond) {
    cerr << "Assertion Failed: " << condstr << " at line " << line << endl;
    exit(1);
  }
}

static sl N;
static vector<sl> Ai;

void solve(void) {
  sl res = 0;
  FOR0(i, N) {
    if (Ai[i] == res + 1) {
      res++;
    }
  }
  if (res == 0) {
    cout << -1 << endl;
  } else {
    cout << N - res << endl;
  }
}

int main(void) {
  cin >> N;
  Ai.resize(N);
  FOR0(i, N) {
    cin >> Ai[i];
  }
  solve();
  return 0;
}

Measured memory_bytes: 1792