akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int s[] = new int[M];
    int c[] = new int[M];
    for(int i=0;i<M;i++){
      s[i]=sc.nextInt();
      c[i]=sc.nextInt();
    }
    int answer = -1;
    if(N==1){
      for(int n=0;n<=9;n++){
        if(isOK(n,s,c,M,N)){
          System.out.println(n);
          return;
        }
      }
    }
    if(N==2){
      for(int n=10;n<=99;n++){
        if(isOK(n,s,c,M,N)){
          System.out.println(n);
          return;
        }
      }
    }
    if(N==3){
      for(int n=100;n<=999;n++){
        if(isOK(n,s,c,M,N)){
          System.out.println(n);
          return;
        }
      }
    }
    System.out.println(answer);
  }
  
  public static boolean isOK(int n,int[] s,int[] c,int M,int keta){
    boolean res = false;
    for(int i=0;i<M;i++){
      if(keta==1){
        if(n==c[i]){
          continue;
        }else{
          return false;
        }
      }else if(keta==2){
        if((s[i]==1&&n/10==c[i])||(s[i]==2&&n%10==c[i])){
          continue;
        }else{
          return false;
        }
      }else{
        if((s[i]==1&&n/100==c[i])||(s[i]==2&&(n/10)%10==c[i])||(s[i]==3&&n%10==c[i])){
          continue;
        }else{
          return false;
        }
      }
    }
    return true;
    
    
  }
  

  
}

Measured memory_bytes: 23124
def main():
    n = int(input())
    a = list(map(int, input().split()))

    mod = 10**9 + 7
    answer = 0
    sum_a = sum(a) % mod

    for i in range(n):
        sum_a = sum_a - a[i]
        answer += a[i] * sum_a
        answer %= mod

    print(answer)


'''
    for i in range(n):
        sum_sub = 0
        for j in range(i+1, n):
            sum_sub += a[j]
            if sum_sub >= mod:
                sum_sub %= mod
        answer += a[i] * sum_sub
        if answer >= mod:
            answer %= mod
    print(answer)
'''

'''
    for i in range(n):
        for j in range(i+1, n):
            answer += a[i] * a[j]
            if answer >= mod:
                answer %= mod
    print(answer)
'''

if __name__ == "__main__":
    main()


Measured memory_bytes: 94012
#include <iostream>
#include <stdio.h>
#include <ctype.h>

using namespace std;

int main() 
{
// your code goes here

int counts[30]={0};

char cs[1201];
while(scanf("%[^\n]\n",cs)!=EOF){
	for(int i=0;cs[i]!='\0';i++){
		if(isalpha(cs[i])){
			counts[tolower(cs[i])-'a']++;
		}
	}
}

for(char c='a';c<='z';c++){
	printf("%c : %d\n",c,counts[c-'a']);
}
return 0;
}


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

using namespace std;

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

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

    long long a, b;
    cin >> a >> b;

    cout << a*b/gcd(a,b);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int mod=1e9+7;
const int INF =LONG_LONG_MAX;
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int pow(int a,int n,int mod){if(n==0)return 1;int p=pow(a,n/2,mod);p=(p%mod*p%mod)%mod;if(n%2) return (p%mod*a%mod)%mod;else return p;}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   int n,w;
   cin>>n>>w;
   int wt[n],val[n];
   for(int i=0;i<n;i++)
    cin>>wt[i]>>val[i];
   int dp[n+1][w+1];

   for(int i=0;i<=n;i++)
   {
       for(int j=0;j<=w;j++)
       {
          if(i==0||j==0)
                {dp[i][j]=0;continue;}
          if(j<wt[i-1])
            dp[i][j]=dp[i-1][j];
          else
            dp[i][j]=max(dp[i-1][j],val[i-1]+dp[i-1][j-wt[i-1]]);
       }
   }
   cout<<dp[n][w]<<endl;
    return 0;
}


