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

int main(){
    int n;
    vector<int> sime(1e2*5);
    for(int i=0;i<sime.size();i++){
        sime[i]=i*(i+1)*(i+2)/6;
    }
    while(cin>>n,n){
        const int INF=1e7;
        vector<int> times(n+1,INF);
                vector<int> odtimes(n+1,INF);   
        times[0]=0;
        odtimes[0]=0;
        for(int k=1;;k++){
            if(n<sime[k]) break;
            for(int i=0;i<times.size();i++){
                if(i-sime[k]>=0) times[i]=min(times[i],times[i-sime[k]]+1);                
            }
            if(sime[k]%2==1){
             for(int i=0;i<odtimes.size();i++){
                if(i-sime[k]>=0) odtimes[i]=min(odtimes[i],odtimes[i-sime[k]]+1);                
            }      
            }
        }
        
        cout<<times[n]<<" "<<odtimes[n]<<endl;
        
    }
}

Measured memory_bytes: 13980
import math
a,b,h,m = map(int, input().split())
p = (h*60+m)%720/720
q = (h*60+m)%60/60
px,py = a*math.sin(2*math.pi*p),a*math.cos(2*math.pi*p)
qx,qy = b*math.sin(2*math.pi*q),b*math.cos(2*math.pi*q)
#print(p,q,px,py,qx,qy)
print(((qx-px)**2+(qy-py)**2)**0.5)


Measured memory_bytes: 9572
def floor_sum(n, m, a, b):
    ans = 0
    if a >= m:
        ans += (n - 1) * n * (a // m) // 2
        a %= m
    if b >= m:
        ans += n * (b // m)

    y_max = (a * n + b) // m
    x_max = y_max * m - b
    if y_max == 0:
        return ans

    ans += (n - (x_max + a - 1) // a) * y_max
    ans += floor_sum(y_max, a, m, (a - x_max % a) % a)
    return ans

T = int(input())
for t in range(T):
    n, m, a, b = [int(_) for _ in input().split()]
    print(floor_sum(n, m, a, b))


Measured memory_bytes: 9232
N, K = map(int, input().split())
S = input()
ct = 0
ans = 0
st = 0
for i in range(N-1):
    if S[i] == S[i+1]:
        st += 1
    else:
        ans += st
        st = 0
        ct += 1
else:
    ans += st

if K * 2 < ct:
    print(ans+2*K)
else:
    print(N-1)


Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    int n;
    cin >> n;
    long long num[100000];
    num[0]= 2;
    num[1]= 1;
    for(int i=2;i<=n;i++){
        num[i]=num[i-1]+num[i-2];
    }
    cout << num[n] << endl;
}


Measured memory_bytes: 256
package main

import "fmt"

func prime_factor(n int64) map[int64]int {
	ret := map[int64]int{}

	for i := int64(2); i*i <= n; i++ {
		for n%i == 0 {
			ret[i]++
			n /= i
		}
	}
	if n != 1 {
		ret[n]++
	}
	return ret
}

func main() {
	var n int64
	fmt.Scan(&n)

	mp := make(map[int64]int)

	for i := int64(2); i <= n; i++ {
		t := prime_factor(i)
		for k, v := range t {
			mp[k] += v
		}
	}

	var ans int64 = 1
	mod := int64(1e9) + 7

	for _, v := range mp {
		ans *= int64(v + 1)
		ans %= mod
	}

	fmt.Println(ans)
}

Measured memory_bytes: 768
fn solve(a: Vec<i64>) -> &'static str {
    if a.iter().fold(a[0], |x, &y| num::integer::gcd(x, y)) > 1 {
        return "not coprime"
    }
    let mut m = vec![0; 1000000];
    for &t in &a {
        let mut v = t as usize;
        for div in 2..v {
            if div*div > v { break }
            if v%div != 0 { continue }
            if m[div] != 0 { return "setwise coprime" }
            while v%div == 0 { v /= div }
            m[div] = 1
        }
        if v > 1 {
            if m[v] != 0 { return "setwise coprime" }
            m[v] = 1
        }
    }
    "pairwise coprime"
}

fn main() {
    proconio::input! {
        n: usize,
        a: [i64; n]
    }
    println!("{}", solve(a));
}


Measured memory_bytes: 17572
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
const int maxn = 1e3 + 50;
const ll mod = 1e9+7;
int h, w;
ll dp[maxn][maxn];
char s[maxn][maxn];
int main(){
    scanf("%d%d", &h, &w);
    for(int i = 1; i <= h; i++)
        scanf("%s", s[i] + 1);
    dp[1][1] = 1;
    for(int i = 1; i <= h; i++)
        for(int j = 1; j <= w; j++){
            if(s[i][j] == '#') continue;
            if(i-1 >= 1 && s[i-1][j] != '#')
                dp[i][j] = (dp[i][j] + dp[i-1][j])%mod;
            if(j-1 >= 1 &&s[i][j-1] != '#')
                dp[i][j] = (dp[i][j] + dp[i][j-1])%mod;
        }
    printf("%lld\n", dp[h][w]);
    return 0;
}





Measured memory_bytes: 9472
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const ll mod=1e9+7;
const ll inf=1ll<<60;

/* */

int main(){

    // 入力スタンダード（複数指定）
    int n, k;
    cin >> n >> k;

    // **************************************
    ll hi[n];
    ll c[n+k];
    for(int i=0; i<n; i++){
        cin >> hi[i];
        c[i] = inf;
    } 
    for(int i=n; i<n+k; i++){
        c[i] = inf;
    }
    // **************************************
    

    c[0]=0;
    for(int i=0; i<n; i++){
        for(int j=1; j<k+1; j++){
            chmin(c[i+j], c[i] + abs(hi[i] - hi[i+j]));
        }
    }
    
    cout << c[n-1] <<endl;

    return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <bitset>
#include <functional>
#include <set>
#include <map>
#include <array>

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define fst first
#define snd second
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cout << #x << ": " << x << endl
//#define int long long int
const int MOD = 1000000007;
const int INF = 100100100;
const double EPS = 0.000000001;

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

bool pairCompare(const P& pair1, const P& pair2) {
    return pair1.second > pair2.second;
}

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

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<ll> A;
  REP(i, N) {
    ll a;
    cin >> a;
    A.push_back(a);
  }
  ll flag = A[0];
  REP(i, N-1){
    flag = min(flag, gcd(A[i+1],A[i]));
  }
  cout << flag << endl;

  return 0;
}


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

using namespace std;
#define ll long long
#define ull unsigned long long
#define mp make_pair
typedef pair<int, int> pii;
typedef priority_queue<int, vector<int>, greater<int> > small_heap;
typedef priority_queue<int> big_heap;
int a[200009];

int main() {
    int n;
    scanf("%d", &n);
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        ans ^= a[i];
    }
    for (int i = 1; i <= n; i++) {
        printf("%d", ans ^ a[i]);
        i == n ? puts(" ") : printf(" ");
    }
    return 0;
}

