akhauriyash/Code-Regression huggingface dataset:
import itertools
N = int(input())
P = input()
Q = input()

P = int("".join(P.split(" ")))
Q = int("".join(Q.split(" ")))

X = []
for i in itertools.permutations(range(1, N+1)):
    x = list(map(str, i))
    y = int("".join(x))
    X.append(y)

a = X.index(P)
b = X.index(Q)

print(abs(a-b))

Measured memory_bytes: 42588
N,x = map(int,input().split())
a = list(map(int,input().split()))
a = sorted(a)
ans = 0

for i in range(N - 1):
    if x >= a[i]:
        x -= a[i]
        ans += 1
    else:
        break

if x == a[-1]:
    ans += 1

print(ans)


Measured memory_bytes: 3060
# coding: utf-8
A = int(input())
B = int(input())
C = int(input())
X = int(input())
c = 0

for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            if 500 * i + 100 * j + 50 * k == X:
                c += 1
print(c)

Measured memory_bytes: 3060
import java.util.*;

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

        long x =   Math.max(a*c, a*d);
        long y =   Math.max(b*c, b*d);
        long z =   Math.max(x, y);
        
        System.out.println(z);
    }
}


Measured memory_bytes: 35680
#include<iostream>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int const MAXN = 20;
int D[MAXN], N;

uint64_t getZ() {
  uint64_t v = 0; int c;
  while((c = getchar_unlocked()) >= '0') v=v*10+c-'0';
  return v;
}

int main() {
  int N = getZ();
  for(int i = 0; i < N; ++i) D[getZ()-1] = i;
  int ans = 0;
  for(int i = 0; i < N; ++i) ans += getZ();
  for(int i = 0; i < N-1; ++i) {
    int C = getZ();
    if(D[i+1]==D[i]+1) ans += C;
  }
  fin(ans);
  return 0;
}


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

int main(){
    int n;
    cin >> n;
    cout << n*800 - 200*(n/15) << endl;
    return 0;
}


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

int main()
{
	int n;
	cin >> n;
	while (n--) {
		int a[10];
		for (int i = 0; i < 10; i++) {
			cin >> a[i];
		}
		bool res = false;
		for (int i = 0; i < (1 << 10); i++) {
			bool flag = true;
			int am = 0, bm = 0;
			for (int j = 0; j < 10; j++) {
				if (i & (1 << j)) {
					if (a[j] > am) {
						am = a[j];
					}
					else {
						flag = false;
						break;
					}
				}
				else {
					if (a[j] > bm) {
						bm = a[j];
					}
					else {
						flag = false;
						break;
					}
				}
			}
			if (flag) {
				res = true;
			}
		}
		cout << (res ? "YES" : "NO") << endl;
	}
	return 0;
}

Measured memory_bytes: 3072
s = gets.chomp

al = ('a'..'z').to_a

i = 0
if s.length < 26
	while i < al.length
		unless s.include?(al[i])
			puts s+al[i]
			exit
		end
		i += 1
	end
elsif s == "zyxwvutsrqponmlkjihgfedcba"
	puts "-1"
else
	for i in 0..26
		if s[-i-1] > s[-i-2]
			for j in 0..i
				if s[-i-2] < s[-j-1]
					puts s[0..-i-3]+s[-j-1]
					exit
				end
			end
		end
	end
end


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

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

int main(){

 long long n,m;

 map<int,int>M;
 map<int,int>ACM;
 cin>>n>>m;

 int ac=0,wa=0;
 while(m--){

  int p; string s;
  cin>>p>>s;

  if(s == "WA")
      ++M[p];

  else if(s == "AC"){

    if(ACM[p] == 0){
        ACM[p] = 1;
        wa += M[p];
        ac++; }
  }

 }

  cout<<ac<<" "<<wa<<endl;

 return 0;
}


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

string reverse(string s){
	string t;
	int l = s.length();
	for (int i = 0; i < l; i++){
		t += s[l - i - 1];
	}
	return t;
}

int main(){
	string s, c1, c4;
	ostringstream oss;
	int q, c2, c3;
	cin >> s >> q;
	for (int i = 0; i < q; i++){
		cin >> c1 >> c2 >> c3;
		if (c1 == "print"){
			oss << s.substr(c2, c3 - c2 + 1) << endl;
			cout << s.substr(c2, c3 - c2 + 1) << endl;
		}
		if (c1 == "reverse"){
			s = s.substr(0, c2) + reverse(s.substr(c2, c3 - c2 + 1)) + (c3 == s.length() - 1 ? "" : s.substr(c3 + 1));
		}
		if (c1 == "replace"){
			cin >> c4;
			s = s.substr(0, c2) + c4 + (c3 == s.length() - 1 ? "" : s.substr(c3 + 1));
		}
	}
	//cout << oss.str() << endl;
}


Measured memory_bytes: 3248
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template<typename T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n);i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'

typedef vector<int> vi;
typedef vector<pair<int,int> > vii;
typedef long long ll;
typedef pair<int, int> pii;


int main()
{

#ifndef ONLINE_JUDGE
	//freopen("in.in", "r", stdin);
	//freopen("out.in", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    long long ans = 0;
	long long n, k;
	cin >> n >> k;
	vector<long long> pref(n+1);
	Tree<pair<ll,int> > ms;
	for(int  i = 1; i <= n; ++i){
		int num;
		cin >> num;
		pref[i] = pref[i-1] + num;
		ms.insert({pref[i-1] - k * (i - 1),i});
        ans += ms.order_of_key({pref[i] - i * k + 1 , -1});
	}
	cout << ans << endl;

    return 0;
}