Measured memory_bytes: 79232
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-03-17 23:53:12
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod) {
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod) {
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod) {
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

ostringstream oss_global;
string s_global = oss_global.str();

int main()
{
    int n;
    cin >> n;
    vector<double> x(n);
    vector<string> u(n);
    for (int i = 0; i < n; i++)
        cin >> x[i] >> u[i];

    double ans = 0.0;
    for (int i = 0; i < n; i++) {
        if (u[i] == "JPY") {
            ans += x[i];
        } else {
            ans += x[i]*380000;
        }
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

void solve(int test_case) {
	int n,x;
	cin>>n>>x;
	vi arr(n);
	for(int &i:arr)cin>>i;
	ll cnt = 0;
	if(arr[n-1]>x){
		cnt+=arr[n-1]-x;
		arr[n-1]=x;
	}
	for(int i=n-2;i>=0;i--) {
		if(arr[i+1]+arr[i]>x) {
			cnt+=arr[i+1]+arr[i]-x;
			arr[i]=x-arr[i+1];
		}
	}
	cout<<cnt;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("in", "r", stdin);
	//freopen("out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
}	


Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;

int main(){
    int N; cin >> N;
    vector<int> B(N); for(int i = 0; i < N; i++) cin >> B[i];
    vector<int> V;
    for(int j = 0; j < N; j++){
        bool flag = true;
        for(int i = B.size()-1; i >= 0; i--){
            if(B[i] == i+1) {
                flag = false;
                V.push_back(B[i]);
                B.erase(B.begin()+i);
                break;
            }

        }
        if(flag){
            cout << -1 << endl;
            return 0;
        }
    }
    for(int i = N-1; i >= 0; i--) cout << V[i] << endl;

}

Measured memory_bytes: 256
import sys
import heapq

def solve():
    input = sys.stdin.readline
    N, M, V, P = map(int, input().split())
    A = [int(a) for a in input().split()]
    A.sort()

    h, l = N, -1
    b = A[N - P]
    while h - l  > 1:
        m = (h + l) // 2
        NG = A[m] + M
        if NG < b: l = m
        elif m >= N - P: h = m
        else:
            room = (m + P) * M
            for i in range(m + 1, N - P + 1): room += NG - A[i]
            if room < M * V: l = m
            else: h = m

    print(N - l - 1)
    return 0

if __name__ == "__main__":
    solve()


Measured memory_bytes: 14380
import sys
sys.setrecursionlimit(10**7)
def solve():
    N,A,B,C,D=map(int,input().split())
    memo={}
    def rec(x):
        if x in memo:
            return memo[x]
        if x==1:
            return D
        if x==0:
            return 0
        res=D*x
        for y,cost in zip([2,3,5],[A,B,C]):
            res=min(res,rec(x//y)+abs(x-(x//y*y))*D+cost)
            res=min(res,rec((x+y-1)//y)+abs(x-(((x+y-1)//y)*y))*D+cost)
            
        memo[x]=res
        return res
    print(rec(N))

T=int(input())
for i in range(T):
    solve()


Measured memory_bytes: 19984
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;   // INFの値は1152921504606846976

ll dp[100005];

int dx[4] = {-1,0,0,1};
int dy[4] = {0,-1,1,0};
int main()
{
    int h,w;
    cin >> h >> w;
    char s[h][w];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> s[i][j];
        }
    }
    int d[h][w];
    int ans = 0;
    for(int sy = 0; sy < h; sy++){
        for(int sx = 0; sx < w; sx++){
            if(s[sy][sx] == '#') continue;
            for(int gy = 0; gy < h; gy++){
                for(int gx = 0; gx < w; gx++){
                    if(s[gy][gx] == '#') continue;
                    for(int i = 0; i < h; i++){
                        for(int j = 0; j < w; j++){
                            d[i][j] = -1;
                        }
                    }
                    queue<P> que;
                    que.push(make_pair(sx,sy));
                    d[sy][sx] = 0;
                    while(!que.empty()){
                        P tmp = que.front(); que.pop();
                        if(tmp.first == gx && tmp.second == gy){
                            int cnt = d[tmp.second][tmp.first];
                            ans = max(ans,cnt);
                            break;
                        }
                        for(int i = 0; i < 4; i++){
                            int nx = tmp.first + dx[i];
                            int ny = tmp.second + dy[i];
                            if(nx >= 0 && nx < w && ny >= 0 && ny < h && s[ny][nx] == '.' && d[ny][nx] == -1){
                                d[ny][nx] = d[tmp.second][tmp.first] + 1;
                                que.push(make_pair(nx,ny));
                            }
                        }
                    }
                }
            }
        }
    }
    cout << ans << endl;
}   

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;
long long second[16];
int s[15];
void setting(int i,int N){
    int p=N-1;
    while(i>0){
        if(i>=second[p]){
            i-=second[p];
            s[p]=1;
        }
        else{
            s[p]=0;
        }
        p--;
    }
    for(int k=p;k>-1;k--)s[k]=0;

    return ;
}

void prepare(){
second[0]=1;
rep(i,15)second[i+1]=second[i]*2;
return ;
}

int main(){

int N;
cin>>N;

int c[N][N];

rep(i,N)rep(k,N)c[i][k]=-1;
rep(i,N){
    int a;
    cin>>a;
    rep(k,a){
        int x,y;
        cin>>x>>y;
        x--;
        c[i][x]=y;
    }
}
prepare();
int ans=0;

for(long long i=0;i<second[N];i++){
    setting(i,N);
    bool t=true;
    rep(k,N){
        if(!t)break;
        rep(l,N){
        if((c[l][k]==0 && s[k]==1 && s[l]==1)|| (c[l][k]==1 && s[k]==0 && s[l]==1))
            {
            t=false;
            break;
            }
        }
    }

    if(t){
        int cnt=0;
        rep(l,N){
            cnt+=s[l];
        }
        ans=max(ans,cnt);
    }
}

cout<<ans<<endl;





 return 0;
}
/*

3
1
2 1
1
1 1
1
2 0

2

3
2
2 1
3 0
2
3 1
1 0
2
1 1
2 0

0

2
1
2 0
1
1 0

1

/*
int  total=0;
int p[N];
rep(i,N){
    int minus=0;
    int plus=0;
    rep(k,N){
        if(c[k][i]==0)minus++;
        if(c[k][i]==1)plus++;
    }
    if(minus>plus)p[i]=0;
    else p[i]=1;
}
int cnt=0;
rep(i,N){
    ans=0;
    dfs(i,1,N);
    total=max(total,ans);
}

*/

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

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<map>
#include<iomanip>
#include<tuple>
#include<bitset>


using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define printfloat(x) cout << fixed << setprecision(7) << (x) << endl;
#define printbit(x) cout << bitset<15>(x) << endl;
using ll = long long int;



long double pi = 3.14159265359;

string s;
int ans;
int cnt;
int main(){
    cin >> s;
    rep(i,3){
        if(s[i] == 'S'){
            ans = max(ans,cnt);
            cnt =0 ;
        }
        else{
            cnt ++;
        }
        if(i == 2){
            ans = max(ans,cnt);
        }
    }
    cout << ans << endl;


return 0;
}

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

int main(){
  int64_t N,Cbc,Cab,ans=0;
  cin >> N;
  vector<int64_t> A(N);
  vector<int64_t> B(N);
  vector<int64_t> C(N);
  for(int i=0;i<N;i++)
    cin>>A.at(i);

  for(int i=0;i<N;i++)
    cin>>B.at(i);
  
  for(int i=0;i<N;i++)
    cin>>C.at(i);

  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  sort(C.begin(),C.end());

  for(int i=0;i<N;i++){
    
    auto iter = lower_bound(C.begin(), C.end(), B.at(i)+1)-C.begin();
    if(iter == C.size())
      continue;
    else{
      Cbc=C.size()-iter;
      
    }
    
    auto iter2 = lower_bound(A.begin(), A.end(), B.at(i))-A.begin();
    if(iter2==0)
      Cab=0;
    else
      Cab=iter2;
    
    
    ans+=Cab*Cbc;
  
  }
  cout <<ans<<endl;
}


Measured memory_bytes: 2560
N, M = map(int,input().split(' '))
S=[]
for i in range(M):
    tmpk=list(map(int,input().split(' ')))
    S.append(tmpk[1:])
P=list(map(int,input().split(' ')))

Slist=[]
for i in range(pow(2,N)):
    # print(format(i,'0'+str(N)+'b'))
    Slist.append(format(i,'0'+str(N)+'b'))

#print(Slist)
ans = 0
for onoff in Slist:
    cnt=0
    for i in range(len(S)):
        tmp=0
        for chk in S[i]:
            #print(chk)
            if onoff[chk-1]=='1':
                tmp+=1
        if tmp%2 == P[i]:
            cnt+=1
    if cnt == M:
        ans+=1
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define yoi cout<<"yo"<<endl;
#define debug(x) cerr << #x << " is " << x << endl;
#define all(x) x.begin(),x.end()
const lli inf=1e18;
const int mod=1e9+7;
int main(){
IOS;
int n,m,x,y;
cin>>n>>m;
int a[1005],b[1005],i,j;
for(i=0;i<m;i++){
    cin>>a[i]>>x;
    int sum=0;
    for(j=0;j<x;j++){
        cin>>y;
        sum+=(1<<(y-1));
    }
    b[i]=sum;
}
int dp[(1<<n)];
for(i=1;i<(1<<n);i++)
    dp[i]=1e8+5;
dp[0]=0;
for(i=0;i<m;i++){
    for(j=(1<<n)-1;j>=0;j--){
        dp[j|b[i]]=min(dp[j|b[i]],dp[j]+a[i]);
    }
}
if(dp[(1<<n)-1]!=1e8+5)
    cout<<dp[(1<<n)-1]<<endl;
else cout<<-1<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long 
using namespace std;
LL A[5], N;
int main()
{
	for (int i = 1; i <= 4; ++i)
		scanf("%lld", &A[i]);
	scanf("%lld", &N);
	for (int i = 2; i <= 4; ++i)
		A[i] = min(A[i], A[i-1] * 2);
	LL Ans =N / 2 * A[4] + (N & 1) * A[3];
	cout<<Ans<<endl;
	return 0;
}

Measured memory_bytes: 256
SA = list(input())
SB = list(input())
SC = list(input())

S = {
    'a': SA[::-1],
    'b': SB[::-1],
    'c': SC[::-1]
}

t = 'a'
N = len(SA) + len(SB) + len(SC)
for _ in range(N):
    if len(S[t]) == 0:
        break
    else:
        t = S[t].pop()
print(t.upper())

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

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; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl

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

    // input
    for(;;){
        ll N; cin >> N;

        if(N==0){
            return 0;
        } 

        vector<ll> A(N);
        FOR(i, 0, N){
            cin >> A.at(i);
        }

        sort(ALL(A));
        ll sum = 0;
        ll L = A.size();
        FOR(i, 1, L-1){
            sum += A[i];
        }
        ll mean = sum / (N-2);
        p(mean);
    }
    
    return 0;
}


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

const int N = 2e3 + 10;
const int inf = INT_MAX;

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

template<typename T> void read(T &x)
{
    x = 0;int f = 1;
    char c = getchar();
    for(;!isdigit(c);c = getchar()) if(c == '-') f = -1;
    for(;isdigit(c);c = getchar()) x = x * 10 + c - '0';
    x *= f;
}

int ans = 0;
int n,a[N];
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
	read(n);
	FOR(i,1,n)
		read(a[i]);
	sort(a + 1,a + 1 + n);
	FOR(i,1,n)
		FOR(j,i + 1,n)
		{
			int haha = a[i] + a[j];
			int tmp = lower_bound(a + 1,a + 1 + n,haha) - a;
			ans += tmp - j - 1;
		}
	printf("%d",ans);
    return 0;
}




Measured memory_bytes: 256
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
# from fractions import *
# from heapq import*
from bisect import *
from io import BytesIO, IOBase
def vsInput():
    sys.stdin = open('input.txt', 'r')
    sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
ALPHA='abcdefghijklmnopqrstuvwxyz'
M=10**9+7
EPS=1e-6
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]


#-------------------------code---------------------------#
#vsInput()


print(Int()^1)
    




    
    
    



    
        

   



































    

Measured memory_bytes: 9316
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    n,k=map(int,input().split())
    A=sorted(list(map(int,input().split())))
    F=sorted(list(map(int,input().split())),reverse=True)

    # https://qiita.com/drken/items/97e37dd6143e33a64c8c#3-%E3%82%81%E3%81%90%E3%82%8B%E5%BC%8F%E4%BA%8C%E5%88%86%E6%8E%A2%E7%B4%A2%E3%81%AE%E3%81%95%E3%82%89%E3%81%AA%E3%82%8B%E5%88%A9%E7%82%B9
    def is_ok(ind):
        cnt=0
        for i in range(n):
            target=ind//F[i]
            if target<A[i]:
                cnt+=A[i]-target
        if cnt<=k:
            return True
        else: return False

    def bin_search_meguru():
        """
        初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
        まずis_okを定義すべし
        ng, okは,とり得る最小の値-1,とり得る最大の値+1
        """
    
        # 適当にいじる
        ng = -1  # ind=0が条件を満たすこともあるため
        ok = A[-1]*F[0]+1  # ind=len(a)-1が条件を満たさないこともあるため
    
        # いじらない
        # okとngのどちらが大きいかわからないことを考慮
        while (abs(ok - ng) > 1):
            mid = (ok + ng) // 2
            if is_ok(mid):
                ok = mid
            else:
                ng = mid
        return ok
    
    val=bin_search_meguru()
    print(val)



    
    
resolve()

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

signed main(){
  string str;
  cin>>str;
  string ans="Yes";
  if(str=="AAA")ans="No";
  if(str=="BBB")ans="No";
  cout<<ans<<endl;
}

Measured memory_bytes: 384
S=input()
Q=int(input())
head=[]
tail=[]
rev=False
for i in range(Q):
  tmp=list(input().split())
  if tmp[0]=='1':
    if rev==False:
      rev=True
    else:
      rev=False
  if tmp[0]=='2':
    if rev==False:
      if tmp[1]=='1':
        head.append(tmp[2])
      else:
        tail.append(tmp[2])
    if rev==True:
      if tmp[1]=='1':
        tail.append(tmp[2])
      else:
        head.append(tmp[2])
head=''.join(map(str,head))
tail=''.join(map(str,tail))

ans=head[::-1]+S+tail
if rev==True:
  ans=ans[::-1]
print(ans)

Measured memory_bytes: 6272
n, x, mod = [int(i) for i in input().split()]
ans = x
tmp = x
s = set()
s.add(x)
for i in range(1, n):
    tmp = (tmp * tmp) % mod
    if tmp in s:
        cycle = [tmp]
        t = (tmp * tmp) % mod
        while t != tmp:
            cycle.append(t)
            t = (t * t) % mod
        ans += sum(cycle) * ((n - i) // len(cycle))
        ans += sum(cycle[:(n-i)%len(cycle)])
        break
    else:
        s.add(tmp)
        ans += tmp
print(ans)

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

int main(){
    int f,d,n,m,cnt=0;
    cin >> n >> m;
    vector<int> num(n);
    for(int i=0;i<n;i++)
        num.at(i)=i;
    vector<vector<bool>> rt(n,vector<bool>(n,false));
    for(int i=0;i<m;i++){
        cin >> f >> d;
        rt.at(f-1).at(d-1) = rt.at(d-1).at(f-1) = true; 
    }
    do{
        bool pos=true;
        for(int i=0;i+1<n;i++)
            if(!rt.at(num.at(i)).at(num.at(i+1)))
                pos=false;
        if(pos)
            cnt++;
    }while(next_permutation(num.begin()+1,num.end()));
    cout << cnt << endl;
}

Measured memory_bytes: 256
// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
//
// See the bottom of file for solution.
// -----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let T = read!(usize, usize; 3);

    let mut deg = vec![0; 4];
    for (u, v) in T {
        let u = u - 1;
        let v = v - 1;
        deg[u] += 1;
        deg[v] += 1;
    }

    debug!(deg);

    println!(
        "{}",
        if deg.into_iter().filter(|d| d % 2 == 1).count() <= 2 {
            "YES"
        } else {
            "NO"
        }
    )
}


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

int N1, N2;
int f[3003][3003];
char s[3003], t[3003];

int main() {
	cin >> s >> t;
	N1 = strlen(s), N2 = strlen(t);
	for(int i = 1; i <= N1; ++i)
		for(int j = 1; j <= N2; ++j) {
			f[i][j] = max(f[i - 1][j], f[i][j - 1]);
			if(s[i - 1] == t[j - 1])
				f[i][j] = max(f[i][j], f[i - 1][j - 1] + 1);
		}
	string Ans;
	int x = N1, y = N2;
	while(x > 0 && y > 0) {
		if(f[x][y] == f[x - 1][y]) {
			--x;
		} else if(f[x][y] == f[x][y - 1]) {
			--y;
		} else {
			Ans += s[x - 1];
			--x, --y;
		}
	}
	reverse(Ans.begin(), Ans.end());
	cout << Ans << endl;
	return 0;
}

Measured memory_bytes: 35456
object Main {

    def main(args: Array[String]) = {
        val sc = new java.util.Scanner(System.in)
        val w, h, x, y, r = sc.nextInt

        println(if( x-r < 0 || x+r > w || y-r < 0 || y+r > h ) "No" else "Yes")
    }
}



Measured memory_bytes: 44884
using System;
using System.Collections.Generic;
using System.Linq;

class Program {
    
    private static int Main() {
        while( true ) {
            var input = Console.ReadLine();
            var values = input.Split( ' ' );

            int m = int.Parse( values[ 0 ] );
            int f = int.Parse( values[ 1 ] );
            int r = int.Parse( values[ 2 ] );

            if( m == -1 && f == -1 && r == -1 ) { break; }

            char grade = GetGrade( m, f, r );
            Console.WriteLine( grade );
        }

 
        return 0;
    }

    /// <summary>
    /// 評価を取得
    /// </summary>
    /// <param name="m">中間試験の点数</param>
    /// <param name="f">期末試験の点数</param>
    /// <param name="r">再試験の点数</param>
    /// <returns></returns>
    private static char GetGrade( int m, int f, int r ) {
        // 中間試験、期末試験のいずれかを欠席した場合成績は F。
        if( m == -1 || f == -1 ) { return 'F'; }

        int total = m + f;
        if( total >= 80 ) {
            // 中間試験と期末試験の合計点数が 80 以上ならば成績は A 。
            return 'A';
        } else if( total >= 65 ) {
            // 中間試験と期末試験の合計点数が 65 以上 80 未満ならば成績は B。
            return 'B';
        } else if( total >= 50 ) {
            // 中間試験と期末試験の合計点数が 50 以上 65 未満ならば成績は C。
            return 'C';
        } else if( total >= 30 ) {
            // 中間試験と期末試験の合計点数が 30 以上 50 未満ならば成績は D。 ただし、再試験の点数が 50 以上ならば成績は C。
            return ( r >= 50 ) ? 'C' : 'D';
        } else {
            // 中間試験と期末試験の合計点数が 30 未満ならば成績は F。
            return 'F';
        }
    }
}

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

using namespace std;

const long long MOD = 1e9 + 7;
const long long  INF = 5e18;
const double DINF = 5e14;
const double eps = 1e-10;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };

#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

long long dp[1010][3010], n, m, v[3010], h[3010], t[1010], s[1010];
long long ruiv[3010];
	
int main() {
	cin >> n >> m;
	for (int i = 0;i < n;i++) {
		cin >> v[i] >> h[i];
		ruiv[i + 1] = ruiv[i] + v[i];
	}
	for (int i = 0;i < m;i++) {
		cin >> t[i] >> s[i];
	}
	for (int i = 0;i <= m;i++) {
		for (int j = 0;j <= n;j++) {
			dp[i][j] = -INF;
		}
	}
	dp[0][0] = 0;
	for (int i = 0;i < m;i++) {//i番目のイベント
		for (int j = 0;j <= n;j++) {//j個目まで買っている
			if (t[i] < ruiv[j]) {
				dp[i + 1][j] = -INF;
				continue;
			}
			if (j > 0)dp[i + 1][j] = max(dp[i][j - 1] + h[j - 1], dp[i + 1][j]);
			if (j > 1)dp[i + 1][j] = max(dp[i + 1][j - 1] + h[j - 1] + abs(h[j - 1] - h[j - 2]), dp[i + 1][j]);
		}
		for (int j = 0;j <= n;j++) {
			dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
		}
		for (int j = 0;j <= n;j++) {
			if (dp[i + 1][j] < s[i])dp[i + 1][j] = -INF;
		}
	}
	long long ans = -INF;
	for (int i = 0;i <= n;i++) {
		if (dp[m][i] == -INF)continue;
		ans = max(ans, t[m - 1] - ruiv[i]);
	}
	if (ans == -INF)cout << -1 << endl;
	else cout << ans << endl;
	return 0;
}




Measured memory_bytes: 26732
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
 
    int k;
    cin>>k;
    
    int64_t sum=0;
    for(int a=1;a<=k;a++){
        for(int b=1;b<=k;b++){
            for(int c=1;c<=k;c++)
                sum+=gcd(gcd(a,b),c);
        }
    }

    cout<<sum<<endl;

    return 0;
}  

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
#define fi first
#define se second
const int INF = 1e15;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class T>
inline bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>
inline bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    bool frag=false;
    string S; cin >> S;
    int ans=0;
    rep(i,SZ(S)){
        ans+=S[i]-'0';
    }
    cout << max(S[0]-'0'-1+9*(SZ(S)-1),ans) << endl;

}

