akhauriyash/Code-Regression huggingface dataset:
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def my_round(a,dig=0):
    p = 10 ** dig
    return (a * p * 2 + 1) // 2 / p

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b): #最小公倍数
    return a/gcd(a,b)*b

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def prime_fact(a): #素因数分解
    sqrt = math.sqrt(a)
    res = []
    i = 2
    if is_prime(a):
        res.append(a)
    else:
        while a!=1:
            while a%i==0:
                res.append(i)
                a //= i
            i += 1
    return res

def main():
    x,y = map(int,input().split())
    if x % y == 0:
        print(-1)
    else:
        print(x)
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 38636
#include<stdio.h>

int main(){

    int a,b,i,j;

    for(i=0;i<3000;i++){
        scanf("%d %d",&a,&b);
        if((a==0)&&(b==0)) break;
        if(a>b){
            j = a;
            a = b;
            b = j;
        }
        printf("%d %d\n",a,b);


    }

        return 0;


}



Measured memory_bytes: 1996
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000100;
int stk[maxn], he, tp, neg;
void push(int v){
	stk[tp++] = v ^ neg;
}
int seek(){
	return stk[he] ^ neg;
}
void pop(){
	he++;
}
int main(){
	int n, k; cin >> n >> k;
	string s; cin >> s;
	for(int i = 0; i < n; i++){
		if(s[i] == 'A') push(0);
		else push(1);
	}
	auto op = [&](){
		if(seek() == 0){
			stk[he] ^= 1;
		} else {
			pop();
			neg ^= 1;
			push(0);
		}
	};
	int sm = min(3 * n, k);
	for(int i = 0; i < sm; k--, i++){
		op();
	}	
	k %= 2;
	if(k){
		op();
	}
	for(int i = 0; i < n; i++){
		cout << char('A' + seek());
		pop();
	}
	cout << endl;
	return 0;
}


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

using namespace std;

int main() {
  int N;
  cin >> N;
  
  vector<int> h(N);
  for (int i = 0; i< N; i++) {
    cin >> h[i];
  }
  
  int maxHeight = 0;
  for (int i = 0; i < N; i++) {
    maxHeight = max(maxHeight, h[i]);
  }
  
  int op = 0;
  for (int i = 0; i < maxHeight; i++) {
    bool prev = false;
    for (int j = 0; j < N; j++) {
      if (h[j] > 0) {
        h[j]--;
        if (!prev) {
          prev = true;
          op++;
        }
      } else {
        prev = false;
      }
    }
  }
  
  cout << op << endl;
  
  return 0;
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
int main() {
    int N, K; cin >> N >> K;

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

    vector<int> divs;
    for(ll i=1; i*i<=sum; i++) {
        if(sum % i == 0) {
            divs.emplace_back(i);
            divs.emplace_back(sum / i);
        }
    }

    sort(divs.rbegin(), divs.rend());
    for(auto d : divs) {
        vector<int> B;
        int s = 0;
        for(int i=0; i<N; i++) {
            if(A[i] % d == 0) continue;
            B.emplace_back(A[i] % d);
            s += A[i] % d;
        }

        int M = B.size();
        if(s > d * M - s) {
            for(auto &e : B) e = d - e;
            s = d * M - s;
        }

        sort(B.rbegin(), B.rend());
        int s1 = s, s2 = 0;
        for(auto e : B) {
            if(s1 == s2) break;
            s1 -= e;
            s2 += d - e;
        }

        if(s1 <= K) {
            cout << d << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>


int main(){
    int point[2][4] = {{0},{0}}, i, j, in;
    
    for (i = 0; i < 2; i++) {
        for (j = 0; j < 10; j++) {
            scanf("%d", &in);
            if (in > point[i][0]) {
                point[i][2] = point[i][1];
                point[i][1] = point[i][0];
                point[i][0] = in;
            }else if(in > point[i][1]){
                point[i][2] = point[i][1];
                point[i][1] = in;
            }else if(in > point[i][2]){
                point[i][2] = in;
            }

        }
    }
    
    printf("%d %d\n", point[0][0] + point[0][1] + point[0][2], point[1][0] + point[1][1] + point[1][2]);
    return 0;
}

Measured memory_bytes: 596
n,x,y=map(int,input().split())
l=[0]*(n-1)
for i in range(n-1):
  for j in range(i+1,n):
    a=min(j-i, abs(x-i-1)+abs(y-j-1)+1)
    l[a-1]+=1
for i in range(n-1):
  print(l[i])

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
int s[100100],n,ans;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",&s[i]);
	for(int i=1<<29;i;i>>=1){
		bool flag=0;
		for(int j=1;j<=n;++j)if(s[j]>i){
			if(s[j]==i*2)flag=1;
			else if(!flag)flag=1;
			else flag=0,ans++;
			s[j]=i;
		} else ans+=flag,flag=0;
		if(flag)ans++;
	}
	printf("%d",ans);
	
}

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

int main() {
    int d = 100000;
    int n;
    cin >> n;
    while(n-- > 0) {
        d *= 1.05;
        if(d % 1000) {
            d = (d / 1000 + 1) * 1000;
        }
    }
        cout << d << endl;
    return 0;
}


Measured memory_bytes: 3072
n, y = map(int,input().split())

ans = 0
flag = False
for a in range(n+1):
    for b in range(n+1-a):
            if y == 10000*a+5000*b+1000*(n-a-b):
                print(a,b,n-a-b)
                ans = 100
                flag = True
            else:
                continue
    if flag:
      break
                
if ans == 0:
    print(-1,-1,-1)

Measured memory_bytes: 3064
def resolve():
    l, r = list(map(int, input().split()))
    if r-l >=2018:
        print(0)
    else:
        ans = 2020
        for i in range(l,r):
            for j in range(l+1,r+1):
                ans = min(ans, (i*j) % 2019)
        print(ans)
resolve()

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

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

	int B, prev; cin >> B;
	prev = B;
	long long ans = prev;
	for(int i=1; i<N-1; ++i){
		cin >> B;

		ans += min(B, prev);

		prev = B;
	}
	ans += B;

	cout << ans << endl;
}


Measured memory_bytes: 256
a,b,k = map(int,input().split())

result = set()

for i in range(a,min(a+k,b+1)):
    result.add(i)
for j in range(max(a,b-k+1),b+1):
    result.add(j)

for k in sorted(list(result)):
    print(k)
    

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<vector<int>> g(n, vector<int>(n, 0));
	while(m--) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a][b] = g[b][a] = true;
	}
	vector<int> a(n);
	iota(a.begin(), a.end(), 0);
	int ans = 0;
	do {
		bool can = true;
		for(int i = 0; i < a.size() - 1; i++) {
				if(!g[a[i]][a[i + 1]]) can = false;
		}
		if(can) ans++;
	} while(next_permutation(a.begin() + 1, a.end()));
	cout << ans << endl;
	return 0;	
}


