akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        FastScanner in = new FastScanner();
        int N= in.nextInt();
        ArrayList <Integer> list = new ArrayList<>();
        int l [] = new int[N];

        for (int i = 0; i < N; i++)
        {
            l [i] = in.nextInt();
            list.add(l[i]);
        }
        Collections.sort(list);


        for (int i =0; i < N; i++)
        {
            if (l[i]<list.get((N/2)))
            {
                System.out.println(list.get((N/2)));
            }
            else
            {
                System.out.println(list.get((N/2)-1));
            }
        }


    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

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

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }

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

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

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


Measured memory_bytes: 90492
import math

N, D = map(int, input().split())
X = []
for i in range(N):
    X.append(list(map(int, input().split())))

def dist(a, b):
    d = 0.0
    for i in range(len(a)):
        d += (a[i] - b[i]) ** 2
    return d ** .5

ans = 0
for i in range(N):
    for j in range(i + 1, N):
        a, b = X[i], X[j]
        d = dist(a, b)
        if int(d) == d:
            ans += 1
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
char s[3005], t[3005];
int dp[3005][3005];
pii pv[3005][3005];
int main(){
    scanf("%s%s", s+1, t+1);
    int n = strlen(s+1), m = strlen(t+1);
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(s[i] == t[j]){
                if(dp[i][j] < dp[i-1][j-1] + 1){
                    pv[i][j] = pii(i-1, j-1);
                    dp[i][j] = dp[i-1][j-1] + 1;
                }
            }
            if(dp[i][j] < dp[i-1][j]){
                dp[i][j] = dp[i-1][j];
                pv[i][j] = pii(i-1, j);
            }
            if(dp[i][j] < dp[i][j-1]){
                dp[i][j] = dp[i][j-1];
                pv[i][j] = pii(i, j-1);
            }
        }
    }
    int y = n, x = m;

    vector<char> ans;
    while(y != 0 || x != 0){
        if(pv[y][x].first+1 == y && pv[y][x].second+1 == x){
            if(s[y] == t[x]) ans.emplace_back(s[y]);
        }
        int vy = pv[y][x].first, vx = pv[y][x].second;
        y = vy;
        x = vx;
    }
    reverse(ans.begin(), ans.end());
    for(int i=0;i<ans.size();i++) printf("%c", ans[i]);
    printf("\n");
}

Measured memory_bytes: 105984
num_str = str(input())

num_int = int(num_str[len(num_str)-1])

if num_int == 3:
    print("bon")
elif num_int == 0 or num_int == 1 or num_int == 6 or num_int == 8:
    print("pon")
else:
    print("hon")



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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

#define rep(i, n) FOR(i, 0, n)
#define FOR(i, x, n) for (int i = (x); i < (n); ++i)
#define all(v) (v).begin(), (v).end()

using ll = long long;

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

int h, w, m;
int y[300000], x[300000];
int ch[300001], cw[300001];

int main() {
    cin >> h >> w >> m;
    for (int i = 0; i < m; ++i) {
        cin >> y[i] >> x[i];
        ch[y[i]]++;
        cw[x[i]]++;
    }
    int maxh = *max_element(ch, ch + h + 1);
    int maxw = *max_element(cw, cw + w + 1);
    int cnth = count(ch, ch + h + 1, maxh);
    int cntw = count(cw, cw + w + 1, maxw);
    int cnt = 0;
    for (int i = 0; i < m; ++i) {
        if (ch[y[i]] == maxh && cw[x[i]] == maxw)
            cnt++;
    }
    cout << maxh + maxw + (cnt == cnth * cntw ? -1 : 0) << endl;

    return 0;
}

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

public class Main{
	public static int solve(int n, int s, boolean[] check){
		if( n > 10 ){
			return 0;
		}
		if( s > n*(n+1)*(28-n)/3 ){
			return 0;
		}
		int a = s/n;
		if( a > 9 ){
			a = 9;
		}
		if( n == 1 ){
			if( s > 9 || check[s] ){
				return 0;
			} else {
				return 1;
			}
		}
		int count = 0;
		for(int i = a; i >= 0; i--){
			if( check[i] ){
				continue;
			}
			check[i] = true;
			count += solve(n-1,s-i*n,check);
			check[i] = false;
		}
		return count;
	}
	
	public static void main(String[] args){
		Scanner stdIn = null;
		List<Integer> result = new ArrayList<Integer>();
		
		try{
			stdIn = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
			while( stdIn.hasNext() ){
				int n = stdIn.nextInt(), s = stdIn.nextInt();
			//	Set<Integer> record = new HashSet<Integer>();
				boolean[] check = new boolean[10];
				result.add(solve(n,s,check));
			}
			for(Integer sum : result){
				System.out.println(sum);
			}
		} finally {
			if( stdIn != null ){
				stdIn.close();
			}
		}
	}
}

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


