akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

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

#define ll long long

int main()
{
	ll n, m, ans = 1;
	vector<ll> divisor;
	cin >> n >> m;

	if (n == 1) {
		cout << m << endl;
		return 0;
	}

	for (ll i = 1; i * i <= m; i++) {
		if (m % i == 0) {
			divisor.push_back(i);
			divisor.push_back(m/i);
		}
	}
	sort(all(divisor));
	for (auto d: divisor) {
		if (d <= m / n)
			ans = d;
		else
			break;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N = int(input())
D = [None] + [int(input()) for _ in range(N)]

parent = [None] * (N+1)
size = [None] + [1] * N # 部分木の頂点数、自分を含む
d_to_i = {d:i for i,d in enumerate(D)}
D_desc = sorted(D[1:],reverse=True)
D_subtree = [0] * (N+1)
edges = []

bl = True
for d in D_desc[:-1]:
    i = d_to_i[d]
    d_parent = d - N + 2*size[i]
    if d_parent not in d_to_i:
        bl = False
        break
    p = d_to_i[d_parent]
    edges.append('{} {}'.format(i,p))
    parent[i] = p
    size[p] += size[i]
    D_subtree[p] += D_subtree[i] + size[i]

root = d_to_i[D_desc[-1]]
bl &= (D_subtree[root] == D[root])

if bl:
    print('\n'.join(edges))
else:
    print(-1)

Measured memory_bytes: 37632
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
typedef pair<int, int> P;
int main(void){
    int n, p[100000];
    vector<P> v;
    set<int> s;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> p[i];
        v.push_back(P(p[i], i));
    }
    sort(v.begin(), v.end(), greater<P>());

    long long ans = 0;
    s.insert(-1);
    s.insert(n);
    for(int i = 0;i <n;i++){
        int a = 0, b, c, d = 0;
        int val = v[i].first;
        int ind = v[i].second;
        auto itr = s.upper_bound(ind);
        int right = *itr;
        itr--;
        int left = *itr;
        b = ind - left;
        c = right - ind;
        if(left != -1){
            itr--;
            a = left - (*itr);
            itr++;
        }
        if(right != n){
            itr++;
            itr++;
            d = (*itr) - right;
        }
        ans += (long long)(a*c+b*d)*val;
        s.insert(ind);
        //cout << val << " " << ans << endl;
        //cout << a << b << c << d << endl;
    }
    cout << ans << endl;
}


Measured memory_bytes: 6132
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  string S, T;
  int A, B;
  string U;
  cin >> S >> T;
  cin >> A >> B;
  cin >> U;
  if(S == U) {
    A--;
  }
  if(T == U) {
    B--;
  }
  cout << A << " " << B << endl;
}

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

using namespace std;

int main()
{
    int A,B;
    cin >> A >> B;
    int  tap = 1;
    int ans = 0;
    while(tap < B){
        tap+=A-1;
        ans++;
    }
    cout<<ans<<endl;
            return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
vector <int>  mp[101];
int A,B,C,D;
int n;
int main() {


  cin >> n;

  cin >> A >> B >> C >> D;

  A--;
  B--;
  C--;
  D--;
  

  int ans = 100000000;
  int c=n;
  while(c !=0) {
    
    int t = 0;
    int count = 0;
    /*
    for(int i=0;i<n;i++)mp[i].clear();
    
    for(int i=0;i<n;i++) {
      if(c == count) t++,count = 0;
      mp[t].push_back(i);
      count++;
    }
    */
    int x[4]={A%c,B%c,C%c,D%c};
    int y[4]={A/c,B/c,C/c,D/c};
    /*
    for(int i=0;i<n;i++) {
      if(mp[i].size()==0)break;
      for(int j=0;j<mp[i].size();j++) {
	if(mp[i][j] == A) x[0] = j,y[0] = i;
	if(mp[i][j] == B) x[1] = j,y[1] = i;
	if(mp[i][j] == C) x[2] = j,y[2] = i;
	if(mp[i][j] == D) x[3] = j,y[3] = i;
      }
    }
    */
    int ABx,DCx,ABy,DCy;
    ABx = x[0] - x[1] ;
    DCx = x[2] - x[3];
    if(ABx<0) ABx*=-1;
    if(DCx<0) DCx*=-1;
    ABy = y[0]-y[1];
    DCy = y[2] - y[3];
    if(ABy < 0) ABy *= -1;
    if(DCy < 0) DCy *= -1;

    if(ABx+ABy+DCx+DCy < ans) ans = ABx+ABy+DCx+DCy;
    if(ans==1){
      for(int I=0;I<4;I++)cout<<x[I]<<' '<<y[I]<<endl;
    }

    /*
    for(int i=0;i<n;i++) {
      if(mp[i].size()==0)break;
      for(int j=0;j<mp[i].size();j++) 
	cout <<mp[i][j] << " ";
      cout << endl;
    }
    */
    c--;
  }
    
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1164
fn read<T: std::str::FromStr>() -> Vec<T> {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.split_whitespace()
        .map(|x| x.parse().ok().unwrap())
        .collect()
}

fn main() {
    let n: usize = read()[0];
    let a: Vec<i64> = read();
    let mut diff = 2 * a[0] - a.iter().sum::<i64>();
    let mut ans = diff.abs();
    for i in 1..n - 1 {
        diff += 2 * a[i];
        ans = std::cmp::min(ans, diff.abs());
    }
    println!("{}", ans);
}


Measured memory_bytes: 10492
// "include" {{{
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <tuple>
// }}}

using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int> 
#define int long long
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9+7;

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

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int k,a,b;
	cin >> k >> a >> b;
	k++;
	if(k <= a || a+2 > b){
		cout << k << '\n';
		return 0;
	}
	k -= a;
	cout << k / 2 * (b - a) + k % 2 + a << '\n';
	return 0;	
}


Measured memory_bytes: 256
x = input()
ll = len(x)

now = 0
mod_dict = {}
mod_dict[0] = 1
for i in reversed(range(len(x))):
    now = now + int(x[i]) * pow(10, (ll - i - 1), 2019)

    now %= 2019
    if now not in mod_dict:
        mod_dict[now] = 1
    else:
        mod_dict[now] = mod_dict[now] + 1

ans = 0
for v in mod_dict.values():
    ans += v * (v-1) // 2
print(ans)



Measured memory_bytes: 9308
n=int(input())
x=list(map(int,input().split()))

ma=max(x)
mi=min(x)

ans=10**9
for i in range(mi,ma+1):
  t_ans=0
  for j in x:
   t_ans+=(i-j)**2
  ans=min(ans,t_ans)
print(ans)

Measured memory_bytes: 3064
n, *a = map(int, open(0).read().split())
a.sort()
ans = 1e10
for i in range(1, n):
    x, y = a[0], a[i]
    while y%x:
        y -= y//x*x
        x, y = y, x
    ans = min(ans, x)
print(ans)

Measured memory_bytes: 14052
ym = 0
my = 0

s = input()

hi = int(s[2:])
lo = int(s[:2])


def isym(l):
    if l == 0:
        return False
    if l <= 12:
        return True
    else:
        return False


ym = 0
my = 0
if isym(hi):
    ym = 1
if isym(lo):
    my = 1

if ym == 1 and my == 1:
    print('AMBIGUOUS')
if ym == 1 and my == 0:
    print('YYMM')
if ym == 0 and my == 1:
    print('MMYY')
if ym == 0 and my == 0:
    print('NA')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < (N); i++)
