akhauriyash/Code-Regression huggingface dataset:
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

template<typename T>
vector<T> make_vec_nd(T init, size_t size) {
    return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, size_t size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

struct Mod {
    static ll BASE;
    ll value = 0;
    static ll residue(ll value) { return (value % BASE + BASE) % BASE; }
    Mod(ll value)
    : value(residue(value)) {}
    Mod operator+(const Mod& rhs) const { return Mod(value + rhs.value); }
    void operator+=(const Mod& rhs) { *this = *this + rhs; }
    Mod operator-(const Mod& rhs) const { return Mod(value - rhs.value); }
    void operator-=(const Mod& rhs) { *this = *this - rhs; }
    Mod operator*(const Mod& rhs) const { return Mod(value * rhs.value); }
    void operator*=(const Mod& rhs) { *this = *this * rhs; }
};
ll Mod::BASE = 1000000007;

int main() {
    ll N;
    cin >> N;
    string s;
    cin >> s;
    auto dp = make_vec_nd((Mod)0, N, N);
    dp[0][0] = 1;
    auto dp_sum = make_vec_nd((Mod)0, N, N+1);
    dp_sum[0][1] = 1;
    for (ll i = 1; i < N; i++) {
        for (ll n = 0; n <= i; n++) {
            if (s[i-1] == '>') {
                dp[i][n] = dp_sum[i-1][i] - dp_sum[i-1][n];
            } else {
                dp[i][n] = dp_sum[i-1][n];
            }
            dp_sum[i][n+1] += dp_sum[i][n] + dp[i][n];
        }
    }
    cout << dp_sum[N-1][N].value << endl;
}



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


int main()
{
	string s; cin >> s;
	ll sum = 0;
	int n = s.size() - 1;
	for (int bit = 0; bit < 1 << n; bit++)
	{
		ll sub = s[n] - 48, base = 10;
		for (int mask = 0; mask < n; mask++)
		{
			if (bit & 1 << mask)
				base = 1;
			sub += (s[n - mask - 1] - 48) * base;
			base *= 10;
		}
		sum += sub;
	}
	cout << sum << endl;
}


Measured memory_bytes: 3628
#include<iostream>
using namespace std;
inline bool isinside(int j, int X){ return 0<=j&&j<X; }
int main()
{
  while(true){
    int X,Y;
    cin >> X >> Y;
    if( X == 0 && Y == 0 ) break;
    int M[Y][X];
    long long int ans[Y+2][X];
    for(int i = 0; i < Y; ++i){
      for(int j = 0; j < X; ++j){
	int c;
	cin >> c;
	M[i][j]=c;
	ans[i][j]=0;
      }
    }
    for(int i = 0; i < X; ++i){
      ans[Y][i] = ans[Y+1][i] = 1;
    }
    const int dx[]={-1,0,1};
    for(int i = Y-1; i >= 0; --i){
      for(int j = 0; j < X; ++j){
	if( M[i][j] == 1 ){
	  ans[i][j] = 0;
	}
	if( M[i][j] == 0 ){
	  for(int k = 0; k < sizeof(dx)/sizeof(*dx); ++k){
	    if( isinside( j + dx[k], X ) ){
	      //if( ans[i][j] == 0 ){
	      //ans[i][j] = ans[i+1][j+dx[k]];
	      //}else{
	      if( M[i+1][j+dx[k]] == 2 && dx[k]!=0 )continue;
		ans[i][j] += ans[i+1][j+dx[k]];
		//}
	    }
	  }
	}
	if( M[i][j] == 2 ){
	  ans[i][j] = ans[i+2][j];
	}
	if( i == Y-1 && ans[i][j] > 0 )ans[i][j] = 1;
	//cout << ans[i][j] << ' ';
      }
      //cout << endl;
    }
    long long int Answer = 0;
    for(int i = 0; i < X; ++i){
      Answer += ans[0][i];
    }
    cout << Answer << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    vint a(N);
    REP(i,N) cin>>a[i];
    cout<<accumulate(ALL(a),0)-N<<endl;
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    string n;
    cin>>n;
    if (((n[0]==n[1])&&(n[1]==n[2]))||((n[1]==n[2])&&(n[2]==n[3])))cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
S = input()
T = ["dream", "dreamer", "erase", "eraser"]
def main():
    i = len(S)
    if i == 0:
        print("NO")
        return 0
    while True:
        if i == 0:
            break
        elif i < 5:
            print("NO")
            return 0
        elif S[i - 5:i] == T[0] or S[i - 5:i] == T[2]:
            i -= 5
        elif i < 6:
            print("NO")
            return 0
        elif S[i - 6:i] == T[3]:
            i -= 6
        elif i < 7:
            print("NO")
            return 0
        elif S[i - 7:i] == T[1]:
            i -= 7
        else:
            print("NO")
            return 0
    print("YES")
    return 0
main()


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

using namespace __gnu_pbds; 
using namespace std;

using   ll=long long;
using   ld=long double;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ordered_set 	tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int 			long long int
#define pll 			pair<ll , ll>

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007

ll mod_pow(ll a,ll b) {
    ll res = 1;
    while(b)	
    {
        if(b&1) 	
        {
        	res=(res*a)%mod;
        }
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) {
	return mod_pow(a , mod-2);
}

void solve() {
    
    int n;
    
    cin >> n;
    
    int tm = (n/1000)*1000;
    
    if(n % 1000) {
    	tm+=1000;
    }
    
    cout << tm - n;
    
}       

signed main() {
    fast;
    
    int t = 1;
    
    while(t--) {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 3648
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    A=list(map(int,input().split()))
    B=[0]*n
    B[0]=sum(A)-sum(A[1::2])*2
    for i in range(1,n):
        B[i]=(A[i-1]-B[i-1]//2)*2
    print(' '.join(map(str,B)))
    
if __name__=='__main__':
    main()

Measured memory_bytes: 19100
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 999999
#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<k;i++)
typedef long long ll;
typedef unsigned long long ull;

int main(){
    int n,m;
    vector<int> vi;
    while(scanf("%d%d",&n,&m),n,m){
        ll num[1010]={0};
        vi.clear();
        rep(i,n)scanf("%lld",&num[i]);
        rep(i,n+1)rep(j,n+1)if(num[i] + num[j] <= m)vi.push_back(num[i] + num[j]);
        sort(vi.begin(),vi.end());
        int len = vi.size();
        ll ans = -99999;
        rep(i , len){
            ll res = m-vi[i];
            if(m - vi[i] < 0)continue;
            ll  p = *(lower_bound(vi.begin(),vi.end(),res)-1);
            ans = max(ans,p+vi[i]);
        }
        printf("%d\n",ans);
    }
	return 0;
}

Measured memory_bytes: 6240
from collections import deque
def resolve():
    drc4 = [(0, 1), (0, -1), (-1, 0), (1, 0)]
    warp = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in [(0, 0)] + drc4]

    H, W = map(int, input().split())
    sy, sx = map(lambda x: int(x) - 1, input().split())
    gy, gx = map(lambda x: int(x) - 1, input().split())
    G = [input() for _ in range(H)]

    INF = 10 ** 12
    ans = [[INF] * W for _ in range(H)]

    q = deque()
    q.append((sy, sx, 0))
    ans[sy][sx] = 0

    while q:
        sy, sx, cost = q.popleft()
        for dy, dx in drc4:
            ny = dy + sy
            nx = dx + sx
            if 0 <= ny < H and 0 <= nx < W and G[ny][nx] == "." and ans[ny][nx] > cost:
                ans[ny][nx] = cost
                # q.appendleft 使用
                q.appendleft((ny, nx, cost))

        for dy8, dx8 in warp:
            ny8 = dy8 + sy
            nx8 = dx8 + sx
            if 0 <= ny8 < H and 0 <= nx8 < W and G[ny8][nx8] == "." and ans[ny8][nx8] > cost + 1:
                ans[ny8][nx8] = cost + 1
                # q.appendleft 使用しない
                q.append((ny8, nx8, cost + 1))

    res = ans[gy][gx] if ans[gy][gx] < INF else -1
    print(res)


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 98272
import sys
import numpy as np
#import math
#import itertools
#import re
#from functools import lru_cache

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

def main():
    k = int(input())
    s = input()

    if len(s) <= k:
        print(s)
    else:
        print(s[:k]+'...')


if __name__ == '__main__':
    main()


Measured memory_bytes: 27120
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

const string YES = "Yes";
const string NO = "No";

const int OFF = 8005;

int dp[2][16010];

void solve(std::string s, long long x, long long y){
    vector<vector<int>> a(2);
    vector<int> b;
    b.push_back(x); b.push_back(y);
    int cnt = 0, p = 0;
    s += 'T';
    cerr << s << x << y << endl;
    for(int i = 0; i < s.size(); ++i) {
        if (s[i] == 'F') {
            ++cnt;
        } else {
            a[p].push_back(cnt);
            cnt = 0;
            p = 1 - p;
        }
    }
    cerr << "hog" << endl;

    for(int k = 0; k < 2; ++k) {
        memset(dp, 0, sizeof(dp));
        if (k == 0) {
            dp[0][a[k][0] + OFF] = 1;
        } else {
            dp[0][OFF + 0] = 1;
        }
        p = 0;
        int q = 1;
        for(int j = k == 0 ? 1: 0; j < a[k].size(); ++j) {
            for(int i = -8000; i <= 8000; ++i) {
                if (OFF + i - a[k][j] >= 0) {
                    dp[q][OFF + i] |= dp[p][OFF + i - a[k][j]];
                }
                if (OFF + i + a[k][j] < 2 * OFF) {
                    dp[q][OFF + i] |= dp[p][OFF + i + a[k][j]];
                }
            }
            memset(dp[p], 0, sizeof(int[16010]));
            swap(p, q);
        }
        if (!dp[p][b[k] + OFF]) {
            cout << NO << endl;
            return;
        }
    }
    cout << YES << endl;
}

signed main(){
	ios::sync_with_stdio(false);
    std::string s;
    std::cin >> s;
    long long x;
    long long y;
    cin >> x >> y;
    solve(s, x, y);
    return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v, n) sort(v, v+n)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define ddvi vector<vector<int>>

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

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
// ここに処理を記述

    int A, B;
    cin >> A >> B;

    FOR(i,1,1001){
        int eight = 0.08 * i;
        int ten = 0.1 * i;

        if(A == eight && B == ten){
            cout << i << "\n";
            return 0;
        }
    }

    cout << "-1" << "\n";

return 0;
}

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

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

  vector<int> v(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    cin >> v.at(i);
  }

  int next = 1;
  int ans = 0;
  bool can = false;
  for (int i = 0; i < n; i++) {
    // ボタンをクリック
    next = v.at(next);
    ans++;
    if (next == 2) {
      can = true;
      break;
    }
  }

  cout << (can ? ans : -1) << endl;
  return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
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; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

ll powLL(ll a, ll n){
    ll res = 1;
    while(n>0){
        if(n&1){
            res *= a;
            res %= mod;
        }
        a = a*a;
        a %= mod;
        n >>= 1;
    }
    return res;
}

const ll N_MAX = 200005;

ll inv[N_MAX],fac[N_MAX],finv[N_MAX];
void make(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<N_MAX;i++){
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        fac[i]=fac[i-1]*(ll) i%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}

ll combination(ll n, ll k){
    ll res = 1;
    for(int i=n-k+1;i<=n;i++){
    	res *= i;
    	res %= mod;
    }
    for(int i=1;i<=k;i++){
    	res *= inv[i];
    	res %= mod;
    }
    return res;
}

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

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

    ll res = 0;
    res += powLL(2, N);
    res -= 1;
    res += mod;
    res %= mod;

    res -= combination(N, a);
    res += mod;
    res %= mod;

    res -= combination(N, b);
    res += mod;
    res %= mod;

    cout << res << endl;
    return 0;
}

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

int main() {
 vector<int> v(3);
 cin >> v.at(0) >> v.at(1) >> v.at(2) ;
 sort(v.begin(), v.end());

  cout << v.at(0)+v.at(1);
 
  
 
}


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

int main() {
	string s;
    cin >> s;
    string t = "abcdefghijklmnopqrstuvwxyz";
    int ans = 0;
    for(int i=0;i<t.size();i++){
      int count = 0;
      for(int j=0;j<s.size();j++){
        if(t[i]==s[j]){
          count++;
        }
      }
      if(count == 0){
        cout << t[i] << endl;
        ans = 1;
        break;
      }
    }
    if(ans == 0){
      cout << "None" << endl;  
    }
}

Measured memory_bytes: 3756
import fractions

n = int(input())
t=[]
for i in range(n):
    t.append(int(input()))

def lcm(a,b):  # python 3.5 ~ import math
    return a*b //fractions.gcd(a,b)
lc = t[0]
for i in range(1,n):
    lc = lcm(t[i],lc)
print(lc)


Measured memory_bytes: 5048
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int A,B;cin >> A >> B;
  cout << (A^B) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  int n,nn,sum = 0;

  cin >> n;

  nn = n;

  for(int i = 0;i < 10;i++){
    sum += nn % 10;
    nn /= 10;
    if(nn == 0)
      break;
  }

  if(n % sum)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;


  return 0;
}


Measured memory_bytes: 256
#define ll long long
#define ffor(i,a,b) for (int i=(a);i<(b);i++)
#define rfor(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define rep(i,n) for (int i=0;i<(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define SIZE 100001
#define MOD 1000000007
#define INF 100000000
using namespace std;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll h,w;
	cin >> h >> w;
	if(h%3 == 0 || w%3 == 0){
		cout << 0 << endl;
		return 0;
	}
	ll p1 = INF,p2=INF,p3=INF,p4=INF;

	//p1,p2
	rep(i,w){
		ll s_left = h*i;
		ll s_right = h*w - s_left;

		//p1
		ll h_div = h/2;
		ll s_up_1 = h_div*(w-i);
		ll s_down_1 = s_right - s_up_1;
		//p2
		ll w_div = (w-i)/2;
		ll s_right_l = w_div*h;
		ll s_right_r = s_right - s_right_l;

		ll p1_max = max(s_left,max(s_up_1,s_down_1));
		ll p1_min = min(s_left,min(s_up_1,s_down_1));
		if(p1 > p1_max - p1_min) p1 = p1_max - p1_min;

		ll p2_max = max(s_left,max(s_right_l,s_right_r));
		ll p2_min = min(s_left,min(s_right_l,s_right_r));
		if(p2 > p2_max - p2_min) p2 = p2_max - p2_min;
	}

	//p3,p4
	rep(i,h){
		ll up = w*i;
		ll down = h*w - up;
		//p3
		ll h_div = (h-i)/2;
		ll down_u = w*h_div;
		ll down_d = down - down_u;
		//p4
		ll w_div = w/2;
		ll down_l = w_div*(h-i);
		ll down_r = down - down_l;


		ll p3_max = max(up,max(down_u,down_d));
		ll p3_min = min(up,min(down_u,down_d));
		if(p3 > p3_max - p3_min) p3 = p3_max - p3_min;

		ll p4_max = max(up,max(down_l,down_r));
		ll p4_min = min(up,min(down_l,down_r));
		if(p4 > p4_max - p4_min) p4 = p4_max - p4_min;
	}

	cout << min(p1,min(p2,min(p3,p4))) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define fill( x, y ) memset( x, y, sizeof x )
#define copy( x, y ) memcpy( x, y, sizeof x )
using namespace std;

typedef long long LL;
typedef pair < int, int > pa;

inline int read()
{
	int sc = 0, f = 1; char ch = getchar();
	while( ch < '0' || ch > '9' ) { if( ch == '-' ) f = -1; ch = getchar(); }
	while( ch >= '0' && ch <= '9' ) sc = sc * 10 + ch - '0', ch = getchar();
	return sc * f;
}

const int MAXN = 100010;

int vis[MAXN], n, m;

int main()
{
#ifdef wxh010910
	freopen( "data.in", "r", stdin );
#endif
	n = read(), m = read();
	for( int i = 1 ; i <= m ; i++ ) vis[ read() ] ^= 1, vis[ read() ] ^= 1;
	for( int i = 1 ; i <= n ; i++ ) if( vis[ i ] ) return puts( "NO" ), 0;
	return puts( "YES" ), 0;
}


Measured memory_bytes: 1148
#include<iostream>
#include<vector>
#include<string>
#include<queue>
using namespace std;

int main() {
	bool hantei[1 << 16]{};
	hantei[0] = hantei[1] = true;
	for (int b = 2; b < 1 << 16; b++) {
		if (!hantei[b]) {
			for (int c = b * 2; c < 1 << 16; c += b)hantei[c] = true;
		}
	}
	int a;
	while (cin >> a, a) {
		int s = 0;
		for (int b = 2; b < a / 2 + 1; b++)if (!hantei[b] && !hantei[a - b])s++;
		cout << s << endl;
	}
}

Measured memory_bytes: 3164
#include<stdio.h>

int main()
{
  int i,c,a[6],count1=0,count2=0,count3=0,count4=0;
  
  for(i=0;i<6;i++)
  {
    scanf("%d",&a[i]);
  }
  
  for(i=0;i<6;i++)
  {
	switch(a[i])
	{
      	case 1:count1++;
        break;
        case 2:count2++;
        break;
        case 3:count3++;
        break;
        case 4:count4++;
        break;
	}
  }
 
    if(count1==2)
    {
      c++;
    }
  if(count2==2)
    {
      c++;
    }
  if(count3==2)
    {
      c++;
    }
  if(count4==2)
    {
      c++;
    }

  if(c==2)
  {
    printf("YES\n");
  }
  else
  {
    printf("NO\n");
  }
}

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

int main() {
	// your code goes here
	int n;
	cin>>n;
	int h[n];
	for(int i=0;i<n;i++)
	cin>>h[i];
	
	vector<int> dp(n+1,INT_MAX/10);
	dp[0]=0;
	dp[1]=0;
	dp[2]=abs(h[0]-h[1]);
	
	for(int i=3;i<=n;i++)
	{
		dp[i]=min(dp[i-1]+abs(h[i-1]-h[i-2]),dp[i-2]+abs(h[i-1]-h[i-3]));
	}


cout<<dp[n];
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
//#include<atcoder/all>

using namespace std;
//using namespace atcoder;
using ll = long long;
using Graph = vector<vector<int>>;

#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rrep(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)

constexpr ll INF = (ll)1e9;
constexpr ll mod = (ll)1e9 + 7;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
    cin.tie(nullptr); cout.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
}

template< typename T > T mod_pow(T x, T n, const T& p) {
    T ret = 1;
    while (n > 0) {
        if (n & 1) (ret *= x) %= p;
        (x *= x) %= p;
        n >>= 1;
    }
    return ret;
}

struct UnionFind {
    vector<int>d;

    UnionFind(int N) :d(N, -1) {}

    int find(int x) {
        if (d[x] < 0)return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y)return false;
        if (d[x] > d[y])swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    int size(int x) {
        return -d[find(x)];
    }
};
int main() {
    init();

    int N, M; cin >> N >> M;
    UnionFind uf(N);
    rep(i, 0, M) {
        int a, b; cin >> a >> b;
        --a; --b;
        uf.unite(a, b);
    }
    int ans = 0;
    rep(i, 0, N) {
        if (uf.d[i] < 0)++ans;
    }
    --ans;
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 3736
n = int(input())
a1 = list(map(int,input().split()))
a2 = list(map(int,input().split()))

ma = 0
for k in range(n):
  s = sum(a1[0:k+1])
  s = s + sum(a2[k:n])
  if s > ma:
    ma = s
  s = 0
print(ma)

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

int main(){
    int N;
    cin >> N;
    deque<int> dq;
    for(int i=0;i<N;i++){
        int a;
        cin >> a;
        if(i%2 ==1){
            dq.push_back(a);
        }else{
            dq.push_front(a);
        }
    }
    if(N%2 ==0){
        reverse(dq.rbegin(),dq.rend());
    }

    for(auto itr = dq.begin(); itr != dq.end(); ++itr) {
        cout << *itr << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3072
n = int(input())
s = int(input())

if n == s:
    print(n + 1)
    exit()
elif n < s:
    print(-1)
    exit()

m = int(n ** 0.5) + 1

for b in range(2, m + 1):
    temp = n
    t = 0
    while temp >= b:
        t += temp % b
        temp //= b
    if s == t + temp:
        print(b)
        exit()

for p in range(m, 0, -1):
    if (n - s) % p != 0:
        continue
    b = (n - s) // p + 1
    temp = n
    t = 0
    while temp >= b:
        t += temp % b
        temp //= b
    if s == t + temp:
        print(b)
        exit()

print(-1)


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(a<=b)
	{
		for(int i=0;i<b;i++)
		cout<<a;
	}
	else
	{
		for(int j=0;j<a;j++)
		cout<<b;
	}
	return 0;
}

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

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    int a;
    int sum = 0;
    for (int i = 0; i < k; i++) {
        cin >> a;
        sum += a;
    }
    int ans = max(-1, n - sum);
    cout << ans << endl;
}

Measured memory_bytes: 3552
#define  _CRT_SECURE_NO_WARNINGS

#pragma comment(linker, "/STACK:256000000")

#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <deque>
#include <queue>
#include <iomanip>
#include <fstream>
#include <string>

#define ll long long 
#define ld long double 
#define fi(n) for(int i = 0; i < (n); i++)
#define FOR(i, k, n) for(int i = (k); i < (n); i++)

//const int INF = 2147483647;
const int INF = 1e9;
const long long lINF = 9223372036854775807;

using namespace std;

//#define cin in
//#define cout out

ifstream in;
ofstream out;

ll soch(ll n, ll k)
{
	vector<vector<ll>> v(n + 1, vector<ll>(n + 1));
	v[0][0] = 1;
	FOR(i, 1, n + 1)
	{
		v[i][0] = 1;
		v[i][n] = 1;
		FOR(j, 1, n + 1)
		{
			v[i][j] = v[i - 1][j - 1] + v[i - 1][j];
		}
	}
	return v[n][k];
}

int main()
{
	in.open("input.txt");
	out.open("output.txt");
	ll n, a, b;
	cin >> n >> a >> b;
	vector<ll> v(n);
	fi(n)
		cin >> v[i];
	sort(v.rbegin(), v.rend());
	ll sum = 0;
	set<ll> el;
	fi(a)
		el.insert(v[i]), sum += v[i];
	ll answ = 0;
	if (el.size() == 1)
	{
		ll cnt = 0;
		fi(n)
			if (v[i] == v[0])
				cnt++;
		FOR(i, a, min(b, cnt) + 1)
		{
			answ += soch(cnt, i);
		}
	}
	else
	{
		ll k = 0, m = 0;
		fi(a)
			if (v[i] == v[a - 1])
				k++;
		fi(n)
			if (v[i] == v[a - 1])
				m++;
		answ = soch(m, k);
	}
	double answ1 = (double)sum / (double)a;
	cout << fixed << setprecision(6) << answ1 << endl;
	cout << answ << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);
	String st = scan.next();
	int a = Integer.parseInt(st);
	st = scan.next();
	int b = Integer.parseInt(st);
	st = scan.next();
	int c = Integer.parseInt(st);
	int t;

	if(a > b)
	    {
		t = b;
		b = a;
		a = t;
	    }
	if(b > c)
	    {
		t = c;
		c = b;
		b = t;
	    }
	if(a > b)
	    {
		t = b;
		b = a;
		a = t;
	    }
	System.out.println(a + " " + b + " " + c);
    }
}



Measured memory_bytes: 26208
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline LL gl()
{
	LL f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int INF = 0x3f3f3f3f, N = 200003;

int a[100] = {0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}; 

int main()
{
	//File("");
    int n = gi();
    cout << a[n] << endl;
	return 0;
}


Measured memory_bytes: 764
# coding: utf-8
def get_ln_inputs():
    return input().split()


def get_ln_int_inputs():
    return list(map(int, get_ln_inputs()))


def main():
    N = get_ln_int_inputs()[0]
    l = list()
    r = list()
    for _ in range(N):
        l_i, r_i = get_ln_int_inputs()
        l.append(l_i)
        r.append(r_i)
    print(sum(r) - sum(l) + N)
    return


main()

Measured memory_bytes: 3060
# https://drken1215.hatenablog.com/entry/2019/03/03/150200
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    N = int(input())
    h = list(map(int, input().split()))

    res = 0
    while True:
        if max(h) == 0:
            break

        i = 0
        while i < N:
            if h[i] == 0:
                i += 1
                continue
            else:
                res += 1
                while i < N and h[i] != 0:
                    h[i] -= 1
                    i += 1
    print(res)


resolve()

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

int main() {
  int n=0;
  cin>>n;
  vector<string> vec(n);
  int count=1;
  
  rep(i,n){
    cin>>vec.at(i);
  }
  sort(vec.begin(),vec.end());
  for(int i=1;i<(int)(n);i++){
    if(vec.at(i)!=vec.at(i-1)){
      count++;
    }
  }
  cout<<count;
}

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

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

	int ans = 0;
	for (int i = 0; i < S.size() / 2; i++) {
		if (S[i] != S[S.size() - i - 1]) {
			ans++;
		}
	}

	cout << ans << endl;

}

Measured memory_bytes: 256
#pragma GCC optimize "-O3"
#include <bits/stdc++.h>
using namespace std;
#define LSOne(S) (S & (-S))
#define ll long long
#define two pair<int,int>
#define four pair<two,two>
#define pb push_back
#define mk make_pair
#define INF 1000000000000000000
#define P 1000000007
#define lmax 1000000000
#define nn 1000003
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define f first
#define s second
#define vi vector<int>
#define vll vector<ll>
#define vtwo vector<two>
#define ALL(container) (container).begin(), (container).end()
#define sz(container) (int)(container.size())
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define mid(a,b) (a+b>>1)
#define minN 0
#define maxN 10000000
#define na(x) ((x)<P?(x):(x)-P)
#define ab(a) (-(a)<(a)?(a):-(a))
int in(){
	int x=0,w=1;char ch=getchar();
	while ((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if (ch=='-') w=0,ch=getchar();
	while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return w?x:-x;
}
int a,b,e,o;
vi v[100003];
int main(){std::ios::sync_with_stdio(false);
for(int i=1;i<4;i++){
	cin>>a>>b;
	v[a].pb(b);
	v[b].pb(a);
}
for(int i=1;i<=4;i++){
	if(v[i].size()==1)e++;
	if(v[i].size()==2)o++;
}
if(e==2&&o==2){
	cout<<"YES"<<endl;
}else{
	cout<<"NO"<<endl;
}
}

/*

                   *         *
                  * *       * *
                 *   *     *   *
                *     *   *     *
                 *   *   * *   *
                  *   *   *   *
                   *   * *   *
                     *  *   *
					   *  *


*/





Measured memory_bytes: 2560
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int s = 100000;
	int n;
	cin >> n;
	while (n--) {
		if (int(s*1.05) % 1000 == 0) {
			s = int(s*1.05);
		}
		else {
			s = int(s*1.05) + (1000 - int(s*1.05) % 1000);
		}
	}
	printf("%d\n", s);
    return 0;
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef vector<int> vi;
typedef long long lint;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef unsigned long long ulint;
#define endl '\n'
#define fst first
#define sed second
#define pb push_back
#define mp make_pair
#define rint register int
#define SZ(x) (int((x).size()))
#define all(x) (x).begin(), (x).end()
#define reveal(x) cerr << #x << " = " << (x) << endl
#define rep(it, f, e) for (rint it = (f); it <= (e); ++it)
#define per(it, f, e) for (rint it = (f); it >= (e); --it)
#define repe(it, x) for (auto it = (x).begin(); it != (x).end(); ++it)
const int INF = 0x3f3f3f3f;
int dp[10086];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	int h, n;
	cin >> h >> n;
	memset(dp, 0x3f, sizeof(dp));
	dp[0] = 0;
	rep (i, 1, n) {
		int a, b;
		cin >> a >> b;
		rep (j, 0, h) if (dp[j] != INF) {
			dp[min(h, j + a)] = min(dp[min(h, j + a)], dp[j] + b);
		}
	}
	cout << dp[h] << endl;
	return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <sstream>
#include <climits>
#include <cstring>
#include <cassert>
#include <utility>
#include <cstdio>
#include <limits>
#include <string>
#include <vector>
#include <cmath>
#include <stack>
#include <ctime>
#include <queue>
#include <set>
#include <map>

#define in freopen("input.in", "r", stdin);
#define out freopen("output.out", "w", stdout);
#define clr(arr, key) memset(arr, key, sizeof arr)
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define mt       make_tuple
#define infinity (1 << 28)
#define LL long long
#define PI acos(-1)
#define gcd(a, b) __gcd(a, b)
#define CF ios_base::sync_with_stdio(0);cin.tie(0);
#define lcm(a, b) ((a)*((b)/gcd(a,b)))
#define all(v) v.begin(), v.end()
#define no_of_ones __builtin_popcount // __builtin_popcountll for LL
#define SZ(v) (int)(v.size())
#define eps 1e-7

int col8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int row8[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int col4[4] = {1, 0, -1, 0};
int row4[4] = {0, 1, 0, -1};
//int months[13] = {0, ,31,28,31,30,31,30,31,31,30,31,30,31};

using namespace std;

//struct point{int x, y; point () {} point(int a, int b) {x = a, y = b;}};
template <class T> T sqr(T a){return a * a;}
template <class T> T power(T n, T p) { T res = 1; for(int i = 0; i < p; i++) res *= n; return res;}
template <class T> double getdist(T a, T b){return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));}    // distance between a and b
template <class T> T extract(string s, T ret) {stringstream ss(s); ss >> ret; return ret;}
template <class T> string tostring(T n) {stringstream ss; ss << n; return ss.str();}
//LL bigmod(LL B,LL P,LL M){LL R=1; while(P>0)  {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;}
struct fast{fast(){ios_base::sync_with_stdio(0);cin.tie(0);}}cincout;

#define MAX 200010
/***********************************THE GRASS IS ALWAYS GREENER ON THE OTHER SIDE***********************************/

int main()
{
    map <int, int> mpp;
    int n, x;
    cin >> n;
    while(n--)
    {
        cin >> x;
        mpp[x]++;
    }
    LL res = 0, last = 0;
    for(auto x: mpp)
    {
        if(x.second < 2)
            continue;
        if(x.second >= 4)
            res = 1LL * x.first * x.first;
        else
            res = x.first * last;
        last = x.first;
    }
    cout << res;
    return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) v.begin(),v.end()
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll a[3];
    rep(i,3) cin>>a[i];
    sort(a,a+3);
    rep(i,3){
        cout<<a[i];
        if(i<2)cout<<" ";
    }
    cout<<endl;
    
    return 0;
}


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

using namespace std;

#define FAST_IO ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define endl "\n"
typedef long long ll;
 
int main(){ 
	
	FAST_IO;
   
	int n;
	cin>>n;

	int h[n];

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

	int dp[n];
	dp[0] = 0;
	dp[1] = abs(h[0] - h[1]);

	for(int i=2; i<n; i++){
		dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
	}

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

Measured memory_bytes: 1024
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

a_sort = sorted(set(a))

max_val_1 = a_sort[-1]
max_total_1 = a.count(max_val_1)

if len(a_sort) >= 2:
    max_val_2 = a_sort[-2]

#print("max val:{}".format(max_val_1))
#print("max total:{}".format(max_total_1))

for i in range(n):
    if max_total_1 >=2:
        print(max_val_1)
    
    elif a[i] < max_val_1:
        print(max_val_1)

    elif a[i] == max_val_1 and max_total_1 == 1:
        print(max_val_2)
    else:
        print("err")

Measured memory_bytes: 17188
import sys
import math
from collections import deque
import heapq
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

a,b,c,d = IL()

while True:
  c -= b
  if c <= 0:
    print("Yes")
    break
  a -= d
  if a <= 0:
    print("No")
    break

Measured memory_bytes: 65348
#include <iostream>
#include <algorithm>
#include <numeric>
#include "math.h"
#include <string>
#include <vector>

using namespace std;



//　9×9
int main() {

	int a, b;
	cin >> a >> b;

	if (a > 9 || b > 9) 
	{
		cout << -1 << endl;
		return 0;
	}

	cout << a * b << endl;


	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int n,m,l;
    int i,j,k;
    int a[100][100]={{0}};
    int b[100][100]={{0}};
    long c[100][100]={{0}};
    
    scanf("%d%d%d",&n,&m,&l);
    
    for(i=0; i<n; i++){
        for(j=0; j<m; j++){
            scanf("%d",&a[i][j]);
        }
    }
    
    for(i=0; i<m; i++){
        for(j=0; j<l; j++){
            scanf("%d",&b[i][j]);
        }
    }
    
    for(i=0; i<n; i++){
        for(j=0; j<l; j++){
            for(k=0; k<m; k++){
                c[i][j] += a[i][k]*b[k][j];
            }
        }
    }
    
    for(i=0; i<n; i++){
        for(j=0; j<l; j++){
            printf("%ld",c[i][j]);
            if(j == l-1) putchar('\n');
            else putchar(' ');
        }
    }
    
    return 0;
}

Measured memory_bytes: 768
import fractions


def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


if __name__ == '__main__':
    A, B, C, D = map(int, input().split())

    # A以上B以下の数
    between_A_B = B - A + 1

    # B以下でCで割り切れる数
    max_num_diveided_by_C = (B//C)

    # A未満でCで割り切れる数
    min_num_diveided_by_C = ((A-1)//C)

    # B以下でDで割り切れる数
    max_num_diveided_by_D = (B//D)

    # A未満でDで割り切れる数
    min_num_diveided_by_D = ((A-1)//D)

    # B以下でCでもDでも割り切れる数
    max_num_diveided_by_CD = (B//lcm(C, D))

    # A未満でCでもDでも割り切れる数
    min_num_diveided_by_CD = ((A-1)//lcm(C, D))

    answer = between_A_B - ((max_num_diveided_by_C - min_num_diveided_by_C) + (max_num_diveided_by_D - min_num_diveided_by_D) - (max_num_diveided_by_CD - min_num_diveided_by_CD))
    print(answer)

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

//#define int long long
#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod

int n;
ll a[100000 + 5];
ll sum[100000 + 5];

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;

    rep(i, n) {
        cin >> a[i];
        sum[i] = a[i] + sum[max(0, i - 1)];
    }

    ll ans = LLONG_MAX;
    ll tmp = 0;
    ll plus = 0;
    rep(i, n) {
        if (i % 2 == 0) {
            if (sum[i] + plus <= 0) {
                tmp += abs(sum[i] + plus) + 1;
                plus += abs(sum[i] + plus) + 1;
            }
        }
        else {
            if (sum[i] + plus >= 0) {
                tmp += abs(sum[i] + plus) + 1;
                plus -= abs(sum[i] + plus) + 1;
            }
        }
    }
    ans = min(ans, tmp);
    tmp = 0;
    plus = 0;
    rep(i, n) {
        if (i % 2 == 0) {
            if (sum[i] + plus >= 0) {
                tmp += abs(sum[i] + plus) + 1;
                plus -= abs(sum[i] + plus) + 1;
            }
        }
        else {
            if (sum[i] + plus <= 0) {
                tmp += abs(sum[i] + plus) + 1;
                plus += abs(sum[i] + plus) + 1;
            }
        }
    }
    cout << min(ans, tmp) << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
    詰まった時に、別の分野の問題として考え直す（これdpでは？、グラフとしてみればいいのでは？）
    多くの問題はパターンマッチだが、パターンに落とし込むまでが難しく、そのための訓練としてわからない問題をあれこれ色々な角度から考察してみるのではないか
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

const ll linf=1LL<<60;
const int inf=1<<29;

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

    int n, k; cin >> n >> k;
    vector<int> h(n+5, 0);
    repr(i, 1, n+1) cin >> h[i];

    const ll inf=1LL<<60;

    vector<ll> dp(n+5, inf);
    dp[1]=0;

    repr(i, 1, n+1){
        repr(j, 1, k+1){
            if(i-j < 1) continue;
            chmin(dp[i], dp[i-j]+abs(h[i]-h[i-j]));
        }
    }

    cout << dp[n] << endl;

    return 0;
}


Measured memory_bytes: 1408
import java.io.IOException;
import java.io.PrintStream;
import java.util.Scanner;

class Main
{
    public static void main(String[] args) throws IOException
    {
        Scanner in = new Scanner(System.in);
        P78ASolver s = new P78ASolver(in, System.out);
        s.read();
        s.solve();
    }
}

class P78ASolver
{
    Scanner in;
    PrintStream out;
    String X, Y;

    public P78ASolver(Scanner s, PrintStream p)
    {
        in = s;
        out = p;
    }

    public void read() throws IOException
    {
        String[] ss = in.nextLine().split(" ");
        X = ss[0];
        Y = ss[1];
    }

    public void solve()
    {
        if (X.compareTo(Y) < 0)
            out.println("<");
        else if (X.compareTo(Y) == 0)
            out.println("=");
        else
            out.println(">");
    }
}


Measured memory_bytes: 21972
#define _USE_MATH_DEFINES
 
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
 
constexpr ll MOD = 1000000007;
 
#ifndef ONLINE_JUDGE
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
#else
#define print(...)
#endif


int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    ll n;
    string ans="No";
    
    cin >> n;

    if(n>=30) ans="Yes";
    
    cout << ans << endl;
 
    return 0;
}



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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using v = vector<T>;
template <class T>
using vv = v<v<T>>;
#define ALL(c) (c).begin(), (c).end()

int main()
{
    v<ll> a(2),b(2);
    for (int i = 0; i < 2; i++)
    {
        cin >> a[i];
    }
    for (int i = 0; i < 2; i++)
    {
        cin >> b[i];
    }
    ll ans = INT64_MIN;
    for (int i = 0; i < 2; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            ans = max(ans,a[i]*b[j]);
        }
        
    }
    
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
from math import factorial
N, P = map(int, input().split())
A = list(map(int, input().split()))

a = [x for x in A if x % 2 == 1]
b = [x for x in A if x % 2 == 0]
x = len(a)
y = len(b)
z = x // 2
w = (x + 1) // 2
S = 0
T = 0

if P == 0:
	for k in range(z+1):
		s = factorial(x) // (factorial(x-2*k) * factorial(2*k))
		S += s
	for k in range(y+1):
		t = factorial(y) // (factorial(y-k) * factorial(k))
		T += t
	U = S * T
	print(U)
else:
	for k in range(w):
		s = factorial(x) // (factorial(x-2*k-1) * factorial(2*k+1))
		S += s
	for k in range(y+1):
		t = factorial(y) // (factorial(y-k) * factorial(k))
		T += t
	U = S * T
	print(U)

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

int main()
{
    string s;

    cin >> s;

    for(int i = 0;i < s.size();i++){
        if(s[i] == 'A'){
            for(int j = s.size()-1;j >= i;j--){
                if(s[j] == 'Z'){
                    cout << j-i+1 << endl;
                    return 0;
                }
            }
        }
    }
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(void) {
    int r,g;
    cin >> r >> g;
    cout << r+(g-r)*2;
}


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

using namespace std;

using ll = long long;

template<int N>
struct Prime {
    bool is_p[N + 1]; // 素数表

    constexpr Prime() : is_p() {
        for (int i = 2; i <= N; ++i) is_p[i] = true;
        is_p[0] = is_p[1] = false;
        for (long long i = 2; i <= N; ++i) {
            if (is_p[i])
                for (long long j = i * i; j <= N; j += i)
                    is_p[j] = false;
        }
    }
    constexpr bool operator[](const int idx) const { return is_p[idx]; }
};

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

    constexpr int n = 1e5 + 5;
    constexpr Prime<n> p;

    vector<int> cnt(n);
    for (int i = 1; i < n; ++i) {
        if (i % 2 == 1 && p[i] && p[(i + 1) / 2])
            cnt[i] = 1;
        cnt[i] += cnt[i - 1];
    }

    int q;
    cin >> q;
    while (q--) {
        int l, r;
        cin >> l >> r;
        cout << cnt[r] - cnt[l - 1] << '\n';
    }

    return 0;
}


Measured memory_bytes: 1152