akhauriyash/Code-Regression huggingface dataset:
N,M,X = map(int,input().split())
C=[0 for i in range(N)]
A=[[] for i in range(N)]
min_cost=10000000000
for i in range(N):
    C[i],*A[i]=map(int,input().split())
for i in range(1<<N):
    L=[0 for i in range(M)]
    cost=0
    for j in range(N):
        if 1&(i>>j):
            for k in range(M):
                L[k]+=A[j][k]
            cost+=C[j]
    if min(L)>=X:
      min_cost=min(min_cost,cost)
if min_cost==10000000000:
  print(-1)
else:
  print(min_cost)

Measured memory_bytes: 9240
#include <iostream>

using namespace std;

#define INF 1<<29

int N, M, R;
int r[8];
int d[200][200];

int search(bool *visited, int from) {
  int min_cost = 0;
  
  for (int i = 0; i < R; i++) {
    if (!visited[i]) {
      visited[i] = true;
      int cost = search(visited, i);
      if (from == -1) {
        if (min_cost == 0 || min_cost > cost) {
          min_cost = cost;
        }
      }
      else if (min_cost == 0 || min_cost > cost + d[r[from]][r[i]]) {
        min_cost = cost + d[r[from]][r[i]];
      }
      visited[i] = false;
    }
  }

  return min_cost;
}

int main() {
  bool visited[8];

  cin >> N >> M >> R;
  for (int i = 0; i < R; i++) {
    cin >> r[i];
    r[i]--;
  }

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (i == j) {
        d[i][j] = 0;
      } else {
        d[i][j] = INF;
      }
    }
  }

  for (int i = 0; i < M; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    d[a][b] = c;
    d[b][a] = c;
  }

  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }

  for (int i = 0; i < R; i++) {
    visited[i] = false;
  }
  cout << search(visited, -1) << endl;

  return 0;
}


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

int main() {
  int N; cin >> N;
  vector<pair<int, int>> vec;
  for (int i = 0; i < N; i++)
  {
    int A, B; cin >> A >> B;
    vec.emplace_back(B, A);
  }

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

  long long t = 0;
  bool check = true;
  for (int i = 0; i < N; i++)
  {
    t += vec[i].second;
    if (t > vec[i].first) {

      check = false;
      break;
    }
  }
  if (check) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 2420
class Segtree():

    def __init__(self, n):
        self.num = 1 << (n - 1).bit_length()
        self.tree = [0] * 2 * self.num
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = max(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = max(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        res = 0
        l, r = l + self.num, r + self.num
        while l < r:
            if l & 1:
                res = max(res, self.tree[l])
                l += 1
            if r & 1:
                res = max(res, self.tree[r - 1])
            l, r = l >> 1, r >> 1
        return res


n, k = map(int, input().split())
a = [int(input()) for _ in range(n)]

num = max(a) + k + 1
seg_dp = Segtree(num)
for ai in a:
    tmp = seg_dp.query(max(ai - k, 0), min(ai + k + 1, num))
    seg_dp.update(ai, tmp + 1)
print(max(seg_dp.tree))


Measured memory_bytes: 109384
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include<unordered_map>
#include <set>
#include<unordered_set>
#include <queue>
#include <stack>
#include <vector>
#include<bitset>
#include<deque>
#include<string>
#include<list>
#include<iterator>
#include<sstream>
#include <algorithm>
#include <math.h>

#define lli long long int
#define ld long double
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);

using namespace std;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353 ;
const long long inf = 1LL << 61;
const int M = 1e6 + 500;
const lli ths = 1LL << 40;
const int NN = 5e5 + 6;

lli modexp(lli a,lli n)
{
    lli r=1;
    while(n){
        if(n&1)
            r=(r*a)%mod;
        a=(a*a)%mod;
        n>>=1;
    }
    return r;
}

void solve()
{
    lli n, a, b;
    cin>>n>>a>>b;
    lli ans = modexp(2, n);
    lli x = 1, y = 1;
//    if(n - a <= 1000000)
//        a = n - a;
//    if(n - b <= 1000000)
//        b = n - a;
    for(int i = 0; i < a; i ++) {
        lli t = ((n - i) % mod * modexp(i + 1, mod - 2) % mod) % mod;
        t %= mod;
        x *= t;
        x %= mod;
    }
    for(int i = 0; i < b; i ++) {
        lli t = ((n - i) % mod * modexp(i + 1, mod - 2) % mod) % mod;
        t %= mod;
        y *= t;
        y %= mod;
    }
    ans = (ans - x - y - 1 + mod) % mod;
    ans = (ans + mod) % mod;
    cout<<ans;
    cout<<'\n';
    return ;
}

/*
*/

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

    int t = 1;
//    cin>>t;
    while(t --)
    {
        solve();
    }
    return 0;
}


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

template <class T>
void print(vector<T>& v){
    for(T x:v) cout<<x<<" ";
    cout<<endl;
}

void sol(){
    int n;
    cin>>n;
    unordered_set<string> ms;
    string s;
    for (int i=0; i<n; ++i){
        cin>>s;
        ms.insert(s);
    }
    cout<<ms.size()<<endl;
}

int main() {
    // int t;
    // cin>>t;
    // for (int i=0; i<t; ++i){
        sol();
    // }
    return 0;
}

Measured memory_bytes: 17692
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll h; cin >> h;
    ll ans = 0;
    ll i = 0;
    while (h > 0) {
        ans += pow(2ll, i);
        h /= 2ll;
        ++i;
    }
    cout << ans << endl;
    return 0;
}

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

const int N = 10;

int n, m;
std::vector<int> g[N];
bool used[N];
int cnt;

