akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

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

    int m;
    long long k;
    cin >> m >> k;
    vector<int> from(n-1);
    for(int i=0; i<n-1; ++i)
        from[i] = i;
    for(int i=0; i<m; ++i){
        int a;
        cin >> a;
        swap(from[a-2], from[a-1]);
    }

    vector<int> to(n-1);
    vector<int> curr(n-1);
    for(int i=0; i<n-1; ++i){
        to[from[i]] = i;
        curr[i] = i;
    }

    while(k > 0){
        if(k & 1){
            for(int i=0; i<n-1; ++i)
                curr[i] = to[curr[i]];
        }
        vector<int> to2(n-1);
        for(int i=0; i<n-1; ++i)
            to2[i] = to[to[i]];
        to.swap(to2);
        k >>= 1;
    }

    vector<long long> ans(n);
    ans[0] = x[0];
    for(int i=0; i<n-1; ++i)
        ans[curr[i]+1] = x[i+1] - x[i];
    for(int i=1; i<n; ++i)
        ans[i] += ans[i-1];
    for(int i=0; i<n; ++i)
        cout << ans[i] << endl;

    return 0;
}

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

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}

template <i64 mod = MOD>
struct ModInt{
    i64 p;

    ModInt() : p(0){}
    ModInt(i64 x){p = x >= 0 ? x % mod : x + (-x + mod - 1) / mod * mod;}

    ModInt& operator+=(const ModInt& y){p = p + *y - ((p + *y) >= mod ? mod : 0); return *this;}
    ModInt& operator-=(const ModInt& y){p = p - *y + (p - *y < 0 ? mod : 0); return *this;}
    ModInt& operator*=(const ModInt& y){p = (p * *y) % mod; return *this;}
    ModInt& operator%=(const ModInt& y){if(y)p %= *y; return *this;}

    ModInt operator+(const ModInt& y) const{ModInt x = *this; return x += y;}
    ModInt operator-(const ModInt& y) const{ModInt x = *this; return x -= y;}
    ModInt operator*(const ModInt& y) const{ModInt x = *this; return x *= y;}
    ModInt operator%(const ModInt& y) const{ModInt x = *this; return x %= y;}

    friend ostream& operator<<(ostream& stream, const ModInt<mod>& x){
        stream << *x;
        return stream;
    }

    friend ostream& operator>>(ostream& stream, const ModInt<mod>& x){
        stream >> *x;
        return stream;
    }

    ModInt& operator++(){p = (p + 1) % mod; return *this;}
    ModInt& operator--(){p = (p - 1 + mod) % mod; return *this;}

    bool operator==(const ModInt& y) const{return p == *y;}
    bool operator!=(const ModInt& y) const{return p != *y;}

    const i64& operator*() const{return p;}
    i64& operator*(){return p;}

};

using mint = ModInt<>;


signed main(){
    
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;


    auto mpow = [](auto x, i64 y){
     auto z = x;
     decltype(x) val = y & 1 ? x : decltype(x)(1);
     while(z *= z, y >>= 1)
      if(y & 1)
       val *= z;
     return val;
    };


    auto calc_fact = [mpow]{
     constexpr int N = 3e6;
     vector<mint> fact(N + 1, 1);
     vector<mint> inv(N + 1, 1);
     for(int i = 1; i < N; ++i){
      fact[i + 1] = fact[i] * (i + 1);
      inv[i + 1] = mpow(fact[i + 1], MOD - 2);
     }
     return make_pair(fact, inv);
    };
    vector<mint> fact, inv;
    tie(fact, inv) = calc_fact();

    auto ncr = [&fact, &inv](int n, int r){
     if(n < 0 || r < 0 || n < r)
      return mint(0);
     return fact[n] * inv[r] * inv[n - r];
    };

    mint ans = 0;
    for(int r = r1; r <= r2; ++r){
        mint val = (mint(c2 + 1) * ncr(r + c2 + 1, r) - mint(c1) * ncr(c1 + r, r)) * mpow(mint(r + 1), MOD - 2);
        ans += val;
    }
    cout << ans << endl;

}



Measured memory_bytes: 93952
n,m=map(int,input().split())
k=[list(map(int,input().split()))[1:]for _ in range(m)]
p=list(map(int,input().split()))
ans=0
for i in range(2**n):
  s=bin(i)[2:].zfill(n)
  f=True
  for j in range(m):
    x=k[j]
    c=0
    for h in x:
      if s[h-1]=="0":c+=1
    if c%2!=p[j]:f=False
  if f:ans+=1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define be(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};

int main()
{
    int h,w;
    while(cin>>h>>w)
    {
        if(h==0)return 0;
        int s=h*h+w*w;
        int hh=h+1;
        bool flag=0;
        rep(i,s,22501)
        {
            if(i!=s)hh=1;
            for(hh;hh<=150;hh++)
            {
                int hhh=hh*hh;
                int ss=i-hhh;
                int ww=sqrt(ss);
                if(hh>=ww)break;
                if(ww*ww==ss){cout<<hh<<" "<<ww<<endl;flag=1;break;}
            }
            if(flag)break;
        }
    }
}


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
#define r1 rt<<1
#define r2 rt<<1|1
#define fi first
#define se second
#define ri register int
#define rep(i,a,b) for(ri i=(a);i<=(b);++i)
#define rep2(i,a,b,c) for(ri i=(a);i<=(b);i+=(c))
#define REP(i,a,b) for(ri i=(a);i>=(b);--i)
#define REP2(i,a,b,c) for(ri i=(a);i>=(b);i-=(c))
using namespace std;