Measured memory_bytes: 17176
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++) 
#define rep(i,n); for(int i = 0; i < (n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b); 
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define all(v) (v).begin(),(v).end()
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={0,1,0,-1,1,-1,-1,1};
int dy[]={1,0,-1,0,1,1,-1,-1};
const int MOD = 1e9+7;
const int INF = 1e18+10;

/*----------------------------------------------*/

int modpow(int x, int n){
  int res=1;
  while(n>0){
    if(n&1) res=(res*x)%MOD;
    x=(x*x)%MOD;
    n>>=1;
  }
  return res;
}

int ncr(int n,int r){
  int res=1,fact=1;
  FOR(i,1,r) fact=(fact*i)%MOD;
  rep(i,r) res=(res*(n-i))%MOD;
  res=(res*modpow(fact,MOD-2))%MOD;
  return res;
}

signed main(){
  int n,a,b;
  cin>>n>>a>>b;
  int ans=modpow(2,n)-1;
  ans-=ncr(n,a)+ncr(n,b);
  ans=(ans+3*MOD)%MOD;
  cout<<ans<<endl;
  return 0;
}




Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())

count = 0
for i in range(a+1):
 if 500*i>x: break
 for j in range(b+1):
  if 500*i+100*j>x: break
  for k in range(c+1):
   if 500*i+100*j+50*k == x:
    count += 1

print(count)

Measured memory_bytes: 3064
n,k = map(int,input().split())
s = []
for i in range(n):
    s.append(int(input()))
s.sort()
s.reverse()
ans = s[0]-s[-1]
for i in range(n-k+1):
    ans = min(ans,s[i]-s[i+k-1])
print(ans)

Measured memory_bytes: 13276
#include <stdio.h>

int min(int a, int b)
{
    return a < b ? a : b;
}