int main() {
  int N;
  cin >> N;
  int A = N;
  // 各桁の数字の和
  int fx = 0;
  while (N){
    fx += N % 10;
    N /= 10;
  }
  if (A % fx == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

const int MAX_N = 20;
int N;
vector<int> H(MAX_N);
void solve()
{
	int cnt = 1;
	int max = H.at(0);
	for(int i = 1; i < N; i++){
		if(max <= H.at(i)){
			max = H.at(i);
			cnt++;
		}
	}
  cout << cnt << endl;
}
int main()
{
	cin >> N;
	for(int i = 0; i < N; i++)
		cin >> H.at(i);
	solve();
	return 0;
}


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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)

int main() {
	ll h,a;
	cin >> h >> a;
	ll res = h / a;
	if(h%a!=0){
		res++;
	}
	cout << res << endl;
	return(0);
}

Measured memory_bytes: 3516
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 55;
const int MAXM = 1000010;
const int MAXK = 100010;
const int MAXQ = 200010;

int n, a[MAXN][MAXN];
ll k;
  
ll sub(ll x, ll y) {
    return (x-y+MODBASE) % MODBASE;
}

ll add(ll x, ll y) {
    return (x+y)%MODBASE;
}

ll mul(ll x, ll y) {
    return ((x%MODBASE) * (y%MODBASE)) % MODBASE;
}

struct Matrix {
    vector<vector<ll> > a;
    int n;
    Matrix(int n) {
        this->n = n;
        a.clear();
        vector<ll> b(n, 0);
        FOR(i,0,n-1) a.emplace_back(b);
    }
    Matrix operator * (Matrix &to) {
        Matrix ans(n);
        FOR(i,0,n-1)
            FOR(j,0,n-1)
                FOR(k,0,n-1) ans.a[i][j] = add(ans.a[i][j], mul(a[i][k], to.a[k][j]));
        return ans;
    }
    vector<ll> operator * (vector<ll> to) { 
        vector<ll> ans(n);
        FOR(i,0,n-1)
            FOR(j,0,n-1) ans[i] = add(ans[i], mul(a[i][j], to[j]));
        return ans;
    }
};

Matrix mu(Matrix A, ll n, Matrix B) {
    while (n) {
        if (n&1) B = B*A;
        A = A*A;
        n >>= 1;
    }
    return B;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> k;
    FOR(i,0,n-1) FOR(j,0,n-1) cin >> a[i][j];
    Matrix ONE(n);
    FOR(i,0,n-1) ONE.a[i][i] = 1;
    Matrix now(n);
    FOR(i,0,n-1)
        FOR(j,0,n-1) now.a[i][j] = a[j][i];
    Matrix res = mu(now, k, ONE);
    vector<ll> fi(n, 1);
    fi = res * fi;
    ll kq = 0;
    FOR(i,0,n-1) kq = (kq + fi[i]) % MODBASE;
    cout << kq;
    return 0;
}


Measured memory_bytes: 384
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        while (true)
        {
            string s = Console.ReadLine();
            if (s == ".") break;
            Stack<char> stack = new Stack<char>();
            foreach (var c in s)
            {
                switch (c)
                {
                    case '[':
                    case '(':
                        stack.Push(c);
                        break;
                    case ']':
                    case ')':
                        if (stack.Count == 0 ||
                            2 < Abs(c - stack.Pop())) goto invalid;
                        break;
                }
            }
            if (stack.Count != 0) goto invalid;
            Console.WriteLine("yes");
            continue;
            invalid:;
            Console.WriteLine("no");
        }
    }
}



Measured memory_bytes: 16252
#include <stdio.h>

int main(void){
    int A,B,C,X;
    int i,j,k;
    int ans=0;
    scanf("%d%d%d%d",&A,&B,&C,&X);

    for (i = 0; i <= A; i++){
        for (j = 0; j <= B; j++){
            for (k = 0; k <= C; k++){
                if(i*500 + j*100 + k*50 == X){
                    ans++;
                }
            }        
        }
    }

    printf("%d",ans);

    return 0;
}

Measured memory_bytes: 128
#https://tjkendev.github.io/procon-library/python/string/rolling_hash.html
class RollingHash():
    def __init__(self, s, base, mod):
        self.mod = mod
        self.pw = pw = [1]*(len(s)+1)

        l = len(s)
        self.h = h = [0]*(l+1)

        v = 0
        for i in range(l):
            h[i+1] = v = (v * base + s[i]) % mod
        v = 1
        for i in range(l):
            pw[i+1] = v = v * base % mod
    def get(self, l, r):
        return (self.h[r] - self.h[l] * self.pw[r-l]) % self.mod
N=int(input())
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
c=[a[i%N]^a[(i+1)%N] for i in range(2*N)]
d=[b[i]^b[(i+1)%N] for i in range(N)]
P=RollingHash(c,97,10**9+7)
Q=RollingHash(d,97,10**9+7)