Measured memory_bytes: 256
// A.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int main()
{
	unsigned long long N;
	cin >> N;

	map<unsigned long long, unsigned long long> am;
	unsigned long long sum = 0u;
	for (unsigned long long i = 0; i < N; ++i)
	{
		unsigned long long a;
		cin >> a;
		if (am.find(a) == am.end())
		{
			am[a] = 1;
		}
		else
		{
			am[a]++;
		}
		sum += a;
	}

	unsigned long long Q;
	cin >> Q;

	vector<unsigned long long> bv;
	vector<unsigned long long> cv;
	for (unsigned long long i = 0; i < Q; ++i)
	{
		unsigned long long b;
		cin >> b;
		bv.emplace_back(b);

		unsigned long long c;
		cin >> c;
		cv.emplace_back(c);
	}

	unsigned long long currentSum = sum;
	for (unsigned long long i = 0; i < Q; ++i)
	{
		if (am.find(bv[i]) != am.end())
		{
			auto changedCount = am[bv[i]];
			if (am.find(cv[i]) == am.end())
			{
				am[cv[i]] = am[bv[i]];
				am.erase(bv[i]);
			}
			else
			{
				am[cv[i]] += am[bv[i]];
				am.erase(bv[i]);
			}
			currentSum += (changedCount * (cv[i] - bv[i]));
		}

		cout << currentSum << endl;
		//for (unsigned long long i = 0; i < N; ++i)
		//{
		//	cout << av[i] << ", ";
		//}
		//cout << endl;
	}
}

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

