akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int max(int a, int b){
    return (a>b?a:b);
}
void lcs(string X, string Y, int n, int m){
    int dp[n+1][m+1];
    for(int i = 0;  i <= n;  i++){
        for(int j = 0;  j <= m;  j++){
            if(i == 0  ||  j == 0)
                dp[i][j] = 0;
            else if(X[i-1] == Y[j-1])
                dp[i][j] = 1+dp[i-1][j-1];
            else
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }
    int size = 1+dp[n][m];
    char str[size];
    str[size-1] = '\0';
    size--;
    int i = n, j = m;
    while(i > 0  &&  j > 0){
        if (X[i-1] == Y[j-1]){ 
            str[size-1] = X[i-1];
            i--; j--; size--;
        } 
        else if (dp[i-1][j] >= dp[i][j-1]) 
            i--; 
        else
            j--; 
    }
    cout << str << endl;
}
int main(){
    string X, Y;
    cin >> X >> Y;
    lcs(X, Y, X.size(), Y.size());
	return 0;
}

Measured memory_bytes: 38788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007

int main(){
    int n, d;
    cin >> n >> d;
    vector<int> x[n];
    for(int i=0; i<n; i++){
        for(int j=0; j<d; j++){
            int a; cin>>a;
            x[i].emplace_back(a);
        }
    }
    int ans = 0;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            int total = 0;
            for(int k=0; k<d; k++){
                int d = abs(x[i][k] - x[j][k]);
                total += d * d;
            }
            bool f = false;
            for(int l=0; l<=total; l++){
                if(l*l == total) f = true;
            }
            if(f) ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
//12:32 start
//12:40 test pass

#include <stdio.h>
//#define DEBUG

int main(void)
{
    FILE *fp;
#ifdef DEBUG
    fp=fopen("input.txt","r");
#else
    fp=stdin;
#endif
    int n_rect=0, n_dia=0;
    while(feof(fp)==0){
        int l1,l2,l3;
        fscanf(fp,"%d,%d,%d\n",&l1,&l2,&l3);
        if(l1*l1+l2*l2==l3*l3 && l1!=l2){
            n_rect++;
        }
        if(l1==l2){
            n_dia++;
        }
    }
    printf("%d\n%d\n",n_rect,n_dia);
    return 0;
}

Measured memory_bytes: 0
//According to all known laws of aviation, there is no way that a bee should be able to fly.
//Its wings are too small to get its fat little body off the ground. The bee, of course, flies anyway.
//Because bees don't care what humans think is impossible.
#include <bits/stdc++.h>
#define FAST_IO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define endl "\n"
using namespace std ;
using bigint = long long int ;
using vi = vector<int> ;
using vll = vector<long long int> ;
bool isPalin( int N ){
    int rev = 0 ;
    int temp = N ;
    while( N > 0 ){
        int d = N % 10 ;
        rev = rev * 10 + d ;
        N /= 10 ;
    }
    return rev == temp ;
}
int main(){
    int A , B ; cin >> A >> B ;
    int ans = 0 ;
    for( int i = A ; i <= B ; i++ ){
        if( isPalin(i) )
            ans++ ;
    }
    cout << ans << endl ;
    return 0 ;
}


Measured memory_bytes: 3628
import copy
D = int(input())
c = list(map(int, input().split()))
s = []
for _ in range(D):
  s.append(list(map(int, input().split())))
t = []
for _ in range(D):
  t.append(int(input()))
u = [] # last(d,i)
x = [0] * 26
u.append(x)
for i in range(D):
  v = copy.deepcopy(u)
  y = v[-1]
  y[t[i]-1] = i+1
  u.append(y)
del u[0]

ans = 0
for i in range(D):
  ans += s[i][t[i]-1]
  for j in range(26):
    ans -= c[j] * ((i+1) - u[i][j]) 
  print(ans)


Measured memory_bytes: 9916
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順

int main()
{
  vector<string> C(2);
  string s;
  cin >> s;
  C.at(0) = s;
  cin >> s;
  C.at(1) = s;
  if (C.at(0).at(0) == C.at(1).at(2)
      && C.at(0).at(1) == C.at(1).at(1)
      && C.at(0).at(2) == C.at(1).at(0)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    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 nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll n; cin >> n; 
  vl array(n);
  
  rep(i,n) cin >> array[i];
  
  vl sum(n+1); sum[n] = array[n-1];
  for(ll i=n-1; i >= 1; i--){
    sum[i] = mod(sum[i+1] + array[i-1]);
  }
  
  ll allsum = 0;
  
  rep(i,n-1){
    allsum += mod(sum[i+2] * array[i]);
    allsum = mod(allsum);
  }
  
  
  cout << allsum << endl;
  
  
}

Measured memory_bytes: 6428
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
	int n,m,a[51],b[51],c[51],d[51],i,j,z;
	long long int x,y;
	scanf("%d%d",&n,&m);
	for(i=0; i<n; i++){
		scanf("%d%d",&a[i],&b[i]);
	}
	for(i=0; i<m; i++){
		scanf("%d%d",&c[i],&d[i]);
	}
	for(i=0; i<n; i++){
		y=10000000000000001;
		for(j=0; j<m; j++){
			x=abs(a[i]-c[j])+abs(b[i]-d[j]);
			if(y>x){
				y=x;
				z=j+1;
			}
		}
		printf("%d\n",z);
	}
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>
int main(){
	int a,b,x;
	scanf("%d%d%d",&a,&b,&x);x=(x+499)/500;
	int k[x+1];k[0]=0,k[1]=fmin(a,b);
	for(int i=2;i<=x;i++){
		k[i]=fmin(k[i-2]+a,k[i-1]+b);
	}
	printf("%d\n",k[x]);
}


Measured memory_bytes: 2140
func main() {
    let N = Int(readLine()!)!
    let S = Array(readLine()!)
    
    var count: [Character: Int] = ["R": 0, "G": 0, "B": 0]
    for c in S {
        count[c]! += 1
    }
    
    var ans = 1
    for c in "RGB" {
        ans *= count[c]!
    }
    
    for i in 1...((N - 1) / 2) {
        var first = 0
        while first + 2 * i < N {
            let mid = first + i
            let last = first + 2 * i
            if S[first] != S[mid] && S[mid] != S[last] && S[first] != S[last] {
                ans -= 1
            }
            first += 1
        }
    }
    
    print(ans)
}

main()


Measured memory_bytes: 8028
n = int(input())-1
result = ''

for i in range(1, 15):
    if n >= 26**i:
        n -= 26**i
        continue
    for j in range(i):
        r = n % 26
        n //= 26
        result += chr(ord('a') + r)
    break
print(result[::-1])

Measured memory_bytes: 9172
n=int(input())
def f(i,x):
    if i%2==0:
        if (2**i+2)//3<=x<=(2**(i+2)-1)//3:
            return True
        else:
            return False
    else:
        if -(2**(i+1)-1)*2//3<=x<=-(2**i+1)//3:
            return True
        else:
            return False
if n==0:
    print('0')
else:
    ans=''
    order=0
    mark=f(order,n)
    while not mark:
        order=order+1
        mark=f(order,n)
    while order>=0:
        if f(order,n):
            ans=ans+'1'
            n=n-(-2)**order
        else:
            ans=ans+'0'
        order=order-1
    print(ans)
        
        
        
    



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

int main(){
    int n,l;
    cin >> n >> l;
    int def = l*n + n*(n+1)/2 -n;
    if(l+n-1<0){
        cout << (def-(l+n-1));
    }else if(l>0){
        cout << (def-l);
    }else{
        cout << def;
    }
    return 0;
}

Measured memory_bytes: 256
/*    ####################  */
/*   # I_LOVE_THUY_LINH #  */
/*  ####################  */
#include <bits/stdc++.h>
#define ll long long
#define db double
#define ld long double
#define ii pair<int,int>
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vii vector<ii>
#define matrix vector<vector<ll>>
#define fir first
#define sec second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define sz(a) int((a).size())
#define ms(s,val) memset(s,val,sizeof(s))
#define bitcount(n) __builtin_popcountll(n)
#define getbit(s,k) ((s >> k)&1)
#define turnbit(s,k) (s | (1<<k))
#define offbit(s,k) (s & ~(1<<k))
#define flipbit(s,k) (s ^ (1<<k))
#define prec(n) fixed<<setprecision(n)
#define sqr(x) (ll)(x)*(ll)(x)
#define lcm(a,b) ((ll)a/__gcd((ll)a,(ll)b)*(ll)(b))
#define gcd(a,b) __gcd(a,b)
using namespace std;
const ll INF = (ll)(1e18);
int n;
ll K;
vector<ll> pos, neg;
ll numzero = 0;

ll Round(ll x,ll y){
    if (x > 0) return (x - 1LL)/y;
    x = -x;
    x++;
    return (x/y) + (x % y != 0);
    
}


ll f(ll x){
    //f(x) count number < x
    ll ans = 0;
    if (x == 0){
        ans = (ll)(pos.size())*(ll)(neg.size());
        return ans;
    }

    if (x > 0){
        ans = (ll)(pos.size() + neg.size())*(ll)numzero + numzero*(numzero - 1)/2 + (ll)(pos.size())*(ll)(neg.size());
        for (int i = 0; i < pos.size(); i++){
            ll q = Round(x,pos[i]);
            int cntpair = upper_bound(pos.begin() + i + 1,pos.end(),q)- (pos.begin() + i + 1);
            ans += (ll)cntpair;
        }

        for (int i = 0; i < neg.size(); i++){
            ll q = Round(x,neg[i]);
            int cntpair = upper_bound(neg.begin() + i + 1,neg.end(),q) - (neg.begin() + i + 1);
            ans += (ll)cntpair;
        }
        return ans;
    }
    // if x < 0
    for (int i = 0; i < pos.size(); i++){
        ll q = Round(x,pos[i]);
        int cntpair = neg.end() - lower_bound(all(neg),q);
        ans += (ll)cntpair;
    }
    return ans;


}


int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> K;
    for (int i = 0; i < n; i++){
        ll x;
        cin >> x;
        if (x > 0) pos.eb(x);
        if (x == 0) numzero++;
        if (x < 0) neg.eb(-x);
    }

    sort(all(pos));
    sort(all(neg));

    ll lef  = -INF, rig = INF;
    ll ans = -INF;
    while (lef <= rig){
        ll mid = (lef + rig) >> 1;
        ll cnt = f(mid);
        if (cnt < K){ // cnt < K
            ans = mid;
            lef = mid + 1;
        }
        else rig = mid - 1;
    }

    cout << ans << '\n';
    //for (int i = -20; i <= 25; i++) cout << f(i) << ' ';
    return 0;
}

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

long long MOD = 1e9 + 7;
long long p(long long n) {
  if (n == 0) {
    return 1;
  }
  if (n == 1) {
    return 2;
  }
  long long tmp = p(n / 2);
  long long tmp2 = tmp * tmp;
  tmp2 %= MOD;
  if (n % 2 == 0) {
    return tmp2;
  } else {
    return (tmp2 * 2) % MOD;
  }
}
long long gcd(long long a, long long b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
int main() {
  int n;
  cin>>n;
  map<pair<long long, long long>, int> m;
  int cnt_a0_b0 = 0;
  int cnt_a0 = 0;
  int cnt_b0 = 0;
  for (int i=0; i<n; i++) {
    long long a, b;
    cin>>a>>b;
    if (a == 0 && b == 0) {
      ++cnt_a0_b0;
      continue;
    }
    // b != 0
    if (a == 0) {
      ++cnt_a0;
      continue;
    }
    // a != 0
    if (b == 0) {
      ++cnt_b0;
      continue;
    }
    long long g = gcd(abs(a), abs(b));
    long long c = abs(a) / g;
    long long d = abs(b) / g;
    if (a < 0 && b > 0) {
      ++m[make_pair(-c, d)];
    } else if (a > 0 && b < 0) {
      ++m[make_pair(-c, d)];
    } else {
      ++m[make_pair(c, d)];
    }
  }
  long long ans = cnt_a0_b0;
  vector<pair<int,int>> s;
  for (auto e: m) {
    auto p = e.first;
    int c = e.second;
    long long a = p.first;
    long long b = p.second;
    if (a < 0) {
      if (m.find(make_pair(b, -a)) != m.end()) {
        s.push_back(make_pair(c, m[make_pair(b, -a)]));
      } else {
        s.push_back(make_pair(c, -1));
      }
    } else {
      if (m.find(make_pair(-b, a)) != m.end()) {
      } else {
        s.push_back(make_pair(c, -1));
      }
    }
  }
  if (cnt_a0 + cnt_b0 > 0) {
    if (cnt_a0 == 0 || cnt_b0 == 0) {
      s.push_back(make_pair(cnt_a0 + cnt_b0, -1));
    } else {
      s.push_back(make_pair(cnt_a0, cnt_b0));
    }
  }
  long long tmp = 1;
  for (auto e: s) {
    long long a = e.first;
    long long b = e.second;
    long long tmp2 = p(a);
    if (b > -1) {
      tmp2 += p(b) - 1;
      tmp2 %= MOD;
    }
    tmp *= tmp2;
    tmp %= MOD;
  }
  ans += tmp - 1;
  if (ans < 0) {
    ans += MOD;
  }
  cout<<ans%MOD<<endl;
}

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

using namespace std;

int main(){
  int y;
  cin >>y;
  int a = y/100;
  int b = y%100;
  if(a>0 && a<13 && b>0 && b<13)cout << "AMBIGUOUS";
  if(a>0 && a<13 && (b==0 || b>12))cout << "MMYY";
  if((a==0 || a>12) && b>0 && b<13)cout << "YYMM";
  if((a==0 || a>12) && (b==0 || b>12))cout << "NA";
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <functional>
#include <initializer_list>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  LL n, x;
  cin >> n >> x;
  VEC<LL> a(n);
  REP(i, 0, n) cin >> a[i];
  sort(ALL(a));
  int cnt = 0;
  int i = 0;
  while (x > 0&&i<n-1) {
    if (x >= a[i]) {
      x -= a[i];
      cnt++;
    } else
      break;
    i++;
  }
  if(x==a[n-1])
    cnt++;
  //DUMP(x, i, cnt);
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <memory.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    int N, W;
    cin >> N >> W;
    vector<int> v(N), w(N);
    for (int n = 0; n < N; ++n) {
        cin >> v[n] >> w[n];
    }
    
    int DP[101][10001];
    memset(DP, 0, sizeof(DP));
    for (int n = 1; n <= N; ++n) {
        for (int wt = 0; wt <= W; ++wt) {
            DP[n][wt] = DP[n-1][wt];
            if (wt >= w[n-1]) {
                DP[n][wt] = max(DP[n][wt], DP[n-1][wt-w[n-1]] + v[n-1]);
                DP[n][wt] = max(DP[n][wt], DP[n][wt-w[n-1]] + v[n-1]);
            }
        }
    }
    cout << DP[N][W] << endl;

    return 0;
}



Measured memory_bytes: 7052
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(50) << setiosflags(ios::fixed);
  int n, q;
  cin >> n >> q;
  stack<int> stk[1000];
  rep(qi, q)
  {
    int type;
    cin >> type;
    if (type == 0)
    {
      int t, x;
      cin >> t >> x;
      stk[t].push(x);
    }
    else if (type == 1)
    {
      int t;
      cin >> t;
      if (!stk[t].empty())
        cout << stk[t].top() << endl;
    }
    else
    {
      int t;
      cin >> t;
      if (!stk[t].empty())
        stk[t].pop();
    }
  }

  return 0;
}



Measured memory_bytes: 4280
/// You just can't beat the person who never gives up
/// ICPC next year

//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<bits/stdc++.h>
using namespace std ;
const int N = 1e5+5 ,mod = 1e9+7 ;

int n ,k ,cnt[N] ,ans ;
int pwr(int b,int p){
    int res=1;
    while(p){
        if(p%2) res = 1ll*res*b%mod;
        b = 1ll*b*b%mod;
        p/=2;
    }
    return res;
}
bool Never_give_up(){
    cin >> n >> k ;
    for(int i=k;i>=1;--i){
        cnt[i] = pwr(k/i,n) ;
        for(int j=i+i;j<=k;j+=i) cnt[i] = ((cnt[i] - cnt[j])%mod + mod)%mod ;
        ans = (0ll + ans + 1ll * cnt[i]*i%mod) %mod ;
    }
    cout << ans ;
    return 0;
}
int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt" ,"r" ,stdin);
    freopen("output.txt" ,"w" ,stdout);
#endif
    std::ios::sync_with_stdio(0);
    cin.tie(0) ,cout.tie(0);
    int t = 1 ;
    //cin >> t ;
    while(t--){
        Never_give_up();
    }
    return 0;
}

Measured memory_bytes: 3964
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n;i++)
        cin >> a[i];
    int res1 = 0, res2 = 0;
    int sum1 = 0, sum2 = 0;
    for (int i = 0; i < n; i++){
        sum1 += a[i];
        sum2 += a[i];
        if(i%2==0){
            if(sum1<=0){
                res1 += abs(sum1) + 1;
                sum1 = 1;
            }
            if(sum2>=0){
                res2 += abs(sum2) + 1;
                sum2 = -1;
            }
        }else{
            if(sum1>=0){
                res1 += abs(sum1) + 1;
                sum1 = -1;
            }
            if(sum2<=0){
                res2 += abs(sum2) + 1;
                sum2 = 1;
            }
        }
    }
    cout << min(res1, res2) << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI acos(-1.0)
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------
ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a % b);
}

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int a,b,c;cin>>a>>b>>c;
  REP(i,b){
    if((a*i)%b==c){
      P("YES");
      return 0;
    }
  }
  P("NO");
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(int(input()) for _ in range(N))