Measured memory_bytes: 256
#include"iostream"
using namespace std;

int main() {
	char a[100], b[100], c[100];
	int d,ai,bi,ci;
	char no[100] = "NO", yes[100] = "YES";

	cin >> a >> b >> c;

	for (d = 0; d < 101; d++) {
		if (a[d] == '\0'){
			ai = d - 1;
			break;
		}
	}
	for (d = 0; d < 101; d++) {
		if (b[d] == '\0') {
			bi = d - 1;
			break;
		}
	}

	if (a[ai] != b[0]) {
		cout << no << endl;
	}
	else if (b[bi] != c[0]) {
		cout << no << endl;
	}
	else {
		cout << yes << endl;
	}

	return 0;
}

Measured memory_bytes: 256
// Ai < Bi < Ci
// jmax = max_j A[j] < Bi
// kmin = min_k Bi < C[k]
// (jmax + 1) * (n - kmin + 1)

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

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

  long long ans = 0;
  for (int i = 0; i < n; i++) {
    long long j = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
    long long k = upper_bound(c.begin(), c.end(), b[i]) - c.begin();
    ans += j * (n - k);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll INF = (1LL << 55);

int main(){ 
  int n, m;
  cin >> n >> m;
  string s;
  cin >> s;
  vector<int> res;
  reverse(s.begin(), s.end());
  int cnt = -1;
  int prev = 0;
  for (int i = 0; i < n+1; i++) {
    int ng = s[i] - '0';
    cnt++;
    if (cnt <= m && !ng) prev = cnt;
    if (cnt == m) {
      if (prev == 0) {
        cout << -1 << endl;
        return 0;
      }
      res.emplace_back(prev);
      cnt -= prev;
      prev = 0;
    }
  }
  if (cnt != 0) res.emplace_back(cnt);
  reverse(res.begin(), res.end());
  for (auto e : res) cout << e << " ";
  cout << endl;
  return 0;
} 

Measured memory_bytes: 1144
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;
int main(){
    int a,b,c;
    cin >>a>>b>>c;
    cout<<max({a,b,c})-min({a,b,c})<<endl;
}

Measured memory_bytes: 256
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"3
4980
7980
6980"# => r#"15950"#,
r#"4
4320
4320
4320
4320"# => r#"15120"#,
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        n: usize,
        mut p: [usize; n],
    }

    p.sort();
    p[n-1] /= 2;
    p.into_iter().sum::<usize>().to_string()
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n , w  ;
vector<int>v1 ,v2;
ll INF = 1e18;
ll dp[110][100000 + 10];
ll dfs(ll i , ll curr){
    if(curr > w)return -INF;
    if(i >= n)return 0;
    if(dp[i][curr] != -1)return dp[i][curr];
    ll c1 = dfs(i+1,curr);
    ll c2 = v2[i] + dfs(i+1,curr+v1[i]);

    return dp[i][curr] = max(c1,c2);
}
int main(){
    cin>>n>>w;
    v1.resize(n);
    v2.resize(n);
    memset(dp , -1 , sizeof dp);
    for(int i=0;i<n;i++){
        cin>>v1[i]>>v2[i];
    }
    cout<<dfs(0,0)<<endl;
    return 0;
}


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

int main() {
	
	double_t N;
	double L;
	cin >> N;
	vector<int> vec(N);
	for (int i = 0; i < N; i++) {
		cin >> vec.at(i);
	}

	L = 0;
	for (int i = 0; i < N; i++) {
			L += 1.0000 / vec.at(i);
		}
	double ans = 1.0000 / L;
	cout << std::fixed << ans << endl;
	// cout << std::fixed << std::setprecision(14) << ans << endl;
			
	}
	

Measured memory_bytes: 256
n,k=map(int,input().split())
p=list(map(int,input().split()))
s=[]
for i in p:
  t=(1+i)
  s.append(t)
  
t=[0,]
for i in range(n):
  u=t[i]+s[i]
  t.append(u)

ans=0
for i in range(n-k+1):
  ans=max(ans,t[i+k]-t[i])
  

print('{:.10f}'.format(ans/2))

Measured memory_bytes: 78984
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

  int n,k;cin>>n>>k;
  int a[3];cin>>a[0]>>a[1]>>a[2];
  string t;cin>>t;

  int te[n];
  REP(i,n){
    if(t[i] == 'r'){
      te[i] = 2;
    }else if(t[i] == 's'){
      te[i] = 0;
    }else{
      te[i] = 1;
    }
  }

  ll ans = 0;

  REP(i,n){
    int score = a[te[i]];
    if(i>=k){
      if(te[i] == te[i-k]){
        te[i] = -1;
        score = 0;
      }
    }
    ans += score;
  }

  cout<<ans<<endl;

 

  return 0;
}


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

