akhauriyash/Code-Regression huggingface dataset:
//
// Created by Naman Bhalla on 2019-05-26.
//

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <utility>
#include <iostream>
#include <climits>

using namespace std;

int dat[100][2];
long long int dp[101][100005];

int main(){
    memset(dp, 0, sizeof dp);
    memset(dat, 0, sizeof dat);

    int n, w;
    cin >> n >> w;

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

    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= w; ++j){
            if(j < dat[i - 1][0]){
                dp[i][j] = dp[i - 1][j];
            } else {
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - dat[i - 1][0]] + dat[i - 1][1] );
            }

//            cout << dp[i][j] << " ";
        }
//        cout << endl;
    }

    cout << *max_element(dp[n], dp[n] + w + 1) << endl;
    return 0;
}

Measured memory_bytes: 79104
#include <stdio.h>

int main(void) {
	int n;
	int ans;
	int i;
	
	while (scanf("%d", &n) != EOF) {
		ans = 1;
		for (i = n; i > 0; i--) {
			ans += i;
		}
		printf("%d\n", ans);
	}
	return 0;
}

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

const int N=2e5+1e3+7,P=1e9+7,M=1e5+1;

long long n,a[N],pos1,pos2,vis[N],fac[N],inv[N];

long long qpow(long long a,long long b)
{
	long long ret=1;
	while(b)
	{
		if(b&1)
			ret=(ret*a)%P;
		a=(a*a)%P;
		b>>=1;
	}
	return ret;
}

long long c(long long n,long long m)
{
	if(m>n||n<0||m<0)
		return 0ll;
	return fac[n]*inv[m]%P*inv[n-m]%P;
}

void pre()
{
	fac[0]=1; 
	for(long long i=1;i<=M;i++)
		fac[i]=(fac[i-1]*i)%P;
	inv[M]=qpow(fac[M],P-2);
	for(long long i=M-1;i>=0;i--)
		inv[i]=inv[i+1]*(i+1)%P;
}

int main()
{
	cin>>n;
	pre();
	for(long long i=1;i<=n+1;i++)
		cin>>a[i];
	for(long long i=1;i<=n+1;i++)
		if(!vis[a[i]])
			vis[a[i]]=i;
		else
			pos1=vis[a[i]],pos2=i;
	for(long long i=1;i<=n+1;i++)
	{
		long long tmp=c(n+1,i);
		int sum=pos1-1+n+1-pos2;
		tmp=(tmp-c(sum,i-1)+P)%P;
		cout<<tmp<<endl;
	}
} 

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 924844033LL;
template <typename T>
bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for(int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
    for(auto& e : t) {
        fill_v(e, v);
    }
};
int dy[4] = {0, 1, 0, -1};
int dx[4] = {1, 0, -1, 0};
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int c = 0;
    for(int i = 0; i < n; i++) {
        bool f = true;
        for(int j = 0; j < i; j++) {
            if(a[i] < a[j]) {
                f = false;
            }
        }
        if(f) {
            c++;
        }
    }
    cout << c << endl;
}

Measured memory_bytes: 764
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const double pi = acos(-1);