Measured memory_bytes: 4632
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	ll a,b,c,d; cin >> a >> b >> c >> d;
	ll s = (c-1) / b + 1;
	ll t = (a-1) / d + 1;
	if(s <= t) puts("Yes");
	else puts("No");
}

Measured memory_bytes: 3620
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_number(A, B) :-
    get_number(A),
    get_number(B).

get_number(A, B, C) :-
    get_number(A, B),
    get_number(C).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

get_chars(Xs) :-
    get_string(S),
    string_chars(S, Xs).

get_numbers(0, []).
get_numbers(N, [X|Xs]) :- 
    get_number(X), 
    N2 is N - 1, 
    get_numbers(N2, Xs).

put_numbers([]).
put_numbers([X|Xs]) :-
    writeln(X),
    put_numbers(Xs).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)
    length(S, L),
    sub_string

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==

    between(L,U,X): L <= X <= U
    nth0(I, Xs, Y), nth1(I, Xs, Y): (Xs,Y) -> I, (I, Xs) -> Y 

    sort(Key, Order, List, Sorted): Keyは通常0?, Orderは=なしが重複削除，=は重複保持
    \+ P(X) : not P(X)

    sum_list(Xs, Sum)
*/

f(0, S, S).
f(N, S, Z) :- N mod 3 =\= 0 , N mod 5 =\= 0, S2 is S + N, N2 is N - 1, f(N2, S2, Z).
f(N, S, Z) :- N2 is N - 1, f(N2, S, Z).

main :-
    get_number(N),
    f(N, 0, Z),
    writeln(Z).


Measured memory_bytes: 99840
#include "bits/stdc++.h"

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) Type __VA_ARGS__; IN(__VA_ARGS__)
#define Float(x) OUTN(fixed, setprecision(x));

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// IN
void IN() {}
template <class Head, class... Tail>
void IN(Head&& head, Tail&&... tail) {
  cin >> head;
  IN(forward<Tail>(tail)...);
}

// OUTS
void OUTS() {}
template <class Head, class... Tail>
void OUTS(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  OUTS(forward<Tail>(tail)...);
}

template <class T>
void OUTS(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e==&vec.back()]; }

template <class T>
void OUTS(vector<vector<T>> &df) { for (auto &vec : df) OUTS(vec); }

// OUTL
void OUTL() {}
template <class Head, class... Tail>
void OUTL(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  OUTL(forward<Tail>(tail)...);
}

template <class T>
void OUTL(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

// OUTN
void OUTN() {}
template <class Head, class... Tail>
void OUTN(Head&& head, Tail&&... tail) {
  cout << head;
  OUTN(forward<Tail>(tail)...);
}

template <class T>
void OUTN(vector<T> &vec) { for (auto &e : vec) cout << e; }
// }}} End

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n; string s;
  IN(n, s);

  int maxv = 0;
  vector<int> cum(n+10);
  for (int i = 1; i <= n; ++i) {
    char c = s[i-1];
    cum[i] = cum[i-1];
    if (c == 'I') cum[i]++;
    else cum[i]--;
    chmax(maxv, cum[i]);
  }

  OUTL(maxv);
  return 0;
}


