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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)
#define rep1(i,n) for(auto i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;


struct init{ init(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); }; }aaaaaaa;

struct Node{
    ll d;
    ll i;
    bool operator< (const Node &r) const{
        return d < r.d;
    }
};

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];


    ll asum = 0;
    ll bsum = 0;
    rep(i, n) asum += a[i];
    rep(i, n) bsum += b[i];

    if(asum < bsum){
        cout << -1 << endl;
        return 0;
    }
    
    vector<ll> c(n);
    rep(i, n) c[i] = a[i];

    priority_queue<Node> que;
    rep(i, n) que.push({c[i]-b[i], i});

    int i = 0;
    ll idx = que.top().i; que.pop();
    while(0 < c[idx]-b[idx]){
        while(i < n){
            ll diff = b[i]-c[i];
            if(c[idx]-b[idx] <= 0) break;
            else if(0 < diff){
                ll add = min(c[idx]-b[idx], diff);
                c[i] += add;
                c[idx] -= add;
            }
            else i++;
        }
        if(i == n) break;
        idx = que.top().i; que.pop();
    }

    
    ll cnt = 0;
    rep(i, n){
        if(c[i] != a[i]) cnt++;        
    }
    cout << cnt << endl;
    
    return 0;
}



Measured memory_bytes: 4724
n,k = map(int,input().split())
li = list(map(int,input().split()))

ans = 10**9
for i in range(n-k+1):
  l = abs(li[i]) + abs(li[i]-li[i+k-1])
  r = abs(li[i+k-1]) + abs(li[i]-li[i+k-1])
  ans = min(ans,l,r)
print(ans)

Measured memory_bytes: 14252
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include<cmath>
using namespace std;

int main()
{
   long long n,m;
    cin>>n>>m;
    int w=m;
    while(w)
    {
        n=n*10;
        w=w/10;
    }
    n=n+m;
    //cout<<n<<endl;
    long long sum=1;
    while(1)
    {
        if(sum*sum==n)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
        else
            if(sum*sum>n)
                break;
        sum++;

    }
    cout<<"No"<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <math.h> // sqrt
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <iomanip> // setprecision
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;

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

int main() {
    ll A, B;
    cin >> A >> B;
    int count = 0;
    ll N = gcd(A, B);
    for (ll i = 2; i * i <= N; i++) {
        if (N % i != 0) {
            continue;
        }
        while(N %  i == 0) {
            N /= i;
        }
        count++;
    }
    if (N != 1) {
        count++;
    }
    cout << count + 1 << endl;
}


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

using namespace std;

int main () {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	long long n; cin >> n;
	vector <long> a;
	for(long i =0; i < n; ++i){
		long long x; cin >> x;
		a.push_back(x);
	}
	long long res = 0;
	for(long i =1; i< n; ++i){
		if(a[i] < a[i-1]){
			res += a[i-1] - a[i];
			a[i] = a[i-1];
		}
	}
	cout << res;
		
}


Measured memory_bytes: 5324
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> p(m), y(m);
    vector<vector<pair<int, int> > > v(n);
    rep(i, m) {
        cin >> p[i] >> y[i];
        v[p[i]-1].push_back(make_pair(y[i], i));
    }
    rep(i, n) {
        sort(v[i].begin(), v[i].end());
        for(unsigned j = 0; j < v[i].size(); j++) {
            y[v[i][j].second] = j+1;
        }
    }

    rep(i, m) {
        printf("%06d%06d\n", p[i], y[i]);
    }
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 7808
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
double a[10],b[10];
int c[10];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i]>>b[i];
	long double sum=0;
	for(int i=1;i<=n;i++) c[i]=i;
	do{
		for(int i=2;i<=n;i++) sum+=sqrt((a[c[i]]-a[c[i-1]])*(a[c[i]]-a[c[i-1]])+(b[c[i]]-b[c[i-1]])*(b[c[i]]-b[c[i-1]]));
	}while(next_permutation(c+1,c+n+1));
	for(int i=1;i<=n;i++) sum/=i;
	printf("%Lf",sum);
	return 0;
}


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

int main() {
  int n;
  cin>>n;
  if(n<1000){
    cout<<"ABC"<<endl;
  }
  else{
    cout<<"ABD"<<endl;
  }
}

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