int main() {
    ll x, y;
    cin >> x >> y;

    exrep(i, 0, x) {
        if(y == 2*i + 4*(x - i)) {
            out("Yes");
            re0;
        }
    }

    out("No");
    re0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;

#define rep(i,n)  for(int i = 0; i < (int)(n);    i++)
#define sz(x)     ((int)(x).size())
#define all(x)    (x).begin(),(x).end()

using ll = long long;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int A, B, C; std::cin >> A >> B >> C;
  std::swap(A,B); std::swap(A,C);
  std::cout << A << " " << B << " " << C << std::endl;
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int a[10],fa[10]={1,1,2,6,24,120,720,5040,40320};
int que[363000],quec,dp[362880];

void swap(int i,int j){
  int t;
  t=a[i];
  a[i]=a[j];
  a[j]=t;
}

int ff(){
  int i,ans=0,b=0;
  for(i=8;i>=0;i--){
    ans+=__builtin_popcount(b&((1<<a[i])-1))*fa[8-i];
    b|=1<<a[i];
  }
  return ans;
}

void gg(int n){
  int i,b=0;
  for(i=0;i<9;i++) a[i]=i;
  for(i=0;i<9;i++){
    int x;
    x=n/fa[8-i];
    n%=fa[8-i];
    for(int j=x;j>0;j--)swap(i+j,i+j-1);
  }
}

int que[363000],quec;
void ck(int p,int k){
  int x;
  x=ff();
  if(!dp[x]){
    dp[x]=k+1;
    que[quec++]=x*10+p;
  }
}

int cal(){
  int i,x,p;
  for(i=0;i<quec;i++){
    x=que[i]/10;
    p=que[i]%10;
    if(x==0) return dp[x]-1;
    gg(x);
    if(p<6)swap(p,p+3),ck(p+3,dp[x]),swap(p,p+3);
    if(p>2)swap(p,p-3),ck(p-3,dp[x]),swap(p,p-3);
    if(p%3<2)swap(p,p+1),ck(p+1,dp[x]),swap(p,p+1);
    if(p%3>0)swap(p,p-1),ck(p-1,dp[x]),swap(p,p-1);
  }
  return -1;
}

int main(){
  int p,i,t;
  for(i=0;i<9;i++){
    scanf("%d",&t);
    if(t) a[i]=t-1;
    else{
      a[i]=8;
      p=i;
    }
  }
  ck(p,0);
  printf("%d\n",cal());
}



Measured memory_bytes: 3908
#include <iostream>

using namespace std;

bool s[31];

int main() {
  for (int i = 0; i < 28; i++) {
    int x;
    cin >> x;
    s[x] = true;
  } 
  for (int x = 1; x <= 30; x++)
    if (!s[x])
      cout << x << endl;
  return 0;
}

Measured memory_bytes: 0
S = input()
T = input()

cnt = 10 ** 9
for i in range(len(S) - len(T) + 1):
    tmp = 0
    for j in range(len(T)):
        if i + j < len(S) and S[i + j] == T[j]:
            continue
        else:
            tmp += 1
    cnt = min(cnt, tmp)

print(cnt)

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

const int M=1000000007;

int main(){
    
    string S;cin>>S;
    int N=S.size();
    vector<int> A(N,0),C(N,0),H(N,0);
    vector<long long int> T(N+1);
    if(S[0]=='A') A[0]=1;
    if(S[0]=='C') C[0]=1;
    if(S[0]=='?') H[0]=1;
    for(int i=1;i<N;i++){
        if(S[i]=='A') A[i]=A[i-1]+1;
        else A[i]=A[i-1];
        if(S[i]=='C') C[i]=C[i-1]+1;
        else C[i]=C[i-1];
        if(S[i]=='?') H[i]=H[i-1]+1;
        else H[i]=H[i-1];
    }
    T[0]=0;T[1]=1;
    for(int i=2;i<=N;i++){
        T[i]=(T[i-1]*3)%M;
    }
    long long int ans=0;
    for(int i=1;i<N-1;i++){
        if(S[i]=='B'||S[i]=='?'){
            long long int left=(A[i-1]*T[H[i-1]+1]+H[i-1]*T[H[i-1]])%M;
            long long int right=((C[N-1]-C[i])*T[H[N-1]-H[i]+1]+(H[N-1]-H[i])*T[H[N-1]-H[i]])%M;
            ans+=(left*right)%M;
            ans=ans%M;
        }
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 2432
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        string s = Console.ReadLine();
        if (s.Length % 2 != 2) s = s.Substring(0, s.Length - 1);
        for(int i = 0; i < s.Length; i += 2)
        {
            string front = s.Substring(0, (s.Length - i) / 2);
            string back = s.Substring((s.Length - i) / 2 , (s.Length - i) / 2);
            if (front == back)
            {
                Console.WriteLine(s.Length - i - 1);
                return;
            }
        }
    }
}


Measured memory_bytes: 13140
import itertools

n,m=map(int,input().split())
rin=[[]for _ in range(n)]
for _ in range(m):
  a,b=map(int,input().split())
  rin[a-1].append(b-1)
  rin[b-1].append(a-1)
  
li=[ i for i in range(2,n+1)]

ans=0

for v in itertools.permutations(li):
  pas=0
  ch=0
  st=1
  for x in range(n-1):
    if v[x]-1 not in rin[st-1]:
      ch+=1
      break
    else:
      st=v[x]
  if ch==0:
    ans+=1
    
print(ans)

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

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

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = (int)1e9 + 7;

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

    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];

    sort(all(a), greater<int>());
    int ans1 = a[0], ans2 = a[1];
    FOR(i, 1, n){
        if(abs((ans1 / 2) - ans2) > abs((ans1 / 2) - a[i])) ans2 = a[i];
    }
    cout << ans1 << " " << ans2 << endl;
}

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