int main(void)
{
    int n, a, b;

    scanf("%d %d %d", &n, &a, &b);
    printf("%d\n", min(n * a, b));

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<cstring>
#include<map>
#include<set>
#include<cstdlib>
typedef long long ll;
using namespace std;
ll a[200005];
ll a1[200005];
ll a2[200005];
ll n;
map<ll,ll> m;
int main(void)
{
	scanf("%lld",&n);
	for(ll i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		a1[i]=i+a[i];
		a2[i]=i-a[i];
	}
	for(ll i=2;i<=n;i++)
	{
		m[a2[i]]++;
	}
	ll sum=0;
	for(ll i=1;i<n;i++)
	{
		sum+=m[a1[i]];
		m[a2[i+1]]--;
	}
	printf("%lld",sum);
}

Measured memory_bytes: 31012
#include <stdio.h>
int main(){
  int n,m,a,b;
  scanf("%d%d",&n,&m);
  int boat[200010] = {};
  for(int i=0; i<m; i++){
    scanf("%d%d",&a,&b);
    if(a == 1){
      if(boat[b]>0){
	printf("POSSIBLE");
	return 0;
      }
      boat[b]++;
    }
    if(b == n){
      if(boat[a]>0){
	printf("POSSIBLE");
	return 0;
      }
      boat[a]++;
    }
  }
  printf("IMPOSSIBLE");
  return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>

int main(){
   int N;
   std::cin >> N;
   std::vector<long long int> L(N+1);
   for (int i=0; i<=N; i++){
      if (i == 0)
         L.at(i) = 2;
      else if (i == 1)
         L.at(i) = 1;
      else
         L.at(i) = L.at(i-1) + L.at(i-2);
   }
   std::cout << L.at(N) << std::endl;

}



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

locx = 0
locy =0
time = 0
for i in range(N):
  t,x,y = map(int,input().split())
  time = t-time
  dis = abs(locx-x)+abs(locy-y)
  if (time-dis)<0 :
    print("No")
    exit()
  if (time-dis)%2 == 1:
    print("No")
    exit()
    
  
  time = t
  locx = x
  locy = y
    
  
else :
  print("Yes")

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

bool check(int start, int end, string S)
{
  for (int i = start; i <= end; i++)
  {
    if (i + 1 == end || i + 2 == end)
      break;
    if (S.at(i + 1) == '#')
    {
      if (S.at(i + 2) == '#')
      {
        cout << "No" << endl;
        return 0;
      }
      else
      {
        i++;
      }
    }
  }
  return 1;
}

bool cannot_pass(string S, int b, int d)
{
  for (int i = b - 1; i <= (d - 2) + 1; i++)
  {
    if (S.at(i) == S.at(i + 1) && S.at(i + 1) == S.at(i + 2) && S.at(i) == '.')
      return 0;
  }
  return 1;
}

int main()
{
  int N, a, b, c, d;
  string S;
  cin >> N >> a >> b >> c >> d >> S;
  if (check(b - 1, d - 1, S) && check(a - 1, c - 1, S))
  {
    if (d < c && cannot_pass(S, b - 1, d - 1))
    {
      cout << "No" << endl;
      return 0;
    }
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 900
/*
  Vishal Shrivastava
  i_am_kirito
*/
#include <bits/stdc++.h>
using namespace std;
#define minpq priority_queue <int, vector<int>, greater<int> >
#define maxpq  priority_queue <int>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define ll long long
#define int ll
#define pll pair<ll,ll>
#define pii pair<int,int>
const int mod = 1e9+7, N = 4e5 + 10;
void solve()
{
   int n;
   cin>>n;
   int rem=n%10;
   if(rem==2||rem==4||rem==5||rem==7||rem==9)
    cout<<"hon\n";
    else if(rem==0||rem==1||rem==6||rem==8)
        cout<<"pon\n";
    else
        cout<<"bon\n";
  return;
}
 
int32_t main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int test=1;
  //cin>>test;
  while(test--)
  {
    solve();
  }
}

Measured memory_bytes: 3692
#include <stdlib.h>
#include <iostream>
#include <algorithm>

using namespace std;

int main(void){
    int A, B;
    char C[100][100];

    cin >> A >> B;

    A--;
    B--;

    for(int i=0;i<100;i++){
        for(int j=0;j<100;j++){
            if(i < 50){
                C[i][j] = '.';
            }
            else{
                C[i][j] = '#';
            }
        }
    }

    for(int i=0;i<50;i+=2){
        for(int j=1;j<100;j+=2){
            if(B <= 0){
                C[i][j] = '.';
            }
            else{
                C[i][j] = '#';
            }
            B--;
        }
    }
    for(int i=51;i<100;i+=2){
        for(int j=1;j<100;j+=2){
            if(A <= 0){
                C[i][j] = '#';
            }
            else{
                C[i][j] = '.';
            }
            A--;
        }
    }

    cout << 100 << ' ' << 100 << endl;

    for(int i=0;i<100;i++){
        for(int j=0;j<100;j++){
            cout << C[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
from  collections import Counter

if __name__ == '__main__':
    H, W = list(map(int, input().split()))
    a = []
    for i in range(H):
        a.extend(input())

    counter = Counter(a)

    value_divide_by_4 = []
    for i in counter.values():
        value_divide_by_4.append(i % 4)
    # print(value_divide_by_4)

    ans = "Yes"
    cnt_odd = 0
    cnt_even = 0
    if H % 2 == 0 and W % 2 == 0:
        for i in value_divide_by_4:
            if i != 0:
                ans = "No"
                break
    elif H % 2 != 0 and W % 2 != 0:
        # cnt_odd = 0
        # cnt_even = 0
        accept = (H - 1) // 2 + (W - 1) // 2
        for i in value_divide_by_4:
            if i == 1:
                cnt_odd += 1
            elif i == 3:
                cnt_odd += 1
                cnt_even += 1
            elif i == 2:
                cnt_even += 1

            if cnt_odd >= 2:
                ans = "No"
                break
            elif cnt_even > accept:
                ans = "No"
                break
    else:
        if H % 2 == 0:
            accept = H // 2
        else:
            accept = W // 2

        for i in value_divide_by_4:
            if i == 1:
                cnt_odd += 1
            elif i == 3:
                cnt_odd += 1
                cnt_even += 1
            elif i == 2:
                cnt_even += 1

            if cnt_odd >= 2:
                ans = "No"
                break
            elif cnt_even > accept:
                ans = "No"
                break

    print(ans)


Measured memory_bytes: 3444
import bisect
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for b in range(N):
    for a in range(b):
        ab = L[a]+L[b]
        r = bisect.bisect_left(L, ab)
        l = b+1
        ans += max(0, r-l)
print(ans)


Measured memory_bytes: 3188
N = int(input())
v = [int(x) for x in input().split()]

v = sorted(v)

for i in range(N-1):
    mix = (v[0] + v[1]) / 2
    v.pop(1)
    v.pop(0)
    v.append(mix)
    v = sorted(v)

print(v[0])

Measured memory_bytes: 3060
#include<iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>

unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

#define LOCAL  1
#define UPLOAD 2

using namespace std;

int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;

    int count = 0;
    for(int i=0;i<=N;i++){
        if((int)floor(log10(i)+1) % 2 == 1){
            count++;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 384
N=int(input())
import sys
l=[list(map(int,input().split())) for i in range(N)]
if l[0][0] != l[0][1] + l[0][2]:
   print("No")
   exit()
for i in range(N-1):
   if abs(l[i][0]-l[i+1][0]) >= abs(l[i][1]-l[i+1][1])+abs(l[i][2]-l[i+1][2]):
      if (abs(l[i][0]-l[i+1][0])-abs(l[i][1]-l[i+1][1])-abs(l[i][2]-l[i+1][2]))%2==0:
         pass
      else:
         print("No")
         exit()
   else:
      print("No")
      exit()
print("Yes")

Measured memory_bytes: 27300
import java.util.Scanner;

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

    int x=scan.nextInt();
    int i=1;

    while (x!=0) {
        System.out.printf("Case %d: %d\n",i,x);
        x=scan.nextInt();
        i++;
    }
    }
}


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

using namespace std;
using ll = long long;

vector< ll > divisor(ll n) {
	vector< ll > ret;
	for(ll i = 1; i * i <= n; i++) {
		if(n % i == 0) {
			ret.push_back(i);
			if(i * i != n) ret.push_back(n / i);
		}
	}
	sort(begin(ret), end(ret));
	return ret;
}

int main() {
	ll N;
	cin >> N;
	ll min = INT64_MAX;
	
	auto divs = divisor(N);
	// for(auto&& v : divs) printf("%lld ", v);
	// printf("\n");
	ll tmp;
	for(int i=0; i<divs.size(); i++) {
		tmp = divs[i] + divs[divs.size()-1 - i] - 2;
		min = (tmp < min) ? tmp : min;
	}
	
	cout << min << endl;
	
	return 0;
}


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

int a[5];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a+3);
    int MAX = a[2];
    if((a[2]-a[0])%2==0 && (a[2]-a[1])%2==0) {
        cout << (a[2]-a[0])/2 + (a[2]-a[1])/2;
    } else if((a[2]-a[0])%2==1 && (a[2]-a[1])%2==1) {
        cout << (a[2]-a[0])/2 + (a[2]-a[1])/2 + 1;
    } else {
        if((a[2]-a[0])%2==0) {
            a[0]++;
            a[2]++;
            cout << 1 + (a[2]-a[0])/2 + (a[2]-a[1])/2;
        } else {
            a[1]++;
            a[2]++;
            cout << 1 + (a[2]-a[0])/2 + (a[2]-a[1])/2;
        }
    }

    return 0;
}


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

int main() {
  ll n, m, k;
  cin >> n >> m >> k;

  ll sa[n + 1], sb[m + 1];
  sa[0] = sb[0] = 0;
  for (int i = 1; i <= n; i++) {
    ll a;
    cin >> a;
    sa[i] = sa[i - 1] + a;
  }
  for (int i = 1; i <= m; i++) {
    ll b;
    cin >> b;
    sb[i] = sb[i - 1] + b;
  }

  ll ans = 0;
  ll nb = m;
  for (ll na = 0; na <= n; na++) {
    if (sa[na] > k) break;
    while (sa[na] + sb[nb] > k) {
      nb--;
    }
    ans = max(ans, na + nb);
  }

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

Measured memory_bytes: 6744
using System;

namespace app1
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			string s = Console.ReadLine ();
			string[] str = Console.ReadLine ().Split (' ');
			int o = int.Parse (s);

			int[] p = new int[o];

			for (int i = 0; i < o; i++) {
				p [i] = int.Parse (str [i]);
			}
				
			Array.Reverse (p);

			for(int i=0;i<o;i++) {
				Console.Write (p[i]);
				if (i == o - 1) {
					break;
				}
				Console.Write (" ");
			}
			Console.WriteLine ();

		}
	}
}

Measured memory_bytes: 9280
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,y;
	cin>>n>>y;
	y/=1000;
	for(ll i=0;i<=n;i++){
		for(ll j=0;j<=n;j++){
			ll z = y - 10*i-5*j;
			if(z < 0) continue;
			if(i+j+z == n && 10*i+5*j+z == y){
				cout<<i<<" "<<j<<" "<<z<<"\n";
				return 0;
			}
		}
	}
	
	cout<<"-1 -1 -1\n";
	return 0;
}

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

int main()
{
  char C[2][3] ;
  for(int i=0;i<2;i++) for(int j=0;j<3;j++) cin>>C[i][j] ;
  
  if(C[0][0]!=C[1][2]||C[0][1]!=C[1][1]||C[0][2]!=C[1][0]) cout<<"NO"<<endl ;
  else cout<<"YES"<<endl ;

  return 0 ;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	ans := gcd(a, b)
	fmt.Println(ans)
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}



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

using namespace std;

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Ti = tuple<int, int, int>;
using Tl = tuple<ll, ll, ll>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define Get(t, i) get<(i)>((t))
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)

const int inf = 1 << 25;
const ll INF = 1LL << 55;

int main()
{
  int N; cin >> N;
  vector<int> T(N); rep(i, N) cin >> T[i];
  vector<int> A(N); rep(i, N) cin >> A[i];
  long long ans = 1;
  vector<int> S(N, 0);
  reps(i, 1, N) {
    if(T[i] < T[i-1]) {
      cout << 0 << endl;
      return 0;
    }
  }
  reps(i, 2, N+1) {
    if(A[N-i] < A[N-i+1]) {
      cout << 0 << endl;
      return 0;
    }
  }
  S[0] = T[0];
  reps(i, 1, N) {
    if(T[i] != T[i-1]) {
      if(S[i] == 0 || S[i] == T[i]) S[i] = T[i];
      else {
	cout << 0 << endl;
	return 0;
      }
    }
  }
  S[N-1] = A[N-1];
  reps(i, 2, N+1) {
    if(A[N-i] != A[N-i+1]) {
      if(S[N-i] == 0 || S[N-i] == A[N-i]) S[N-i] = A[N-i];
      else {
	cout << 0 << endl;
	return 0;
      }
    }
  }
  vector<int> B(N), U(N);
  B[0] = S[0];
  reps(i, 1, N) {
    B[i] = max(B[i-1], S[i]);
  }
  U[N-1] = S[N-1];
  reps(i, 2, N+1) {
    U[N-i] = max(U[N-i+1], S[N-i]);
  }
  rep(i, N) {
    if(B[i] != T[i] || U[i] != A[i]) {
      cout << 0 << endl;
      return 0;
    }
  }
  reps(i, 1, N) {
    if(S[i] == 0) ans = (ans * min(A[i], T[i])) % 1000000007 ;
  }
  cout << ans << endl;

  return 0;
}


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

    ll sm[200020];

    void solve() {
        ll n, c;
        cin >> n >> c;
        ll x[n], y[n], z[n], a[200020];
        for(ll i = 0; i < n; i++) cin >> x[i] >> y[i] >> z[i];
        ll cnt = 0;
        for(ll j = 1; j <= c; j++) {
           for(ll i = 0; i < 200020; i++) a[i] = 0;
           for(ll i = 0; i < n; i++) if(z[i] == j) a[2*x[i] - 1]++, a[2*y[i]]--;
           for(ll i = 1; i < 200020; i++) a[i] += a[i-1];
           for(ll i = 0; i < 200020; i++) if(a[i] > 0) cnt = max(cnt, ++sm[i]);
        }
        cout << cnt << endl;
    }

    int main() {
      cin.sync_with_stdio(0); cin.tie(0);
      cin.exceptions(cin.failbit);
      //ll ti;   cin >> ti;  while(ti--)
      solve();
      return 0;
    }


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

iSP = []
for i in range(N):
    S, P = input().split()
    iSP.append([i + 1, S, int(P)])
    
iSP.sort(key = lambda x: x[2], reverse = True)
iSP.sort(key = lambda x: x[1])

for x in iSP:
    print(x[0])

Measured memory_bytes: 38512
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>

//エイリアス
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    template<typename T>
    vector<T> read_vec(size_t n){
        vector<T> tmp(n);
        for(size_t i = 0; i < n; i++){
            cin >> tmp[i];
        }
        return tmp;
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;
    
    string S, T;
    io.read(S, T);
    int ans = 0;
    for(int i = 0; i < S.size(); i++){
        if(S[i] != T[i]) ans++;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3916
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  
  vector<int> l(m),r(m);
  for(int i=0;i<m;i++){
    cin >> l.at(i) >> r.at(i);
  }
  sort(l.begin(),l.end());
  sort(r.begin(),r.end());
  
  if(l.at(m-1)>r.at(0)){
    cout << 0 << endl;
    }else{
      cout << r.at(0)-l.at(m-1)+1 << endl;
  }
}

Measured memory_bytes: 1024
local n=io.read("n")
local a={1,1,1}
for i=1,n do
    local input=io.read("n")
    a[input]=a[input]+1
end

local dp={}
for i=1,n+1 do
    dp[i]={}
    for j=1,n+1 do
        dp[i][j]={}
        for k=1,n+1 do
            dp[i][j][k]=-1
        end
    end
end


local function solve(i,j,k)
    if dp[i][j][k]>=0 then
        return dp[i][j][k]
    end
    if i==1 and j==1 and k==1 then
        return 0
    end
    local total=0
    if i>1 then
        total=total+solve(i-1,j,k)*(i-1)
    end
    if n+1>i and j>1 then
        total=total+solve(i+1,j-1,k)*(j-1)
    end
    if n+1>j and k>1 then
        total=total+solve(i,j+1,k-1)*(k-1)
    end
    total=total+n
    total=total*(1/(i+j+k-3))
    
    dp[i][j][k]=total
    return dp[i][j][k]
end

print(solve(a[1],a[2],a[3]))

Measured memory_bytes: 371376
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int m, d;
    cin >> m >> d;
    int cnt = 0;
    for(int i = 1; i <= m; i++){
        for(int j = 10; j <= d; j++){
            if(j/10 > 1 && j % 10 > 1 && (j / 10) * (j % 10) == i) cnt++;  
        }
    }
    cout << cnt;
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))