#define vec vector<int>
using namespace std;
int main()
{
    int N, ans = 0;
    cin >> N;
    char S;
    rep(i, N)
    {
        cin >> S;
        if (S == 'Y')
        {
            cout << "Four" << endl;
            return 0;
        }
    }
    cout << "Three" << endl;
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 61)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



int n, Q, a[101010], b[101010], c[101010];
int d[101010];
void solve(){
	cin >> n;
	i64 cnt = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		d[a[i]]++;
		cnt += a[i];
	}
	cin >> Q;
	for(int i = 0; i < Q; i++){
		cin >> b[i] >> c[i];
		cnt += d[b[i]]*(c[i]-b[i]);
		d[c[i]] += d[b[i]];
		d[b[i]] = 0;
		cout << cnt << endl;
	}
	
	
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 5228
#include <iostream>
#include <string>
#include <stack>
using namespace std;

int main()
{
  string line;
  while (getline(cin, line)) {
    if (line.find_first_of("\n") != string::npos)
      line.erase(line.end()-1);
    if (line.find_first_of("\r") != string::npos)
      line.erase(line.end()-1);

    if (line == ".")
      break;

    bool yes = true;
    stack<char> stk;
    for (unsigned int i = 0; i < line.size() && yes; ++i) {
      if (line[i] == '(') {
	stk.push('(');
      } else if (line[i] == ')') {
	if (stk.empty() || stk.top() != '(')
	  yes = false;
	else
	  stk.pop();
      } else if (line[i] == '[') {
	stk.push('[');
      } else if (line[i] == ']') {
	if (stk.empty() || stk.top() != '[')
	  yes = false;
	else
	  stk.pop();
      }
    }

    if (yes && stk.empty())
      cout << "yes" << endl;
    else
      cout << "no" << endl;
  }
  return 0;
}

Measured memory_bytes: 904
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <functional>
using namespace std;

typedef long long ll;

int main() {
	string s; cin >> s;
	string t = s;
	reverse(s.begin(), s.end());
	if (s == t) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(inti=a;i<=b;i++)

#define MOD 1000000009
typedef long long int ll;
typedef vector<int>vi;
typedef pair<int,int>pi;



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

ll ans =1000000000001;
for(ll i = 1;i*i<=n;i++)
{
    if(n%i==0)
    ans = min(ans,(i-1)+(n/i-1));
}
std::cout<<ans<<endl;

 return 0;
}


Measured memory_bytes: 3644
N = int(input())
name = []
alphabet = [chr(i) for i in range(97, 97+26)]

while 0 < N:
    num = N // 26
    mod = N % 26
    if 26 < num:
        if mod == 0:
            name += alphabet[-1]
            num -= 1
        else:
            name += alphabet[mod-1]
    else:
        if mod == 0:
            name += alphabet[-1]
            num -= 1
        else:
            name += alphabet[mod-1]
    N = num

name.reverse()
print(*name, sep='')

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


int main()
{
    int n,h;
    cin >>h>> n;
    int ans=0;
    int a[100000+3];
    for(int i=0;i<n;i++){
        cin >>a[i];
        ans+=a[i];
    }
    if(ans >= h){
        cout<<"Yes";
    }else {
        cout<<"No";
    }

}


Measured memory_bytes: 640
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
a = lr()
a.sort()
a1 = [0]
for num in a:
    a1.append(a1[-1]+num)