typedef struct{
	int tID;
	int pID;
	int time;
	int judge;
} Data;

typedef struct{
	int team;
	int correct;
	int bad[10];
	int pena;
} Result;

int cmp(const void* a,const void* b){
	Result *x,*y;
	x=(Result*) a;
	y=(Result*) b;
	if(x->correct<y->correct){
		return 1;
	}else if(x->correct==y->correct){
		if(x->pena>y->pena){
			return 1;
		}else if(x->pena==y->pena){
			if(x->team>y->team){
				return 1;
			}
		}
	}
	return -1;
}

int main(void){
	int t,p,r,i,j;
	char tmp[8];
	Data data[500];
	Result team[50];
	while(scanf("%d %d %d",&t,&p,&r)!=0 && (t!=0 || p!=0 || r!=0)){
		for(i=0;i<t;i++){
			team[i].team=0;
			team[i].correct=0;
			for(j=0;j<p;j++){
				team[i].bad[j]=0;
			}
			team[i].pena=0;
		}
		for(i=0;i<r;i++){
			scanf("%d %d %d %s",&data[i].tID,&data[i].pID,&data[i].time,tmp);
			if(strcmp(tmp,"CORRECT")==0){
				data[i].judge=1;
			}else{
				data[i].judge=0;
			}
		}
		
		/*for(i=0;i<r;i++){
			printf("%d %d %d %d\n",data[i].tID,data[i].pID,data[i].time,data[i].judge);
		}*/
	
		for(i=0;i<t;i++){
			team[i].team=i;
		}
		for(i=0;i<r;i++){
			if(data[i].judge==1){
				team[data[i].tID-1].correct++;
				team[data[i].tID-1].pena+=(team[data[i].tID-1].bad[data[i].pID-1]*1200+data[i].time);
			}else{
				team[data[i].tID-1].bad[data[i].pID-1]++;
			}
		}
		qsort(team,t,sizeof(Result),cmp);
		for(i=0;i<t;i++){
			printf("%d %d %d\n",team[i].team+1,team[i].correct,team[i].pena);
		}
	}
	return 0;
}

Measured memory_bytes: 616
as = []
bingo = []

3.times{
	a = gets.split.map(&:to_i)
	as << a
	temp = {}
	a.each{ |aa|
		temp[aa] = false
	}
	bingo << temp
}

3.times{ |i|
	temp = {}
	temp[as[0][i]] = false
	temp[as[1][i]] = false
	temp[as[2][i]] = false
	bingo << temp
}

temp = {}
temp[as[0][0]] = false
temp[as[1][1]] = false
temp[as[2][2]] = false
bingo << temp

temp = {}
temp[as[2][0]] = false
temp[as[1][1]] = false
temp[as[0][2]] = false
bingo << temp

n = gets.to_i

n.times{
	b = gets.to_i
	bingo.each{ |bingo_e|
		if bingo_e[b] == false then
			bingo_e[b] = true
		end
	}
}

if bingo.select{ |b| b.values == [true,true,true]}.size > 0 then
	puts 'Yes'
else
	puts 'No'
end

Measured memory_bytes: 1788
N,M,X=map(int,input().split())
B=[list(map(int,input().split())) for _ in range(N)]
inf=(10**5)*12+1
ans=inf
for i in range(1,2**N):
  tmp=[0]*M
  c=0
  for j in range(N):
    if i>>j&1:
      for k in range(M):
        tmp[k]+=B[j][k+1]
      c+=B[j][0]
  if len([i for i in tmp if i>=X])==M:
    ans=min(c,ans)
print(ans if ans<inf else -1)

Measured memory_bytes: 9072
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		ABC056CSolve solve = new ABC056CSolve();
		solve.main();
	}
}

class ABC056CSolve {
	
	int X;
	
	ABC056CSolve() {
		Scanner cin = new Scanner(System.in);
		this.X = cin.nextInt();
	}
	
	void main() {
		
		int time = 0;
		int position = 0;
		while (position < X) {
			time++;
			position = (time*(time + 1)) / 2;			
		}
		System.out.println(time);
	}
	
}


Measured memory_bytes: 22484
#include <stdio.h> 

int main(){
	int a;
	int b;
	int c;

	char buf[10];
	fgets(buf,10,stdin);
	sscanf(buf,"%d %d %d" ,&a,&b,&c);

	if(b-a==c-b){
	   printf("YES\n");
	}else{
	   printf("NO\n");
	}
	return 0;
}

	


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,a[10005],b[10005],c[10005],x;
long long s;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
	cin>>a[i];
	}
	for(int i=1;i<=n;i++)
	{
	cin>>b[i];
	}
	for(int i=1;i<=n;i++)
	{
		if(a[i]>b[i])s-=(a[i]-b[i]);
		if(a[i]<b[i])s+=(b[i]-a[i])/2;
	} 	
	if(s>=0)cout<<"Yes"<<endl;
	else cout<<"No"<<endl; 
	return 0;
 } 

Measured memory_bytes: 384
#include<stdio.h>

typedef struct Card{
  char mark;
  int number;
} card;

