akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i))
#define mat(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define each(x,y) for(auto &(x):(y))
#define var(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { cin >> first; Scan(rest...); }
#define vec(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pb pop_back
#define fi first
#define se second
#define get(a, i) get<i>(a)
#define bit_count __builtin_popcount
#define mt make_tuple
inline string zero(int a,string s,char c='0'){return string(a-len(s),c)+s;}
inline string zero(int a,int t,char c='0'){return zero(a, to_string(t), c);}
inline string zero(int a,ll t,char c='0'){return zero(a, to_string(t), c);}
#define mini min_element
#define maxi max_element
#define sum accumulate
#define chmax(a,b) if(a<b)a=b
#define chmin(a,b) if(a>b)a=b
template <class T> inline void print(T t){cout << t << '\n';}
template <class H, class... T> inline void print(H h, T... t){cout << h << " ";print(t...);}
ll solve() {
	var(ll, n, p);
	if (n == 1)
		return p;
	if (p == 1)
		return 1;
	ll ans = 1;
	ll cnt = 0;
	while(p % 2 == 0) {
		p /= 2;
		++cnt;
	}
	if (cnt >= n) {
		ans *= pow(2, cnt / n);
	}
	for (ll i = 3, sqrt_p = sqrt(p) + 1; i <= sqrt_p; i += 2) {
		if (p % i == 0) {
			cnt = 0;
			while(p % i == 0) {
				p /= i;
				++cnt;
			}
			if (cnt >= n) {
				ans *= pow(i, cnt / n);
			}
		}
	}
	return ans;
}
int main() {
	print(solve());
	return 0;
}


Measured memory_bytes: 256
n, m, x, y = map(int, input().split())
xs = list(map(int, input().split()))
ys = list(map(int, input().split()))

xx = max(xs)
yy = min(ys)

for i in range(x+1,y+1):
  if xx < i <= yy:
    print('No War')
    break
else:
  print('War')

Measured memory_bytes: 3064
import math

if __name__ == '__main__':
    q = int(input())
    for i in range(q):
        a, b = list(map(int, input().split()))
        prod = a*b
        rootInt = int(math.sqrt(prod))
        if a == b: print((a-1)*2)
        elif math.sqrt(prod) == rootInt:
            print((rootInt-2)*2+1)
        else:
            if rootInt*(rootInt+1) < prod:
                print((rootInt-1)*2+1)
            else:
                print((rootInt-1)*2)

Measured memory_bytes: 3064
(let* ((s (read-line))
       (len (length s)))
  (format t "~d~%"
          (loop :for i :from (- 2 (mod len 2)) :by 2
                :when (string= s s
                               :start1 0
                               :end1 (/ (- len i) 2)
                               :start2 (/ (- len i) 2)
                               :end2 (- len i))
                :return (- len i))))


Measured memory_bytes: 13920
#include<stdio.h>
int cmp(const void *a,const void *b){
  return *(int*)a-*(int*)b;}
int main(){
  int a,b,i,count=0;
  double c,d;
  scanf("%d",&a);
  for(i=1;i<a+1;i++){
    c=i*1.08;
    b=c;
    if(a==b){
      printf("%d\n",i);
      break;
    }
    else 
      count++;
  }
  if(count==a)
    printf(":(\n");
  return 0;}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pb push_back
#define mp make_pair
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
#define INF 1e18
#define M 1000000009
#define pi 3.14159265358979323846264338327950
typedef pair<int,int> pr;
#define N 1000002
signed main()
{
    SPEED;
  	int n;
  	cin>>n;
  double b;
  cin>>b;
  int b1=round(b*100.00);
  cout<<(n*b1)/100;
}

Measured memory_bytes: 3736
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

struct City {
  ll prefecture;
  ll year;
  ll index;
  ll x;
};

int main() {
  ll N, M;
  cin >> N >> M;

  vector<City> Cities(M);
  for (ll i = 0; i < M; i++) {
    cin >> Cities[i].prefecture >> Cities[i].year;
    Cities[i].index = i;
  }
  sort(begin(Cities), end(Cities), [](auto x, auto y) {
    if (x.prefecture != y.prefecture) {
      return x.prefecture < y.prefecture;
    }
    return x.year < y.year;
  });

  ll pre = 1;
  for (ll i = 0; i < M;) {
    ll num = 1;
    while (Cities[i].prefecture > pre) {
      pre++;
      num = 1;
    }
    while (Cities[i].prefecture == pre) {
      Cities[i].x = num;
      num++;
      i++;
    }
  }

  sort(begin(Cities), end(Cities), [](auto x, auto y) { return x.index < y.index; });

  for (const auto& city : Cities) {
    printf("%06d%06d\n", city.prefecture, city.x);
  }

  return 0;
}


Measured memory_bytes: 4608
from collections import deque
N = int(input())
A = [int(i) for i in input().split()]

pos = [a for a in A if a >= 0]
neg = [a for a in A if a < 0]
# zero = [a for a in A if a == 0]

pos.sort()
neg.sort()

pd = deque(pos)
nd = deque(neg)

buf = []