def sumArea(l,r):
    return a1[r]-a1[l]
ans = 1
for i in range(1,n):
    if a[n-i] > 2*sumArea(0,n-i):
        break
    else:
        ans+=1
print(ans)

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

using namespace std;

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

	vector<int> a(n);
	for(int i=0; i<n; ++i) {
		int j;
		cin >> j;
		a[j-1]=i+1;
	}

	for(auto i:a){
		cout << i << " ";
	}
	cout << endl;

	return 0;

}




Measured memory_bytes: 1152
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;


void main() {
    int N;
    int[] a;

    scan(N);
    a = readln.split.to!(int[]);

    long x = 0, y = a.sum(0L);
    long ans = long.max;

    foreach (i ; 0 .. N - 1) {
        x += a[i], y -= a[i];
        ans = min(ans, abs(x - y));
    }

    writeln(ans);
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 11264
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef long long LL;
typedef pair<int,int> pa;
typedef vector<int> vec;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
int n,x,y,nedge,dep[500010],o[500010],hed[500010],tot,t,too[500010],rot[500010],nxt[500010],ANS[500010],ans[500010],siz[500010],fa[500010],mx[500010],T[20000010],ls[20000010],rs[20000010];
void ae(int x,int y){
	nxt[++nedge]=hed[x];
	hed[x]=nedge;
	too[nedge]=y;
}
void mkt(int x,int l){
	o[x]=max(o[l],x);
	dep[x]=dep[l]+1;
	fa[x]=l;
	mx[x]=x;
	siz[x]=1;
	for (int i=hed[x];i;i=nxt[i]){
		int y=too[i];
		if (y==l) continue;
		mkt(y,x);
		mx[x]=max(mx[x],mx[y]);
		siz[x]+=siz[y];
	}
}
void pushup(int rt){
	if (T[ls[rt]]==0) ls[rt]=0;
	if (T[rs[rt]]==0) rs[rt]=0;
	T[rt]=T[ls[rt]]+T[rs[rt]];
}
void ins(int l,int r,int rt,int x,int y){
	if (l==r){
		T[rt]=y;
		return;
	}
	ls[rt]=rs[rt]=0;
	int m=l+r>>1;
	if (x<=m) ins(l,m,ls[rt]=++tot,x,y);
	else ins(m+1,r,rs[rt]=++tot,x,y);
	pushup(rt);
}
int mer(int l,int r,int x,int y){
	if (!x || !y) return x+y;
	if (l==r){T[x]+=T[y];return x;}
	int m=l+r>>1;
	ls[x]=mer(l,m,ls[x],ls[y]);
	rs[x]=mer(m+1,r,rs[x],rs[y]);
	pushup(x);
	return x;
}
void upd(int l,int r,int rt,int x,int y){
	if (l==r){
		T[rt]+=y;
		return;
	}
	int m=l+r>>1;
	if (x<=m) upd(l,m,ls[rt],x,y);
	else upd(m+1,r,rs[rt],x,y);
	pushup(rt);
}
int que(int l,int r,int rt,int L,int R){
	if (!rt) return 0;
	if (l>=L && r<=R) return T[rt];
	int m=l+r>>1,t=0;
	if (L<=m) t+=que(l,m,ls[rt],L,R);
	if (R>m) t+=que(m+1,r,rs[rt],L,R);
	return t;
}
void UPD(int l,int r,int rt,int L,int R){
	if (!rt) return;
	if (l>=L && r<=R){
		t+=T[rt];
		T[rt]=0;
		return;
	}
	int m=l+r>>1;
	if (L<=m) UPD(l,m,ls[rt],L,R);
	if (R>m) UPD(m+1,r,rs[rt],L,R);
	pushup(rt);
}
void dfs(int x,int l){
	rot[x]=++tot;
	ins(1,n,rot[x],x,1);
	for (int i=hed[x];i;i=nxt[i]){
		int y=too[i];
		if (y==l) continue;
		dfs(y,x);
		rot[x]=mer(1,n,rot[x],rot[y]);
	}
	t=0;
	if (x>1) UPD(1,n,rot[x],1,x-1);
	upd(1,n,rot[x],x,t);
	if (o[fa[fa[x]]]>1) ans[x]=que(1,n,rot[x],1,o[fa[fa[x]]]-1); // x zishu zhong , max < max(fafax -> 1)
}
void DFS(int x,int l){
	int t=0;
	for (int i=hed[x];i;i=nxt[i]){
		int y=too[i];
		if (y==l) continue;
		t+=ans[y];
	}
	ANS[x]+=t;
	for (int i=hed[x];i;i=nxt[i]){
		int y=too[i];
		if (y==l) continue;
		ANS[y]=ANS[x]-ans[y];
		DFS(y,x);
	}
}
int main(){
	cin>>n;
	FOR(i,2,n){
		getint(x),getint(y);
		ae(x,y),ae(y,x);
	}
	mkt(1,0);
	dfs(1,0);
	DFS(1,0);
	FOR(i,2,n) printf("%d ",ANS[i]+dep[i]-1);
	return 0;
}

Measured memory_bytes: 81408
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main(){
    double x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << setprecision(20) << sqrt(pow(x1-x2,2)+pow(y1-y2,2));
}


Measured memory_bytes: 3272
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int n, m, x; cin >> n >> m >> x;
	vector<int> c(n);
	vector<vector<int>> a(n, vector<int>(m));
	rep(i, n)
	{
		cin >> c[i];
		rep(j, m)cin >> a[i][j];
	}
	int res = 1e9;
	rep(i, pow(2, n))
	{
		bool ok = true;
		vector<int> v(m);
		int cost = 0;
		rep(j, n)
		{
			if (i&(1 << j))
			{
				cost += c[j];
				rep(k, m)
				{
					v[k] += a[j][k];
				}
			}
		}
		rep(j, m)if (v[j] < x)ok = false;
		if (ok)res = min(res, cost);
	}
	if (res == 1e9)cout << -1 << endl;
	else cout << res << endl;
}

