akhauriyash/Code-Regression huggingface dataset:
n = int(input())
s = input()

num = [0]
for c in s:
    if c == '(':
        num.append(num[-1] + 1)
    else:
        num.append(num[-1] - 1)

for _ in range(num[0] - min(num)):
    print('(', end='')

print(s, end='')

for _ in range(num[-1] - min(num)):
    print(')', end='')

Measured memory_bytes: 62096
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>

auto& in = std::cin;
auto& out = std::cout;

int32_t N;
int64_t G[300][300];

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	int64_t cost = 0;
	in >> N;
	for (int i = 0; i < N; ++i)
		for (int j = 0; j < N; ++j)
	{
			in >> G[i][j];
			cost += G[i][j];
	}
	cost /= 2;

	for (int i = 0; i < N; i++)
		for (int k = i+1; k < N; k++)
	{
			bool is_same = false;
			for (int j = 0; j < N; j++)
			{
				if (j == i || j == k) { continue; }
				auto longpath = G[i][j] + G[j][k];
				if (longpath < G[i][k]) {
					out << -1 << endl; return 0;
				}
				if (longpath == G[i][k]) { is_same = true; }
			}
			if (is_same) {
				cost -= G[i][k];
			}

	}
	out << cost << endl;

	return 0;
}
#endif


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

int main(){
 	string s;
	cin >>s;
	int t = 0;
  	for(int i = 0; i < 4; i++) {
      	if(s[i] == '-')
          	t--;
      	else
          	t++;
    }
  	cout << t << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int num[300010];
int main(){
	int n,q;
	scanf("%d%d",&n,&q);
	
	int x = 0;
	for(int i = 0; i < n; i++){
		scanf("%d",&x);
		num[x] = x;
	}
	
	for(int i = 0; i < 300000; i++){
		num[i+1] = max(num[i],num[i+1]);
	}
	
	int ans = 0;
	for(int i = 0; i < q; i++){
		scanf("%d",&x);
		ans = 0;
		
		for(int j = x; j < 300001; j+= x){
			ans = max(ans,num[j-1] % x);
		}
		ans = max(ans,num[300000]%x);
		printf("%d\n",ans);
		
	}
	return 0;
}

Measured memory_bytes: 2196
import java.util.*;
class Main {
	
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while (true) {
			int n = stdIn.nextInt();
			if(n == 0) break;
			int[][] x = new int[n + 1][];
			int[][] y = new int[n + 1][];
			for (int i = 0; i < n + 1; i++) {
				int m = stdIn.nextInt();
				x[i] = new int[m];
				y[i] = new int[m];
				for (int j = 0; j < m; j++) {
					int xi = stdIn.nextInt();
					int yi = stdIn.nextInt();
					x[i][j] = xi;
					y[i][j] = yi;
				}
			}
			//原点へ移動
			for (int i = 0; i < n + 1; i++) {
				int dx = x[i][0];
				int dy = y[i][0];
				for (int j = 0; j < x[i].length; j++) {
					x[i][j] -= dx;
					y[i][j] -= dy;
				}
			}
			
			int[] CAX = x[0];
			int[] CAY = y[0];
			
			int[] CBX = new int[x[0].length];
			int[] CBY = new int[y[0].length];
			int dx = CAX[CAX.length-1];
			int dy = CAY[CAY.length-1];
			for(int i = 0; i < x[0].length; i++) {
				CBX[i] = CAX[x[0].length - i - 1]-dx;
				CBY[i] = CAY[x[0].length - i - 1]-dy;
			}
			
			for(int i = 1; i < n+1; i++) {
				boolean isF = false;
				for(int j = 0; j < 3; j++) {
					if(check(CAX,CAY,x[i],y[i]) || check(CBX,CBY,x[i],y[i])) {
						isF = true;
					}
					turn(x[i],y[i]);
				}
				if(check(CAX,CAY,x[i],y[i]) || check(CBX,CBY,x[i],y[i])) {
					isF = true;
				}
				if(isF) {
					System.out.println(i);
				}
				
			}
			System.out.println("+++++");
		}
		
	}
	public static void turn(int[] ax, int[] ay) {
		for(int i = 0; i < ax.length; i++) {
			ay[i] *= -1;
			int tmp = ax[i];
			ax[i] = ay[i];
			ay[i] = tmp;
		}
	}
	public static boolean check(int[] ax, int[] ay, int[] bx, int[] by) {
		if(ax.length != bx.length) return false;
		for(int i = 0; i < ax.length; i++) {
			if(ax[i] != bx[i]) return false;
			if(ay[i] != by[i]) return false;
		}
		return true;
	}
}

Measured memory_bytes: 29372
import sys
n = int(input())
S = list(map(int, input().split(' ')))
q = int(input())
T = list(map(int, input().split(' ')))
counter = 0
def binary_search(A, left, right, t):
    if(left > right):
        return
    global counter
    center = (right + left) // 2
    if(A[center] == t):
        counter += 1
        return
    elif(A[center] < t):
        binary_search(A, center+1, right, t)
    else:
        binary_search(A, left, center-1, t)

for t in T:
    binary_search(S, 0, n, t)
print(counter)



Measured memory_bytes: 16716
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, x, a;
    cin >> n >> x;
    cin >> a;
    ll d = abs(x - a);
    rep(i,n-1){
        cin >> a;
        a = abs(x - a);
        d = gcd(d, a);
    }
    cout << d << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define endl '\n'