void dfs(int k){
    bool flg = true;
    for(int i = 0; i < n; ++i)if(!used[i])flg = false;
    if(flg){
        ++cnt;
        return;
    }
    
    for(int i = 0; i < g[k].size(); ++i){
        int to = g[k][i];
        if(used[to])continue;
        used[to] = true;
        dfs(to);
        used[to] = false;
    }
}

int main(){
    std::cin >> n >> m;
    for(int i = 0; i < m; ++i){
        int a, b;
        std::cin >> a >> b;
        --a, --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    
    used[0] = true;
    dfs(0);
    std::cout << cnt << std::endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

typedef struct {
	int key, id;
} data;

typedef struct {
	data obj[400001];
	int size;
} min_heap;

void push(data x, min_heap* h)
{
	int i = ++(h->size);
	data tmp;
	h->obj[i] = x;
	while (i > 1) {
		if (h->obj[i].key < h->obj[i>>1].key) {
			tmp = h->obj[i>>1];
			h->obj[i>>1] = h->obj[i];
			h->obj[i] = tmp;
			i >>= 1;
		} else break;
	}
}

data pop(min_heap* h)
{
	int i = 1, j = 2;
	data output = h->obj[1], tmp;
	h->obj[1] = h->obj[(h->size)--];
	while (j <= h->size) {
		if (j < h->size && h->obj[j^1].key < h->obj[j].key) j ^= 1;
		if (h->obj[j].key < h->obj[i].key) {
			tmp = h->obj[j];
			h->obj[j] = h->obj[i];
			h->obj[i] = tmp;
			i = j;
			j = i << 1;
		} else break;
	}
	return output;
}

int main()
{
	int i, H, W, A, B;
	scanf("%d %d", &H, &W);
	
	int j, k, l[200002], r[200002], left[200002], right[200002], L, R, M;
	data d;
	min_heap h;
	h.size = 0;
	for (i = 0; i <= W + 1; i++) {
		l[i] = i;
		r[i] = i + 1;
		left[i] = i - 1;
		right[i] = i + 1;
	}
	for (i = 1, d.key = 0; i <= W; i++) {
		d.id = i;
		push(d, &h);
	}
	for (i = 1; i <= H; i++) {
		scanf("%d %d", &A, &B);
		/* L = 0;
		R = W;
		while (L < R) {
			M = (L + R + 1) / 2;
			if (l[M] < A[i]) L = M;
			else R = M - 1;
		}
		for (; l[L] == r[L] || l[L] >= A[i]; L = left[L]); */
		for (L = 0; l[right[L]] < A; L = right[L]);
		if (r[L] < B + 1) r[L] = B + 1;
		for (j = right[L]; r[j] <= r[L]; j = right[j]) l[j] = r[j];
		right[L] = j;
		left[j] = L;
		if (l[j] <= B) {
			l[j] = r[L];
			d.key = l[j] - j;
			d.id = j;
			push(d, &h);
		}
		
		while (h.size > 0 && l[h.obj[1].id] > h.obj[1].key + h.obj[1].id) pop(&h);
		if (h.size > 0) printf("%d\n", h.obj[1].key + i);
		else printf("-1\n");
	}
	
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 5728
def solve(N):
    ret = []
    for i in range(1, int(N ** 0.5) + 1):
        if N % i == 0:
            ret.append(max(len(str(i)), len(str(N // i))))
    return min(ret)


if __name__ == "__main__":
    N = int(input())
    print(solve(N))


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

using namespace std;
using LL = long long;
const int N = 1024;
const int INF = INT32_MAX;

int a[N];
int n;

int main() {
    ios_base::sync_with_stdio(false);

#ifdef CF_DEBUG
    freopen("../cf/input.txt","r",stdin);
#endif
    string s;
    cin>>s;
    int n=s.length();
    int res=0;
    for(int i=0;i<n/2;++i){
        if(s[i]!=s[n-1-i]){
            res+=1;
        }
    }
    cout<<res;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include <cassert>
    #include <cmath>

    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<int,int>;


    ll dp[105][100005];
    
    int main(){
       int n,w;cin>>n>>w;
       auto a = vec(int,n);
       auto v = vec(ll,n);
       rep(i,n)cin>>a[i]>>v[i];
       rep(i,n){
           REP(j,0,w){
               dp[i+1][j] = dp[i][j];
              if(j-a[i]>=0) dp[i+1][j] = max(dp[i][j],dp[i][j-a[i]]+v[i]);
           }
       }
       cout<<dp[n][w];
    }
    


Measured memory_bytes: 79360
# encoding: utf-8
N = int(input())

memo = [None] * (N + 1)

def cut(val, pow6, pow9):
    # print("#", val, pow6, pow9)
    rets = [100000] * 2
    if memo[val] != None: return memo[val]
    # maximum 6 ** x
    p6_tmp = pow6
    for x in list(range(pow6))[::-1]:
        if val < (6 ** (x + 1)): p6_tmp -= 1
        else:
            rets[0] = cut(val - (6 ** (x + 1)), p6_tmp, pow9) + 1
            break
    else: rets[0] = val
    # maximum 9 ** x
    p9_tmp = pow9
    for x in list(range(pow9))[::-1]:
        if val < (9 ** (x + 1)): p9_tmp -= 1
        else:
            rets[1] = cut(val - (9 ** (x + 1)), pow6, p9_tmp) + 1
            break
    else: rets[1] = val
    # return
    ret = min(rets)
    if memo[val] == None: memo[val] = ret
    return ret

print(cut(N, 32, 32))

Measured memory_bytes: 3828
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
#include <math.h>
#define rep(i,n) for (int i = 0; (i) < (n); ++ (i))
using namespace std;
 
int main(void){
    int count = 0;
    int n;
    while(1) {
        scanf("%d",&n);
        if(n == 0) break;
        if(count != 0) {
            cout << endl;
        }
        count = 1;
        
        vector<string> country(n);
        vector<int> point(n,0);
        vector<int> pointw(n,0);
        
        
        int lose,win,tie;
        rep(i,n) {
            cin >> country[i];
            scanf("%d",&win);
            scanf("%d",&lose);
            scanf("%d",&tie);
            point[i] = win*3 + tie;
            pointw[i] = win*3 + tie;
        }
        sort(point.begin(),point.end());
        int search;
        rep(i,n) {
            search = 0;
            while(pointw[search] != point[n-i-1]) search++;
            cout << country[search] << "," << point[n-i-1] << endl;
            pointw[search] = -1;
       }
    }
}


Measured memory_bytes: 3244
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=1e5+5;

int a, b, c, d;

int32_t main()
{
	IOS;
	int t;
	cin>>t;
	while(t--)
	{
		cin>>a>>b>>c>>d;
		bool check=1;
		if(a<b || d<b)
			check=0;
		int k=a%b;
		if(k>c)
			check=0;
		d%=b;
		if(c<b&&d>0)
		{
			for(int i=1;i<=1e5&&check;i++)
			{
				int t=(c+1-k+d-1)/d;
				k+=t*d;
				k%=b;
				if(k>c)
				{
					check=0;
					break;
				}
			}
		}
		if(check)
			cout<<"Yes"<<endl;
		else
			cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
function main(input) {
  input = input.trim();
  const [x,a,b] = input.split(" ").map(Number);

  if(Math.abs(x - a) < Math.abs(x - b)){
    console.log("A");
  }else{
    console.log("B");
  }
    
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 30768
//
// Created by 今村秀明 on 2017/01/20.
//

#include <stdio.h>
#include <set>
#include <math.h>

using namespace std;

int is_prime(int n){
    int ans = 1;
    if(n==2)return 1;
    for(int i = 2; i <= ceil(sqrt(n)); i++){
        if(n % i == 0){
            ans=0;
            break;
        }
    }
    return ans;
}

int main(){
    set<int> facts;
    int a,b,N,num;
    unsigned long long ans;

    scanf("%d", &N);

    for(int i=2;i<=N;i++){
        for(int j=2;j<=i;j++) {
            if (is_prime(j) && i % j == 0) {
                facts.insert(j);
            }
        }
    }

    ans = 1;
    for(int i : facts){
        num = 1;
        for(int n = 1;n <= N; n++){
            a = n;
            while(1){
                b = a % i;
                a = a / i;
                if(a==0 || b!=0){
                    break;
                }else{
                    num++;
                }
            }
        }
        ans = ans * num % 1000000007;
    }

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

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    string n;
    int tmp = 0;
    cin >> n;

    for (int i = 0; i < n.length(); i++) {
        tmp += n[i] - '0';
    }

    if (tmp % 9 == 0) {
        cout << "Yes";
    } else {
        cout << "No";
    }

    return 0;
}

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

using namespace std;

struct P{
  string a,b,c;
  P(){}
  P(string &a,string &b,string &c) : a(a),b(b),c(c) {}
};

vector<P> rules,ans;
map<string,bool> mp;

bool check(P p){
  for(int i = 0 ; i < (int)rules.size() ; i++){
    P rule = rules[i];
    bool flg = false;
    for(int j = 0 ; j < 8 ; j++){
      if((rule.b[j] != '?' && rule.b[j] != p.a[j]) ||
         (rule.c[j] != '?' && rule.c[j] != p.b[j])){
        flg = true;
        break;
      }
    }
    if(!flg) return mp[rule.a];
  }
  return false;
}

int main(){
  int N,M;
  mp["permit"] = true;
  mp["deny"] = false;
  while(cin >> N >> M, (N|M)){
    P in;
    rules.clear(); ans.clear();
    while(N--){
      cin >> in.a >> in.b >> in.c;
      rules.push_back(in);
    }
    reverse(rules.begin(),rules.end());
    while(M--){
      cin >> in.a >> in.b >> in.c;
      if(check(in)){
        ans.push_back(in);
      }
    }
    int s = ans.size();
    cout << s << endl;
    for(int i = 0 ; i < s ; i++){
      cout << ans[i].a << " " << ans[i].b << " " << ans[i].c << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1464
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; (i) < int(n); ++ (i))
#define REP_R(i, n) for (int i = int(n) - 1; (i) >= 0; -- (i))
#define ALL(x) begin(x), end(x)
using namespace std;

template <typename UnaryPredicate>
int64_t binsearch(int64_t l, int64_t r, UnaryPredicate p) {
    assert (l <= r);
    -- l;
    while (r - l > 1) {
        int64_t m = l + (r - l) / 2;  // avoid overflow
        (p(m) ? r : l) = m;
    }
    return r;
}

int main() {
    // input
    int n; scanf("%d", &n);
    vector<int> a(n); REP (i, n) scanf("%d", &a[i]);
    vector<int> b(n); REP (i, n) scanf("%d", &b[i]);

    // solve
    int acc = 0;
    REP_R (k, 29) {
        sort(ALL(a));
        sort(ALL(b));
        int m = binsearch(0, n, [&](int j) {
            return b[j] >= (1 << k);
        });
        long long cnt = 0;
        for (int a_i : a) {
            bool pred = a_i & (1 << k);
            int l = binsearch(0, m, [&](int j) {
                return pred !=     bool((a_i + b[j]) & (1 << k));
            });
            int r = binsearch(m, n, [&](int j) {
                return pred != not bool((a_i + b[j]) & (1 << k));
            });
            cnt += pred ? n - (r - l) : r - l;
        }
        if (cnt % 2 == 1) {
            acc |= 1 << k;
        }
        REP (i, n) {
            a[i] &= ~ (1 << k);
            b[i] &= ~ (1 << k);
        }
    }

    // output
    printf("%d\n", acc);
    return 0;
}


Measured memory_bytes: 1792
import itertools
K, S = map(int, input().split())
ans = 0
for i in itertools.product(range(K+1), repeat=2):
    Z = S - sum(i)
    if 0 <= Z <= K:
      ans += 1
print(ans)
# for x in range(K+1):
#  for y in range(K+1):
#    z = S - x - y
#    if 0 <= z <= K:
#      ans += 1


Measured memory_bytes: 9244
#include <bits/stdc++.h>
#define VI vector<int> 
#define SI set<int>
#define QI queue<int> 
#define PII pair<int, int>
#define MP make_pair
#define PB push_back
#define REP(i,a,b) for(int i = a; i < b; ++i)
#define F for(int i = 0; i < n; ++i)
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define M 1000000007
using namespace std;

int main() 
{
    int n,m,k; cin>>n>>m>>k;
    vector<ll> a(n+1),b(m+1);
    REP(i,1,n+1) {cin>>a[i]; a[i] += a[i-1]; }
    REP(i,1,m+1) {cin>>b[i]; b[i] += b[i-1]; }

    int ans=0;

    for (int i = 0; i <= n; ++i)
    {
        int selb=1;
        if(k - a[i] >= 0) {
            selb = upper_bound(b.begin(),b.end(),k-a[i]) - b.begin();
            ans = max(ans,i+selb-1);
        } 
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 6404
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>

using ll = long long;
typedef unsigned long long ull;
typedef std::pair<ll, ll>P;
struct edge { ll to, cost; };
std::vector<edge>v[100010], w[100010];
typedef std::vector<std::vector<int>>ma;

ll min(ll a, ll b) {
	if (a >= b)return b;
	else return a;
}
ll max(ll a, ll b) {
	if (a >= b)return a;
	else return b;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

const ll Z = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
bool flag = true;
bool fl = true;
bool f = true;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
std::string abc = "abcdefghijklmnopqrstuvwxyz";

int main() {
	int n, a[100000], b[100000], ans = 0, ma = 0, mi = INF;
	std::cin >> n;
	for (int i = 0;i < n;i++) {
		std::cin >> a[i] >> b[i];
		mi = min(b[i], mi);
		if (mi == b[i])ma = a[i];
	}
	std::cout << ma + mi << std::endl;
}

Measured memory_bytes: 5760
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String a = sc.nextLine();
		String b = a.toLowerCase();
		if(a.equals(b)){
			System.out.println('a');
		}else{
			System.out.println('A');
		}
	}

}

Measured memory_bytes: 35752
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<stack>
#include<queue>
#include<sstream>
#include<string>
#include<set>
#include<array>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i);
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

using namespace std;

long long M=1000000007;

int main(){
 
  int n,max_t=0,max_a=0;
  cin >> n;
  vector<int> l = vector<int>(n,0);
  vector<bool> lb = vector<bool>(n,false);
  rep(i,n){
    cin >> l[i];
    if(l[i]>max_a) lb[i] = true;
    max_a = max(l[i],max_a);
  }
  rep(i,n){
    int a;
    cin >> a;
    l[i] = min(l[i],a);
    max_t = max(l[i],max_t);
  }
  
  int max_b=0;
  rep(i,n){
    if(l[n-i-1] > max_b) lb[n-i-1] = true;
    max_b = max(l[n-i-1],max_b);
  }


  if(max_t != max_a){
    cout << 0 << endl;
    return 0;
  }

  long long ans =1;
  rep(i,n){
   if(lb[i]) continue; 
   else  ans*=l[i];
   ans=ans%M;
  }

  cout << ans << endl;
}




Measured memory_bytes: 640
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	for {
		n := getNextInt(scanner)
		if n == 0 {
			break
		}
		sum := 0
		ll := make([]int, 1)
		rr := make([]int, 1)
		for i := 0; i < n/2; i++ {
			a := getNextInt(scanner)
			sum += a
			ll = merge(ll, a)
		}
		for i := n / 2; i < n; i++ {
			a := getNextInt(scanner)
			sum += a
			rr = merge(rr, a)
		}
		r := len(rr) - 1
		var ans cint
		ans = math.MaxInt32
		for l := 0; l < len(ll); l++ {
			for r >= 0 && ll[l]+rr[r] > 0 {
				r--
			}
			if r >= 0 {
				ans.minAs(cint(ll[l] + rr[r]).abs())
			}
			if r+1 < len(rr) {
				ans.minAs(cint(ll[l] + rr[r+1]).abs())
			}
		}
		fmt.Fprintln(writer, ans)
	}
}

type cint int64

func (ct *cint) minAs(x cint) *cint {
	*ct = ct.min(x)
	return ct
}
func (ct *cint) maxAs(x cint) *cint {
	*ct = ct.max(x)
	return ct
}
func (ct cint) min(x cint) cint {
	if ct > x {
		return x
	}
	return ct
}
func (ct cint) max(x cint) cint {
	if ct < x {
		return x
	}
	return ct
}
func (ct cint) abs() cint {
	return ct.max(-ct)
}
func merge(aa []int, a int) []int {
	n := len(aa)
	bb := make([]int, n)
	cc := make([]int, 0)
	for i := 0; i < n; i++ {
		bb[i] = aa[i] + a
		aa[i] = aa[i] - a
	}
	i := 0
	j := 0
	for i < n || j < n {
		if first(aa, bb, i, j, n) {
			cc = append(cc, aa[i])
			i++
			continue
		}
		cc = append(cc, bb[j])
		j++
	}
	return cc
}
func first(aa, bb []int, a, b, n int) bool {
	if a == n {
		return false
	}
	if b == n {
		return true
	}
	return aa[a] < bb[b]
}



Measured memory_bytes: 2312
n,m,x=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]

ans=10**9
for i in range(2**n):
  t_ans=0
  us=[0 for j in range(m)]
  for k in range(n):
    if (i>>k)&1:
      book=l[k]
      t_ans+=book[0]
      for p in range(m):
        us[p]+=book[p+1]

  if min(us)>=x:
    ans=min(ans,t_ans)

print(ans if ans!=10**9 else -1)

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

int main(){
  int X,N;
  cin >>X>>N;
  vector<int> p(N);
  for(int i = 0;i<N;i++){
    cin>>p.at(i);
  }
  int min_dis = 10000;
  for(int i = 0;i<102;i++){
    bool isin = false;
    for(int j = 0;j<N;j++){
      if(p.at(j)==i){
        isin = true;
      }
    }
    if(isin==false){    
      int dis = abs(X-i); 
   	  if(dis<min_dis){
        min_dis=dis;
      }
    }
  }
  for(int i = 0;i<102;i++){
    bool isin = false;
    for(int j = 0;j<N;j++){
      if(p.at(j)==i){
        isin = true;
      }
    }
    if(isin==false&&abs(X-i)==min_dis){    
      cout<<i<<endl;
      break;
    }
  }
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(x,n) for(ll i=x;i<n;i++)

void solve(){
    ll n;
    cin>>n;
    ll a[n];
    fr(0,n){
        cin>>a[i];
    }

    ll dp[n];
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(ll i=2;i<n;i++){
        dp[i]=min(abs(a[i]-a[i-1])+dp[i-1],abs(a[i]-a[i-2])+dp[i-2]);
    }
    cout<<dp[n-1]<<endl;

}

int main()
{
    solve();

    
}

Measured memory_bytes: 5148
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        int N = sc.nextInt();
        int M = sc.nextInt();
        List<List<Integer>> list = new ArrayList<>();
        for (int i = 0; i < N; ++i) {
            list.add(new ArrayList<>());
        }
        for (int i = 0; i < M; ++i) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            list.get(a).add(b);
            list.get(b).add(a);
        }

        for (int i = 0; i < N; ++i) {
            _out.println(list.get(i).size());
        }
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 22228
#include<iostream>
using namespace std;
int main(){
  int n,c=0,max=0;
  cin>>n;
  int a=1;
  for(int i=1;i<=n;i++){
  int b=i;
  c=0;
    while(b%2==0){
      b/=2;
      c++;
    }
    if(max<c){
      max=c;
      a=i;
    }
  }
    cout<<a;

}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
    int a,b,c;
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);

    if(a <= c && b >= c){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <tuple>
#include <climits>
#include <sstream>
using namespace std;

static const unsigned long long int MOD = 1000000007LL;

int main()
{
    int n, d[100001];

    cin >> n;

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

    sort(d, d + n);

    cout << d[n / 2] - d[n / 2 - 1];
}


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


const int M_V=100001;
const int logV=21;

vector<int> G[M_V];

int parent[logV][M_V];
int depth[M_V];

void dfs(int v,int p,int d){
    parent[0][v]=p;
    depth[v]=d;
    for(int i=0;i<G[v].size();i++){
        if(G[v][i]!=p) dfs(G[v][i],v,d+1);
    }
}

void init(int V,int root){
    dfs(root,-1,0);
    for(int k=0;k<logV-1;k++){
        for(int v=0;v<V;v++){
            if(parent[k][v]<0) parent[k+1][v]=-1;
            else parent[k+1][v]=parent[k][parent[k][v]];
        }
    }
}

int lca(int u,int v){
    if(depth[u]>depth[v]) swap(u,v);
    for(int k=0;k<logV;k++){
        if((depth[v]-depth[u])>>k&1){
            v=parent[k][v];
        }
    }
    if(u==v) return u;
    for(int k=logV-1;k>=0;k--){
        if(parent[k][u]!=parent[k][v]){
            u=parent[k][u];
            v=parent[k][v];
        }
    }
    return parent[0][u];
}


int main(){
    int n,u,v;cin >> n >> u >> v;
    u--,v--;
    for (int i = 0; i < n-1; i++) {
        int a,b;cin >> a >> b;
        a--,b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    init(n,0);
    vector<int> x(n,0),y(n,0);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        x[i] = depth[u]+depth[i]-2*depth[lca(u,i)]+1;
        y[i] = depth[v]+depth[i]-2*depth[lca(v,i)]+1;
        if(x[i] < y[i]){
            ans = max(ans , y[i] - 2);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 20480
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <string>
#include <cctype>
#include <algorithm>
#include <climits>
#include <list>

using namespace std;

int main()
{
	string str, order, p;
	int q, a, b;
	cin >> str >> q;
	for (int i = 0; i < q; i++) {
		cin >> order;
		if (order == "print") {
			cin >> a >> b;
			cout << str.substr(a, b - a + 1) << endl;
		}
		else if (order == "reverse") {
			cin >> a >> b;
			string oldstr = str.substr(a, b - a + 1);
			string newstr;
			for (int i = 0; i < b - a + 1; i++) {
				newstr += oldstr[b - a - i];
			}
			str.replace(a, b - a + 1, newstr);
		}
		else if (order == "replace") {
			cin >> a >> b >> p;
			str.replace(a, b - a + 1, p);
		}
	}
	return 0;
}

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

int main()
{
    int A, B;
    cin >> A >> B;
    if (A + B == 3)
    {
        cout << 3 << endl;
    }
    else if (A + B == 4)
    {
        cout << 2 << endl;
    }
    else
    {
        cout << 1 << endl;
    }
}


Measured memory_bytes: 256
/* https://atcoder.jp/contests/abc075/tasks/abc075_c */

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>

using namespace std;

/* {{{ Variables */
int N, M;
vector<int> A, B;
vector<vector<int>> edges;
set<int> reached_nodes;
/* }}} */

void dfs(int node)
{
  if (reached_nodes.find(node) != reached_nodes.end()) {
    return;
  }

  reached_nodes.insert(node);

  for (int e: edges[node]) {
    dfs(e);
  }

  return;
}

int main(int argc, char *argv[])
{
  /* {{{ Input */
  cin >> N >> M;

  A = vector<int>(M);
  B = vector<int>(M);
  edges = vector<vector<int>>(N);

  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    A.at(i) = --a;
    B.at(i) = --b;
  }
  /* }}} */

  /* {{{ Output */
  int cnt = 0;

  for (int i = 0; i < M; ++i) {
    edges = vector<vector<int>>(N);
    reached_nodes = set<int>();

    for (int j = 0; j < M; ++j) {
      if (j == i) {
        continue;
      }

      int a = A.at(j), b = B.at(j);

      edges.at(a).emplace_back(b);
      edges.at(b).emplace_back(a);
    }

    dfs(0);

    if ((int)reached_nodes.size() != N) {
      cnt++;
    }
  }

  cout << cnt << endl;
  /* }}} */

  return 0;
}


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

ll gcd(ll a, ll b, ll c) {
    return __gcd(__gcd(a, b), c);
}

void solve(long long K){
    ll ans = 0;
    for (ll i = 1; i <= K; i++) {
        for (ll j = 1; j <= K; j++) {
            for (ll k = 1; k <= K; k++) {
                ans += gcd(i, j, k);
            }
        }
    }
    cout << ans << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
// clang-format off
#pragma GCC diagnostic ignored "-Wunused-result"
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long long K;
    scanf("%lld",&K);
    solve(K);
    return 0;
}


Measured memory_bytes: 3692
#include<stdio.h>
#include<stdlib.h>

int main(){
  int i = 0 ,j,n,q,count = 0;
  int *S,*T;

  scanf("%d",&n);

  S = (int *)malloc(sizeof(int) * n);

  for(i = 0 ; i < n ; i++)
    scanf("%d",&S[i]);

  scanf("%d",&q);

  T = (int *)malloc(sizeof(int) * q);

  for(i = 0 ; i < q ; i++)
    scanf("%d",&T[i]);

  for(i = 0 ; i < q ; i++)
    for(j = 0 ; j < n ; j++)
      if(S[j] == T[i]){
	count++;
	break;
      }

  printf("%d\n",count);

  return 0;
}

Measured memory_bytes: 636
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<algorithm>
#include<map>
#pragma warning(disable: 4996)
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;


int main() {
	int N;
	cin >> N;
	vector <int> A(N);
	vector <int> F(N);
	rep(i, N) {
		cin >> A[i];
		F[A[i]-1] = i+1;
	}
	rep(i, N) {
		cout << F[i];
		if (i != N - 1) {
			cout << ' ';
		}
	}
	cout << endl;
	return 0;
}

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

int main(){
  string s;
  cin >> s;
  int sz = s.size();
  string ans = "";
  rep(i, sz){
    if(s.at(i) == 'B' && ans == "") ans = "";
    else if(s.at(i) == '0') ans = ans + "0";
    else if(s.at(i) == '1') ans = ans + "1"; 
    else ans.pop_back();

  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N=int(input())
A=[list(map(int,input().split())) for i in range(N)]

import math

road=0
for i in range(N):
  for j in range(N):
    distance=(A[i][0]-A[j][0])**2+(A[i][1]-A[j][1])**2
    road+=math.sqrt(distance)/2
    
path=2/N
print(road*path)


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

int main()
{
	int n, h;
	cin >> n >> h;
	vector<int> v(n);
	int maxa = 0;
	for (auto& i : v) {
		int a;
		cin >> a >> i;
		maxa = max(maxa, a);
	}

	sort(v.rbegin(),v.rend());

	int ret = 0;
	for (auto& i : v) {
		if (i <= maxa) {
			break;
		}

		h -= i;
		++ret;

		if (h <= 0) {
			break;
		}
	}

	if (0 < h) {
		ret += h / maxa;
		if (h % maxa != 0) {
			ret++;
		}
	}

	cout << ret << endl;

	return 0;
}

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

int main() {
  int a,b;
  cin>>a>>b;
  int c=min(a,b);
  rep(i,max(a,b)){
      cout<<c;
  }
  cout<<endl;
  
}




 







Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#define ll long long

using namespace std;
ll arr[100001]{};
ll n;
ll mem[100009]{};
ll MAX = 9223372036854775807;
ll minCost(ll i)
{
    if(i==n)
    {
        return 0;
    }
    ll &ret = mem[i];
    if(ret!=-1)
        return ret;
    ret = MAX;
    ll mov1 = MAX;
    ll mov2 = MAX;

    if(i+1<n)
        mov1 = abs(arr[i]-arr[i+1])+minCost(i+1);
    else if(i+1==n)
    {
        mov1 = minCost(i+1);
    }
    if(i+2<n)
    mov2 = abs(arr[i]-arr[i+2])+minCost(i+2);

    ret = min(ret, mov1);
    ret = min(ret,mov2);

    return ret;

}
int main()
{
    cin>>n;
   for(int i  = 0 ; i< 100009 ; i++)
   mem[i] = -1;


    for(int i = 0 ; i<n ; i++)
        cin>>arr[i];

    cout<<minCost(0)<<endl;
    return 0;
}


Measured memory_bytes: 4992
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#define SIZE 102

using namespace std;

void Inputdate(void);             //データ入力
void Solve(void);                 //データ処理と出力

int  n,m;
int  sum;                         //合計値
int  Price[SIZE];                 //素材の値段  
int  Quantity[SIZE];              //練金時に必要な素材の種類の数        
char Item[SIZE][SIZE];            //素材の名前
char Recipe[SIZE][SIZE];          //練金の結果
char Material[SIZE][SIZE][SIZE];  //練金に必要な素材
char Favorite[SIZE];              //最終練金結果

int main(){
  
  int  i,j;
  
  while(1){
   
    scanf("%d",&n);

    if(n==0){
      break;
    } 

    /*データの入力*/
    Inputdate();
    
    /*データ処理と出力*/
    Solve();
    
  }

  return 0;
}
void Inputdate(void){

  int  i,j;
  
  /*素材とその値段の入力*/
  
  for(i=0;i<n;i++){
    scanf("%s %d",Item[i],&Price[i]);
  }

  /*練金レシピの入力*/
  
  scanf("%d",&m);  //レシピ数の入力
  
  for(i=0;i<m;i++){
    
    scanf("%s %d",Recipe[i],&Quantity[i]);
    
    for(j=0;j<Quantity[i];j++){
      scanf("%s",Material[i][j]);
    }
    
  }
  
  /*最終練金結果の出力*/
  
  scanf("%s",Favorite);
  
  return;
  
}
void Solve(void){
  
  int i,j,k;
  int Total_Price=0;        //練金にかかった値段
  int Usual_Price=0;        //練金結果の通常価格
  
  /*レシピ数だけ繰り返す*/
  
  for(i=0;i<m;i++){
    
    /*最終でない練金結果の通常価格を探す*/
    
    j=0;
    while(strcmp(Item[j-1],Recipe[i])!=0){
      Usual_Price=Price[j];
      j++;
    }
    
    /*練金にかかる値段を調べる*/
    
    for(j=0;j<Quantity[i];j++){
      for(k=0;k<n;k++){
	if(strcmp(Item[k],Material[i][j])==0){
	  Total_Price+=Price[k];
	  k=n;
	}
      }
    }
    
    /*元値と練金後の価格を比較*/
    
    if(Total_Price<=Usual_Price){
      for(k=0;k<n;k++){
	if(strcmp(Item[k],Recipe[i])==0){
      Price[k]=Total_Price;
      k=n;
      }
    }
    } 
    
    Total_Price=0;
  }

  /*最終練金結果の価格を調べる*/

  for(i=0;i<n;i++){
    if(strcmp(Favorite,Item[i])==0){
      printf("%d\n",Price[i]);
      break;
    }
  }

  return;
}

Measured memory_bytes: 1292
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;
typedef long long LL;
typedef long double DD;
const int inf = 1e9;
const int mo= 1e9+7;
const int N = 200010;
char s[N];


int main(){
	scanf("%s",s+1);
	int n=strlen(s+1);
	int ans=0;
	for(int i=2;i<=n;i++)
		if(s[i]!=s[i-1])
			ans++;
	printf("%d\n",ans);
	return 0;
}

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

long long n,m,ans=0;

int main()
{ 
	cin >> n >> m;
	if(n>2 && m>2)
		ans += (n-2)*(m-2);
	if(n == 1 || m == 1)
	{
		if(n == 1 && m == 1)
			ans += 1;
		else
			ans += n+m-3;
	} 
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
data class PC(val p: Int, val c: Int) {
    constructor(pc: List<Int>): this(pc[0], pc[1])
}
fun main(args: Array<String>) {
    var (D, G) = listOfInt()
    val pc = Array(D) { PC(listOfInt()) }
    var ans = Int.MAX_VALUE
    var mask = 0
    while(mask < 1.shl(D)) {
        try {
            var s = 0
            var num = 0
            var rest_max = -1
            for (d in 0 until D) {
                if (mask.ushr(d) and 1 != 0) {
                    s += 100 * (d + 1) * pc[d].p + pc[d].c
                    num += pc[d].p
                } else rest_max = d
            }
            if (s < G) {
                val s1 = 100 * (rest_max + 1)
                val need = (G - s + (s1 - 1)) / s1
                if (need >= pc[rest_max].p) continue
                num += need
            }
            ans = Math.min(ans, num)
        } finally {
            mask += 1
        }
    }
    println(ans)
}

fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun nextInt(offset: Int = 0) = nextInt() + offset
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }


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

using namespace std;

int main(){
  int n,m;
  int h[110000],vis[110000]={0};
  cin>>n>>m;
  for(int i = 1;i <= n;i++)scanf("%d",&h[i]);
  for(int i = 1;i <= m;i++)
  {
  	int x,y;
  	scanf("%d%d",&x,&y);
  	if(h[x]>h[y]) vis[y]=1;
    if(h[x]==h[y]) vis[y]=vis[x]=1;
    if(h[x]<h[y]) vis[x]=1;
  }
  int ans = 0;
  for(int i = 1;i <= n;i++)
   if(vis[i]==0) ans++;
  cout<<ans<<endl;
  return 0;
}


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

#define pb push_back
#define mp make_pair
#define all(n) (n).begin(),(n).end()
#define fi first
#define se second

typedef pair<int, int> PII;
typedef long long ll;

const int MOD = 1e9+7;
const int MAXN = 1e6+5;
int cop[MAXN],v[MAXN];

int main() {

	ios::sync_with_stdio(0);
	cin.tie(0);
	cop[1]=1;
	for (int i=2;i<=1000001;++i) {
		if (cop[i]) continue;
		cop[i]=i;
		for (ll j=i*1LL*i;j<=1000001;j+=i) {
			cop[j]=i;
		}
	}
	int n,f,l;
	cin >> n;
	bool pair=true;
	cin >> l;
	f=l;
	for (int i=1;i<n;i++) {
		int a;
		cin >> a;
		f=__gcd(f,a);
		if (pair) {
			int cur = a;
			while (cur!=1) {
				int lfac = cop[cur];
				if (v[lfac]) {
					pair=false;
					break;
				}
				while (cur%lfac==0) cur/=lfac;
				v[lfac]=1;
			}
		}
	}
	if (pair) cout << "pairwise coprime\n";
	else if (f==1) cout << "setwise coprime\n";
	else cout << "not coprime\n";
}

Measured memory_bytes: 11424
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n = int(input())
    E = [[] for _ in range(n)]
    for _ in range(n - 1):
        u, v = map(int,input().split())
        u -= 1; v -= 1
        E[u].append(v)
        E[v].append(u)
    deg = [len(E[v]) - 1 for v in range(n)]
    deg[0] += 1

    topological_sort = []
    parent = [None] * n
    stack = [(~0, -1), (0, -1)] # (v, p)
    while stack:
        v, p = stack.pop()
        if v >= 0:
            parent[v] = p
            for nv in E[v]:
                if nv == p:
                    continue
                stack.append((~nv, v))
                stack.append((nv, v))
        else:
            if deg[~v] == 0:
                topological_sort.append(~v)
            deg[p] -= 1

    dp = [[None] * 2 for _ in range(n)]
    for v in topological_sort:
        white = black = 1
        for nv in E[v]:
            if nv == parent[v]:
                continue
            white *= dp[nv][0] + dp[nv][1]
            black *= dp[nv][0]
            white %= MOD
            black %= MOD
        dp[v][0] = white
        dp[v][1] = black

    print((dp[0][0] + dp[0][1]) % MOD)
resolve()

Measured memory_bytes: 82788
#include <stdio.h>
int main(void)
{
        int N,K,i,a=1;
        scanf("%d",&N);
        scanf("%d",&K);
        for(i=0;i<N;i++){
        if (a*2<a+K) a=a*2;
        else         a=a+K;
        }
        printf("%d\n",a);
        return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  if (a + b == c || a + c == b || b + c == a) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

ll solve1(ll N, ll S) {
  for (ll i=2; i*i<=N; i++) {
    ll tmp = N;
    ll s = 0;

    while (tmp) {
      s += tmp % i;
      tmp /= i;
    }

    if (s == S) {
      return i;
    }
  }

  return LLINF;
}

ll solve2(ll N, ll S) {
  ll t = 0;

  for (ll i=1; i*i<N; i++) t = i;

  for (ll i=t; i>=1; i--) {
    // t * b + x = N
    // t + x = S

    ll x = S - i;
    ll b = (N - x) / i;

    if (i * b + x == N && 0 <= x && x < b && i < b) {
      debug(i); debug(x);
      return b;
    }
  }

  if (S == N) {
    return N + 1;
  }

  return LLINF;
}

int main(){
  ll N, S;

  cin >> N >> S;

  ll ans = solve1(N, S);

  ans = min(ans, solve2(N, S));

  if (ans == LLINF) {
    ans = -1;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<stdio.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  for(int i=0;i<s.length();i++){
    int x=((s[i]-'A')+n)%26;
    putchar('A'+x);
  }
  return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use proconio::derive_readable;
use proconio::fastout;
#[allow(unused_imports)]
use num::Integer;
#[allow(unused_imports)]
use itertools::Itertools;

#[fastout]
fn main() {
  input! {
    n: usize,
    a: [i64; n],
  }
  let mut sum = vec![0; n+2];
  for (i, &x) in a.iter().enumerate() {
    sum[i+2] = sum[i] + x;
  }
  if n % 2 == 0 {
    let mut ans = - (1i64 << 60);
    let mut i = 0;
    while i <= n {
      ans = cmp::max(ans, sum[i] + sum[n+1] - sum[i+1]);
      i += 2;
    }
    println!("{}", ans);
  } else {
    let mut ans = - (1i64 << 60);
    let mut right = vec![- (1i64 << 60); n+3];
    let mut i = n;
    loop {
      right[i] = cmp::max(right[i+2], sum[i] + sum[n+1] - sum[i+1]);
      if i < 2 {
        break;
      }
      i -= 2;
    }
    let mut j = 0;
    while j < n {
      ans = cmp::max(ans, right[j+1] - sum[j+1] + sum[j]);
      j += 2;
    }
    println!("{}", ans);
  }
}


Measured memory_bytes: 8848
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<string,int>;
using T = tuple<string,int,int>;

int main(){
  int n,m; cin >> n >> m;
  vector<vector<int>> s(m); 
  for(int i = 0; i < m; i++){
    int k; cin >> k;
    for(int j = 0; j < k; j++){
      int a; cin >> a;
      s[i].push_back(a);
      s[i][j]--;
    }
  }
  vector<int> p(m);
  for(int i = 0; i < m; i++){
    cin >> p[i];
  }
  ll ans = 0;
  for(int bit = 0; bit < (1<<n); bit++){
    bool flg = true;
    for(int i = 0; i < m; i++){
      int sum = 0;
      for(auto v: s[i]){
        if(bit & (1<<v)) sum++;
      }
      if(sum % 2 != p[i]) flg = false;
    }
    if(flg) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256