int search(int N, vector<int> b)
{
    for (int i = N; i >= 1; i--) {
        if (b[i-1] > i) return -1;
        if (b[i-1] == i) return i;
    }
}

int main()
{
    int N;
    cin >> N;
    vector<int> b(N); 
    for (int i = 0; i < N; i++) cin >> b[i];

    vector<int> ans(N, 0);

    for (int size = N; size >= 1; size--) {
        int pos = search(size, b);
        if (pos == -1) {
            cout << -1 << endl;
            return 0;
        } else {
            ans[size-1] = pos;
            b.erase(b.begin() + pos - 1);
        }
    }

    for (int i = 0; i < N; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    ll n,m;
    cin>>n>>m;
    if(2*n>=m)cout<<m/2<<endl;
    else cout<<n+(m-2*n)/4<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
using namespace std;
int main()
{
	int n, m;
	int k[31], A[31][31];
	int i, j,cnt=0;
	bool isLike[31] = { 0 }, ans[31] = { 0 };
	cin >> n >> m;
	m++;
	for (i = 0; i < n; i++) {
		cin >> k[i];
		for (j = 0; j < k[i]; j++) {
			cin >> A[i][j];
			isLike[A[i][j]] = 1;
		}
		for (j = 0; j < m; j++) {
			if (isLike[j] == 0) {
				ans[j] = 1;
			}
			isLike[j] = 0;
		}

	}
	for (i = 0; i < m; i++) {
		if (ans[i] == 0) {
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

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

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
template<typename T> auto operator<<(ostream& os, const T& t)
    -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }

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

    ll N, A, B;
    std::cin >> N >> A >> B;

    std::vector<ll> H(N + 1, 0);
    REP(i, N) {
        std::cin >> H[i];
    }

    auto simulate = [&](ll val) -> ll {
                        ll cnt = 0;
                        REP(i, N) {
                            ll rem = H[i] - val * B;
                            if(0 < rem) cnt += ceil(rem / double(A - B));
                        }
                        return cnt;
                    };

    ll r_num = 0;
    ll l_num = INF;
    while(r_num < l_num) {
        ll med = (r_num + l_num) / 2;
        if(med < simulate(med)) {
            r_num = med + 1;
        }
        else {
            l_num = med;
        }
    }

    std::cout << r_num << std::endl;

    return 0;
}


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

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

ll a[100] = { 2, 1 };

int main() {
	int n;
	cin >> n;
	for (int i = 2; i <= n; ++i) {
		a[i] = a[i - 1] + a[i - 2];
	}
	cout << a[n] << endl;

	return 0;
}

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

#define int long long 

const int N = 1e5+10;
const int mod = 1e9 + 7;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n+1),b(n);
	for(int i = 0; i < n+1; ++i) cin >> a[i];
	for(int i =0 ; i < n; ++i) cin >> b[i];
	
	int ans = 0;
	for(int i = 0; i < n; ++i)
	{
		if(b[i] >= a[i])
		{
			ans += a[i];
			b[i] -= a[i];
			a[i] = 0;
		}
		else
		{
			ans += b[i];
			a[i] -= b[i];
			b[i] = 0;
		}
		if(b[i] >= a[i+1])
		{
			ans += a[i+1];
			a[i+1] = 0;
		}
		else
		{
			ans += b[i];
			a[i+1] -= b[i];
		}
	}
	cout << ans;
}



Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
typedef long long ll;
int sgn(double x){
    if(fabs(x)<eps){
        return 0;
    }
    if(x<0){
        return -1;
    }else{
        return 1;
    }
}
struct Point{
    double x,y;
    Point(){}
    Point(double _x,double _y){
        x = _x;
        y = _y;
    }
    void input(){
        scanf("%lf%lf",&x,&y);
    }
    Point operator+(const Point &b)const{
        return Point(x+b.x,y+b.y);
    }
    Point operator -(const Point &b)const{
        return Point(x-b.x,y-b.y);
    }
    double operator *(const Point &b)const{
        return x*b.x+y*b.y;
    }
    Point operator *(const double &k)const{
        return Point(x*k,y*k);
    }
    double operator ^(const Point &b)const{
        return x*b.y-y*b.x;
    }
    Point operator /(const double &k)const{
        return Point(x/k,y/k);
    }
    bool operator <(const Point &b)const{
        return sgn(x-b.x)==0?sgn(y-b.y)<0:x<b.x;
    }
    double len2(){
        return x*x+y*y;
    }
};

struct Line{
    Point s,e;
    Line(){}
    Line(Point _s,Point _e){
        s = _s;
        e = _e;
    }
    bool parallel(Line v){
        return sgn((e-s)^(v.e-v.s))==0;
    }
    //没考虑重合
    //0 非垂直相交
    //1 垂直
    //2 平行
    int linecrossline(Line v){
        if((*this).parallel(v)){
            return 2;
        }else{
            if((e-s)*(v.e-v.s) == 0){
                return 1;
            }else{
                return 0;
            }
        }
    }
};

int main(){
    int q;
    Point p0,p1,p2,p3;
    scanf("%d",&q);
    while(q--){
        p0.input();
        p1.input();
        p2.input();
        p3.input();
        Line line1(p0,p1);
        Line line2(p2,p3);
        printf("%d\n",line1.linecrossline(line2));
    }
   
    return 0;
}


Measured memory_bytes: 3244
table = [0, 0, 0, 0, 0, 0, 14, 9, 4, 0, 0, 8, 3, 2, 0, 0, 15, 10, 15, 10,
         6, 12, 7, 9, 11, 6, 23, 18, 13, 8, 3, 23, 18, 13, 8, 3, 34, 29, 24,
         22, 17, 28, 23, 24, 19, 27, 34, 29, 35, 30, 28, 31, 28, 23, 24, 28,
         42, 37, 32, 27, 22, 42, 37, 32, 27, 22, 53, 48, 43, 41, 36, 47, 42,
         43, 38, 46, 64, 59, 54, 49, 44, 61, 56, 51, 46, 44, 72, 67, 62, 57,
         52, 72, 67, 62, 57, 52, 83, 78, 73, 71]
puts $<.readlines.map(&:to_i).map {|i| table[i]}


Measured memory_bytes: 6856
def main():
    N = int(input())
    A = list(map(int, input().split()))

    l, r = 1, 0
    t = A[0]
    n = 1
    while l < N:
        if A[l] & t:
            t ^= A[r]
            r += 1
            continue
        t |= A[l]
        l += 1
        n += l - r
    return n

print(main())


Measured memory_bytes: 24712
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n;
int a[100005];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  REP(i, n) cin >> a[i];

  ll ans;
  ll t = 0, sum = 0, c = 1;
  REP(i, n) {
    sum += a[i];
    if(sum * c <= 0) {
      t += abs(sum) + 1;
      sum = c;
    }

    c *= -1;
  }

  ans = t;
  t = 0, sum = 0, c = -1;
  REP(i, n) {
    sum += a[i];
    if(sum * c <= 0) {
      t += abs(sum) + 1;
      sum = c;
    }

    c *= -1;
  }
  ans = min(ans, t);

  cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << ", "
template <typename T> ostream& operator<<(ostream& _o_, const vector<T>& _v_){ \
 if(!_v_.empty()){_o_<<'[';copy(_v_.begin(),_v_.end(),ostream_iterator<T>(_o_,", "));_o_<<"\b\b]";}return _o_;}
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
typedef unsigned int uint;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef unsigned char uchar;
struct secure_hash {
 static uint64_t splitmix64(uint64_t x) {
  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); } };