dp = [0]*(N)
dp[0] = 0
dp[1] = abs(H[1] - H[0])
for i in range(2, N):
    dp[i] = min(dp[i-1]+abs(H[i] - H[i-1]), dp[i-2] + abs(H[i] - H[ i-2]))
print(dp[-1])


Measured memory_bytes: 20632
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>

using namespace std;

#define sz(a) static_cast<int>((a).size())
#define f first
#define s second
#define els(v) for (auto &el : (v))


#ifdef KIRYA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) {
    cerr << _s << " = " << _h << "\n";
}

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;

    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;

    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

const int64_t INF = static_cast<int64_t>(1e9) + 7;
const int64_t LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

void solve() {
    int l, r;
    cin >> l >> r;
    if (r / 2019 > l / 2019) {
        cout << "0\n";
        return;
    }
    l %= 2019;
    r %= 2019;
    if (r <= l) {
        r += 2019;
    }
    int res = (l * (l + 1)) % 2019;
    for (int i = l; i <= r; ++i) {
        for (int j = l; j < i; ++j) {
            res = min(res, (i * j) % 2019);
        }
    }
    cout << res;
}

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

    int q = 1;

    for (int i = 0; i < q; ++i) {
        solve();
    }
}

Measured memory_bytes: 256
//-----------------------
// author : xyqkoala
// time : 2020-09-20
//-----------------------

