akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;
int N,M,K;
long long int *orange;
long long int *memo;
long long int answer(int);
int main(){
    cin>>N>>M>>K;
    orange=new long long int [N];
    memo = new long long int [N]{0};
    for(int i=0;i<N;++i){
        cin>>orange[i];
    }
    cout<<answer(0)<<endl;
    return 0;
}

long long int answer(int npoint){
    if(npoint==N)return 0;
    else if(memo[npoint]!=0)return memo[npoint];
    long long int nmin,nmax,na;
    na=answer(npoint+1)+K;
    nmin=orange[npoint];
    nmax=nmin;
    for(int nlong=1;nlong+npoint<N&&nlong<M;++nlong){
        nmin=min(nmin,orange[npoint+nlong]);
        nmax=max(nmax,orange[npoint+nlong]);
        na=min(na,(nmax-nmin)*(nlong+1)+K+answer(nlong+npoint+1));
    }
    memo[npoint]=na;
    return na;
}

Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int A,B;
    cin >> A >> B;
    cout << A*B << "\n";
}

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

int main() {
  int N;
  cin >> N;
  vector<char> color(N);
  for(int i = 0; i < N; i++){ 
    cin >> color.at(i);
    if(color.at(i) == 'Y'){
      cout << "Four" << endl;
      break;
    }else if(i == N - 1 && color.at(i) != 'Y'){
      cout << "Three" << endl;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  string S; cin >> S;
  ll N = sz(S);
  ll ans = 0;
  vector<ll> A(N+1,0);
  rep(i,N) A[i+1] = S[i]-'0';
  vector<ll> dp1(N+1,0);
  vector<ll> dp2(N+1,0);
  dp1[0] = 10-A[0];
  dp2[0] = A[0];
  for(int i=1; i<=N; i++){
    dp1[i] = min(dp1[i-1]+9-A[i],dp2[i-1]+10-A[i]);
    if(A[i]!=9){
      dp2[i] = min(dp1[i-1]+A[i]+1, dp2[i-1]+A[i]);
    }
    else{
      dp2[i] = dp2[i-1]+A[i];
    }
  }
  ans = min(dp1[N]+1, dp2[N]);
  cout << ans << endl;
  return 0;
}


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

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

const int N = 1e5+9;
int cache[N], h[N], n;

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin >> n;
	for(int i = 1; i <= n; i ++) {
		cin >> h[i];
	}
	for(int i = n-1; i > 0; i --) {
		cache[i] = 1e9;
		for(int j = 1; j <= 2 and i+j <= n; j ++) {
			cache[i] = min(cache[i], abs(h[i]-h[i+j])+cache[i+j]);
		}
	}
	cout << cache[1] << endl;

	return 0;
}

Measured memory_bytes: 5200
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
int main()
{
    string s,t;
    cin >> s >> t;
    int ans = t.size();
    for(int i = 0;i < s.size();i++)
    {
        int temp = t.size();
        for(int j = 0;j < t.size();j++)
        {
            if(!(i + j < s.size()))
            {
                cout << ans << "\n";
                return 0;
            }
            if(s[i + j] == t[j])
            {
                temp--;
            }
        }
        ans = min(ans,temp);
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define em3 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
#define X real()
#define Y imag()
#define cross(a, b) ((conj(a) * (b)).Y)
#define dot(a, b) ((conj(a) * (b)).X)
#define EPS 1e-7
long long mod = 1e9 +7;
typedef long long ll;
typedef long double ld;
const double pi = acos(-1);
typedef complex <double> point;
typedef tuple<int, int, int> line;
typedef vector<point> polygon;
int n , m  , ans[1005][1005];
char arr[1005][1005];


int main()
{

    em3
    cin >> n >> m;
    for(int i = 0 ; i < n ; i++)
        for(int j = 0 ; j < m ; j++)
            cin >> arr[i][j];
    ans[0][0] = 1;
    for(int i = 0 ; i < n ; i++)
    {
        for(int j = 0 ; j < m ; j++)
        {
            if(arr[i][j] == '#')
                continue;
            if(i)
                ans[i][j] += ans[i - 1][j];
            if(j)
                ans[i][j] += ans[i][j- 1];
            ans[i][j] %= mod;

        }
    }
    cout << ans[n - 1][m - 1] << endl;
    return 0;
}



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

int main() {
    int M1,D1,M2,D2;
    cin >> M1 >> D1 >> M2 >> D2;

    if(M2!=M1) cout << 1 << endl;
    else cout << 0 << endl;

    return 0;
}


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

int main(){
  int n,arr[102];
  cin >> n;
  arr[n+1];
  int maxi=0,sum=0;
  for(int i=1;i<=n;i++){
    cin >> arr[i];
    if(arr[i]>maxi){
      maxi=arr[i];
    }
   sum+=arr[i];
  }
  sum=sum-maxi;
  if(sum>maxi){
    cout << "Yes" <<endl;
  }
  else
    cout << "No" <<endl;

 return 0;
}


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

ans = sum(B)
for i in range(N):
  if A[i] <= B[i]:
    B[i] -= A[i]
    A[i] = 0
  elif A[i] > B[i]:
    A[i] -= B[i]
    B[i] = 0
  if A[i+1] <= B[i]:
    B[i] -= A[i+1]
    A[i+1] = 0
  elif A[i+1] > B[i]:
    A[i+1] -= B[i]
    B[i] = 0
print(ans - sum(B))

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

#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define low(a,b) lower_bound(all(a),(b))-(a).begin()
#define upp(a,b) upper_bound(all(a),(b))-(a).begin()
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<vint> vvint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;

int N,K;
int a[111];
int dp[100010];
int win[100010];

bool dfs(int now,int turn){
    turn%=2;
    if(dp[now]==1)return true;
    if(dp[now]==-1)return false;
    bool ok=false;
    rep(i,0,N)if(now-a[i]>=0)if(dfs(now-a[i],turn+1))ok=true;
    ok=ok?false:true;
    if(ok)dp[now]=1;
    else dp[now]=-1;
    return ok;
}


signed main() {
    IOS();
    //(1ll<<N)シフト演算のオーバーフローに気をつける
    cin>>N>>K;
    rep(i,0,N)cin>>a[i];
    rep(i,0,a[0])dp[i]=1;
    dfs(K,0);
    if(dp[K]==-1)cout<<"First"<<endl;
    else cout<<"Second"<<endl;
    //rep(i,0,K+1)cout<<i<<" "<<dp[i]<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
    return 0;
}

Measured memory_bytes: 5760
#include "bits/stdc++.h"
using namespace std;
int main(){
    string s, t;
    cin >> s;
    cin >> t;
    if(s.at(0) == t.at(2) && s.at(1) == t.at(1) && s.at(2) == t.at(0))
    cout << "YES" << endl;
    else 
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
/*input
4 5



*/ 
#include <iostream>
#include <bits/stdc++.h>
#include <math.h> 
    
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define gc getchar_unlocked
#define fo(i,n) for(ll i=0;i<n;i++)
#define Fo(i,k,n) for(ll i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define int long long
#define si(x)   scanf("%d",&x)
#define sl(x)   scanf("%lld",&x)
#define ss(s)   scanf("%s",s)
#define pi(x)   printf("%d\n",x)
#define pl(x)   printf("%lld\n",x)
#define ps(s)   printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define ms(a,x) memset(a, x, sizeof(a));
#define endl "\n"
typedef pair<int, int>  pii;
typedef vector<int>     vi;
typedef vector<pii>     vpii;
typedef vector<vi>      vvi;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 1000000001;
const int MAX = 1e5+1;
    



int32_t main() {
    IOS;
	int s,w;
	cin>>s>>w;
	if(w>=s){
		cout<<"unsafe"<<endl;
	}
    else{
    	cout<<"safe"<<endl;
    }

    return 0;
}       



Measured memory_bytes: 3624
n = int(input())
limit = n**0.5
q = 2

if n == 1:
    print(0)
else:
    ans = 0
    while q < limit:
        cnt = 0
        while n % q == 0:
            cnt += 1
            n /= q
        if cnt > 0:
            ans += int((2*cnt + 0.25)**0.5 - 0.5)
            limit = n**0.5
        q += 1
    if n > 1:
        ans += 1
    print(ans)


Measured memory_bytes: 9288
#include<cstdio>
#include<cmath>
#include<iostream>
using namespace std;


struct Point {
    double x, y;
};

double PI = 3.14159265;

void koch(int d, Point a, Point b){
    if(d==0) return;

    Point s, t, u;

    double deg = 60;
    double rad = deg*PI/180.0;

    s.x = (2*a.x + 1*b.x)/3;
    s.y = (2*a.y + 1*b.y)/3;
    t.x = (1*a.x + 2*b.x)/3;
    t.y = (1*a.y + 2*b.y)/3;
    u.x = (t.x-s.x)*cos(rad) - (t.y-s.y)*sin(rad) + s.x;
    u.y = (t.x-s.x)*sin(rad) + (t.y-s.y)*cos(rad) + s.y;

    koch(d-1, a, s);
    printf("%.8f %.8f\n", s.x, s.y);
    koch(d-1, s, u);
    printf("%.8f %.8f\n", u.x,u.y);
    koch(d-1, u, t);
    printf("%.8f %.8f\n", t.x, t.y);
    koch(d-1, t, b);
}

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

    Point p1, p2;
    p1.x = 0;
    p1.y = 0;
    p2.x = 100;
    p2.y = 0;

    printf("%f %f\n", p1.x, p1.y);
    koch(n, p1, p2);
    printf("%f %f\n", p2.x, p2.y);

    return 0;
}


Measured memory_bytes: 3344
n=int(input())
D=[0]*(n+1)
F=[0]*(n+1)
v=[[] for i in range(n+1)]
flg=True
t=1
for i in range(n):
  a=list(map(int,input().split()))
  v[a[0]]=sorted(a[2:])

def dfs(p):
  global t
  if D[p]!=0: return
  D[p]=t
  t+=1
  for i in v[p]:
    if D[i]==0: dfs(i)
  F[p]=t
  t+=1

while flg:
  flg=False
  for i in range(1,n+1):
    if D[i]==0:
      flg=True
      dfs(i)

for i in range(1,n+1):
  print(f'{i} {D[i]} {F[i]}')


Measured memory_bytes: 5640
import numpy as np


def resolve():
    n = int(input())
    p = [int(i) for i in input().split()]
    count = 0
    for i in range(n - 2):
        idx = np.argsort(p[i:i + 3])
        if (idx[1] == 1):
            count += 1
    print(count)
resolve()

Measured memory_bytes: 20676
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
using ll = long long;
int main(){
    int r;
    cin >> r;
    cout << fixed << setprecision(20);
    out(r*2*M_PI);
}

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

main()
{
	int n,a,b;
	scanf("%d %d %d",&n,&a,&b);
	if(abs(a-b)%2==0)
	{
		printf("Alice");
	}
	else
	{
		printf("Borys");
	}
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

int main() {

    ll N,K;
    cin >> N >> K;
    ll A[N];
    rep(i,N) A[i] = 0;
    rep(i,N){
        ll a;
        cin >> a;
        A[a-1]++;
    }
    ll out = 0;
    sort(A,A+N);
    rep(i,K){
        out += A[N-1-i];
    }
    out = N - out;
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#define MOD 2019	//2019 = 3 * 673
using namespace std;

int main(){
	/*input*/
	long long int l, r;	cin >> l >> r; 
	/*calculation*/
	int o = MOD - 1;
	if((r - l) < MOD){
		for(long long int i = l; i < r; i++){
			for(long long int j = i + 1; j <= r; j++){
				int tmp = i*j%MOD;
				if(o > tmp)	o = tmp;
				if(o == 0)	break;
			}
			if(o == 0)	break;
		}
	}else{
		o = 0;
	}
	/*output*/
	cout << o << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		while (sc.hasNext()) {
			int n = sc.nextInt();
			int[] r = new int[n];
			int S = sc.nextInt();

				if (n == 0 && S == 0) {
					break;
				}

				for (int i = 0; i < n; i++) {
					r[i] = sc.nextInt();
				}
			System.out.printf("%d\n", findComb(n ,S ,r));
		}

		sc.close();

	}

	private static int findComb(int n, int S, int[] r) {
		int cnt = 0;

			for (int i = 0; i < r.length - 1; i++) {
				for (int j = i + 1; j < r.length; j++) {
					if (r[i] + r[j] > S) {
						cnt++;
					}
				}
			}
		return cnt;
	}

}


Measured memory_bytes: 68156
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int t[N], x[N], y[N];
    rep(i, N) cin >> t[i] >> x[i] >> y[i];
    rep(i, N) {
        if (!((t[i] % 2) == (x[i] + y[i]) % 2 && x[i] + y[i] <= t[i])){
            cout << "No" << endl;
            return 0;
        } else {
            if (i+1 <= N) {
                t[i+1] = t[i+1] - t[i];
                x[i+1] = abs(x[i+1] - x[i]);
                y[i+1] = abs(y[i+1] - y[i]);
            }
        }
    }
    cout << "Yes" << endl;


    return 0;
}


Measured memory_bytes: 1408
S = input()
k = int(input())


def ans():
    if len(S) == 1:
        return S
    else:
        for i in range(len(S)):
            if i + 1 == k:
                return S[i]
            if S[i] != '1':
                return S[i]

    return 1


print(ans())


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

int main() {
  	int a, b;
  	cin >> a >> b;
  
  	if(a-2*b <0) cout << 0 << endl;
  	else cout << a-2*b << endl;
  	return 0;  
}


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

int main(){
  string S, T;
  cin >> S >> T;
  int ans = 0;
  rep(i, S.size()){
    if (S[i] != T[i]) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3836
fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let s: String = std::io::Read::bytes(stdin.lock())
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    s.parse().ok().expect("error")
}

fn count_divisor(n: &u32) -> usize {
    (1..n + 1).filter(|i| n % i == 0).count()
}

fn main() {
    let n: u32 = input();
    println!(
        "{}",
        (1..n + 1)
            .filter(|i| i % 2 == 1)
            .filter(|i| count_divisor(i) == 8)
            .count()
    );
}

Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
using namespace std;
int a[10]={},b[10]={},c=1,cnt=0,j;

void d( ){
  if(c==10&&b[7]*100+b[8]*10+b[9]==b[4]*100+(b[5]+b[2])*10+b[1]+b[3]+b[6]){
    cnt++;
    return;
  }
  if(b[c]!=0){
    c++;
    d();
    c--;
    return;
  }
  for(int i=1;i<=9;i++){
    if(a[i]==0){
      a[i]++;
      b[c]=i;
      c++;
      d();
      a[i]--;
      c--;
      b[c]=0;
    }
  }
  
}

int main(){
  int n;
  for(int i=1;i<10;i++){
    cin>>n;
    if(n>0){
      a[n]++;
      b[i]=n;
    }
  }
  d();
  cout<<cnt<<endl;
  return 0;
}

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

typedef long long ll;
ll n, m, r, s, ans = 2e9, a[10], d[205][205];
int main()
{
	ll i, j, k, t1,t2, t3;
	cin>> n >> m >> r;
	for (i = 0; i < r; i++) scanf("%lld", &a[i]);
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= n; j++) d[i][j] = 2e9;
		d[i][i] = 0;
	}
	while (m--) {
		scanf ("%lld %lld %lld", &t1, &t2, &t3);
		d[t1][t2] = min(d[t1][t2], t3);
		d[t2][t1] = min(d[t2][t1], t3);
	}
	for (k = 1; k <= n; k++) {
		for (i = 1; i <= n; i++) {
			for (j = 1; j <= n; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
		}
	}
	sort(a, a + r);
	do {
		s =0;
		for (i = 1; i < r; i++) s += d[a[i]][a[i - 1]];
		ans = min(ans, s);
	} while(next_permutation(a, a + r));
	cout << ans;
    return 0;
}


Measured memory_bytes: 512
a,b,c,x,y = map(int,input().split())
d = c * 2 #aピザ1枚とbピザ1枚
if a + b < d:
    print(x * a + y * b)
    exit()
elif x >= y:
    tmp1 = y * d + (x - y) * a
    tmp2 = x * d
    print(min(tmp1, tmp2))
elif y > x:
    tmp1 = x * d + (y - x) * b
    tmp2 = y * d
    print(min(tmp1, tmp2))
    

Measured memory_bytes: 38256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
using namespace std;


int main() {

    string a, b;
    int hit, blow;
    for (;;) {
        set<char> s;
        cin >> a >> b;
        if (a.size() == 1 && b.size() == 1) break;
        hit = blow = 0;
        for (int i = 0; i < 4; i++) s.insert(b[i]);
        for (int i = 0; i < 4; i++) {
            if (a[i] == b[i]) hit++;
            else if (s.find(a[i]) != s.end()) blow++;
        }
        cout << hit << " " << blow << endl;

    }

    return 0;
}



Measured memory_bytes: 3072
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  ll a[N];
  for(int i=0;i<N;++i) cin>>a[i];
  ll ans1=0, ans2=0;
  ll sum = 0;
  for(int i=0;i<N;++i) {
    sum += a[i];
    if(i%2==0) {
      if(sum<=0) {
        ans1 += 1-sum;
        sum = 1;
      }
    }
    else {
      if(sum>=0) {
        ans1 += sum+1;
        sum = -1;
      }
    }
  }
  sum = 0;
  for(int i=0;i<N;++i) {
    sum += a[i];
    if(i%2!=0) {
      if(sum<=0) {
        ans2 += 1-sum;
        sum = 1;
      }
    }
    else {
      if(sum>=0) {
        ans2 += sum+1;
        sum = -1;
      }
    }
  }
  cout<<min(ans1, ans2)<<endl;
}



Measured memory_bytes: 4372
#include <iostream>

using namespace std;

int main(){

    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    int cost = 0;

    int common;
    if( x > y ){
        common = y;
    }else{
        common = x;
    }

    if( a + b < 2 * c){
        cost += ( a + b ) * common;
        x -= common;
        y -= common;
    }else{
        cost += 2 * c * common;
        x -= common;
        y -= common;
    }

    if( x > 0){
        if( a < 2 * c){
            cost += x * a;
        }else{
            cost += x * 2 * c;
        }
    }else{
        if( y > 0){
            if( b < 2 * c){
                cost += y * b;
            }else{
                cost += y * 2 * c;
            }
        }
    }

    cout << cost;

    return 0;
}


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


using namespace std;
int main()
{

   int a, b;
    cin >> a >> b;
    if ((a+b)%2==0) {
        cout << (a+b)/2 << endl;
    }
    else {
        cout << "IMPOSSIBLE" << endl;
    }
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  long long a[3*n];
  for(int i = 0; i < 3*n; i++)cin >> a[i];
  sort(a, a+3*n);
  long long sum=0;
  for(int i = 1; i <= n; i++){
    sum+=a[3*n-i*2];
  }
  cout << sum << endl;
  return 0;
}


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

using namespace std;
int a[110], sum = 0;
int main(){
	int n, m;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d",&a[i]);
		sum += a[i];
	}
	int ans = 0;
	for (int i = 0; i < n; i++){
		ans = ans+(sum-a[i])*a[i];
	}
	ans=ans/2;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
 
typedef long long ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (n); ++i)
const double PI=3.14159265358979323846;
 
using namespace std;
 
int main() {

	int n, q;
	cin >> n >> q;

	vector<int> v[n];

	int a, t, x;

	rep(i, q) {

		cin >> a >> t;

		switch(a) {
			case 0:
				cin >> x;
				v[t].push_back(x);
				break;

			case 1:
				rep(i, v[t].size()) {
					if(i) cout << ' ';
					cout << v[t][i];

				}
				cout << endl;
				break;

			case 2:
				v[t].clear();
				break;
		}
	}
}


Measured memory_bytes: 5876
#include <stdio.h>

int main(void){

  int n,k;
  int di,a,f[100];
  int i=0,j=0;
  int count=0;
  
  if(scanf("%d %d",&n,&k)==1){}
  for(i=0;i<n;i++){
    f[i]=1;
  }

  for(j=0;j<k;j++){
    if(scanf("%d",&di)==1){}
    for(i=0;i<di;i++){
      if(scanf("%d",&a)==1){}
      f[a-1]=0;
    }
  }

  for(i=0;i<n;i++){
    if(f[i]==1){
      count++;
    }
  }
  printf("%d\n",count);
  return 0;
}


Measured memory_bytes: 1736
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define EPS 10e-8
#define MAX_N 200000

using namespace std;
typedef pair<int, int> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

int N, a[MAX_N];

int main(int argc, char **argv) {
    cin >> N;
    for(int i = 0; i < N; ++i)
        cin >> a[i];
    
    llong res = 0;
    int right = 0;
    int a_xor = 0;
    for(int left = 0; left < N; ++left) {

        while(right == left || 
            right < N && (a_xor & a[right]) == 0) {
                a_xor ^= a[right];
                ++right;
        }

        res += right - left;
        a_xor ^= a[left];
    }
    
    cout << res << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n,m;
    cin >> n >> m;
    VVI ks(m);
    VI p(m);
    int k,in;
    REP(i,0,m) {
        cin >> k;
        REP(j,0,k) {
            cin >> in;
            ks[i].push_back(in-1);
        }
    }
    REP(i,0,m) cin >> p[i];
    int ans = 0;
    REP(i,0,1<<n) {
        bool b = true;
        REP(j,0,m) {
            int sum = 0;
            REP(k,0,ks[j].size()) {
                if ((i & (1<<ks[j][k])) != 0) ++sum;
            }
            if (sum % 2 != p[j]) {
                b = false;
                break;
            }
        }
        if (b) ++ans;
    }
    cout << ans << endl;
}

int main() {
    solve();
    
    return 0;
}

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

int main(){
bool flag = false;
int count = 0;
int a , b; cin >> a >> b;
for(int i = a; i <= b; i++){
  if(i == 0){
    flag = true;
  }
  if(i < 0){
    count++;
  }
}
if(flag){
  cout << "Zero" <<endl;
}
else{
  if(count %2 == 1){
    cout << "Negative" << endl;
  }
  else{
    cout << "Positive" << endl;
  }
}
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}

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

    ll N;
    cin >> N;

    ld ans = 0 ;
    rep(i, N){
        ld price;
        string typ;

        cin >> price >> typ;

        if(typ =="JPY") ans += price;
        else ans += price * 380000.0;
    }

    cout << fixed << setprecision(8) << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int s = 0;
  int w = 0;
  int x = 0;
  int y = 0;
  scanf("%d", &s);
  scanf("%d", &w);
  scanf("%d", &x);
  scanf("%d", &y);
  int e = s/y;
  int f = s%y;
  int g = x/w;
  int h = x%y;
  while(1){
  	x = x-w;
  	if(x<=0){
  		printf("Yes");
  		break;
  	}
  	s = s-y;
  	if(s<=0){
  		printf("No");
  		break;
  	}
  }
}

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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  string s;
  ll k;
  cin >> s >> k;
  ll cnt = 0;
  if (s.size() == 1) {
    cout << k / 2 << endl;
    return;
  }
  int diff = false;
  rep(i, s.size() - 1) {
    if (s[i] != s[i + 1]) {
      diff = true;
      break;
    }
  }
  dump(s, diff);
  if (!diff) {
    cnt = s.size();
    cnt *= k;
    cout << cnt / 2 << endl;
    return;
  }
  s += s[0];
  string t = s;
  dump(s);
  int n = s.size();
  int flag = false;
  rep(i, n) {
    if (s[i] == s[i + 1]) {
      if (i == n - 2) flag = true;
      char c = s[i + 1] + 5;
      s[i + 1] = c;
      cnt++;
    }
  }
  ll cnt2 = 0;
  if (t[0] == t[1]) {
    char c = t[0] + 7;
    t[0] = c;
    t[n - 1] = c;
    cnt2++;
  }
  dump(s);
  rep(i, n) {
    if (t[i] == t[i + 1]) {
      char c = t[i + 1] + 9;
      t[i + 1] = c;
      cnt2++;
    }
  }
  ll ans2 = cnt2 * k;
  ll ans = cnt * k;
  if (flag) ans--;
  dump(cnt, ans, flag, cnt2, ans2);
  cout << min(ans, ans2) << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 256