template<typename T> using V = vector<T>;
template<typename T, typename U> using umap = unordered_map<T,U,secure_hash>;
template<typename T> using uset = unordered_set<T,secure_hash>;
template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using max_heap = priority_queue<T>;

const int SIZE = 301;
int n;
ld dp[SIZE][SIZE][SIZE];
bool computed[SIZE][SIZE][SIZE];

ld f(int ones, int twos, int threes)
{
    if (ones + twos + threes == 0) return 0;
    ld& ans = dp[ones][twos][threes];
    bool& iscomputed = computed[ones][twos][threes];
    if (iscomputed) return ans;
    ld a = ones > 0 ? (ld)ones/n*f(ones-1,twos,threes) : 0;
    ld b = twos > 0 ? (ld)twos/n*f(ones+1,twos-1,threes) : 0;
    ld c = threes > 0 ? (ld)threes/n*f(ones,twos+1,threes-1) : 0;
    iscomputed = true;
    return ans = (1+a+b+c)/(1-(ld)(n-ones-twos-threes)/n);
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    int cnt[3];
    memset(cnt, 0, sizeof(cnt));
    rep(i,0,n) {
        int x;
        cin >> x;
        if (x > 0) ++cnt[x-1];
    }
    memset(computed, 0, sizeof(computed));
    cout << fixed << setprecision(14) << f(cnt[0], cnt[1], cnt[2]) << endl;
}