#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;

typedef long long LL;
const int MOD = 1e9+7;

void solve();


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


void solve(){
	LL n,x,m;
	cin>>n>>x>>m;
	vector<LL> dp{0};
	vector<int> vis(m+1,0);
	LL s = x;
	int idx = 1;
	while(!vis[s]){
		vis[s] =idx++;
		dp.push_back(s+dp.back());
		s = (s*s)%m;
	}
	// for(auto item:dp) cout<<item<<endl;
	if(LL(dp.size())>n){
		cout<<dp[n]<<endl;
		return;
	}
	LL res = 0;
	res+=dp.back();
	int tn = dp.size()-1;
	n-=tn;
	int tcnt = tn+1-vis[s];
	res+=(n/tcnt) * (dp[tn]-dp[vis[s]-1]);
	n = n%tcnt;
	res+=dp[vis[s]+n-1]-dp[vis[s]-1];
	cout<<res<<endl;
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int n;
  string s[50];
  cin>>n;
  int cnt[26],cnt2[26];
  rep(i,26){
    cnt[i]=0;
    cnt2[i]=BIG;
  }
  rep(i,n){
    cin>>s[i];
  }
  rep(i,n){
    rep(j,s[i].size() ){
      cnt[s[i][j]-97]++;
    }
   
    rep(j,26){
      cnt2[j]=min(cnt2[j],cnt[j]);
      cnt[j]=0;
    }
    // cout<<cnt2[0]<<" "<<cnt2[1]<<" "<<cnt2[2]<<" "<<cnt2[3];
  }
  rep(i,26){
    while(cnt2[i]!=0){
      char c=i+97;
      cout<<c;
      cnt2[i]--;
    }
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $n);
$x = strlen($n);
$m = floor(sqrt($n));
$mx = strlen($m);
for ($i = 2; $i <= $m; $i++) {
	if ($n % $i == 0) {
		$x = strlen($n / $i);
		if ($x == $mx) break;
	}
}
echo $x, "\n";

Measured memory_bytes: 4604
// AOJ ALDS1_11_A Graph
// 2018.5.1 bal4u

#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

char mat[102][102];

int main()
{
	int n, i, k, u, v;

	n = in();
	for (i = 0; i < n; i++) {
		u = in()-1;
		k = in();
		while (k--) {
			v = in()-1;
			mat[u][v] = 1;
		}
	}
	for (u = 0; u < n; u++) {
		pc('0'+mat[u][0]);
		for (v = 1; v < n; v++) pc(' '), pc('0'+mat[u][v]);
		pc('\n');
	}
	return 0;
}


Measured memory_bytes: 2040
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
  
public class Main{
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        while(true){
            String str[] = br.readLine().split(" ");
            int h = Integer.parseInt(str[0]);
            int w = Integer.parseInt(str[1]);
            if(h==0 && w==0) break;
            for(int i=0;i<h;i++){
                for(int j=0;j<w;j++){
                    sb.append("#");
                }
                sb.append("\n");
            }
            sb.append("\n");
        }
        System.out.print(sb);
    }
}