for k in range(N):
    if P.get(k,k+N)==Q.get(0,N):
        x=b[0]^a[k]
        print(k,x)


Measured memory_bytes: 85936
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int A,B;
    cin>>A>>B;
    int x=__gcd(A,B);
    int cou=1;
    map<int,int> m;
    int q=2;
    int y=sqrt(x)+2;
    while(x>1 ){
        if(x%q==0){
            m[q]++;
            x/=q;
        }else q++;
        if(q>y) break;
    }
    for(auto p:m){
        if(p.second>0) cou++;
    }
    if(x!=1) cou++;
    
    cout << cou<< endl;



}


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

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

    int sum = 0;
    for(int i=0;i<n;i++){
        int l,r;
        cin >> l >> r;

        sum += r - l + 1;
    }
    
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace aizu
{
    class OnlineJudge
    {
        static void Main()
        {
            string input;
            while((input = Console.ReadLine()) != "0 0") {
                int[] cnt = input.Split().Select(p => int.Parse(p)).ToArray();
                Player current = new Player { Index = 1 }, first = current;
                for(int i=0; i < cnt[0] - 1; ++i) {
                    current = (current.Next = new Player { Index = current.Index + 1 });
                }
                current.Next = first;
                while(current != current.Next) {
                    for(int i=0; i < cnt[1] - 1; ++i) {
                        current = current.Next;
                    }
                    current.Next = current.Next.Next;
                }
                Console.WriteLine(current.Index);
            }
        }
    }
    class Player
    {
        public Player Next { get; set; }
        public int Index { get; set; }
    }
}

Measured memory_bytes: 6000
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

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

  vector<pair<int, int>> vp[100010];
  for (int i = 0; i < m; i++) {
    int p, y;
    cin >> p >> y;
    vp[p].push_back({y, i});
  }

  pair<int, int> ans[100010];
  for (int i = 1; i <= n; i++) {
    sort(vp[i].begin(), vp[i].end());
    for (int j = 0; j < vp[i].size(); j++) {
      ans[vp[i][j].second] = {i, j + 1};
    }
  }

  for (int i = 0; i < m; i++) {
    cout << setfill('0') << right << setw(6) << ans[i].first;
    cout << setfill('0') << right << setw(6) << ans[i].second << endl;
  }
}


Measured memory_bytes: 7808
//https://atcoder.jp/contests/abc135/tasks/abc135_a
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main() {
    ll A,B; cin>>A>>B;
    ll l=A*A-B*B;
    ll r=2*(A-B);
    ll k=l/r;
    if(abs(A-k)==abs(B-k)) cout<<k<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
    return 0;
}

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

int main() {
    int n;
    ll k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];

    ll l = 0, r = 1e9;
    while (l+1 < r) {
      ll mid = (l+r)/2;
      ll cnt = 0;
      rep(i,n) {
        cnt += (a[i]+mid-1)/mid-1;
      }
      if (cnt <= k) r = mid;
      else l = mid;
    }
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 4732
#include<iostream>
#include<bits/stdc++.h>
#include<string>
#include<limits>
#include<queue>
#include<stack>
#include<set>
#include<unordered_set>
#include<unordered_map>
#include<map>
#include <algorithm>
#include<utility>
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define vi  vector<int>
#define ll long long
#define pb push_back
#define ff first
#define ss second 
#define rep(n) for(int i=0; i<n ; i++)
#define input(n) for(int i=0; i<n ; i++){cin>>arr[i];}
#define output(n) for(int i=0; i<n ; i++){cout<<arr[i]<<" ";}
#define tc int t; cin>>t; while(t--)
using namespace std;
int32_t main()
{
	int n;
	cin>>n;
	

	int a[n];
	int b[n];
	int c[n];

	rep(n)
	{
		cin>>a[i]>>b[i]>>c[i];
	}

	int dp[n][3];

	memset(dp,0,sizeof(dp));


	dp[0][0]=a[0];
	dp[0][1]=b[0];
	dp[0][2]=c[0];

	for(int i=1 ; i<n;i++)
	{
		dp[i][0] = a[i] + max(dp[i-1][1],dp[i-1][2]);
		dp[i][1] = b[i] + max(dp[i-1][2],dp[i-1][0]);
		dp[i][2] = c[i] + max(dp[i-1][1],dp[i-1][0]);
	}

	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;


	

	return 0;
}


Measured memory_bytes: 2560
import java.io.*;

public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String num = br.readLine();
		String input = br.readLine();
		String[] item = input.split(" ");
		for(int i = item.length; i >= 1; i--){
			if(i > 1){
				System.out.print(item[i-1] + " ");
			}
			else{
				System.out.print(item[i-1]);
			}
		}
		System.out.print("\n");

	}
}