#include<bits//stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1;i <=n;i++)
typedef long long ll;
ll n, w = -1, num, sum; 
int main(void) {
	cin >> n;
	for(int i = 0;i*(i-1)/2 <= n;i++)  {
		if (i * (i - 1) / 2 == n) {
			w = i;
			break;
		}
	}if (w == -1) cout << "No" << endl;
	else {
		cout << "Yes" << endl;
		vector<vector<int>> S(w);
		num = 1;
		rep(i, w) {
			for (int j = i + 1; j < w; j++) {
				S[i].push_back(num);S[j].push_back(num);
				num++;
			}
		}cout << w << endl;
		rep(i, w) {
			cout << S[i].size();
			rep(j, S[i].size()) cout << ' ' << S[i][j];
			cout << endl;
		}
	}
}

Measured memory_bytes: 4188
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
typedef long long LL;
typedef long double Lf;
#define in (void)scanf
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
//#define Rep(i,a,n)for(LL i=(LL)(a);i<(LL)(n);i++)
#define rep(i,n)Rep(i,0,n)
#define Repp(i,l,r,k)for(int i=(int)(l);i<(int)(r);i+=(int)(k))
//#define Repp(i,l,r,k)for(LL i=(LL)(l);i<(LL)(r);i+=(LL)(k))
#define Ma(x,y) ((x)>(y)?(x):(y))
#define mi(x,y) ((x)<(y)?(x):(y))
#define MOD 1000000007//998244353,1000000007,1000000009,4999999999999997
int upi(const void* a, const void* b) { return*(int*)a<*(int*)b ? -1 : *(int*)a> * (int*)b ? 1 : 0; }
int downi(const void* a, const void* b) { return*(int*)a<*(int*)b ? 1 : *(int*)a> * (int*)b ? -1 : 0; }
void sortupi(int* a, int n) { qsort(a, n, sizeof(int), upi); } //1,2,3,4,...
void sortdowni(int* a, int n) { qsort(a, n, sizeof(int), downi); }
int upLL(const void* a, const void* b) { return*(LL*)a<*(LL*)b ? -1 : *(LL*)a> * (LL*)b ? 1 : 0; }
int downLL(const void* a, const void* b) { return*(LL*)a<*(LL*)b ? 1 : *(LL*)a> * (LL*)b ? -1 : 0; }
void sortupLL(LL* a, int n) { qsort(a, n, sizeof(LL), upLL); }
void sortdownLL(LL* a, int n) { qsort(a, n, sizeof(LL), downLL); }
int cmp_char(const void* a, const void* b) { return *(char*)a - *(char*)b; } // a,b,c,d
int cmp_str(const void* a, const void* b) { return strcmp(*(const char**)a, *(const char**)b); } // aaa,aab
LL gcd(LL p, LL q) { while (q) { LL t = p % q; p = q; q = t; }return p; }
LL modpow(LL a,LL n,int m){LL x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define invmodpow(b,p)modpow(b,p-2,p)// a/b≡a*b^{-1}(mod p)...return b^{-1}(mod p)
typedef struct fac { LL n, exp; }F;
LL fact(LL n,F*a){LL x,i,j,c=0;x=n;for(i=2;i*i<=x;i++){for(j=1;x%i==0;j++)x/=i;if(j>1){a[c].n=i;a[c++].exp=j-1;}}if(x-1){a[c].n=x;a[c++].exp=1;}return c;}
//snippet


#define N 200009

void run() {
	int n;
	LL a[N], s[N] = { 0 }, ans = 0;
	in("%d", &n);
	rep(i, n) {
		in("%lld", &a[i]);
		if (!i)s[i] = a[i];
		else s[i] = s[i - 1] + a[i];
		s[i] %= MOD;
	}
	rep(i, n) {
		if (!i)continue;
		ans += a[i] * s[i - 1];
		ans %= MOD;
	}
	printf("%lld\n", ans);
}

int main() {
	int test = 1;
//	in("%d", &test);
	while (test--) {
		run();
	}
}

Measured memory_bytes: 4856
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric> // accumulate
#include <queue>
#include <string>
#include <cmath> // sqrt
#include <map>
using namespace std;
typedef long long ll;

const int INF = 1000000010;
int dp[100010];

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

    for (int i = 0; i < n; i++) {
        dp[i] = INF;
    }

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

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

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int INF = 1 << 30;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100;

vector<pii> G[N];
bool T[N];

int main() {
	int n; cin >> n;
	rep(i, n) { rep(j, n) {
		int a; cin >> a;
		if (a == -1) continue;
		G[i].push_back(pii(a, j));
	} }
	rep(i, n) T[i] = false;

	int ans = 0;
	priority_queue<pii, vector<pii>, greater<pii>> Q;
	Q.push(pii(0, 0));
	while (!Q.empty()) {
		pii p = Q.top(); Q.pop();
		if (T[p.second]) continue;
		ans += p.first;
		T[p.second] = true;
		for (auto i : G[p.second]) Q.push(i);
	}
	cout << ans << endl;
}



Measured memory_bytes: 3232
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

D, G = list(map(int, sys.stdin.readline().split()))
P, C = list(zip(*[map(int, sys.stdin.readline().split()) for _ in range(D)]))

P = np.array(P, dtype=int)
C = np.array(C, dtype=int)
A = np.arange(1, D + 1, dtype=int) * 100  # 1問のスコア
comp_scores = P * A + C

ans = P.sum()
for i in range(D):
    # i: 途中まで解く
    # comp: True ならその問題は全部解く
    for comp in itertools.product([True, False], repeat=D):
        comp = np.array(comp)
        comp[i] = False
        cnt = P[comp].sum()
        score = comp_scores[comp].sum()
        add_cnt = max(0, min(P[i] - 1, math.ceil((G - score) / A[i])))
        add_score = A[i] * add_cnt
        if score + add_score >= G:
            ans = min(ans, cnt + add_cnt)
print(ans)


Measured memory_bytes: 15660
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(void){
    ll h, w;
    cin >> h >> w;
    string s[h];
    for(ll i = 0; i < h; i++)
        cin >> s[i];
    vector<string> g(h+2);
    for(ll i = 0; i < h+2; i++){
        //cout << i << endl;
        g[i].push_back('.');
        for(ll j = 0; j < w; j++){
            //cout << i <<" " << j << endl;
            if(i==0 || i==h+1) g[i].push_back('.');
            else g[i].push_back(s[i-1][j]);
        }
        g[i].push_back('.');
    }
    /*for(ll i = 0; i < h+2; i++){
        for(ll j = 0; j < g[i].size(); j++){
            cout << g[i][j] << " ";
        }
        cout << endl;
    }*/
    bool ok = true;
    for(ll i = 1; i <= h; i++){
        for(ll j = 1; j <= w; j++){
            if(g[i][j]=='.') continue;
            for(ll k = 0; k < 4; k++){
                ll a = i+dx[k], b = j+dy[k];
                if(g[a][b]=='#') break;
                if(k==3) ok = false;
            }
        }
    }
    if(ok==true) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pb push_back
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.x<<','<< P.y<<')';}
template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}