int main(){
    int n,m;
    cin >> n >> m;
    long long x[n],y[n],z[n];
    for(int i=0; i<n; i++){
        cin >> x[i] >> y[i] >> z[i];
    }
    long long ans = 0;
    long long sum[n];
    for(int i=-1; i<2 ; i+=2){
        for(int j=-1; j<2 ; j+=2){
            for(int k=-1; k<2 ; k+=2){
                for(int l=0; l<n; l++){
                    sum[l] = i*x[l]+j*y[l]+k*z[l];
                }
                sort(sum,sum+n);
                long long t=0;
                for(int l=0; l<m; l++){
                    t += sum[n-1-l];
                }
                ans = (ans < t)? t : ans;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
while True:
    m,s,r=map(int,input().split())
    if m==-1 and s==-1 and r==-1:
        break
    if r>=50:
        print('C')
    elif m==-1 or s==-1:
        print('F')
    else:
        k=m+s
        if k>=80:
            print('A')
        if k>=65 and k<80:
            print('B')
        if k>=50 and k<65:
            print('C')
        if k>=30 and k<50:
            print('D')
        if k<30:
            print('F')
    
    


Measured memory_bytes: 5596
#include <bits/stdc++.h>
#define fu(i,a,b) for(int i=a;i<=b;i++)
#define X first
#define Y second
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
const int MAXN = 211;
const int INF = 1e6;
int n,dd[MAXN],g[MAXN][MAXN],check,ret;
char s[MAXN][MAXN];
vector < int > E[MAXN];
void visit(int u,int p,int t)
{
    dd[u] = t;
    for(auto v:E[u])
    {
        if(v!=p)
        {
            if(!dd[v])
            {
                int nxt = (t==2)?1:2;
                visit(v,u,nxt);
            }
            else
            {
                if(dd[u] == dd[v])
                {
                    check = 1;
                    return ;
                }
            }
        }
    }
}
void floyd()
{
    fu(i,1,n) g[i][i] = 0;
    fu(k,1,n)
    fu(i,1,n)
    fu(j,1,n)
    {
        g[i][j] = min(g[i][j],g[i][k]+g[k][j]);
    }
    fu(i,1,n)
    fu(j,1,n)
    {
        ret = max(ret,g[i][j]);
    }
    ret++;
}
int main()
{
    //freopen("A.inp","r",stdin);
    cin >> n;
    fu(i,1,n)
    fu(j,1,n)
    {
        g[i][j] = INF;
    }
    fu(i,1,n)
    fu(j,1,n)
    {
        cin >> s[i][j];
        if(s[i][j] == '1')
        {
            E[i].push_back(j);
            g[i][j] = 1;
        }
    }
    fu(i,1,n)
    {
         memset(dd,0,sizeof(dd));
         visit(i,i,1);
    }
    if(check)
    {
        cout << -1;
        return 0;
    }
    floyd();
    cout << ret;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(long long i=s;i<n;i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
const double pi = acos(-1.0);
const ll mod = pow(10,9) + 7;
const ll INF = pow(2,31) - 1;

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

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

int main()
{
    ll n,q,cnt = 0;
    cin >> n;
    vll s(n);
    rep(i,n)cin >> s[i];
    cin >> q;
    rep(i,q){
        ll t;
        cin >> t;
        rep(j,n)if(s[j] == t){
            cnt++;
            break;
        }
    }

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <string>
#include <algorithm>
#define ll long long
using namespace std;

int main(void){
    ll a, b;
    cin >> a >> b;
    if(a+b >= 10){
        cout << "error" << endl;
    }else{
        cout << a+b << endl;
    }
    return 0;
}

Measured memory_bytes: 764
//C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

//Hang in there!

using namespace std;


int main() {
	int A, B;
	cin >> A >> B;
	if (A > 8 || B > 8) {
		cout << ":(" << endl;
	}
	else {
		cout << "Yay!" << endl;
	}
}



Measured memory_bytes: 256
a=input()
a=[i for i in a]
x=int(a[0]+a[1])
y=int(a[2]+a[3])
cy=0
cm=0
if 0<x<13 and y<=99:
    cm+=1
if x<=99 and 0<y<13:
    cy+=1
if cy==1:
    if cm==1:
        print("AMBIGUOUS")
    else:
        print("YYMM")
elif cm==1:
    print("MMYY")
else:
    print("NA")


Measured memory_bytes: 3060
N, M = [int(v) for v in input().split()]
tbl = [[0] * (N + 1) for _ in range(N + 1)]


def dfs(v, visited):
    if len(visited) == N:
        return 1

    ans = 0
    for i in range(1, N + 1):
        if i == v: continue
        if tbl[i][v] == 1 and i not in visited:
            visited.append(i)
            ans += dfs(i, visited)
            visited.pop()
    return ans


for _ in range(M):
    a, b = [int(v) for v in input().split()]
    tbl[a][b] = 1
    tbl[b][a] = 1

paths = [1, ]
print(dfs(1, paths))

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

int main() {
   std::string S,T;
   std::cin >> S >> T;
   int eq = 0;
   for (size_t i = 0; i < S.size() - T.size() +1; i++) {
      std::string Sp = S.substr(i, T.size());
      int subeq = 0;
      for (size_t j = 0; j < T.size(); j++) {
         if (Sp.at(j) == T.at(j)) {
            subeq++;
         }
      }
      if (subeq > eq) {
         eq = subeq;
      }
   }
   std::cout << (T.size() - eq) << '\n';
}


Measured memory_bytes: 3600
import math

count = 0

n, d=map(int, input().split())

for i in range(n) :
    num_list=list(map(int, input().split()))
    dis = math.sqrt(num_list[0] * num_list[0] + num_list[1] * num_list[1])
    if dis <= d:
        count += 1

print(count)


Measured memory_bytes: 70072
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int n,t,e,f=0;
  vector<int> v;
  cin>>n>>t>>e;
  for(int i=0,x;i<n;++i){cin>>x;v.push_back(x);}
  for(int i=0;i<n;++i){
    if(t%v[i]<=e||-e<=t%v[i]-v[i]){cout<<i+1<<endl;f=1;break;}
  }
  if(!f)cout<<-1<<endl;
  return 0;
}

Measured memory_bytes: 1220
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const int MOD = 1000000007;
//const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R;


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

	cin >> N;
	string s;
	cin >> s;
	M = s.size();
	vector<vector<long long int>>dp(N + 1, vector<long long int>(N + 1));
	dp[0][0] = 1;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j <= N; j++) {
			if (j != N)dp[i][j] += dp[i - 1][j + 1] * 2;
			if (j)dp[i][j] += dp[i - 1][j - 1];
			else dp[i][j] += dp[i - 1][j];
			dp[i][j] %= MOD;
		}
	}
	cout << dp[N][M] << endl;
}


Measured memory_bytes: 195840
#include<stdio.h>
#define MAX_NUM 101
#define LOW_INF -2000000000


int main(){
  int i,j,n,m,to,from,maxPoint=LOW_INF;

  int pass[MAX_NUM][MAX_NUM];
  for(i=0; i<MAX_NUM; i++){
    for(j=0; j<MAX_NUM; j++){
      pass[i][j]=0;
    }
  }

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&from,&m);
    if(from>maxPoint)maxPoint=from;
    for(j=1;j<=m;j++){
      scanf("%d",&to);
      pass[from][to]=1;
    }
  }

  for(i=1; i<=maxPoint; i++){
    for(j=1; j<=maxPoint; j++){
      printf("%d",pass[i][j]);
      if(j!=maxPoint)printf(" ");
    }
    printf("\n");
  }
  return 0;
  
}



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

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

    map<string , int> mp;

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

    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;
}

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