inline int read(){
	ri x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^'0'),c=getchar();
	return x*f;
}
inline ll readll(){
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^'0'),c=getchar();
	return x*f;
}
inline void write(ll x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10+'0');
}

const int N=305;
const ll inf=1e18;
int n,k,a[N];
ll f[N][N];

int main()
{
	n=read();k=read();
	rep(i,1,n)a[i]=read(),f[i][1]=a[i];
	rep(i,1,n){
		rep(j,2,n-k){
			f[i][j]=inf;
			rep(l,1,i-1){
				f[i][j]=min(f[i][j],f[l][j-1]+max(0,a[i]-a[l]));
			}
		}
	}ll ans=inf;
	rep(i,1,n)ans=min(ans,f[i][n-k]);
	printf("%lld\n",ans);
	return 0; 
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;
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; }

int main(){
    int n;cin>>n;
    lvec d(n);cinf(n,d);
    int m;cin>>m;
    lvec t(m);cinf(m,t);
    int l=0,r=0;
    sort(all(d));
    sort(all(t));
    bool ok=1;
    while(r<m){
        while(t[l]==t[r])r++;
        int u=r-l;
        int v=ub(all(d),t[l])-lb(all(d),t[l]);
        if(u>v){
            ok=0;
            break;
        }
        l=r;
    }
    cout<<(ok?"YES":"NO");
}

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

int main(){
  int n;
  int p = 0;
  int k = 0;
  cin >> n;
  vector<string> s(n);
  for (int i=0; i<n; i++){
    cin >> s.at(i);
  }
  sort(s.begin(), s.end());

  for (int i=1; i<n; i++){
    p++;
    if(s.at(i-1)!=s.at(i)){
      if(p>k){k=p;}
      p=0;
    }
  }
  p++;
  if(p>k){k=p;}

  p=0;
  for(int i=1; i<n; i++){
    p++;
    if(s.at(i-1)!=s.at(i)){
      if(p==k){cout << s.at(i-1) << endl; p=0;}
      p=0;
    }
  }
  
  p++;
  if(p==k){cout << s.at(n-1) << endl;}
}

Measured memory_bytes: 14208
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

//macro
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define EPS (1e-8)
#define equals(a,b)(fabs((a)-(b))<EPS)

using ll = long long;
using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vvll = vector<vll>;
//func
template<typename A, typename T>void assign2d(A&arr, ll H, ll W, T t) { arr.resize(H); REP(i, H) arr[i].assign(W, t); }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); REP(i, n)os << v[i] << (i == n - 1 ? "" : " "); return os; }
template <class T = int> inline T IN() { T x; cin >> x; return x; }
template<class T> inline void OUT(const T &x) { cout << x << "\n"; }
void YESNO(bool c) { OUT(c ? "YES" : "NO"); };
void YesNo(bool c) { OUT(c ? "Yes" : "No"); };
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); /*cout << fixed << setprecision(6);*/ } } pre__;

int main() {
	int X, A, B;
	cin >> X >> A >> B;
	if (B - A <= X) {
		if (B - A > 0) {
			OUT("safe");
		}
		else {
			OUT("delicious");
		}
	}
	else {
		OUT("dangerous");
	}
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	long long int n,m,ans;
	scanf("%lld %lld",&n,&m);
	ans = n * m - (2 * n + 2 * m) + 4;
        if(ans < 0)
        ans = ans * -1;
	printf("%lld",ans);
	return 0;
}

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

const bool DEBUG = false;