signed main()
{ 
	speed
	int n;cin>>n;
	map<int,map<int,int>> mp;
	for(int i=1;i<=n;++i)
	{
		int en=i%10;
		int beg=to_string(i)[0]-'0';
		mp[beg][en]++;
	}
	int ans=0;
	for(int i=1;i<=n;++i)
	{
		int en=i%10;
		int beg=to_string(i)[0]-'0';
		ans+=mp[en][beg];
	}
	cout<<ans<<"\n";
}

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

int main() {
    int n, d, x, a;
    cin >> n >> d >> x;
    rep(i, n) {
        cin >> a;
        x += 1 + (d - 1) / a;
    }
    cout << x << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int get_int() {
    int n = 0;
    int c = getchar_unlocked();
    if(c == 45) {
        c = getchar_unlocked();
        while(47 < c && c < 58) n = 10 * n + (c & 0xf), c = getchar_unlocked();
        return -n;
    } else if(c < 48 || 57 < c) return c;
    while(47 < c && c < 58) n = 10 * n + (c & 0xf), c = getchar_unlocked();
    return n;
}
void put_int(int n) {
    if(!n) {
        putchar_unlocked('0');
        return;
    }
    if(n < 0) n = -n, putchar_unlocked('-');
    char buf[11];
    int i = 0;
    while(n) buf[i++] = (char)(n % 10 + '0'), n /= 10;
    while(i--)putchar_unlocked(buf[i]);
}
void put_str(char *str) { while(*str) putchar_unlocked(*str++); }

int main(int argc, char **argv) {
    int h = get_int();
    int a[h + 1];
    for(int i = 1; i <= h; ++i) a[i] = get_int();
    for(int i = 1; i <= h; ++i) {
        put_str("node "), put_int(i);
        put_str(": key = "), put_int(a[i]), put_str(", ");
        if(i / 2) put_str("parent key = "), put_int(a[i / 2]), put_str(", ");
        if(i * 2 <= h) put_str("left key = "), put_int(a[i * 2]), put_str(", ");
        if(i * 2 + 1 <= h) put_str("right key = "), put_int(a[i * 2 + 1]), put_str(", ");
        putchar_unlocked('\n');
    }
    return 0;
}



Measured memory_bytes: 2104
#include<stdio.h>
int main(void){
	char s[3][10];
	int i;
	scanf("%s %s %s",s[0],s[1],s[2]);
	for(i=0;i<3;i++){
		putchar((char)((s[i][0]-'a')+'A'));
	}
	puts("");
	return 0;
}

Measured memory_bytes: 128
// ------------------------------------
// Date:2018/ 3/ 1
// Problem:ABC 057 Checkpoints b.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

static const int MOD = 1000000007;

int N, M;

int main()
{
  cin >> N >> M;
  vector< int > a(N);
  vector< int > b(N);
  vector< int > c(M);
  vector< int > d(M);
  REP(i, N) {
    cin >> a[i] >> b[i];
  }
  REP(i, M) {
    cin >> c[i] >> d[i];
  }
  
  int num;
  ll distance, tmp;
  REP(i, N) {
    distance = 1e9;
    REP(j, M) {
      tmp = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      if (tmp < distance) {
        distance = tmp;
        num = j + 1;
      }
    }
    cout << num << endl;
  }
  return 0;
}



Measured memory_bytes: 256
function Main(input){
  var N=parseInt(input.trim());
  var ans=[];
  var n=2;
  while(N>0){
    if(n.isPrime())
      ans[--N]=n;
    n+=5;
  }
  console.log(ans.join(' '));
}

Number.prototype.isPrime=function(){
  var n=this;
  var i=1;
  while(n/i>i)
    if(n%(++i)===0)return false;
  return true;
}

Main(require('fs').readFileSync('/dev/stdin','utf8'));


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

int n, m;
vector<pair<int, int>> edges;
vector<vector<int>> nodes;
int count = 0;

void search(int position, vector<bool> is_visited) {
  is_visited[position] = true;
  //全部訪れていたら終わり
  int is_visited_count = 0;
  for (const auto& b : is_visited)
    if (b) is_visited_count++;
  if(is_visited_count == n) {
    count++;
    return;
  }

  //次のエッジについて探索
  for (const auto& next_position : nodes[position]) {
    if (!is_visited[next_position])
      search(next_position, is_visited);
  }
  return;
}

int main(){
  cin >> n >> m;
  edges.resize(m);
  for (auto& edge : edges) {
    int a, b;
    cin >> a >> b;
    edge.first = a - 1;
    edge.second = b - 1;
  }
  
  //エッジ基準に書き換え
  nodes.resize(n);
  for (auto& edge : edges) {
    nodes[edge.first].push_back(edge.second);
    nodes[edge.second].push_back(edge.first);
  }
  
  //探索
  vector<bool> is_visited(n, false);
  search(0, is_visited);
  cout << count << endl;
  return 0;  
}

Measured memory_bytes: 256
(n, k) = list(map(int, input().split()))
snk = set(range(1, n + 1))
items = []
for i in range(k):
    d = int(input())
    for a in list(map(int, input().split())):
        if a in snk:
            snk.remove(a)
print(len(list(snk)))

Measured memory_bytes: 9120
def resolve():
    import math
    a, b, c, x, y = map(int, input().split())
    ans = a*x + b*y
    #abの枚数だけ考える
    for i in range(1, max(x, y)+1):
        ab = i*2 #abピザを奇数個買うことはない
        total = ab*c + a*max(0, x-i) + b*max(0, y-i) #負の値を採らないようにmaxにしてる
        ans = min(ans, total)
    print(ans)
resolve()

Measured memory_bytes: 9116
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
 ll w,x;
 sc(w);
 ll a[w+1];
 rep(i,0,w)sc(a[i]);
  
 rep(i,0,w){
  if(a[i]!=i+1)continue;
  x=a[i];a[i]=a[i+1];a[i+1]=x;
  ans++;
 }
 pr(ans);
  
return 0;}