Measured memory_bytes: 452992
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class C
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public void Solve()
	{
		int N = GetInt();
		int[] a = GetInts(N);

		int xor = 0;
		for(int i = 0; i < N; i++)
			xor ^= a[i];

		int[] diff = new int[N];
		for(int i = 0; i < N; i++)
			diff[i] = a[i] ^ (a[i] - 1);

		int cnt = 0;
		bool[] used = new bool[N];
		for(int i = 30; i >= 0; i--)
		{
			if(!contains(xor, i))
				continue;

			int mask = (1 << (i + 1)) - 1;
			for(int j = 0; j < N; j++)
			{
				if(used[j] || diff[j] != mask)
					continue;

				xor ^= diff[j];
				used[j] = true;
				break;
			}

			cnt++;			
		}

		Console.WriteLine((xor == 0) ? cnt : -1);
	}

	private bool contains(int s, int x) => ((s >> x) & 1) == 1;
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
	public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}


Measured memory_bytes: 17104
N, M = map(int, input().split())
link = [[] for i in range(N)]
for i in range(M):
    A, B = map(int, input().split())
    link[A-1].append(B-1)
    link[B-1].append(A-1)
visited = [False for i in range(N)]
result = [0] * N
Q = [0]
visited[0] = True
#Qに要素がなくなるまで
while Q:
    #一番上の要素をpop
    v = Q.pop(0)
    for i in link[v]:
        if visited[i] == False:
            visited[i] = True
            result[i] = v
            Q.append(i)
print("Yes")
for i in range(1, N):
    print(result[i] + 1)


Measured memory_bytes: 34460
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)

	n := nextInt()
	r := float64(0)

	for i := 0; i < n; i++ {
		a := nextInt()
		r += float64(1) / float64(a)
	}

	fmt.Println(1.0 / r)
}