#define pii pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define traceloop(x,a) {for(ll i=0;i<x;i++) cerr<<a[i]<<" "; cerr<<endl;}
ll ab(ll x) {return x>0LL?x:-x;}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	ll n,k;
	cin>>n>>k;
	vector<ll> h(n+1);
	for(int i=1; i<=n; i++)
		cin>>h[i];
	h[0]=h[1];
	vector<ll> dp(n+1,INT_MAX);
	dp[0]=dp[1] = 0;
	for(ll i=2; i<=n; i++)
	{
		for(ll j=1; j<=k; j++)
			dp[i] = min(dp[i],dp[max(0LL,i-j)] + abs(h[i]-h[max(0LL,i-j)]));
	}
	cout<<dp[n];
	return 0;
}
	

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

int main(){
    string s;
    cin>>s;
    int cnt[3];
    for(int i=0;i<3;i++) cnt[i]=0;
    for(int i=0;i<s.size();i++){
        cnt[s[i]-'a']++;
    }
    int ma=max({cnt[0],cnt[1],cnt[2]});
    if(ma<=cnt[0]+1 && ma<=cnt[1]+1 && ma<=cnt[2]+1) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    
    return 0;
}

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

using namespace std;
typedef long long ll;

const int N=2e5+10;
int n,k,m;
int a[N];
int b[N];
int ans[N];
string s;
int vis[N];
map<int,int> mp;

int cmp(int a, int b){
    return a>b;
}
int main()
{
    cin>>n;
    if(n==0) cout<<1;
    else cout<<0;
}



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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n; cin >> n;
  int ans = 0;
  long double d; cin >> d;
  for(int i = 0; i < n; ++i){
    long double x,y; cin >> x >> y;
    ans += x*x+y*y <= d*d;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    vector<int> c = a;
    sort(c.begin(), c.end());
    c.erase(unique(c.begin(), c.end()), c.end());

    if (c.size() >= 3) {
        cout << "No" << endl;
        return 0;
    }
    if (c.size() == 1) {
        if (c[0] == n-1 || 2 * c[0] <= n) {
            cout << "Yes" << endl;
            return 0;
        }
    } else if (c.size() == 2) {
        if (c[1] - c[0] != 1) {
            cout << "No" << endl;
            return 0;
        }
        int n1 = 0, n2 = 0;
        rep(i, n) {
            if (a[i] == c[0]) n1++;
            else n2++;
        }
        if (1 <= c[1] - n1 && (c[1] - n1) * 2 <= n2) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


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

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int isprime[1000000];

void sieve(int n){
  int i, j;

  memset(isprime, 1, sizeof(isprime));
  isprime[0] = isprime[1] = 0;
  for(i = 0; i*i <= n; i++) if(isprime[i]){
    for(j = 2*i; j <= n; j += i) isprime[j] = 0;
  }

  return;
}

int main(){
  int i, n;
  int res = 0;

  while(scanf("%d",&n) != EOF){
    res = 0; n++;
    sieve(n);
    rep(i,n) if(isprime[i]) res++;

    printf("%d\n", res);
  }

  return 0;
}

Measured memory_bytes: 4316
N,L = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

A2 = [x+A[ind+1] for ind,x in enumerate(A[:-1])]
A2.index(max(A2))
if(max(A2)<L):
    print('Impossible')
else:
    print('Possible')
    last = A2.index(max(A2))
    for i in range(last):
        print(i+1)
    for i in range(N-1,last+1,-1):
        print(i)
    print(last+1)


Measured memory_bytes: 14052
import sys

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


def main():
    N = int(readline())
    s = set()

    for i in range(1000):
        for j in range(1000):
            s.add(i * 4 + j * 7)

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


if __name__ == '__main__':
    main()


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

int main()
{
  int a,b,c;
  cin >> a>> b>> c;
  cout << ((a <= c && b >= c) ? "Yes" : "No" ) << endl;
  return 0;
}


Measured memory_bytes: 3604
#include <stdio.h>

int H, W;
char a[10][10];
int x = 0, y = 0;
bool ans = true;

int main(void) {
	scanf("%d%d", &H, &W);
	for (int i = 0; i < H; ++i) { scanf("%s", &a[i]); }

	while (true) {
		if (x == H - 1 && y == W - 1) { a[x][y] = '.'; break; }
		if (a[x][y] == '#'&&a[x][y + 1] == '#') { a[x][y] = '.'; y++; }
		else if (a[x][y] == '#'&&a[x + 1][y] == '#') { a[x][y] = '.'; x++; }
		else { ans = false; break; }
	}

	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (a[i][j] == '#') { ans = false; }
		}
	}
	if (ans == true) { printf("Possible\n"); }
	else { printf("Impossible"); }
	return 0;
}

Measured memory_bytes: 128
package main

import (
	"fmt"
)

func isPrime(x int) bool {

	for i := 2; i < x; i++ {
		if x%i == 0 {
			return false
		}
	}
	return true
}
func main() {
	var x int
	fmt.Scan(&x)

	result := x

	for i := x; i < x*x; i++ {
		if isPrime(i) {
			result = i
			break
		}
	}

	fmt.Println(result)
}


Measured memory_bytes: 512
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <tuple>
using namespace std;

const double pi = acos(-1);
#define nyan cout << "(=^•ω•^=)" << endl;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop while(true)

signed main(){
    int x,y;
    cin>>x>>y;
    cout<<x+y/2<<endl;
    return 0;
}