int main(){
  int num,i,j,min,flag,check=0;
  card CA_1[36],CA_2[36],CA_3[36],tmp;
  scanf("%d",&num);
  for(i=0;i<num;i++)scanf(" %c%d",&CA_1[i].mark,&CA_1[i].number);
  for(i=0;i<num;i++)CA_2[i]=CA_1[i];
  for(i=0;i<num;i++)CA_3[i]=CA_1[i];

  /*BubbleSort*/
  flag=1;
  while(flag){
    flag=0;
    for(j=num-1;j>=1;j--){
      if(CA_1[j].number<CA_1[j-1].number){
        tmp=CA_1[j];
        CA_1[j]=CA_1[j-1];
        CA_1[j-1]=tmp;
        flag=1;
      }
    }
  }

  /*BubblePrint*/
  for(i=0;i<num-1;i++)printf("%c%d ",CA_1[i].mark,CA_1[i].number);
  printf("%c%d\n",CA_1[i].mark,CA_1[i].number);
  puts("Stable");

  /*SelectionSort*/
  for(i=0;i<num-1;i++){
    min=i;
    for(j=i;j<num;j++){
      if(CA_2[j].number<CA_2[min].number){
        min=j;
      }
    }
    if(CA_2[i].number!=CA_2[min].number){
      tmp=CA_2[i];
      CA_2[i]=CA_2[min];
      CA_2[min]=tmp;
    }
  }

  /*SelectionPrint*/
  for(i=0;i<num-1;i++)printf("%c%d ",CA_2[i].mark,CA_2[i].number);
  printf("%c%d\n",CA_2[i].mark,CA_2[i].number);
  for(i=0;i<=num-1;i++){
    if(CA_2[i].number==CA_1[i].number&&CA_2[i].mark!=CA_1[i].mark){
      check=1;
    }
  }
  if(check==1)puts("Not stable");
  else puts("Stable");
  return 0;
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define each(i, c) for (auto& (i) : (c))

using namespace std;
typedef long long int lli;
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }

int main() {
    int n, t;
    cin >> n >> t;
    const int inf = 1001;
    int minc = inf;
    rep(i,n) {
        int rc, rt;
        cin >> rc >> rt;
        if (rt <= t && rc < minc) {
            minc = rc;
        }
    }
    if (minc != inf) {
        cout << minc << endl;
    } else {
        puts("TLE");
    }
    return 0;
}

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

int main(){
  int a,b,k;
  cin >> a >> b >> k;
  
  int res = 0;
  int c = 0;
  
  for(int i = min({a,b}); i > 0; --i){
    if(a % i == 0 && b % i == 0){
      c += 1;
    }
    if(c == k){
      res = i;
      break;
    }
  }
  
  cout << res << endl;
}

Measured memory_bytes: 3640
from collections import Counter


def resolve():
    n = int(input())
    s = input()
    c = Counter(s)
    ans = 1
    mod = 10 ** 9 + 7
    for v in c.values():
        ans *= v + 1
        ans %= mod
    print(ans - 1)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 3444
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define maxn 100010
#define mod 1000000007
#define mp(x,y) make_pair(x,y)
#define se second
#define fi first
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
typedef unsigned long long ull;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int f[20][(1<<16)+5];
int n,m,N;
int a[20];
int fac[(1<<16)+5],inv[(1<<16)+5];
int quick_pow(int x,int p)
{
    int an=1,po=x;
    while(p)
    {
        if(p&1)  an=1ll*an*po%mod;
        po=1ll*po*po%mod;
        p>>=1;
    }
    return an;
}
int C(int x,int y)
{
    if(x<0||y<0||x<y)  return 0;
    return 1ll*fac[x]*inv[y]%mod*inv[x-y]%mod;
}
int mix(int x,int y){return (x+y>=mod)?x+y-mod:x+y;}
void add(int &x,int y){x=mix(x,y);}
int siz[(1<<16)+5];
int lb(int x)
{
    return x&(-x);
}
int main()
{
    n=read();m=read();N=(1<<n);
    for(int i=1;i<=m;i++)  a[i]=read();
    fac[0]=1;
    for(int i=1;i<=N;i++)  fac[i]=1ll*fac[i-1]*i%mod;
    inv[N]=quick_pow(fac[N],mod-2);
    for(int i=N-1;i>=0;i--)  inv[i]=1ll*inv[i+1]*(i+1)%mod;
    
    f[m+1][0]=1;
    for(int i=m;i>=1;i--)
    {
        for(int j=0;j<(1<<n);j++)
        {
            if(!f[i+1][j])  continue;
            add(f[i][j],f[i+1][j]);
            for(int k=0;k<n;k++)
            {
                if((j>>k)&1)  continue;
                int x=(N-a[i]+1)-j;
                f[i][j|(1<<k)]=(f[i][j|(1<<k)]+1ll*f[i+1][j]*C(x-1,(1<<k)-1)%mod*fac[(1<<k)])%mod;
            }
        }
    }
    
    for(int i=0;i<(1<<n);i++)  f[1][i]=1ll*f[1][i]*fac[N-i-1]%mod;
    for(int i=1;i<(1<<n);i++)  siz[i]=siz[i-lb(i)]+1;
    int ans=0;
    for(int i=0;i<(1<<n);i++)
    {
        if(siz[i]&1)  add(ans,mod-f[1][i]);
        else           add(ans,f[1][i]);
    }
    ans=1ll*ans*(1<<n)%mod;
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

#define FOR(i,n)	for(int i=0;i<(int)n;i++)
#define FOB(i,n)	for(int i=n;i>=1;i--)
#define MP(x,y)	make_pair((x),(y))
#define ii pair<int, int>
#define lli long long int
#define ld long double
#define ulli unsigned long long int
#define lili pair<lli, lli>
#ifdef EBUG
#define DBG	if(1)
#else
#define DBG	if(0)
#endif
#define SIZE(x) int(x.size())
const int infinity = 2000000999 / 2;
const long long int inff = 4000000000000000999;

typedef complex<long double> point;

template<class T>
T get() {
    T a;
    cin >> a;
    return a;
}

template <class T, class U>
ostream& operator<<(ostream& out, const pair<T, U> &par) {
    out << "[" << par.first << ";" << par.second << "]";
    return out;
}

template <class T>
ostream& operator<<(ostream& out, const set<T> &cont) {
    out << "{";
    for (const auto &x:cont) out << x << ", ";
    out << "}";
    return out;
}

template <class T, class U>
ostream& operator<<(ostream& out, const map<T,U> &cont) {
    out << "{";
    for (const auto &x:cont) out << x << ", ";
    out << "}"; return out;
}

template <class T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  FOR(i, v.size()){
    if(i) out << " ";
    out << v[i];
  }
  out << endl;
  return out;
}