Measured memory_bytes: 25480
#include <bits/stdc++.h>
#define maxn 100005
#define MOD 1000000007
#define INF 1000000000000000000
#define lim 20

using namespace std;

#define ll long long
#define pii pair<ll, ll>
#define piii pair<pii, ll>
#define ft first
#define sd second

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}


void solve(){
    ll n;
    cin >> n;
    ll s = 0;
    for(ll i = 0; i < n; i++){
        for(ll j = 0; j < n; j++){
            for(ll k = 0; k < n; k++){
                s += __gcd(__gcd(i+1, j+1), (k+1));
            }
        }
    }
cout << s;

}
int main()
{
    fast();
    ll t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

using FLOW = int;
const int MAX_V = 100;
const FLOW INF = 100000000;

struct Edge {
    int rev, from, to;
    FLOW cap, icap;
    Edge(int r, int f, int t, FLOW c)
        : rev(r), from(f), to(t), cap(c), icap(c) {}
};

struct Graph {
    int V;
    vector<Edge> list[MAX_V];
    Graph(int n = 0) { init(n); }
    void init(int n = 0) {
        V = n;
        for(auto &&v : list)
            v.clear();
    }
    void resize(int n = 0) { V = n; }
    void reset() {
        for(auto &&v : list)
            for(auto &&e : v)
                e.cap = e.icap;
    }
    vector<Edge> &operator[](int i) { return list[i]; }
    Edge &redge(Edge e) { return list[e.to][e.rev + (e.from == e.to)]; }
    void addedge(int from, int to, FLOW cap) {
        list[from].emplace_back(list[to].size(), from, to, cap);
        list[to].emplace_back(list[from].size() - 1, to, from, 0);
    }
};

static int level[MAX_V];
static int iter[MAX_V];

void dibfs(Graph &G, int s) {
    memset(level, -1, sizeof(level));
    level[s] = 0;
    queue<int> que;
    que.push(s);
    while(!que.empty()) {
        int v = que.front();
        que.pop();
        for(auto &&e : G[v]) {
            if(level[e.to] < 0 && e.cap > 0) {
                level[e.to] = level[v] + 1;
                que.push(e.to);
            }
        }
    }
}

FLOW didfs(Graph &G, int v, int t, FLOW f) {
    if(v == t) return f;
    for(int &i = iter[v]; i < (int)G[v].size(); i++) {
        Edge &e = G[v][i], &re = G.redge(e);
        if(level[v] < level[e.to] && e.cap > 0) {
            FLOW d = didfs(G, e.to, t, min(f, e.cap));
            if(d > 0) {
                e.cap -= d;
                re.cap += d;
                return d;
            }
        }
    }
    return 0;
}

FLOW Dinic(Graph &G, int s, int t) {
    FLOW res = 0;
    while(true) {
        dibfs(G, s);
        if(level[t] < 0) return res;
        memset(iter, 0, sizeof(iter));
        FLOW f;
        while((f = didfs(G, s, t, INF)) > 0)
            res += f;
    }
}

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

    int n, m;
    cin >> n >> m;
    Graph G(n);
    rep(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        G.addedge(a, b, c);
    }

    cout << Dinic(G, 0, n - 1) << "\n";

    return 0;
}


Measured memory_bytes: 3248
#include<iostream>
#include<stack>
using namespace std;
typedef long long ll;
#define fr(i,n) for(int i=0;i<n;i++)