Measured memory_bytes: 4316
#include <bits/stdc++.h>
using namespace std;
int main(){
	double a,b,t;
	cin>>a>>b>>t;t=t/180*acos(-1);
	printf("%.10f\n",a*b*sin(t)/2);
	printf("%.10f\n",a+b+sqrt(a*a+b*b-2*a*b*cos(t)));
	printf("%.10f\n",b*sin(t));
	return 0;
}


Measured memory_bytes: 3404
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100005
#define MOD 1000000007
#define INF 1000000009
typedef long long int lli;

typedef struct list {
  int node;
  int dist;
  struct list *next;
} list;

list *graph[MAX];

void initGraph(void) 
{
  for (int i = 0; i < MAX; i++)
    graph[i] = NULL;
}

void addEdge(int node1, int node2, lli dist)
{
  list *new1 = (list *)malloc(sizeof(list *));
  new1->node = node2;
  new1->dist = dist;
  new1->next = graph[node1];
  graph[node1] = new1;

  list *new2 = (list *)malloc(sizeof(list *));
  new2->node = node1;
  new2->dist = dist;
  new2->next = graph[node2];
  graph[node2] = new2;
}

// 頂点k(根)からの距離
lli kyori[MAX];

void dfs(int n, int p) {
  list *c = graph[n];
  for ( ; c != NULL; c = c->next ) {
    int cn = c->node;
    if ( cn == p ) continue;
    kyori[cn] = kyori[n] + c->dist;
    dfs(cn, n);
  }
}