bool ccw(point p, point a, point b) {
  if((conj(a - p) * (b - p)).imag() <= 0) return false;
  else return true;
}

int main() {
    cin.sync_with_stdio(false);
    cout.sync_with_stdio(false);
    int n = get<int>();
    int x = get<int>();
    vector<int> A;
    FOR(i, n) A.push_back(get<int>());
    sort(A.begin(), A.end());
    int i = 0;
    while(i < n && A[i] <= x) {
        x -= A[i];
        i ++;
    }
    if(i == n && x) i --;
    cout << i << endl;
}


Measured memory_bytes: 256
h, w = map(int, input().split())


table = {}
for i in range(h):
    a = input()
    for c in a:
        if c not in table:
            table[c] = 1
        else:
            table[c] += 1

mod0 = []
mod1 = []
mod2 = []
mod3 = []
for key, value in table.items():
    if value % 4 == 0:
        mod0.append(key)
    elif value % 4 == 1:
        mod1.append(key)
    elif value % 4 == 2:
        mod2.append(key)
    else:
        mod3.append(key)


if w % 2 == 0 and h % 2 == 0:
    if len(mod1) > 0 or len(mod2) > 0 or len(mod3) > 0:
        print("No")
    else:
        print("Yes")

elif w % 2 == 0 or h % 2 == 0:
    if h % 2 == 0:
        w, h = h, w

    if w // 2 < len(mod2):
        print("No")
    elif len(mod1) > 0 or len(mod3) > 0:
        print("No")
    else:
        print("Yes")
else:
    if len(mod1) == 1 and len(mod2) <= (h + w - 1) // 2:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 65264
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=b-1;i>=a;i--)

int main(){
  string s;
  cin >> s;
  ll n = s.size();
  vector<ll> a(n, 1);
  rep(i, 0, n - 1) if(s[i] == 'R' && s[i + 1] == 'R') {
    a[i + 2] += a[i];
    a[i] = 0;
  }
  rrep(i, 1, n) if(s[i] == 'L' && s[i - 1] == 'L') {
    a[i - 2] += a[i];
    a[i] = 0;
  }
  rep(i, 0, n) cout << a[i] << " \n"[i + 1 == n];
}

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

using namespace std;

int main(){
  int H,W;
  vector <int> a;
  vector < vector <int> > c;

  c = vector < vector <int> > (100,vector <int> (100,0));

  int N,b;
  cin >> H >> W;

 
  cin >> N;

  for(int i = 0;i < N;i++){
    cin >> b;
    a.push_back(b);
  }
  int he = 0,we = 0,flag = 1;
  for(int i = 0;i< N;i++){
    for(int j = 0;j < a[i];j++){
      if(we < W && we >= 0){
	c[he][we] = i+1;
	if(flag == 1){
	  we++;
	}
	else if(flag == -1){
	  we--;
	}
      }
      else{
	he++;
	if(we >= 0){
	  flag = -1;
	  we--;
	  c[he][we] = i+1;
	  we--;
	}
	else if(we < 0){
	  flag = 1;
	  we++;
	  c[he][we] = i+1;
	  we++;
	}
	
      }
    }
  }

  for(int i = 0;i < H;i++){
    for(int j = 0;j < W;j++){
      cout << c[i][j] << " ";
    }
    cout << endl;
  }
  
}


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

