akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define debug(...) cout<<__FUNCTION__<<":"<<__LINE__<<": ";debugger(#__VA_ARGS__, __VA_ARGS__);
template<typename arg>
void debugger(const char* varname, arg&& var) { cout<<varname<<" = "<<var<<endl; }
template<typename arg, typename... args>
void debugger(const char* varnames, arg&& var, args&&... vars) {
    const char* comma = strchr(varnames + 1, ',');
    cout.write(varnames, comma - varnames)<<" = "<<var<<" | ";
    int sz = 1; if(isspace(comma[sz])) sz++;
    debugger(comma + sz, vars...);
}
#define forr(i, s, n) for(ll i=(ll)(s); i<(ll)(n); ++i)
#define forn(i, n) forr(i, 0, n)
#define eb(n) emplace_back(n)
#define endl '\n'
#define fst first
#define snd second
using ll = long long;
using ii = pair<ll,ll>;
using vi = vector<ll>;
extern const int INF = INT_MAX - 5;
extern const ll LINF = LLONG_MAX - 5;
extern const int MOD = 1e9 + 7;
extern const int N = 2e5 + 200;
int n,x,y;
ll ans[N];
int main() {
    scanf("%d %d %d", &n, &x, &y);
    for(int i = 1; i <= n; ++i) {
        for(int k = i + 1; k <= n; ++k) {
            if(i <= x) {
                if(k >= y) ans[1 + (x - i) + (k - y)]++;
                else {
                    int mn = min(k - i, x - i + y - k + 1);
                    ans[mn]++;
                }
            } else if(i <= y) {
                if(k <= y) {
                    int mn = min(k - i, i - x + y - k + 1);
                    ans[mn]++;
                } else {
                    int mn = min(k - i, i - x + k - y + 1);
                    ans[mn]++;
                }
            } else ans[k - i]++;
        }
    }
    for(int i = 1; i < n; ++i) {
        printf("%lld\n", ans[i]);
    }
    return 0;
}


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

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define BUFF ios::sync_with_stdio(false);

typedef long long int ll;
typedef long double ld;
typedef vector < int > vi;
typedef vector < vi > vvi;
typedef pair < int, int > ii;
typedef vector < ii > vii;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const int MOD = 1e9+7;
const ld pi = acos(-1);

int n, k;
vector<bool> d(15, true);
int main() { BUFF
  cin >> n >> k;
  for(int i=0; i<k; i++) {
    int x; cin >> x;
    d[x] = false;
  }
  for(;;n++) {
    string s = to_string(n);
    bool ok = true;
    for(auto c : s) {
      if(!d[c - '0']) {
        ok = false;
      }
    }
    if(ok){
    cout << s << endl;
    return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
/* 36 - 44 */
#include <iostream>
#include <vector>
using namespace std;

vector<bool> prime(10000001,true);

void init_prime(){
	prime[0] = prime[1] = false;
	
	for(int i=2;i*i<=10000000;i++){
		if(prime[i]){
			for(int j=i*2;j<=10000000;j+=i){
				prime[j] = false;
			}
		}
	}
}

int main(){
	init_prime();
	int n;
	while(cin >> n , n ){
		while(n){
			if( prime[n] && prime[n-2] && prime[n-6] && prime[n-8] ){
				cout << n << endl;
				break;
			}
			n--;
		}
	}
}

Measured memory_bytes: 2120
#include<stdio.h>

struct drink{
  long a;
  int b;
};
void quick(struct drink *,int,int);

int main(){

int N,M,d_count=0;
long ans=0;
scanf("%d%d",&N,&M);
struct drink d[N];
for (int i = 0; i < N; i++)
{
  scanf("%ld%d",&d[i].a,&d[i].b);
}

quick(d,0,N-1);

int i=0;
while (d_count<M)
{
  d_count += d[i].b;
  ans+=d[i].a*d[i].b;
  i++;
}

printf("%ld",ans-(d_count-M)*d[i-1].a);

  return 0;
}

void quick(struct drink a[],int left,int right)
{    
    int i,j;
    struct drink t,s;
    if (left<right){
        s.a=a[(left+right)/2].a;
        i=left-1; j=right+1;
        while (1){
            while (a[++i].a<s.a);
            while (a[--j].a>s.a);
            if (i>=j) break;
            t=a[i]; a[i]=a[j]; a[j]=t;
        }

        quick(a,left,i-1);
        quick(a,j+1,right);
    }
}

Measured memory_bytes: 3292
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll N; cin >> N;
    cout << N * (N - 1) / 2 << endl;
    return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(ll i=x;i<y;i++)
#define frr(i,x,y) for(ll i=x-1;i>=y;i--)
#define inf 1e18+1
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll mod=1000000007;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

void solve()
{
    ll n;
    cin>>n;
    VL arr(n);
    ll ans=0;
    fr(i,0,n)
    {
        cin>>arr[i];
        ans=ans^arr[i];
    }
    fr(i,0,n)
    {
        ll f=ans^arr[i];
        cout<<f<<" ";

    }
    cout<<"\n";
    return;
}
int main()
{
    IOS;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}
/* stuff you should look for
        * int overflow, array bounds
        * special cases (n=1?)
        * do smth instead of nothing and stay organized
        * WRITE STUFF DOWN
*/
// BITMASK:
// 1)When some constrall is of the order of 15-20, think of bitmask DP.
// 2)When some constrall is around 40, try out meet in the middle
// 3) See Strings,palindromes,prefix,suffix etc -> KMP,Z algorithm

Measured memory_bytes: 4764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int inf=1e9;
int main(void)
{
    int N;
    ll A[200005];
    ll sum=0;
    ll ans=1e18;
    cin >> N;
    for(int i=0;i<N;i++)
    {
        cin >> A[i];
        sum+=A[i];
    }
    for(int i=0;i<N;i++)
    {
        if(i>0) A[i]+=A[i-1];
        ans=min(ans,abs((sum-2LL*A[i])));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define FOR(i, b, n) for (ll i = b; i < n; ++i)

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

void solve(ll N, vector<ll> a) {
  ll ans(0);
  REP(i, N)
    if (((i + 1) % 2) && (a[i] % 2))
      ans++;
  cout << ans << endl;
}

int main(){
  // int 3E4  long 2E9  ll 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;
  vector<ll> a(N);
  REP(i, N) {
    cin >> a[i];
  }

  solve(N, move(a));

  return 0;
}


Measured memory_bytes: 3568
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <stack>
#include <bitset>
#include <utility>
#include<iomanip>
// #include <numeric>
using namespace std;



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector<vector<ll>> vvint;
typedef vector<string> vstring;
typedef vector<vector<string>> vvstring;
typedef vector<char> vchar;
typedef vector<vector<char>> vvchar;
typedef vector<long double> vdouble;
typedef vector<vector<long double>> vvdouble;
typedef vector<vector<vector<long double>>> vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define INT_MAX 2147483647
#define LLONG_MAX 9223372036854775807
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define DIVIDER 1000000007


//
// struct Node{
//   vint children;
//   ll index;
//   ll prop;
// };
// struct edge{ll to; ll cost;};



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

// ll X,Y,Z,K;
// ll pmax = 30000000000;
// vint A,B,C;




// struct UnionFind {
//     vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
//
//     UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
//         for(int i = 0; i < N; i++) par[i] = i;
//     }
//
//     int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
//         if (par[x] == x) return x;
//         return par[x] = root(par[x]);
//     }
//
//     void unite(int x, int y) { // xとyの木を併合
//         int rx = root(x); //xの根をrx
//         int ry = root(y); //yの根をry
//         if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
//         par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
//     }
//
//     bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };
//
// vint divisor(ll n){ // nの約数
//   vint ret;
//   for(ll i=1;i*i<=n;i++){
//     if(n%i == 0){
//       ret.pb(i);
//       if(i*i!=n) ret.pb(n/i);
//     }
//   }
//   vsort(ret);
//   return ret;
// }
//
// ll get_digits_num(ll n){
//   ll ret=0;
//   while(n){
//     n/=10;
//     ret++;
//   }
//   return ret;
// }



int main() {
  cout<<fixed<<setprecision(10);

  ll N,M,K;
  cin>>N>>M>>K;

  bool can = false;
  rep(i,N+1){
    rep(j,M+1){
      if(K==i*M+j*N-2*i*j){
        can=true;
        break;
      }
    }
  }

  if(can) cout << "Yes" <<endl;
  else cout <<"No"<<endl;


}

















//


Measured memory_bytes: 256
date = [int(s) for s in input().split('/')]
if date[0] > 2019:
    print('TBD')
elif date[0] == 2019 and date[1] > 4:
  	print('TBD')
elif date[0] == 2019 and date[1] == 4 and date[2] > 30:
  	print('TBD')
else:
  	print('Heisei')

Measured memory_bytes: 3060
N = int(input())
W = [input() for _ in range(N)]

if len(W) != len(set(W)):
    print("No")
    exit()
    
for i in range(N-1):
    if W[i][len(W[i])-1] != W[i+1][0]:
        print("No")
        exit()

print("Yes")


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <functional>
#include <cmath>
#include <cstdint>
#include <mutex>
#include <thread>
#include <bitset>
#include <utility>

using namespace std;

int main()
{
	int x, y, z;
	cin >> x >> y >> z;
	cout << z << " " << x << " " << y;
	return 0;
}


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

using namespace std;

int main() {

	const long long INF = 1ll << 60;
	int v, e;
	cin >> v >> e;
	vector<vector<long long>> G(v, vector<long long>(v, INF));
	int in1, in2, in3;
	for (int i = 0; i < e; i++) {
		cin >> in1 >> in2 >> in3;
		G[in1][in2] = in3;
	}

	vector < vector <long long >> dp(1 << v, vector<long long>(v, INF));

	dp[0][0] = 0;

	for (int s = 0; s < (1 << v); s++) {

		for (int i = 0; i < v; i++) {

			for (int j = 0; j < v; j++) {

				if ((s & (1 << i)) == 0) {

					if (i != j) {
						dp[s | (1 << i)][j] = min(dp[s | (1 << i)][j]
														, dp[s][i] + G[i][j]);
					}

				}

			}

		}
		
	}

	if (dp[(1 << v) - 1][0] != INF) {
		cout << dp[(1 << v) - 1][0] << endl;
	}
	else { cout << -1 << endl; }

	return 0;

}


Measured memory_bytes: 7644
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt = fst . fromJust . BS.readInt

readIntList = map readInt . BS.words

getIntList = readIntList <$> BS.getLine

getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine

-- 双方向化
setEdge :: VM.IOVector [Int] -> [[Int]] -> IO ()
setEdge v (ab : abs) = do
  let [a, b] = ab
  VM.modify v (a :) b
  VM.modify v (b :) a
  when (abs /= []) $ setEdge v abs

-- table個別埋め
draw :: VUM.IOVector Int -> [Int] -> Int -> [Int] -> IO [Int]
draw table (e : es) n ks = do
  p <- VUM.read table (e - 1)
  when (p == 0) $ VUM.write table (e - 1) n
  let ks' = if (p == 0) then (e : ks) else ks
  if (es /= [])
    then draw table es n ks'
    else return ks'

-- 埋める
simulate :: [Int] -> [Int] -> VUM.IOVector Int -> V.Vector [Int] -> IO ()
simulate (n : ns) ks table edges = do
  let edges' = edges V.! n
  ks' <- draw table edges' n ks
  if (ns /= [])
    then simulate ns ks' table edges
    else when (ks' /= []) $ simulate ks' [] table edges

main = do
  [n, m] <- getIntList
  abs <- getIntNList m
  vm <- VM.replicate (n + 1) [] :: IO (VM.IOVector [Int])
  setEdge vm abs
  edges <- V.freeze vm
  table <- VUM.replicate n 0 :: IO (VUM.IOVector Int)
  simulate [1] [] table edges
  t <- VU.freeze table
  putStrLn "Yes"
  VU.mapM_ print (VU.tail t)


Measured memory_bytes: 72736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
using pii = pair<int, int>;
const ll mod = 1e9 + 7;
int main() {
  int n, m;
  cin >> n >> m;
  vector<bool> ng(n, false);

  for (int i = 0; i < m; i++) {
    int temp;
    cin >> temp;
    ng[temp] = true;
  }

  vector<ll> dp(n + 1, 0LL);
  dp[0] = 1;
  dp[1] = ng[1] ? 0 : 1;

  for (int i = 0; i < n - 1; i++) {
    if (ng[i]) dp[i] = 0;
    if (ng[i + 1]) dp[i + 1] = 0;

    dp[i + 2] = dp[i + 1] % mod + dp[i] % mod;
    dp[i + 2] %= mod;
  }

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

Measured memory_bytes: 4008
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using Tup = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<(v)<<"\n";
#define fl cout<<flush;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld pi=3.141592653589793238;



signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> p(N,0);
    for(ll i=0;i<N;++i)cin>>p[i];
    ll sum=0;
    for(ll i=0;i<N;++i)sum+=p[i];
    sort(p.rbegin(), p.rend());
    sum-=p[0]/2;
    prt(sum)

    return 0;
}


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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005;

int main(){
    
    string S;cin>>S;
    int N=S.size();
    vector<int> T(N,0),sum(N+1,0);
    int K;cin>>K;
    for(int i=0;i<N;i++){
        T[i]=(26-(S[i]-'a'))%26;
        sum[i+1]=sum[i]+T[i];
    }
    int stop=N;
    for(int i=0;i<N+1;i++){
        if(K<sum[i]){
            stop=i-1;
            break;
        }
    }
    for(int i=0;i<stop;i++){
        S[i]='a';
    }
    K-=sum[stop];
    for(int i=stop;i<N;i++){
        if(K>=T[i]){
            S[i]='a';
            K-=T[i];
        }
    }
    
    S[N-1]+=(K%26);
    
    cout<<S<<endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;


template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

// 繰り返し二乗法
ll pow2(ll n, ll p, ll mod) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n % mod, p / 2, mod);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret % mod;
	}
}

#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


int main() {
	ll N;
	std::cin >> N;

	vll A(N+1);
	repeq(i, 0, N) {
		std::cin >> A[i];
	}

	vll sum(N + 2, 0);
	for (ll i = N ; i >= 0; i--) {
		sum[i] = sum[i + 1] + A[i];
	}
	
	ll ans = 0;
	ll cnt = 1;
	repeq(i, 0, N) {

		if (cnt < A[i]) {
			std::cout << -1 << endl;
			return 0;
		}

		ans += cnt;
		cnt -= A[i];
		cnt = min(2*cnt,sum[i+1]);
	}
	std::cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4824
#include <stdio.h>

int main(void){
  int n;
  int a;
  scanf("%d",&n);
  for(int i=0;i<3;i++){
    if(n%10==7){
      printf("Yes\n");
      return 0;
    }
    else n /=10;
  }
  printf("No\n");
  return 0;
}


Measured memory_bytes: 1612
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int main()
{
	int k, a, b;
	cin >> k >> a >> b;
	for(int i = a; i<= b; i ++)
		if(i % k == 0)
			return cout << "OK", 0;
		cout << "NG";





	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

Measured memory_bytes: 3596
# -*- coding: utf-8 -*-
N=int(input())
A=[]
for _ in range(N):
    A.append(int(input()))
maxvalue=max(A)
i=A.index(maxvalue)
del A[i]
secondvalue=max(A)
for j in range(0,i):
    print(maxvalue)
print(secondvalue)
for j in range(i+1,N):
    print(maxvalue)

Measured memory_bytes: 12628
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()

graph = defaultdict(list)
for _ in range(M):
	L, R, D = MAP()
	graph[L-1].append((R-1, D))
	graph[R-1].append((L-1, -D))

num = [None]*N

for i in range(N):
	if num[i] != None:
		continue
	q = deque([i])
	num[i] = 0
	while q:
		n = q.popleft()
		for node, weight in graph[n]:
			if num[node] == None:
				num[node] = num[n] + weight
				q.append(node)
			else:  # 閉路⇒条件チェック
				if num[node]-num[n] != weight:
					print("No")
					exit()

print("Yes")


Measured memory_bytes: 76484
import sys

MAX = 10**18

N = int(input())
A = list(map(int,input().split()))

if 0 in A:
    print("0")
else:
    res = 1
    for a in reversed(sorted(A)):
        if a == 1:
            break
        res *= a
        if res > MAX:
            print("-1")
            sys.exit()
    print(res)


Measured memory_bytes: 21660
#include<stdio.h>
#include<string.h>

int main(){
 int a,b;
  scanf("%d %d",&a,&b);
  int c,d,e;
  float f,g,h;
  c=a/0.08;
  d=b/0.1;
  f=a/0.08;
  g=b/0.1;
  h=g-f;
    if(h>-10 && h<12.5){
      goto next;
    }else{
      printf("-1");
      
      return 0;
    }
 
  
    next:;
    if(c>d){
      if(f-c>0){
      e=c+1;
      }
        else{
          e=c;
        }
    }else{
        if(g-d>0){
          e=d+1;
        }else{
          e=d;
        }
    }
    printf("%d",e);
  }
    

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
using namespace std;
typedef long long int lli;

void dfs(int v, vector<int> &dist, vector<vector<int> > &g){
    for(int next: g[v]){
        if(dist[next] == -1){
            dist[next] = dist[v]+1;
            dfs(next, dist, g);
        }
    }
}

int diameter(vector<vector<int> > &g){
    int n = g.size();
    vector<int> d(n, -1);
    d[0] = 0;
    dfs(0, d, g);
    int idx = max_element(d.begin(), d.end()) -d.begin();
    d = vector<int>(n, -1);
    d[idx] = 0;
    dfs(idx, d, g);
    return *max_element(d.begin(), d.end());
}

int main(){
    int n;
    cin >> n;
    vector<vector<int> > g(n);
    for(int i=0; i<n-1; i++){
        int u,v;
        cin >> u >> v;
        u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    int d = diameter(g);
    vector<bool> win(1000000, false);
    win[1]=true;
    win[2]=false;
    for(int i=3; i<1000000; i++){
        if(!win[i-2] or !win[i-1]) win[i] = true;
    }
    if(win[d+1]){
        cout << "First" << endl; 
    }else{
        cout << "Second" << endl;
    }
    return 0;
}

Measured memory_bytes: 21760
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c;
    std::cin >> a>>b>>c;
    int A1,A2,A3;
    
    if(a>b)
    {
        if(a>c)
        {
            A1=a;
            if(b>c)
            {
                A2=b;
                A3=c;
            }
            else
            {
                A2=c;
                A3=b;
            }
        }
    }
    
    if(b>c)
    {
        if(b>a)
        {
            A1=b;
            if(c>a)
            {
                A2=c;
                A3=a;
            }
            else
            {
                A2=a;
                A3=c;
            }
        }
    }
    
    if(c>a)
    {
        if(c>b)
        {
            A1=c;
            if(a>b)
            {
                A2=a;
                A3=b;
            }
            else
            {
                A2=b;
                A3=a;
            }
        }
    }
    
    std::cout << A3<<" "<<A2<<" "<<A1 << std::endl;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h> 
typedef double ll;
#define pb push_back
#define MP make_pair

using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll x,y,n,d,i;
    cin>>n>>d;
    double j,r,a,b;
    ll c=0;
    for(i=0;i<n;i++)
    {
     cin>>x>>y;
     a=x*x;
     b=y*y;
     j=a+b;
     r=sqrt(j);
     if(r<=d)
     c++;
    
    }
    cout<<c<<"\n";
    
     return 0;
}


Measured memory_bytes: 3852
N = list(input())

#print(N)

def count(list_1):
    count_2 = 0
    count_1 = 0
    for a in range(len(list_1)):
        if list_1[a] == 'R':
            count_1 += 1
        else:
            count_1 = 0
        if count_2 < count_1:
            count_2 = count_1
            #print(count_2)
    return count_2

print(count(N))

Measured memory_bytes: 9068
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import random
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def main():

	#N = int(input())
	#S = list(input())
	N,A,B = map(int, input().split(" "))
	#L = list(map(int, input().split(" ")))

	a = N*A
	b=B
	

	

	print(min(a,b))




if __name__ == "__main__":
	main()

Measured memory_bytes: 5104
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(){

    long long x; cin >> x;

    long long ure = 0;

    ure += (x/500)*1000;
    ure += ((x%500)/5)*5;
    
    cout << ure << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    int m, d;
    cin >> m >> d;
    int ans = 0;
    REP(i, 1, m+1) {
        REP(j, 2, 10) REP(k, 2, 10) {
            if(j*10+k <= d) {
                if(j*k == i) ++ans;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    int tmp = n;
    int num = 0;
    REP(i,10){
        num += n%10;
        n/=10;
    }
    if(tmp%num == 0)cout << "Yes" << endl;
    else cout<< "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

int main(){
    int t;
    cin >> t;
    rep(i, t){
        ll a, b, c, d;
        cin >> a >> b >> c >> d;
        if (a < b || d < b) {
            cout << "No" << endl;
            continue;
        }
        if (c >= b - 1) {
            cout << "Yes" << endl;
            continue;
        }
        ll g = __gcd(b, d);
        if (b + a%g - g > c) cout << "No" << endl;
        else cout << "Yes" << endl;
    }

    return 0;
}


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

int main(int argc, char const *argv[]) {
    string s, p, concatedStr;
    cin >> s >> p;

    concatedStr = s + s;
    if (concatedStr.find(p) == concatedStr.npos) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }

    return 0;
}



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

count = 0
if cList[0] > x:
  count += cList[0]- x
  cList[0] = x
for i in range(1,n):
  tmp = cList[i-1]+cList[i]-x
  if tmp > 0:
    cList[i] -= tmp
    count += tmp

print(count)
 

Measured memory_bytes: 14052
#include<iostream>

using namespace std;

int main(){

    ios::sync_with_stdio(false);

    int i,h,cont=1,limit;

    cin>>i;

    cin>>limit;
    i--;

    while(i--){
        cin>>h;
        if(h>=limit){
            cont++;
            if(h>limit)limit=h;
        }
    }

    cout<<cont<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  while(1) {
    string s; cin >> s;
    if(s == "0") break;
    string t, u; cin >> t >> u;
    int n = s.size();
    vector<int> a(n), b(n), c(n);
    for(int i=0;i<n;++i) {
      if(s[i] == '?') a[i] = -1;
      else a[i] = s[i] - '0';
    }
    for(int i=0;i<n;++i) {
      if(t[i] == '?') b[i] = -1;
      else b[i] = t[i] - '0';
    }
    for(int i=0;i<n;++i) {
      if(u[i] == '?') c[i] = -1;
      else c[i] = u[i] - '0';
    }
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    reverse(c.begin(), c.end());
    vvll dp(n+1, vll(2, 0));
    dp[0][0] = 1;
    for(int d=0;d<n;++d) {
      for(int i=0;i<=9;++i) {
        if(d == n-1 && i == 0) continue;
        for(int j=0;j<=9;++j) {
          if(d == n-1 && j == 0) continue;
          for(int k=0;k<=9;++k) {
            if(d == n-1 && k == 0) continue;
            if((a[d] == -1 || a[d] == i) &&
                (b[d] == -1 || b[d] == j) &&
                (c[d] == -1 || c[d] == k)) {
              if((i + j) % 10 == k) dp[d+1][(i + j) / 10] += dp[d][0];
              if((i + j + 1) % 10 == k) dp[d+1][(i + j + 1) / 10] += dp[d][1];
              dp[d+1][0] %= MOD;
              dp[d+1][1] %= MOD;
            }
          }
        }
      }
    }
    cout << dp[n][0] << endl;
  }
}



Measured memory_bytes: 3096
import java.util.*;

public class Main{
    public static void main (String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long ans = 1;

        for(int i=1; i<=N; i++){
            ans = ans * i % 1000000007;
        }

        System.out.println(ans);
    }
}

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

int main(){
        while(true){
                int m,n,Mx[200],My[200],Nx[1000],Ny[1000];

                cin>>m;
                if(m==0){
                        break;
                }
                for(int i=0;i<m;i++){
                        cin>>Mx[i]>>My[i];
                }
                cin>>n;
                for(int i=0;i<n;i++){
                        cin>>Nx[i]>>Ny[i];
                }

                int dx[200][1000],dy[200][1000];
                for(int i=0;i<m;i++){
                        for(int j=0;j<n;j++){
                                dx[i][j]=Nx[j]-Mx[i];
                                dy[i][j]=Ny[j]-My[i];
                        }
                }

                int ansx,ansy,star;
                for(int i=0;i<m;i++){
                        for(int j=0;j<n;j++){
                                star=0;
                                for(int k=0;k<m;k++){
                                        for(int l=0;l<n;l++){
                                                if(dx[i][j]==dx[k][l] && dy[i][j]==dy[k][l] && i!=k && j!=l){
                                                        star++;
                                                        if(star==m-1){
                                                                ansx=dx[i][j];
                                                                ansy=dy[i][j];
                                                                goto goal;
                                                        }
                                                }
                                        }
                                }
                        }
                }

goal:
                cout<<ansx<<" "<<ansy<<endl;
        }
        
        return 0;
}

Measured memory_bytes: 2732
a,b,c=map(int,input().split())
d=max(a,b,c)
s=a+b+c
if d%2==0 and s%2==0:
  print((3*d-a-b-c)//2)
elif d%2==1 and s%2==1:
  print((3*d-a-b-c)//2)
else:
  print((3*(d+1)-a-b-c)//2)

Measured memory_bytes: 9132
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define ll long long int



int main(){
    int n,m;
    cin>>n>>m;
    vector<int> a(n,-1);
    vector<vector<int>> tree(n);
    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        u--,v--;
        tree[u].push_back(v);
        tree[v].push_back(u);
    }
    vector<bool> inc(n,false);
    function<void(int,int)> dfs =[&](int node,int cur){
        debug(node,cur);
        a[node]=cur;
        inc[node]=true;
        for(auto v:tree[node]){
            if(!inc[v])dfs(v,cur);
        }
    };
    int gr=1;
    for(int i=0;i<n;i++){
        if(!inc[i])dfs(i,gr++);
        
    }
    debug(a);
    vector<int> cnt(gr);
    for(int i=0;i<n;i++){
        cnt[a[i]-1]++;
    }
    debug(cnt);
    cout<<*max_element(cnt.begin(),cnt.end())<<"\n";
    return 0;
}


Measured memory_bytes: 39880
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7;
const ll LINF=1e18;
using namespace std;
#define int long long
//template

//main
signed main(){
  int N;string s;cin>>N>>s;
  std::vector<int> v(26,0);
  for(int i=0;i<N;i++)v[s[i]-'a']++;
  int ans=1;
  for(int i=0;i<26;i++)ans=ans*(v[i]+1)%MOD;
  cout<<ans-1<<endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdlib>
#include <cstdio>
using namespace std;

struct Node {
  int key;
  Node *right,*left,*parent;
};

Node *root, *NIL;

Node *treeMinimum(Node *x) {
  while (x->left!=NIL) {
    x=x->left;
  }
  return x;
}
Node *treeSuccessor(Node *x) {
  if (x->right!=NIL) {
    return treeMinimum(x->right);
  }
  Node *y=x->parent;
  while (y!=NIL && x==y->right) {
    x=y;
    y=y->parent;
  }
  return y;
}
void treeDelete(Node *z) {
  Node *y;
  Node *x;
  if (z->left==NIL || z->right==NIL) {
    y=z;
  } else {
    y=treeSuccessor(z);
  }
  if (y->left!=NIL) {
    x=y->left;
  } else {
    x=y->right;
  }
  if (x!=NIL) {
    x->parent=y->parent;
  }
  if (y->parent==NIL) {
    root=x;
  } else {
    if (y==y->parent->left) {
      y->parent->left=x;
    } else {
      y->parent->right=x;
    }
  }
  if (y!=z) {
    z->key=y->key;
  }
  free(y);
}
Node *find(Node *u,int k) {
  while (u!=NIL && k!=u->key) {
    if (k<u->key) {
      u=u->left;
    } else {
      u=u->right;
    }
  }
  return u;
}
void insert(int k) {
  Node *y=NIL;
  Node *x=root;
  Node *z;
  z=(Node *)malloc(sizeof(Node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;
  while (x!=NIL) {
    y=x;
    if (z->key<x->key) {
      x=x->left;
    } else {
      x=x->right;
    }
  }
  z->parent=y;
  if (y==NIL) {
    root=z;
  } else {
    if (z->key<y->key) {
      y->left=z;
    } else {
      y->right=z;
    }
  }
}
void inorder(Node *u) {
  if (u==NIL) {
    return;
  }
  inorder(u->left);
  cout<<" "<<u->key<<flush;
  inorder(u->right);
}
void preorder(Node *u) {
  if (u==NIL) {
    return;
  }
  cout<<" "<<u->key<<flush;
  preorder(u->left);
  preorder(u->right);
}
int main() {
  int n;
  scanf("%d",&n);
  string com;
  int x;
  for (int i=0; i<n; i++) {
    cin>>com;
    if (com=="find") {
      scanf("%d",&x);
      Node *t=find(root,x);
      if (t!=NIL) {
        cout<<"yes"<<endl;
      } else {
        cout<<"no"<<endl;
      }
    } else if (com=="insert") {
      scanf("%d",&x);
      insert(x);
    } else if (com=="print") {
      inorder(root);
      cout<<endl;
      preorder(root);
      cout<<endl;
    } else if (com=="delete") {
      scanf("%d",&x);
      treeDelete(find(root,x));
    }
  }
  return 0;
}





Measured memory_bytes: 21892
#include<stdio.h>
 
int main(void){
    long long A=0;
    long long B=0;
    long long C=0;
    long long D=0;
    
    long long bC=0,bD=0,bCD=0;
    long long aC=0,aD=0,aCD=0;
    long long sumB=0,sumA=0;
    long long max=0;
    long long min=0;
    long long amari=0;
    long long lcm=0;
    scanf("%lld %lld %lld %lld",&A,&B,&C,&D);
    bC=B/C;
    bD=B/D;
    aC=(A-1)/C;
    aD=(A-1)/D;
    if(C<D){
        max=D;
        min=C;
    }
    else{
        max=C;
        min=D;
    }
    while(1){
        amari=max%min;
        if(amari==0) break;
        max=min;
        min=amari;
    }

    lcm=C*D/min;
   
    bCD=B/(lcm);
    aCD=(A-1)/(lcm);
   
    sumB=B-bC-bD+bCD;
    sumA=(A-1)-aC-aD+aCD;
   
  
    printf("%lld\n",sumB-sumA);
    
    return 0;

}

Measured memory_bytes: 128
n,m = map(int,input().split())
a = list(map(int,input().split()))

# for i in range(m):
#     a = sorted(a)
#     b,c = map(int,input().split())
#     for j in range(b):
#         if a[j] >= c:
#             break
#         else:
#             a[j] = c
# print(sum(a))
d = []
for i in range(m):
    b,c = map(int,input().split()) # b 交換できる枚数 c:カードの値
    d.append((b,c))

# dを降順にsorted
d = sorted(d,key=lambda x: x[1], reverse=True)

for i in range(m):
    b,c = d[i]
    a.extend([c]*b)
    if len(a) > 2*n:
        break

print(sum(sorted(a)[-n:]))

Measured memory_bytes: 26696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef pair<string , int> s_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<typename T> void remove(T & vector, unsigned int index){vector.erase(vector.begin() + index);}

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

  ll K, A, B; cin >> K >> A >> B;

  if(A >= K or A + 1 >= B) cout << 1 + K << endl;
  else {
    if( (K - A - 1) % 2 == 0) {
      cout << B  + (K - A - 1) / 2 * (B - A)<< endl;
    }
    else cout << B  + (K - A - 1) / 2 * (B - A) + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int h[200005];
int n;
int i=1;
int dp[200005];
int f(int i){
    if(i+1==n) return 0;
    if(i+2==n) return abs(h[i]-h[i+1]);
    if(dp[i]!=-1) return dp[i];
    return dp[i] = min(abs(h[i]-h[i+1]) + f(i+1),abs(h[i]-h[i+2])+f(i+2));
}
void solve(){
   cin>>n;
   for(int i=0;i<n;i++) cin>>h[i];
   for(int i=0;i<n;i++) dp[i] = -1;
   cout<<f(0)<<endl;
}
int main(){
    int t;
    t = 1;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#define M 500010
using namespace std;

int n,m,num,cnt;
int head[M],c[M],in[M][2];
char s[M];bool vis[M];
struct point{int to,next;}e[M<<1];
void add(int from,int to)
{
	e[++num].next=head[from];
	e[num].to=to;
	head[from]=num;
}
queue<int>q;
int main()
{
	scanf("%d%d",&n,&m);
	scanf("%s",s+1);
	for(int i=1;i<=n;i++) c[i]=s[i]-'A';
	for(int i=1;i<=m;i++)
	{
		int x,y;scanf("%d%d",&x,&y);
		add(x,y); add(y,x);
		in[x][c[y]]++; in[y][c[x]]++;
	}
	for(int i=1;i<=n;i++)
		if(!in[i][0]||!in[i][1])
		{
			q.push(i);
			cnt++;
			vis[i]=true;
		}
	while(!q.empty())
	{
		int x=q.front();q.pop();
		for(int i=head[x];i;i=e[i].next)
		{
			int to=e[i].to;
			in[to][c[x]]--;
			if((!in[to][0]||!in[to][1])&&!vis[to])
			{
				q.push(to);
				cnt++;
				vis[to]=true;
			}
		}
	}
	printf(cnt==n?"No":"Yes");
	return 0;
}

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

int a[20];

int main(){
	int cnt, flag;
	long long n;
	cin >> n;
	cnt = 0;
	while (n > 0){
		a[++cnt] = n % 10;
		n /= 10;
	}
	if (cnt == 1){
		cout << a[1] << '\n';
		return 0;
	}
	flag = 1;
	for (int i = 1; i <= cnt - 1; i++){
		if (a[i] != 9){
			flag = 0;
			break;
		}
	}
	if (flag) cout << a[cnt] + (cnt - 1) * 9 << '\n';
	else cout << a[cnt] + (cnt - 1) * 9 - 1 << '\n';
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
class Program{
    public static void Main(){
        int n = int.Parse(Console.ReadLine());
        var num = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        int q = int.Parse(Console.ReadLine());
        for(int i=0; i<q; i++){
            string[] str = Console.ReadLine().Split(' ');
            int b = int.Parse(str[0]);
            int e = int.Parse(str[1]);
            int t = int.Parse(str[2]);
            for(int k=0; k<(e-b); k++){
                Swap(num, b+k, t+k);
            }
        }
        Console.WriteLine(string.Join(" ",num));
    }
    public static void Swap(int[] num, int a, int b){
        var t = num[a];
        num[a] = num[b];
        num[b] = t;
    }
}



Measured memory_bytes: 20192
#include<stdio.h>
#include<string.h>
#define H 2000000

int n,A[H+1];
int parent(int i){
  return i/2;
}
int left(int i){
  return 2*i;
}
int right(int i){
  return 2*i+1;
}

void maxHeapify(int i){
  int l,r,x,largest;
  l=left(i);
  r=right(i);
  if(l<=n && A[l]>A[i])
    largest=l;
  else
    largest=i;
  if(r<=n && A[r]>A[largest])
    largest=r;
  if(largest!=i){
    x=A[i];
    A[i]=A[largest];
    A[largest]=x;
    maxHeapify(largest);
  }
}

int heapExtractMax(){
  int max;
  if(n<1)
    return -1;
  max=A[1];
  A[1]=A[n];
  n--;
  maxHeapify(1);
  return max;
}
void heapIncreaseKey(int i,int key){
  int x;
  if(key<A[i])
    return;
  A[i]=key;
  while(i>1 && A[parent(i)]<A[i]){
    x=A[i];
    A[i]=A[parent(i)];
    A[parent(i)]=x;
    i=parent(i);
  }
}
void maxHeapInsert(int key){
  n=n+1;
  A[n]=-1;
  heapIncreaseKey(n,key);
}
int main(){
  int i,k,x;
  char com[20];

  while(1){
    scanf("%s",&com);
    
    if(strcmp(com,"end")==0)
      break;
    if(com[0]=='i'){
      scanf("%d",&k);
      maxHeapInsert(k);
    }
    else if(com[0]=='e'){
      x=heapExtractMax();
      if(x!=-1)
	printf("%d\n",x);
    }
  }
  return 0;
}

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

int main() {

    int x, y;
    cin >> x >> y;

    int ans = 0;
    if(x == 3) {
        ans +=100000;
    }

    if(x == 2) {
        ans +=200000;
    }

    if(x == 1) {
        ans +=300000;
    }

    if(y == 3) {
        ans +=100000;
    }

    if(y == 2) {
        ans +=200000;
    }

    if(y == 1) {
        ans +=300000;
    }


    if(x == 1 && y == 1) {
        ans +=400000;   
    }
    cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <time.h>
using namespace std;
#include <math.h>
#define ll long long 
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
//clock_t tStart = clock();
//printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define max1 100001
vector<vector<int> > arr(max1);




int main(){	
	long long int n,k;
	cin>>n>>k;
	vector<int> a(n+1);
	for (int i = 1; i <=n; ++i)
	{
		cin>>a[i];
	}
	map<int,int> mp;
	mp[1]=1;
	int ind=1;
	int ansfd=0;
	int dp[n+1]={0};
	int step=0;
	while(true){
		ind = a[ind];
		step++;
		
		if(k==step){
			ansfd=1;
			cout<<ind<<endl;
			break;
		}
		if(mp[ind]==1){
			break;
		}
		//cout<<ind<<endl;
		dp[ind]=step;
		mp[ind]=1;

	}
	//cout<<ind<<" "<<k<<endl;
	if(!ansfd){
		int cylen=step-dp[ind];
		k-=step;
		k=k%cylen;
		while(k){
			ind=a[ind];
			k--;
		}
		cout<<ind<<endl;
	}
}

Measured memory_bytes: 14500
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
using namespace std;
struct P {
	int x, y;
};
int main() {
	int a[102][102], w, h, c;
	cin >> w >> h;
	for (int i = 0; i <= h + 1; i++) {
		for (int j = 0; j <= w + 1; j++) a[i][j] = 0;
	}
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> c;
			if (c == 0) a[i][j] = 0;
			else a[i][j] = 1;
		}
	}
	queue<P>p;
	int sum = 0;
	h+=2;
	w+=2;
	for (int z = 0; z < 2; z++) {
		if (z == 0) c = 0;
		else c = h - 1;
		for (int j = 0; j < w; j++) {
			p.push(P{ c,j });
		}
	}
	for (int z = 0; z < 2; z++) {
		if (z == 0) c = 0;
		else c = w - 1;
		for (int j = 0; j < h; j++) {
			p.push(P{ j,c });
		}
	}
	while (!p.empty()) {
		P t = p.front(); p.pop();
		int x = t.x, y = t.y;
		if (a[x][y] == 0) {
			a[x][y] = 2;
			if (x % 2 == 0) {
				if (x > 0) {
					if (y > 0 && a[x - 1][y - 1] == 0)
						p.push(P{ x - 1,y - 1 });
					if (y > 0 && a[x - 1][y - 1] == 1)
						sum++;
					if (a[x - 1][y] == 0)
						p.push(P{ x - 1,y });
					if (a[x - 1][y] == 1) sum++;
				}
				if (x + 1 < h) {
					if (y > 0 && a[x + 1][y - 1] == 0)
						p.push(P{ x + 1,y - 1 });
					if (y > 0 && a[x + 1][y - 1] == 1)
						sum++;
					if (a[x + 1][y] == 0)
						p.push(P{ x + 1,y });
					if (a[x + 1][y] == 1) sum++;
				}
			}
			if (x % 2 == 1) {
				if (x > 0) {
					if (y + 1<w && a[x - 1][y + 1] == 0)
						p.push(P{ x - 1,y + 1 });
					if (y +1< w && a[x - 1][y + 1] == 1)
						sum++;
					if (a[x - 1][y] == 0)
						p.push(P{ x - 1,y });
					if (a[x - 1][y] == 1) sum++;
				}
				if (x + 1 < h) {
					if (y +1< w && a[x + 1][y + 1] == 0)
						p.push(P{ x + 1,y + 1 });
					if (y +1<w && a[x + 1][y + 1] == 1)
						sum++;
					if (a[x + 1][y] == 0)
						p.push(P{ x + 1,y });
					if (a[x + 1][y] == 1) sum++;
				}
			}
			if (y > 0 && a[x][y - 1] == 0)
				p.push(P{ x,y - 1 });
			if (y > 0 && a[x][y - 1] == 1) sum++;
			if (y + 1 < w&&a[x][y + 1] == 0)
				p.push(P{ x,y + 1 });
			if (y + 1 < w&&a[x][y + 1] == 1) sum++;
		}
	}
	cout << sum << endl;
	cin >> sum;
}

Measured memory_bytes: 3136