Measured memory_bytes: 256
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let w: usize = input();
    let wv: Vec<(usize, i64)> = (0..n).map(|_| (input(), input())).collect();

    let mut v = vec![vec![0; w + 1]; n + 1];
    for i in 1..n + 1 {
        let (wi, vi) = wv[i - 1];
        v[i][wi] = std::cmp::max(v[i][wi], vi);
        for j in 0..w + 1 {
            if v[i - 1][j] > 0 {
                v[i][j] = std::cmp::max(v[i][j], v[i - 1][j]);
                if j + wi <= w {
                    v[i][j + wi] = std::cmp::max(v[i][j + wi], v[i - 1][j] + vi);
                }
            }
        }
    }

    println!("{}", v[n].iter().max().unwrap());
}


Measured memory_bytes: 106748
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(t) for(ll i=0;i<t;i++)
#define ll long long int
#define ld long double
#define umpl unordered_map<ll,ll> 
#define vl vector<ll>
#define vld vector<ld>
#define vvl vector<vl>
#define pb push_back
#define mod 998244353
#define inf 1e18
#define pcout(x,p) cout<<fixed<<setprecision(p)<<x
#define all(a) a.begin(),a.end()
#define endl "\n"

inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c >= mod) c -= mod; return c; }
inline ll max(ll a, ll b){return a>b?a:b;}
inline ll min(ll a, ll b){return a<b?a:b;}
inline ll ceil(ll a,ll b){if(a%b==0)return a/b;else return a/b+1;}
inline ll mo(ll a,ll b){if(b<0){b=abs(b)%mod;b=a-b;return (b<0)?b+mod:b;}else{return (a+b)%mod;}}
inline ll pow(ll a,ll b){if(b==0){return 1;}else{if(b%2==0){ll temp=pow(a,b/2);return temp*temp;}
else{return a*pow(a,b-1);}}}

struct comp { 
    template<class T1,class T2,class T3,class T4>
    bool operator()(const pair<T1,T2> &p1,const pair<T3,T4> &p2){
        return p1.first<p2.first;
    }
}; 