Measured memory_bytes: 1804
#include<iostream>
using namespace std;
int main()
{
    int a,b,i;
    cin>>a>>b;
    if((a*b)%2!=0)
        cout<<"Yes"<<endl;
    else if((a*b)%2==0 && (b-a)>1)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    string s; cin >> s;
    bool ans = false;
    rep(i,2) {
        if (s[i]!=s[i+1]) ans = true;
    }
    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env pypy3

import math

def num_cuts(A, ml):
	ret = 0
	for a in A:
		ret += (math.ceil(a / ml) - 1)
	return ret

def ok(A, ml):
	return num_cuts(A, ml) <= K

def ans(A, K):

	low = min(A) / (K+5)
	high = max(A)+1

	assert(not(ok(A, low)))
	assert(ok(A, high))

	while (high - low) > 0.1:
		mid = (low + high) / 2
		if ok(A, mid):
			high = mid
		else:
			low = mid

	low = max(1, math.floor(low) - 5)

	for i in range(100):
		p = low + i/2
		if ok(A, p):
			return math.ceil(p)

	assert(False)


N, K = input().split()
N = int(N)
K = int(K)

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

print(ans(A, K))

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

namespace AtCoder_solve
{
    class Program
    {
        public const ulong mod = 1000000007;

        static void Main(string[] args)

        {
            var n = ulong.Parse(Console.ReadLine());
            var x = 0;
            ulong ans = 0;

            for(ulong i = 1; i <= n; i++)
            {
                if (i % 3 == 0 || i % 5 == 0) x++;
                else ans += i; 
            }

            Console.WriteLine(ans);
                
                





        }

       
        static public long Input()
        {
            return long.Parse(Console.ReadLine());
        }

        static public string[] Input2()
        {
            return Console.ReadLine().Split();
        }

        static public long[] Input3()
        {
            string[] data = Console.ReadLine().Split();
            long[] res = new long[data.LongLength];
            for(long i = 0; i < data.LongLength; i++)
            {
                res[i] = long.Parse(data[i]);
            }
            return res;
        }
        public static long Choose(long n, long a)
        {
            long x = 1;
            long y = 1;
            for (long i = 0; i < a; i++)
            {
                x *= n - i;
                y *= i + 1;
            }
            return x / y;
        }
    }
}


Measured memory_bytes: 27604
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>


using namespace std;
long long cnt;

vector<int> G;
void insertionSort(int a[], int n, int g);
void shellSort(int a[], int n);

int main() {

    int a[1000000];
    int n;

    cin >> n;
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    cnt = 0;

    shellSort(a, n);
    cout << G.size() << endl;
    for (int i = G.size() - 1; i >= 0; i--) {
        printf("%d", G[i]);
        if (i) printf(" ");
    }
    printf("\n");
    printf("%lld\n", cnt);
    for (int i = 0; i < n; i++)
        printf("%d\n", a[i]);

    return 0;
}

void insertionSort(int a[], int n, int g) {
    int i, j;
    for (i = g; i < n; i++) {
        for (j = i - g; j >= 0 && a[j] > a[j + g]; j -= g) {
            swap(a[j], a[j + g]);
            cnt++;
        }
    }
}


void shellSort(int a[], int n) {
    for (int h = 1; ;) {
        if (h > n) break;
        G.push_back(h);
        h = 3*h + 1;
    }

    for (int i = G.size() - 1; i >= 0; i--) {
        insertionSort(a, n, G[i]);
    }
    
}


Measured memory_bytes: 7104
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main{

    private static int[] w;

    public static void main(String[] args){

	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	try{
	    String input = br.readLine();
	    String[] n_k = input.split(" ", 0);
	    int n = Integer.parseInt(n_k[0]);
	    int k = Integer.parseInt(n_k[1]);
	    w = new int[n];
	    for(int i=0;i<n;i++){
		w[i] = Integer.parseInt(br.readLine());
		//System.out.println(w[i]);
	    }
	    	    
	    //System.out.println(k);
	    Allocation(n,k);
	 

	}catch(Exception e){

	}	
	
    }
    public static int Check(int P, int n, int k){
	int c = 0;
	for(int i=0;i<k;i++){
	    int sum = 0;
	    while(sum+w[c]<=P){
		sum += w[c];
		c++;
		if(c==n) return n;
	    }
	}
	return c;
    }
    
    public static void Allocation(int n, int k){
	int left = 0;
	int right = 100000 * 10000;
	int m;

	while(right -left>1){
	    m = (left + right)/2;
	    int c = Check(m,n,k);
	    if(c >= n){
		right = m;
	    }else{
		left = m;
	    }
	}

	System.out.println(right);

    }
}




Measured memory_bytes: 35484
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		String line = in.readLine();
		StringTokenizer tk = new StringTokenizer(line);
		out.println(solve(Integer.parseInt(tk.nextToken()), Integer.parseInt(tk.nextToken())));

		out.close();
		in.close();
	}

	static int solve(int x, int y) {
		if (x == y)
			return 0;
		if (x == -y)
			return 1;
		if (x == 0) {
			if (y < 0)
				return Math.abs(y) + 1;
			else
				return Math.abs(y);
		}
		if (y == 0) {
			if (x < 0)
				return Math.abs(x);
			else
				return Math.abs(x) + 1;
		}
		if (x > 0 && y > 0) {
			if (x > y) {
				return x - y + 2;
			} else {
				return y - x;
			}
		}
		if (x < 0 && y < 0) {
			if (x < y) {
				return Math.abs(x - y);
			} else {
				return Math.abs(x - y) + 2;
			}
		}
		if(x>0 && y<0)
			if(x<Math.abs(y)){
				return Math.abs(x-Math.abs(y))+1;
			}else{
				return Math.abs(x-Math.abs(y))+1;
			}
		if(y>0 && x<0){
			if(Math.abs(x)>y){
				//System.out.println("c");
				return (Math.abs(x)-y)+1;
			}else{
				return (y-Math.abs(x))+1;
			}
		}
		return -17;
	}
}


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

int main(){
  int N,K;
  cin>>N>>K;
  vector<int> l(N);
  for(int i=0;i<N;i++){
    cin>>l.at(i);
  }
  sort(l.begin(),l.end());
  reverse(l.begin(),l.end());
  int ans=0;
  for(int i=0;i<K;i++){
    ans+=l.at(i);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>
 
using namespace std;
template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
 
#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())
#define SRT(v) sort(v.begin(),v.end())
#define MOD 1000000007
 
typedef long long ll;
typedef tuple<int,int,bool> Tb;


int abc104_c(){
    //入力
    int n,a,b;
	cin >> n >> a >> b;
  
    //処理
  
    //出力
    cout << min(n*a,b) << ENT;
    return 0;
}

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


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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int n;
	cin >> n;
	double ans = 0;
	FOR(i,0,n){
		double x;
		string u;
		cin >> x >> u;
		if(u == "JPY"){
			ans += x;
		}else{
			ans += x * 380000;
		}
	}
	printf("%10f", ans);
	return 0;
}


Measured memory_bytes: 256
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


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;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b){
  ll r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return b;
}