int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  int n2 = 1 << n;  // シフト演算子で2^nを作る
  vector<int> a(n2);
  for (size_t i = 0; i < n2; i++) cin >> a[i];
  sort(a.begin(), a.end());

  vector<int> s;  // 今の頂点集合．世代ごとに増えていく
  s.push_back(a.back());  // sの初期化．a.back()で末尾参照を取得 (最大値)
  a.back() = -1;  // 使用した要素は-1にすることにする．pop_back()で消さない
  for (size_t i = 0; i < n; i++) {  // n世代繰り返す
    vector<int> p = s;              // pに1世代前のデータを入れる
    sort(p.begin(), p.end());
    int ai = n2 - 1;
    while (p.size() > 0 && ai >= 0) {
      if (a[ai] == -1) {
        // すでに使用済みなら無視する
        --ai;
        continue;
      }
      if (a[ai] < p.back()) {
        // もしa[ai]がpの最大値よりも小さい (生成可能)なら
        s.push_back(a[ai]);  // 次世代にa[ai]を追加
        p.pop_back();        // 1世代前のpから候補を外す
        a[ai] = -1;          // a[ai]を使用済みに
      }
      --ai;
    }
    if (p.size() > 0) {
      // もし親として消化できてないノードがあるなら失敗
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 3060
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    return


def main():
    A, B = map(int, input().split())
    print(max(0, A - 2 * B))


if __name__ == '__main__':
    main()


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

using namespace std;

#define MAX 100
 
int main()
{
    int a, b, arr[MAX+1];
 
    while (cin >> a >> b) {
        memset(arr, 0, sizeof(arr));
	arr[--a]++;
	arr[--b]++;
 
	while (cin >> a >> b, (a | b)) {
	    arr[--a]++;
	    arr[--b]++;
	}
 
	bool flg = 0;
	if ((arr[0] % 2 == 1) && (arr[1] % 2==1)) flg = 1;
	for (int i = 2; i < MAX; i++) {
	    if(arr[i] % 2 == 1) flg = 0;
	}
        cout << (flg ? "OK" : "NG") << endl;
    }
    return 0;
}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

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

const int maxn = 2005;

int n, m;
int q;
int a[maxn][maxn];
string s;
int cnt[maxn][maxn];
int sum[maxn][maxn];
int row[maxn][maxn], col[maxn][maxn];
int dx[4] = {0, -1, 0, 1};
int dy[4] = {1, 0, -1, 0};

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> m >> q;
    for(int i = 1;i <= n;i++){
        cin >> s;
        for(int j = 0;j < m;j++){
            a[i][j + 1] = s[j] - '0';
        }
    }
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= m;j++){
            if(a[i][j] == 1){
                int tmp = 0;
                for(int k = 0;k < 4;k++){
                    int nx = i + dx[k];
                    int ny = j + dy[k];
                    if(a[nx][ny] == 0){
                        tmp++; 
                    }
                }
                cnt[i][j] = tmp;
            }
        }
    }
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= m;j++){
            if(a[i][j] == 1 and a[i - 1][j] == 1){
                row[i][j] = 1;
            }
            if(a[i][j] == 1 and a[i][j - 1] == 1){
                col[i][j] = 1;
            }
            col[i][j] += col[i - 1][j];
            row[i][j] += row[i][j - 1];
        }
    }
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= m;j++){
            cnt[i][j] += cnt[i - 1][j] + cnt[i][j - 1] - cnt[i - 1][j - 1];
            sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + a[i][j];
        }
    }
    for(int i = 1;i <= q;i++){
        int u, d, l, r;
        cin >> u >> l >> d >> r;
        int tmp = cnt[d][r] - cnt[u - 1][r] - cnt[d][l - 1] + cnt[u - 1][l - 1];
        int tmp1 = sum[d][r] - sum[u - 1][r] - sum[d][l - 1] + sum[u - 1][l - 1];
        tmp += row[u][r] - row[u][l - 1];
        tmp += row[d + 1][r] - row[d + 1][l - 1];
        tmp += col[d][l] - col[u - 1][l];
        tmp += col[d][r + 1] - col[u - 1][r + 1];
        int ans = tmp - tmp1 * 2;
        cout << ans / 2 << endl;
    }
    return 0;
}


Measured memory_bytes: 80256
#include <stdio.h>
int main(){
  int m,n,i,j,a[100][100],b[100],c[100];
  scanf("%d %d",&n,&m);
  for(i=0; i<n; i++){
    for(j=0; j<m; j++){
      scanf("%d ",&a[i][j]);
    }   
  }
  for(j=0; j<m; j++){
    scanf("%d",&b[j]);
  }
  for(i=0; i<n; i++){
    c[i]=0;
  }
  for(i=0; i<n; i++){
    for(j=0; j<m; j++){
      c[i]+=(a[i][j]*b[j]);
    }
  }//-----                          
 for(i=0; i<n; i++){
    printf("%d\n",c[i]);
  }
  return 0;
}


Measured memory_bytes: 2112
#include <iostream>


using namespace std;
int main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int c5 = 0;
  int c7 = 0;
  for (int i = 0; i < 3; ++i)  {
    int tmp;
    cin >> tmp;
    if (tmp == 5)c5++;
    else if (tmp == 7) c7++;
  }
  bool ans = (c5 == 2 && c7 == 1);

  if (ans) cout << "YES" << "\n"; else cout << "NO" << "\n";
  return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    
    int d = sc.nextInt();
    int t = sc.nextInt();
    int s = sc.nextInt();

    long ans = t*s;

    if(d <= ans){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }

    
    return;

  }
}



Measured memory_bytes: 35644
#include <stdio.h>

int isprime(int n) {
 for(int i = 2; i * i <= n; i++) {
	 if(n % i == 0) return 0;
 }
 return 1;
}

