akhauriyash/Code-Regression huggingface dataset:
words = lambda t : list(map(t, input().split()))
h,w,k = words(int)
mat = []
w_empty = []
for i in range(h):
    wi = input()
    mat.append(wi)
    emp = True
    for ww in wi:
        if ww == "#":
            emp = False
            break
    w_empty.append(emp)

ans = [[0] * w for i in range(h)]
ki = 1
i = 0
stt = 0
lastMark = 0
while i < h:
    while i < h and w_empty[i]:
        i+=1
    if i >= h:
        break
    lastSharp = 0
    for j in range(w):
        for k in range(stt,i+1):
            ans[k][j] = ki
            if mat[k][j] == "#":
                ki += 1
                lastSharp = j
    for j in range(lastSharp,w):
        for k in range(stt,i+1):
            ans[k][j] = ki-1
    #print(i, "----------------------")
    #for wi in ans:
    #    print(" ".join((list(map(str,wi)))))
    lastMark = i
    i+=1
    stt = i

for j in range(lastMark+1,h):
    for k in range(w):
        ans[j][k] = ans[lastMark][k]

for wi in ans:
    print(" ".join((list(map(str,wi)))))


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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> D(K);
    vector<vector<int>> A(K, vector<int>(0));
    
    for (int i = 0; i < K; i++) {
        cin >> D.at(i);
        
        for (int j=0; j<D.at(i); j++){
            int a;
            cin >> a;
            A.at(i).push_back(a);
        }
    }
    
    
    /*for (int i = 0; i < K; i++) {
        
        
        for (int j=0; j<D.at(i); j++){
            
            cout << A.at(i).at(j);
        }
    }*/
    
    
    int cnt = 0;
    for (int i = 1; i<=N; i++) {
        int z = 0;
        
        for (int j=0; j<K; j++) {
            for (int k = 0; k<D.at(j);k++) {
                if (i == A.at(j).at(k)) {
                    z = 1;
                    
                }
                //cout << z;
            }
        }
        if (z == 0) {
            cnt++;
        }
        
        
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3640
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = input()

    if "9" in s:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 61848
N = int(input())
ary = [int(_) for _ in input().split()]


def selection_sort(ary, verbose=True):
    count = 0

    for i in range(0, N):
        minj = i

        for j in range(i, N):
            if ary[j] < ary[minj]:
                minj = j

        if i != minj:
            ary[i], ary[minj] = ary[minj], ary[i]
            count += 1

    print(' '.join([str(_) for _ in ary]))

    if verbose:
        print(count)


selection_sort(ary)



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

int main() {
	int n,x,y;
	cin >> n >> x >> y;
	x--;
	y--;
	vector<int> ans(n,0);
	int size_lp = y - x;
	for(int i=0;i<n;i++) {
		for(int j=i+1;j<n;j++) {
			int dist = 0;
			if(i<x) {
				if (j<x) dist = j-i;
				else if (j<y) dist = (x-i)+min(j-x, y-j+1);
				else dist = (x-i)+1+(j-y);
			}
			else if (i<y) {
				if (j<y) dist = min(j-i,i-x+1+y-j);
				else dist = j-y+min(y-i,i-x+1);
			}
			else {
				dist = j-i;
			}
			ans[dist]++;
		}
	}
	for(int i=1;i<n;i++) cout << ans[i] << endl;
	return 0;
}


Measured memory_bytes: 256
func solver7() {
    var plus:Array<Int>=[], minus:Array<Int>=[]
    let _ = Int(readLine()!)!
    let sn = readLine()!.split(separator: " ").map({Int($0)!})
    var wholesum = 0
    var absmin = abs(sn.first!)
    var zerocount = 0
    for c in sn {
        wholesum += abs(c)
        absmin=min(absmin,abs(c))
        if c>0 {plus.append(c)}
        else if c<0 {minus.append(c)}
        else {zerocount+=1}
    }
    if wholesum==0 {print(0)}
    else {
        var vans = wholesum
        if zerocount==0 && plus.count*minus.count==0 {vans -= 2 * absmin}
        print(vans)
    }
    if zerocount>1 {for _ in 1...zerocount-1 {print(0,0)}}

    plus = plus.sorted(by:>)
    minus = minus.sorted(by:<)
    if plus.count*minus.count==0 {
        if plus.count+minus.count==0 {
            return
        } else {
            if plus.count != 0 {
                if plus.count==1 {
                    print(plus.first!,0)
                    return
                } else if plus.count==2 {
                    if zerocount>0 {
                        print(0,plus.last!)
                        print(plus.first!,-1*plus.last!)
                    } else {print(plus.first!,plus.last!)}
                    return
                } else {
                    if zerocount != 0 {plus.append(0)}
                    let l1 = plus.popLast()!
                    let l2 = plus.popLast()!
                    print(l1,l2)
                    minus.append(l1-l2)
                }
            } else {
                if minus.count==1 {
                    print(0,minus.first!)
                    return
                } else if minus.count==2 {
                    if zerocount>0 {
                        print(0,minus.last!)
                        print(-1*minus.last!, minus.first!)
                    } else {print(minus.last!, minus.first!)}
                    return
                } else {
                    if zerocount != 0 {minus.append(0)}
                    let l1 = minus.popLast()!
                    let l2 = minus.popLast()!
                    print(l1,l2)
                    plus.append(l1-l2)
                }
            }
        }
    } else {
        if zerocount>0 {
            if plus.count<=minus.count {plus.append(0)}
            else {minus.append(0)}
        }
    }
    while plus.count>1 || minus.count>1 {
        if plus.count >= minus.count {
            print(minus.last!,plus.last!)
            minus[minus.count-1]-=plus.popLast()!
        } else {
            print(plus.last!,minus.last!)
            plus[plus.count-1]-=minus.popLast()!
        }
    }
    print(plus.first!,minus.first!)
    return
}
solver7()

Measured memory_bytes: 12748
s = input()
n = int(s.split()[0])
k = int(s.split()[1])

current = n
absV = 0
if current - k > 100000000:
    current = current % k
while True:
    absV = abs(current - k)
    if current < absV:
        print(current)
        exit()
    else:
        current = absV


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

long long fact[202020], frev[202020];

long long modpow(long long a, long long p = MOD - 2) {
    if (p == 0) return 1;
    long long tmp = modpow(a, p / 2);
    tmp = tmp * tmp % MOD;
    if (p % 2 == 1) tmp = tmp * a % MOD;
    return tmp;
}

long long C(int p, int q){
    if (q < 0 || p < q) return 0;
    return fact[p] * frev[q] % MOD * frev[p - q] % MOD;
}

int main(){
    fact[0] = frev[0] = 1;
    for(int i=1;i<=200000;i++){
        fact[i] = (fact[i - 1] * i) % MOD;
        frev[i] = modpow(fact[i]);
    }

    ll B, W;
    cin >> B >> W;

    ll bunbo = 2, bunshi = 1;
    ll acc = 0;
    for(ll i=1;i<=B+W;i++){
        ll ans = (bunshi * modpow(bunbo)) % MOD;
        if(W < i){
            cout << (ans + acc) % MOD << endl;
        }else{
            cout << ans << endl;
        }

        bunshi = (bunshi * 2) % MOD;
        if(W <= i){
            ll node = C(i - 1, W - 1);
            bunshi = (bunshi - node + MOD) % MOD;
            acc = (acc + (node * modpow(bunbo)) % MOD) % MOD;
        }
        if(B <= i){
            ll node = C(i - 1, B - 1);
            bunshi = (bunshi - node + MOD) % MOD;
        }
        bunbo = (bunbo * 2) % MOD;
        // cout << bunshi << " " << bunbo << " " << acc << endl;
    }

    return 0;
}


Measured memory_bytes: 5376
#include <stdio.h>

int main(void)
{
	int i, j = 0, num[26];
	char moji;
	
	for(i = 0; i < 26; i++) num[i] = 0;
	
	while(scanf("%c", &moji) != EOF)
	{
		for(i = 0; i < 26; i++)
		if(i == (moji - 'a') || i == (moji - 'A')) num[i]++;
	}
	
	for(i = 0; i < 26; i++) printf("%c : %d\n", i + 'a', num[i]);
	
	return 0;
}

Measured memory_bytes: 540
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
#define ll long long
int main (){
    string s;
    cin >> s;
    int co[26]={};
    for (int i = 0; i <  s.size(); i++){
        co[s[i]-'a']++;
    }
    for (int i = 0; i < 26; i++){
        if (co[i]==0) {
            cout << (char)('a'+i) << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define sort(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
#define P pair<int,int>
#define mk make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }



int main() {
	int n;
	cin >> n;
	vector<ll> a(26, 0);
	rep(i, n) {
		char x;
		cin >> x;
		a[x - 'a']++;
	}
	ll ans = 1;
	rep(i, 26) {
		if (a[i] != 0) {
			ans *= (a[i] + 1);
			ans = ans % mod;
		}
	}
	cout << ans - 1 << endl;
}



Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] args){
     	Scanner sc = new Scanner(System.in);
      	String s = sc.next();
      	String t = sc.next();
      	if(t.length()==s.length()+1){
         	if(t.substring(0,t.length()-1).equals(s)){
             System.out.println("Yes"); 
            }else{
				System.out.println("No");
            }
        }else{
         	System.out.println("No"); 
        }
    }
}

Measured memory_bytes: 35624
from fractions import gcd
A, B, C, D = map(int, input().split())
BdivC, BdivD = B // C, B // D
AdivC, AdivD = A // C, A // D
GCD = gcd(C, D)
BdivCD, AdivCD = B // ((C * D) // GCD), A // ((C * D) // GCD)
N1 = BdivC + BdivD - BdivCD
N2 = AdivC + AdivD - AdivCD
ans = (B - A) - (N1 - N2)
if(A % C != 0): ans += 1
print(ans)


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

int main() {
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  vector<ll> A(X);
  vector<ll> B(Y);
  vector<ll> C(Z);
  rep(i,X) cin >> A[i];
  rep(i,Y) cin >> B[i];
  rep(i,Z) cin >> C[i];
  vector<ll> AB;
  rep(i,X) rep(j,Y) AB.push_back(A[i]+B[j]);
  sort(AB.rbegin(), AB.rend());
  vector<ll> AB_cand;
  ll k = min((int)AB.size(), K);
  rep(i,k) AB_cand.push_back(AB[i]);
  vector<ll> ans;
  rep(i,k) rep(j,Z) ans.push_back(AB_cand[i]+C[j]);
  sort(ans.rbegin(), ans.rend());
  rep(i, K) cout << ans[i] << endl;
}

Measured memory_bytes: 43272
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int m = 0;
		int a = 0; 
		int r = 0;
		int c = 0;
		int h = 0;
		
		for(int i = 0 ; i < n ;i++) {
			String s = sc.next();
			char x = s.charAt(0);
			if(x == 'M') m++;
			if(x == 'A') a++;
			if(x == 'R') r++;
			if(x == 'C') c++;
			if(x == 'H') h++;
			
			}
		long sum = 0;
		
		sum += (long)m * a * r;
		sum += (long)m * a * c;
		sum += (long)m * a * h;
		sum += (long)m * r * c;
		sum += (long)m * r * h;
		sum += (long)m * c * h;
		sum += (long)a * r * c;
		sum += (long)a * r * h;
		sum += (long)a * c * h;
		sum += (long)r * c * h;
		
		System.out.println(sum);
		
	
	}
}