Measured memory_bytes: 4080
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    long long A, B, C, ans=0, A1, B1, C1;

    cin >> A >> B >> C;

    if(A%2==1 || B%2==1 || C%2==1){
        cout << 0 << endl;
    }

    else{
        if(A==B && B==C){
            cout << -1 << endl;
        }

        else{
            while(A%2==0 && B%2==0 && C%2==0){
                A1=A;
                B1=B;
                C1=C;
                A=(B1+C1)/2;
                B=(C1+A1)/2;
                C=(A1+B1)/2;

                ans++;
            }

            cout << ans << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
def main():
    from sys import stdin
    input = stdin.readline
    n = int(input())
    ab = [list(map(int, input().split())) for _ in [0]*(n-1)]

    g = [set() for _ in [0]*n]
    [g[a-1].add(b-1) for a, b in ab]
    [g[b-1].add(a-1) for a, b in ab]

    mod = 10**9+7
    fact = [1, 1]
    inv = [pow(i, mod-2, mod) for i in range(n+1)]
    for i in range(2, n+1):
        fact.append(fact[-1]*i % mod)

    # merge:頂点aにbをマージするときのモノイド
    # adj_bu:ボトムアップ時の調整（a:値,i:頂点）
    # adj_td:トップダウン時の調整（a:値,i:頂点,p:親）
    # （根方向への調整と考えるとわかりやすい）
    # adj_fin:最終調整（a:値,i:頂点）
    def merge(a, b): return a * b % mod
    def adj_bu(a, i): return a * inv[size[i]] % mod
    def adj_td(a, i, p): return a * inv[n-size[i]] % mod
    def adj_fin(a, i): return a * fact[n-1] % mod

    # トポロジカルソートをする
    # T:木の隣接グラフ表現をset化
    # P:親
    # q:キュー
    # order:トポソしたもの
    T = g
    P = [-1]*n
    q = [0]
    ini = 1
    order = []
    while q:
        i = q.pop()
        order.append(i)
        for a in T[i]:
            if a != P[i]:
                P[a] = i
                T[a].remove(i)
                q.append(a)

    T = [list(i) for i in T]

    # サイズの処理を先に行う
    # size[i]:0を根とする根付き木における、iを根とする部分木の大きさ
    size = [1]*n
    for i in order[1:][::-1]:
        size[P[i]] += size[i]

    # ボトムアップ処理をする
    # ME:マージした値を一時保存
    # DP:DP値、MEを調整したもの
    ME = [ini]*n
    DP = [0]*n
    for i in order[1:][::-1]:
        DP[i] = adj_bu(ME[i], i)
        p = P[i]
        ME[p] = merge(ME[p], DP[i])
    DP[order[0]] = adj_fin(ME[order[0]], order[0])
    TD = [ini]*n

    # トップダウン処理をする
    for i in order:
        # 左からDP（結果はTDに入れている）
        ac = TD[i]
        for j in T[i]:
            TD[j] = ac
            ac = merge(ac, DP[j])
        # 右からDP（結果はacに入れている、一度しか使わないのでacで問題ない）
        # 例えばjが1から4だったとすると、TD[j]にはそれぞれ
        # TD[1] = 無、TD[2] = DP[1]、TD[3] = DP[1]*DP[2]、TD[4] = DP[1]*DP[2]*DP[3]
        # が入っている。
        # ここでacにそれぞれ無、DP[4]、DP[3]*DP[4]、DP[2]*DP[3]*DP[4]を
        # 順に入れていくといい感じになることがわかる。
        # 最後にTDに欠けているのは本来の根方向への補正なので、
        # jの部分木以外のサイズの逆数を掛けてやる必要がある。
        # これで、TDには根方向、MEにはそれ以外の方向のDP値が入っている状態になっているので
        # あとは掛けてやるだけでよい。
        ac = ini
        for j in T[i][::-1]:
            TD[j] = adj_td(merge(TD[j], ac), j, i)
            ac = merge(ac, DP[j])
            DP[j] = adj_fin(merge(ME[j], TD[j]), j)
    for i in DP:
        print(i)


main()


Measured memory_bytes: 144740
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
#define getbit(n, i) (((n) & (1LL << (i))) != 0) 
#define setbit0(n, i) ((n) & (~(1LL << (i)))) 
#define setbit1(n, i) ((n) | (1LL << (i))) 
#define togglebit(n, i) ((n) ^ (1LL << (i))) 
#define lastone(n) ((n) & (-(n))) 
char gap = 32;
template<typename T> 
ostream& operator<<(ostream &os, const vector<T> &v) { 
    os << '{'; 
    for (const auto &x : v) os << gap << x;
        return os << '}'; 
}
template<typename A, typename B> 
ostream& operator<<(ostream &os, const pair<A, B> &p) {
        return os << '(' << p.first << gap << p.second << ')';
}

template <class T>
void read(T &x) {
    char c;
    for (c = getchar(); c < '0' || c > '9'; c = getchar())
        ;
    for (x = 0; c <= '9' && c >= '0'; c = getchar()) x = x * 10 + (c & 15);
}
#define ll long long 
#define lll __int128_t
#define pb push_back
#define mp make_pair
typedef pair < int,int> ii;
typedef vector<ii> vii;
typedef vector<ll>vl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll hashPrime = 1610612741;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n,i,j,k,l,m;
    cin >> n;
    for (i = -1000; i <= 1000;i++){
        for (j = -1000;j<=1000;j++){
            ll res = (i * i * i * i * i) - (j * j * j * j * j);
            if(res==n){
                cout << i << " " << j << "\n";
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3656
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#define MOD 1000000007
using namespace std;
typedef long long ll;

template <typename Tp> inline void getint(Tp &num){
	register int ch, neg = 0;
	while(!isdigit(ch = getchar())) if(ch == '-') neg = 1;
	num = ch & 15;
	while(isdigit(ch = getchar())) num = num * 10 + (ch & 15);
	if(neg) num = -num;
}

inline int kazu(int a, const int &b) {return (a += b) >= MOD ? a - MOD : a;}
inline int hiku(int a, const int &b) {return (a -= b) < 0 ? a + MOD : a;}

inline ll fastpow(ll bas, ll ex = MOD - 2){
	register ll res = 1; bas %= MOD;
	for(; ex; ex >>= 1, bas = bas * bas % MOD) if(ex & 1) res = res * bas % MOD;
	return res;
}

int N, A, B, C, Apow[100005] = {1}, Bpow[100005] = {1}, ans = 0;
int fac[200005] = {1}, ifac[200005];

inline ll binom(const int &n, const int &m) {return fac[n] * (ll)ifac[m] % MOD * ifac[n - m] % MOD;}

int main(){
	getint(N), getint(A), getint(B), getint(C);
	for(register int i = 1; i <= (N << 1); i++) fac[i] = fac[i - 1] * (ll)i % MOD;
	ifac[N << 1] = fastpow(fac[N << 1]);
	for(register int i = (N << 1); i >= 1; i--) ifac[i - 1] = ifac[i] * (ll)i % MOD;
	int tot = A + B;
	A = A * fastpow(tot) % MOD;
	B = B * fastpow(tot) % MOD;  // Ignore the probability of C(draw)
	C = C * fastpow(100) % MOD;  // Shrink C to 1/100
	for(register int i = 1; i <= N; i++){
		Apow[i] = Apow[i - 1] * (ll)A % MOD;
		Bpow[i] = Bpow[i - 1] * (ll)B % MOD;
	}
	for(register int i = 0; i < N; i++)  // Aoki has i wins while Takahashi reaches N wins
		ans = kazu(ans, Apow[N] * (ll)Bpow[i] % MOD * binom(N - 1 + i, i) % MOD * (N + i) % MOD);
	for(register int i = 0; i < N; i++)  // Takahashi has i wins while Aoki reaches N wins
		ans = kazu(ans, Apow[i] * (ll)Bpow[N] % MOD * binom(N - 1 + i, i) % MOD * (N + i) % MOD);
	return printf("%lld\n", ans * (1 + C * fastpow(MOD + 1 - C) % MOD) % MOD), 0;  // Calculate the extra while considering C
}


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

#define int long long
#define pb push_back
#define MOD 1000000007
int power(int x, unsigned int y, int p) 
{ 
    int res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or  
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p;   
    } 
    return res; 
} 
  
signed main(){
    int n, K;
    cin>>n>>K;
    vector<int> vec;
    int tmp;
    for(int i=0; i<n; i++){
        cin>>tmp;
        vec.pb(tmp);
    }
    int inv = 0;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            if(vec[i] > vec[j]){
                inv  =  inv%MOD + 1;
                inv %= MOD;
            }
        }
    }
    int res = ((K%MOD)*(inv%MOD))%MOD;
    res %= MOD;

    for(int i=0; i<n; i++){
        tmp = 0;
        for(int j=0; j<n; j++){
            if(vec[i] > vec[j]){
                tmp = tmp%MOD + 1;
                tmp %= MOD;
            }
        }
        int mul = ((K%MOD)*((K-1)%MOD))%MOD;
        mul = (mul*power(2,MOD-2,MOD))%MOD;
        res += ((mul%MOD)*(tmp%MOD))%MOD;
        res %= MOD;
    }
    cout<<res%MOD<<endl;
    return 0;
}

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

int h, w;
cin >> h >> w;
vector<string> table(100);
rep(i,h) cin >> table[i];
bool possible=true;
rep(i,h){
    rep(j,w){
        if(table[i][j]=='#') {
            int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};
            int cnt=0;
            rep(k,4){
                int nx=i+dx[k], ny=j+dy[k];
                if(0<=nx && nx<=h-1 && 0<=ny && ny<=w-1 && table[nx][ny]=='#') cnt++;
                //cout << cnt << endl;
            }
            if(cnt==0) possible=false;
        }
        if(!possible) break;
    }
    if(!possible) break;
}

if(possible) cout << "Yes" << endl;
else cout << "No" << endl;
}

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