while len(pd) + len(nd) > 2:  # more 3
    # もし負の数が無かったら追加
    if len(nd) == 0:
        y, x = pd.pop(), pd.popleft()
        buf.append((x, y))
        nd.append(x - y)
        continue
    # もし正の数が無かったら追加
    if len(pd) == 0:
        x, y = nd.pop(), nd.popleft()
        buf.append((x, y))
        pd.append(x - y)
        continue
    # 正の数が1より大きかったら減らす
    if len(pd) > 1:
        x, y = nd.pop(), pd.pop()
        buf.append((x, y))
        nd.append(x - y)
        continue
    # 正の数がちょうど1だったらどんどん正の数を大きくする
    if len(pd) == 1:
        x, y = pd.pop(), nd.pop()
        buf.append((x, y))
        pd.append(x - y)
        continue

merge = []
merge.extend(nd)
merge.extend(pd)

val = merge[1] - merge[0]
buf.append((merge[1], merge[0]))

# print
print(val)
for b in buf:
    print(b[0], b[1])

Measured memory_bytes: 21100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 1000000007
ll H[90002],W[90002],man[90002],rui[90002];

int main() {
	ll h,w,d;
	cin>>h>>w>>d;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			ll z;
			cin>>z;
			z--;
			H[z]=i;
			W[z]=j;
		}
	}
	for(int i=0;i<d;i++){
		ll j=1;
		while(i+d*j<h*w){
			ll now=i+d*(j-1);
			ll next=i+d*j;
			man[next]=abs(H[now]-H[next])+abs(W[now]-W[next]);
			rui[next]=rui[now]+man[next];
			j++;
		}
	}
	ll q;
	cin>>q;
	for(int i=0;i<q;i++){
		ll l,r;
		cin>>l>>r;
		l--;r--;
		cout <<rui[r]-rui[l]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3968
#include <iostream>

using namespace std;
int main()
{
    int x, y;
    cin >> x >> y;
    for (int i=0; i<=x; i++){
        for (int j=0; j<=x; j++){
            if(i+j==x){
                int leg = i*2 + j*4;
                if(leg==y){
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

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

const int MOD = 1e9 + 7;

int add(int a, int b) {
	return (a + b) % MOD;
}

int mul(int a, int b) {
	return (a * b) % MOD;
}

int modpow(int base, int exp, int modulus) {
  base %= modulus;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}

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

  int N;
  cin >> N;

  vector<int> cnt(N+1);

  for(int i=0; i<N-1; i++){
    int idx;
    cin >> idx;
    cnt[idx]++;
  }

  for(int i=1; i<N+1; i++){
    cout << cnt[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 4756
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>//for queue and priority_queue
#include <fstream>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#define endl "\n"
typedef long long ll;
using namespace std;
void Lancer() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
bool isPrime(ll n){
	if (n == 2 || n == 3 || n == 5)
		return true;
	else if (n % 2 == 0 || n % 3 == 0 || n % 5 == 0 || n == 1)
		return false;
	else {
		for (int i = 5; i <= sqrt(n); i += 2){
			if (n%i == 0)
				return false;
		}
		return true;
	}
}

int arr[100007];
int main(){
	Lancer();
	ll n,pw=0,res=1;
	cin >> n;
	while (pw<7)
	{
		res = pow(2, pw);
		if (res > n){
			res = pow(2, pw - 1);
			break;
		}
		pw++;
	}
	cout << res;
	cout << endl;
	return 0;
}


Measured memory_bytes: 4068
N,K = map(int,input().split())
ans = []

for i in range(N):
    ab = list(map(int,input().split()))
    ans.append(ab)

ans.sort()

l = 0
 
for i in range(N):
    l += ans[i][1]
    if l >= K:
        s = i
        break
print(ans[s][0])

Measured memory_bytes: 27544
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう
//a=0x61=97 '0'=0x30=48
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long  ll;
typedef long double  ld;
typedef string str;
typedef pair<int,int> pairii;
typedef vector<int> veci;
const double pi=3.1415926535;
const ll  mod=1000000007;
//桁数指定　cout << fixed << setprecision(2)
int main() {
  ll sum;str v;cin>>v;
  rep(i,v.size()){
  sum+=(v[i]-48);}
  if(sum%9)cout<<"No"<<endl;  
  else cout<<"Yes"<<endl;
}

Measured memory_bytes: 3764
x,y=map(int,input().split())
mod=10**9+7

def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)
def mod_combinations_count(n, r, mod):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res

if (x+y)%3!=0:
    print(0)
else:
    n=(x+y)//3
    m=(-x+2*y)//3
    if n<0 or m<0 or n<m:
        print(0)
        exit()
    else:
        print(mod_combinations_count(n,m,mod)%mod)


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int h, w;
  cin >> h >> w;
  vector<string> mp(h);
  for (int i = 0; i < h; i++) {
    cin >> mp[i];
    cout << mp[i] << endl << mp[i] << endl;
  }
  return 0;
}


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

int main(void) {

    int n; cin >> n;
    while (n--) {
        string psg, msg; cin >> psg >> msg;
        int len = msg.size();

        for (int i = psg.size()-1; i >= 0; i--) {
            switch (psg[i]) {
            case 'J':
                // right shift
                msg = string(1, msg[len-1]) + msg.substr(0, len-1);
                break;
            case 'C':
                // left shift
                msg = msg.substr(1, len-1) + string(1, msg[0]);
                break;
            case 'E':
                // swap
                if (len%2 == 0) {
                    string l = msg.substr(0, len/2);
                    string r = msg.substr(len/2, len/2);
                    msg = r+l;
                } else {
                    string l = msg.substr(0, len/2);
                    string r = msg.substr(len/2+1, len/2);
                    msg = r+msg[len/2]+l;
                }
                break;
            case 'A':
                // reverse
                reverse(msg.begin(), msg.end());
                break;
            case 'P':
                // decrement digits
                for (auto &m : msg) {
                    if (isdigit(m)) {
                        if (m == '0') m = '9';
                        else m--;
                    }
                }
                break;
            case 'M':
                // increment digits
                for (auto &m : msg) {
                    if (isdigit(m)) {
                        if (m == '9') m = '0';
                        else m++;
                    }
                }
                break;
            default:
                break;
            }
        }
        cout << msg << endl;
    }

    return 0;
}

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

using namespace std;

int main(void) {
    int n;
    vector <int> a;
    cin >> n;
    for (int i = 0; i < 3 * n; i++) {
        int ai;
        cin >> ai;
        a.push_back(ai);
    }

    priority_queue <int> left;
    long long sleft = 0;
    long long sl[300000];
    for (int i = 0; i < 2 * n; i++) {
        left.push(-a[i]);
        sleft += a[i];
        if (left.size() > unsigned(n)) {
            sleft -= left.top() * (-1);
            left.pop();
        }
        sl[i] = sleft;
    }

    priority_queue <int> right;
    long long sright = 0;
    long long sr[300000];
    for (int i = 3 * n - 1; i >= n; i--) {
        right.push(a[i]);
        sright += a[i];
        if (right.size() > unsigned(n)) {
            sright -= right.top();
            right.pop();
        }
        sr[i] = sright;
    }

    long long res;
    res = -999999999999999;
    for (int i = n - 1; i < 2 * n; i++) {
        res = max(res, sl[i] - sr[i + 1]);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 7408
#include <bits/stdc++.h>
#include <numeric>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP1(i, n) for(int i = 1; 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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
	int n; cin >> n;
	int t = n / 2;
	if (n % 2 == 0) {
		cout << t - 1 << endl;
	}
	else {
		cout << t << endl;
	}
}

Measured memory_bytes: 3496
#include <stdio.h>

int main()
{

  int a, b;

  scanf("%d %d", &a, &b);
  if(a >= -1000 && b <= 1000){
    if(a < b) {
      printf("a < b\n");
    }
    if(a > b) {
      printf("a > b\n");
    }
    if(a == b) {
      printf("a == b\n");
    }

  }
  return 0;
}

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

int main() {
  int N, K, Q;
  cin >> N >> K >> Q;
  vector<int> A(Q);
  for (int i = 0; i < Q; i++) {
    cin >> A[i];
  }

  vector<int> B(N, K-Q);
  
  for (int i = 0; i < Q; i++) {
    B[A[i]-1]++;
  }
  
  for (int i = 0; i < N; i++) {
    if (B[i] > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }

  
}


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

int main(){
    int x,y;
    while(cin>>y>>x){
        if(x!=0||y!=0){
            for(int i=0;i<y;i++){
                for(int j=0;j<x;j++){
                    cout<<'#';
                }
                cout<<endl;
            }
            cout<<endl;
        }
    }
    
}


Measured memory_bytes: 3080
def print_by_preorder nodes, node_id, res
  left_id = nodes[node_id][0]
  right_id = nodes[node_id][1]
  res << node_id
  print_by_preorder nodes, left_id, res if left_id != -1
  print_by_preorder nodes, right_id, res if right_id != -1
  return res
end

def print_by_inorder nodes, node_id, res
  left_id = nodes[node_id][0]
  right_id = nodes[node_id][1]
  print_by_inorder nodes, left_id, res if left_id != -1
  res << node_id
  print_by_inorder nodes, right_id, res if right_id != -1
  return res
end

def print_by_postorder nodes, node_id, res
  left_id = nodes[node_id][0]
  right_id = nodes[node_id][1]
  print_by_postorder nodes, left_id, res if left_id != -1
  print_by_postorder nodes, right_id, res if right_id != -1
  res << node_id
  return res
end

n = gets.chomp.to_i
nodes = Array(n)
not_roof_ids = []
while l = gets
  node_id, left_id, right_id = l.chomp.split(' ').map(&:to_i)
  nodes[node_id] = [left_id, right_id]
  not_roof_ids << left_id
  not_roof_ids << right_id
end
root_node_id = nil
nodes.each_with_index do |n, i|
  unless not_roof_ids.include?(i)
    root_node_id = i
    break
  end
end

puts 'Preorder'
res = print_by_preorder nodes, root_node_id, []
puts ' ' + res.join(' ')
puts 'Inorder'
res = print_by_inorder nodes, root_node_id, []
puts ' ' + res.join(' ')
puts 'Postorder'
res = print_by_postorder nodes, root_node_id, []
puts ' ' + res.join(' ')


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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

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

    string s;
    cin >> s;
    int n = s.length();

    long long ret = 0;
    int pref = 0, power = 1;
    vector<int> cnt(2019);
    cnt[0] = 1;
    for (int i=n-1; i>=0; i--) {
        pref = (pref + (s[i] - '0') * power % 2019) % 2019;
        power = power * 10 % 2019;
        ret += cnt[pref]++;
    }
    cout << ret << "\n";

    return 0;
}


Measured memory_bytes: 3728
N, M = map(int, input().split())
X = sorted(list(map(int, input().split())))

if N > M:
    print(0)
else:
    Y = [None] * (M - 1)
    for i in range(M - 1):
        Y[i] = X[i + 1] - X[i]

    Y.sort()
    print(sum(Y[:M - N]))


Measured memory_bytes: 13968
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

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

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	S := sc.nextStr()
	N := len(S)
	//fmt.Fprintln(wtr, S[0:(N-1)/2])
	//fmt.Fprintln(wtr, S[(N+3)/2-1:N])
	if f(S) && f(S[0:(N-1)/2]) && f(S[(N+3)/2-1:N]) {
		fmt.Fprintln(wtr, "Yes")
	} else {
		fmt.Fprintln(wtr, "No")
	}
}

func f(str string) bool {
	l := 0
	r := len(str) - 1
	for l < r {
		if str[l] != str[r] {
			return false
		}
		l += 1
		r -= 1
	}
	return true
}


Measured memory_bytes: 640
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll mod=(ll)1e9+7;
//}}}

ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

ll gcd2(ll a, ll b){
  if(a == -1) return b;
  if(b == -1) return a;
  return gcd(a, b);
}

const int kMaxN = 131072;
ll dat[kMaxN * 2 - 1];
int n;
void update(int i, ll x){
  i += n - 1;
  dat[i] = x;
  while (i > 0) {
    i = (i - 1) / 2;
    dat[i] = gcd2(dat[i * 2 + 1], dat[i * 2 + 2]);
  }
}

ll query(int a, int b, int k, int l, int r){
  if(r <= a || b <= l) return -1;
  if(a <= l && r <= b) return dat[k];
  else{
    ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return gcd2(vl, vr);
  }
}

int main(){
  int N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];

  n = kMaxN;
  rep(i, 2 * n - 1) dat[i] = -1;
  rep(i, N) update(i, A[i]);
  rep(i, N, n) update(i, -1);

  ll ans = 0;
  rep(i, N){
    ll v = gcd2(query(0, i, 0, 0, n), query(i + 1, N, 0, 0, n));
    ans = max(ans, v);
  }
  cout << ans << endl;
  return 0;
}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORB(i, m, n) for (int i = m; i >= n; i--)
#define ll long long
#define pb push_back
#define popb pop_back
#define debug(i) cout << #i << "= " << i << endl
using namespace std;

int main()
{
    int x;
    cin >> x;
    string ans = "No";
    if (x >= 30)
        ans = "Yes";
    cout << ans << endl;
}


Measured memory_bytes: 3624
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<class T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<class T,class Size=typename vector<T>::size_type>inline auto vector_2d(Size h,Size w,T v){return vector<vector<T>>(h,vector<T>(w,v));}
template<class RandomAccessIterator,class Pair=typename iterator_traits<RandomAccessIterator>::value_type>inline void sort_pairs_by_second(RandomAccessIterator first,RandomAccessIterator last){sort(first,last,[](const Pair&p1,const Pair&p2){return p1.second<p2.second||(p1.second==p2.second&&p1.first<p2.first);});}

int main()
{
    constexpr ll foo=1000001;
    vector<bool>is_prime(foo,true);
    is_prime[0]=is_prime[1]=false;
    for(ll i=0;i*i<foo;++i){
        if(is_prime[i]){
            for(ll j=i*i;j<foo;j+=i){
                is_prime[j]=false;
            }
        }
    }
    vector<ll>primes;
    for(ll i=0;i<foo;++i){
        if(is_prime[i]){
            primes.push_back(i);
        }
    }

    ll n=in();
    vector<ll>a(n);
    for(ll i=0;i<n;++i)a[i]=in();

    ll gcd_sum=a[0];
    set<ll>used_primes;
    bool is_pairwise=true;
    for(ll i=0;i<n;++i){
        gcd_sum=gcd(gcd_sum,a[i]);
        if(is_pairwise){
            if(is_prime[a[i]]){
                if(used_primes.count(a[i])){
                    is_pairwise=false;
                }
                used_primes.insert(a[i]);
            }else{
                for(ll j=0;primes[j]*primes[j]<=a[i];++j){
                    if(a[i]%primes[j]==0){
                        if(used_primes.count(primes[j])){
                            is_pairwise=false;
                            break;
                        }
                        used_primes.insert(primes[j]);
                        while(a[i]%primes[j]==0){
                            a[i]/=primes[j];
                        }
                    }
                }
                if(a[i]!=1){
                    if(used_primes.count(a[i])){
                        is_pairwise=false;
                    }
                    used_primes.insert(a[i]);
                }
            }
        }
    }
    if(is_pairwise){
        cout<<"pairwise coprime"<<endl;
    }else if(gcd_sum==1){
        cout<<"setwise coprime"<<endl;
    }else{
        cout<<"not coprime"<<endl;
    }
}


Measured memory_bytes: 12060
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

ll a[2001],dp[2001];
int main(){
    ll n,x,ai;
    cin>>n>>x;
    ll sum=1000100010001000;
    rep(i,n){
        cin>>ai;
        dp[i]=a[i]=ai;
    }
    rep(i,n){
        ll s=0;
        rep(j,n){
            dp[j]=min(dp[j],a[(j-i+n)%n]);
            s+=dp[j];
        }
        sum=min(sum,s+i*x);
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 384
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T, class U> inline bool chmax(T& a,U b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T& a,U b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int n, k;
    cin >> n >> k;
    long long t[1100]; t[0] = 0;
    double tt[1100];
    for (int i = 1; i < 1100; i++) t[i] = t[i-1] + i;
    for (int i = 1; i < 1100; i++) tt[i] = (double)t[i] / i;
    vector<int> p(n);
    vector<double> a(n), sum(n+1, 0); 
    for (int i = 0; i < n; i++) {        
        cin >> p[i];
        a[i] = tt[p[i]];
        sum[i+1] = sum[i] + a[i];
    }
    
    double ans = 0;
    for (int i = 0; i + k <= n; i++) {
        double s = (double)sum[i+k] - sum[i];
        if (ans < s) ans = s;
    }
    
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pi = pair<int,int>;

int main()
{
    int n;
    scanf(" %d", &n);
    vector<int> x(n),y(n),w(n);
    rep(i,n) scanf(" %d %d %d", &x[i], &y[i], &w[i]);

    map<pi,int> m;
    rep(i,n) m[pi(x[i],y[i])] = w[i];

    int ans = 0;
    rep(i,n)
    {
        int dx[3]={0,1,1}, dy[4]={1,1,0};
        rep(j,4)
        {
            int W = w[i];
            rep(k,3)
            {
                int nx = x[i]+dx[k], ny = y[i]+dy[k];
                pi p(nx,ny);
                if(m.count(p)) W += m[p];
            }
            ans = max(ans,W);

            if(j%2==0) rep(k,3) dx[k] = -dx[k];
            else rep(k,3) dy[k] = -dy[k];
        }
    }

    printf("%d / 1\n", ans);
    return 0;
}

Measured memory_bytes: 10216
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0;i < N;i++)cin >> A[i];
    ll sum = 0;
    for(int i = 0;i < N;i++){
        sum += A[i]/2;
        if((A[i]&1) && i < N-1 && A[i+1]){
            sum++;
            A[i+1]--;
        }
    }
    cout << sum << endl;

}

Measured memory_bytes: 640
n = int(input())
s = list(input())

r = s.count('R')
g = s.count('G')
b = s.count('B')

ans = r*g*b

for i in range(n-2):
  for j in range(i+1,i+((n-i-1)//2)+1):
    if s[i] != s[j] and s[i] != s[2*j - i] and s[j] != s[2*j - i]:
      ans -= 1
      
print(ans)

Measured memory_bytes: 9236
#include<cstdio>
#include<vector>

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

using namespace std;

typedef long long ll;

class DominatingSet{
	const int n;
	const ll Omega;
	vector<ll> mask,mask2;
	vector< vector<int> > adj;

	int dfs(int u,ll S,int tmp,int &ub){
		if(S==Omega){
			ub=tmp;
			return tmp;
		}
		if(u==n || tmp>=ub || (S|mask2[u])!=Omega) return n;

		return min(dfs(u+1,S,tmp,ub),dfs(u+1,S|mask[u],tmp+1,ub));
	}

public:
	DominatingSet(const vector< vector<int> > &A):n(A.size()),Omega((1LL<<A.size())-1),adj(A){
		mask.resize(n);
		rep(u,n){
			mask[u]=1LL<<u;
			rep(i,adj[u].size()) mask[u]|=1LL<<adj[u][i];
		}

		mask2.resize(n);
		mask2[n-1]=mask[n-1];
		for(int u=n-1;u>0;u--) mask2[u-1]=mask[u-1]|mask2[u];
	}

	int solve(){
		int ub=n;
		return dfs(0,0,0,ub);
	}
};

int main(){
	for(int n,m;scanf("%d%d",&n,&m),n||m;){
		vector< vector<int> > adj(n);
		rep(i,m){
			int u,v; scanf("%d%d",&u,&v);
			adj[u].push_back(v);
			adj[v].push_back(u);
		}
		printf("%d\n",DominatingSet(adj).solve());
	}

	return 0;
}

Measured memory_bytes: 0
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 9e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class AABCARC {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    int x;
	    in >> x;
	    if(x < 1200) out << "ABC" << endl;
	    else out << "ARC" << endl;
	}
};


int main() {
	AABCARC solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <utility>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <fstream>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <ctime>
#include <stack>
#include <map>
#include <set>
#if __cplusplus > 199711L
#include <unordered_set>
#include <unordered_map>
#include <tuple>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
//	tree<key, mapped = null_type, cmp = less<key>, rb_tree_tag, tree_order_statistics_node_update> name;
//	order_of_key
//	find_by_order
#endif

using namespace std;

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fs first
#define sc second
#define abs(a) ((a) < 0 ? -(a) : (a))
#define sqr(a) ((a) * (a))

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

inline pair<pair<bool, bool>, pair<string, bool> > useinout();

void init() {
#ifdef SOL
	if (useinout().fs.fs)
		freopen("input.txt", "r", stdin);
	if (useinout().fs.sc)
		freopen("output.txt", "w", stdout);
#else
	srand(time(0));
	const string file = useinout().sc.fs;
	if (!file.empty()) {
		freopen((file + ".in").c_str(), "r", stdin);
		freopen((file + ".out").c_str(), "w", stdout);
	}
	if(useinout().sc.sc) {
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}
#endif
}

int solve();

void finish(int exitval) {
	fflush(stdout);
#ifdef SOL
	fprintf(stderr, "\nexit value: %d\ntime: %.3lf ms\n", exitval, 1000. * clock() / CLOCKS_PER_SEC);
#endif
}

int main() {
	init();
	int exitval = solve();
	finish(exitval);
	return (0);
}

const double eps = 1e-9;
const int mod = (int) 1e+9 + 7;
const double pi = acos(-1.);
const int maxn = 100100;

inline pair<pair<bool, bool>, pair<string, bool> > useinout() {
	return (mp(mp(0, 0), mp("", 0)));
}

vector<pair<int, int> > p;

int solve() {

	int w, h;
	scanf("%d%d", &w, &h);
	for (int i = 0; i < w; i++) {
		int x;
		scanf("%d", &x);
		p.pb(mp(x, 0));
	}
	for (int i = 0; i < h; i++) {
		int x;
		scanf("%d", &x);
		p.pb(mp(x, 1));
	}

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

	ll ans = 0;

	for (int i = 0; i < (int) p.size(); i++) {
		if (p[i].sc == 0) {
			ans += (h + 1) * 1ll * p[i].fs, w--;
		} else {
			ans += (w + 1) * 1ll * p[i].fs, h--;
		}
	}

	printf("%lld\n", ans);

	return (0);
}

// by Andrey Kim


Measured memory_bytes: 2548
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N; cin >> N;
  vector<string>S(N);
  for (int i=0; i<N; i++) cin >> S[i];  
  map<string, int>mp;
  for (int i=0; i<N; i++){
    mp[S[i]]++;
  }
  int a = mp.size();
  int mx=0;
  for (int i=0; i<N; i++){
    mx = max(mx, mp[S[i]]);
  }
  vector<string>ANS(N);
  set<string>SET;
  for (int i=0; i<N; i++){
    if (mp[S[i]]==mx){
      SET.insert(S[i]);
    }
  }
  for (auto x : SET) {
      cout << x << endl;
  }
  return 0;
}

Measured memory_bytes: 37760
#include <bits/stdc++.h>
#define ll long long int
#define booga cout << "booga" << endl
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;

const int INF= 1e9 + 5;

void min_self(int &a, int b){
	a = min(a,b);
}

void testcase(){
	int H,W;
	cin >> H >> W;
	vector<string> grid(H);
	for(int i{0};i < H;i++){
		cin >> grid[i];
	}
	vector<vector<int>> dp(H,vector<int>(W,INF));
	dp[0][0] = grid[0][0] == '#';
	for(int i{0};i < H;i++){
		for(int j{0};j < W;j++){
			if(i == 0 && j == 0){
				continue;
			}
			if(i == 0){
				min_self(dp[i][j],dp[i][j-1] + (grid[i][j-1] == '.' && grid[i][j] == '#'));
			}
			else if(j == 0){
				min_self(dp[i][j],dp[i-1][j] + (grid[i-1][j] == '.' && grid[i][j] == '#'));
			}
			else{
				min_self(dp[i][j],dp[i][j-1] + (grid[i][j-1] == '.' && grid[i][j] == '#'));
				min_self(dp[i][j],dp[i-1][j] + (grid[i-1][j] == '.' && grid[i][j] == '#'));
				
			}
		}
	}
	cout << dp[H-1][W-1] << endl;
}
	

int main(int argc, char** argv){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t;
	t = 1;
	while(t--){
		testcase();
	}
	return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
#define endl "\n"
#define FASTIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define f first
#define s second
typedef long long int ll;
const int INF = 1e9;

using namespace std;
 
int main()
{
    FASTIO
    int a, b, c, d, h1, h2;
    cin>>a>>b>>c>>d;
  	h1=c/b;
  	h2=a/d;
  	if(c%b != 0) ++h1;
  	if(a%d != 0) ++h2;
  	if(h1<=h2) cout<<"Yes\n";
  	else cout<<"No\n";
    return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<vector>

using namespace std;

int main() {

    int w,n;
    cin>>n>>w;

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

    vector<int> wt(n);
    vector<int> val(n);

    for(i=0;i<n;i++) {
        wt[i] = h[i][0];
        val[i] = h[i][1];
    }

    vector<vector<long> > dp(n + 1,vector<long> (w+1,0));
    
    for(i=0;i<=n;i++) {
        for(j=0;j<=w;j++) {
            if(i==0 || j==0)
                dp[i][j] = 0;
            else if(wt[i-1]<=j) {
                dp[i][j] = max(val[i-1] + dp[i-1][j-wt[i-1]],dp[i-1][j]);

            }
            else
                dp[i][j] = dp[i-1][j];

        }   

    }
    


    cout<<dp[n][w]<<endl;

    return 0;
    
}


Measured memory_bytes: 80256
import java.util.*

private val readInt: ()->Int = { readLine()!!.toInt() }
private val readListInt: ()->List<Int> = { readLine()!!.split(' ').map(String::toInt) }


fun main(args: Array<String>) {
    val (N, K) = readListInt()

    var hasTreat = Array<Boolean>(N){false};
    repeat (K) {
        val D = readInt()
        val A = readListInt()
        for (e in A) {
            //st.add(e)
            hasTreat[e-1] = true;
        }
    }

    val ans = hasTreat.count { !it }
    println(ans)
}


Measured memory_bytes: 38868
s = int(input())
a = []
a.append(s)
for i in range(1000000):
    if a[i] % 2 == 0:
        a.append(a[i]/2)
    else:
        a.append(3*a[i]+1)
    if a[-1] in a[:i-1]:
        print(i+2)
        break

Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    while (cin >> n, n)
    {
        vector<string> lines(n);
        for (auto &line : lines)
        {
            cin >> line;
        }

        for (auto &line : lines)
        {
            replace(line.begin(), line.end(), '.', ' ');
        }

        for (auto &line : lines)
        {
            auto lastSpace = line.find_last_of(' ');
            if (lastSpace != string::npos)
            {
                line[lastSpace] = '+';
            }
        }

        for (size_t i = 0; i < lines.size(); ++i)
        {
            auto lineIPlusPos = lines[i].find('+');
            for (size_t j = i + 1; j < lines.size(); ++j)
            {
                auto lineJPlusPos = lines[j].find('+');
                if (lineJPlusPos < lineIPlusPos)
                {
                    break;
                }
                if (lineIPlusPos == lineJPlusPos)
                {
                    for (size_t k = i + 1; k < j; ++k)
                    {
                        lines[k][lineIPlusPos] = '|';
                    }
                    break;
                }
            }
        }

        for (auto &line : lines)
        {
            cout << line << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 1832
#include<bits/stdc++.h>
using namespace std;
int n,s[100000],q,t,c,l,m,r,i,j;
main(){  
  for(cin>>n;i<n;)cin>>s[i++];
  for(cin>>q;j++<q;){
    l=0,r=n,cin>>t;
    while(m=(l+r)/2,l<r){
      t-s[m]||(l=r,c++);
      if(t<s[m])r=m;
      else if(t>s[m])l=m+1;
    }
  }
  cout<<c<<endl;
}

Measured memory_bytes: 3476
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a7=1000000007;
ll inf=100000000000000000;

int main()
{
  ll x,a,ans=10;cin>>x>>a;
  if(x<a)ans=0;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <assert.h>
#include <sstream>
#include <string>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;

int  MOD = 1e9 + 7;
uint64_t inverseModp(uint64_t a, uint64_t p) {
    assert(p < (1ull << 63));
    assert(a < p);
    assert(a != 0);
    uint64_t ex = p-2, result = 1;
    while (ex > 0) {
        if (ex % 2 == 1) {
            result = (result*a) % p;
        }
        a = (a*a) % p;
        ex /= 2;
    }
    return result;
}


uint32_t nCrModp(uint32_t n, uint32_t r, uint32_t p)
{
    assert(r <= n);
    if (r > n-r) r = n-r;
    if (r == 0) return 1;
    if(n/p - (n-r)/p > r/p) return 0;
    
    uint64_t result = 1; //intermediary results may overflow 32 bits
    
    for (uint32_t i = n, x = 1; i > r; --i, ++x) {
        if( i % p != 0) {
            result *= i % p;
            result %= p;
        }
        if( x % p != 0) {
            result *= inverseModp(x % p, p);
            result %= p;
        }
    }
    return result;
}

int main(){
    int x,y;
    cin >> x >> y;
    if ( (2*y-x)%3 != 0 || (2*x-y)%3!= 0 || (2*y-x)/3 < 0 || (2*x-y)/3 < 0 ){
        cout << 0 ;rn 0;
    }
    int q = (2*y-x)/3;
    int p = (2*x-y)/3;
    
    cout << nCrModp((uint32_t) p + q, (uint32_t) q, (uint32_t) MOD);
    rn 0;
}


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

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

int gcd(int a,int b){
  int r=a%b;
  while(r>0){
    a=b;b=r;r=a%b;
  }
  return b;
}

void run(void){
  int n,m;
  scanf("%d%d",&n,&m);
  char *s=(char *)malloc(sizeof(char)*(n+1));
  scanf("%s",s);
  char *t=(char *)malloc(sizeof(char)*(m+1));
  scanf("%s",t);
  int g=gcd(n,m);
  int i;
  for(i=0;i*(n/g)<n;i++){
    if(s[i*(n/g)]!=t[i*(m/g)]){
      printf("-1\n");
      return;
    }
  }
  printf("%lld\n",(int64)n*m/g);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<pair<ll,ll> > vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
const int INF=1e9+7;
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
int main(){
  ll n,ans=0;cin>>n;
  vll a(n),b(n);
  rep(i,0,n){
    cin>>a[i]>>b[i];
  }
  for(int i=n-1;i>=0;i--){
    if(mod(a[i]+ans,b[i])!=0){
      ans+=b[i]-mod(a[i]+ans,b[i]);
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1792
from functools import lru_cache

n = int(input())
A = sorted(list(map(int, input().split())))
q = int(input())
query = list(map(int, input().split()))

@lru_cache(maxsize=None)
def solve(i, m):
    if m == 0:
        return True
    elif i >= n or m < A[i]:
        return False
    else:
        return solve(i + 1, m - A[i]) or solve(i + 1, m)

for m in query:
    if solve(0, m):
        print("yes")
    else:
        print("no")

Measured memory_bytes: 14728
#include <iostream>
#include <vector>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;

int n,m,q;
vector<int> a,b,c,d;
int ans=0;

void dfs(vector<int> A){
    if(A.size()==n+1){
        int now=0;
        rep(i,q) {
            if(A.at(b.at(i))-A.at(a.at(i)) == c.at(i)){
                now+=d.at(i);
            }
            
            ans=max(ans,now);
        }
    }else{
        A.push_back(A.back());
        for(int i=A.back();i<=m;i++){
            dfs(A);
            A.back()++;
        }
    }
}

int main(void){
    cin >> n >> m >> q;
    a=b=c=d=vector<int>(q);
    rep(i,q){
        cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
    }
    dfs(vector<int>(1,1));
    
    cout << ans << endl;
    
}


Measured memory_bytes: 3612
#include <stdio.h>

int n;
double head[3010], memo[3005][1505];

double dp(int id, int ekor) {
	if (memo[id][ekor] > -0.5)
		return memo[id][ekor];
	if (ekor == 0) {
		memo[id][ekor] = 1.0;
		for (int k = id; k < n; k++)
			memo[id][ekor] *= head[k];
		return memo[id][ekor];
	}
	if (id + ekor == n) {
		memo[id][ekor] = 1.0;
		for (int k = id; k < n; k++)
			memo[id][ekor] *= (1.0 - head[k]);
		return memo[id][ekor];
	}
	memo[id][ekor] = (head[id] * dp(id + 1, ekor)) + ((1 - head[id]) * dp(id + 1, ekor - 1));
	return memo[id][ekor];
}

int main() {
	int tail;
	double ans = 0.0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%lf", &head[i]);
	tail = n / 2;
	for (int i = 0; i < n; i++)
		for (int j = 0; j <= tail; j++)
			memo[i][j] = -1.0;
	for (int i = 0; i <= tail; i++)
		ans += dp(0, i);
	printf("%.12lf\n", ans);
	return 0;
}

Measured memory_bytes: 35584
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7,N=2e5+5;
int n,k;
int main()
{
    scanf("%d%d",&n,&k);
    int ans=0;
    while(k--)
    {
        int x;scanf("%d",&x);
        ans+=x;
    }
    if(n-ans<0) printf("-1\n");
    else printf("%d\n",n-ans);
}


Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1e9+7;
typedef long long int lli;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<lli> vlli;
typedef vector<bool> vb;
long long int max(long long int a,long long int b){
  if(a>b)
    return a;
  else
    return b;
}
long long int min(long long int a,long long int b){
  if(a<b)
    return a;
  else
    return b;
}
long long int binpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
      a = a * a % m;
      b >>= 1;
    }
  return res;
}
long long binpow(long long a, long long b) {
    if (b == 0)
        return 1;
    long long res = binpow(a, b / 2);
    if (b % 2)
        return res * res * a;
    else
        return res * res;
}
 
//############################ENDOFTEMPLATE############################

int dfs(lli num,lli x,int dig){
  if(num>x) return 0;

  lli cpy = num;
  int d = 0;

  while(cpy>0){
    d++;
    cpy/=10;
  }
  if(d==dig){
    return 1;
  }

  int ld = num%10;

  lli curr = 0;
  for(int i = -1;i<=1;i++){
    if(ld+i>=0 && ld+i<=9)
      curr = curr+dfs(num*10+ld+i,x,dig);
  }

  return curr;

}



bool check(lli x,int k,vi& less){
  //cout<<x<<endl;
  int dig = 0;
  lli cx = x;
  while(cx>0){
    dig++;
    cx/=10;
  }

  if(less[dig-1]>k)
    return false;

  lli val = less[dig-1];

  cx = x;
  while(cx>=10){
    cx/=10;
  }

  for(int i = 1;i<=cx;i++){
    val = val+dfs(i,x,dig);
  }

  

  if(val<k)
    return true;

  return false;

}

void solve(){
  int k;
  cin>>k;

  vector<vi> dp(13,vi(10,0));
  for(int i = 1;i<=9;i++){
    dp[1][i] = 1;
  }

  for(int i = 2;i<=12;i++){
    for(int j = 0;j<=9;j++){
      dp[i][j] = dp[i-1][j]+(j+1<10?dp[i-1][j+1]:0)+ (j-1>=0?dp[i-1][j-1]:0);
    }
  }

  vi less(13,0);

  for(int i = 0;i<=12;i++){
    for(int j = 0;j<=9;j++){
      less[i]+=dp[i][j];
    }
  }

  for(int i = 1;i<=12;i++){
    less[i] = less[i-1]+less[i];
    //cout<<less[i]<<" ";
  }

  //cout<<endl;

  lli x = 0;

  for(lli b = 3234566667+1;b>=1;b/=2){
    while(check(x+b,k,less)) x+=b;
  }


  ///for(int i = 1;i<=9;i++){
    //cout<<dfs(i,i,1)<<endl;
  //}

  cout<<x+1;

}

 
 
 
 
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  //freopen("moobuzz.in","r",stdin);
  //freopen("moobuzz.out","w",stdout);
  int t = 1;
  //cin>>t;
  while(t--){
    solve();
  }
}

Measured memory_bytes: 3656
# import sys

dishTime = []

for _ in range(5):
  dishTime.append(int(input()))

# minVal = sys.maxsize # int型最大値
minVal = dishTime[0]
minIdx = 0

for i in range(len(dishTime)):
  if dishTime[i] % 10 != 0 and minVal > (dishTime[i] % 10): # 一の位の最小値を求める
    minVal = dishTime[i] % 10
    minIdx = i # 添え字を記憶


ans = 0
for i in range(len(dishTime)):
  if i == minIdx:
    ans += dishTime[i]
    continue
  
  if dishTime[i] % 10 == 0:
    ans += dishTime[i]
  else:
    ans += (int(dishTime[i] / 10) + 1) * 10

print(ans)




Measured memory_bytes: 3064