Measured memory_bytes: 16908
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????

		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int[] num = new int[w];
		for (int i = 0; i < num.length; i++) {
			num[i] = i + 1;
		}
		int n = sc.nextInt();
		for (int i = 0; i < n; i++) {
			String str = sc.next();
			String[] ab = str.split(",");
			int a = Integer.parseInt(ab[0]) - 1;
			int b = Integer.parseInt(ab[1]) - 1;
			int c = 0;
			c = num[a];
			num[a] = num[b];
			num[b] = c;
		 }
		for (int i = 0; i < w; i++) {
			System.out.println(num[i]);
		}

	}

}

Measured memory_bytes: 26260
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define MAX 110
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
using namespace __gnu_pbds; 
using namespace std;

typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> new_data_set; 

ll a[MAX];
ll dp[101000];
ll f(ll K,ll n){
	if(dp[K]!=-1) return dp[K];
	For(i,0,n){
		if(K-a[i]<0) continue;
		bool x = f(K-a[i],n);
		if(!x) {
			dp[K]=1;
			return 1;
		}
	}
	dp[K]=0;
	return 0;
}

int main(){
	ios_base::sync_with_stdio(false);
	memset(dp,-1,sizeof(dp));
	ll n,k;cin>>n>>k;
	For(i,0,n) cin>>a[i];
	if(f(k,n)){
		cout<<"First"<<endl;
	}else{
		cout<<"Second"<<endl;
	}
}


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