int main() {
  long long x, y;
  cin >> x >> y;
  
  if(x % y == 0){
    cout << -1 << endl;
    return 0;
  }
  long long k = 1;
  while(1){
    long long ans = k * x;
    if(ans % y == 0){
      k++;
      continue;
    }
    cout << ans << endl;
    return 0;
  }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
const ll mod=1000000007;
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

int main() {
  int n;cin >> n;
  vector<ll> a(n);
  repi(i,0,n)cin >> a[i];
  ll cnt =0LL;
  cnt += a[0]/2LL;
  a[0]= a[0]%2LL;
  repi(i,1,n){
    if(a[i-1]>0 && a[i]>0){
      ++cnt;
      a[i-1] -= 1;
      a[i] -= 1;
    }
    cnt += a[i]/2LL;
    a[i]= a[i]%2LL;
  }
  cout << cnt << endl;
  return 0;
}


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

using namespace std;

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

  if (S.front() != 'A') {
    cout << "WA";
    return 0;
  }

  string cond2_string = S.substr(2, S.size() - 3);
  if (count(cond2_string.begin(), cond2_string.end(), 'C') != 1) {
    cout << "WA";
    return 0;
  }

  for (int i = S.size() - 1, upper_counter = 0; i >= 0; --i) {
    if (S[i] >= 65 and S[i] <= 90) upper_counter++;
    if (upper_counter > 2) {
      cout << "WA";
      return 0;
    }
  }

  cout << "AC";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cmath>

int get_distance(int a,int b,int c,int d){
    return std::abs(a-c)+std::abs(b-d);
}



int main(int argc, char const *argv[]) {
    int N,M;std::cin >> N>>M;
    int a[N],b[N];
    int c[M],d[M];

    for (size_t i = 0; i < N; i++) {
        std::cin >> a[i]>>b[i];
    }
    for (size_t i = 0; i < M; i++) {
        std::cin >> c[i] >> d[i];
    }
    for (size_t i = 0; i < N; i++) {
        int min=std::pow(10,9);
        int min_j;
        for (size_t j = 0; j < M; j++) {
            int dist=get_distance(a[i],b[i],c[j],d[j]);
            if (dist<min) {
                min_j=j;
                min=dist;
            }
        }
        std::cout << min_j+1 << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#define endl "\n";
using namespace std;

const long long INF = 100100100100100100;
const int MOD = 1000000007;
const int inf = 1001001001;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

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

//fac[]はn! inv[]はMODにおける逆元 finv[]はinv[]とfinv[]の累積積
const long long MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int 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;
    }
}

// 二項係数計算(nCkをO(1)で)
long long COM(long long n, long long k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

    COMinit();
    long long N,K;cin >> N >> K;
    vector<long long> retu(N);
    for(int i = 0;i<N;i++){
        cin >> retu.at(i);
    }
    sort(retu.begin(),retu.end());
    long long mini = 0;
    long long maxi = 0;
    //答えはmaxi-mini miniはminの合計,maxiはmaxの合計
    for(long long i = 0;i<N;i++){
        mini += retu.at(i)*COM((N-i-1),K-1);
        mini %= MOD;
        if(mini < 0) mini += MOD;
    }
    for(long long i = 0;i<N;i++){
        maxi += retu.at(i)*COM(i,K-1);
        maxi %= MOD;
        if(maxi < 0) maxi += MOD;
    }
    long long ans = maxi-mini;
    if(ans < 0) ans += MOD;
    cout << ans << endl;
}


Measured memory_bytes: 15848
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1000000000;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
typedef pair<int, int> P;

/** Problem1509 : Rental DVD Shop NEO **/
int main()
{
	int a, b, c, d, e;
	while (cin>>a>>b>>c>>d>>e, a||b||c|d||e) {
		int na, nb, nc; cin>>na>>nb>>nc;
		int ans=0;
		int nd=d;
		
		int tmp = a*na + b*nb + c*nc;
		
		if (d>nc && e*d < nc*c)
			tmp = a*na + b*nb + e*d;
		
		if (nc >= nd) {
			ans = nc*e + b*nb + a*na;
		} else {
			nd -= nc;
			nc = 0;
			
			if (nb >= nd) {
				nb -= nd;
				nd = 0;
				
				ans = d*e + b*nb + a*na;
			} else {
				nd -= nb;
				nb = 0;
				
				if (na >= nd) {
					na -= nd;
					nd = 0;
					
					ans = d*e + a*na;
				} else {
					ans = INF;
				}
			}
		}
		
		cout << min(ans, tmp) << endl;
	}
}

Measured memory_bytes: 1160
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()

scores = {'r':r,'p':p,'s':s}
def calc_score(my_hand, other_hand):
    if my_hand == 'r' and other_hand == 's':
        return r
    elif my_hand == 's' and other_hand == 'p':
        return s
    elif my_hand == 'p' and other_hand == 'r':
        return p
    else:
        return 0

def winnable_hand(other_hand):
    if other_hand == "r":
        return "p"
    elif other_hand == "p":
        return "s"
    else:
        return "r"
def losable_hand(other_hand):
    if other_hand == "r":
        return "s"
    elif other_hand == "p":
        return "r"
    else:
        return "p"

result = 0
for i in range(k):
    target = t[i::k]
    rps = {'r':0,'p':0,'s':0}
    for other_hand in target:
        wh = winnable_hand(other_hand)
        lh = losable_hand(other_hand)
        r_max = max(rps['p'], rps['s'])
        p_max = max(rps['r'], rps['s'])
        s_max = max(rps['p'], rps['r'])
        current_max = {hand: m for hand, m in zip(["r","s","p"], [r_max, s_max, p_max])}
        rps[wh] = current_max[wh] + scores[wh]
        rps[other_hand] = current_max[other_hand]
        rps[lh] = current_max[lh]
    
    result += max(rps.values())

print(result)


Measured memory_bytes: 3316
#include <iostream>
using namespace std;
int main()
{
    int n,m;
    bool flag=true;
    cin>>n>>m;
    char x[n][n],z[m][m];
    for(int i=0; i<n; i++)
        for(int j=0; j<n; j++)
            cin>>x[i][j];
    for(int i=0; i<m; i++)
        for(int j=0; j<m; j++)
        {
            cin>>z[i][j];
        }

    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
        {

                flag=true;
            for(int w=i,k=0; w<m+i; k++,w++)
            {
                for(int q=j,k2=0; q<m+j; k2++,q++)
                {
                    if(x[w][q]!=z[k][k2])
                        flag=false;
                }
            }
            if(flag)
                return cout<<"Yes", 0;
        }
    }
    cout<<"No";
}

Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
using std::vector;
#include<map>
using std::map;