Measured memory_bytes: 256
// ######      ###      #######    #######    ##     #     #####        ###     ##### //
// #     #    #   #          #        #       # #    #    #     #      #   #     ###  //
// #     #   #     #        #         #       #  #   #   #       #    #     #    ###  //
// ######   #########      #          #       #   #  #   #           #########    #   //
// #     #  #       #     #           #       #    # #   #    ####   #       #    #   //
// #     #  #       #    #            #       #     ##   #    #  #   #       #        //
// ######   #       #   #######    #######    #      #    #####  #   #       #    #   //

// #pragma GCC optimize(2)
// #pragma GCC optimize(3)
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> ppl;
#define ain(a,n) for(ll i=0;i<(n);++i)	cin>>(a)[i];
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(ll i=0;i<(n);++i)
#define FOR(i,a,b) for(ll i=(a);i<=(b);++i)
#define FORD(i,a,b) for(ll i=(a);i>=(b);--i)
#define cases ll T=0;cin>>T;while(T--)
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define END "\n"
#define pb push_back
#define mp make_pair
#define go(c,itr) for(auto itr=(c).begin(); itr!=(c).end(); ++itr)
// #define back(c,itr) for(auto itr=(c).rbegin(); itr!=(c).rend(); ++itr)
#define PI 3.14159265359
#define inf 9e18
#define MOD 1000000007
#define MODU 998244353
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MAXN 300005
const string alpha = "abcdefghijklmnopqrstuvwxyz";
const ll N = 200005;
const long double epsilon = 1e-9;
ll binexp(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
ll modinvfermat(ll a, ll m)
{
	return binexp(a, m - 2, m);
}
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}
ll lcm(ll a, ll b)
{
	return ((1LL * a * b) / (__gcd(a, b)));
}

bool check(vl a, ll mid, ll k, ll n)
{
	ll cuts = 0;
	loop(i, n)
	{
		if (a[i] > mid)
		{
			if (a[i] % mid == 0)
				cuts += a[i] / mid - 1;
			else
				cuts += a[i] / mid;
		}
	}
	// cout << mid << " " << cuts << END;
	return (cuts <= k);
}
signed main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	fast
	ll n, k;
	cin >> n >> k;
	vl a(n);
	ain(a, n);
	ll lo = 1, hi = 1e9, ans = 1e9;
	ll iter = 0;
	while (lo < hi)
	{
		// ++iter;
		ll mid = (lo + hi) / 2;
		// cout << lo << " " << mid << " " << hi << END;
		if (check(a, mid, k, n))
			hi = mid, ans = mid;
		else
			lo = mid + 1;
	}
	cout << ans << END;



// #ifndef ONLINE_JUDGE
// 	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
// #endif
	return 0;
}


Measured memory_bytes: 6356
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
  
inline char nc(){  
  static char buf[100000],*p1=buf,*p2=buf;  
  if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; }  
  return *p1++;  
}  
  
inline void read(int &x){  
  char c=nc(),b=1;  
  for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;  
  for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;  
}

const int N=200005;

struct abcd{
  int l,r;
  abcd(int l=-1,int r=-1):l(l),r(r) { }
  bool operator == (const abcd &B) const{
    return l==B.l && r==B.r;
  }
}T[N<<2];

bool Jud(abcd L,abcd R){
  return L.r+1==R.l;
}

inline void Push(int x,abcd u){
  if (T[x]==abcd(-1,-1)) { T[x]=u; return; }
  if (T[x]==abcd(-2,-2)) return;
  if (u==abcd(-2,-2)) { T[x]=u; return; }
  if (Jud(T[x],u) || T[x]==abcd(-1,-1)) T[x].r=u.r;
  else T[x]=abcd(-2,-2);
}

inline void Modify(int x,int l,int r,int ql,int qr,abcd u){
  int mid=(l+r)>>1;
  if (!(T[x]==abcd(-1,-1)) && l!=r) Push(x<<1,T[x]),Push(x<<1|1,T[x]),T[x]=abcd(-1,-1);
  if (ql<=l && r<=qr){
    Push(x,u);
    return;
  }
  if (ql<=mid) Modify(x<<1,l,mid,ql,qr,u);
  if (mid<qr) Modify(x<<1|1,mid+1,r,ql,qr,u);
}

int n,K;
int cnt=0;

inline void Query(int x,int l,int r){
  if (l==r){
    if (T[x]==abcd(0,K))
      cnt++;
    return;
  }
  if (!(T[x]==abcd(-1,-1)) && l!=r) Push(x<<1,T[x]),Push(x<<1|1,T[x]),T[x]=abcd(-1,-1);
  int mid=(l+r)>>1;
  Query(x<<1,l,mid);
  Query(x<<1|1,mid+1,r);
}


int main(){
  int Q; int l,r,c;
  read(n); read(K);
  T[1]=abcd(0,0);
  read(Q);
  while (Q--){
    read(l); read(r); read(c);
    Modify(1,1,n,l,r,abcd(c,c));
  }
  Query(1,1,n);
  printf("%d\n",cnt);
  return 0;
}