Measured memory_bytes: 46652
/*
*author: rits1272	
*/
#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define F first
#define S second
#define MAX 1e9
#define MIN -1e9
#define INF 1e18
#define MOD 1000000007
#define int long long
#define FOR(x, n) for(int i=x; i<n; i++)
#define print(x) cout << "[" << #x << ":" << x << "] "; 
#define println(x) cout << "[" << #x << ":" << x << "]\n"; 

int dx[8] = { -1, 0, 0, 1, -1, -1, 1, 1 }; 
int dy[8] = { 0, 1, -1, 0, -1, 1, -1, 1 };  
double PI = acos(-1); 

int32_t main(){
	ios::sync_with_stdio(0); 
    cin.tie(0); 
	#ifndef ONLINE_JUDGE
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif
	int a, b, c, d; cin >> a >> b >> c >> d;
	int ans = max({b*d, a*c ,a*d, b*c});
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int N = s.size();
  int ans = 0;
  for (int i = 0; i < N; i++){
    if (i % 2 == 0){
      if (s[i] == 'p'){
        ans--;
      }
    } else {
      if (s[i] == 'g'){
        ans++;
      }
    }
  }
  cout << ans << endl;
}

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

int main() {
    int n;
    while(cin >> n, n) {
        vector<string> v(n);
        for(int i=0; i<n; ++i) {
            cin >> v[i];
        }
        int ans = 0;
        for(int i=1; i<v.size(); ++i) {
            if((v[i-1] == "lu" && v[i] == "ru") || (v[i-1] == "ru" && v[i] == "lu") ||
               (v[i-1] == "rd" && v[i] == "ld") || (v[i-1] == "ld" && v[i] == "rd")) {
                ans++;
            }
        }
        cout << ans << endl;
    }
}


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