int main(){
  char x[200010],y;
  int n=0;
  stack<char> z;
  for(;cin>>y;) x[n++]=y;
  fr(i,n){
    if(x[i]=='S') z.push('S');
    else{
      if(!z.empty() && z.top()=='S') z.pop();
      else z.push('T');
    }
  }
  cout<<z.size()<<endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 0
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
using namespace std;

int n,m,ans;
vector<int> v;
unordered_map<int,int> flag;
void dfs(int num,int i){
	if(flag[num])return;
	if(num>3234566667)return;
	flag[num]=1;
	v.push_back(num);
	string s=to_string(num);
	if((s[s.size()-1]-'0')-1>=0)dfs(num*10+((s[s.size()-1]-'0')-1),i+1);
	if((s[s.size()-1]-'0')+1<10)dfs(num*10+((s[s.size()-1]-'0')+1),i+1);
	dfs(num*10+(s[s.size()-1]-'0'),i+1);
}
signed main(){
	cin>>n;
	dfs(0,0);
	dfs(1,0);
	dfs(2,0);
	dfs(3,0);
	dfs(4,0);
	dfs(5,0);
	dfs(6,0);
	dfs(7,0);
	dfs(8,0);
	dfs(9,0);
	sort(v.begin(),v.end());
	//rep(i,v.size())cout<<i+1<<":"<<v[i]<<endl;
	//cout<<endl;
	cout<<v[n]<<endl;
}

Measured memory_bytes: 15036
#include<bits/stdc++.h>
using namespace std;
#define READ() freopen("in.txt","r",stdin)
#define WRITE() freopen("out.txt","w",stdout)
#define  pb(x)  push_back(x)
#define mem(arr,val) memset(arr,val,sizeof(arr));

typedef long long int ll;
const int mx=30005;
vector<int>G[mx],cost[mx];
struct data{
    bool ev;
    int val;
};

bool cmp(data a,data b)
{
    if(a.val<b.val)
    {
        return true;
    }
    if(a.val==b.val)
    {
        return a.ev;

    }
    return false;
}
int vis[105],arr[102][102];
int main()
{
  //READ();
  int n;
  cin>>n;
  ll arr[n+2],total=0;
  arr[0]=0;
  for(int i=1;i<=n;i++)
  {
      cin>>arr[i];
      total+=abs(arr[i]-arr[i-1]);
  }
  arr[n+1]=0;
   total+=abs(arr[n+1]-arr[n]);
    for(int i=1;i<=n;i++)
  {
      cout<<abs(total-abs(arr[i]-arr[i-1])-abs(arr[i+1]-arr[i])+abs(arr[i+1]-arr[i-1]))<<endl;
  }
    return 0;


}




Measured memory_bytes: 3456
#include<stdio.h>

int main(void)
{
   int n, s[100], i, v=0, x=0, a=0;

   scanf("%d",&n);
   for(i=0;i<n;i++){
      scanf("%d",&s[i]);
      v+=s[i];
      if(s[i]%10==0)
         x++;
      if((s[i]%10!=0)&&((a==0)||(a>s[i])))
         a=s[i];
   }

   if(n==x)
      printf("0\n");
   else if(v%10!=0)
      printf("%d\n",v);
   else
      printf("%d\n",v-a);
   return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  priority_queue<int> Q;
  for (int a; cin >> a;) Q.push(a);
  while (M--) Q.push(Q.top() / 2), Q.pop();
  long ans = 0;
  while (Q.size()) ans += Q.top(), Q.pop();
  cout << ans << "\n";
}

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

#define rep(a,b) for(int ii=a;ii<b;ii++)
#define ll long long int
#define test() int tt; cin>>tt; while(tt--) 
#define arrayInput for(int ii = 0; ii<n; ii++) cin >> arr[ii];
#define fst_io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl '\n'
#define lg 1000000000

int main()
{
  int x, y, c = 0, f = 0;
  test()
  {
    cin >> x >> y;
    if(x == y) c++;
    else if(x != y) c = 0;
    if(c == 3) f=1;
  }
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3632
import numpy as np 
from itertools import combinations

n,m,x = map(int, input().split())
n_num = [_ for _ in range(n)]

l = np.array([list(map(int, input().split())) for _ in range(n)])

ptns = []
for i in range(n):
    ptns += list(combinations(n_num, i+1))

ans = float('inf')
for j in range(len(ptns)):
    tmp = np.array([0]*(m+1))
    for k in range(len(ptns[j])):
        tmp += l[ptns[j][k]]
    if min(tmp[1:]) >= x:
        ans = min(ans, tmp[0])
    
print(-1 if ans == float('inf') else ans)

Measured memory_bytes: 27184
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

int main(){
  ll x , y;
  cin >> x >> y;
  int times = 1;
  while(x * 2 <= y) x *= 2 , times++;
  cout << times << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
typedef long long ll;

using namespace std;

int main() 
{
  string str;
  cin >> str;
  int num;
  cin >> num;
  REP(i, num) {
    string cmd;
    cin >> cmd;
    int a, b;
    cin >> a >> b;
    if (cmd == "replace") {
      string p;
      cin >> p;
      str.replace(a, b-a+1, p);
    } else if (cmd == "reverse") {
      string rs = str;
      int j = b;
      FOR(i, a, b + 1)
      {
        str[i] = rs[j];
        j--;
      }
    } else if (cmd == "print") {
      FOR(i, a, b+1) {
        cout << str[i];
      }
      cout << "\n";
    }
  }
}



Measured memory_bytes: 3176
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main() {
	int X , t;

	cin >> X >> t;

	if (X > t) {
		X = X - t;
			cout << X<<endl;
			
	}
	else {
		X = 0;
			cout << X<<endl;
	}
}

Measured memory_bytes: 256
def func(a, b):
    g1 = [1, 3, 5, 7, 8, 10, 12]
    g2 = [4, 6, 9, 11]
    result = 'Yes' if (A in g1 and B in g1) or (A in g2 and B in g2) else 'No'
    return result

A, B = map(int, input().split())

print(func(A, B))

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {
  int A, B;
  cin >> A >> B;
  
  if (A == 1) {
    A += 13;
  }
  if (B == 1) {
    B += 13;
  }
  if (A > B) {
    cout << "Alice" << endl;
  } else if (A < B) {
    cout << "Bob" << endl;
  } else {
    cout << "Draw" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	double n;
	while (cin >> n) {
		if (n <= 48.0) cout << "light fly" << endl;
		else if (n <= 51.0) cout << "fly" << endl;
		else if (n <= 54.0) cout << "bantam" << endl;
		else if (n <= 57.0) cout << "feather" << endl;
		else if (n <= 60.0) cout << "light" << endl;
		else if (n <= 64.0) cout << "light welter" << endl;
		else if (n <= 69.0) cout << "welter" << endl;
		else if (n <= 75.0) cout << "light middle" << endl;
		else if (n <= 81.0) cout << "middle" << endl;
		else if (n <= 91.0) cout << "light heavy" << endl;
		else cout << "heavy" << endl;
	}
}

Measured memory_bytes: 0
def main():
    from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #n = int(stdin.readline()[:-1])   
    r = stdin.readline()[:-1]
    #r = [stdin.readline() for i in range(n)]
    #t = [int(stdin.readline()) for i in range(n)]
    #n = int(r)
    #a = r.split()
    #a,b,c = r.split()
    #a = list(map(int, r.split()))
    #a,b,c,d = map(int, r.split())
    #a = [int(s[i]) for i in range(1, n+1)]
    #a = [list(map(int, r.split())) for i in range(1,n+1)]
    #res = 0

    print(r.replace(',',' '))

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
// This code Write By chtholly_micromaker(MicroMaker)
#include <cstdio>
#include <cctype>
#define reg register
using namespace std;
template <class t> inline void rd(t &s)
{
	s=0;
	reg char c=getchar();
	while(!isdigit(c))
		c=getchar();
	while(isdigit(c))
		s=(s<<3)+(s<<1)+(c^48),c=getchar();
	return;
}
signed main(void)
{
	int n,d;rd(n);rd(d);
	reg int ans=0;
	while(true)
	{
		n-=d*2+1;
		++ans;
		if(n<=0)
			break;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
N = int(input())
T, A = map(int, input().split())
h_list = list(map(int, input().split()))

T_list = []
margin = []
for i in range(N):
    h = h_list[i]
    t = T - h*0.006
    margin.append(abs(A-t))

min_margin = float("inf")
min_i = -1

for i in range(N):
    if min_margin >= margin[i]:
        min_margin = margin[i]
        min_i = i+1
print(min_i)




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

int main(){
    int K;
    string S;
    cin >> K;
    cin >> S;
    if(S.size() <= K){
        cout << S << endl;
    }
    else{
        for(int i=0;i<K;i++){
            cout << S[i];
        }
        cout << "..." <<endl;
    }
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string S, T;
	cin >> S >> T;
	REP(n, 2) {
		vector<char> VC(26, '.');

		REP(i, SZ(S)) {
			if (VC[S[i] - 'a'] != '.') {
				if (VC[S[i] - 'a'] != T[i]) {
					cout << "No" << endl;
					PAU;
					return 0;
				}
			}
			else {
				VC[S[i] - 'a'] = T[i];
			}
		}
		swap(S, T);
	}
	cout << "Yes" << endl;
	PAU;
	return 0;
}


Measured memory_bytes: 1164
#include <iostream>
#include <cstdio>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());

int main(){
	int n;
	cin>>n;
	vint v(n,0);
	int a[200][3]={0};
	int b[300][3]={0};
	rep(i,n){
		rep(j,3){
			cin>>b[i][j];
			a[b[i][j]][j]++;
		}
	}
	rep(i,n){
		rep(j,3){
			if(a[b[i][j]][j]==1){
				v[i]+=b[i][j];
			}
		}
	}
	rep(i,n){
		cout<<v[i]<<endl;
	}

}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<vector<int>> vvi;
#define clr(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define frpn(x) freopen(#x ".in","r",stdin);freopen(#x ".out","w",stdout);
#define all(a) a.begin(), a.end()
#define mkp make_pair
#define forn(i, n) for(int i=0; i<(int)(n); ++i)
#define forab(i, a, b) for(int i=(int)(a); i<=(int)(b); ++i)
#define fornd(i, n) for(int i=(int)(n-1); i>=0; --i)

const int MOD = (int)1e9+7;

template <class T>
inline void rem(T &n){
   n = (-MOD <= n && n <= MOD) ? n : n%MOD ;
  if(n < 0) n += MOD; 
}
//modular inverse
//inv(a,m) - inverse of a mod m
template <class T>
inline T inv(T a, T m){
 return 1<a ? m - inv(m%a, a)*m/a : 1;
}
//const int NAX = (int)3e5+5;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef LOCAL
    clock_t tStart = clock();
#endif
    string s; cin >> s;
    forn(i, s.length()) {
      if(s[i] == 'U' || s[i] == 'D') continue;
      if((i+1)%2 == 0 && s[i] == 'R') {
        cout << "No\n";
        return 0;
      }  
      else if((i+1)%2 == 1 && s[i] == 'L') {
         cout << "No\n";
         return 0;
      }
    }
    cout << "Yes\n";
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * (clock() - tStart)/ CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


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

typedef long long ll;
typedef long double ld;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	
	
	int a,b,c;
	cin>>a>>b>>c;
	
	int i=0;
	
	while(i<=b)
	{
		int temp=a*i;
		if(temp%b==c)
		{
			printf("YES");
			return 0;
		}
		i++;
	}
	
	printf("NO");
	
		
	return 0;
}



Measured memory_bytes: 256
/* Alohomora */
#include<bits/stdc++.h>
#define ll         long long
#define fl(i,n)    for(i=0;i<n;i++)
#define fld(i,a,b) for(i=a;i>b;i--)
#define fli(i,a,n) for(i=a;i<n;i++)
#define pb         push_back
#define mp         make_pair
#define mod        1000000007
#define all(x)     x.begin(),x.end()    
#define F          first 
#define S          second
#define speedup    ios_base::sync_with_stdio(false),cin.tie(0)
using namespace std;
void comp() {
 ll i,j,k,n,m;
 cin>>n>>m;
 vector<ll>v1;
  ll sum=0;
  fl(i,n)
   {
     cin>>j;
     sum+=j;
     v1.pb(j);
   } 
   ll temp1=4*m;
   ll temp=(sum/temp1);
   if(sum%temp1)
   {
      temp++;
   }
   sort(v1.rbegin(),v1.rend());
   ll count1=0;
   fl(i,n)
   {
      if(v1[i]<temp) {
        break;
      }
      count1++;
   }
   if(count1>=m) cout<<"Yes\n";
   else cout<<"No\n";
}
  
int main() {
  speedup;
  ll i=0,t;
  //cin>>t;
  t=1;
  while(t--) {
    comp();
  }
  return 0;
}



Measured memory_bytes: 256