int main(){
	int n,i,min,max;
	int number[10000+2] = {0};
	for(i = 2;i < 10000;i++){
		number[i] = isprime(i);
	}
	while(scanf("%d",&n)){
		if(n == 0)break;
		max = 0; min = 0;
		for(i = n;i > 0;i--){
			//printf("%d  ",i);
			if(number[i] && number[i-2]){
				min = i-2;
				max = i;
				//printf("%d %d\n",i,i-2);
				break;
			}
		}
		printf("%d %d\n",min,max);
	}
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007


#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define lo(i,a,b) for(int i=a;i<b;i++)
#define rlo(i,n) for(int i=n-1;i>=0;i--)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))
#define pr(a) {for(auto x:a)cout<<x<<" ";cout<<nl;}
#define yes cout<<"Yes"<<nl
#define no cout<<"No"<<nl
#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

void f()
{
  string s,t;
  cin>>s>>t;
  int n=sz(s);
  lo(i,0,n)
  {
    if(s==t)
    {
      yes;
      return;
    }
    s=s[n-1]+s;
    s.pop_back();
  }
  no;
}

int main()
{
    su;
    f();
    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

template<typename T>
void cout_vec(vector<T> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}

int full_search(vector<int> cls, vector<int> &ABC, vector<int> &bamboo){
    if((int)cls.size() == (int) bamboo.size()){
        int cost=0;
        vector<int> flag(3,0);
        vector<int> tmp(3,0);
        copy(ABC.begin(), ABC.end(), tmp.begin());

        for(int i=0; i<(int)cls.size(); i++){
            int c = cls[i];
            if(c==3)continue;
            if(flag[c]==0){
                flag[c]=1;
            }else{
                cost+=10;
            }
            tmp[c]-=bamboo[i];
        }
        for(int i=0; i<3; i++){
            if(flag[i]==0){
                return MOD;
            }
            cost+=abs(tmp[i]);
        }
        //cout_vec(cls);
        //cout_vec(tmp);
        //cout << cost << endl;
        return cost;
    }

    int ret=MOD;

    for(int i=0; i<4; i++){
        cls.push_back(i);
        ret=min(ret,full_search(cls, ABC, bamboo));
        cls.pop_back();
    }
    return ret;
}

int main(){
    int N;
    cin >> N;
    vector<int> ABC(3,0);
    for(int i=0; i<3; i++){
        cin >> ABC[i];
    }
    vector<int> bamboo(N,0);
    for(int i=0; i<8; i++){
        cin >> bamboo[i];
    }
    cout << full_search({}, ABC, bamboo) << endl;;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
/*--------------------------------------------*/

int main(){
    //cout << fixed << setprecision(10)
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N, a, b;cin >> N >> a >> b;

    ll c = a + b;

    cout << (N / c) * a + min(N % c, a) << endl; 

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

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

ll lcm(ll x, ll y) {
    return x / gcd(x,y) * y;
}

int main(void)
{
    IOS
    constexpr int ER = 1e6+5;
    vector<int> prime;
    vector<int> erato(ER+5);
    FOR(i,2,ER+1) {
        if (erato[i]) continue;
        prime.push_back(i);
        for(int j = 1; i * j <= ER; j++) erato[i*j] = i;
    }

    int N; cin >> N;
    vector<int> A(N);
    vector<int> pr(ER);
    vector<set<int>> vs(N);
    REP(i,N) {
        cin >> A[i];
        int a = A[i];
        while(a != 1) {
            if (erato[a] > 1) {
                vs[i].insert(erato[a]);
                a /= erato[a];
            }
        }
        for(auto p:vs[i]) pr[p]++;
    }

    REP(i,N) {
        // pairwise coprime
        if (i == N-1) {
            OUT("pairwise coprime")
            return 0;
        }
        bool ok = true;
        for(auto p: vs[i]) pr[p]--;
        for(auto p: vs[i]) {
            if (pr[p] != 0) {
                ok = false;
                break;
            }
        }
        if (!ok) break;
    }

    ll allgcd = A[0];
    FOR(i,1,N) allgcd = gcd(allgcd,A[i]);
    if (allgcd == 1) {
        OUT("setwise coprime")
    } else {
        OUT("not coprime")
    }

    return 0;
}

Measured memory_bytes: 298912
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int x[] = new int[N];
		int y[] = new int[N];
		int h[] = new int[N];
		int start = 0;
		for (int i = 0; i < N; i++) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
			h[i] = sc.nextInt();
		    if(h[i]>0) {
			start = i;
		    }
		}
		for (int i = 0; i <= 100; i++) {
			for (int j = 0; j <= 100; j++) {
				int cx = i;
				int cy = j;
				int ch = h[start] + (int)(Math.abs(cx-x[start])) + (int)(Math.abs(cy-y[start]));
				for (int k = 0; k < N; k++) {
					int tmp = Math.abs(cx-x[k]) + Math.abs(cy-y[k]);
					if (Math.max(ch-tmp, 0) != h[k]) {
						break;
					}
					if (k==N-1) {
						System.out.println(cx + " " + cy + " " + ch);
						return;
					}
				}
			}
		}
	}
}


Measured memory_bytes: 21972
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int max = 0;
		int sum = 0;
		List<Integer> list = new ArrayList<Integer>();
		for (int i=0; i<n; i++) {
			int input = scan.nextInt();
			list.add(input);
			
			if (input > max) max = input;
			sum += input;
		}
		
		if (max < (sum - max)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 22868
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);

        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();

        while (true) {
            C -= B;

            if (C <= 0) {
                System.out.println("Yes");
                break;
            }

            A -= D;

            if (A <= 0) {
                System.out.println("No");
                break;
            }
        }
    }
}


