akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) < (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n) - 1; (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;
#define all(x) (x).begin(),(x).end()

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;
}

ll fac(ll n){
    ll t = 1;
    rep1(i, n + 1)t *= i;
    return t;
}

int main()
{
    ll a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    if (a + b >= c * 2) {
        if (x < y && b < c * 2) {
            cout << x * c * 2 + (y - x) * b << endl;
        }else if(x > y && a < c * 2){
            cout << y * c * 2 + (x - y) * a << endl;
        }else{
            cout << max(x,y) * c * 2 << endl;
        }
    }else{
        cout << a * x + b * y << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define MAX 200005

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> P;

int n, d, a;
P p[MAX];

int main(){
  cin >> n >> d >> a;
  d=2*d;
  rep(i, n){
    cin >> p[i].first >> p[i].second;
  }
  sort(p, p+n);
  queue<P> Q;
  ll tot=0, ans=0;
  rep(i, n){
    int x=p[i].first;
    int h=p[i].second;
    while(Q.size() && Q.front().first < x){
      tot-=Q.front().second;
      Q.pop();
    }
    h-=tot;
    if(h>0){
      int num=(h+a-1)/a;
      ans+=num;
      ll damage=num*a;
      tot+=damage;
      Q.emplace(x+d,damage);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2688
#include<iostream>
#include<vector>
#include<cmath>

using namespace std;

int main()
{
    long N;
    cin>>N;
    vector<long>A(N+1),B(N);
    for(int i=0;i<N+1;i++){
        cin>>A[i];
    }
    for(int i=0;i<N;i++){
        cin>>B[i];
    }
    long count=0;
    for(int i=0;i<N;i++){
        if(B[i]>A[i]){
            B[i]-=A[i];
            count+=A[i];
            if(B[i]>=A[i+1]){
                count+=A[i+1];
                A[i+1]=0;
            }else{
                A[i+1]-=B[i];
                count+=B[i];
            }
        }else{
            count+=B[i];
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;
const int INF = 2100000000;

class Heap{
  public:
    vector<int> a;
    int N;
    Heap(int n){
      N = n;
      a.resize(N, INF);
      N--;
    }

    int get_parent(int x){
      return a[(x)/2];
    }

    int get_left(int x){
      if(x*2 < N){
        return a[x*2];
      }
      return INF;
    }

    int get_right(int x){
      if(x*2+1 < N){
        return a[x*2+1];
      }return INF;
    }

    void print(){
      for(int j = 1; j <= N; ++j){
        cout << " " << a[j];
      }cout << endl;
    }

//     void mx(int i){
//       int l = get_left(i);
//       int r = get_right(i);
//       int largest = -1;
//
//       if(l <= N && a[l] > a[i]){
//         largest = l;
//       }else{
//         largest = i;
//       }
//
//       if(r <= N && a[r] > a[largest])
//           largest = r;
//
//       if(largest != i){
//         swap(a[i], a[largest]);
//         mx(largest);
//       }
//     }
//
//     void buildMXHeap(){
//       for(int i = N/2; i > 0; --i){
//         mx(i);
//       }
//     }
};

void mx(Heap &A, int i){
  int l = i*2;
  int r = i*2+1;
  int largest = INF;


  if(l <= A.N && A.a[l] > A.a[i]){
    largest = l;
  }else{
    largest = i;
  }

  if(r <= A.N && A.a[r] > A.a[largest])
      largest = r;

  if(largest != i){
    swap(A.a[i], A.a[largest]);
    mx(A, largest);
  }
}

void buildMXHeap(Heap &A){
  for(int i = A.N/2; i > 0; --i){
    mx(A, i);
  }
}



int main(void){
  int n, a;
  cin >> n;
  n++;
  Heap hp(n);

  for(int i = 1; i < n; i++){
    cin >> a;
    hp.a[i] = a;
  }

//   for(int i = 1; i < n; ++i){
//     cout << "node " << i << ": key = " << hp.a[i];
//     if(hp.get_parent(i) != INF){
//       cout << ", parent key = " << hp.get_parent(i);
//     }
//     if(hp.get_left(i) != INF){
//       cout << ", left key = " << hp.get_left(i);
//     }
//     if(hp.get_right(i) != INF){
//       cout << ", right key = " << hp.get_right(i);
//     }
//     cout << ", " << endl;
//   }

  buildMXHeap(hp);
  hp.print();
}

Measured memory_bytes: 4648
#include <iostream>
using namespace std;
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
char judge(int a[],int m1)
{
   int i,j,k,l;
   int x[100];
   int n; /* 投票の対象となる競技者の数 */
   int m; /* 優勝した競技者の番号 */
   int p; /* 控除率（百分率）を表す整数 */
   int sum = 0; /* 人数の合計 */
   cin >> n >> m >> p;
   if(n == 0 && m == 0 && p == 0) return 0;

   for(i=0;i<n;i++) {
      cin >> x[i];
      sum += x[i];
   }
   if(x[m-1])
      a[m1] = sum * (100-p) / x[m-1] ;
   else a[m1] = 0;
   return 1;
}



int main()
{
   int i,j,k,l;
   int m1;
   int a[100];
   int go = 1;
   for(i=0;go;i++) {
      go = judge(a,i);
   }
   i--;
   m1 = i;
   for(i=0;i<m1;i++)
      cout << a[i] << endl;
   return 0;
}

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

typedef long long ll;
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)

ll mod=1e9+7;

using namespace std;


ll inputValue(){
	ll a;
	cin >> a;
	return a;
};

void inputArray(int * p, ll a){
	rep(i, a){
		cin >> p[i];
	}
};

template<typename T>
void inputVector(vector<T>& p, ll a){
	rep(i, a){
		T input;
		cin >> input;
		p.emplace_back(input);
	}
}


template <typename T>
void output(T a) {
	cout << a << "\n";
}

int main(int argc, const char * argv[]) {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
    ll a[] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    ll k;
    cin >> k;

    cout << a[--k] << endl;

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define rep(i, N) for(i = 0; i < N; i++)
#define ll long long

int main() {
  string str;
  cin >> str;

  if(str == "ABC") {
    cout << "ARC";
  } else {
    cout << "ABC";
  }

  return 0;
}

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

int main() {
  
  int L;
  
  cin>>L;
  
  int M=L%100;
  int N=M%10;
  int La=L/100;
  int Ma=M/10;
  int Na=N/1;
  
  cout << La+Ma+Na << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
bool j(ll x,ll y,ll z){
    return (x>y &&y>=z)||(z>y&&y>=x);
}
int main(void){
    ll n;
    cin>>n;
    vector<ll>a(n);
    rep(0,i,n)cin>>a[i];
    ll ans=0;
    rep(1,i,n-1){
        if(j(a[i-1],a[i],a[i+1]))++ans;
    }
    cout<<ans;
}

Measured memory_bytes: 256
N, x = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]

ans = sum(A)
for k in range(1, N + 1):
    A = [min(i, j) for i, j in zip(A, A[1:] + [A[0]])]
    ans = min(ans, x * k + sum(A))
print(ans)


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

    cout << "square1001" << endl;

    return 0;
}



Measured memory_bytes: 3080
#!/usr/bin/env python3
import sys
import numpy as np

def solve(N: int, C: int, s: "List[int]", t: "List[int]", c: "List[int]"):
    torec = np.zeros((C, max(t)+1), int)
    for i in range(N):
        torec[c[i]-1][s[i]:t[i]+1] = 1
    print(np.max(np.sum(torec, axis=0)))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    s = [int()] * (N)  # type: "List[int]" 
    t = [int()] * (N)  # type: "List[int]" 
    c = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        s[i] = int(next(tokens))
        t[i] = int(next(tokens))
        c[i] = int(next(tokens))
    solve(N, C, s, t, c)

if __name__ == '__main__':
    main()


Measured memory_bytes: 44940
#include <bits/stdc++.h>
#define rep(a,n) for (int a = 0; a < (n); ++a)
using namespace std;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
typedef vector<vector<ll> > Graph;
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 INF = 1e18;

vector<pair<ll, ll> > prime_factorize(ll N) {
    vector<pair<ll, ll> > res;
    for (ll a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin >> n;
    vector<ll>a(n);
    ll g = 0;
    rep(i,n){
        cin>>a[i];
        g = __gcd(a[i],g);
    }
    vector<ll>cnt(1e6+1);
    rep(i,n){
        auto res = prime_factorize(a[i]);
        rep(j,res.size()){
            ll div = res[j].first;
            cnt[div]++;
        }
    }
    bool fi = true;
    rep(i,1e6+1){
        if(cnt[i]>1){
            fi=false;
            break;
        }
    }
    if(fi){
        cout << "pairwise coprime" << endl;
        return 0;
    }
    if(g==1){
        cout << "setwise coprime" << endl;
        return 0;
    }
    cout << "not coprime" << endl;


    return 0;
}

Measured memory_bytes: 18712
import Data.List
import Control.Monad

main = do
  n <- readLn
  sps <- map words <$> replicateM n getLine
  mapM_ print $ solve sps

solve sps =
  let
    f [a, b] = (a, - (read b))
    spss = zip [1..] $ map f sps
  in
    map fst $ sortOn snd spss

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

const int MOD = 1000000007;
const long long INF = 1LL << 60;

int main()
{
    int r, g, b;
    cin >> r >> g >> b;
    if ((10 * g + b) % 4 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define dbg(x) cerr<<#x<<" = "<<x<<endl;
#define dbg_v(v,n) {cerr<<#v<<" = [";for(int III=0;III<=n;III++)cerr<<v[III]<<(III!=n?",":"]\n");}
#define ll long long
#define ld long double
#define ull unsigned long long
#define pii pair<int,int>
#define MOD 1000000007
#define zeros(x) x&(x-1)^x
#define fi first
#define se second
#define Nmax 505
using namespace std;

int n,m,mat[Nmax][Nmax],v[Nmax];
int fr[Nmax];

int getAns(int &bst){
	memset(fr, 0, sizeof(fr));
	for (int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if (v[mat[i][j]]){
				fr[mat[i][j]]++;
				break;
			}
		}
	}
	int mx = 0;
	for (int i=1;i<=m;i++){
		if (fr[i] > mx){
			mx = fr[i];
			bst = i;
		}
	}
	return mx;
}

int main(){
    ios::sync_with_stdio(false);
    cin >> n >> m;
    for (int i=1;i<=n;i++){
    	for (int j=1;j<=m;j++){
    		cin >> mat[i][j];
    	}
    }
    for (int i=1;i<=m;i++) v[i] = 1;

    int ans = 1e9;
    for (int i=1;i<=m;i++){
    	int bst;
    	ans = min(ans, getAns(bst));
    	v[bst] = 0;
    }

    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int n, m, q;
vector<int> a, b, c, d;
vector<int> v(10);
ll ans = 0;
void dfs(int dep, int prev) {
    if (dep == n) {
        ll res = 0;
        rep(i, q) {
            if (v[b[i]] - v[a[i]] == c[i]) res += d[i];
        }
        ans = max(ans, res);
    } else {
        v[dep] = prev;
        dfs(dep+1, prev);
        for (int i=1;i+prev<=m;i++) {
            v[dep] = prev + i;
            dfs(dep+1, prev+i);
        }
        /*if (prev + 1 <= m) {
            v[dep] = prev + 1;
            dfs(dep+1, prev + 1);
        }*/
    }
}
int main() {
    cin >> n >> m >> q;
    a.resize(q); b.resize(q); c.resize(q); d.resize(q);
    rep(i, q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--; b[i]--;
    }
    dfs(0, 1);
    cout << ans << endl;
}


Measured memory_bytes: 3644
with Ada.Text_IO;
with Ada.Integer_Text_IO;

procedure main is

    n : String(1 .. 3);
    last : Natural;
    c : Integer := 0;

begin

    Ada.Text_IO.Get_Line(n, last);

    if(n(1) = '7')then
        c := c + 1;
    elsif(n(2) = '7')then
        c := c + 1;
    elsif(n(3) = '7')then
        c := c + 1;
    end if;

    if(c > 0)then  
        Ada.Text_IO.Put_Line("Yes");
    else
        Ada.Text_IO.Put_Line("No");
    end if;

end main;

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5005;
int n,a,b,i,j,p[N],s[N][N],x,y;
ll f[N],ans;
int ask(int a,int b,int c,int d){return s[b][d]-s[b][c-1]-s[a-1][d]+s[a-1][c-1];}
int main(){
	scanf("%d%d%d",&n,&a,&b);ans=1ll*n*min(a,b);
	for(i=1;i<=n;++i)for(scanf("%d",p+i),memcpy(s[i]+1,s[i-1]+1,n<<2),j=p[i];j<=n;++j)++s[i][j];
	for(i=1;i<=n;++i){
		x=ask(1,i-1,p[i]+1,n);f[i]=1ll*x*a+1ll*(i-1-x)*min(a,b);
		for(j=1;j<i;++j)if(p[j]<p[i]){
			x=ask(j+1,i-1,1,p[j]-1);y=ask(j+1,i-1,p[i]+1,n);
			f[i]=min(f[i],1ll*x*b+1ll*y*a+1ll*(i-j-1-x-y)*min(a,b)+f[j]);
		}
		x=ask(i+1,n,1,p[i]-1);ans=min(ans,f[i]+1ll*x*b+1ll*(n-i-x)*min(a,b));
	}
	printf("%lld\n",ans);
	return 0;
}

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

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


int main() {
    int a,b;
    cin>>a>>b;
    int count=0;
    if(a>b) cout<<a-1<<endl;
    else if(a==b) cout<<a<<endl;
    else cout<<a<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <cassert>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1e9 + 7;

template <int mod = MOD>
struct modBase {
	modBase(int v = 0) : val(v) {}
	int val;
 
	void operator += (modBase<mod> o) { *this = *this + o; }
	void operator -= (modBase<mod> o) { *this = *this - o; }
	void operator *= (modBase<mod> o) { *this = *this * o; }
	modBase<mod> operator * (modBase<mod> o) { return (int)((long long) val * o.val % mod); }
	//modBase<mod> operator / (modBase<mod> o) { return *this * fexp(o, mod - 2); }
	modBase<mod> operator + (modBase<mod> o) { return val + o.val >= mod ? val + o.val - mod : val + o.val; }
	modBase<mod> operator - (modBase<mod> o) { return val - o.val < 0 ? val - o.val + mod : val - o.val; }
};

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	modBase<> ans;
	int n, k;
	std::cin >> n >> k;
	long long l = 0, r = 0;
	for(int i = 1; i <= n+1; i++) {
		l += i;
		r += (n+1) - i + 1;
		if(i >= k) {
			ans = ans + (int)((r - l + 1) % MOD);
		}
	}
	std::cout << ans.val << '\n';
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>


int main() {
	std::string str = "", res = "";
	std::getline(std::cin, str);

	int i = 0, c = 0;
	while (1) {
		if (str[i] == ',' || str[i] == '.' || str[i] == ' ' || str[i] == '\0') {
			if(3 <= c && c <= 6)
				res += str.substr(i - c, c) + " ";

			c = 0;
		} else {
			c++;
		}

		if (str[i] == '\0')
			break;

		i++;
	}

	std::cout << res.substr(0, res.size() - 1) << std::endl;

	return 0;
}

Measured memory_bytes: 3040
#test.py
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def gcd_list(numbers):
    return reduce(math.gcd, numbers)


K = int(input())
ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            if i==1 or j==1 or k ==1:
                ans += 1
            else:
                ans += gcd(i,j,k)

print(ans)

Measured memory_bytes: 69340
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
constexpr int mod = 1000000007;
constexpr int inf = 1e9;
int x;
int main(){
	cin>>x;
	for(ll k = -1000; k <= 1000; ++k){
		for(ll l = -1000; l <= k; ++l){
			vector<long long> a(5, k), b(5, l);
			a[0] = k;
			b[0] = l;
			for(int i = 1; i < 5; ++i){
				a[i] *= a[i - 1];
				b[i] *= b[i - 1];
			}
			//cout<<k<<" "<<l<<" "<<a[4]<<" "<<b[4]<<endl;
			if(a[4] - b[4] == x){
				cout<<k<<" "<<l<<" "<<endl;
				return 0;
			}
			else if(b[4] - a[4] == x){
				cout<<l<<" "<<k<<" "<<endl;
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3548
MOD = int(10**9+7)
n, m = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))

x_mul = 0
y_mul = 0
for i in range(n):
    x_mul += (i-(n-i-1))*x[i]%MOD
for i in range(m):
    y_mul += (i-(m-i-1))*y[i]%MOD
print(x_mul*y_mul%MOD)

Measured memory_bytes: 18556
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,a,b;
	cin>>n>>a>>b;
	ll ans=n+1;
	if(n>=a-1){
		n-=a-1;
		//puta(n);
		ll tmp=a+n%2+(b-a)*(n/2);
		chmax(ans,tmp);
	}
	puta(ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.Map.Entry;
import java.io.*;
import java.util.*;

public class Main {
	
	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		
		int N = sc.nextInt();
		for(int x = 1; x <= N; x++){
			if(N <= 1L * x * (x + 1) / 2){
				long sum = N;
				for(int i = x; i >= 1; i--){
					if(sum >= i){
						System.out.println(i);
						sum -= i;
					}
				}
				return;
			}
		}
	}
}

class FastScanner {
    private InputStream in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(InputStream in) {
		this.in = in;
	}
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
    	if (hasNextByte()) return buffer[ptr++];
    	else return -1;
    }
    private static boolean isPrintableChar(int c){
    	return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
    	while(hasNextByte() && !isPrintableChar(buffer[ptr]))
    		ptr++; return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
    	return Double.parseDouble(next());
    }
}


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

int main(){
	int n;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++)
		cin>>arr[i];
	int dp[n];
	memset(dp,INT_MAX,sizeof(dp));
	dp[0]=0;
	for(int i=1;i<n;i++){
		dp[i]=min(dp[i-1]+abs(arr[i-1]-arr[i]),( i-2 >= 0 ? dp[i-2]+abs(arr[i]-arr[i-2]) : INT_MAX));
	}
	cout<<dp[n-1]<<endl;
	return 0;
}


Measured memory_bytes: 1024
N, M = map(int, input().split())
high = list(map(int, input().split()))
route = []
ans = 0
for i in range(N + 1):
  ls = set()
  route.append(ls)

for i in range(M):
  A, B = map(int, input().split())
  route[A].add(B)
  route[B].add(A)

for i, v in enumerate(route):
  if i == 0:
    continue
  kijun = high[i - 1]
  if v == set():
    ans += 1
    continue
  else:
    flag = True
    for j in v:
      tmp = high[j - 1]
      if tmp >= kijun:
        flag = False
    if flag:
      ans += 1

print(ans)
    


Measured memory_bytes: 45228
#include<iostream>
#include<queue>
#include<memory>
#include<map>
#include<set>
#include<unordered_map>
#include<array>
#include<vector>
#include<algorithm>
#include<list>
#include<limits>
#include<stdio.h>
#include<math.h>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using lst = list<ll>;

const ll MOD = 1000000007;

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

	int n = X / 100;

	int m = X % 100;
	m = m / 5 + (m % 5 != 0);
	
	cout << (n >= m) << endl;
	return 0;
}

Measured memory_bytes: 256
def search(y, x):
    dy_list = [-1, 0, 1, 0]
    dx_list = [0, -1, 0, 1]

    queue = [(y, x)]
    dist = [[-1 for _ in range(w)] for _ in range(h)]
    dist[y][x] = 0
    while queue:
        # print('queue: ', queue)
        now_y, now_x = queue.pop(0)
        for dy, dx in zip(dy_list, dx_list):
            next_y = now_y+dy
            next_x = now_x+dx

            # 範囲外なら
            if not(0 <= next_y < h and 0 <= next_x < w):
                continue
            # 壁なら
            elif s_list[next_y][next_x] == '#':
                continue
            # 探索済なら
            elif dist[next_y][next_x] != -1:
                continue

            dist[next_y][next_x] = dist[now_y][now_x]+1
            # print((now_y, now_x), (next_y, next_x), dist[now_y][now_x]+1)
            # print(dist, '\n')
            queue.append((next_y, next_x))

    return max(max(d) for d in dist)


h, w = map(int, input().split())
s_list = [list(input()) for _ in range(h)]

ans = 0
for i in range(h):
    for j in range(w):
        if s_list[i][j] == '.':
            ans = max(search(i, j), ans)
print(ans)


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

int main()
{
	ll N, K, T, U, V, L;
	cin >> N >> K >> T >> U >> V >> L;
	vector<ll> D(N + 1);
	for (int i = 0; i < N; i++) {
		cin >> D[i];
	}
	D[N] = L;
	double res = (double)D[0] / U, pos = D[0];
	ll cnt = 1;
	for (int i = 1; i <= N; i++) {
		if (D[i] <= pos + T * V * cnt) {
			int tmp = cnt - (D[i] - pos) / (T * V);
			if (tmp < K) {
				cnt++;
				if (i == N) {
					res += (double)(D[i] - pos) / V;
				}
			}
			else {
				res += (double)(D[i] - pos) / V;
				cnt = K + 1;
				pos = D[i];
			}
		}
		else {
			res += T * cnt + (double)(D[i] - pos - T * V * cnt) / U;
			cnt = 1;
			pos = D[i];
		}
	}
	cout << fixed << setprecision(8) << res << endl;
	return 0;
}

Measured memory_bytes: 3260
x1,y1,x2,y2 = map(int, input().split())

x3 = x2 - (y2 - y1)
x4 = x3 - (x2 - x1)
y3 = y2 + (x2 - x1)
y4 = y3 - (y2 - y1)

print(x3, y3, x4, y4)


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

void solve(const std::string& s)
{
  for (std::size_t i = 0; i < s.size(); ++i) {
    std::cout << 'x';
  }
  std::cout << std::endl;
}

int main()
{
  std::string s;
  std::cin >> s;

  solve(s);
}


Measured memory_bytes: 256
N, T = map(int, input().split())


AB_array = [list(map(int, input().split())) for _ in range(N)]

AB_array = sorted(AB_array, key=lambda x: x[0])

dp = [[0] * T for _ in range(N)]

ans = 0

for i in range(1, N):
    for j in range(T):
        if j >= AB_array[i - 1][0]:
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1], dp[i - 1]
                           [j - AB_array[i - 1][0]] + AB_array[i - 1][1])
        else:
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])
    ans = max(ans, dp[i - 1][-1] + AB_array[i - 1][1])
ans = max(ans, dp[-1][-1] + AB_array[-1][1])
print(ans)


Measured memory_bytes: 117336
N,T = [int(x) for x in input().split()]
t = [int(x) for x in input().split()]
cnt = 0
for ind,i in enumerate(t[:-1]):
    x = t[ind+1]-i
    if(x>T):
        cnt += T
    else:
        cnt += x
cnt += T
print(cnt)


Measured memory_bytes: 25196
#include <cstdio>
#include <algorithm>
static const int MAXN = 200004;

int n, dur;
int t[MAXN];

int main()
{
    scanf("%d%d", &n, &dur);
    for (int i = 0; i < n; ++i) scanf("%d", &t[i]);

    int ans = 0;
    for (int i = 1; i < n; ++i) {
        ans += std::min(dur, t[i] - t[i - 1]);
    }
    ans += dur;
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)                                 //g++ template.cpp -o template.exe
#define zeroes(x) memset(x,0,sizeof(x))                                        //all elements to 0  |  \
#define all(x) (x).begin(), (x).end()
typedef long long int ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn=100000;
#define MAX 50 







bool sortbysec(const pair<int,int> &a,                         //sorting of elements wrt second
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
} 






int main()
{
	char ch;
	cin>>ch;
	if(isupper(ch))
		cout<<"A";
	else
		cout<<"a";

	return 0;
}

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

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

    int X, t;
    cin >> X >> t;
    cout << max(X-t, 0) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	#ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    // string s;
    // cin>>s;
   	// int flag=1;
    // for(int i=0;i<s.size();++i){
    // 	for(int j=i+1;j<s.size();++j){
    // 		if(s[i]==s[j]){
    // 			flag=0;
    // 			break;
    // 		}
    // 	}
    // }
    // cout<<((flag)?"yes":"no");



    string s;
    cin>>s;
    set<char>c;
    for(char k:s) c.insert(k);
    cout<<((s.size()==c.size())?"yes":"no");
    return 0;
}


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

int main() {
  int A,N,x,y;
  cin >> N >> A;
  
  x = N / 500;
  y = N - x * 500; 
  if (A >= y) {
	cout << "Yes" << endl;
  } else {
  	cout << "No" << endl;
  }

}

Measured memory_bytes: 256
/*****************************************************
 *     created by: nayakashutosh9
 * "Winners Never Quit and Quitters Never Win".
*****************************************************/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("Ofast")
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define endl '\n'
#define mod 1000000007
#define inf 1e18
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
const int N = 300005;
/**********************************************************************************************/

int n, m, x;
vector<vector<int>> a;
vector<int> c, cur;
int ans;
void check(int i, int sum) {
	if (i == n) {
		if ((*min_element(cur.begin(), cur.end())) >= x) ans = min(ans, sum);
		return;
	}
	check(i + 1, sum);
	for (int j = 0; j < m; j++) cur[j] += a[i][j];
	check(i + 1, sum + c[i]);
	for (int j = 0; j < m; j++) cur[j] -= a[i][j];
}
void solve() {
	cin >> n >> m >> x;
	a.clear(); a.resize(n, vector<int>(m));
	c.clear(); c.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> c[i];
		for (int j = 0; j < m; j++) cin >> a[i][j];
	}
	ans = inf;
	cur.clear(); cur.resize(m, 0);
	check(0, 0);
	if(ans!=inf) cout << ans << endl;
	else cout<<"-1\n";
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t = 1, z = 1;
	// cin >> t; cin.ignore();
	while (t--) {
		// cout << "Case #" << (z++) << ": ";
		// clock_t start = clock();
		solve();
		// clock_t end = clock();
		// cout << (end-start) << endl;
		//print execution time in ms
	}

	return 0;
}

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

using namespace std;

#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;

const int oo = 0x3f3f3f3f;

const int maxn = 100000;

LL dp[maxn + 5][2];

int n;
int a[maxn + 5];

int main()
{
#ifdef matthew99
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	memset(dp, -oo, sizeof dp);
	scanf("%d", &n);
	REP(i, 0, n) scanf("%d", a + i);
	dp[0][0] = 0;
	REP(i, 0, n) REP(j, 0, 2) if (dp[i][j] >= 0)
	{
		REP(k, 0, min(a[i], 1) + 1)
		{
			int tmp = (a[i] - k) >> 1;
			int res = a[i] - (tmp << 1) - k;
			if (j && k) chkmax(dp[i + 1][res], dp[i][j] + tmp + 1);
			else chkmax(dp[i + 1][k], dp[i][j] + tmp);
		}
	}
	cout << max(dp[n][0], dp[n][1]) << endl;
	return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (int)(n); i++)
#define sum(a) accumulate(a.begin(),a.end(),0LL)
#define put(i) cout<<fixed<<i<<endl
using namespace std;
using ll = long long;

int main(){
    string n; cin >> n;
    ll ans = sum(n);
    ans -= '0' * n.size();
    if(ans % 9 == 0) put("Yes");
    else put("No");
}

Measured memory_bytes: 3724
n,x=map(int,input().split())
a,p=[1],[1]
for i in range(n):
    a.append(a[i]*2+3)
    p.append(p[i]*2+1)
def f(n,x):
    if n==0: return 0 if x<=0 else 1
    elif x<=1+a[n-1]: return f(n-1,x-1)
    else: return p[n-1]+1+f(n-1,x-a[n-1]-2)
print(f(n,x))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
inline int read(){
    int res=0;
    char c;
    bool zf=0;
    while(((c=getchar())<'0'||c>'9')&&c!= '-');
    if(c=='-')zf=1;
    else res=c-'0';
    while((c=getchar())>='0'&&c<='9')res=(res<<3)+(res<<1)+c-'0';
    if(zf)return -res;
    return res;
}
signed main(){
	int n=read(),ans=0;
	while(n--)ans+=(read()&1);
	if(ans&1)puts("NO");
	else puts("YES");
	return 0;
}

Measured memory_bytes: 3624
n = int(input())
num = []
maxnum = 0
count = 1
for i in range(n):
  a = int(input())
  if a>maxnum:
    maxnum = max(maxnum,a)
    count = 1
  elif a==maxnum:
    count += 1
  num.append(a)
  
for i in range(n):
  if count>1:
    print(maxnum)
  else:
    if num[i]!=maxnum:
      print(maxnum)
    else:
      subnum = num[0:i] + num[i+1:n]
      subnum = sorted(subnum)
      print(subnum[n-2])

Measured memory_bytes: 15684
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b)
{if (a < b) {a = b; return true;} return false;}
template<class T> inline bool chmin(T& a,T b)
{if (a > b) {a = b; return true;} return false;}

const long long INF = (1LL<<60);
const int MAX_N = 111;
const int MAX_V = 1010101;
int N, value[MAX_N];
long long W, weight[MAX_N];
long long dp[MAX_N][MAX_V];


int main(){
    cin >> N >> W;
    for(int i = 0; i < N; i++){
        cin >> weight[i] >> value[i];
    }
    
    for(int i = 0; i < MAX_N; i++){
        for(int j = 0; j < MAX_V; j++){
            dp[i][j] = INF;
        }
    }
    
    dp[0][0] = 0;
    for(int i = 0; i < N; i++){
        for(int v = 0; v < MAX_V; v++){
            if(v - value[i] >= 0){
                chmin(dp[i + 1][v], dp[i][v - value[i]] + weight[i]);
            }
            chmin(dp[i + 1][v], dp[i][v]);
        }
    }
    
    long long ans = 0;
    for(int i = 0; i < MAX_V; i++){
        if(dp[N][i] <= W)ans = i;
    }
    
    cout << ans << endl;
    return 0;
}
    

Measured memory_bytes: 876288
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  int k;
  cin >> s >> k;
  int n = s.size();
  REP(i,n-1){
    if(k >= ('z' - s[i] + 1) && s[i] != 'a'){
      k -= 'z' - s[i] + 1;
      s[i] = 'a';
    }
  }
  k %= 26;
  REP(kk,k){
    s[n-1]++;
    if(s[n-1]>'z') s[n-1] = 'a';
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 592
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int gcd(int a, int b){ //最大公約数
  if(a % b == 0) return b;
  return gcd(b, a % b);
}
int main(){
  int n;
  cin >> n;
  int g;
  rep(i, n){
    int a;
    cin >> a;
    if(!i) g = a;
    else g = gcd(g, a);
  }
  cout << g << endl;
}

Measured memory_bytes: 256
// 辞書型 map を利用

#define _GLIBCXX_DEBUG
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>

using namespace std;

int main(){
    int N;
    cin >> N;
    map<string, int> count_map; // ソート後の文字列ごとの個数をカウント
    long long ans = 0;
    for (int i = 0; i < N; i++){
        string key;
        cin >> key;
        sort(key.begin(), key.end());
        if (!count_map.count(key)){ // 所属判定
            count_map[key] = 1;
        } else {
            count_map[key]++;
        }
    }

    for (auto i : count_map){
        // cout << i.first << " : " << i.second << endl;
        int num = i.second;
        ans += (long long)num * (num-1) / 2;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 11136
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <bitset>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll N, P;
  std::cin >> N >> P;
  std::vector<ll> A(N);
  range(i, N) std::cin >> A[i];
  std::vector<ll> odd(N+1, 0);
  std::vector<ll> even(N+1, 0);
  odd[1] = A[0]%2;
  even[1] = (A[0]+1)%2 + 1;
  ranges(i, 1, N) {
    if(A[i]%2==0){
      odd[i+1] = 2 * odd[i];
      even[i+1] = 2 * even[i];
    }else{
      odd[i+1] =  odd[i] + even[i];
      even[i+1] = odd[i] + even[i];
    }
  }
  std::cout << (P==1?odd[N]:even[N]) << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
using namespace std;
long long n,m,i,j,l,r,mid,ans,sum,pre[100005];
struct ii
{
	long long lim,c1,c2;
}a[100005];
bool cmp(ii x,ii y)
{
	return x.lim*x.c1+(m-x.lim)*x.c2>y.lim*y.c1+(m-y.lim)*y.c2;
}
bool check(long long mid)
{
	long long i,p=0;
	while(p<n&&(p+1)*m<=mid)p++;
	if(p>=n){
		return 1;
	}
	fz1(i,n){
		long long t=0;
		if(i>p){
			long long re=mid-m*p;
			t=pre[p];
			if(re<=a[i].lim){
				t+=a[i].c1*re;
			}
			else{
				t+=a[i].c1*a[i].lim+a[i].c2*min(m-a[i].lim,re-a[i].lim);
			}
		}
		else{
			t=pre[p]-(a[i].lim*a[i].c1+(m-a[i].lim)*a[i].c2);
			long long re=mid-m*(p-1);
			if(re>=m){
				t+=(a[p+1].lim*a[p+1].c1+(m-a[p+1].lim)*a[p+1].c2);
				re-=m;
			}
			if(re<=a[i].lim){
				t+=a[i].c1*re;
			}
			else{
				t+=a[i].c1*a[i].lim+a[i].c2*min(m-a[i].lim,re-a[i].lim);
			}
		}
		if(t>=sum)return 1;
	}
	return 0;
}
int main()
{
	scanf("%lld%lld",&n,&m);
	fz1(i,n){
		scanf("%lld%lld%lld",&a[i].lim,&a[i].c1,&a[i].c2);
		sum+=a[i].lim*a[i].c1;
	}
	sort(a+1,a+n+1,cmp);
	fz1(i,n){
		pre[i]=pre[i-1];
		pre[i]+=a[i].lim*a[i].c1+(m-a[i].lim)*a[i].c2;
	}
	l=-1;r=sum;ans=sum;
	while(l<r){
		mid=(l+r+1)/2;
		if(check(mid)){
			r=mid-1;ans=mid;
		}
		else l=mid;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3456
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let n: i32 = s.trim().parse().ok().unwrap();

    let t: i32 = s.trim()
                  .chars()
                  .map(|c| c.to_digit(10)
                            .unwrap() as i32)
                  .sum();
    if n % t == 0 {
        println!("Yes");
    } else {
        println!("No");
    }
}

Measured memory_bytes: 4352
#define rep(i,n) for(i=0;i<n;++i)
a[1<<18],v[1<<18][3],n,m,q,c,i,j;main(){scanf("%d%d%d",&n,&m,&q);rep(i,n)rep(j,2)v[i][j]=(i+n+1-2*j)%n;rep(i,m){scanf("%d",a+i);rep(j,a[i])c=v[c][a[i]&1];v[c][2]=1;rep(j,2)v[v[c][j^1]][j]=v[c][j];c=v[c][0];}rep(i,q)scanf("%d",&c),printf("%d\n",1-v[c][2]);exit(0);}

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

int a, b;

void solve()
{
    int ans;
    if (a < 10 && b < 10)
    {
        ans = a * b;
    }
    else
        ans = -1;
    cout << ans;
}

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

    solve();
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int a,b,i,t;
	scanf("%d%d",&a,&b);
	for(i = 0;i <= 0;i++){
	
	if(a % b == 0){
	printf("%d",-1);
		break;
		}

	for(t = 2;t <= 100000000;t++){
	if((a * t) % b != 0){
	printf("%d",a * t);
		break;
		}
		}
}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define testcase int t;cin>>t;while(t--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<long long int,long long int>
#define ub upper_bound // '>'
#define lb lower_bound // '>='
//erase,count,find,make_unique
#define len(arr) (sizeof(arr)/sizeof(arr[0]))
#define make_unique(arr) arr.erase(unique(arr.begin(),arr.end()),arr.end()) //Makes a sorted array unique
#define rep(a,b) for(int i=a;i<b;i++)
#define updiv(a,b) (ceil)((a)*(1.0)/(b))
typedef long long int ll;
typedef unsigned long long int ull;
#define M 1000000007
using namespace std;
int main()
{
    fast
ll n;
cin>>n;
int h[n+1];
for(ll i=1;i<=n;i++)
{
    cin>>h[i];
}
ll dp[n+1];
dp[1]=0;
dp[2]=abs(h[2]-h[1]);
for(ll i=3;i<=n;i++)
{
  dp[i]=min((dp[i-1]+abs(h[i]-h[i-1])),(dp[i-2]+abs(h[i]-h[i-2])));
} cout<<dp[n]<<endl;
return 0;
}








Measured memory_bytes: 1408
#include<iostream>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	int a,b,c;
	a=n*m*1;
	b=n*m*2;
	c=n*m*3;
	if((a%2!=0)||(b%2!=0)||(c%2!=0))
	printf("Yes");
	else
	printf("No");
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long i64;
using std::cout;
using std::endl;
using std::cin;

int main(){
	std::string s, tmp; cin >> s;
	cin >> tmp; s += tmp;
	cin >> tmp; s += tmp;
	
	int ma = 0;
	for(int i = 0; i < 3; i++) {
		for(int j = 0; j < 3; j++) {
			for(int k = 0; k < 3; k++) {
				if(i == j || j == k || k == i) continue;
				std::string A = "";
				A += s[i];
				A += s[j];
				A += s[k];
				
				for(int l = 1; l < 3; l++) {
					ma = std::max(ma, stoi(A.substr(0, l)) + stoi(A.substr(l, s.size() - l)));
				}
			}
		}
	}
				
	cout << ma << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>
#include <string.h>

int main( void ) {

	char temp[33], words[100][33];
	int count[100], i , maxfreq[2], maxlen[2];

	maxfreq[0] = 0, maxlen[0] = 0;

	for ( i = 0; i < 100; i++) { strcpy( words[i], "" ); count[i] = 0; }

	while ( scanf( "%s", &temp ) != EOF ) {

		for ( i = 0; temp[i] != '\0'; i++ ) { if ( isupper( temp[i] ) ) { tolower( temp[i] ); } }

		for ( i = 0; strcmp( words[i], "" ) != 0; i++ ) { if ( strcmp( temp, words[i] ) == 0 ) { count[i]++; break; } }

		strcpy( words[i], temp );

	}

	for ( i = 0; i < 100; i++) {

		if ( strlen( words[i] ) > maxlen[0] ) { maxlen[0] = strlen( words[i] ); maxlen[1] = i; }
		if ( count[i] > maxfreq[0] ) { maxfreq[0] = count[i]; maxfreq[1] = i; }
	
	}

	printf( "%s %s\n", words[maxfreq[1]], words[maxlen[1]] );

	return 0;

}

Measured memory_bytes: 572
#include <bits/stdc++.h> 
#include <complex>
#include <queue>
#include <set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF LLONG_MAX
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())

ll mpow(ll a, ll b){
	if(b==0) return 1;
	ll t1 = mpow(a,b/2);
	t1 *= t1;
	t1 %= MOD;
	if(b%2) t1 *= a;
	t1 %= MOD;
	return t1;
}

ll mpow(ll a, ll b, ll p){
	if(b==0) return 1;
	ll t1 = mpow(a,b/2);
	t1 *= t1;
	t1 %= p;
	if(b%2) t1 *= a;
	t1 %= p;
	return t1;
}

ll modinverse(ll a, ll m){
	ll m0 = m; 
    ll y = 0, x = 1; 
    if (m == 1) return 0; 
    while (a > 1){
        ll q = a / m; 
        ll t = m; 
        m = a % m, a = t; 
        t = y; 
        y = x - q * y; 
        x = t; 
    }
    if (x < 0) x += m0; 
    return x; 
}

ll range(ll l, ll r){
	return l + rand()%(r-l+1);
}

void solve(){
	ll n;
	cin >> n;
	ll a[n];
	ll c = 0;
	forn(i,n){
		cin >> a[i];
		if(a[i]!=i+1) c++;
	}
	if(c<3){
		cout << "YES" << ln;
	}
	else{
		cout << "NO" << ln;
	}
}

int main()
{
	fast_cin();
    ll t=1;
    // cin >> t;
    forn(i,t) {
    	solve();
    }
    return 0;
}

Measured memory_bytes: 256
import sys
import queue
n,m = map(int, sys.stdin.readline().rstrip("\n").split())
adj = [[]for i in range(n+1)]
parent = [-1] * (n+1)
for line in sys.stdin:
    a,b = map(int, line.rstrip("\n").split())
    adj[a].append(b)
    adj[b].append(a)
q = queue.Queue()
q.put((1,0))
while(not q.empty()):
    x, p = q.get()
    if parent[x] != -1: # 訪問済み
        continue
    parent[x] = p
    for next in adj[x]:
        if parent[next] == -1: # 未訪問なら
            q.put((next,x))
print ('Yes') # 必ず目標は達成できる
for p in parent[2:]: # 部屋2以降の親（前の部屋）
    print(p)

Measured memory_bytes: 40276
#include <iostream>

using namespace std;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main() {
	int d[3];
	cin >> d[0] >> d[1] >> d[2];

	for (int j = ARRAY_LENGTH(d) - 1; j >= 1; j--) {
		for (int i = 0; i < j; i++) {
			if (d[i] > d[i + 1]) {
				int tmp = d[i];
				d[i] = d[i + 1];
				d[i + 1] = tmp;
			}
		}
	}
	for (int i = 0; i < ARRAY_LENGTH(d) - 1; i++) {
		cout << d[i];
		cout << " ";
	}
	cout << d[ARRAY_LENGTH(d) - 1] << endl;

}


Measured memory_bytes: 3084