int main(){
	ll a;cin>>a;
	cout<<a+a*a+a*a*a<<endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007;

void solve(){
    int n, k; cin >> n >> k;
    long long ans = 1;
    for(int i = 0; i < n; i++){
        ans *= k;
        ans %= MOD;
    }
    cout << ans << endl;
}

int main(){
    solve();
    return 0;
}


Measured memory_bytes: 3132
/**********************************************
 * author : deepak nayan
 * file   : e:/Solutions/atcoder/abc143_a.cpp
 * time   : Sat May  2 13:49:31 2020
 * quest  : A - Curtain
 *********************************************/
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  cout << max(0, a - 2 * b) << "\n";
  return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque
import heapq
import bisect
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

N = int(input())
xy = [tuple([int(x) for x in input().strip().split()] + [n+1]) for n in range(N)]
x_sorted = sorted(xy)
y_sorted = sorted(xy, key=lambda x: x[1])
L = [deque([]) for _ in range(N)]
L[x_sorted[0][2]-1].append((x_sorted[1][2], x_sorted[1][0]-x_sorted[0][0]))
L[y_sorted[0][2]-1].append((y_sorted[1][2], y_sorted[1][1]-y_sorted[0][1]))
for n in range(1, N-1):
    L[x_sorted[n][2]-1].append((x_sorted[n-1][2], x_sorted[n][0]-x_sorted[n-1][0]))
    L[x_sorted[n][2]-1].append((x_sorted[n+1][2], x_sorted[n+1][0]-x_sorted[n][0]))
    L[y_sorted[n][2]-1].append((y_sorted[n-1][2], y_sorted[n][1]-y_sorted[n-1][1]))
    L[y_sorted[n][2]-1].append((y_sorted[n+1][2], y_sorted[n+1][1]-y_sorted[n][1]))
L[x_sorted[-1][2]-1].append((x_sorted[-2][2], x_sorted[-1][0]-x_sorted[-2][0]))
L[y_sorted[-1][2]-1].append((y_sorted[-2][2], y_sorted[-1][1]-y_sorted[-2][1]))


q = [(0, 1)]
cost = [float('inf')] * N

while q:
    c, p = heapq.heappop(q)
    if cost[p-1] <= c:
        continue
    cost[p-1] = c
    for np, nc in L[p-1]:
        if cost[np-1] == float('inf') and cost[np-1] > c + nc:
            heapq.heappush(q, (nc, np))

print(sum(cost))

Measured memory_bytes: 130684
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int qsort_compare(const void *a, const void *b)
{
  return strcmp(a, b);
}

int main()
{
  int N, L;
  char s[100][101] = {{0}};

  scanf("%d%d", &N, &L);

  for(int cnt = 0; cnt < N; cnt++){
    scanf("%s", s[cnt]);
  }

  qsort(s, N, sizeof(s[0]), qsort_compare);

  for(int cnt = 0; cnt < N; cnt++){
    printf("%s", s[cnt]);
  }  

  printf("\n");
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};




int main(){
    int n;cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int now = 0;
    for (int i = 0; i < n; i++) {
        if(now + 1 == a[i]) now++;
    }
    if(now) cout << n - now << endl;
    else cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 1024
use proconio::input;

#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::ops::*;

#[derive(Clone, Debug, Default)]
struct Struct;

//#[proconio::fastout]
fn main() {
    input! {
        h: usize,
        w:usize,
        ab: [(Usize1,Usize1);h],
    }

    const MAX_WALK: usize = 200005;
    let mut m = BTreeMap::new();
    for i in 0..w {
        m.insert(i, 0);
    }

    let mut w_hist = vec![0; MAX_WALK + 1];
    w_hist[0] = w;
    w_hist[MAX_WALK] = 1;

    let mut v = Vec::with_capacity(w);
    let mut ans = 0;

    for i in 0..h {
        let l = ab[i].0;
        let r = ab[i].1 + 1;
        v.clear();
        let mut min_walk = MAX_WALK;
        for (&pos, &walk) in m.range(l..r + 1) {
            min_walk = min(min_walk, walk + (r - pos));
            v.push(pos);
            w_hist[walk] -= 1;
        }
        for pos in &v {
            m.remove(pos);
        }
        if min_walk != MAX_WALK && r < w {
            m.insert(r, min_walk);
            w_hist[min_walk] += 1;
        }

        // for j in 0..w {
        //     if let Some(wa) = m.get(&j) {
        //         print!("{} ", wa);
        //     } else {
        //         print!("x ",);
        //     }
        // }
        // println!("--{}", ans);

        while w_hist[ans] == 0 {
            ans += 1;
        }

        if ans == MAX_WALK {
            println!("{}", -1);
        } else {
            println!("{}", ans + i + 1);
        }
    }
}


Measured memory_bytes: 14960
#include<stdio.h>
int main(void){
  int a, b, c, d;
  scanf ("%d %d %d", &a, &b, &c);
  if(c > b){
  d = b;
  b = c;
  c = d;
  }
  if(b > a){
  d = a;
  a = b;
  b = d;
  }
  if(c > b){
  d = b;
  b = c;
  c = d;
  }
  printf ("%d %d %d\n", c, b, a);
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG

signed main() {
  int A, B, C, K; cin >> A >> B >> C >> K;
  
  while(A >= B) {
    B *= 2;
    K--;
  }
  while(B >= C) {
    C *= 2;
    K--;
  }
  
  if(K >= 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  
  

}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

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

    ll tmp;
    rep(i, n) cin >> tmp;

    ll ans = 1;
    if((n - k) % (k - 1) == 0)
        ans += (n - k) / (k - 1);
    else
        ans += (n - k) / (k - 1) + 1;
    cout << ans;
}


Measured memory_bytes: 256
#define S 0
#define H 1
#define C 2
#define D 3
#include <iostream>

using namespace std;


int main(){
    
    int cards[4][13]={0};
    char patterns[] = {'S', 'H', 'C', 'D'};
    int n, rank;
    char pattern;

    cin >> n;
    for(int i=0; i<n; i++){
        cin >> pattern >> rank;
        switch(pattern){
            case 'S':
                cards[S][rank-1] = 1;
                break;
            case 'H':
                cards[H][rank-1] = 1;
                break;
            case 'C':
                cards[C][rank-1] = 1;
                break;
            case 'D':
                cards[D][rank-1] = 1;
                break;
            default:
                break;
        }
    }
    for(int p=S; p<=D; p++){
        for(int r=0; r<13; r++){
            if(cards[p][r]==0){
                cout << patterns[p] << " " << r+1 << endl;
            }
        }
    }

    return 0;
}




Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define LL long long
#define maxn 100005
using namespace std;
bool slove(char *s)
{
	int len;
	len = strlen(s);
	for (int i = 0; i < len; i++)
	{
		if (*(s + i) != *(s+len - i - 1)) return false;
	}
	return true;
}

int main()
{
    double L;
    cin>>L;
    double ans=L*L*L/27;
    printf("%.8f",ans);
}


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


int main(){

  long n,m,i,left;
  long total=0;
  cin>>n>>m;

  long a[m];
  for(i=0; i<m; i++){
    scanf("%ld",&a[i]);
    total=total+a[i];
  }

  left=n-total;

  if(total>n){
    printf("-1\n");
  }else{
    printf("%ld\n",n-total);
  }

  return 0;
}

Measured memory_bytes: 3760
import sys
stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

S = rs()
S = S.replace('BC', 'D')
cnt_A = 0
answer = 0
for s in S:
    if s == 'A':
        cnt_A += 1
    elif s == 'D':
        answer += cnt_A
    else:
        cnt_A = 0
print(answer)

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

int main(){
  string s;
  cin >> s;
  
  rep(i, 0, s.size())
    cout << "x";
  cout << endl;
  
  return 0;
  
}

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

vector<unsigned long> table;

// valueはreturn回で倒せるよー的な
ull sub(ull value);

int main()
{
    ull H;
    cin >> H;
    cout << sub(H);

    cout << "\n";
    return 0;
}

ull sub(ull value)
{
    if(value == 1)
    {
        return 1;
    }
    else
    {
        // テーブルにすでに値があればそれを返す
        {
            ull half=0;
            if(value % 2 == 0)
            {
                half = value / 2;
                ull table_value = sub(half)* 2  + 1;
                // table.at(value) = table_value;
                return table_value;
            }
            else
            {
                half = (value-1) / 2;
                ull table_value = sub(half) * 2 + 1;
                // table.at(value) = table_value;
                return table_value;
            }
        }
    }
}

Measured memory_bytes: 256
from bisect import bisect
n, m = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
a.append(0)
b.append(0)
a.sort()
b.sort()
ia = 0
ib = 0
cnt = 1
for i in range(1,n*m+1)[::-1]:
    if i == a[-1]:
        if i == b[-1]:
            cnt *= 1
            a.pop(-1)
            b.pop(-1)
            ia += 1
            ib += 1
        else:
            cnt *= ib
            a.pop(-1)
            cnt %= 1000000007
            ia += 1
    else:
        if i == b[-1]:
            cnt *= ia
            b.pop(-1)
            cnt %= 1000000007
            ib += 1
        else:
            cnt *= ia*ib - (n*m - i)
            cnt %= 1000000007

print(cnt)


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

int main() {
	int a,b;
	cin >> a >> b;
	if (a < b) {
		cout << "a < b" << endl;
	} else if(a > b){
		cout <<"a > b" << endl;
	} else {
		cout <<"a == b" << endl;
	}
	return 0;
}


Measured memory_bytes: 3080
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	/*string s,b;
	cin>>s>>b;
	if(s[0]==b[1])cout<<"!"<<endl;*/
	string a,b;
	while(cin>>a>>b,a!="0"||b!="0"){
		int h=0,br=0;
		rep(i,4)rep(j,4){
			if(a[i]==b[j]){
				if(i==j)h++;
				else br++;
			}
		}
		cout<<h<<" "<<br<<endl;
	}
}

Measured memory_bytes: 1188
n,m = map(int,input().split())
edges = []
for _ in range(m):
    edges.append(list(map(int,input().split())))
ans = []
cur = ((n-1)*n)//2
par = {i:i for i in range(1,n+1)}
size = {i:1 for i in range(1,n+1)}
rank = {i:0 for i in range(1,n+1)}
def find(x):
    if x != par[x]:
        par[x] = find(par[x])
    return par[x]

def union(x,y):
    px,py = find(x),find(y)
    res = 0
    if px != py:
        res = size[px] * size[py]
        if rank[px] < rank[py]:
            par[px] = py
            size[py] += size[px]
        else:
            par[py] = px
            size[px] += size[py]
            if rank[px] == rank[py]:
                rank[px] += 1
    return res

for i in range(m-1,-1,-1):
    ans.append(cur)
    x,y = edges[i]
    cur -= union(x,y)
for i in range(m-1,-1,-1):
    print(ans[i])

Measured memory_bytes: 60332
# 与えられた N 以下の素数を列挙して、その N 以下の素数の素因数分解を高速に与えるアルゴリズム。
# 
# 計算量:
#     構築: O(N)　
#     素因数分解: n <= N なる n に対し O(log n)、N < n <= N**2 なる n に対し、O(N / log N)
#
# 
# 参考: https://cp-algorithms.com/algebra/prime-sieve-linear.html (n <= N に対して O(log n) の部分)

N = 10 ** 6 # 10 ** 7 以下だとよさそう。10 ** 7 でPyPy3で構築に500ms程度。
lp = [0] * (N+1)
pr = [] # N 以下の素数のリスト
for i in range(2, N+1):
    if lp[i] == 0:
        lp[i] = i
        pr.append(i)
    for j, p in enumerate(pr):
        if p > lp[i] or i * p > N:
            break
        lp[i * p] = p

def fac_small(n):
    """
    引数 n の素因数分解をして、素因数を昇順に格納したリストを返す。
    ex. fac_small(60) == [2, 2, 3, 5]
    与えられた n について 1 <= n <= N を仮定する。n == 1 では空リストを返す。
    計算量は O(log n) 
    """
    # assert 1 <= n <= N
    ret = []
    while n > 1:
        ret.append(lp[n])
        n //= lp[n]
    return ret

def fac(n):
    """
    引数 n の素因数分解をして、素因数を昇順に格納したリストを返す。
    ex. fac_small(60) == [2, 2, 3, 5]
    与えられた n について 1 <= n <= N**2 を仮定する。n == 1 では空リストを返す。
    計算量は、1 <= n <= N で O(log n)、N < n <= N ** 2 で O(N / log N) 程度。
    """
    # assert 1 <= n <= N**2
    if 1 <= n <= N:
        return fac_small(n)
    else:
        sqr = int(N ** 0.5) + 10
        ret = []
        for p in pr:
            while n % p == 0:
                n //= p
                ret.append(p)
            if n == 1:
                return ret
            elif n <= N:
                return ret + fac_small(n)
            if p > sqr:
                break
        ret.append(n)
        return ret


from collections import defaultdict

N = int(input())
As = list(map(int, input().split()))

divisible_by_prime = defaultdict(list)
divisible_by_prime[1] = []
for A in As:
    for p in set(fac_small(A)):
        divisible_by_prime[p].append(A)

ispair = True
isset = True
ans = max(v for v in map(len, divisible_by_prime.values()))
if ans <= 1:
    print("pairwise coprime")
elif ans < N:
    print("setwise coprime")
else:
    print("not coprime")

Measured memory_bytes: 249580
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

int main()
{
  int n;
  while (cin >> n) {
    if (n == 0)
      break;

    vector<int> w(n);
    for (int i = 0; i < n; ++i)
      cin >> w[i];
    sort(w.begin(), w.end());

    vector<long long int> dp(n, 0);
    for (int i = 1; i < n; ++i)
      dp[i] = dp[i-1] + w[i-1];

    cout << accumulate(dp.begin(), dp.end(), 0LL) << endl;
  }
  return 0;
}

Measured memory_bytes: 0
lst = []
for i in range(5):
    lst.append(int(input()))
lst_f=[]
for i in range(5):
    lst_f.append(lst[i]%10)
while 0 in lst_f:
    lst_f.remove(0)
if len(lst_f) == 0:
    print(sum(lst))
else:
    print(sum(lst)-sum(lst_f)+10*(len(lst_f)-1)+min(lst_f))

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int main(){
    int a,b,c,d,e,f;
    double x,y;
    while(scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f)!=EOF){
        //x = (double)((c*e)-(f*b)) / (double)((a*e)-(b*d));
        y = (double)((c*d)-(a*f)) / (double)((b*d)-(a*e));
        x = double(((double)c-b*y)/a);
        printf("%.3lf %.3lf\n",x,y);
    }
    return 0;
}

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

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

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

    bool f = true;
    for(int i = 0; i < n - 1; i++){
        if(A[i] < A[i + 1]);
        else{
            f = false;
            break;
        }
    }

    if(f){
        cout << "YES" << endl;
        return 0;
    }

    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            vector<int> B(n);
            for(int k = 0; k < n; k++){
                B[k] = A[k];
            }
            swap(B[i], B[j]);
            bool f = true;
            for(int k = n - 1; k >= 1; k--){
                if(B[k] > B[k - 1]);
                else{
                    f = false;
                    break;
                }
            }
            if(f){
                cout << "YES" << endl;
                return 0;
            }
        }
    }

    cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 500000