Measured memory_bytes: 35724
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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 long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<int, int> P;
ll ma = 1000000000 + 7;
ll h, w, n,k; string s;
char maze[60][60];
int dis[101][101];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll dp[100010][2]; int x[509][509]; int c[509][509];
int gcd(int x, int y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);

}
int main() {
	ll m, Q;
	cin >> n >> m >> Q;
	vector<P> lr(m+1);
	for(int i=1;i<=m;i++) {
		cin >> lr[i].first;
		cin >> lr[i].second;
		x[lr[i].first][lr[i].second]++;
	}
	
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			c[i][j] = c[i][j - 1] + x[i][j];
		}
	}
	for (int i = 1; i <= Q; i++) {
		int p, q;
		cin >> p >> q;
		int sum = 0;
		for (int j = p; j <= q; j++) {
			sum+= c[j][q] - c[j][p - 1];
		}
		cout << sum << endl;
	}
}




Measured memory_bytes: 4480
<?php
list($X, $Y, $A, $B, $C) = ints();
$P = ints();
$Q = ints();
$R = ints();
rsort($P);
rsort($Q);
rsort($R);
for($i = 0; $i < $X; $i++){
    $R[] = $P[$i];
}
for($i = 0; $i < $Y; $i++){
    $R[] = $Q[$i];
}
rsort($R);
$ans = 0;
for($i = 0; $i < $X+$Y; $i++){
    $ans+=$R[$i];
}
echo $ans;


function str(){return trim(fgets(STDIN));}
function ints(){return array_map('intval',explode(' ',trim(fgets(STDIN))));}
function int(){return intval(trim(fgets(STDIN)));}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}
function popcount($x){$c=0;while($x){$x&=$x-1;++$c;}return$c;}
function o(...$val){
    if(count($val)==1)$val=array_shift($val);
    echo debug_backtrace()[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0)echo "empty array";
        elseif(!is_array(current($val)))echo "array: ",implode(" ", addIndex($val)),"\n";
        else{
            echo "array:array\n";
            if(isCleanArray($val))foreach($val as $row)echo implode(" ", addIndex($row)),"\n";
            else foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row)),"\n";
        }
    }else echo $val."\n";
}
function addIndex($val){if(!isCleanArray($val)){$val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);}return $val;}
function isCleanArray($array){$clean=true;$i = 0;foreach($array as $k=>$v){if($k != $i++)$clean = false;}return $clean;}
// 座圧対象の配列 -> [圧縮された配列,復元用のMap,圧縮用のMap]
function atsu($array){$a = array_flip($array);$fuku=array_flip($a);sort($fuku);$atsu = array_flip($fuku);foreach($array as $i=>$val)$array[$i]=$atsu[$val];return [$array, $fuku, $atsu];}
function gcdAll($array){$gcd=$array[0];for($i=1,$I=count($array);$i<$I;++$i){$gcd=gcd($gcd,$array[$i]);}return $gcd;}
function gcd($m, $n){if(!$n)return $m;return gcd($n, $m % $n);}
function lcmAll($array){$lcm=$array[0];for($i=1,$I=count($array);$i<$I;++$i){$lcm=lcm($lcm,$array[$i]);}return $lcm;}
function lcm($a, $b) {return $a / gcd($a, $b) * $b;}

function dfs($current, $from = -1, $d = 0){
  global $G, $distance;
  $distance[$current] = $d;
  foreach($G[$current] as $to){
    if($from != $to){
      dfs($to, $current, $d + 1);
    }
  }
}

function loadTree($N = false){
  if($N === false)$N = $GLOBALS['N'];
  return loadGraph($N, $N-1);
}
function loadGraph($N = false, $M = false, $both = true){
  if($N === false)$N = $GLOBALS['N'];
  if($M === false)$N = $GLOBALS['M'];
  $G = array_fill(1, $N, []);
  for($i = 0; $i < $M; $i++){
    $values = ints();
    if(count($values) == 2){
      list($a, $b) = $values;
      $G[$a][] = $b;
      if($both)$G[$b][] = $a;
    }else{
      list($a, $b, $d) = $values;
      $G[$a][] = [$b, $d];
      if($both)$G[$b][] = [$a, $d];
    }
  }
  return $G;
}


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

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    vector<int> l(n), r(n);
    vector<vector<int>> s(m + 1);
    for (int i = 0; i < n; ++i) {
        scanf("%d%d", &l[i], &r[i]);
        s[l[i]].push_back(r[i]);
    }
    vector<int> cnt(m + 2, 0);
    vector<vector<int>> tree((m + 2) * 4, vector<int>(2));
    vector<int> tag((m + 2) * 4, 0);
    int ans = 0;

    auto Build = [&](auto self, int l, int r, int o = 0) {
        if (r - l == 1) {
            tree[o][0] = 0;
            tree[o][1] = l;
            return;
        }
        int m = (l + r) >> 1;
        self(self, l, m, o * 2 + 1);
        self(self, m, r, o * 2 + 2);
        for (int v = 0; v < 2; ++v) tree[o][v] = max(tree[o * 2 + 1][v], tree[o * 2 + 2][v]);
    };

    auto Push = [&](int o) {
        for (int v = 1; v <= 2; ++v) {
            for (int r = 0; r < 2; ++r) tree[o * 2 + v][r] += tag[o];
            tag[o * 2 + v] += tag[o];
        }
        tag[o] = 0;
    };

    auto Modify = [&](auto self, int l, int r, int ql, int qr, int v, int o = 0) {
        if (l >= qr || ql >= r) return;
        if (l >= ql && r <= qr) {
            tag[o] += v;
            tree[o][0] += v;
            tree[o][1] += v;
            return;
        }
        Push(o);
        int m = (l + r) >> 1;
        self(self, l, m, ql, qr, v, o * 2 + 1);
        self(self, m, r, ql, qr, v, o * 2 + 2);
        for (int v = 0; v < 2; ++v) tree[o][v] = max(tree[o * 2 + 1][v], tree[o * 2 + 2][v]);
    };

    constexpr int kInf = 1'000'000'000;

    auto Query = [&](auto self, int l, int r, int ql, int qr, int p, int o = 0) {
        if (l >= qr || ql >= r) return -kInf;
        if (l >= ql && r <= qr) return tree[o][p];
        Push(o);
        int m = (l + r) >> 1;
        return max(self(self, l, m, ql, qr, p, o * 2 + 1),
                self(self, m, r, ql, qr, p, o * 2 + 2));
    };

    Build(Build, 0, m + 2);
    for (int i = 0; i <= m; ++i) {
        for (int u : s[i]) Modify(Modify, 0, m + 2, 0, u + 1, 1);
        ans = max(ans, Query(Query, 0, m + 2, i + 1, m + 2, 1) - (i + m + 1));
        ans = max(ans, Query(Query, 0, m + 2, 0, i + 1, 0) - m);
    }
    printf("%d\n", ans);
    return 0;
}


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