#define ll long long int
#define mp make_pair 
#define pb push_back
#define fast  ios_base::sync_with_stdio(false);cin.tie(0);
#define ff first
#define ss second
#define ll_MAX 922337203685477999
#define endl "\n"
inline ll absdiff(ll a,ll b) {return (a>b)?a-b:b-a;}
const ll MOD = 1000000007;
ll fast_expo(ll x,ll p){if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
ll gcd(ll a,ll b){if(a==0||b==0) return a+b;  else return gcd(b%a,a); }

int main()
{
    // freopen("input.txt","r",stdin);
    // freopen("output.txt", "w", stdout);

    ll t_c;t_c = 1;
    // cin >> t_c;
    for (ll ti = 0; ti < t_c; ++ti)
    {  
        ll val,k; cin >> val >> k;
        ll ans = 0;
        while(val){
            ans++;
            val = val/k;
        }
        cout << ans;
    }
    return 0;       
}       

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod (1000000007)
#define int long
main(){
  int n;
  string s;
  cin>>s;
  n=s.size();
  vector<vector<int>> dp(n,vector<int>(13,0));
  if(s[0]=='?')for(int i=0;i<10;++i)dp[0][i]=1;
  else dp[0][s[0]-'0']=1;
  for(int i=1;i<n;++i){
    if(s[i]=='?')for(int j=0;j<10;++j)for(int k=0;k<13;++k)dp[i][(k*10+j)%13]+=dp[i-1][k];
    else for(int k=0;k<13;++k)dp[i][(k*10+s[i]-'0')%13]+=dp[i-1][k];
    for(int j=0;j<13;++j)dp[i][j]%=mod;
  }
  cout<<dp[n-1][5]<<endl;
}

Measured memory_bytes: 13696
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 2e5 + 10, mod = 1e9 + 7;

ll c[N], dp[N], sum[N];

int main() {
	fast_cin();
	int n; cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> c[i];
	}
	sum[c[1]] = 1;
	dp[1] = 1;
	for (int i = 2; i <= n; ++i) {
		if (c[i - 1] != c[i]) {
			sum[c[i]] += dp[i - 1];
			sum[c[i]] %= mod;
		}
		dp[i] = sum[c[i]];
	}
	cout << dp[n] << endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define print(ele) cout << (ele) << endl
#define print10(ele) cout << fixed << setprecision(10) << (ele) << endl

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

int main() {
  ivec a(5);
  int k;
  REP(i, 5) cin >> a[i];
  cin >> k;
  bool ok = true;
  REP(i, 5) {
    REP(j, 5) {
      if (i == j) continue;
      if (max(a[i], a[j]) - min(a[i], a[j]) > k) ok = false;
    }
  }
  print(ok ? "Yay!" : ":(");
  return 0;
}

Measured memory_bytes: 256
N, K = gets.chomp.split.map(&:to_i)
A = gets.chomp.split.map(&:to_i)

posi = []
nega = []
zeros = 0
A.each do |ai|
  if ai < 0
    nega << ai
  elsif ai > 0
    posi << ai
  else
    zeros += 1
  end
end

posi.sort!
nega.sort!.reverse!

posi_size = posi.size
nega_size = nega.size

nega_pairs = posi_size * nega_size
zero_pairs = zeros * (zeros - 1) / 2 + zeros * (N - zeros)

inf = 10**18+1

ans = (-inf..inf).bsearch do |mid|
  
  cnt = 0
  
  cnt += zero_pairs if mid >= 0

  if mid > 0
    cnt += nega_pairs
    [posi, nega].each do |a|
      l = 0
      r = a.size - 1
      while l < r
        r -= 1 while l < r && a[l] * a[r] > mid
        cnt += r - l
        l += 1
      end
    end
  else
    r = nega_size - 1
    posi_size.times do |l|
      r -= 1 while(r >= 0 && posi[l] * nega[r] <= mid)
      cnt += nega_size - r - 1
    end
  end

  cnt >= K
end

puts ans


Measured memory_bytes: 20616
#include<stdio.h>

int main(){
	int size=0;
	int min=0,max=0;
	int array[200000]={};
	scanf("%d",&size);
	scanf("%d",&min);
	for(int i=1; i<size; i++){
		scanf("%d",&array[i]);
		if(i==1){
			max=array[i]-min;
		}else if(array[i]-min>max){
			max=array[i]-min;
		}
		if(min>array[i]){
			min=array[i];
		}
	}
	printf("%d\n",max);
	return 0;
}



Measured memory_bytes: 3536
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑


int main() {
	int n, k[15];
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> k[i];
	}
	sort(k, k + n);
	reverse(k, k + n);
	int ans = k[0] / 2;
	for (int i = 1; i < n; ++i) {
		ans += k[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include "vector"
#include "set"
#include "map"
#include "unordered_set"
#include "unordered_map"
#include "string"
#include "iostream"
#include "algorithm"
#include "queue"

using namespace std;

#define ll long long
#define INF 2e9
#define INF2 4611686018427387904
//#define MOD 1000000007
#define MOD 998244353
#define MAX_SIZE 1000000000

typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) { bool first = true; for (const auto& j: v) { if (!first) { os << " "; } first = false; os <<j; } os << "\n"; return os; }
template<typename T>
istream& operator>>(istream& is, vector<T>& v) { for (auto& elem : v) { is >> elem; } return is; }

vector<ll> f;
void set_f(int n) { f.resize(n+1); f[0] = 1; for (int i=1; i<= n; i++) { f[i] = (f[i-1] * i) % MOD;} }
ll nod(ll a, ll b) { if (b == 0) { return a; } else { return nod(b, a % b); } }
ll pw(ll x, ll n, ll m=MOD) { if (n == 0) { return 1;} if (n%2 == 0) { return pw((x*x) % m, n/2, m); } return (pw(x, n-1, m) * x) % m; }
ll dv(ll a, ll b) { return (a * pw(b, MOD - 2)) % MOD; }
ll c_n_k(int n, int k) { if (k > n) { return 0; } if (k < 0) { return 0; } return dv(dv(f[n], f[k]), f[n-k]); }

struct v {
    int a;
    int b;
    int c;
    int d;
};

bool comp(const v& x, const v& y) {
    return x.d > y.d;
}

void solve() {
    int n, m, q;
    cin >> n >> m >> q;

    vector<v> x(q);
    for (int i=0; i<q; i++) {
        cin >> x[i].a >> x[i].b >> x[i].c >> x[i].d;
        x[i].a--;
        x[i].b--;
    }
    //sort(x.begin(), x.end(), comp);

    vi y(n, 1);

    int ma = 0;
    while (true) {
        int cur = 0;
        for (int j=0; j<q; j++) {
            int a = x[j].a;
            int b = x[j].b;
            int c = x[j].c;
            int d = x[j].d;

            if (y[b] - y[a] == c) {
                cur += d;
            }
        }
        ma = max(ma, cur);

        int i=n-1;
        while (i >= 0 && y[i] >= m) {
            i--;
        }

        if (i < 0) {
            break;
        }

        y[i]++;
        for (int ii=i+1; ii<n; ii++) {
            y[ii] = y[i];
        }
    }

    cout << ma;
}


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

    if (0) {
        int tests;
        cin >> tests;
        for (int t = 1; t <= tests; t++) {
            //cout << "Case #" << t << ": ";
            solve();
            //cout << "\n";
        }
    } else {
        solve();
        cout << endl;
    }

    return 0;
}

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

// macros
#define overload_rep(va_0, va_1, va_2, name, ...) name
#define rep_0(i, n) for(int i = 0; i < (n); ++i)
#define rep_1(i, x, y) for(int i = (x); i <= (y); ++i)
#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0)(__VA_ARGS__)
#define all(a) a.begin(), a.end()
#ifndef STOP_DEBUG
#define debug(...)\
    do { cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_cerr(__VA_ARGS__); cerr << noboolalpha; } while (0)
#else
#define debug(...)
#endif

// functions
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; }
void debug_cerr(){ cerr << '\n'; }
template<class Head, class... Tail>
void debug_cerr(Head head, Tail... tail){
    cerr << ' ' << head;
    debug_cerr(tail...);
}