#define SENTINEL 1000000000
 
int S[MAX], count=0;
 
void merge(int *, int, int, int);
void mergeSort(int *, int, int);
 void mergeSort(int *A, int left, int right)
{
  int mid;
 
  if(left+1 < right)
    {
      mid = (left + right) / 2;
      mergeSort(A, left, mid);
      mergeSort(A, mid, right);
      merge(A, left, mid, right);
    }
}
void merge(int *A, int left, int mid, int right)
{
  int n1 = mid - left;
  int n2 = right - mid;
  int L[n1+1], R[n2+1], i, j, k;
 
  for(i=0; i<n1; i++)
    {
      L[i] = A[left+i];
    }
  for(i=0; i<n2; i++)
    {
      R[i] = A[mid+i];
    }
  L[n1] = SENTINEL;
  R[n2] = SENTINEL;
 
  i=0;
  j=0;
 
  for(k=left; k<right; k++)
    {
      if(L[i] <= R[j])
        {
          A[k] = L[i];
          i = i + 1;
        }
      else
        {
          A[k] = R[j];
          j = j + 1;
        }
      count++;
    }
}
 

int main()
{
  int n, i, left, right;
 
  scanf("%d", &n);
  for(i=0; i<n; i++)
    {
      scanf("%d", &S[i]);
    }
 
  left = 0;
  right = n;
 
  mergeSort(S, left, right);
 
  for(i=0; i<n; i++)
    {

      if(i < n-1)printf("%d ", S[i]);
      else printf("%d\n%d\n", S[i], count);
    }
 
  return 0;
}
 

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