//#define DEBUG

using namespace std;

template <class T>
void print_vect(std::vector<T> v){
    for(int i = 0 ; i < v .size(); i++) cout << v[i] << " ";
    cout << endl;
}


void solve(){
    uint32_t N ;
    cin >> N;
    vector<int> ans(N + 1, 0);
    for(int x = 1  ; x <= 100 ; x++){
        for(int y = 1   ; y <= 100 ; y++){
            for(int z = 1; z <= 100 ; z++ ){
                int sum = x * x + y * y + z * z + x * y + y*z + x * z ;
                if( sum <= N){
                    ans[sum] = ans[sum] + 1;
                } 
            }
        }
    }
    for(int i = 1; i <= N ; i++){
        cout << ans[i] << "\n";
    }
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/

    #ifdef DEBUG
    int TEST_CASES = 4;
    while(TEST_CASES--){
    #endif // DEBBUG

    solve();

    #ifdef DEBUG
    }
    #endif // DEBUG
    
    return 0;
}


Measured memory_bytes: 3680
c1 = list(map(int, input(). split()))
c2 = list(map(int, input(). split()))
c3 = list(map(int, input(). split()))

if c1[0] - c2[0] == c1[1] - c2 [1] == c1[2] - c2[2]:
    if c1[0] - c3[0] == c1[1] - c3[1] == c1[2] - c3[2]:
        print('Yes')
    else:
        print('No')
else:
    print('No')

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