int main(){
    int n;
    cin >> n;
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (x != i + 1) cnt++;
    }
    if (cnt == 0 || cnt == 2) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

int main()
{
  ios::sync_with_stdio(false);  cin.tie(0); cout.tie(0);
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int s = 0;
  rep(i,n) s^= a[i];
  rep(i,n) a[i] ^= s;
  rep(i,n) cout << a[i] << " ";
  cout << endl;
  return 0;
}

Measured memory_bytes: 3844
#include<iostream>
#include <math.h>
#include <algorithm>
#include<queue>
// #include <bits/stdc++.h>


using namespace std;

#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)

main(){
   string s;
   int b = 0;
    cin >> s;
    FOR(i,0,4){
        if(s[i]==s[i+1]){
            b = 1;
            break;
        }
    }

    if(b){cout << "Bad" << endl;; }
    else{cout << "Good" << endl;}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;scanf("%d",&n);
    vector<int> ans(n,2e9);
    for(int i=0;i<n;i++){
        int a;scanf("%d",&a);
        int left=-1,right=n;
        while(right-left>1){
            int middle=(left+right)/2;
            if(ans[middle]<a)left=middle;
            else right=middle;
        }
        ans[right]=a;
    }
    for(int i=n-1;i>=0;i--){
        if(ans[i]!=2e9){
            printf("%d\n",i+1);
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3428
def selectionSort(A, N):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if A[j][1:] < A[minj][1:]:
                minj = j
        if i != minj:
            A[i], A[minj] = A[minj], A[i]

    return A


def bubbleSort(A, N):
    for i in range(N):
        for j in range(N - 1, i, -1):
            if A[j][1:] < A[j - 1][1:]:
                A[j], A[j - 1] = A[j - 1], A[j]

    return A


if __name__ == '__main__':
    n = int(input())
    R = list(map(str, input().split()))
    C = R[:]
    BR = bubbleSort(R, n)
    SR = selectionSort(C, n)

    fStable = SR == BR

    print(*BR)
    print("Stable")
    print(*SR)
    if (fStable == True):
        print("Stable")
    else:
        print("Not stable")


Measured memory_bytes: 5612
#include<cstdio>
#include<iostream>
#include<map>
#include<cmath>
#include<cstring>

using namespace std;

typedef long long ll;

ll fun1(ll x, ll y)
{
    ll z=0;
    while(y)
    {
        if(y%2==1)
        {
            z=(z+x)%998244353;
        }
        y=y/2;
        x=(x*2)%998244353;
    }
    return z;
}

ll fun(ll n,ll k)
{
    ll z=1;
    while(k)
    {
        if(k%2==1)
        {
            z=fun1(z,n)%998244353;
        }
        n=fun1(n,n)%998244353;
        k=k/2;
    }
    return z;
}

ll ma[100005], f[100005];

int main()
{
    ll n;
    scanf("%lld",&n);
    memset(ma,0,sizeof(ma));
    int m=0, pan=1;
    for(ll i=0;i<n;i++)
    {
        int p;
        scanf("%d",&p);
        if(i==0&&p!=0)
        {
            pan=0;
        }
        if(p>m)
            m=p;
        ma[p]++;
    }
    ll z=1;
    for(ll i=m;i>=0;i--)
    {
        if(ma[i]==0||ma[0]!=1||pan==0)
        {
            z=0;
            break;
        }
        if(i!=0)
            f[i]=fun(ma[i-1],ma[i]);
        else
            f[i]=1;
    }
    if(z==0)
        cout << z << endl;
    else
    {
        for(int i=0;i<=m;i++)
        {
            z=fun1(z,f[i]);
        }
        cout << z << endl;
    }
    return 0;
}


Measured memory_bytes: 1792
#include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <time.h>
#include <functional>
using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(int i=0;i<n;i++)

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

ll beki(ll a, ll b) {
	ll tmp = 1;
	REP(i, b) tmp *= a;
	return tmp;
}

ll N, K;
ll M;
int main() {
    cin >> N >> K;
    M = N % K;
    cout << min(M, K - M) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
typedef long long int ll;

int main() {
	string s;
	cin >> s;
	int n = s.length();
	ll ans = 0;
	for(int i = 0; i < 1 << (n - 1); i++){
		ll sum = 0;
		ll num = s[0] - '0';
		for(int j = 0; j < n - 1; j++){
			if(i & (1 << j)){
				num *= 10;
				num += s[j + 1] - '0';
			}else{
				sum += num;
				num = s[j + 1] - '0';
			}
		}
		sum += num;
		ans += sum;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
main :: IO ()
main = do
  n <- readLn
  as <- map read . words <$> getLine
  print $ solve n as

solve :: Int -> [Int] -> Int
solve n as = sum $ map (\x -> (x - m) ^ 2) as
  where m = round $ (realToFrac $ sum as) / (realToFrac n)

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define fo(i,a) for(i = 0;i < a;i++)
using namespace std;
int main(void)
{
	int a,b,c,d,e,n=0;
	
	cin >> a >> b >> c >> d >> e ;
	if(a < 0) a = a * -1 ;
	else{
		b -= a ;
		a = 0 ;
		d = 0 ;
	}
	n = a * c + d + b * e ;
	cout << n << endl ;
	
	return 0 ;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
//#define MOD 1000000007
const int INF = 1LL<<30;

char fi[410][410];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int h,w;
int vis[410][410];

int main() {
    
    cin>>h>>w;

    rep(i,h){
        rep(j,w){
            cin>>fi[i][j];
        }
    }

    ll ans=0;
    rep(i,h){
        rep(j,w){
            if(vis[i][j]) continue;
            vis[i][j]=true;
            vector<ll> num(2,0);
            queue<pair<int,int>> que;
            que.push({i,j});

            while (!que.empty())
            {
                auto p=que.front();
                que.pop();
                int x=p.first,y=p.second;
                num[fi[x][y]=='#']++;

                rep(k,4){
                    int nx=x+dx[k];
                    int ny=y+dy[k];
                    if(nx>=0 && nx<h && ny>=0 && ny<w && !vis[nx][ny] && fi[nx][ny]!=fi[x][y]){
                        que.push({nx,ny});
                        vis[nx][ny]=true;
                    }
                }
            }
            ans+=num[0]*num[1];
        }
    }

    cout<<ans<<endl;
}

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

using namespace std;

int main()
{
    string s;
    cin >> s;
    int sum =0;
    for(auto symbol : s){
        if(symbol == '+')
            sum += 1;
        else
            sum -= 1;
    }
    cout << sum << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <iomanip>
#include <tuple>
#include <functional>
#include <bitset>
#define INF 1000000009
#define LINF 1000000000000000009
#define double long double
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
template<class T> bool chmax(T &a, const T&b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T&b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

int main() {
	ll n, a, b;
	cin >> n >> a >> b;
	if ((b - a) % 2 == 0) {
		cout << (b - a) / 2 << endl;
		return 0;
	}
	cout << min((a - 1 + (b - a - 1) / 2), (n - b + (b - a - 1) / 2))  + 1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const int maxn = 100100;
ll arr[maxn], n;

int main() {
	cin>>n;
	int br = 0, result = 0;
	for(int i=1;i<=n;i++) {
		cin>>arr[i];

		if(i == 1) br = 1;
		else {
			if(arr[i] <= arr[i-1]) br++;
			else br = 1;
		}

		if(br != 1)
			result = max(result, br-1);
	}
	cout<<result<<"\n";
}

Measured memory_bytes: 1024
import java.util.*;
import java.io.PrintWriter;
public class Main{
	static int[] pe;
	static int n;
	static int m;
	static int q;
	static int[][] ad;
	static int ans=0;
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		m=sc.nextInt();
		q=sc.nextInt();
		pe=new int[n];
		ad=new int[q][4];
		for(int i=0; i<q; i++){
			ad[i][0]=sc.nextInt()-1;
			ad[i][1]=sc.nextInt()-1;
			ad[i][2]=sc.nextInt();
			ad[i][3]=sc.nextInt();
		}
		dfs(1,0);
		System.out.println(ans);
	}
	static void dfs(int now,int co){
		pe[co]=now;
		if(co==n-1){
			int tmp=0;
			for(int i=0; i<q; i++){
				if(pe[ad[i][1]]-pe[ad[i][0]]==ad[i][2]){
					tmp+=ad[i][3];
				}
			}
			ans=Math.max(ans,tmp);
			return;
		}
		for(int i=now; i<=m; i++){
			dfs(i,co+1);
		}
	}
}

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

#define ll long long int
#define fun() ll t; cin>> t; while (t--)
#define arr() ll n;cin>> n;
#define ip() ll a[n]; for(ll x=0;x<n;x++){cin>>a[x];} 
#define MOD 1000000007

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	bool x;cin>>x;
  if(x)cout<<"0";
  else cout<<"1";
    return 0;
}

Measured memory_bytes: 3632
#11
n,m = map(int,input().split())
ab = []
cd = []
for i in range(n):
    ab.append(list(map(int,input().split())))
for i in range(m):
    cd.append(list(map(int,input().split())))
    
for i in range(n):
    Min = [0,float("inf")]
    for j in range(m):
        l = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])
        if Min[1]>l:
            Min = [j+1,l]
    print(Min[0])
    
    

Measured memory_bytes: 9156
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
   int n;
   cin >> n;
   vector<int> a(n);
   rep(i,n) cin >> a[i];
   int count = 1;
   int jokyo = 0;
   rep(i,n){
       if(a[i] == count){
           count++;
       }else{
           jokyo++;
       }
   }

   if(jokyo == n){
       cout << -1 << endl;
   }else{
       cout << jokyo << endl;
   }

  return 0;
}

Measured memory_bytes: 1024
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input, _ := reader.ReadString('\n')
	n := []int{}

	for i := 0; i < len(input)-1; i++ {
		n = append(n, int(input[i]-'0'))
	}
	// fmt.Println(n)

	res := 0
	carryOver := false

	for i := len(n) - 1; i >= 0; i-- {
		d := n[i]
		if carryOver {
			d++
		}
		carryOver = false

		if d > 5 || (d == 5 && i > 0 && n[i-1] > 4) {
			res += 10 - d
			carryOver = true
		} else {
			res += d
		}
	}
	if carryOver {
		res++
	}

	fmt.Println(res)
}


Measured memory_bytes: 34816
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int N , K , S;
	cin >> N >> K >> S;
	for (int i = 0 ; i < K ; i++)
	{
		cout<<S<<" ";
	}
	for (int i = 0 ; i < N - K ; i++)
	{

		if (S >= 1000 * 1000)
		{
			cout<<1<<" ";
		}
		else
		{
			cout<<1000 * 1000 * 1000<<" ";
		}
	}
	cout<<endl;
}

Measured memory_bytes: 1280
import math


def digit_sum(b, n):
    if b > n:
        return n
    else:
        return digit_sum(b=b, n=n // b) + n % b


def main(n, s):
    if s > n:
        return -1
    elif n == s:
        return n + 1
    else:
        b = 2
        while b * b <= n:
            if digit_sum(b, n) == s:
                return b
            b += 1

        p = 1
        b_min = -1
        while p * p <= n:
            if (n - s) % p == 0:
                b = (n - s) // p + 1
                if digit_sum(b, n) == s:
                    b_min = min(b_min, b) if b_min != -1 else b
            p += 1
        return b_min


if __name__ == '__main__':
    N = int(input())
    S = int(input())
    print(main(n=N, s=S))


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


li a[200200];

int main() {
    li n;
    cin >> n;
    rin{cin >> a[i];}

    li res = 1;
    li left = 0;
    li xor_now = a[0];
    repp(i, 1, n) {
        while (left < i && ((xor_now ^ a[i]) != xor_now + a[i])) {
            xor_now = xor_now ^ a[left];
            ++left;
        }
        xor_now = xor_now ^ a[i];
        //p2(i, left);
        res += (i - left + 1);
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main(){
    int a,b,c;
    int answer;
    answer=0;

    scanf("%d %d %d",&a,&b,&c);

    if(a==7){
        if(b==5&&c==5) answer =1;
        
    }

    else if(b==7){
        if(a==5&&c==5) answer =1;
        
    }
    else if(c==7){
        if(b==5&&a==5) answer =1;
        
    }



    if(answer==1){
     printf("YES");
    }
    else
    {
    printf("NO");
    }

    return 0;

}

Measured memory_bytes: 128
import math
A,B,C,D = map(int,input().split())

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

lcm = lcm(C,D)

u_b_ans = (B//C + B//D) - B//lcm
u_a_ans = ((A-1)//C + (A-1)//D) - (A-1)//lcm

print(B-A+1 - u_b_ans + u_a_ans)


Measured memory_bytes: 9008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n,m;
	cin>>n>>m;
	pair<ll,ll> a[m];
	ll p[100005];
	memset(p,0,sizeof(p));
	for(ll i=0;i<m;i++)
	{
		cin>>a[i].first>>a[i].second;
		p[a[i].first]++;
		p[a[i].second+1]--;
	}
	ll ans=0;
	for(ll i=1;i<100005;i++){
		p[i]=p[i-1]+p[i];
		if (p[i]==m)
			ans++;
	}
	cout<<ans;

}

Measured memory_bytes: 2560
s = int(input())
integers = {s}
count = 1
while True:
    count += 1
    if s % 2 == 0:
        tmp = s / 2
    else:
        tmp = 3 * s + 1
    if tmp in integers:
        break
    integers.add(tmp)
    s = tmp
print(count)

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

int main() {
  int N;
  int x;
  int count = 0;
  cin >> N;
  
  //ボタンの情報を取得
  vector<int> buttons(N);
  vector<bool> isLight(N);
  for (int i=0;i<N;i++) {
    cin >> buttons.at(i);
    isLight.at(i) = false; //初期化
  }
  isLight.at(0) = true; //ボタン１は点灯済み
  x = 0;
  //
  while (isLight.at(1) == false) { //ボタン２が点灯するまで続ける
    //ボタンを押して光るボタンはすでに１回点灯済みか判定
    if (isLight.at(buttons.at(x)-1) == true) {
      count = -1;
      break;
    }
    //ボタンを押す
    isLight.at(buttons.at(x)-1) = true;	//対応するボタンを点灯
    x = buttons.at(x)-1;				//次に押すボタンを取得
    count += 1;						//カウントを追加
  }
  
  //結果出力
  cout << count << endl;
}


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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

int main(){
	vector<vector<int>> vec_n;
	vector<vector<int>> vec;

	while(1){
		int n, m;
		cin >> n >> m;
		if (n == 0 && m == 0) break;

		vector<int> v_n;
		v_n.push_back(n);
		v_n.push_back(m);
		vec_n.push_back(v_n);

		vector<int> v;
		rep(i, n)
		{
			int a;
			cin >> a;
			v.push_back(a);
		}

		vec.push_back(v);
	}

	rep(k, vec.size()){
		int ans = -1;

		int n = vec_n[k][0];
		int m = vec_n[k][1];

		rep(i, n - 1){
			REP(j, i + 1, n){
				int x = vec[k][i] + vec[k][j];
				if(x <= m && ans <= x) ans = x;
			}
		}

		if(ans == -1) cout << "NONE";
		else cout << ans;

		if(k != vec.size()) cout << endl;
	}

	return 0;
}


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

#define int long long

using namespace std;



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

	int N;
	cin >> N;

	cout << N + N*N + N*N*N << '\n';    

    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll a[4][1000000];
ll n, w;
ll dpdp[101][1000000];
ll dp(ll x, ll m)
{
    if(x>=n||m<=0)
    {
        dpdp[x][m]=0;
        return 0;
    }
    if(dpdp[x][m]!=-1)
        return dpdp[x][m];
    if(m<a[0][x])
    dpdp[x][m]=dp(x+1, m);
    else
    dpdp[x][m]=max(dp(x+1, m-a[0][x])+a[1][x], dp(x+1, m));
    return dpdp[x][m];
}
int main()
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    cin >> n >> w;
    for (int i = 0; i < n; ++i)
    {
        cin >> a[0][i]>> a[1][i];
    }
    for (int i = 0; i < w+1; ++i)
    {
        for (int j = 0; j < n+1; ++j)
        {
            dpdp[j][i]=-1;
        }
     }
    cout << dp(0, w);
    return 0;
}

Measured memory_bytes: 293888
n = gets.to_i
t, a = gets.split(" ").map(&:to_i)
hs = gets.split(" ").map(&:to_i)

diff = Float::INFINITY
ans = nil
n.times do |i|
  if (a - (t - hs[i] * 0.006)).abs < diff
    diff = (a - (t - hs[i] * 0.006)).abs
    ans = i + 1
  end
end

puts ans

Measured memory_bytes: 1788
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;

  vll cnt(13, 0);
  cnt[0]++;
  rep(i, n) {
    ll x;
    cin >> x;
    cnt[x]++;
  }

  ll ans = 0;
  rep(i, 1 << 14) {
    ll tmp = 12;
    vll lst;
    rep(j, 13) {
      if (cnt[j] == 1) {
        if (i >> j & 1) {
          ll jp = (24 - j)%24;
          lst.push_back(jp);
        } else {
          lst.push_back(j);
        }
      } else if (cnt[j] == 2) {
        lst.push_back(j);
        lst.push_back(24 - j);
      } else if(cnt[j] >= 3) {
        cout << 0 << endl;
        return 0;
      }
    }
    ll m = lst.size();
    repLRE(ii, 0, m - 2) {
      repLRE(jj, ii + 1, m - 1) {
        ll now = abs(lst[ii] - lst[jj]);
        chmin(now, 24 - now);
        chmin(tmp, now);
      }
    }
    chmax(ans, tmp);
  }  // i

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,m,ans;
int main(){
    cin>>n>>m;
    for(int i=m/n;i>=1;i--){
        if(m%i==0){
            int g=m/i;
            if(g>=n){
            	cout<<i<<endl;
            	return 0;
			}
        }
    }
    return 0;
}

Measured memory_bytes: 3600
#include<iostream>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a>b && a>c)
    {
        if(b>c)
            cout<<c<<" "<<b<<" "<<a<<endl;
        else
            cout<<b<<" "<<c<<" "<<a<<endl;
    }
    else if(b>a && b>c)
    {
        if(a>c)
            cout<<c<<" "<<a<<" "<<b<<endl;
        else
            cout<<a<<" "<<c<<" "<<b<<endl;
    }
    else if(c>a && c>b)
    {
        if(a>b)
            cout<<b<<" "<<a<<" "<<c<<endl;
        else
            cout<<a<<" "<<b<<" "<<c<<endl;
    }
    else
        cout<<"error"<<endl;

    return 0;
}



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

int main()
{
	int x;
	cin >> x;
	int dp[100001] = {};
	int kane[6] = {100,101,102,103,104,105};
	for (int i = 0; i < 6; ++i)
	{
		for (int j = 0; j <= x; ++j)
		{
			if ((dp[j] != 0 || j == 0) && j + kane[i] <= x)
			{
				dp[j + kane[i]] = 1;
			}
		}
	}
	cout << dp[x] << endl;
	return 0;
}

Measured memory_bytes: 640
N, K = map(int, input().split())
X = list(map(int, input().split()))

lim = 100
dp = [[0] * (N + 1) for _ in range(lim)]
dp[0] = [0] + X
for k in range(1, lim):
    for i in range(N + 1):
        dp[k][i] = dp[k - 1][dp[k - 1][i]]

ans = 1
for i in range(lim):
    if K >> i & 1:
        ans = dp[i][ans]

print(ans)


Measured memory_bytes: 237088
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
void hr() { cerr << "--------------" << endl; }
const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   string s;
   cin >> s;
   string t = "ATCG";
   int n = s.size();

   int now = 0;
   int ans = 0;
   rep(i, 0, n) {
      bool ok = false;
      rep(j, 0, t.size()) {
         if (s[i] == t[j]) ok = true;
      }
      if (ok) {
         now++;
         ans = max(ans, now);
      } else {
         now = 0;
      }
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
# -*- codin: utf-8 -*-

s = input()
a = int(s[:2])
b = int(s[2:5])

if 1 <= a <= 12 and 1 <= b <= 12:
    print('AMBIGUOUS')
elif (a == 0 or a >= 13) and (1 <= b <= 12):
    print('YYMM')
elif (b == 0 or b >= 13) and (1 <= a <= 12):
    print('MMYY')
else:
    print('NA')




Measured memory_bytes: 2940
import fractions
N = int(input())
A = list(map(int,input().split()))
mod = 10**9+7
answer = 0


def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

g = A[0]
for i in range(1, N):
    p = fractions.gcd(g, A[i])
    g = g*A[i]//p
    
g = g%mod
for i in A:
    answer += (g*modinv(i))%mod
    
print(answer%mod)

Measured memory_bytes: 68824
#include <iostream>

int main() {
    long long int N,K;
    scanf("%lld %lld",&N,&K);
    long long int count = 0;
    long long int digit = 1;
    while(1){
        digit = digit*K;
        count++;
        if(N == digit ){
            printf("%lld",count+1);
            return 0;
        }
        else if(N/digit == 0){
            printf("%lld",count);
            return 0;
        }
    }

}

int A(){
    int N,K;
    scanf("%d %d",&N,&K);
    if(N < 10){
        printf("%d",K+100*(10-N));
    }
    else{
        printf("%d",K);
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
ll bpow(ll b, ll p, ll m = 1000000007LL) {
  ll rt = 1;
  for (; p; p >>= 1, b = b * b % m)
    if (p & 1)
      rt = rt * b % m;
  return rt;
}
ll a[200005];
int main() {
  IOS;
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  for (int i = k + 1; i <= n; i++) {
    if (a[i] <= a[i - k]) {
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
  }
}


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

double conc(int water, int sugar) {
  double sum = water + sugar;
  return 100 * sugar / sum;
}

int main() {
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;

  set<int> water;
  set<int> sugar;

  for (int i = 0; i < F; i++) {
    for (int j = 0; j < F; j++) {
      int x = 100 * A * i + 100 * B * j;
      if (x <= F) water.insert(x);
    }
  }

  for (int i = 0; i < F; i++) {
    for (int j = 0; j < F; j++) {
      int y = C * i + D * j;
      if (y <= F) sugar.insert(y);
    }
  }

  double desired_conc = conc(100, E);
  double max_conc = 0;
  int ans_sum, ans_sugar;

  for (auto x : water) {
    for (auto y : sugar) {
      if (F < x + y) continue;
      double c = conc(x, y);
      if (max_conc <= c && c <= desired_conc) {
        max_conc = c;
        ans_sum = x + y;
        ans_sugar = y;
      }
    }
  }

  cout << ans_sum << ' ' << ans_sugar << endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define INF_LL (ll)1e18

#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

class LazySegTree{
private:
	int n;
	vector<ll> node, lazy;
	vector<bool> lazyFlag;
public:
	LazySegTree(vector<ll> v){
		int sz = v.size();
		n = 1; while(n < sz) n *= 2;
		node.resize(2*n-1, 0);
		lazy.resize(2*n-1, 0);
		lazyFlag.resize(2*n-1, false);
		REP(i, sz) node[i+n-1] = v[i];
		for(int i = n-2;i >= 0;i--) node[i] = node[2*i+1]+node[2*i+2];
	}

	void eval(int k, int l, int r){
		if(lazyFlag[k]){
			node[k] += lazy[k] * (r-l);
			if(r-l > 1){
				lazy[2*k+1] += lazy[k];
				lazy[2*k+2] += lazy[k];
				lazyFlag[2*k+1] = lazyFlag[2*k+2] = true;
			}
			lazy[k] = 0;
			lazyFlag[k] = false;
		}
	}

	void add(int a, int b, ll x, int k=0, int l=0, int r=-1){
		if(r < 0) r = n;
		eval(k, l, r);
		if(b <= l || r <= a) return;

		if(a <= l && r <= b){
			lazy[k] += x;
			lazyFlag[k] = true;
			eval(k, l, r);
		}else{
			add(a, b, x, k*2+1, l, (l+r)/2);
			add(a, b, x, k*2+2, (l+r)/2, r);
			node[k] = node[k*2+1] + node[k*2+2];
		}
	}

	ll query(int a, int b, int k=0, int l=0, int r=-1){
		if(r < 0) r = n;
		eval(k, l, r);

		if(b <= l || r <= a) return 0;
		if(a <= l && r <= b) return node[k];

		return query(a, b, k*2+1, l, (l+r)/2) + query(a, b, k*2+2, (l+r)/2, r);
	}
};

int sum[26][214514] = {}, rsum[26][214514] = {};


int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int n = s.size();
	LazySegTree reg(vector<ll>(n+10, 0)), rev(vector<ll>(n+10, 0));
	REP(i, s.size()){
		s[i] -= 'a';
		sum[s[i]][i]++;
		rsum[s[i]][n-i-1]++;
	}
	REP(i, 26){
		REP(j, n){
			sum[i][j+1] += sum[i][j];
			rsum[i][j+1] += rsum[i][j];
		}
	}
	int cnt = 0;
	REP(i, 26){
		if(sum[i][n]%2)
			cnt++;
	}
	if(cnt > 1){
		cout << -1 << endl;
		return 0;
	}
	ll res = 0;
	int use[26] = {};
	REP(i, n/2){
		int willuse = 0, cost = INF, uin, urin;
		REP(j, 26){
			if(use[j]+1 >= sum[j][n]) continue;
			int in = lower_bound(sum[j], sum[j]+n, use[j]/2+1)-sum[j];
			int rin = lower_bound(rsum[j], rsum[j]+n, use[j]/2+1)-rsum[j];
			int tcost = in-rev.query(n-in-1, n-in)+reg.query(in, in+1)-i+rin+rev.query(rin, rin+1)-reg.query(n-rin-1, n-rin)-i;
			if(cost > tcost){
				willuse = j;
				cost = tcost;
				uin = in;
				urin = rin;
			}
		}
		int in = uin;
		int rin = urin;
		use[willuse]+=2;
		res += cost;
		reg.add(0, in, 1);
		rev.add(0, rin, 1);
	}
	cout << res << endl;
}


Measured memory_bytes: 61944
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<map>
#include<cmath>
using namespace std;

typedef long long LL;

const int N=100005;

int n;
LL a[N],b[N];
map<LL,int> ma;
LL sqr(LL x)
{
    return x*x;
}
int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
    {
        LL x;scanf("%lld",&x);
        for (LL j=2;j*j*j<=x;j++)
            while (x%(j*j*j)==0) x/=j*j*j;
        ma[x]++;a[i]=x;
        LL y=1;
        for (LL j=2;j*j*j<=x;j++)
            if (x%j==0)
            {
                y*=(x%(j*j)==0)?j:j*j;
                while (x%j==0) x/=j;
            }
        if (sqr((LL)sqrt(x))==x) y*=(LL)sqrt(x);
        else y*=x*x;
        b[i]=y;
    }
    int ans=0;
    if (ma[1]) ans++,ma[1]=0;
    for (int i=1;i<=n;i++) ans+=max(ma[a[i]],ma[b[i]]),ma[a[i]]=ma[b[i]]=0;
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (1E9+7)
#define PI 3.1415926535897932384626433832795

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}
std::ostream &operator<<(std::ostream &out, const vector<char> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		string str(1, tgt[i]);
		s += (str + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

vi a,c;
vector<char> b;
bool sw = true;

int partition(int p,int r) {
	int cnt = 0;
	int x = a[r];
	int i = p-1;
	for (int j = p; j < r; j++) {
		if (a[j] <= x) {
			i++;
			swap(a[i], a[j]);
			swap(b[i], b[j]);
			swap(c[i], c[j]);
		}
	}
	swap(a[i + 1], a[r]);
	swap(b[i + 1], b[r]);
	swap(c[i + 1], c[r]);
	return i +1;
}


void quickSort(int p, int r) {
	if (p < r) {
		int q = partition(p, r);
		quickSort(p, q - 1);
		quickSort(q + 1, r);
	}
}


int main() {
	char ch;
	int n,in;
	cin >> n;
	rep(i, n) {
		cin >> ch;
		cin >> in;
		a.push_back(in);
		b.push_back(ch);
		c.push_back(i);
	}
	quickSort(0,n-1);
	for (int i = 1; i < n; i++) {
		if (a[i] == a[i - 1] && c[i] < c[i - 1])sw = false;
	}
	cout << (sw ? "S" : "Not s") << "table" << endl;
	rep(i, n) {
		cout << b[i] << " " << a[i] << endl;
	}
}



Measured memory_bytes: 3872
def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    s = 0
    before = 0
    for ai in a:
        s += b[ai - 1]
        if ai == before + 1 and before > 0:
            s += c[before - 1]
        before = ai
    print(s)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 3064