const int N = 200005;
bitset<N> bs;

char s[N];
int main(){
	int n, k;
	n = 100000, k = 1000000000;
	scanf("%d %d", &n, &k);
	scanf("%s", s);
	for(int i = 0; i < n; i++) if(s[i] == 'B') bs.set(i);
	int done = 0;
	int doneb = 0;
	for(; doneb < n + 3 && done < k; done++){
		if(bs[0]){
			doneb++;
			// bs = (~(bs >> 1));
			bs >>= 1;
			bs.flip();
			bs.reset(n - 1);
		} else{
			bs.set(0);
		}
	}
	int rem = done - k;
	if((n == 1 || bs[1]) && (rem & 1)) bs.flip(0);
	for(int i = 0; i < n; i++) printf("%c", (bs[i] ? 'B' : 'A'));
}

Measured memory_bytes: 640
d, g=map(int, input().split())
p=[]
c=[]
for i in range(d):
    p_new, c_new=map(int, input().split())
    p.append(p_new)
    c.append(c_new)
t=2**d
bins=[]
for i in range(t):
    p1=bin(i)[2:]
    p2="0"*(d-len(p1))+p1
    bins.append(p2)
ans=sum(p)
for a in bins:
    point=0
    cnt=0
    for b in range(d):
        if a[b]=="1":
            point+=p[b]*100*(b+1)+c[b]
            cnt+=p[b]
    if point>=g and ans>cnt:
        ans=cnt
    elif point<g:
        for e in range(d-1, -1, -1):
            if a[e]=="0":
                for f in range(p[e]-1):
                    point+=100*(e+1)
                    cnt+=1
                    if point>=g:
                        if ans>cnt: ans=cnt
                        break
                else:
                    continue
                break
            else: pass
print(ans)