int main(){
  string S;
  int sum=0;
  cin >> S;
  for(int i=0;i<S.size();i++){
    for(int j=0;j<i;j++){
      if(S[i]==S[j]){
        sum++;
      }
    }
  }
  if(sum>0){
    cout << "no" << endl;
  }else{
    cout << "yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <sstream>
#include <iostream>
#include <string>

using namespace std;
int main() {
    string line;
    getline(cin, line);
    istringstream f(line);
    string _group_num;
    getline(f, _group_num, ' ');
    int group_num = stoi(_group_num);
    int total_num = 0;
    for (int i = 0; i < group_num; i++) {
        string _l;
        string _r;
        getline(cin, line);
        istringstream f1(line);
        getline(f1, _l, ' ');
        getline(f1, _r, ' ');
        total_num += stoi(_r) - stoi(_l) + 1;
    }
    cout << total_num << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
using namespace std;
const ll maxn = 1e5 + 7;
const ll mod = 1e9 + 7;
const ll mod1 = 123456789;
const int maxx = 1005;
ll q, t, n, m, T, k, ans, a[maxn], b[maxn], f[maxx][maxx];
priority_queue<ll> pr;
string s, str;
char ss[maxx][maxx];
map<ll, ll> mp;
void sol()
{
    cin >> n;
    ll mx = 1e16;
    for(int i = 0; i < n; i ++)
    {
        cin >> a[i];
    }
    for(int i = n - 1; i >= 0; i--)
    {
        for(int j = i; j >= 0; j --)
        {
            if(i == n - 1)f[i][j] = (j == 0 ? a[i] : 0);
            else
                f[i][j] = min(a[i] + f[i+1][a[i] > 100 ? j + 1 : j], j > 0 ? f[i+1][j-1] : mx);
        }
    }
    cout << f[0][0];
}
deque<char>st;
char ch;
void test()
{
    cin >> n;
    k = 100;
    ans = 0;
    while(k < n)
    {
        t = k / 100;
        k += t;
        ++ans;
        if(k >= n)break;
    }
    cout << ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    test();
}


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

int main(){
    double A, B;
    cin >> A >> B;

    double C = A + B;

    double D = C / 2;
    int E = C / 2;

    if(D - E >= 0.5){
        cout << E + 1 << endl;
    }

    else{
        cout << E << endl;
    }
}

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

bool judge(int s){
  if(s==2||s==3){return true;}
  else{
    for(int i=2;i*i<=s;i++){
      if(s%i!=0 && (i+1)*(i+1)>s){return true;}
      if(s%i==0){return false; break;}
  }}
}


int main(){
  while(1){
    int n,count=0;
    cin>>n;
    if(n==0){break;}
    for(int k=n+1;k<=2*n;k++){
      if(judge(k)){count++;}
    }
    cout<<count<<endl;
  }

  
  return 0;
}



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

using namespace std;
const int N = 2048; 
int a[N][N], b[N][N];
// make sure data in d[1..=n], and >= 0.
template <typename T=int>
T max_area(const vector<T>& d, int n=0) {
    if (!n) n = d.size() - 2;
    assert(n > 0 && d[0] == 0 && d[n+1] == 0);
    vector<int> stk; stk.reserve(n+2);
    stk.emplace_back(0);
    T res = 0;
    for (int i = 1; i <= n+1; i++) {
        while (d[i] < d[stk.back()]) {
            T ht = d[stk.back()]; stk.pop_back();
            T tmp = (ht+1) * (i - stk.back() -1 +1); // +1
            res = max(res, tmp);
        }
        stk.emplace_back(i);
    }
    return res;
}
void solve() {
    int n,m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        string s; cin >> s;
        for (int j = 0; j < m; j++) {
            a[i][j] = s[j] == '#';
        }
    }
    for (int i = 1; i < n; i++) {
        for (int j = 1; j < m; j++) {
            b[i][j] = a[i][j]^a[i][j-1]^a[i-1][j-1]^a[i-1][j] ^1;
        }
    }
    int res = max(n,m);
    for (int i = 1; i < n; i++) {
        vector<int> d;
        d.emplace_back(0);
        for (int j = 1; j < m; j++) {
            if (b[i][j]) b[i][j] += b[i-1][j];
            d.emplace_back(b[i][j]);
        }
        d.emplace_back(0);
        int ans = max_area<int>(d);
        res = max(res, ans);
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s;
	set<char> st(s.begin(), s.end());
	cout << (s.size()==st.size() ? "yes" : "no") << endl;
	return 0;
}


Measured memory_bytes: 256
H,W = map(int,input().split())

def cal(l):
    ll = list(l)
    ll.append('#')
    vol = [-100 for j in range(len(ll))]
    i = 0
    while i <= len(ll)-1:
        cnt = 0
        while (ll[i] != '#' and i <= len(ll)-1):
            cnt += 1
            i += 1

        for j in range(i-cnt,i):
            vol[j] = cnt

        i += 1
    return vol[:-1]

ver = [] # 縦
hori = [] # 横
fmap = []

for h in range(H):
    l = list(input())
    hori.append(cal(l))
    fmap.append(l)



new_map = []
for i in range(len(fmap[0])):
    mini_l = []
    for j in range(len(fmap)):
        mini_l.append(fmap[j][i])
    new_map.append(mini_l)

fmap = new_map    

for w in range(W):
    ver.append(cal(fmap[w]))

ans = 0

for h in range(H):
    for w in range(W):
        s = hori[h][w]+ver[w][h]
        if s > ans:
            ans = s
print(ans-1)



Measured memory_bytes: 283272
N, K = map(int, input().split())
x = [int(i) for i in input().split()]
ans = float('inf')

for i in range(N - K + 1):
    ans = min(ans, min(abs(x[i]), abs(x[i+K-1])) + abs(x[i] - x[i+K-1]))
print(ans)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) ll aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) string aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007


int main() {
	
	ll N,A,B;
	cin>>N>>A>>B;
	vec(X)
	fx(N){
		vecp(X)
	}
	
	ll ans=0;
	fx(N-1){
		ans+=min(A*(X.at(x+1)-X.at(x)),B);
	}
	ce(ans)
}

Measured memory_bytes: 892
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <numeric>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

int main(){
    while(1){
        int n,m;
        cin>>n>>m;
        if(n==0&&m==0)break;
        vector<int> ans(n,0);
        rep(i,0,n){
            int d,v;
            cin>>d>>v;
            ans[d-1]=max(ans[d-1],v);
        }
        
        cout<<accumulate(ans.begin(),ans.begin()+m,0)<<endl;
    }
    
    
    return 0;
}



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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef pair<int, int> ii;
typedef pair<ll, ll> pll;

int main( int argc, char *argv[] ) {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll k, n, m = 0, first, tmp, prev, i;
	cin >> k >> n;
	cin >> first;
	tmp = first;
	for ( i = 1 ; i < n ; i++ ) {
		prev = tmp;
		cin >> tmp;
		m = max(tmp-prev, m);
	}
	m = max(k - tmp + first, m);
	std::cout << k - m << std::endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

LL f(LL n) {
  return (n * (n + 1)) / 2; 
}

int main() {
  int n;
  S(n);
  LL tot = 0;
  rep(i,1,n+1) {
    tot += f(i);
  }
  rep(i,0,n-1) {
    int u,v;
    S2(u,v);
    if(u > v) swap(u,v);
    tot -= u * 1LL * (n + 1 - v);
  }
  cout << tot << "\n";
  return 0;
}


Measured memory_bytes: 3616
import math

k = int(input())
k_arr = range(1,k+1)

a_arr = list()
b_arr = list()

for k in k_arr:
    for a in k_arr:
        a_arr.append(a)

for b in k_arr:
    for k in k_arr:
        b_arr.append(b)

gcds = list(map(math.gcd,a_arr,b_arr))

total = 0
for c in k_arr:
    c_arr = [c] * k * k
    total += sum(map(math.gcd,gcds,c_arr))

print(total)

Measured memory_bytes: 10640
/*
author: madhav_1999 aka orthodoxparadox
26 April 2020 at 5:28 PM
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define dbl long double
#define int ll
#define ll long long
#define pii pair<int, int>
#define len(x) (int) x.size()
#define rev(a) reverse(all(a))
#define oiint ostream_iterator<int>(cout, " ") 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define all(a) a.begin(), a.end()
#define initialise(a, x) memset(a, x, sizeof(a))
#define onlyunique(v) v.erase(unique(all(v)), v.end()); //only for sorted vector
#define inf 2e18
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#ifdef MADHAV
#define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << "  ";
	__f(comma + 1, args...);}
#else
#define dbg(...) 42
#endif
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(int i=0;i<(int)v.size();++i) x<<v[i]<<" ";return x;} 
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;} 
template <typename X> ostream& operator << (ostream& x,const multiset<X>& v){for(auto it:v) x<<it<<" ";return x;} 
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;} 
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
struct pair_hash {inline std::size_t operator()(const std::pair<int, int> & v) const {return v.first*31+v.second;}};
const int MOD = 1e9 + 7;

int takemod(int a, int mod = MOD){a%=mod;if(a<0)a+=mod;return a;}

int fast_exp(int base, int expo, int mod = MOD) {
	int res=1;
	while(expo>0) {
		if(expo&1) res=(res*base)%mod;
		base=(base*base)%mod;
		expo>>=1;}
	return res;}

int modinv(int a, int mod = MOD){return takemod(fast_exp(takemod(a, mod), mod-2, mod), mod);}


void solve()
{
	int s, w;
	cin >> s >> w;
	if(w >= s) {
		cout << "unsafe";
	}
	else {
		cout << "safe";
	}
}

signed main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	#ifdef MADHAV
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt", "w", stderr);
	#endif
	clock_t t1, t2;
	t1 = clock();

	int tt = 1;
	// cin >> tt;
	while(tt--)
	{
		solve();
	}
	#ifdef MADHAV
	t2 = clock(); cout << "\n\ntime taken: " << (t2-t1)/(dbl)CLOCKS_PER_SEC;
	#endif
	return 0;
}

Measured memory_bytes: 3652
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n,m;
  cin>>n>>m;
  
  int x;
  int B[10]={0,2,5,5,4,5,6,3,7,6};
  vector<int> A(10),C(10);
  rep(i,m){
    cin>>x;
    A[x]=1;
    C[B[x]]=1;
  }
  
  int dp[10010];
  rep(i,10010) dp[i]=-1;
  dp[0]=0;
  
  for(int i=2;i<=n;i++){
    for(int j=2;j<=7;j++){
      if(C[j]==1 && i-j>=0 && dp[i-j]!=-1 && dp[i]<dp[i-j]+1) dp[i]=dp[i-j]+1;
    }
  }
    
  int t=n;
  for(int i=9;i>0 && t>0;i--){
    if(A[i]==0) continue;
    while(t-B[i]>=0 && dp[t-B[i]]==dp[t]-1){
      cout<<i;
      t-=B[i];
    }
  }
  cout<<endl;
  
  return 0;
}

Measured memory_bytes: 3688
#[allow(unused_imports)]
use proconio::{fastout, input, marker::*};

#[fastout]
fn main() {
    input! {
        mut a: isize,
        mut b: isize,
        mut c: isize,
        mut k: isize,
    }
    let mut ans = 0;

    a = std::cmp::min(a, k);
    ans += a * 1;
    k -= a;

    b = std::cmp::min(b, k);
    k -= b;

    c = std::cmp::min(c, k);
    ans -= c * 1;

    println!("{}", ans);
}


Measured memory_bytes: 2164
#include <iostream>
#include <queue>
#include <algorithm>

using namespace std;

int main(){
  int n; cin >> n;
  int a[3*n+1];
  for(int i=1;i<=3*n;i++) cin >> a[i];
  priority_queue<int> S;
  priority_queue<int,vector<int>,greater<int> > F;
  long long sumF=0,sumS=0;
  long long sf[n+1],ss[n+1];
  for(int i=1;i<=n;i++){
    F.push(a[i]);
    sumF=sumF+a[i];
  }
  sf[0]=sumF;
  for(int k=1;k<=n;k++){
    F.push(a[n+k]);
    int x=F.top(); F.pop();
    sumF=sumF+a[n+k]-x;
    sf[k]=sumF;
  }
  for(int i=2*n+1;i<=3*n;i++){
    S.push(a[i]);
    sumS=sumS+a[i];
  }
  ss[n]=sumS;
  for(int k=n-1;k>=0;k--){
    S.push(a[n+k+1]);
    int x=S.top(); S.pop();
    sumS=sumS+a[n+k+1]-x;
    ss[k]=sumS;
  }
  long long ans=sf[0]-ss[0];
  for(int k=1;k<=n;k++){
    ans=max(ans,sf[k]-ss[k]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3960