int main(void) {
  int n;
  scanf("%d", &n);
  initGraph();
  int a, b, c;
  rep(i, 0, n-1) {
    scanf("%d %d %d", &a, &b, &c);
    addEdge(a, b, c);
  }
  int q, k;
  scanf("%d %d", &q, &k);
  int x[MAX], y[MAX];
  rep(i, 0, q) scanf("%d %d", &x[i], &y[i]);

  // 頂点kが根
  kyori[k] = 0;
  dfs(k, 0);

  rep(i, 0, q) {
    printf("%lld\n", kyori[x[i]] + kyori[y[i]]);
  }
  return 0;
}


Measured memory_bytes: 14976
#include <algorithm>
#include <cmath>
#include <limits>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

int main() {
  std::string s;

  std::cin >> s;

  for (size_t i = 0; i < s.size() / 2; i++) {
    if (s.at(i) != s.at(s.size() - 1 - i)) {
      std::cout << "No" << std::endl;
      return 0;
    }
  }

  for (size_t i = 0; i < s.size() / 2; i++) {
    if (s.at(i) != s.at((s.size() - 1) / 2 - 1 - i)) {
      std::cout << "No" << std::endl;
      return 0;
    }
  }

  std::cout << "Yes" << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long n,ans;
  ans=0;
  cin>>n;
  vector<long> vec(n);
  vector<long> kosuu(n+1);
  vector<long> sa(n+1);
  for(int i=0; i<n; i++){
    cin>>vec.at(i);
    kosuu.at(i)=0;
    sa.at(i+1)=0;
  }
  for(int i=0; i<n; i++){
    kosuu.at(vec.at(i))=kosuu.at(vec.at(i))+1;
  }
  for(int i=1; i<n+1; i++){
    if(kosuu.at(i)!=0){
      sa.at(i)=kosuu.at(i)*(kosuu.at(i)-1)/2;
      ans=ans+sa.at(i);
      sa.at(i)=sa.at(i)-(kosuu.at(i)-1)*(kosuu.at(i)-2)/2;
    }
  }
  for(int i=0; i<n; i++){
    cout<<ans-sa.at(vec.at(i))<<endl;
  }
}