Measured memory_bytes: 3064
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn main() {
    let n: i64 = read();
    let root_n: i64 = (n as f64).sqrt() as i64 + 1;
    let mut ans = n-1;
    for i in 2..root_n {
        if n%i == 0 {
            ans = std::cmp::min(ans, (i-1)+(n/i-1));
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
N,Y=map(int,input().split())

Y/=1000

s=0

for i in range(N+1):
    for j in range(N+1-i):
        if i*10+j*5+(N-i-j)==Y:
            s=1
            e=i
            f=j
            g=N-i-j

if s==0:
    print('-1 -1 -1')
else:
    print('{} {} {}'.format(e,f,g))

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

const int MAX = 1e5 + 5;
const int MOD = 1e9 + 7;

#define dbg(a) cout << "-> " << __LINE__ << ": " << #a << " = " << a << endl

int add (int a, int b) {
	return (a + b < MOD) ? (a + b) : (a + b - MOD);
}

int sub (int a, int b) {
	return (a >= b) ? (a - b) : (a - b + MOD);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	vector <int> a(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	vector <int> dp(k + 1, 1), cp(k + 1, 0);
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= k; j++) {
			int l = max(j - a[i], 0), r = j;
			cp[j] = (l > 0) ? sub(dp[r], dp[l - 1]) : dp[r];
			if (j > 0) {
				cp[j] = add(cp[j], cp[j - 1]);
			}
		}
		dp = cp;
	}
	dp[k] = sub(dp[k], ((k > 0) ? dp[k - 1] : 0));
	cout << dp[k] << '\n';
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
signed main(){
  Int a,b,q;
  cin>>a>>b>>q;
  vector<Int> s(a),t(b),x(q);
  for(Int i=0;i<a;i++) cin>>s[i];
  for(Int i=0;i<b;i++) cin>>t[i];
  for(Int i=0;i<q;i++) cin>>x[i];

  const Int INF = 1e14;
  s.emplace(s.begin(),-INF);
  s.emplace(s.begin(),-INF*2);
  s.emplace_back(INF);
  s.emplace_back(INF*2);
  
  t.emplace(t.begin(),-INF);
  t.emplace(t.begin(),-INF*2);
  t.emplace_back(INF);
  t.emplace_back(INF*2);

  for(Int i=0;i<q;i++){
    Int u=lower_bound(s.begin(),s.end(),x[i])-s.begin();
    Int v=lower_bound(t.begin(),t.end(),x[i])-t.begin();
    
    Int res=INF;
    for(Int j=-1;j<=1;j++){
      for(Int k=-1;k<=1;k++){
        chmin(res,abs(s[u+j]-x[i])+abs(t[v+k]-s[u+j]));
        chmin(res,abs(t[v+k]-x[i])+abs(s[u+j]-t[v+k]));
      }
    }
    cout<<res<<"\n";
  }
  cout<<flush;
  return 0;
}


Measured memory_bytes: 3680
#include <iostream>
#include <vector>
#define int long long
using namespace std;
const int NM = 100000+1;
const int MOD = 1e9+7;
int n;
bool visited[NM];
vector<int> graph[NM];
pair<int,int> colors[NM];

pair<int,int> getColor(int i) {
    colors[i].first = colors[i].second = 1;
    visited[i] = true;
    for(int j = 0;j<graph[i].size();j++) {
        if(not visited[graph[i][j]]) {
            auto c = getColor(graph[i][j]);
            colors[i].first = (colors[i].first * c.second)%MOD;
            colors[i].second = (colors[i].second * (c.first + c.second))%MOD;
        }
    }
    return colors[i];
}
void solve() {
    auto ans = getColor(1);
    cout << (ans.first+ans.second)%MOD<<'\n';
}
signed main() {
    cin>>n;
    for(int i=0;i<NM;i++) visited[i] = false;
    for(int i=0;i<NM;i++) colors[i].first = colors[i].second = 0;

    for(int i = 0;i<n-1;i++) {
        int x,y;
        cin>>x>>y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    solve();
//    for(int i =0;i<5;i++)
//        cout << colors[i].first << ' ' << colors[i].second << '\n';
}



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

const int MAXN = 123;
int N;
int A[MAXN];

int get_cost(int x, int y) {
	return (x-y) * (x-y);
}

int go(int v) {
	int sum = 0;
	for (int i = 0; i < N; i++) {
		sum += get_cost(A[i], v);
	}
	return sum;
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];

	int ans = 1e9;
	for (int v = -100; v <= 100; v++) {
		ans = min(ans, go(v));
	}

	cout << ans << '\n';

	return 0;
}


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


int main()
{
	int n;
	cin>>n;
	
	int num_div[n+1]={0};
	
	for(int i=1;i<=n;i++)
	{
		for(int j=i;j<=n;j+=i)
		{
			num_div[j]++;
		}
	}
	
	long long ans=0;
	
	for(int c=1;c<n;c++)
	{
		int rem=n-c;
		
		ans+=num_div[rem];
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 7540
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll; 
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 4e5 + 30, Mod = 1e9 + 7;
const ll SQ = 330;

ll a[N], b[N], n, A, B;

bool ok(ll x) {
	ll C = A - B;
	for (int i = 1; i <= n; i ++) 
		b[i] = a[i] - x * B;
	ll rem = 0;
	for (int i = 1; i <= n; i ++) {
		if (b[i] <= 0) continue;
		rem += (b[i] + C - 1) / C;
	}
	return rem <= x;
}
int main () {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n >> A >> B;
	for (int i = 1; i <= n; i ++) {
		cin >> a[i];
	}
	ll H = 2e9, L = 0, M;
	for (int i = 0; i < 5; i ++) {
		if (ok(i)) {
			return cout << i, 0;
		}
	}
	while (H - L > 1) {
		M = (H + L) >> 1;
		if (ok(M)) H = M;
		else L = M;
	}
	if (ok(L)) H = L;
	cout << H;
	
	
}


Measured memory_bytes: 3072
import collections


def ans(n):
    dist = [10 ** 5] * n
    dist[1] = 1
    d = collections.deque()
    d.append(1)
    while not d.count == 0:
        u = d.popleft()
        if u == 0:
            return dist[u]
        if dist[u] < dist[(u * 10) % n]:
            dist[(u * 10) % n] = dist[u]
            d.appendleft((u * 10) % n)
        if dist[u] < dist[(u + 1) % n]:
            dist[(u + 1) % n] = dist[u] + 1
            d.append((u + 1) % n)

n = int(input())
print(ans(n))


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

int main(){
  string S; cin >> S;
  int N0 = S.size();

  bool flag=true;
  while (true) {
    flag = true;
    rep(i,S.size()-1){
      if (i>=0 && i<S.size()-1 && S[i]!=S[i+1]){
        S.erase(i,2); 
        i-=2;
        flag = false;
      }
    }

    if (S.size()==0 || flag) break;
  }
  cout << N0 - S.size() << endl;
}

 

Measured memory_bytes: 512
def N(d1):
  t1=[0 for i in range(6)]
  t1[0]=d1[1]
  t1[1]=d1[5]
  t1[2]=d1[2]
  t1[3]=d1[3]
  t1[4]=d1[0]
  t1[5]=d1[4]
  return t1
def S(d1):
  t1=[0 for i in range(6)]
  t1[0]=d1[4]
  t1[1]=d1[0]
  t1[2]=d1[2]
  t1[3]=d1[3]
  t1[4]=d1[5]
  t1[5]=d1[1]
  return t1
def E(d1):
  t1=[0 for i in range(6)]
  t1[0]=d1[3]
  t1[1]=d1[1]
  t1[2]=d1[0]
  t1[3]=d1[5]
  t1[4]=d1[4]
  t1[5]=d1[2]
  return t1
def W(d1):
  t1=[0 for i in range(6)]
  t1[0]=d1[2]
  t1[1]=d1[1]
  t1[2]=d1[5]
  t1[3]=d1[0]
  t1[4]=d1[4]
  t1[5]=d1[3]
  return t1

n=int(input())
d=[[0 for i in range(6)] for j in range(n)]
for i in range(n):
  d[i][:]=(int(x) for x in input().split())
  dup=[x for x in set(d[i]) if d[i].count(x)==1]
  if dup:
    if dup[0]==d[i][0]:
      d[i]=E(d[i])
    elif dup[0]==d[i][1]:
      d[i]=N(d[i])
      d[i]=E(d[i])
    elif dup[0]==d[i][3]:
      d[i]=E(d[i])
      d[i]=E(d[i])
    elif dup[0]==d[i][4]:
      d[i]=S(d[i])
      d[i]=E(d[i])
    elif dup[0]==d[i][5]:
      d[i]=W(d[i])

for i in range(1,n):
  for j in range(i-1,-1,-1):
    if d[i][2]==d[j][0]:
      d[j]=E(d[j])
    elif d[i][2]==d[j][1]:
      d[j]=N(d[j])
      d[j]=E(d[j])
    elif d[i][2]==d[j][3]:
      d[j]=E(d[j])
      d[j]=E(d[j])
    elif d[i][2]==d[j][4]:
      d[j]=S(d[j])
      d[j]=E(d[j])
    elif d[i][2]==d[j][5]:
      d[j]=W(d[j])
    elif d[i][2]!=d[j][2]:
      continue

    if d[i]==d[j]:
      print("No")
      exit()

    for k in range(3):
      d[j]=N(d[j])
      if d[i]==d[j]:
        print("No")
        exit()

print("Yes")

      


Measured memory_bytes: 5744
import numpy as np
def main():
    n,s=map(int,input().split())
    A=list(map(int,input().split()))
    dp=np.array([0 for i in range(s+1)])
    dp[0]=1
    for ai in A:
        tmp=dp[:-ai].copy()
        #print(tmp)
        dp*=2
        dp[ai:]+=tmp
        dp%=998244353
    print(dp[s])
    

if __name__=="__main__":
    main()


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

vector<int> sieve;

void make_sieve(int m) {
    const int l = m / 2 + 1;
    vector<bool> s(l, true);
    for (int i = 3, e = sqrt(m); i <= e; i += 2) {
        if (!s[i / 2])
            continue;
        for (int j = i * i / 2; j < l; j += i)
            s[j] = false;
    }
    for (int i = 1; i < l; i++)
        if (s[i])
            sieve.push_back(i * 2 + 1);
}

bool is_prime(int x)
{
    if (x == 2)
        return true;
    else if (x % 2 == 0)
        return false;

    const int e = sqrt(x);
    for (int p : sieve)
        if (p > e)
            return true;
        else if (x % p == 0)
            return false;

    return true;
}

int main()
{
    int n, c = 0, m = 0;
    cin >> n;
    vector<int> d(n);
    for (int &x: d) {
        cin >> x;
        m = max(m, x);
    }

    make_sieve(sqrt(m));

    for (int x: d)
        if (is_prime(x))
            c++;

    cout << c << endl;
}


Measured memory_bytes: 3152
import sys
input = sys.stdin.readline
K,S=map(int,input().split())
ans = []
 
for i in range(K+1):
  s_z = S - i
  if s_z < 0:
    pass
  elif K < s_z:
    if (K + 1) > (s_z - K):
      ans.append(K*2 - s_z + 1)
  else:
    ans.append(s_z + 1)

print(sum(ans))

Measured memory_bytes: 3060
#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() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	int					n;
	int					maxv;
	map<string, int>	M;

	cin >> n;
	rep(i, n)
	{
		string	s;

		cin >> s;
		M[s]++;
	}
	maxv = 0;
	for (auto&& x : M)
		maxv = max(x.second, maxv);
	for (auto&& it = M.begin(); it != M.end(); it++)
	{
		if (it->second == maxv)
			cout << it->first << endl;
	}
}


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

int main(void){
    string a, b;
    cin >> a >> b;
    if (a.size() > b.size()){
        cout << "GREATER" << endl;
    } else if (a.size() < b.size()){
        cout << "LESS" << endl;
    } else{
        for (int i=0; i<a.size(); i++){
            if (a[i] > b[i]){
                cout << "GREATER" << endl;
                return 0;
            } else if (a[i] < b[i]){
                cout << "LESS" << endl;
                return 0;
            }
        }
        cout << "EQUAL" << endl;
    }
    return 0;
}

Measured memory_bytes: 3620
#ifndef LOCAL
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#else
#include <iostream>
#include <iomanip> 
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
#define fix(a) fixed << setprecision(a)
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'



void solve(){
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> m(n);
  forn(i,q){
    int a;
    cin >> a;
    a--;
    m[a]++;
  }
  rep(i,0,n){
    if(k+m[i]-q <= 0){
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
  }
}

int main() {
  ios::sync_with_stdio(false); 
  // cin.tie(0); cout.tie(0);
  int t = 1;
  // cin >> t;
  forn(i, t){
    solve();
  }
}

/* 




*/

Measured memory_bytes: 3688