int n, m, ct;
pair <int, int> ans[200005];
int main()
{
	scanf("%d%d", &n, &m);
	int h = n / 2;
	if (n & 1)
	{
		for (int i = 1; 2 * i <= h; i++)
			ans[++ct] = make_pair(i, h - i + 1);
		for (int i = h + 1; 2 * i < n + h + 1; i++)
			ans[++ct] = make_pair(i, n - i + h + 1);
	}
	else
	{
		for (int i = 1; 2 * i <= h; i++)
			ans[++ct] = make_pair(i, h - i + 1);
		for (int  i = h + 2; 2 * i < n + h + 2; i++)
			ans[++ct] = make_pair(i, n - i + h + 2);
	}
	for (int i = 1; i <= m; i++)
		printf("%d %d\n", ans[i].first, ans[i].second);
	return 0;
}

Measured memory_bytes: 4412
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

fn main() {
    let mut abc = get!(String).split_whitespace().map(|n| n.parse::<usize>().unwrap()).collect::<Vec<_>>();
    abc.sort();
    println!("{}", if abc[0] + abc[1] == abc[2] { "Yes" } else { "No" });
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>

int main()
{
	int N, T;
	std::cin >> N >> T;

	std::vector<std::pair<int, int> > v;
	for ( int i = 0; i < N; i++ )
	{
		int c, t;
		std::cin >> c >> t;
		v.emplace_back( std::make_pair( c, t ) );
	}

	int cost = 1e5;
	for ( auto &&it : v )
	{
		if ( it.second <= T )
		{
			if ( cost > it.first )
			{
				cost = it.first;
			}
		}
	}

	if ( cost == 1e5 )
	{
		std::cout << "TLE" << std::endl;
	}
	else
	{
		std::cout << cost << std::endl;
	}

	return ( 0 );
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
typedef long long int ll;

int main(){
    int n; cin >> n;
    vector<ll> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    ll last=1;
    ll ans=a[0]-1;
    for(int i=1;i<n;i++){
        if(a[i]==(last+1)){
            last++;
        }
        else if(a[i]<last+1){
            continue;
        }
        else if(a[i]%(last+1)==0){
            a[i]-=(last+2);
            ans++;
            ans+=a[i]/(last+1);
            last=max(last,a[i]%(last+1));
        }
        else{
            ans+=a[i]/(last+1);
            last=max(last,a[i]%(last+1));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()

int solve(vi b, vi p){
    if(accumulate(all(b),0) != accumulate(all(p),0)) return 1000;

    int cost=0,n=b.size();
    rep(i,n){
        int j;
        for(j=i; p[i]!=b[j] and j<n ;j++);
        cost+=j-i;
        swap(b[i],b[j]);
    }
    return cost;
}

int main(){
    int n,m;
    cin>>n>>m;
    
    vi b(n),p,cp;
    for(auto &&i:b) cin>>i;
    rep(i,m){
        int t; cin>>t;
        rep(j,t) p.push_back(i%2);
    }
    
    int ans=1000;
    ans=min(ans,solve(b,p));
    for(auto &&i:p) i^=1;
    ans=min(ans,solve(b,p));
    
    cout<<ans<<endl;
	return 0;
}




Measured memory_bytes: 3160
s = input()
a = 0
if s[:2] != '00' and s[:2] < '13':
  a += 1
if s[2:] != '00' and s[2:] < '13':
  a += 2
if a == 0:
  print('NA')
elif a == 1:
  print('MMYY')
elif a == 2:
  print('YYMM')
else:
  print('AMBIGUOUS')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define int long long

using namespace std;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int l[3], r[3], g = c * d / __gcd(c, d);
    l[0] = (a - 1) / c * c + c;
    r[0] = b / c * c;
    l[1] = (a - 1) / d * d + d;
    r[1] = b / d * d;
    l[2] = (a - 1) / g * g + g;
    r[2] = b / g * g;
    cout << (b - a + 1) - max((r[0] - l[0]) / c + 1, 0LL) - max((r[1] - l[1]) / d + 1, 0LL) + max((r[2] - l[2]) / g + 1, 0LL) << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
using namespace std;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	int bills;
	for(bills = (n/1000)*1000;bills<n;bills+=1000);
	cout<<bills-n;
	return 0;
}


Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;


#define ll       long long int
#define fast     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define MOD      1000000007
#define pb       push_back
#define S        second
#define F        first
#define P 		 pair<ll,ll>
#define PI 3.1415926535897932384626433832795028
//#define ordered_set tree<ll, null_type,less_equal<>, rb_tree_tag,tree_order_statistics_node_update>
ll dp[3000][3000],sum[3000][3000];
ll solve(vector<ll> &v,ll i,ll j){
	if(i==j)
		return 0;
	if(dp[i][j]!=-1) return dp[i][j];
	ll mincost=1e16;
	for(ll k=i;k<j;k++){
		mincost=min(mincost,sum[i][j]+solve(v,i,k)+solve(v,k+1,j));

	}
	return dp[i][j]=mincost;
}
void preprocess(vector<ll> &v){
	for(ll i=1;i<=v.size();i++){
		for(ll j=i;j<=v.size();j++){
			sum[i][j]=v[j] + ( (j==i) ? 0 : sum[i][j-1]);
		}
	}
}
int32_t main()
{	fast

// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	memset(dp,-1,sizeof dp);
	ll n;
	cin>>n;
	vector<ll> v(n+1);
	for(ll i=1;i<=n;i++)
		cin>>v[i];
	preprocess(v);
	cout<<solve(v,1,n)<<endl;

	
	return 0;

}

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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
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; }

//INT_MAX	2,147,483,647 = 2*1.0e9

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    string S; cin >> S;
    
    bool ans = true;
    for(int i = 0; i < S.length(); i++){
        if(i%2 == 0){
            if(S[i] != 'R' && S[i] != 'U' && S[i] != 'D') ans = false;
            else continue;
        } else {
            if(S[i] != 'L' && S[i] != 'U' && S[i] != 'D') ans = false; 
            else continue;
        }   
    }

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

    return 0;
}


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

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

    bool flg = false;
    
    if (S == T){
        flg = true;
    }

    for (int i = 1; i < S.length(); i++){
        if (S.substr(i, S.length() - i) + S.substr(0, i) == T){
            flg = true;
        }
    }
    if (flg) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

#define rep(i, n) for (int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;

int n;
vector<vector<P>> v;

bool judge(int bit) {
  rep(i, n) {
    if( !(bit & (1 << i)) ) continue;;
    for (P xy : v[i] ) {
      int x = xy.first;
      int y = xy.second;

      if (y == 1 && !(bit & (1 << x))) return false;
      if (y == 0 && (bit & (1 << x))) return false;
    }
  }
  return true;
}

int main() {
  cin >> n;
  v.resize(n);
  rep(i, n) {
    int a;
    cin >> a;
    v[i].resize(a);
    rep(j, a) {
      cin >> v[i][j].first >> v[i][j].second;
      --v[i][j].first;
    }
  }

  int res = 0;
  rep(bit, 1 << n) {
    if (judge(bit)) {
      int count = 0;
      rep(i, n) {
	if (bit & (1 << i)) ++count;
      }
      res = max(res, count);
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		var mx = A.Max();
		var mn = A.Min();
		mn *= -1;
		
		List<String> L = new List<String>();
		if(mx > mn){
			int idx = -1;
			for(int i=0;i<N;i++) if(A[i] == mx) idx = i;
			for(int i=0;i<N;i++) L.Add(String.Format("{0} {1}",idx + 1, i + 1));
			for(int i=0;i<N-1;i++) L.Add(String.Format("{0} {1}",i + 1, i + 2));
		} else {
			int idx = -1;
			for(int i=0;i<N;i++) if(A[i] == -mn) idx = i;
			for(int i=0;i<N;i++) L.Add(String.Format("{0} {1}",idx + 1, i + 1));
			for(int i=N-1;i>0;i--) L.Add(String.Format("{0} {1}",i + 1, i));
		}
		Console.WriteLine(L.Count);
		foreach(var s in L) Console.WriteLine(s);
		
		
		
	}
	int N;
	int[] A;
	public Sol(){
		N = ri();
		A = ria();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13396
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var imp = Console.ReadLine().Split('/');

            if((int.Parse(imp[0])*10000)+(int.Parse(imp[1])*100)+(int.Parse(imp[2]))<=20190430)
            {
                Console.Write("Heisei");
            }
            else
            {
                Console.Write("TBD");
            }

           // System.Threading.Thread.Sleep(1000);
        }
    }
}


Measured memory_bytes: 11092
/*
    Mbak Sana Dong
    Mbak Chaeyoung Dong
*/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int mod;
ll power(ll a, ll b, ll m)
{
    ll ret = 1;
    if(b == 0) return ret;
    while(b>0)
    {
        if(b%2==1) ret = (ret*a) % m;
        b /= 2;
        a = (a*a) % m;
    }
    return ret;
}
int go(int now)
{
    int ans = 0;
    while(now > 0)
    {
        int popcount = 0;
        int temp = now;
        while(temp > 0) {
            if(temp%2==1) popcount++;
            temp /= 2;
        }
        now %= popcount;
        ans++;
    }
    return ans;
}
int main()
{
    int n,i,j,k,x,y,ans,curr,temp,m;
    int tc;
    cin >> n;
    string s;
    cin >> s;
    ans = 0;
    for(auto x : s) {
        if(x == '1') ans++;
    }
    mod = ans;
    int atas = 0, bawah = 0;
    for(i=0;i<n;i++) {
        curr = s[i]-'0';
        if(curr) {
            if(mod-1 > 0) {
                bawah += power(2, n-i-1, mod-1);
                bawah %= (mod-1);
            }
            atas += power(2, n-i-1, mod+1);
            atas %= (mod+1);
        }
    }
    for(i=0;i<n;i++) {
        curr = s[i]-'0';
        int chaeng = 1;
        if(curr) {
            if(mod-1 == 0) {
                cout << "0" << endl;
                continue;
            }
            int now = bawah;
            now -= power(2, n-i-1, mod-1);
            while(now < 0) now += (mod-1);
            chaeng += go(now);
        } else {
            int now = atas;
            now += power(2, n-i-1, mod+1);
            now %= (mod+1);
            chaeng += go(now);
        }
        printf("%d\n", chaeng);
    }
    return 0;
}


Measured memory_bytes: 3844
import sys
input = sys.stdin.buffer.readline
N = int(input())
A = [int(input()) for _ in range(N)]
max_A = max(A)
sorted_A = sorted(A, reverse=True)
if sorted_A[1] == max_A:
    for _ in range(N):
        print(max_A)
    exit()

for a in A:
    if a == max_A:
        print(sorted_A[1])
    else:
        print(max_A)


Measured memory_bytes: 14112
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll multbig(ll a,ll b,ll mod){
    if(a==0 or b==0) return 0;
    if(a==1 or b==1) return (a*b)%mod;
    ll cur=multbig(a,b/2,mod);
    cur=(2*cur)%mod;
    if(b%2) cur=(cur+a)%mod;
    return cur;
}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = MOD){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}



void solve(){	
	int a, b;
	cin>>a>>b;
	cout<<max(a+b, max(a*b, a-b));
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    t =1;
//     cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>
#include<chrono>

#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#define int128 __int128
#else
#define int128 long long
#endif

#define all(x) x.begin(), x.end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

ll mod = 1e9 + 7;

namespace {
    ll mul(ll a, ll b) {
        ll val = a * b - (ll)((ld)a * b / mod) * mod;
        if (val < 0) val += mod;
        if (val >= mod) val -= mod;
        return val;
    }
    ll poww(ll a, ll b) {
        ll val = 1;
        a %= mod;
        while (b > 0) {
            if (b % 2) val = mul(a, val);
            a = mul(a, a);
            b >>= 1;
        }
        return val % mod;
    }
    ll inv(ll a) {
        return poww(a, mod - 2);
    }
}

ll const maxn = 3e5 + 5;
ll a[3005][3005];
ll d[3005][3005], used[3005][3005];

vector<ll> dx = { -1,0,1,0 };
vector<ll> dy = { 0, 1, 0, -1 };

ll n, m;

bool good(ll x, ll y) {
    return (x < n and x >= 0 and y < m and y >= 0 and !a[x][y]);
}

signed main() {
    ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
    string  s; cin >> s;
    ll sm = 0;
    for (ll i = 0; i < s.size(); i++) {
        sm += s[i] - '0';
        sm %= 9;
    }
    cout << (sm == 0 ? "Yes\n" : "No\n");

    return 0;
}

/*


*/

/*

*/

Measured memory_bytes: 3632
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(10000000)

N, A, B, C, D = map(int, raw_input().split())

diff = B - A
flag = False

for i in range(N):
    rem = N - i - 1
    if C * i - D * rem <= diff <= D * i - C * rem:
        flag = True

if flag:
    print "YES"
else:
    print "NO"

Measured memory_bytes: 18680
#include <stdio.h>
#include <stdlib.h>
#define MAX 100000
 
int Partition(int [], int, int);
 
int q;
 
int main(void){
 
  int A[MAX+1];
  int i, p, n;
 
  scanf("%d",&n);
 
  for(i=1;i<=n;i++) scanf("%d",&A[i]);
 
  p = 1;
  q = Partition(A,p,n);
 
 
  for(i=1;i< n;i++){
    if(i==q) printf("[%d] ",A[i]);
    else printf("%d ",A[i]);
  }
 
  printf("%d\n",A[i]);
 
  return 0;
}
 
 
int Partition(int A[], int p, int r){
 
  int i, j, x;
  int tmp;
 
  x = A[r];
  i = p - 1;
 
  for(j = p;j<r;j++){
    if(A[j] <= x){
      i = i + 1;
      tmp = A[j];
      A[j] = A[i];
      A[i] = tmp;
    }
  }
   
  tmp = A[i+1];
  A[i+1] = A[r];
  A[r] = tmp;
 
  return i+1;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  int A, B, C; cin >> A >> B >> C;
  string result = (A==B&&B==C) ? "Yes" : "No";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 764
#include <stdio.h>
int main() {
int a, i, j, p = 0, y = 0, g = 0, w = 0;
char s;
scanf("%d", &a);
for (j = 0;j < a;j++) {
scanf("%c", &s);
if (s == ' ') {
    j--;
    continue;
}
if(s == 'Y') {
y = 1;
} else if(s == 'W') {
w = 1;
} else if(s == 'G') {
g = 1;
} else if(s == 'P') {
p = 1;
}
}

if (p + y + g + w == 3) {
printf("Three\n");
} else if(p + y + g + w == 4) {
printf("Four\n");
} return 0;
}

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

using namespace std;

#define sz(v)           ((int)((v).size()))
#define clr(v, d)       memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0; i<sz(v); ++i)
#define lp(i, n)        for(int i=0; i<(int)(n); ++i)
#define lpi(i, j, n)    for(int i=(j); i<(int)(n); ++i)
#define lpd(i, j, n)    for(int i=(j); i>=(int)(n); --i)
#define INF             1000000000


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

const int N = 3e3+5;

double arr[N];
double dp[N][N];

int n;

double solve(int idx, int num_heads)
{
    if(idx == n && num_heads > n/2)
        return 1.00;
    if(idx == n)
        return 0.00;
    double & cur = dp[idx][num_heads];
    if(cur != ((double)2.0))
        return cur;
    cur = (1-arr[idx])*solve(idx+1, num_heads) + arr[idx]*solve(idx+1, num_heads+1);
    return cur;
}

int main()
{
    cin >> n;
    lp(i, n){
        cin >> arr[i];
        lp(j, n)
            dp[i][j] = 2.0;
    }
    cout << setprecision(10);
    cout << solve(0, 0);
    return 0;
}

Measured memory_bytes: 70912
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n,s;
    cin>>n>>s;
    ll w[n],v[n];
    for(ll i=0;i<n;i++){
        cin>>w[i]>>v[i];
    }
    ll dp[n+1][s+1];
    for(ll i=0;i<=n;i++){
        for(ll j=0;j<=s;j++){
            dp[i][j]=0;
        }
    }
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=s;j++){
            if(w[i-1]<=j){
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1]);
            }
            else{
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    cout<<dp[n][s]<<endl;
    return 0;
}


Measured memory_bytes: 79232
<?php
fscanf(STDIN,'%d',$N);
$sum=0;
for ($i=0; $i <$N ; $i++) {
  // code...
  $Money=explode(" ",trim(fgets(STDIN)));
  if($Money[1]=="BTC"){
    $sum+=$Money[0]*380000;
  }else{
    $sum+=$Money[0];
  }
}
echo $sum;
 ?>


Measured memory_bytes: 3576
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        long[] x = new long[n];
        long[] y = new long[n];
        for (int i = 0 ; i < n ; i++) {
            x[i] = sc.nextLong();
            y[i] = sc.nextLong();
        }
        //二辺の組み合わせを総当たり
        long ans = Long.MAX_VALUE;
        for (int hl = 0 ; hl < n ; hl++) {
            for (int hr = hl + 1 ; hr < n ; hr++) {
                for (int wl = 0 ; wl < n ; wl++) {
                    for (int wr = wl + 1 ; wr < n ; wr++) {
                        long l = Math.min(x[wl], x[wr]);
                        long r = Math.max(x[wl], x[wr]);
                        long d = Math.min(y[hl], y[hr]);
                        long u = Math.max(y[hl], y[hr]);
                        int count = 0;
                        for (int i = 0 ; i < n ; i++) {
                            if (x[i] >= l && x[i] <= r && y[i] >= d && y[i] <= u ) {
                                count++;
                            }
                        }
                        if (count == k) ans = Math.min(ans, (r - l) * (u - d) );
                    }
                }
            }
        }

        System.out.println(ans);

    }

}