void Main() {
  int X, Y;
  cin >> X >> Y;

  bool exist = false;
  for (int i = 0; i <= X; i++) {
    if (i * 2 + (X - i) * 4 == Y) exist = true;
  }
  if (exist) cout << "Yes" << endl;
  else cout << "No" << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}



Measured memory_bytes: 3656
//include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std; 

using ll = long long;

const int N = 1000005, INF = 1000000005;

int arr[N];

vector < int > vec;

int div(int v){
    if(--arr[v])  return 0;
    for(int i = 1; i * i <= v; i++){
        if(v % i != 0)  continue;
        if(arr[i] || arr[v / i]){
            return 0;
        }
    }
    return 1;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, ans = 0;     cin >> n;
    for(int i = 0; i < n; i++){
        int v;  cin >> v;
        arr[v]++;
        vec.push_back(v);
    }
    for(int &v: vec){
        ans += div(v);
        arr[v]++;
    }   
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 7680
/*+lmake
 * STD = c++14
 * DEFINE += MDEBUG
 */
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#ifdef DEBUG
#define debug(args...)                                                                             \
    {                                                                                              \
        dbg, args;                                                                                 \
        cerr << endl;                                                                              \
    }
#else
#define debug(args...) // Just strip off all debug tokens
#endif

struct debugger
{
    template <typename T>
    debugger &operator,(const T &v)
    {
        cerr << v << " ";
        return *this;
    }
} dbg;
bool b1[10001], b2[10001];
void solve(long long Q, vector<long long> A, vector<long long> B)
{
    for (int i = 0; i < Q; ++i) {
        LL a = A[i], b = B[i];
        LL t = a * b;
        if (t <= 10000) {
            memset(b1, true, sizeof(b1));
            memset(b2, true, sizeof(b2));
            b1[a] = false;
            b2[b] = false;
            int ans = 0;
            for (int i = 1; i <= t; ++i) {
                if (!b1[i])
                    continue;
                for (int j = (t - 1) / i; j >= max(1LL, (t - 1) / i - 10); --j)
                    if (b2[j] && i*j<t) {
                        b1[i] = false;
                        b2[j] = false;
						++ans;
                        break;
                    }
            }
            for (int i = 1; i <= t; ++i) {
                if (!b2[i])
                    continue;
                for (int j = (t - 1) / i; j >= max(1LL, (t - 1) / i - 10); --j)
                    if (b1[j] && (i*j<t)) {
                        b2[i] = false;
                        b1[j] = false;
						++ans;
                        break;
                    }
            }
			cout<<ans<<endl;
			continue;
        }
		--t;
        LL st = sqrt(static_cast<long double>(t));
		//if (st*st>t) --st;
		LL ans=2*st;
		if (st*(st+1)>=t) --ans;
		if (a!=b) --ans; 
		cout<<ans<<endl;
    }
}

int main()
{
#ifdef MDEBUG
	//freopen("in.txt","r",stdin);
#endif
    long long Q;
    scanf("%lld", &Q);
    vector<long long> A(Q - 1 + 1);
    vector<long long> B(Q - 1 + 1);
    for (int i = 0; i <= Q - 1; i++) {
        scanf("%lld", &A[i]);
        scanf("%lld", &B[i]);
    }
    solve(Q, A, B);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
const int MOD = 1e9 + 7;

int main() {
    int N, K;
    long long ans = 0;
    cin >> N >> K;
    for (int i = K; i <= N + 1; i++) {
        long long begin = 0, curL = i - 1, curR = N - i + 1, end = N;
        ans = (ans + (curR + end) * i / 2 - (begin + curL) * i / 2 + 1) % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <ctime>
 
using namespace std;
 
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
 
long gcd(long a, long b){
	if (a%b==0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}
}
 
long lcm(long a, long b){
	return (a*b) / gcd(a,b);
}
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; }
 
typedef long long ll;
 
const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-10;

int m[500][500];

int main(){
	int r, g;
	
	cin >> r >> g;
	
	cout << g*2 - r << endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
	public class Main {
	public static void main(String[] args) {
		
		
			Scanner sc=new Scanner(System.in);
			//there's only 1 2 and 3
			// sum = 6;
			int a=sc.nextInt();
			int b=sc.nextInt(); 
			
			
			int sum=a+b;
			
			System.out.println(6-sum);
}
	
	}

Measured memory_bytes: 26776
#include <stdio.h>

void swap(int *p, int *q);
void scn(char *str, int *p, int *q);

int main(void)
{
	int amida[31];
	int no_x;
	int no_y;
	int input;
	int to_jump;
	int i;
	char in_str[6];
	
	scanf("%d %d", &no_y, &no_x);
	
	for (i = 1; i <= no_y; i++) amida[i] = i;
	
	for (i = 0; i < no_x; i++){
		scanf("%6s", in_str);
		scn(in_str, &input, &to_jump);
		swap(&amida[input], &amida[to_jump]);
	}
	
	for (i = 1; i <= no_y; i++){
		printf("%d\n", amida[i]);
	}
	
	return (0);
}

void swap(int *p, int *q)
{
	int buf;
	
	buf = *p;
	*p = *q;
	*q = buf;
}

void scn(char *str, int *p, int *q)
{
	int i;
	
	*p = *q = i = 0;
	while (str[i] != ','){
		*p *= 10;
		*p += str[i] - '0';
		i++;
	}
	
	i++;
	
	while (str[i] != '\0'){
		*q *= 10;
		*q += str[i] - '0';
		i++;
	}
}

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

int main(void){
  vector<int> E(3);
  cin>>E[0]>>E[1]>>E[2];
  if(E[0]==E[1]&&E[1]==E[2]){
      cout<<"Yes"<<endl;
  }else{
      cout<<"No"<<endl;
  }
  return 0;
}

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

int N, K;
vector<vector<int>> edge;

int dfs(int now, int pre, int d, int m) {
    int res = 0;
    if (d > m) res++;
    for (int nxt : edge[now]) {
        if (pre == nxt) continue;
        res += dfs(nxt, now, d+1, m);
    }
    return res;
}

int main() {
    cin >> N >> K;
    edge.resize(N);
    for (int i = 0; i < N-1; i++) {
        int a, b;
        cin >> a >> b;
        a--;b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    int ans = N;
    if (K%2 == 0) {
        for (int i = 0; i < N; i++) {
            int cand = dfs(i, -1, 0, K/2);
            ans = min(ans, cand);
        }
        cout << ans << endl;
    }
    if (K%2 == 1) {
        for (int i = 0; i < N; i++) {
            for (int j : edge[i]) {
                if (i < j) continue;
                int cand = dfs(i, j, 0, (K-1)/2) + dfs(j, i, 0, (K-1)/2);
                ans = min(ans, cand);
            }
        }
        cout << ans << endl;
    }
     
    return 0;
}


Measured memory_bytes: 3900
#coding: euc-jp
class Main
  def self.main
    s = read
    l = s.length
    c = 0
    m = 0
    l.times do |i|
      if /[ATGC]/ === s[i] then
        c += 1
      else
        if m < c then
          m = c
        end
        c = 0
      end
      if m < c then
        m = c
      end
    end
    puts m
  end

  def self.read
    gets.chomp
  end
end

Main.main


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
int h[200001];
long long t[600001];
long long query(int index,int lb,int rb,int lq,int rq)
{
	if((lb==lq&&rb==rq)||lb==rb)
		return t[index];
	int mid=(lb+rb)/2;
	if(rq<=mid)
		return query(index*2,lb,mid,lq,rq);
	else if(lq>mid)
		return query(index*2+1,mid+1,rb,lq,rq);
	else
		return max(query(index*2,lb,mid,lq,mid),query(index*2+1,mid+1,rb,mid+1,rq));
}
long long  update(int index,int lb,int rb,int id,long long value)
{
	if(lb==rb&&lb==id)
		return t[index]=max(t[index],value);
	int mid=(lb+rb)/2;
	if(id<=mid)
		return t[index]=max(t[index],update(index*2,lb,mid,id,value));
	else
		return t[index]=max(t[index],update(index*2+1,mid+1,rb,id,value));
}

int main()
{
	int n,i;
	long long tmp;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&h[i]);
	}
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&tmp);
		update(1,1,n,h[i],query(1,1,n,1,h[i]-1)+tmp);
	}
	printf("%lld",t[1]);
	return 0;
}

Measured memory_bytes: 5120
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include <random>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pll pair<ll,ll>
#define pint pll
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

bool dp[200020],dp2[1000020];

int main(){
  ll a,b,c,d,e,f;
  cin >> a >> b >> c >> d >> e >> f;
  pint ans={0,0};
  rep(i,31)rep(j,31)dp[a*100*i+b*100*j]=true;
  rep(i,3001)rep(j,3001)dp2[c*i+d*j]=true;
  for(int i=0;i<=f;i+=100){
    if(!dp[i])continue;
    for(int j=0;i+j<=f;j++){
      if(!dp2[j])continue;
      if(j<=e*(i/100) && j*ans.first>=(i+j)*ans.second){
        ans={i+j,j};
      }
    }
  }
  cout << ans.first << ' ' << ans.second << endl;
return 0;}

Measured memory_bytes: 512
h, w = [int(i) for i in input().split()]
mod = 10 ** 9 + 7
dp = [[0] * (w + 1) for _ in range(h + 1)]
dp[0][0] = 1
for i in range(h):
    a = input()
    for j, k in enumerate(a):
        if i == 0 and j == 0:
            continue
        if k != "#":
            dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod
print(dp[h-1][w-1])


Measured memory_bytes: 50540
#include <bits/stdc++.h>
#define  rep(i,n) for(li i=0;i<(n);i++)
#define  red(i,n) for(li i=(n)-1;i>=0;i--)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a) 
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vs = vector<string>;


int main()
{
    ll a,b;
    cin>>a>>b;

    cout<<(a-1)*(b-1)<<endl;

    return 0;
}


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

int main(){
    using namespace std;
    unsigned long N, D, A;
    cin >> N >> D >> A;
    vector<pair<unsigned long, unsigned long>> enemies(N);
    for(auto& i : enemies){
        cin >> i.first >> i.second;
        (i.second += A - 1) /= A;
    }
    sort(enemies.begin(), enemies.end(), greater<>());
    unsigned long ans{0}, now{0};
    queue<pair<unsigned long, unsigned long>> pq;
    for(const auto& i : enemies){
        while(!pq.empty() && pq.front().first > i.first && (now += pq.front().second))pq.pop();
        auto k = i.second - min(i.second, ans - now);
        if(k)pq.emplace(i.first - min(i.first, D * 2), k);
        ans += k;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include<algorithm>
#include<queue>
#define X first
#define Y second
using namespace std;

pair<int,int> a[300010],c;
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > Q;

int main(){
	int n,ans=0;
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i].X>>a[i].Y;
	sort(a,a+n);
	long long sum=0;
	for(int i=0;i<n;i++){
		sum+=a[i].X;
		c.X=a[i].Y,c.Y=a[i].X;
		Q.push(c);
		while(!Q.empty()){
			if(sum<=Q.size()*Q.top().X)break;
			sum-=Q.top().Y;
			Q.pop();
		}
		if(ans<Q.size())ans=Q.size();
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 9368
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
s = len(str(N))
ans = 0
if s % 2 == 1:
    ans += (N - 10**(s-1)) + 1

for i in range(1,s,2):
    ans += 10**(i-1) * 9

print(ans)


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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

const string YES = "Yes";
const string NO = "No";

void solve(long long N, long long A, long long B, long long C, long long D, std::string S){
    bool double_shape = false;

    REP2(i, A, C) {
        if(i+1 != N && S[i] == '#' && S[i+1] == '#') double_shape = true;
    }

    REP2(i, B, D) {
        if(i+1 != N && S[i] == '#' && S[i+1] == '#') double_shape = true;
    }

    if(double_shape) {
        cout << NO << endl;
        return;
    }

    if(D < C) {
        if(S[B-2] == '.' && S[B] == '.') {
            cout << YES << endl;
            return;
        } 

        for(int i=B-1; i<D-1; i++){
            if(i+2 != N && S[i] == '.' && S[i+1] == '.' && S[i+2] == '.') {
                cout << YES << endl;
                return;
            }
        }

        cout << NO << endl;
    } else {
        cout << YES << endl;
    }
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long D;
    scanf("%lld",&D);
    std::string S;
    std::cin >> S;
    solve(N, A, B, C, D, S);
    return 0;
}


Measured memory_bytes: 772
import heapq
n, m = map(int, input().split())
*a, = map(lambda x: -x, map(int, input().split()))

heapq.heapify(a)
for i in range(m):
    _a = int(heapq.heappop(a)/2)
    heapq.heappush(a, _a)

print(sum(a)*-1)


Measured memory_bytes: 14252
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

int L,place;
set<int> edge[200050];
set<int> edge2[200050];

void DFS(int x,int dep){
  while(!edge[x].empty()){
    int y=*edge[x].begin();
    edge[x].erase(y);
    edge[y].erase(x);
    DFS(y,dep+1);
  }
  if(dep>L) place=x;
  L=max(L,dep);
  return;
}

void DFS2(int x,int dep){
  while(!edge2[x].empty()){
    int y=*edge2[x].begin();
    edge2[x].erase(y);
    edge2[y].erase(x);
    DFS2(y,dep+1);
  }
  L=max(L,dep);
  return;
}

int main(void){
  int N;
  cin >> N;
  rep(i,N-1){
    int x,y;
    cin >> x >> y;
    x--,y--;
    edge[x].insert(y);
    edge[y].insert(x);
    edge2[x].insert(y);
    edge2[y].insert(x);
  }
  rep(i,N){
    if(edge[i].size()==1){
      DFS(i,1);
      L=0;
      DFS2(place,1);
      break;
    }
  }
  if(L%3==2) cout << "Second" << endl;
  else cout << "First" << endl;
}

Measured memory_bytes: 60288
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  map<int,int> b;
  map<int,bool> f;
  int m=0;
  for(int _=0;_<n;_++){
    int a;
    cin>>a;
    b[a]++;
    f[a]=1;
    m=max(a,m);
  }
  for(auto a:b){
    if(a.second>1)
      f[a.first]=0;
    for(int i=2;a.first*i<=m;i++)
      if(b.count(a.first*i))
        f[a.first*i]=0;
  }
  int c=0;
  for(auto a:f)
    c+=(a.second?1:0);
  cout<<c<<endl;
}

Measured memory_bytes: 22292
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<utility>
#include<cmath>
#include<set>
#include<list>
#include<string>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<cstring>
#include<iterator>
#include<bitset>
#include<assert.h>
//#include<chrono>
//#include<time.h>
//#include<windows.h>
using namespace std;
 
//#define int ll
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef vector<int> VI;
typedef vector<long long int> VL;
static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
#define ALL(x) (x).begin(),(x).end()
#define YESNO(x) puts((x)?"YES":"NO")
struct edge {int /*from,*/to,cost;};

bool isOK(int n, set<int> s){
    string t = to_string(n);
    REP(i,LEN(t)){
        if(s.find(t[i]-'0')!=s.end()) return false;
    }
    return true;
}

main(){
    int n,k;
    cin >> n >> k;
    set<int> s;
    REP(i,k){
        int tmp;
        cin >> tmp;
        s.insert(tmp);
    }
    while(1){
        if(isOK(n,s)){
            printf("%d\n",n);
            break;
        }
        n++;
    }

    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)

def input():
    return sys.stdin.readline()[:-1]

n, q = map(int,input().split())
g = [[] for _ in range(n+1)]
for  _ in range(n-1):
    a,b = map(int,input().split())
    g[a].append(b)
    g[b].append(a)
points = [0]*(n+1)
for _ in range(q):
    p, x = map(int,input().split())
    points[p] += x
# print(g)
# print(points)
def dfs(e,preve = -1):
    for nexte in g[e]:
        # print(nexte)
        if nexte == preve:
            continue
        points[nexte] = points[nexte] + points[e]
        dfs(nexte,e)
dfs(1)
print(*points[1:])



Measured memory_bytes: 268436