int n,temp;
vector<int> V;
map<int,int> M;

int main(void){
	register int i,ans=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++,M[temp]++){
		scanf("%d",&temp);
		if(!M[temp])
			V.push_back(temp);
	}
	for(i=0;i<V.size();i++)
		if(M[V[i]]>=V[i])
			ans+=M[V[i]]-V[i];
		else
			ans+=M[V[i]];
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 5112
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>

using namespace std;

template<typename T>
T absi(T x) {
    if (x < static_cast<T>(0)) {
        x *= static_cast<T>(-1);
    }
    return x;
}

int main()
{
    int64_t N;
    std::cin >> N;

    std::vector<int64_t> A;

    int64_t prev = 0;
    for (size_t i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        A.push_back(t);
    }

    // 偶数番目を正にする場合
    int64_t sum = 0;
    int64_t count1 = 0;
    for (size_t i = 0; i < N; ++i) {
        sum = sum + A[i];
        if (i % 2 == 0) {
            // 和を正にすべし
            if (sum <= 0) {
                count1 += absi(sum) + 1LL;
                sum = 1;
            }
        }
        else {
            // 負にすべし
            if (sum >= 0) {
                count1 += sum + 1LL;
                sum = -1;
            }
        }
    }

    // 偶数番目を負にする場合
    sum = 0;
    int64_t count2 = 0;
    for (size_t i = 0; i < N; ++i) {
        sum = sum + A[i];
        if (i % 2 != 0) {
            // 和を正にすべし
            if (sum <= 0) {
                count2 += absi(sum) + 1;
                sum = 1;
            }
        }
        else {
            // 負にすべし
            if (sum >= 0) {
                count2 += sum + 1;
                sum = -1;
            }
        }
    }
    std::cout << std::min(count1, count2) << std::endl;

    return 0;
}