// cin/cout setup
struct IoSetup{
    IoSetup(){
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} iosetup;

// libraries

// declarations

// solve
int main(){

    int N;
    cin >> N;
    string S;
    cin >> S;

    for(char &c : S){
        int t = c - 'A';
        t += N;
        t %= 26;
        c = 'A' + t;
    }

    cout << S << '\n';
    return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

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

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

    LL ans_x = -1;
    LL ans_y = -1;
    LL ans_h = -1;

    bool end = true;

    for(int i = 0; i < 101 && end; i++){
        for(int j = 0; j < 101 && end; j++){
            bool frag = true;
            LL tmp = -1;
            for(int k = 0; k < n; k++){
                if(tmp < 0){
                    tmp = h[k] + abs((LL)(i)-x[k]) + abs((LL)(j)-y[k]);
                }else if(tmp != h[k] + abs((LL)(i)-x[k]) + abs((LL)(j)-y[k])){
                    frag = false;
                }
            }
            if(frag && tmp > 0){
                ans_x = i;
                ans_y = j;
                ans_h = tmp;
                end = false;
            }
        }
    }

    for(int i = 0; i < 101 && end; i++){
        for(int j = 0; j < 101 && end; j++){
            bool frag = true;
            LL tmp = -1;
            for(int k = 0; k < n; k++){
                if(tmp < 0 && h[k] != 0){
                    tmp = h[k] + abs((LL)(i)-x[k]) + abs((LL)(j)-y[k]);
                }else if(tmp != h[k] + abs((LL)(i)-x[k]) + abs((LL)(j)-y[k]) && h[k] != 0){
                    frag = false;
                }
            }
            if(frag && tmp > 0){
                ans_x = i;
                ans_y = j;
                ans_h = tmp;
                end = false;
            }
        }
    }

    cout << ans_x << " ";
    cout << ans_y << " ";
    cout << ans_h << endl;
    
    return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <algorithm>
//#include <cstdio>
//#include <functional>
#include <iostream>
//#include <cfloat>
//#include <climits>
//#include <cstdlib>
//#include <cstring>
#include <cmath>
//#include <map>
//#include <queue>
//#include <set>
//#include <sstream>
//#include <stack>
//#include <string>
//#include <time.h>
#include <vector>
//#include <random>
//#include <unordered_set>
//#include <complex>
//#include <string.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define LL long long
#define pii pair<int,int>

using namespace std;
const int MOD=1e5+10;

int main()
{
	int n,a,b,h[MOD];
	 
	cin>>n>>a>>b;
	int hi=0;
	rep(i,n) {
		cin>>h[i];
		hi=max(hi,h[i]);
	}
	
	int lb=(hi+a-1)/a;
	int ub=(hi+b-1)/b;
	
	while(lb<ub) {
		LL mid=(lb+ub)/2;
		LL count=0; 
		rep(i,n){
			LL temp=h[i]-(mid*b); //按mid轮*b先消 
			if(temp<=0) continue; //已消掉 
			count+= (temp+a-b-1)/(a-b); //该点至少需要几轮a 
			if(count>mid) break;
		}
		if(count<=mid){//mid轮可以完成
			ub=mid; 
			continue;
		} 
		lb=mid+1;
	}
	cout<<lb;
    rt0;
}


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

signed main() {
	string s;
	cin >> s;
	if(s == "abc" || s=="acb"||s=="bac"||s=="bca"||s=="cab"||s=="cba") cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 3608
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
using namespace std;

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <stack>
#include <bitset>

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

	vector<pair<pair<string, int>, int>> v(N);

	rep(i, N) {
		string S;
		int P;
		cin >> S >> P;
		v.at(i) = make_pair(make_pair(S, P * -1), i + 1);		
	}

	sort(v.begin(), v.end());

	rep(i, N) {
		cout << v.at(i).second << endl;	
	}
}

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

int main() {
	long long n,i,j,sum=0,ans=0,count=0,x,y,l,r,k;
    cin>>n;
    long long a[n],b[10005]={0};
    for(i=1;i<=100;i++)
    {
        for(j=1;j<=100;j++)
        {
            for(x=1;x<=100;x++)
            {
                k=i*i+j*j+x*x+i*j+j*x+x*i;
                if(k<=10000)
                b[k]++;
            }
        }
    }
    
    for(i=1;i<=n;i++)
    {
        cout<<b[i]<<"\n";
    }
    
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define sz(x) ((long long)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define oo 1e15;

const ld eps = 1e-9;
const ld pi = acosl(-1);
const int mod = 998244353;
const int mod1 = 1e9 + 7;


mt19937_64 rnd(time(0));

void faster()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios::sync_with_stdio(false);
}

signed main() {
    faster();
    // freopen("in", "r", stdin);
    // freopen("out", "w", stdout);
    //______________________________________
    /*__*/double start = clock();/*__*/
    //_____________________________________
    int n, k;
    cin >> n >> k;
    int a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    vector <bool> dp(k + 1, false);
    for (int i = 0; i <= k; i++)
    {
        bool wasl = false, wasw = false;
        for (int j = 0; j < n; j++)
        {
            if (i < a[j]) continue;
            if (dp[i - a[j]] == false)
                wasl = true;
            else
                wasw = true;
        }
        if (wasl) dp[i] = true;
        else dp[i] = false;
        //cout << i << " " << dp[i] << endl;
    }
    if (dp[k])
        cout << "First";
    else
        cout << "Second";
    //______________________________________
    //  cerr << "Time " << (clock() - start)  * 1.0 / CLOCKS_PER_SEC << "s\n";
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Edge
    {
        internal int from, to, cost;

        public Edge(int from, int to, int cost)
        {
            this.from = from;
            this.to = to;
            this.cost = cost;
        }
    }

    class Union_Find
    {
        internal int[] parents, rank;

        public Union_Find(int n)
        {
            parents = Enumerable.Range(0, n).ToArray();
            rank = new int[n];
        }

        public int Find(int x)
        {
            if (parents[x] == x) return x;
            else return parents[x] = Find(parents[x]);
        }

        public void Unite(int x, int y)
        {
            x = Find(x);
            y = Find(y);

            if (x == y) return;

            if (rank[x] < rank[y])
            {
                parents[x] = y;
            }
            else
            {
                parents[y] = x;
                if (rank[x] == rank[y]) rank[x]++;
            }
        }

        public bool Same(int x, int y)
        {
            return Find(x) == Find(y);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int V = int.Parse(input[0]);
            int E = int.Parse(input[1]);

            Edge[] edges = new Edge[E];

            int s, t, w;
            for (int i = 0; i < E; i++)
            {
                input = Console.ReadLine().Split(' ');
                s = int.Parse(input[0]);
                t = int.Parse(input[1]);
                w = int.Parse(input[2]);
                edges[i] = new Edge(s, t, w);
            }

            Console.WriteLine(Kruskal(edges, V));
        }

        static int Kruskal(Edge[] edges, int V)
        {
            Array.Sort(edges, (a, b) => a.cost - b.cost);
            Union_Find UF = new Union_Find(V);

            int totalCost = 0;
            int len = edges.Length;

            for (int i = 0; i < len; i++)
            {
                Edge e = edges[i];

                if (!UF.Same(e.from, e.to))
                {
                    UF.Unite(e.from, e.to);
                    totalCost += e.cost;
                }
            }
            return totalCost;
        }
    }
}

Measured memory_bytes: 15320
import java.util.Scanner;
class Main{
    public static void main(String arg[]){
        Scanner scn=new Scanner(System.in);
        int a = scn.nextInt();
        int b =scn.nextInt();
        int x= scn.nextInt();
        String answer = "NO";
        if(a<=x&&a+b>=x) answer = "YES";
        System.out.println(answer);
    }
}

Measured memory_bytes: 21844
MOD = 10**9 + 7
S = input()
res = 0
dp0 = 1 # ''
dp1 = 0 # 'a'
dp2 = 0 # 'ab'
dp3 = 0 # 'abc'

for c in S:
    if c == 'A':
        dp1 = (dp0+dp1)%MOD
    elif c == 'B':
        dp2 = (dp1+dp2)%MOD
    elif c == 'C':
        dp3 = (dp2+dp3)%MOD
    else:
        dp3 = (dp3*3+dp2)%MOD
        dp2 = (dp2*3+dp1)%MOD
        dp1 = (dp1*3+dp0)%MOD
        dp0 = (dp0*3)%MOD
print(dp3)


Measured memory_bytes: 9100
S = str(input())

cnt = 0

if S[0] == 'R' and S[1] == 'R' and S[2] == 'R':
    cnt = 3
elif S[0] == 'R' and S[1] == 'R' and S[2] == 'S':
    cnt = 2
elif S[0] == 'R' and S[1] == 'S' and S[2] == 'S':
    cnt = 1
elif S[0] == 'R' and S[1] == 'S' and S[2] == 'R':
    cnt = 1
elif S[0] == 'S' and S[1] == 'S' and S[2] == 'R':
    cnt = 1
elif S[0] == 'S' and S[1] == 'R' and S[2] == 'R':
    cnt = 2
elif S[0] == 'S' and S[1] == 'R' and S[2] == 'S':
    cnt = 1
elif S[0] == 'S' and S[1] == 'S' and S[2] == 'S':
    cnt = 0

print(cnt)

Measured memory_bytes: 9104
N = int(input())
S = input()
ans = 0

passwords = [str(i).zfill(3) for i in range(1000)]
for pw in passwords:
    S_copy = S
    for digit in pw:
        try:
            S_copy = S_copy[S_copy.index(digit)+1:]
        except ValueError:
            break
    else:
        ans += 1

print(ans)



Measured memory_bytes: 68080
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define deb(x)        cerr << #x << " = " << x << "\n";
#define deb2(x, y)    cerr << #x << " = " << x << ", " << #y << " = " << y << "\n";
#define deb3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << "\n";

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define F  first
#define S  second

#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()

typedef long long ll;  
const int mxN = 1e5+1;
vector<int> adj[mxN];
vector<bool> vis(mxN);
int n, m;

void dfs(int u) {
    if (vis[u]) {
        return;
    }
    vis[u] = true;
    if (!adj[u].empty())
    for (int v : adj[u]) {
        dfs(v);
    }
}

void solve() {
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    int cc = 0;
    for (int i = 0; i < n; ++i) {
        if (!vis[i]) {
            dfs(i);
            ++cc;
        }
    }
    cout << cc-1;
}

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

    ll tc = 1;
    //cin >> tc;

    while(tc--) {
        solve();
        cout << '\n';
    }

    return 0;
}



Measured memory_bytes: 9604