Measured memory_bytes: 24276
taka_f,taka_p,aoki_f,aoki_p = map(int,input().split())

while True:
    aoki_f -= taka_p
    if  aoki_f < 1:
        print("Yes")
        exit()
    taka_f -= aoki_p
    if taka_f < 1:
        print("No")
        exit()

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  ll n,k;cin>>n>>k;
  ll result= 0;
  while(n){
    result++;
    n/=k;
  }

  cout<<result; 

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	char c;
	cin >> c;
	if (c == 'A')cout << "T" << endl;
	else if (c == 'C')cout << "G" << endl;
	else if (c == 'G')cout << "C" << endl;
	else cout << "A" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
int main(){
    int c[3][3];
    rep(i,3){
        rep(j,3){
            cin>>c[i][j];
        }
    }
    bool ans=false;
    if(c[0][1]-c[0][0]==c[1][1]-c[1][0]&&c[0][1]-c[0][0]==c[2][1]-c[2][0]){
        if(c[0][2]-c[0][1]==c[1][2]-c[1][1]&&c[0][2]-c[0][1]==c[2][2]-c[2][1]){
            if(c[1][0]-c[0][0]==c[1][1]-c[0][1]&&c[1][0]-c[0][0]==c[1][2]-c[0][2]){
                if(c[2][0]-c[1][0]==c[2][1]-c[1][1]&&c[2][0]-c[1][0]==c[2][2]-c[1][2]){
                    ans=true;
                }
            }
        }
    }
    if(ans){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N; cin >> N;
    vector<ll> a(N); rep(i, N){cin >> a.at(i);}

    // 最初を負にする場合と正にする場合で少しだけ違う
    ll ans = INF;
    rep(i, 2){
        ll tmp_ans = 0, tmp = 0;
        rep(j, N){
            if ((j % 2 == 0) ^ (i == 0)){ // 累積和を正にしたい
                tmp += a.at(j);
                if (tmp <= 0){
                    tmp_ans += (1 - tmp);
                    tmp = 1;
                }
            } else {
                tmp += a.at(j);
                if (tmp >= 0){
                    tmp_ans += (tmp - (-1));
                    tmp = -1;
                }
            }
        }
        if (tmp_ans < ans){ans = tmp_ans;}
    }
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

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

    char[] S = scanner.next().toCharArray();
    int N = S.length;
    char[] T = new char[N * 2];
    char[] U = new char[N * 3];
    System.arraycopy(S, 0, T, 0, N);
    System.arraycopy(S, 0, T, N, N);
    System.arraycopy(T, 0, U, 0, T.length);
    System.arraycopy(S, 0, U, T.length, N);

    long K = scanner.nextInt();
    long res1 = count(S);
    long res2 = count(T);
    long res3 = count(U);
    long res = res1 + (K - 1) / 2 * (res3 - res1);
    res += (K - 1) % 2 * (res2 - res1);
    System.out.println(res);
  }

  private static long count(char[] s) {
    long res = 0;
    for (int i = 1; i < s.length; i++) {
      if (s[i] == s[i - 1]) {
        res++;
        i++;
      }
    }
    return res;
  }
}