Measured memory_bytes: 9564
#include<bits/stdc++.h>
#define endl '\n'
#define PI 3.14159265358979323844
#define DECIMAL(n)  std::cout << std::fixed;std::cout << std::setprecision(n);
#define mp make_pair
#define pb push_back
#define int long long int 
#define forr(i,a,b) for (int i= a; i <b; ++i)
    using namespace std; 
   double dp[3005][3005];
   double coinhead(int n , int head ,double *arr){
       if(head==0)return 1;
       if(n==0)return 0;
       if(dp[n][head]>-.9)return dp[n][head];
       dp[n][head]=coinhead(n-1,head,arr)*(1-arr[n])+coinhead(n-1,head-1,arr)*arr[n];
       return dp[n][head];
   }
   
    signed main(){
        int n;
        cin>>n;
        double arr[n];
        memset(dp , -1  , sizeof dp);
        forr(i,1,n+1)cin>>arr[i];
        DECIMAL(10);
    cout<<coinhead(n,(n+1)/2,arr);}

Measured memory_bytes: 71040
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007
#define MAX 3000

    int rcv[MAX+1][MAX+1]={{0}};
    int ans[4][MAX+1][MAX+1];

signed main(){
    int R,C,K;
    cin>>R>>C>>K;


    for(int i=0;i<K;i++){
        int r,c,v;
        cin>>r>>c>>v;
        rcv[r][c]=v;
    }

    queue<int> qx,qy;

    qx.push(1);
    qy.push(1);

    for(int i=1;i<=R;i++){
        for(int j=1;j<=C;j++){
            for(int k=0;k<4;k++){
                ans[k][i][j]=-1;
            }
        }
    }

    ans[0][1][1]=0;
    while(!qx.empty()){
        int nx=qx.front();
        qx.pop();
        int ny=qy.front();
        qy.pop();
        for(int i=0;i<4;i++){
            if(ans[i][ny][nx]==-1) continue;
            if(i<=2){
                if(nx!=C&&(ans[i+1][ny][nx+1]<ans[i][ny][nx]+rcv[ny][nx])){
                    ans[i+1][ny][nx+1]=ans[i][ny][nx]+rcv[ny][nx];
                    qx.push(nx+1);
                    qy.push(ny);
                }
                if(ny!=R&&(ans[0][ny+1][nx]<ans[i][ny][nx]+rcv[ny][nx])){
                    ans[0][ny+1][nx]=ans[i][ny][nx]+rcv[ny][nx];
                    qx.push(nx);
                    qy.push(ny+1);
                }
            }
            if(nx!=C&&(ans[i][ny][nx+1]<ans[i][ny][nx])){
                ans[i][ny][nx+1]=ans[i][ny][nx];
                qx.push(nx+1);
                qy.push(ny);
            }
            if(ny!=R&&(ans[0][ny+1][nx]<ans[i][ny][nx])){
                ans[0][ny+1][nx]=ans[i][ny][nx];
                qx.push(nx);
                qy.push(ny+1);
            }

        }
    }
    cout<<max(ans[0][R][C]+rcv[R][C],max(ans[1][R][C]+rcv[R][C],max(ans[2][R][C]+rcv[R][C],ans[3][R][C])))<<endl;
}


Measured memory_bytes: 355528
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import           Data.Bits             (xor)
import qualified Data.ByteString.Char8 as BC
import           Data.List             (unfoldr)
import           Data.Maybe            (fromJust)
import           Data.Vector.Unboxed   (Vector, (!))
import qualified Data.Vector.Unboxed   as V

main :: IO ()
main = do
  n <- readLn
  as <- map readInt . BC.words <$> BC.getLine
  print $ solve n as

solve :: Int -> [Int] -> Int
solve n as = sum $ twoPointMethod n as' where
  as' = V.fromList as

twoPointMethod :: Int -> Vector Int -> [Int]
twoPointMethod n as = unfoldr f (0, 0, 0) where
  f (l, r, s)
    | l >= n    = Nothing
    | l == r'   = Just (0, (l + 1, r' + 1, s'))
    | otherwise = Just (r' - l, (l + 1, r', s' - as!l)) where
        (r', s') = last . takeUntil p $ iterate g (r, s)
        p (r, s) = r < n && s `xor` as!r == s + as!r
        g (r, s) = (r + 1, s + as!r)

takeUntil :: (a -> Bool) -> [a] -> [a]
takeUntil _ []     = []
takeUntil p (x:xs) = x : if p x then takeUntil p xs else []

readInt :: BC.ByteString -> Int
readInt = fst . fromJust . BC.readInt


Measured memory_bytes: 13692
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<int> C(N-1), S(N-1), F(N-1);
    for(int i = 0; i < N-1; i++) cin >> C.at(i) >> S.at(i) >> F.at(i);
    
    for(int start = 0; start < N; start++) {
        int ans = 0;
        for(int i = start; i < N-1; i++) {
            while(S.at(i)>ans || ans%F.at(i)!=0) ans++;
            ans += C.at(i);
        }
        cout << ans << endl;
    }
}


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