Measured memory_bytes: 7296
#include <iostream>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

using ll = long long;

int n, a, b;
int x[100000];

int main(){
  cin >> n >> a >> b;
  rep(i, n){
    cin >> x[i];
  }

  ll ans = 0;
  rep(i, n - 1){
    ans += min<ll>(ll(x[i + 1] - x[i]) * a, b);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std; //std::の省略のため
using ll = long long;

int main(){
    int N, Y;
    cin >> N >> Y;

    int x, y, z;
    int ansx=0, ansy=0, ansz=0;

    for(x = 0; x <= N; x++){
        for(y = 0; y <= N-x; y++){
            z = N-x-y;
            if((10000*x + 5000*y + 1000*z) == Y){
                ansx = x;
                ansy = y;
                ansz = z;
                break;
            }
        }
    }

    if(ansx == 0 && ansy == 0 && ansz == 0){
        ansx = -1;
        ansy = -1;
        ansz = -1;
    }

    cout << ansx << " " << ansy << " " << ansz << " " << endl;
}

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  double pi=acos(-1);
  double a,b,h,m;cin>>a>>b>>h>>m;
  double hm=h*60+m;
  double rshort=b;
  double rlong=a;
  double shortx,shorty,longx,longy;
  shortx=rshort*cos(-pi*2/60.0*m);
  shorty=rshort*sin(-pi*2/60.0*m);
  longx=rlong*cos(-pi*2/720.0*hm);
  longy=rlong*sin(-pi*2/720.0*hm);
  double ans=(shortx-longx)*(shortx-longx)+(shorty-longy)*(shorty-longy);
  ans=sqrt(ans);
  cout<<fixed<<setprecision(18)<<ans<<endl;
}


Measured memory_bytes: 4088