Measured memory_bytes: 1400
import java.util.*;

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

        int[] arr = { scanner.nextInt(), scanner.nextInt(), scanner.nextInt() };

        Arrays.sort(arr);

        System.out.printf("%d %d %d\n", arr[0], arr[1], arr[2]);
    }
}


Measured memory_bytes: 26344
// Aizu 2199: Differential Pulse Code Modulation
// 2017.9.21 bal4u@uu
// 2017.12.10

#include <stdio.h>
#include <string.h>

#define INF   0x1fffffff
int code[16];				// code book
int dp[20001][257];			// Sum of Squares

int x2[256][256];
int tbl[256][16];

char buf[15], *p;
int getsint()
{
	int n = 0;
	if (*p == '-') {
		p++; while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
		return -n;
	}
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int main()
{
	int n, m, i, j, k, x, s, t, ans;

	for (i = 0; i < 256; i++) for (j = i+1; j < 256; j++) x2[i][j] = x2[j][i] = (i-j)*(i-j);

	while (fgets(p=buf, 15, stdin) && *p != '0') {
		n = getint(), p++, m = getint();

		for (j = 0; j < m; j++) fgets(p=buf, 10, stdin), code[j] = getsint();
		for (i = 0; i < 256; i++) for (j = 0; j < m; j++) {
			t = i + code[j];
			if (t < 0) t = 0;
			else if (t >= 256) t = 255;
			tbl[i][j] = t;
		}

		memset(dp, 0x33, sizeof(dp));
		dp[0][128] = 0;

		for (k = 0; k < n; k++) {
			fgets(p=buf, 10, stdin), x = getint();
			for (i = 0; i < 256; i++) {
				if (dp[k][i] > INF) continue;
				for (j = 0; j < m; j++) {
					t = tbl[i][j], s = x2[t][x] + dp[k][i];
					if (s < dp[k+1][t]) dp[k+1][t] = s;
				}
			}
		}

		for (ans = INF, i = 0; i < 256; i++) if (dp[n][i] < ans) ans = dp[n][i];
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 22068
#include <bits/stdc++.h>
using namespace std;
#define fastIO                        \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL)
// g++ -std=c++11 -O2 -Wall *.cpp -o *
#define eps 1e-9
#define MAX 10000010
#define MOD 1000000007
#define PI 3.14159265358979323846
#define Fi first
#define Se second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(), a.end()
#define maxof(a) *max_element(all(a))
typedef long long ll;
typedef pair<int, int> pr_int;

int main()
{
	fastIO;
	// freopen("input.txt", "r", stdin);
	// freopen("output.out", "w", stdout);

	int n;

	cin >> n;
	int a[4] = {0};
	while (n--)
	{
		string s;
		cin >> s;
		if (s[0] == 'A')
			a[0]++;
		else if (s[0] == 'W')
			a[1]++;
		else if (s[0] == 'T')
			a[2]++;
		else
			a[3]++;
	}
	cout << "AC x " << a[0] << "\n";
	cout << "WA x " << a[1] << "\n";
	cout << "TLE x " << a[2] << "\n";
	cout << "RE x " << a[3] << "\n";

	cout << "\n";
}


Measured memory_bytes: 3656
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b, c = LI()
    if a <= c <= b:
        print("Yes")
        return
    print("No")
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()


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

using namespace std;

int n, k;
int cnt[200100];

int main() {
    int i;

    scanf("%d%d",&n,&k);
    for (i=0;i<n;i++) {
        int a;
        scanf("%d",&a); cnt[a]++;
    }
    sort(cnt,cnt+n+1,greater<int>());
    int sum = 0;
    for (i=k;i<=n;i++) sum += cnt[i];
    printf("%d\n",sum);

    return 0;
}


Measured memory_bytes: 1024
from sys import stdin, setrecursionlimit

setrecursionlimit(10 ** 9)
INF = 1 << 60


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


X, Y = map(int, input().split())

if (X + Y) % 3:
    print(0)
    exit()

n = (X + Y) // 3
x = (2 * X - Y) // 3
y = (-X + 2 * Y) // 3
if x < 0 or y < 0:
    print(0)
    exit()

MOD = 1000000007
COM_MAX = n

fac, finv, inv = [0] * (COM_MAX + 1), [0] * (COM_MAX + 1), [0] * (COM_MAX + 1)
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1

for i in range(2, COM_MAX + 1):
    fac[i] = fac[i - 1] * i % MOD
    inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD
    finv[i] = finv[i - 1] * inv[i] % MOD


def mod_com(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD


print(mod_com(n, x))


Measured memory_bytes: 82164