ll LCM(ll a,ll b){
  ll c=a,d=b,r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return c/b*d;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

vector<pair<char,ll>> runlength(string s,vector<pair<char,ll>> p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
    return p;
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
  return p;
}


ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}







/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n;
  cin>>n;
  vector<ll> v(n);
  rep(i,n) cin>>v[i];
  sort(ALL(v));
  vector<ll> sum(n,0);
  sum[0]=v[0];
  rep(i,n-1) sum[i+1]=sum[i]+v[i+1];
  ll ans=1,tmp=sum[0];
  rep(i,n-1){
    if(tmp*2>=v[i+1]){
      tmp+=v[i+1];
      ans++;
    }else{
      tmp+=v[i+1];
      ans=1;
    }
  }
  cout<<ans<<endl;
  
}

Measured memory_bytes: 1792
s=input()
budet=0
point=0

for i in s:
  if i == "g":
    if budet==0:
      budet+=1
    else:
      budet-=1
      point+=1
  elif i =="p":
    if budet==0:
      budet+=1
      point-=1
    else:
      budet-=1
print(point)


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

const int MAX_N = 100000;

int n, l;
int a[MAX_N];

int memo[MAX_N];

int Icicle(int i) {
	if (memo[i] > 0)
		return memo[i];

	int res = l - a[i];

	if (i == 0) {
		if (a[i] > a[i + 1])
			return memo[i] = res;
		else
			return memo[i] = res + Icicle(i + 1);
	}

	else if (i == (n - 1)) {
		if (a[i] > a[i - 1])
			return memo[i] = res;
		else
			return memo[i] = res + Icicle(i - 1);
	}

	else {
		if (a[i - 1] < a[i] && a[i + 1] < a[i])
			return memo[i] = res;
		else if (a[i - 1] > a[i] && a[i + 1] < a[i])
			return memo[i] = res + Icicle(i - 1);
		else if (a[i - 1]<a[i] && a[i + 1]>a[i])
			return memo[i] = res + Icicle(i + 1);
		else if (a[i - 1] > a[i] && a[i + 1]>a[i])
			return memo[i] = res + std::max(Icicle(i + 1),  Icicle(i - 1));
	}
}

int main() {
	std::cin >> n >> l;
	for (int i = 0; i < n; ++i)
		std::cin >> a[i];
	int res = 0;
	for (int i = 0; i < n; ++i) {
		res = std::max(res, Icicle(i));
	}
	std::cout << res << std::endl;
	return 0;
}

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

int main()
{
	int n,a,ans=0;
    scanf("%d\n",&n);
    for (int i=1;i<=n;i++)
    {
    	scanf("%d",&a);
    	ans=ans^a;
    }
    if (ans==0) printf("Yes\n");
    else printf("No\n");
    return 0;
 } 


Measured memory_bytes: 256
n = int(input())
a = [[] for i in range(5)]
for i in range(n):
    c = input()
    a[len(c) -1].append(c)
for i in range(5):
    a[i].sort()
b, c, d = 0, 0, 0
for i in range(5):
    if len(a[i]) != 0:
        if b == 0:
            b = len(a[i])
            if b >= 3:
                if b == 3:
                    print(a[i][1] + a[i][0])
                else:
                    print(a[i][0] + a[i][3])
                break
            j = i
        elif c == 0:
            c = len(a[i])
            if b + c >= 3:
                if b == 1:
                    if c == 2:
                        e = [int(a[j][0] + a[i][0]), int(a[j][0] + a[i][1]), int(a[i][0] + a[j][0]), int(a[i][1] + a[j][0])]
                        e.sort()
                        print(e[2])
                    else:
                        e = [int(a[j][0] + a[i][0]), int(a[j][0] + a[i][1]), int(a[j][0] + a[i][2]), int(a[i][0] + a[j][0]), int(a[i][1] + a[j][0]), int(a[i][2] + a[j][0])]
                        e.sort()
                        print(e[2])
                else:
                    print(min(int(a[j][0] + a[i][0]), int(a[i][0] + a[j][0])))
                break
        else:
            print(min(int(a[j][0] + a[i][0]), int(a[i][0] + a[j][0])))
            break