def ins_sort(a, n, g):
    count = 0
    for i in range(g, n):
        v = a[i]
        j = i - g
        while j >= 0 and a[j] > v:
            a[j+g] = a[j]
            j -= g
            count += 1
        a[j+g] = v
    return count


def shell_sort(a, n):
    cnt = 0
    *g, = []
    h = 0
    for i in range(0, n):
        h = h * 3 + 1
        if h > n:
            break
        g.insert(0, h)

    m = len(g)
    for i in range(0, m):
        cnt += ins_sort(a, n, g[i])
    print(m)
    print(*g)
    print(cnt)
    for i in range(len(a)):
        print(a[i])


shell_sort(A, N)



Measured memory_bytes: 45476
#include<stdio.h>
int main(){
  int k[8],i,j,min,w,s;
  int m[15]={1,2,1,2,1,4,1,4,1,2,1,2,1,4,1};
  int h[8]={1,5,2,6,4,8,3,7};
  while(scanf("%d %d %d %d %d %d %d %d",
   &k[0],&k[1],&k[2],&k[3],&k[4],&k[5],&k[6],&k[7])!=EOF){
    min=1000000000;
    for(i=0;i<8;i++){
      w=0;
      for(j=0;j<8;j++){
	if(k[j]-m[i+j]>0){
	  w+=k[j]-m[i+j];
	}
      }
      if(min>w){
	min=w;
	s=i;
      }
      else if(min==w){
	if(h[i]<h[s]){
	  s=i;
	}
      }
    }
    for(i=0;i<8;i++){
      if(i!=0)printf(" ");
      printf("%d",m[s+i]);
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
#define fs first
#define se second

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;
typedef pair<ld, ld> pdd;

int n;
int A[100000];
int B[100000];
llong Bcnt[100001];
int C[100000];
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> A[i];
    for (int i = 0; i < n; ++i) cin >> B[i];
    for (int i = 0; i < n; ++i) cin >> C[i];
    sort(A, A + n);
    sort(B, B + n);
    sort(C, C + n);
    for (int i = 0, j = 0; i < n; ++i) {
        while (j < n && A[j] < B[i]) ++j;
        Bcnt[i + 1] = Bcnt[i] + j;
    }
    llong ans = 0;
    for (int i = 0, j = 0; i < n; ++i) {
        while (j < n && B[j] < C[i]) ++j;
        ans += Bcnt[j];
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 2304
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int nt=(c+b-1)/b;
    int na=(a+d-1)/d;
    if(nt<=na) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3636
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")
//#pragma GCC optimize("unroll-loops")

#ifdef __APPLE__
    # include <iostream>
    # include <cmath>
    # include <algorithm>
    # include <stdio.h>
    # include <cstdint>
    # include <cstring>
    # include <string>
    # include <cstdlib>
    # include <vector>
    # include <bitset>
    # include <map>
    # include <queue>
    # include <ctime>
    # include <stack>
    # include <set>
    # include <list>
    # include <random>
    # include <deque>
    # include <functional>
    # include <iomanip>
    # include <sstream>
    # include <fstream>
    # include <complex>
    # include <numeric>
    # include <immintrin.h>
    # include <cassert>
    # include <array>
    # include <tuple>
    # include <unordered_map>
    # include <unordered_set>
    # include <thread>
#else
    # include <bits/stdc++.h>
#endif

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define files(name) name!=""?freopen(name".in","r",stdin),freopen(name".out","w",stdout):0
#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define elif else if
#define mp make_pair
#define pb push_back
#define fir first
#define sec second

using namespace std;
#define int long long

typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long double ld;
typedef long long ll;

const int arr=2e5+10;
const int ar=2e3+10;
const ld pi=acos(-1);
const ld eps=1e-10;
const ll md=1e9+7;
const ll inf=1e18+10;

///---program start---///

#define md (ll)(998244353ll)

#define ar (int)(3000+10)

void inc(int& a,int b)
{
    a+=b;
    if (a>=md){
        a-=md;
    }
}

int dp[ar][ar];

signed main()
{
    #ifdef __APPLE__
        files("barik");
        freopen("debug.txt","w",stderr);
    #endif

    int a,b,c,d;
    cin>>a>>b>>c>>d;
    dp[a][b]=1;
    for (int i=a;i<=c;i++){
        for (int j=b;j<=d;j++){
            if (i==a&&j==b){
                continue;
            }
            if (i==a){
                dp[i][j]=1ll*dp[i][j-1]*i%md;
            }
            else if (j==b){
                dp[i][j]=1ll*dp[i-1][j]*j%md;
            }
            else {
                inc(dp[i][j],1ll*dp[i-1][j]*j%md);
                inc(dp[i][j],1ll*dp[i][j-1]*i%md);
                inc(dp[i][j],(-1ll*dp[i-1][j-1]*(i-1)%md*(j-1)%md+md)%md);
            }
        }
    }
    cout<<dp[c][d]<<"\n";
}


Measured memory_bytes: 74140
#include<bits/stdc++.h>
using namespace std;
int main(){
int l, n;
  cin>>l>>n;
  string s1, s2="";
  string mood[l];
  for(int i=0; i<l;i++){
    cin>>s1;
    mood[i]=s1;}
    sort(mood, mood+l);
    for(int i=0; i<l; i++){
    	s2+=mood[i];
	}
  cout<<s2;}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll n, i, ans = 0;
    cin >> n;
    vll p(n);
    for(i = 0; i < n; i++)
        cin >> p[i];
    for(i = 1; i < n - 1; i++)
        if(max({p[i], p[i + 1], p[i - 1]}) != p[i] && min({p[i], p[i + 1], p[i - 1]}) != p[i])
            ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int A,B;
  cin >>A>>B;
  if(A>8||B>8)puts(":(");
  else puts("Yay!");
  return 0;
    
  
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define int long long
#define MP make_pair
#define PB push_back
#define FI first
#define SE second
typedef pair<int, pair<int, int> > PPII;
typedef pair<int, int> PII;
static const int INF = 1ll<<60;

int n,k;
int a[100005];
int ans;
signed main(){
    cin>>n>>k;
    for(int i=0;i<n;++i)cin>>a[i];
    for(int i=0;i<n-1;++i){
        if(a[i]+a[i+1]<=k)continue;
        int v=a[i]+a[i+1]-k;
        if(a[i+1]>=v)a[i+1]-=v;
        else{
            a[i]-=a[i+1]-v;
            a[i+1]=0;
        }
        ans+=v;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
  int N,M;
  cin>>N>>M;
  vector<vector<char>> A(N,vector<char>(N));
  vector<vector<char>> B(M,vector<char>(M));
  for(int i=0;i<N;++i){
    for(int j=0;j<N;++j){
      cin>>A[i][j];
    }
  }
  for(int i=0;i<M;++i){
    for(int j=0;j<M;++j){
      cin>>B[i][j];
    }
  }

  bool frag=false;
  for(int i=0;i<N;++i){
    for(int j=0;j<N;++j){
      if(i+M>N || j+M>N) continue;

      int cnt=0;
      for(int k=i;k<i+M;++k){
        for(int l=j;l<j+M;++l){
          if(A[k][l]==B[k-i][l-j]) ++cnt;
        }
      }

      if(cnt==M*M) frag=true;
    }
  }

  if(frag) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string>
using namespace std;

int main() {
	long long x, t,result;
	cin >> x >> t;
	result = x - t;
	if (result < 0) result = 0;
	cout << result;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int K, A, B, objective = 0;
  scanf("%d %d %d", &K, &A, &B);
  
  for(int i = A; i <= B; i++) {
    if(i % K == 0) {
      objective = 1;
      break;
    }
  }

  (objective) ? puts("OK") : puts("NG");
  return 0;
}

Measured memory_bytes: 1640
#include <bits/stdc++.h>
typedef long long int LL;
using namespace std;
#define INF (1LL << 60)
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,k,n) for(int i=(k);(i)<(n);(i)++)
#define REP(i,n) for(int i = 0;(i)<(n);(i)++)
#define REPR(i,n) for(int i = n; i >= 0; i--)
#define F first
#define S second

int main() {
	char b;
	cin >> b;
	char ans;
	if (b == 'A') ans = 'T';
	if (b == 'T') ans = 'A';
	if (b == 'C') ans = 'G';
	if (b == 'G') ans = 'C';
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
while True:
    try:
        a = raw_input()
        count = 0
        for i in range(10):
            for j in range(10):
                for k in range(10):
	            for l in range(10):
                        b = i+j+k+l
			if b == int(a):
                            count += 1
	print count
    except EOFError:
	break

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

using namespace std;
#define int long long
#define rep(i, n) for(int i=0;i<(n);++i)
#define INF (1ll<<60)
#define FI first
#define SE second
typedef pair<int, int> pii;
#define l_b lower_bound
#define double long double

//data:数列
//dp:dp用の配列(関数内で初期化される）
//data,dptableの要素数
int Lis(int *data, int *dp, int n) {
    fill(dp, dp + n, INF);
    rep(i, n) {
        *l_b(dp, dp + n, data[i]) = data[i];
    }
    return l_b(dp, dp + n, INF) - dp;
}

int X1, Y1, X2, Y2;
vector<pii> xy;

const int n108 = 100000000;
bool yrev = false;
int lisdp[200200];
int y[200200];

signed main() {
    cin >> X1 >> Y1 >> X2 >> Y2;
    if (X1 > X2) {
        swap(X1, X2);
        swap(Y1, Y2);
    }
    if (Y1 > Y2) {
        Y1 = n108 - Y1;
        Y2 = n108 - Y2;
        yrev = true;
    }
    int s = X2 - X1 + Y2 - Y1;
    int n;
    cin >> n;
    rep(i, n) {
        int x, y;
        cin >> x >> y;
        if (x < X1 || X2 < x)continue;
        if (yrev) {
            y = n108 - y;
        }
        if (y < Y1 || Y2 < y)continue;
        xy.emplace_back(x, y);
    }
    sort(xy.begin(), xy.end());
    rep(i, xy.size()) y[i] = xy[i].SE;
    int lis = Lis(y, lisdp, xy.size());

    cout.precision(50);
    if (lis == X2 - X1 + 1 || lis == Y2 - Y1 + 1) {
        cout << 100 * s - 20 * lis + (5 * lis + 5) * M_PIl << endl;
        return 0;
    }
    cout << 100 * s - 20 * lis + 5 * lis * M_PIl << endl;
}

Measured memory_bytes: 7404
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  for(ll h=1;h<=3500;h++){
    for(ll w=1;w<=3500;w++){
      ll bo=4*h*w-n*w-n*h;
      ll shi=n*h*w;
      if(bo>0&&shi%bo==0){
	cout<<h<<" "<<w<<" "<<shi/bo<<endl;
	return 0;
      }
    }
  }
  return 0;
}


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

using namespace std;

int cases;
int T, X, Y;

int main()
{
	int flag = 0;
	int temp1 = 0;
	int temp2 = 0;
	int temp3 = 0;
	scanf("%d", &cases);
	while(cases--)
	{
		scanf("%d %d %d", &T, &X, &Y);
		flag = 0;
		// if((T - temp3) + temp1 == X && temp2 == Y)
		// {
		// 	flag = 1;
		// }
		// // cout << (T - temp3) + temp2 << " " << Y << "\n";
		// // cout << temp1 << " " << X << "\n";
		// if(temp1 == X && (T - temp3) + temp2 == Y)
		// {
		// 	// cout << "YES";
		// 	flag = 1;
		// }
		// if(temp1 - (T - temp3) == X && temp2 == Y)
		// {
		// 	flag = 1;
		// }
		// if(temp1 == X && temp2 - (T - temp3) == Y)
		// {
		// 	flag = 1;
		// }
		// if(X + Y == T)
		// {
		// 	flag = 1;
		// }
		// if((X + Y) % 2 == 0 && X == 0 && Y == 0)
		// {
		// 	flag = 1;
		// }
		// // if(flag == 2)
		// // {
		// // 	break;
		// // }
		// if(!flag)
		// {
		// 	cout << "GONE" ;
		// 	break;
		// }

		if(T % 2 != 0 && (X + Y) % 2 == 1 && (X + Y) <= T)
		{
			flag = 1;
		}
		else if(T % 2 == 0 && (X + Y) % 2 == 0 && (X + Y) <= T)
		{
			flag = 1;
		}
		else
		{
			flag = 0;
			break;
		}
		temp1 = X;
		temp2 = Y;
		temp3 = T;
	}
	if(flag == 1)
	{
		cout << "Yes\n";
	}
	else
	{
		cout << "No\n";
	}
	
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define res(n) resize(n)
#define rev(v) reverse(v.begin(),v.end())
#define sor(v) sort(v.begin(),v.end())
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
#define vi vector<int>
#define vl vector<long long>
#define vii vector<vector<int>>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;



int main()
{

    int a,b;
    cin >> a >> b;
    if(a*500 >= b) out("Yes");
    else out("No");


    return 0;
}


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

using ll = long long;
using namespace std;

char s[10000];

int main() {
	int n; scanf("%d", &n);
	scanf("%s", s);
	ll r = 0, g = 0, b = 0;
	for (int i = 0; s[i]; ++i) {
		if (s[i] == 'R') ++r;
		if (s[i] == 'G') ++g;
		if (s[i] == 'B') ++b;
	}
	ll ans = r * g * b;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			if (s[i] == s[j]) continue;
			int k = 2 * j - i;
			if (k < n && s[k] != s[i] && s[k] != s[j]) --ans;
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3836
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  vector<ll> v(n);
  rep(i, n) cin >> v[i];
  sort(v.begin(), v.end());
  ll ans = 0;
  for (ll i = n - 1; i >= 0; i--) {
    for (ll j = i - 1; j >= 0; j--) {
      auto itr = lower_bound(v.begin(), v.end(), v[i] + v[j]);
      ll d = distance(itr, v.end());
      ans += (n - 1 - i) - d;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3608
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
pair<vl,vb> eratosthenes_sieve(ll n){
  vb is_prime(n+1,true);
  vl prime;
  is_prime[0] = false;
  is_prime[1] = false;
  FOR(i,2,sqrt(n)+1){
    if(!is_prime[i]) continue;
    for(ll j=2*i;j<=n;j+=i) is_prime[j] = false;
    prime.eb(i);
  }
  return {prime,is_prime};
}
signed main(){
  int n;
  cin >> n;
  vi fib(n+1,1);
  REP(i,n-1) fib[i+2] = fib[i+1]+fib[i];
  cout << fib[n] << endl;
}



Measured memory_bytes: 3124
import java.util.*;


public class Main {
	
	Scanner cin = new Scanner(System.in);
	
	public static void main(String[] args) {
		new Main().run(); 
	}
	
	public void run() {		
		
		/* input */
		int n = cin.nextInt();
		int x = cin.nextInt();
		
		int[] nums = new int[n];
		
		for (int i = 0; i < n; i ++) {
			nums[i] = cin.nextInt();
		}
				
		/* start 
		 * greedy */
		long res = 0;
		
		for (int i = 0; i < n; ) {
			
			if (i == 0) {
				if (nums[i] <= x) {
					
					if (i + 1 < n && nums[i] + nums[i+1] > x) {
						res += nums[i + 1] + nums[i] - x;
						nums[i+1] = x - nums[i];
					}
					i ++;
				} else {
					res += nums[i] - x;
					
					if (i + 1 < n) {
						res += nums[i+1];
						nums[i+1] = 0;
					}
					
					nums[i] = x;	
					i ++;
				}
			}
			else {
				
				if (i + 1 < n) {
					
					if (nums[i] + nums[i + 1] <= x) {
						i ++;
					} else {
						res += nums[i + 1] + nums[i] - x;
						nums[i + 1] = x - nums[i];
					}
				} else {// last element
					i ++;
				}
			}
			
		}
		
		
		
		/*finish*/
		System.out.println(res);
	}
}



Measured memory_bytes: 50912
#include <stdio.h>

int main(int argc, char const *argv[])
{
    int N;
    scanf("%d",&N);
    int H[N];
    for (size_t i = 0; i < N; i++)
    {
        scanf("%d",&H[i]);
    }
    int ans=1;
    int flag;
    for (size_t i = 1; i <N; i++){
        flag=1;
        for (size_t j = 0; j < i; j++){
            if (H[j]>H[i]){flag=0;}
        }
        if (flag==1){ans++;}
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
    ll n;
    cin >> n;
    vector<char> vc(n);
    vector<ll> c_cnt(3,0);//B = 0,G = 1,R = 2に入れる
    rep(i,n){
        cin >> vc.at(i);
        if(vc.at(i) == 'B')c_cnt[0]++;
        else if(vc.at(i) == 'G')c_cnt[1]++;
        else c_cnt[2]++;
    }
    ll ans = c_cnt[0]*c_cnt[1]*c_cnt[2];
    for(ll i = 0;i<n;i++){
        for(ll j = i+1;j<n;j++){
            if(vc[i] == vc[j])continue;
            ll k = 2*j - i;
            if(k >= n || vc[i] == vc[k] || vc[j] == vc[k])continue;
            ans --;
        }
    }
    cout << ans << endl;
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 3600
import numpy as np
N, K = map(int, input().split(" "))
p = list(map(int, input().split(" ")))
ex = [i + 1 for i in p]
ans = sum(ex[0: K])
max_ans = ans
for i in range(K, N):
    ans += ex[i] - ex[i - K]
    max_ans = max(ans, max_ans)
print(max_ans / 2.0)

Measured memory_bytes: 33984
#include<stdio.h>
#include<string.h>
int main()
{
	int N;
	scanf("%d", &N);
	
	int A[N];
	int r;
	
	for(r=0; r<N; r++) scanf("%d", &A[r]);
	
	int c1 = N;
	int c2 = 0;
	
	for(r=0; r<N; r++){
		if(A[r] % 2 == 1) c1 = c1 - 1;
		else if (A[r] % 3 == 0 || A[r] % 5 == 0) c2++;
	}
	
	if(c1 == c2) printf("APPROVED");
	else printf("DENIED");
		
		return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
using namespace std;
#define int long long

signed main() {
  int n, x;
  cin >> n >> x;
  if (x == 1 || x == 2 * n - 1) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  if (n == 2) {
    cout << 1 << endl;
    cout << 2 << endl;
    cout << 3 << endl;
    return 0;
  }
  int ans[2 * n - 1];
  ans[n - 1] = x;
  if (x == 2) {
    ans[n - 2] = x + 1;
    ans[n] = x - 1;
    ans[n + 1] = x + 2;
    int res = x + 3;
    for (int i = 0; i < n - 2; i++) {
      ans[i] = res;
      res++;
    }
    for (int i = n + 2; i < 2 * n - 1; i++) {
      ans[i] = res;
      res++;
    }
  } else {
    ans[n - 2] = x - 1;
    ans[n] = x + 1;
    ans[n + 1] = x - 2;
    int res = 1;
    for (int i = 0; i < n - 2; i++) {
      if (res == x - 2) res = x + 2;
      ans[i] = res;
      res++;
    }
    for (int i = n + 2; i < 2 * n - 1; i++) {
      if (res == x - 2) res = x + 2;
      ans[i] = res;
      res++;
    }
  }
  for (int i = 0; i < 2 * n - 1; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 3072
//
// Created by Myabu on 2020/01/25.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;


int main(void){
    int D;
    cin>>D;

    if(D==25){
        cout<<"Christmas"<<endl;
    }else if(D==24){
        cout<<"Christmas Eve"<<endl;
    }else if(D==23){
        cout<<"Christmas Eve Eve"<<endl;
    }else{
        cout<<"Christmas Eve Eve Eve"<<endl;
    }


    return 0;
}

Measured memory_bytes: 888
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let a: Vec<char> = read::<String>().chars().collect();
    let mut ans: usize = 0;
    let n = a.len();
    let mut pos = 0;
    for i in 0..n {
        if a[i] == 'W' {
            ans += i - pos;
            pos += 1;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
/* Huyyt */
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define mkp(a,b) make_pair(a,b)
#define pb push_back
const int dir[8][2] = {{0, 1}, {1, 0}, {0, -1}, { -1, 0}, {1, 1}, {1, -1}, { -1, -1}, { -1, 1}};
using namespace std;
typedef long long ll;
inline void read(int &v)
{
        v = 0;
        char c = 0;
        int p = 1;
        while (c < '0' || c > '9')
        {
                if (c == '-')
                {
                        p = -1;
                }
                c = getchar();
        }
        while (c >= '0' && c <= '9')
        {
                v = (v << 3) + (v << 1) + c - '0';
                c = getchar();
        }
        v *= p;
}
const long long mod = 1e9 + 7;
const int N = 2e5 + 5;
int n;
ll num[N];
int main()
{
        read(n);
        for (int i = 1; i <= n; i++)
        {
                cin >> num[i];
        }
        if (num[1] != 0)
        {
                cout << -1 << endl;
                return 0;
        }
        for (int i = 2; i <= n; i++)
        {
                if (num[i] - num[i - 1] > 1)
                {
                        cout << -1 << endl;
                        return 0;
                }
        }
        ll anser = 0;
        for (int i = 2; i <= n; i++)
        {
                if (num[i] == num[i - 1] + 1)
                {
                        anser++;
                }
                else
                {
                        anser += num[i];
                }
        }
        cout << anser << endl;
        return 0;
}


Measured memory_bytes: 1792
#include<cstdio>

int main()
{
	int suuretu;
	scanf("%3d", &suuretu);

	int count = 1;

	switch (suuretu)
	{
	case 1:
	case 2:
		printf("%d\n", 4);
		return 0;
	default:
		while (suuretu != 4)
		{
			if (suuretu % 2 == 0)
			{
				suuretu /= 2;
			}
			else
			{
				suuretu = 3 * suuretu + 1;
			}
			count++;
		}
		printf("%d\n", count+3);
		return 0;
	}
}

Measured memory_bytes: 128
import java.util.Scanner;
     
    public class Main{
        public static void main(String[] args){
            Scanner scanner = new Scanner(System.in);
     
            int a, b;
            a = scanner.nextInt();
            b = scanner.nextInt();
            if(b % a == 0){
                System.out.println(a + b);
            }
            else{
                System.out.println(b - a);
            }
        }
    }

Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)

const ll MOD = (ll)1e9 + 7;
const ll HIGHINF = (ll)1e18;

int main() {
  V<char> ov;
  vll vv;
  ll top = 0;
  char s;
  ll val = -1;
  while (scanf("%c", &s) != EOF) {
    if (s == '+') {
      ll val1 = vv.back(); vv.pop_back();
      ll val2 = vv.back(); vv.pop_back();
      vv.push_back(val1 + val2);
    } else if (s == '-') {
      ll val1 = vv.back(); vv.pop_back();
      ll val2 = vv.back(); vv.pop_back();
      vv.push_back(val2 - val1);
    } else if (s == '*') {
      ll val1 = vv.back(); vv.pop_back();
      ll val2 = vv.back(); vv.pop_back();
      vv.push_back(val1 * val2);
    } else if (s == ' ') {
      if (val != -1) {
        vv.push_back(val); val = -1;
      }
    } else {
      if (val == -1) {
        val = s - '0';
      } else {
        val = val * 10 + (s - '0');
      }
    }
  }
  cout << vv.back() << endl;
  return 0;
}



Measured memory_bytes: 3228