const int N = 110;
int n, a[N];

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) scanf("%d", a + i);

	long long ans = 1e18;
	for (int x = -200; x <= 200; ++x) {
		long long res = 0;
		for (int i = 1; i <= n; ++i) res += 1LL * (x - a[i]) * (x - a[i]);
		ans = min(ans, res);
	}

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

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
bool road[30][200001],rail[30][200001];
int prec[30][30],mk1[200001],mk2[200001],color;
vector<int> mp1[200001],mp2[200001],cc1[200001],cc2[200001];
vector<pair<int,int>> siz1,siz2;
map<pair<int,int>,int> dp;
void dfs1(int k)
{
	++siz1.back().first;
	mk1[k]=color;
	cc1[color].push_back(k);
	for (size_t i=0;i<mp1[k].size();++i)
		if (mk1[mp1[k][i]]==-1)
			dfs1(mp1[k][i]);
}
void dfs2(int k)
{
	++siz2.back().first;
	mk2[k]=color;
	cc2[color].push_back(k);
	for (size_t i=0;i<mp2[k].size();++i)
		if (mk2[mp2[k][i]]==-1)
			dfs2(mp2[k][i]);
}
int main()
{
	int n,k,l;
	scanf("%d%d%d",&n,&k,&l);
	for (int i=1;i<=k+l;++i)
	{
		int t1,t2;
		scanf("%d%d",&t1,&t2);
		if (i<=k)
		{
			mp1[t1].push_back(t2);
			mp1[t2].push_back(t1);
		}
		else
		{
			mp2[t1].push_back(t2);
			mp2[t2].push_back(t1);
		}
	}
	memset(mk1,-1,sizeof(mk1));
	memset(mk2,-1,sizeof(mk2));
	for (int i=1;i<=n;++i)
		if (mk1[i]==-1)
		{
			siz1.push_back(make_pair(0,color));
			dfs1(i);
			sort(cc1[color].begin(),cc1[color].end());
			++color;
		}
	sort(siz1.begin(),siz1.end());
	reverse(siz1.begin(),siz1.end());
	int big1=min(30,int(siz1.size()));
	for (int i=0;i<big1;++i)
	{
		int cc=siz1[i].second;
		for (size_t j=0;j<cc1[cc].size();++j)
			road[i][cc1[cc][j]]=true;
	}
	color=0;
	for (int i=1;i<=n;++i)
		if (mk2[i]==-1)
		{
			siz2.push_back(make_pair(0,color));
			dfs2(i);
			sort(cc2[color].begin(),cc2[color].end());
			++color;
		}
	sort(siz2.begin(),siz2.end());
	reverse(siz2.begin(),siz2.end());
	int big2=min(30,int(siz2.size()));
	for (int i=0;i<big2;++i)
	{
		int cc=siz2[i].second;
		for (size_t j=0;j<cc2[cc].size();++j)
			rail[i][cc2[cc][j]]=true;
	}
	for (int i=0;i<big1;++i)
		for (int j=0;j<big2;++j)
			for (int k=1;k<=n;++k)
				prec[i][j]+=(road[i][k]&&rail[j][k]);
	for (int i=1;i<=n;++i)
	{
		if (dp.count(make_pair(mk1[i],mk2[i])))
		{
			printf("%d ",dp[make_pair(mk1[i],mk2[i])]);
			continue;
		}
		int b1idx=-1,b2idx=-1;
		for (int j=0;j<big1;++j)
			if (siz1[j].second==mk1[i])
				b1idx=j;
		for (int j=0;j<big2;++j)
			if (siz2[j].second==mk2[i])
				b2idx=j;
		if (b1idx==-1&&b2idx==-1)
		{
			vector<int> tmp;
			set_intersection(cc1[mk1[i]].begin(),cc1[mk1[i]].end(),cc2[mk2[i]].begin(),cc2[mk2[i]].end(),back_inserter(tmp));
			printf("%d ",dp[make_pair(mk1[i],mk2[i])]=int(tmp.size()));
		}
		else if (b1idx!=-1&&b2idx!=-1)
			printf("%d ",prec[b1idx][b2idx]);
		else if (b1idx==-1)
		{
			int ans=0;
			for (size_t j=0;j<cc1[mk1[i]].size();++j)
				if (rail[b2idx][cc1[mk1[i]][j]])
					++ans;
			printf("%d ",dp[make_pair(mk1[i],mk2[i])]=ans);
		}
		else
		{
			int ans=0;
			for (size_t j=0;j<cc2[mk2[i]].size();++j)
				if (road[b1idx][cc2[mk2[i]][j]])
					++ans;
			printf("%d ",dp[make_pair(mk1[i],mk2[i])]=ans);
		}
	}
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 1;
  for (int i = 1; i < n; i++) {
    if (s[i] != s[i - 1]) ans++;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 512
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <queue>
# include <stack>
# define MOD 1000000000+7
# define INF 1000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
ll counter;

int main() {
	ll a = 0, b = 0, n = 0, m = 0, counter = 0, maxi = 0, asum = 0, bsum = 0,counter2=0;
	ll A[10001], B[10001];
	priority_queue<ll> pque;
	std::string str, str2;
	cin >> n;
	rep(i, n) {
		cin >> A[i];
		asum += A[i];
	}
	rep(i, n) {
		cin >> B[i];
		bsum += B[i];
	}
	if (asum > bsum) {
		cout << "No" << endl;
		return 0;
	}
	else {
		rep(i, n) {
			while (A[i] < B[i]) {
				A[i] += 2;
				counter++;
			}
		}
		rep(i, n) {
			while(A[i]>B[i]){
				B[i] += 1;
				counter2++;
			}
		}
		if (counter >= counter2) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
		
		
	}
}


Measured memory_bytes: 384
#include<iostream>
#include<climits>
#include<numeric>
using namespace std;
typedef long long ll;

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

    ll a[n], b[n];
    for(int i = 0; i < n; i++) cin >> a[i], b[i] = a[i];

    ll ans = accumulate(b, b+n, 0ll);

    for(int k = 1; k < n; k++){
        ll tmp = (ll)k * x;
        for(int i = 0; i < n; i++){
            b[i] = min(b[i], a[(i+n-k)%n]);
        }
        tmp += accumulate(b, b+n, 0ll);
        ans = min(ans, tmp);
    }

    cout << ans << endl;

    return 0;
}

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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define endl '\n'
#define int long long

const int K = 1e5+5, N = 105;
int dp[K][2], a[N], n, k;

int solve(int cur_stones, int cur_player) {
	int &ans = dp[cur_stones][cur_player];
	if(ans != -1) 
		return ans;
	ans = cur_player ^ 1;
	for(int i = 1; i <= n; i ++) {
		if(cur_stones - a[i] >= 0)
			if(solve(cur_stones - a[i], cur_player ^ 1) == cur_player)
				ans = cur_player;
	}
	return ans;
}

int32_t main()
{
	IOS;

	cin >> n >> k;
	for(int i = 1; i <= n; i ++)
		cin >> a[i];
	memset(dp, -1, sizeof(dp));
	int ans = solve(k, 0);

	if(!ans)	
		cout << "First";
	else 
		cout << "Second";

	return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <tuple>
#define ll long long
using namespace std;
struct all_init
{
    all_init()
    {
        cout << fixed << setprecision(12);
    }
} All_init;

int main()
{
    ll h, a;
    cin >> h >> a;
    cout << (h + a - 1) / a << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define rep2(i,a,b) for (ll i = (a); i < (b); ++i)
#define INF (1<<18)


int main() {
    int n;
    cin>>n;
    vector<int> a(8,0);
    int over = 0;
    rep(i,n){
        int b;
        cin>>b;

        if(1 <= b && b <=399) a[0]++;
        rep2(j,1,8){
            if(j*400 <= b && b <= j*400+399) a[j]++;
        }
        if(3200 <= b) over++;
    }

    int color = 0;
    rep(i,8){
        if(a[i] != 0) color++;
    } 
    
    int min, max;

    if(over >= 1 && color == 0){
       min = 1; 
    }
    else{
        min = color;
    }
    max = color + over;

    cout<<min<<" "<<max<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int N;
    scanf("%d",&N);

    if(N>=10 && N<=99)
    {
        if(N == 19 || N == 29 || N== 39 || N==49 || N==59 || N==69 || N==79 || N==89 || N>=90 && N<=99)
        {
            printf("Yes");
        }
        else
        {
            printf("No");
        }
    }

}


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

int main(){
    int N,M;
    cin >> N >> M;
    int ans = 0;
    vector<long> height(N);
    vector<bool> isgood(N,true);
    for(int i = 0; i < N; i++){
        cin >> height[i];
    }
    for(int i = 0 ;i < M; i++){
        int a,b;
        cin >> a >> b;
        //cout << height[a-1] << " " << height[b-1] << endl;
        if(height[a-1] < height[b-1]){
            isgood[a-1] = false;
        }else if(height[a-1] > height[b-1]){
            isgood[b-1] = false;
        }else{
            isgood[a-1] = false;
            isgood[b-1] = false;
        }
    }
    for(int i = 0; i < isgood.size(); i++){
        if(isgood[i] == true) ans++;
    }
    cout << ans << endl;

    return 0;
}

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

signed main()
{
	int a,b;
	cin>>a>>b;
	int ans = 0;
	int k = (b-a)/4;
	//a += k*4;
   // cout<<a<<" "<<b<<" "<<k<<endl;
	for(int i=a;i<=b;i++){
        if(i%4==0)
            break;
        ans ^= i;
    }
	for(int i=b;i>=0;i--)
    {
        ans ^= i;
        if(i%4==0) break; 
    }
	//cout<<ans;
    cout<<ans;
	
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, k;
  cin >> n >> k;
  
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  
  for (int i = k; i < n; i++) {
    if (a.at(i - k) < a.at(i)) cout << "Yes\n";
    else cout << "No\n";
  }
}

Measured memory_bytes: 3964
n = int(input())
l = list(sorted(map(int, input().split())))
x = 0
if n >= 3:
    for k in range(n - 2):
        for j in range(k + 1):
            for i in range(j + 1):
                if l[i] < l[j + 1] < l[k + 2] and l[i] + l[j + 1] > l[k + 2]:
                    x += 1
print(x)

Measured memory_bytes: 9072
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
long long modpow(long long b, long long i){
  long long s=1;
  while(i){
    if(i%2) s=(s*b)%MOD;
    b=(b*b)%MOD; i/=2;
  }
  return s;
}
int main(){
  clock_t start,end;
  start=clock();

  int x,y; cin >>x >>y;
  int m=2*y-x,n=2*x-y;
  if(m<0||n<0||m%3||n%3){cout <<0; return 0;}
  else{
    long long p=(m+n)/3,q=min(m,n)/3,pp=1,qq=1;
    for(int i=0; i<q; i++){
      pp=(pp*(p-i))%MOD; qq=(qq*(q-i))%MOD;
    }
    cout <<(pp*modpow(qq,MOD-2))%MOD<<endl;
  }

  //end=clock();
  //double time_taken=double(end-start)/double(CLOCKS_PER_SEC); 
  //cout <<"Time taken: "<<fixed<<setprecision(5);
  //cout <<time_taken<<"s/"<<time_taken*1000<<"ms"<<endl;
return 0;}

Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>

#define rep(i,a,b) for(int (i) = (a) ; (i) < (b) ; (i) ++)
#define scin(a) scanf("%d",&a);
#define scdo(a) scanf("%lf",&a);
#define scch(a) scanf("%s",a);
#define anin(a) printf("%d\n",a);
#define ando(a) printf("%lf\n",a);
#define anch(a) printf("%s\n",a);

int main(void){
	long long int n,k,q,ans;
	scanf("%lld %lld %lld",&n,&k,&q);
	long long int A[q],B[n] = {};
	rep(i,0,q){
		scanf("%lld",&A[i]);
		B[A[i] - 1] ++;
	}
	if(k > q){
		rep(i,0,n){
			printf("Yes\n");
		}
	} else {
		rep(i,0,n){
			if(k - q + B[i] > 0) printf("Yes\n"); else printf("No\n");
		}
	}
	return 0;
}

Measured memory_bytes: 2048
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
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; }


int main(){
    int n, k; cin >> n >> k;
    vector<ll> A(n); rep(i, n) cin >> A[i];
    sort(all(A));
    ll sum = 0;
    rep(i, k){
        sum += A[i];
    }
    cout << sum << ln;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(ll i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(ll i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;


template<typename T>
struct edge {
  int v; T w;
  edge(int v, T w) : v(v), w(w) {}
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using Graph = vector<Edges<T>>;


template<typename T>
vector<T> dijkstra(Graph<T> &G, int s) {
  const auto INF = numeric_limits<T>::max();
  vector<T> dist(G.size(), INF);

  using PTi = pair<T, int>;
  priority_queue<PTi, vector<PTi>, greater<PTi>> pq;
  dist[s] = 0;
  pq.emplace(dist[s], s);

  while (!pq.empty()) {
    T cost; int u;
    tie(cost, u) = pq.top(); pq.pop();
    if (dist[u] < cost) continue;
    for (auto &e : G[u]) {
      auto n_cost = cost + e.w;
      if (dist[e.v] <= n_cost) continue;
      dist[e.v] = n_cost;
      pq.emplace(dist[e.v], e.v);
    }
  }
  return dist;
}


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

  Graph<ll> G(n);
  rep(_, m) {
    int l, r, c; cin >> l >> r >> c;
    --l, --r;
    G[l].emplace_back(r, c);
  }
  rep(i, n-1) G[i+1].emplace_back(i, 0);

  auto dist = dijkstra(G, 0);
  cout << (dist[n-1] < INFll ? dist[n-1] : -1) << "\n";
  return 0;
}


Measured memory_bytes: 9336
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
int main()
{
	int N, Alice, Bob;
	vector<int> A;
	Alice = Bob = 0;
	cin >> N;
	A.resize(N);
	rep(i, N) cin >> A.at(i);

	sort(A.begin(), A.end(), greater<int>());

	rep(i, N) {
		if (i % 2) Alice += A[i];
		else Bob += A[i];
	}
	cout << Bob - Alice << endl;

	return 0;
}

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

VC = sorted(zip(V, C), key=lambda x:x[0])[::-1]

vsum = csum = 0
dmax = 0
for i in range(N):
	if VC[i][1] < VC[i][0]:
		vsum += VC[i][0]
		csum += VC[i][1]
		dmax = max(dmax, vsum - csum)
print(dmax)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

int main(){
	ll n,m;
	cin >> n >> m;
	if(n == 1 && m == 1)cout << 1 << endl;
	else if(n == 1)cout << m-2 << endl;
	else if(m == 1)cout << n-2 << endl;
	else cout << (n-2)*(m-2) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using ll = long long;
// using ll = boost::multiprecision::int128_t;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(ll i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(ll i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
const int MOD  = int(1e9)+7;


int main() {
  ll n; cin >> n;
  Vll a(n+1); cin >> a;

  Vll s = a;
  drep(i, n) s[i] += s[i+1];

  ll ans = 0;
  ll x = 1;
  rep(i, n+1) {
    if (i) x = min(2*(x-a[i-1]), s[i]);
    if (x <= 0) {
      cout << -1 << "\n";
      return 0;
    }
    ans += x;
  }
  x = min(2*(x-a[n]), 0ll);
  if (x != 0) cout << -1 << "\n";
  else cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 4784
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, M = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    edge = [[] for i in range(N)]
    for i in range(M):#木の場合M=N-1
        a,b,z = map(int,input().split())
        if z%2==0:
            w=0
        else:w=1
        edge[a-1].append((w,b-1))
        edge[b-1].append((w,a-1)) #有向のばあいコメントアウト
    
    visited=[False]*N
    def dfs(start,visited,ans):
        q=deque([start])
        if visited[start]:
            return ans
        else:
            ans+=1

        while len(q):
            e=q.pop()#ここをpopleftにすると幅優先探索BFSになる
            if visited[e]:continue
            visited[e]=1
            for dw,ne in edge[e]:
                q.append(ne)
        return ans

    ans=0
    for i in range(N):
        ans=dfs(i,visited,ans)
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 99376
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    string a,b,c; cin>>a>>b>>c;
    int l=a.length(),r=b.length(),p=c.length();
    if(a[l-1]==b[0] && b[r-1]==c[0])cout<<"YES";
    else cout<<"NO";
}


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

int main() {
    int64_t n, k; cin >> n >> k;
    vector<int64_t> a(n+1);
    for (int64_t i = 1; i <= n; i++) {
        cin >> a.at(i);
    }
    vector<bool> visited(n+1, false);
    visited.at(1) = true;
    vector<int64_t> seq(n, 0);
    seq.at(0) = 1;
    int64_t pos = 1;
    int64_t i;
    for (i = 1; i <= n; i++) {
        pos = a.at(pos);
        if (visited.at(pos)) {
            break;
        }
        visited.at(pos) = true;
        seq.at(i) = pos;
    }
    i--;
    int64_t j;
    for (j = 0; j < n; j++) {
        if (seq.at(j) == pos) {
            break;
        }
    }
    if (k <= i) {
        cout << seq.at(k) << endl;
    } else {
        cout << seq.at((k - j) % (i - j + 1) + j) << endl;
    }
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//MOD
//--------------------------------------------
#define MUL(a,b) (((a) % MOD) * ((b) % MOD)) % MOD

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//main code

int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	VL a(n);
	bool m_odds = false;
	LL ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] < 0) {
			m_odds = !m_odds;
		}
		ans += abs(a[i]);
	}
	LL min_abs = INT32_MAX;
	for (int i = 0; i < n; i++) {
		min_abs = min(min_abs, abs(a[i]));
	}
	ans -= m_odds ? min_abs*2 : 0;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		if (Math.abs(x - a) < Math.abs(x - b))
			System.out.println("A");
		else
			System.out.println("B");
		sc.close();
	}
}

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

using namespace std;

int n, r;

int main(){
    cin >> n >> r;
    cin.ignore();

    if(n >= 10){
        cout << r << endl;
        return 0;
    }

    cout << r + 100 * (10 - n) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
#include<complex>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

const int MAXN = 30;
int x[MAXN], y[MAXN], r[MAXN], c[MAXN];
bool ok[MAXN];
map<int, int> dp;

int square(int x) {return x*x;}

// i, j ???????????£?????????????????????
// ????????£????????? true
bool check(int i, int j) {
    int d2 = square(x[i]-x[j]) + square(y[i]-y[j]);
    return d2 < square(r[i]+r[j]);
}

int dfs(int state, int n) {
    int ret = 0;
    if (dp.find(state) != dp.end()) return dp[state];
    // ???????????¨??????????????§??????????????????????????????
    vector<int> already;
    memset(ok, true, sizeof(ok));
    for (int i = 0; i < n; i++) {
        if ((state>>i)&1) continue;
        if (ok[i]) {
            already.push_back(i);
        }
        for (int j = i+1; j < n; j++) {
            if (check(i, j)) ok[j] = false;
        }
    }
    int sz = already.size();
    for (int i = 0; i < sz; i++) {
        for (int j = i+1; j < sz; j++) {
            int ai = already[i], aj = already[j];
            if (c[ai] == c[aj]) {
                int nstate = state;
                nstate |= 1<<ai;
                nstate |= 1<<aj;
                ret = max(2+dfs(nstate, n), ret);
            }
        }
    }
    return dp[state] = ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    while (cin >> n) {
        if (n==0) break;
        for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> r[i] >> c[i];
        dp.clear();
        cout << dfs(0, n) << endl;
    }
    return 0;
}

Measured memory_bytes: 52344