Measured memory_bytes: 5976
import java.util.Scanner;

public class Main {

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

        final int N = sc.nextInt();
        final int M = sc.nextInt();

        final int[][] p = new int[M][2];
        for (int i = 0; i < M; i++) {
            int s = sc.nextInt();
            int c = sc.nextInt();
            p[i][0] = s;
            p[i][1] = c;
        }

        for (int i = 0; i < 1000; i++) {
            String str = String.valueOf(i);
            if (str.length() != N) continue;

            boolean ok = true;
            for (int j = 0; j < M; j++) {
                int k = Character.getNumericValue(str.charAt(p[j][0]-1));
                if (k != p[j][1]) ok = false;
            }

            if (ok) {
                System.out.println(i);
                return;
            }
        }

        System.out.println(-1);
    }
}


Measured memory_bytes: 22228
n, k = map(int, input().split())
p = list(map(int, input().split()))

max_mean = 0
for i in range(k):
    max_mean += 0.5 * (p[i] + 1)

cur = max_mean
for i in range(k, n):
    cur += 0.5 * (p[i] - p[i-k])
    max_mean = max(cur, max_mean)

print(max_mean)


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

int main() {
  ll n, t, ans = 0;
  cin >> n >> t;

  vector<ll> s(n);
  for (int i = 0; i < n; i++) cin >> s[i];

  for (int i = 0; i < n - 1; i++) {
    if (s[i + 1] - s[i] < t)
      ans += s[i + 1] - s[i];
    else
      ans += t;
  }

  cout << ans + t << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
//#pragma GCC optimize(2)

using namespace std;

#define LL long long
#define Re register
#define U unsigned
#define forn(i,a,b) for(int i = a;i <= b;++i)
#define nfor(i,a,b) for(int i = a;i >= b;--i)
#define CLR(i,a) memset(i,a,sizeof(i))
#define BR printf("--------------------\n")
#define pb push_back
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const double PI=atan(1.)*4.;
const int maxn=1e6+5;
const int inf = 0x3f3f3f3f;
const int mod=1e9+7;
const double e=2.71828182845904523536;
int dir[4][2]={1,0,0,1,-1,0,0,-1};

int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
   	cout.tie(0);
    int a,b;
    cin>>a>>b;
    int ans=0;
    bool f=true;
    if(a==b)
    {
        ans=0;

    }
    else
    {
        if((a+b)%2==1)
            f=false;
        ans=(a+b)/2;
    }
    if(f)
        cout<<ans;
    else
        cout<<"IMPOSSIBLE\n";
	return 0;
}


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

public class MainClass
{
	public const long Giri = 1000000007;

	public static void Main(string[] args)
	{
		var n = Console.ReadLine().ToInt();
		var p = Input().ToInt();
		var q = new int[p.Length];
		Array.Copy(p, q, n);
		Array.Sort(q);
		int c = 0;
		for(int i = 0; i < n; i++)
		{
			if(p[i] != q[i])
				c++;
		}
		Console.WriteLine((c == 2 || c== 0)? "YES" : "NO");
		
	}

	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}



Measured memory_bytes: 13140
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

int main() {
  long long a, b, k;
  cin >> a >> b >> k;
  long long x = min(a, k);
  a -= x;
  k -= x;
  x = min(b, k);
  b -= x;
  k -= x;
  cout << a << " " << b << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a;
	int a1;
	cin>>a;
	a1=a.size();
	for(int i=0;i<a1;i++)
	{
		if(a[i]==',')
		cout<<" ";
		else
		cout<<a[i];
	}
	return 0;
}

Measured memory_bytes: 256
#define LOCAL
#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 rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 100001;
static const ll MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool int_ceil(T a, T b) { T res = a / b; if(a % b != 0) res++; return res; }
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define print(...)
#endif

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	string s, ans; cin >> s;

	rep(i, s.size()){
		if(s[i] == 'B'){
			if(!ans.empty()){
				ans.erase(ans.end()-1);
			}
		}
		else{
			ans.push_back(s[i]);
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
long long gcd(long long a, long long b){
  if(b == 0) return a;
  return gcd(b, a%b);
}

int main(void)
{
    ll a,b,c;cin>>a>>b>>c;

    if(a==1 || b==1){
      cout<<"YES"<<endl; return 0;
    }

    if(c%gcd(a, b)==0){
      cout<<"YES"<<endl; return 0;
    }

    cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 256