Measured memory_bytes: 23764
#include<stdio.h>
int main(void){
    int w,h,x,y,r;
    scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
    if((x-r)>=0&&(x+r)<=w&&(y-r)>=0&&(y+r)<=h){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}


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

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

int main() {
    int n;
    cin >> n;
    vector<double> v(n);
    for(int i = 0;i < n;i++) {
        cin >> v.at(i);
    }
    
    for(int i = 0;i < n - 1;i++) {
        sort(v.begin(),v.end());
        v.at(0) = (v.at(0) + v.at(1)) / 2;
        remove(v,1);
    }
    cout << v.at(0) << endl;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<cstring>
#include<sstream>
#include<complex>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < int(Y);++(X))
#define rrep(X,Y) for (int (X) = int(Y-1);(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()

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

vector<pii> edges[1123];
vector<int> c;

int solve(int p,int pp,int costmx){
//  cout<<p<<","<<pp<<","<<costmx<<endl;
  int re=(c[p]>0)*2123456;
  rep(i,edges[p].size()){
    if(edges[p][i].X!=pp)
      re+=solve(edges[p][i].X,p,edges[p][i].Y);
  }
//  cout<<p<<","<<pp<<","<<costmx<<":"<< min(costmx,re)<<endl;
  return min(costmx,re);
}

int main(){
  int i,j,k;
  int n;
  cin>>n;
  c.resize(n,0);
  rep(i,n-1)
    cin>>c[i+1];
  int u,v,p;
  rep(i,n-1){
    cin>>u>>v>>p;
    edges[u].pb(pii(v,p));
    edges[v].pb(pii(u,p));
  }
  cout<<solve(0,-1,2123456)<<endl;
  return 0;
}

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

int main()
{
    char s[100], t[200], p[100], temp[100];

    scanf("%s", &s);
    scanf("%s", &p);

    strcpy(t, s);
    strcat(t, s);

    if(strstr(t, p)==NULL){
        printf("No\n");
    }
    else{
        printf("Yes\n");
    }

    return 0;
}


Measured memory_bytes: 2092
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# input=lambda :sys.stdin.readline().rstrip()
def resolve():
    a,b=map(int,input().split())
    if(a>9 or b>9):
        print(-1)
    else:
        print(a*b)
resolve()

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

int main() {
  int N;
  cin >> N;
  vector<bool> V(N);
  for (int i = 0; i < N; i++) {
    int A, B;
    cin >> A >> B;
    if (A == B) V.at(i) = true;
    else V.at(i) = false;
  }
  string ans = "No";
  for (int i = 0; i < N - 2; i++) {
    if (V.at(i) && V.at(i + 1) && V.at(i + 2)) {
      ans = "Yes";
      break;
    }
  }
  cout << ans << endl;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
	int n; cin >> n;
	vector<int> v(n);
	map<int, int> o, e;
	rep(i, n) {
		int v; cin >> v;
		if (i % 2) e[v]++;
		else o[v]++;
	}

	vector<pair<int, int>> a, b;
	a.push_back(make_pair(0, 0));
	b.push_back(make_pair(0, 0));
	for (auto i : o) a.push_back(make_pair(i.second, i.first));
	for (auto i : e) b.push_back(make_pair(i.second, i.first));

	sort(all(a), greater<pair<int, int>>());
	sort(all(b), greater<pair<int, int>>());

	if (a[0].second == b[0].second)
		cout << min(n - a[0].first - b[1].first, n - a[1].first - b[0].first) << endl;
	else
		cout << n - a[0].first - b[0].first << endl;
}


Measured memory_bytes: 6524
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int x;
    cin>>x;
    if(x<30){
        cout<<"No";
    }else{
        cout<<"Yes";
    }

    return 0;
}


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

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define sz(s) (int)s.size()

int main() {
	int a, b, x;
	cin >> a >> b >> x;
	bool ok = (a <= x && x <= a + b);
	cout << (ok ? "YES\n" : "NO\n");
}

Measured memory_bytes: 256