int main() {
  int n;
  string s;
  cin>>n>>s;
  if (n % 2 == 1) {
    cout<<"No"<<endl;
    return 0;
  }
  for (int i=0; i<n/2; i++) {
    if (s[i] != s[i+n/2]) {
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lim 1000000000000000007
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(),v.end()
#define mod ((int)1e9+7)
using namespace std;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<int,pair<int,int>> pii;
const int N = (int)1e3+5;

vector<pii> v[N][N];
vector<vector<int>> distance_from_source;
vector<string> grid;

void dijksta(int source_x, int source_y) {
  distance_from_source[source_x][source_y] = 0;
  priority_queue<pii,vector<pii>,greater<pii>> pq;
  pq.push({0,{source_x,source_y}});
  while(!pq.empty()) {
    pii curr_node = pq.top();
    pq.pop();
    int x = curr_node.second.first, y = curr_node.second.second;
    if(distance_from_source[x][y] == curr_node.first) {
      for(auto it: v[x][y]) {
        int _x = it.second.first, _y = it.second.second;
        if(distance_from_source[_x][_y] > distance_from_source[x][y] + it.first) {
          distance_from_source[_x][_y] = distance_from_source[x][y] + it.first;
          pq.push({distance_from_source[_x][_y], {_x, _y}});
        }
      }
    }
  }
}

void solve() {
  int r,c;
  cin >> r >> c;
  distance_from_source = vector<vector<int>>(r,vector<int>(c,1e9));

  int source_x, source_y;
  int destination_x, destination_y;
  cin >> source_x >> source_y;
  cin >> destination_x >> destination_y;
  source_x--, source_y--;
  destination_x--, destination_y--;

  grid = vector<string>(r);
  REP(i,0,r-1) {
    cin>>grid[i];
  }
  REP(i,0,r-1) {
    REP(j,0,c-1) {
      if(grid[i][j]=='.') {
        REP(k,-2,2) {
          REP(l,-2,2) {
            if(i+k>=0 && i+k<r && j+l>=0 && j+l<c && grid[i+k][j+l]=='.') {
              v[i][j].push_back({(abs(k)+abs(l))!=1,{i+k,j+l}});
            }
          }
        }
      }
    }
  }
  dijksta(source_x, source_y);
  if(distance_from_source[destination_x][destination_y] == 1e9) {
    distance_from_source[destination_x][destination_y] = -1;
  }
  cout << distance_from_source[destination_x][destination_y];
}

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

  int T=1;
  //cin>>T;
  REP(TC,1,T) {
      //cout<<"Case #"<<TC<<": ";
      solve();
      cout<<"\n";
  }
}


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

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

Measured memory_bytes: 3612
n,k = map(int,input().split())

dic = {}
for i in range(n):
    a,b = map(int,input().split())
    try:
        dic[a] += b
    except:
        dic[a] = b

#print(dic)
dic = sorted(dic.items(),key=lambda x:x[0])

for a,b in dic:
    if b-k >=0:
        print(a)
        exit()
    else:
        k -= b

Measured memory_bytes: 54744
using System;
    using System.Text;
    using System.Collections.Generic;
    using static System.Math;
    using System.Linq;
    using static System.Array;
    
    namespace ConsoleApp2
    {
    class Program
    {
        static Node[] Nodes;
        static long N;
        static long M;
        static bool[] used;
        static void Main(string[] args)
        {
            //var K = long.Parse(Console.ReadLine());
            //var S = Console.ReadLine();
            var NM = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
            N = NM[0];
            M = NM[1];
            Nodes = new Node[N + 1];
            used = new bool[N + 1];
            for (int i = 1; i <= N; i++)
            {
                Nodes[i] = new Node();
            }

            for (int i = 0; i < M; i++)
            {
                var AB = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
                var A = AB[0];
                var B = AB[1];
                Nodes[A].adj.Add(B);
                Nodes[B].adj.Add(A);
            }

            Console.WriteLine("Yes");
            wfs();
            for (int i = 2; i <= N; i++)
            {
                Console.WriteLine(Nodes[i].sign);
            }
        }

        static void wfs()
        {
            var que = new Queue<long>();
            que.Enqueue(1);
            used[1] = true;
            while(que.Count() > 0)
            {
                var top = que.Dequeue();
                
                foreach (var item in Nodes[top].adj)
                {
                    if (!used[item])
                    {
                        Nodes[item].sign = top;
                        que.Enqueue(item);
                        used[item] = true;
                    }
                }
            }
        }
    }

    class Node
    {
        public List<long> adj;
        public long sign = -1;
        public Node()
        {
            adj = new List<long>();
        }
    }

}


Measured memory_bytes: 43028
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

int main(void){
    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;

    ll ans = abs(a - b);
    rep(i, 0, n){
        ll s = (d * (-n + 1 + i)) + (i * c);
        ll e = (c * (-n + 1 + i)) + (i * d);
        if(s <= ans && ans <= e){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
n,l = map(int,input().split())
s=[]


for i in range(n):
    s.append(i+l)
a = sum(s)
m=0
c = abs(s[0])
for i in range(n):
    if c > abs(s[i]):
        c = abs(s[i])
        m = i
        

print(a-s[m])


Measured memory_bytes: 3060
#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--)
using namespace std;
int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string S;
	cin >> S;
	string A={};
	rep(i,S.length()){
		A += S[i];
		i++;
	}
	cout << A << endl;
}

Measured memory_bytes: 592
#include <iostream>
#include <climits>
#include <algorithm>
using namespace std;

long long calc(long long rectA, long long rectB, long long rectC) {
    return max(rectA, max(rectB, rectC)) - min(rectA, min(rectB, rectC));
}

int main() {
    long long H,W;
    cin >> H >> W;

    long long ans = LLONG_MAX;
    // Wを固定
    for (long long i=1; i<H; i++) {
        long long rectC = W * (H - i); // 一つの長方形

        // 長方形A (W,i) をさらに分割する
        // 垂直分割 (W/2, i), (W-(W/2), i)
        ans = min(ans, calc((W/2)*i, (W-(W/2))*i, rectC));
        // 水平分割 (W, i/2), (W, i-(i/2))
        ans = min(ans, calc(W*(i/2), W*(i-(i/2)), rectC));
    }

    // Hを固定
    for (long long i=1; i<W; i++) {
        long long rectC = H * (W - i);

        // 長方形A (i,H) をさらに分割
        // 垂直分割 (i/2, H), (i-(i/2), H)
        ans = min(ans, calc((i/2)*H, (i-(i/2))*H, rectC));
        // 水平分割 (i, H/2), (i, H-(H/2))
        ans = min(ans, calc(i*(H/2), i*(H-(H/2)), rectC));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int sq = 1;
    char now=s[0];
    int l = s.size();
    for(int i=1;i<l;++i){
        if(s[i]==now){
            sq++;
            if(sq>=3){
                cout << "Yes\n";
                return 0;
            }
        }else{
            sq=1;
            now=s[i];
        }
    }
    cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(i, (q).size()) { cerr << (q)[i] << (i == i_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    // インタラクティブ問題では除去した方がいいかも
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    vector<ll> a(5);
    REP(i, 5) {
        cin >> a[i];
    }

    ll ans = INF;
    REP(i, 5) {
        ll cand = 0;
        REP(j, 5) {
            if (i == j) {
                cand += a[j];
            } else {
                cand += (a[j] + 9) / 10 * 10;
            }
        }
        chmin(ans, cand);
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
/* be name khoda */

#define long_enable
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <vector>
#include <fstream>
#include <set>
#include <queue>
using namespace std;

#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif

typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<pii> vpii;

#define forifrom(i, s, n) for (ll i = s; i < n; ++i)
#define forirto(i, n, e) for (ll i = (n) - 1; i >= e; --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))

#define debug(x) cout << #x << " -> " << (x) << endl
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl

const ll MOD = 1000000007;
const ll INF = 2000000000;
const long long BIG = 1446803456761533460LL;

#define XL (x << 1)
#define XR (XL | 1)
#define MD ((l + r) >> 1)
#define Add(a, b) a = ((a) + (b)) % MOD
#define Mul(a, b) a = (1LL * (a) * (b)) % MOD

// -----------------------------------------------------------------------

const ll maxn = 100010;

ll X, Y, Z, N, A[maxn], B[maxn], C[maxn], idxs[maxn], Ar[maxn], lt[maxn], rt[maxn];
priority_queue<ll, vi, greater<ll>> pq;

void kmax(ll *Ar, ll k, ll *des) {
    while (!pq.empty()) pq.pop();
    ll s = 0;
    fori (i, N) {
        pq.push(Ar[i]);
        s += Ar[i];
        if ((ll) pq.size() > k) {
            s -= pq.top();
            pq.pop();
        }
        des[i] = s;
    }
}

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

    cin >> X >> Y >> Z;
    N = X + Y + Z;
    ll Csum = 0;
    fori (i, N) {
        cin >> A[i] >> B[i] >> C[i];
        A[i] -= C[i], B[i] -= C[i];
        Csum += C[i];
    }
    iota(idxs, idxs + N, 0);
    sort(idxs, idxs + N, [] (ll a, ll b) { return A[a] - B[a] > A[b] - B[b]; } );
    fori (i, N) Ar[i] = A[idxs[i]];
    kmax(Ar, X, lt);
    fori (i, N) Ar[i] = B[idxs[N - 1 - i]];
    kmax(Ar, Y, rt);
    reverse(rt, rt + N);
    ll mx = -BIG;
    forifrom (i, X - 1, N - Y) smax(mx, lt[i] + rt[i + 1]);
    ll ans = Csum + mx;
    cout << ans << '\n';

}


Measured memory_bytes: 9468
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//uniform_int_distribution<int>(1000,10000)(rng)

ll binpow(ll a, ll b) {
    if (b == 0)
    {
        return 1;
    }
    ll res = binpow(a, b / 2);
    res*=res;
    if (b % 2)
    {
        return res * a;
    }
    return res;
}

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

string to_upper(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
    return a;
}
 
string to_lower(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
    return a;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,k;
    cin>>n>>k;
    int a[n];
    for (int i=0;i<n;++i)
        cin>>a[i];
    sort(a,a+n);
    for (int i=1;i<k;++i)
        a[i]+=a[i-1];
    cout<<a[k-1];
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <random>
#include <algorithm>
#include <functional>
#include <cassert>

using namespace std;
typedef long long ll;

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

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string S,T;
  cin>>S>>T;
  string ans="Yes";
  if(S.length()+1!=T.length())ans="No";
  REP(i,S.length()){
    if(S[i]!=T[i])ans="No";
  }
  cout<<ans<<endl;
}


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

std::vector<int> A;
int inf = 1001001001;


int parent(int key){
    int parent = key / 2;
    return parent;
}

int heapIncreaseKey(int i, int key){
    if(key < A[i]){
        return 0;
    }
    A[i] = key;
    int pa = parent(i);
    while(i > 1 && A[pa] < A[i]){
        std::swap(A[i], A[pa]);
        i = pa;
        pa = parent(i);
    }
}

void insert(int key){
    A.push_back(-inf);
    heapIncreaseKey(A.size()-1, key);
}


int maxHeapify(int i){
    int l, r, largest;
    l = 2 * i;
    r = 2 * i + 1;
    int n = A.size();
    if(l <= n && A[l] > A[i]){
        largest = l;
    }else{
        largest = i;
    }

    if(r <= n && A[r] > A[largest]){
        largest = r;
    }

    if(largest != i){
        int tmp;
        tmp = A[i];
        A[i] = A[largest];
        A[largest] = tmp;
    }else{
        return 0;
    }

    maxHeapify(largest);
}

int heapExtractMax(void){
    if(A.size() < 1){
        return -inf;
    }
    int max = A[1];
    A[1] = A[A.size()-1];
    A.pop_back();
    maxHeapify(1);
    return max;
}

int main(void){
    std::string str;
    int a;
    A.push_back(-inf);
    while(true){
        std::cin >> str;
        if(str == "insert"){
            std::cin >> a;
            insert(a);
        }else if(str == "extract"){
            int max = heapExtractMax();
            std::cout << max << std::endl;
        }else{
            break;
        }
    }
    
    return 0;
}


Measured memory_bytes: 6980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	string t;
	cin>>t;
	reverse(t.begin(),t.end());
	t+='0';
	ll ch[1000010][2];
	for(ll i=0;i<1000010;i++){
		for(ll j=0;j<2;j++){
			ch[i][j]=INF;
		}
	}
	ch[0][0]=0;
	for(ll i=0;i<t.size();i++){
		ll now=t[i]-'0';
		for(ll a=0;a<=9;a++){
			ll num=now;
			if(a>=now){
				ch[i+1][0]=min(ch[i+1][0],ch[i][0]+2*a-num);
			}
			if(a<now){
				ch[i+1][1]=min(ch[i+1][1],ch[i][0]+a+10-num);
			}
			if(a>=now+1){
				ch[i+1][0]=min(ch[i+1][0],ch[i][1]+2*a-(num+1));
			}
			if(a<now+1){
				ch[i+1][1]=min(ch[i+1][1],ch[i][1]+2*a+10-(num+1));
			}
		}
	}
	cout << ch[t.size()][0];
	// your code goes here
	return 0;
}


Measured memory_bytes: 20036
#include<iostream>
#include<iomanip>
#include<cmath>

using namespace std;

int main() {

    int n;                  // XとYの次元数n
    int x[100];             // ベクトル
    int y[100];             // ベクトル

    double S[4] = {0};
    double D[4];  // ミンコフスキー距離

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

    for (double p = 0; p < 3; p++) {

        for (int i = 0; i < n; i++) {
            S[(int)p] += pow(abs(x[i] - y[i]), p + 1);
        }

        D[(int)p] = pow(S[(int)p], 1 / (p + 1));

    }

    D[3] = x[0] - y[0];

    for (int i = 0; i < n; i++) {
        if (abs(x[i] - y[i]) > D[3]) {
            D[3] = abs(x[i] - y [i]);
        }
    }

    cout << fixed;

    for (int i = 0; i < 4; i++) {
        cout << setprecision(10) << D[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3428
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> //tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <numeric>
using namespace std;

int main() {
    int N, M, C;
    cin >> N >> M >> C;
    vector<vector<int>> A(N, vector<int>(M));
    vector<int> B(M);
    for (int j = 0; j < M; j++) {
        cin >> B.at(j);
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            cin >> A[i][j];
        }
    }
    int count = 0;
    for (int i = 0; i < N; i++) {
        int sum = C;
        for (int j = 0; j < M; j++) {
            sum += A[i][j] * B.at(j);
        }
        if (sum > 0) count++;
    }
    cout << count << endl;
}

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

// 5 6

/*
    0 -> 48
    1 -> 49
    2 -> 50
    5 -> 53


*/

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

    int a = s[6] - '0';
    int b = s[5] - '0';
    int month = a + 10*b;

    if (month > 4) {
        cout << "TBD";
    } else {
        cout << "Heisei";
    }


    return 0;
}


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

int main()
{
  int n,d,v;
  cin >> n >> d >> v;
  int x = v;
  for(int i=0;i<10;i++)
  {
    x = n*x-d;
    cout << x << endl;
  }
  return 0;
}

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

using namespace std;

int main()
{
  int as[ 3 ];
  cin >> as[ 0 ] >> as[ 1 ] >> as[ 2 ];
  sort( as, as + 3 );
  int cost = 0;
  for( int i = 1; i < 3; ++i )
  {
    cost += as[ i ] - as[ i - 1 ];
  }
  cout << cost << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)
 
int main(){
	string s;
	cin>>s;
 
	while(1){
		if(s=="ABC")break;
		
		string nxt="";
		int count=0;
		int c[3]={};
		for(int i=0;i<s.size();){
			if(i+2<s.size()&&s.substr(i,3)=="ABC"){
				count++;
				i+=3;
			}
			else{
				c[s[i]-'A']++;
				i++;
			}
		}
		int zero=0,pos=-1;
		rep(i,3)if(c[i]==0)zero++,pos=i;
		if(zero!=1){
			cout<<"No"<<endl;
			return 0;
		}
		if(count==0){
			cout<<"No"<<endl;
			return 0;
		}
 
		for(int i=0;i<s.size();){
			if(i+2<s.size()&&s.substr(i,3)=="ABC"){
				nxt+=('A'+pos);
				i+=3;
			}
			else{
				nxt+=s[i];
				i++;
			}
		}
		s = nxt;
	}
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 3256
import sys
from itertools import accumulate

input = sys.stdin.readline


def is_ok(a, key, idx):
    if a[idx] <= key:
        return True
    else:
        return False


def binary_search(a, key):
    """Meguru type binary search"""
    ok = -1
    ng = len(a)

    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(a, key, mid):
            ok = mid
        else:
            ng = mid

    return ok


def main():
    N, M, K = map(int, input().split())
    A = tuple(map(int, input().split()))
    B = tuple(map(int, input().split()))

    B_cumsum = tuple(accumulate(B))
    ans = 0
    time = 0
    for i in range(N + 1):
        if time > K:
            break
        j = binary_search(B_cumsum, K - time) + 1
        ans = max(ans, i + j)

        if i < N:
            time += A[i]

    print(ans)


if __name__ == "__main__":
    main()


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

main() {
  int A, B;
  cin >> A >> B;
  if (A == 1) A = 14;
  if (B == 1) B = 14;
  if (A > B) {
    cout << "Alice" << endl;
  } else if (A < B) {
    cout << "Bob" << endl;
  } else {
    cout << "Draw" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
N =int(input())
A_n =list(map(int,input().split()))
ans =1
i = 0

while ans <= 10**18 and i < N:
  ans *= A_n[i]
  i +=1
if ans > 10**18:
  if 0 in A_n:
    print(0)
  else:
    print(-1)
else:
  print(ans)

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int K,A,B;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>K>>A>>B;
	if(A%K==0 || B%K==0 || A/K!=B/K) {
		cout<<"OK"<<endl;
	}
	else {
		cout<<"NG"<<endl;
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

int ret_place( char c )
{
  c -= 32;
  if( c == 'Q' || c == 'W' || c == 'E' || c == 'R' || c == 'T' || c == 'A' || c == 'S' ||c == 'D' || c == 'F' || c == 'G' || c == 'Z' || c == 'X' || c == 'C' || c == 'V' || c == 'B' ) return 0;
  else return 1;
}

int main()
{
  string s;
  while( cin >> s, s != "#" ) {
    int now = ret_place( s[0] ); //0:l 1:r
    int cnt = 0;
    for(int i=1; i<s.size(); i++) {
      int res = ret_place( s[i] );
      if( now != res ) cnt++, now = res;  
    }

    cout << cnt << endl;
  }
}

Measured memory_bytes: 3192
function Main(input){
  input = input.split("\n");
  inputStr = input[0].split(" ");
  var N = Number.parseInt(inputStr[0]);
  var P = input[1].split(" ");
  var count = 0;
  var max = 0;
  var min = 0;
  
  for (var i = 1; i < N - 1 ; i++ ){
  	max = Math.max(Number.parseInt(P[i-1]),Number.parseInt(P[i]),Number.parseInt(P[i+1]));	
  	min = Math.min(Number.parseInt(P[i-1]),Number.parseInt(P[i]),Number.parseInt(P[i+1]));	

    if (Number.parseInt(P[i]) != max && Number.parseInt(P[i]) != min ){
      count += 1;
    }
  }
  console.log(count);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 11468
#include<stdio.h>
int main()
{
    int n, m, c;
    scanf("%d %d %d", &n, &m, &c);
    int i;
    int b[25];
    for (i = 0; i < m; i++)
        scanf("%d", &b[i]);
    int ans = 0;
    int a[25];
    int sum;
    int j;
    for (i = 0; i < n; i++)
    {
        for (j = 0; j < m; j++)
            scanf("%d", &a[j]);
        sum = c;
        for (j = 0; j < m; j++)
            sum += a[j] * b[j];
        if (sum > 0)
            ans++;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (in i = 0; i < (in)(n); i++)
const double PI=3.14159265358979323846;
const int64_t waru = 1000000007;
const in INF=1<<30;
#define vecvec(a,y,x) vector<vector<int>> a(y,vector<int>(x))
#define vec(a,n) vector<in> a(n);rep(i,n)cin>>a[i]

int main(){
in n;cin>>n;
  vec(a,n);
 vector<in> b(n);
  in len=0ll;
  rep(i,n) len+=a[i];
  rep(i,n-1) a[i+1]+=a[i];
  rep(i,n){
   in ama=len-a[i];
    b[i]=abs(ama-a[i]);
  }
  sort(all(b));
  cout<<b[0];
}


Measured memory_bytes: 3328
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const long long INF = 1LL << 60;    // 1.15x10^18
template<class T> void add(T &a, T b) { a = (a > INF - b ? INF : a + b); }

int main() {
    int n; cin >> n;
    long long x; cin >> x;
    vector<int> a(n);
    for (auto &ai: a) cin >> ai;
    vector<long long> acc(n + 1);
    for (int i = 0; i < n; i++) acc[i + 1] = acc[i] + a[i];
    long long mi = INF;
    for (int k = 1; k <= n; k++) {
        long long tmp = 5 * acc.back() + (k + n) * x;
        int cur = n - k;
        while (cur > k) add(tmp, 2 * acc[cur -= k]);
        mi = min(mi, tmp);
    }
    cout << mi << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>
int trump[101]={};
int n;

void print(void)
{
    int i;
    for(i=0;i<n;i++)
    {
        printf("%d",trump[i]);
        if(i<n-1)printf(" ");
    }
    printf("\n");
    return;
}

int main(void)
{
    scanf("%d",&n);
    int i,j;

    for(i=0;i<n;i++)
    {
        scanf("%d",&trump[i]);
    }
    int v;
    print();
    for(i=1;i<n;i++)
    {
        v=trump[i];
        j=i-1;
        while(j>=0 && trump[j]>v)
        {
            trump[j+1]=trump[j];
            j--;
        }
        trump[j+1]=v;
        print();
    }


    return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using ll = long long;
const int INF = 0x3f3f3f3f;
using namespace std;

int n, m, M=1e9+7, arr[100001], d;
int main() {
    IOS
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        cin >> d;
        arr[d]++;
    }
    vector<int> dp(n+1);
    dp[0] = 1;
    if (!arr[1]) {
        dp[1] = 1;
    }
    for (int i = 2; i <= n; ++i) {
        if (!arr[i]) {
            dp[i] = dp[i-1] + dp[i-2];
            if (dp[i] >= M) {
                dp[i] -= M;
            }
        }
    }
    cout << dp[n] << endl;
    return 0;


}


Measured memory_bytes: 1024