akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
using namespace std;

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

  int h[N];
  rep(i,0,N-1) cin >> h[i];

  int cnt = 0, i, j;
  for (i = 0; i < N;) {
    if (h[i] == 0) {
      i++;
      continue;
    }

    for (j = i; j < N; j++) {
      if (h[j] == 0) break;
      else h[j]--;
    }

    cnt++;
  }

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


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

int A, B;

int main() {
    cin >> A >> B;

    int ans = 0;
    for (int i = 0; i < 2; i++) {
        if (A > B) {
            ans += A;
            A--;
        } else {
            ans += B;
            B--;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cctype>
#include<vector>
#include<map>
#include<iomanip>
using namespace std;
#define fr first
#define sc second
typedef pair<int,int> Pt;
int main(){
  map<char,Pt> tmp;
  for(int i = 0 ; i < 9 ; i++ ) tmp['A' + i] = Pt( i / 3 , i % 3 );

  char s,t,b;
  Pt st,gt,bt;
  int n,d[]={0,1,0,-1};
  while(cin >> n && n){
    double dp[16][4][4] = {{{}}};
    cin >> s >> t >> b;
    st = tmp[s] , gt = tmp[t] , bt = tmp[b];
    dp[0][st.fr][st.sc] = 1.0;
    for(int i = 0 ; i < n ; i++ ){
      for(int x = 0 ; x < 3 ; x++ ){
        for(int y = 0 ; y < 3 ; y++ ){
          for(int j = 0 ; j < 4 ; j++ ){
            int px = x + d[j] , py = y + d[3-j];
            if( px < 0 || px > 2 || py < 0 || py > 2 || bt == Pt(px,py)){
              px = x , py = y;
            }
            dp[i+1][px][py] += dp[i][x][y] / 4.0;
          }
        }
      }
    }
    cout << fixed << setprecision(8) << dp[n][gt.fr][gt.sc] << endl;
  }
}

Measured memory_bytes: 1264
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

const int MAX=510000;
const int mod=1000000007;
ll fac[MAX],finv[MAX],inv[MAX];

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a){
  return modpow(a,mod-2);
}

void init(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  rep(i,MAX){
    if(i>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;
    }
  }
}

ll com(int n,int 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(){
  int N;
  cin>>N;
  VI A(N);
  rep(i,N) cin>>A[i];
  ll sum=0;
  rep(i,N) sum+=A[i];
  ll ans=0;
  rep(i,N) (ans+=(sum+mod-A[i])%mod*A[i]%mod)%=mod;
  cout<<ans*modinv(2)%mod<<endl;
}



Measured memory_bytes: 4048
/**
** 
** Last Updated: 2019/06/07 22:37:20 JST
** (c) was
**/
#include <bits/stdc++.h>
using namespace std;

int main() {
  //input
  int r,d,x; cin >> r >> d >> x;
  int x1;
  //compute
  for(int i=0;i<10;i++){
    x1=r*x-d;
    x=x1;
    //output
    cout << x1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
n, m = gets.chomp.split.map(&:to_i)
k = []
s = []
m.times do |i|
  s[i] = gets.chomp.split.map(&:to_i)
  k[i] = s[i].shift
end
p = gets.chomp.split.map(&:to_i)

ans = 0
[0, 1].repeated_permutation(n) do |a|
  flg = false
  m.times do |i|
    tmp = 0
    s[i].each do |t|
      tmp += a[t-1]
    end
    if tmp % 2 != p[i]
      flg = true
      break
    end
  end
  next if flg
  ans += 1
end
p ans


Measured memory_bytes: 3836
let n, k = Scanf.scanf " %d %d" @@ fun a b -> a, b
let r = n - k
let memo = Array.make_matrix 3000 3000 @@ -1
let rec comb n k =
  if n < 0 || k < 0 then 0
  else if memo.(n).(k) > -1 then memo.(n).(k)
  else
    (memo.(n).(k) <- if n < k then 0 else if n = k then 1 else if k = 0 then 1
      else (comb (n - 1) (k - 1) + comb (n - 1) k) mod 1_000_000_007;
    memo.(n).(k))
let h n k = comb (n + k - 1) k
let _ =
  for i = 1 to k do
    Printf.printf "%d\n" @@ comb (k - 1) (i - 1) * h (i + 1) (r - i + 1) mod 1_000_000_007 done

Measured memory_bytes: 73336
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>



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

using namespace std;
int a;

int main(){
  cin >> a;
  cout << a*800 - (a/15)*200 << endl;
  
  
  return 0;
}



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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
clock_t startTime;
long double getTime(){
	return (long double)(clock()-startTime)/CLOCKS_PER_SEC;
}
ll n;
//int a,b,c;
int main(){
	startTime=clock();
	cin >> n;
	
	for(int i=1;i < 3501;i++)
		for(int j=1;j < 3501;j++){
			if (i*j*4-n*i-n*j > 0 && n*i*j %(i*j*4-n*i-n*j)==0   ){
				cout << i <<" "<<j <<" "<<n*i*j/(i*j*4-n*i-n*j);
				return 0;
			}
			
	}
	
	

	return 0;
}

Measured memory_bytes: 3636
using System;
using AtCorder;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            var input1 = int.Parse(Console.ReadLine());
            var input2 = int.Parse(Console.ReadLine());
            Console.WriteLine(6 - input1 - input2);
            //new Program().Solve();
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
 
int n;
vector<int> G[100010];
int d[2][100010];

void dist(int s,int* ret) {
	for(int i=1;i<=n;i++)ret[i]=-1;
	queue<int> que;
	ret[s]=0;
	que.push(s);
	while(!que.empty()){
		int v=que.front(); que.pop();
		for(int u: G[v]){
			if(ret[u]==-1){
				ret[u]=ret[v]+1;
				que.push(u);
			}
		}
	}
}
 
int main(){
	scanf("%d",&n);
	for(int i=0;i<n-1;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		G[a].push_back(b);
		G[b].push_back(a);
	}
	
	dist(1,d[0]);
	dist(n,d[1]);
	int s=1,t=n;
	while(1){
		for(int u: G[s]){
			if(d[1][u]<d[1][s]){
				s=u;
				break;
			}
		}
		if(s==t){
			for(int u: G[s]){
				if(d[0][u]<d[0][s]){
					s=u;
					break;
				}
			}
			break;
		}
		for(int u: G[t]){
			if(d[0][u]<d[0][t]){
				t=u;
				break;
			}
		}
		if(s==t){
			for(int u: G[t]){
				if(d[1][u]<d[1][t]){
					t=u;
					break;
				}
			}
			break;
		}
	}
	dist(s,d[0]);
	dist(t,d[1]);
	s=t=0;
	for(int i=1;i<=n;i++){
		if(d[0][i]<d[1][i])s++;
		else t++;
	}
	if(s>t)puts("Fennec");
	else puts("Snuke");
}

Measured memory_bytes: 6656
import sys

def main():
    n = int(input())
    a=sys.stdin.readline().rstrip().split()
    if '0' in a:
        print(0)
        return
    ans=1
 
    for i in a:
        ans=ans*int(i)
        if ans>1000000000000000000:
            print("-1")
            return
    else:
        print(ans)
main()

Measured memory_bytes: 19360
#include<cstdio>
using namespace std;
char a[10];
int main() 
{
	scanf("%s",a);
	for(int i=1;i<4;i++)
	{
		if(a[i]==a[i-1])
		{
			printf("Bad");
			return 0;
		}
	}
	printf("Good");
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;

class Comb {
 public:
  Comb(int n) {
    fact[0] = fact[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < n; i++){
        fact[i] = fact[i-1] * i % kMod;
        inv[i] = kMod - inv[kMod%i] * (kMod / i) % kMod;
        finv[i] = finv[i-1] * inv[i] % kMod;
    }
  }

  LL nCr(int n, int r) const {
    LL numerator = fact[n];
    LL denominator = finv[r] * finv[n-r] % kMod;
    return (numerator * denominator) % kMod;
  }

 private :
  static constexpr int kMax = 1e5;
  LL fact[kMax];
  LL inv[kMax];
  LL finv[kMax];
};


int main() {
  int N, K; std::cin >> N >> K;
  Comb c(N);
  std::cout << c.nCr(N - K + 1, 1) << std::endl;
  for (int k = 2; k <= K; ++k) {
    std::cout << c.nCr(N - K + 1, k) * c.nCr(K - 1,  k - 1) % kMod << std::endl;
  }
}


Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 69;
const int MAXT = 2569;
const int INF = 1e18;
struct vl{
    int x,y,z;
    bool operator<(vl t)const{
        if(x==t.x&&y==t.y)return z<t.z;
        if(x==t.x)return y<t.y;
        return x<t.x;
    }
};
vector<vl>a[MAXN];
int m,n,q,k,S,t;
int c[MAXN];
int d[MAXN];
int dist[MAXN][MAXT];
void Dij(int x){
    for(int i=1;i<=n;i++){
        for(int j=0;j<=2500;j++){
            dist[i][j]=INF;
        }
    }
    dist[1][S]=0;
    set<vl>s;
    s.insert({0,S,1});
    while(!s.empty()){
        vl t = *s.begin();
        s.erase(s.begin());
        int u = t.z;
        int money = t.y;
        for(vl tmp:a[u]){
            int v = tmp.x;
            int w = tmp.y;
            int fee = tmp.z;
            if(money<fee)continue;
            if(dist[u][money]+w>=dist[v][money-fee])continue;
            set<vl>::iterator itr = s.find({dist[v][money-fee],money-fee,v});
            if(itr!=s.end())s.erase(itr);
            dist[v][money-fee] = dist[u][money]+w;
            s.insert({dist[v][money-fee],money-fee,v});
        }
        for(int i=1;money+c[u]*i<=2500;i++){
            if(dist[u][money+c[u]*i]<=dist[u][money]+d[u]*i)continue;
            set<vl>::iterator itr = s.find({dist[u][money+c[u]*i],money+c[u]*i,u});
            if(itr!=s.end())s.erase(itr);
            dist[u][money+c[u]*i] = dist[u][money] + d[u]*i;
            s.insert({dist[u][money+c[u]*i],money+c[u]*i,u});
        }
    }
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m>>S;
    S = min(S,2500ll);
    for(int i=1;i<=m;i++){
        int x,y,z,t;
        cin>>x>>y>>t>>z;
        a[x].push_back({y,z,t});
        a[y].push_back({x,z,t});
    }
    for(int i=1;i<=n;i++)cin>>c[i]>>d[i],c[i]=min(c[i],2500ll);
    Dij(1);
    for(int i=2;i<=n;i++){
        int tmp = INF;
        for(int j=0;j<=2500;j++){
            tmp = min(tmp,dist[i][j]);
        }
        cout<<tmp<<'\n';
    }
}


Measured memory_bytes: 12344
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()
    ds = LI()
    ans = 0
    c = 0
    for i in range(n):
        for j in range(n):
            if i >= j:
                continue
            ans += ds[i] * ds[j]
            c += 1
    assert c == n*(n-1)/2
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000001


int main(){
	
	int N;
	cin>>N;
	
	vector<long long> A(N);
	
	map<long long,long long> mp;
	
	for(int i=0;i<N;i++){
		cin>>A[i];
		mp[A[i]]++;
	}
	
	long long ans = 0;
	
	for(auto a:mp){
		ans += a.second * (a.second-1) / 2;
	}
	
	for(int i=0;i<N;i++){
		cout<<ans-(mp[A[i]]-1)<<endl;
	}
	
    return 0;
}


Measured memory_bytes: 12800
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int M=2e5+7,inf=0x3f3f3f3f;
int read(){
	int ans=0,f=1,c=getchar();
	while(c<'0'||c>'9'){if(c=='-') f=-1; c=getchar();}
	while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=getchar();}
	return ans*f;
}
int n,m,cnt,first[M],q[M],d[M],vis[M];
struct node{int to,next,w;}e[2*M];
void ins(int a,int b,int w){cnt++; e[cnt].to=b; e[cnt].w=w; e[cnt].next=first[a]; first[a]=cnt;}
void insert(int a,int b,int w){ins(a,b,w); ins(b,a,w);}
void spfa(){
	memset(d,0x3f,sizeof(d));
	int head=0,tail=1;
	q[0]=1; d[1]=0; vis[1]=1;
	while(head!=tail){
		int x=q[head++]; vis[x]=0; if(head>M) head=0;
		for(int i=first[x];i;i=e[i].next){
			int now=e[i].to;
			if(d[now]>d[x]+e[i].w){
				d[now]=d[x]+e[i].w;
				if(!vis[now]){q[tail++]=now; vis[now]=1; if(tail>M) tail=0;}
			}
		}
	}
}
int main()
{
	int x,y;
	n=read(); m=read();
	for(int i=1;i<=m;i++) x=read(),y=read(),insert(x,y,1);
	spfa();
	if(d[n]>2) printf("IMPOSSIBLE\n");
	else printf("POSSIBLE\n");
	return 0;
}

Measured memory_bytes: 7936
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;

int main(){
    ll d=0,n=0;
    //VI a(N);
    string s,s1,s2;
    cin >> n;
    Vl a(n+1);
    Vl b(n);
    rep(i,n+1){
        cin >> a[i];
    }
    rep(i,n){
        cin >> b[i];
    }

    for(ll i = n; i >= 0; i--){
        if(i == 0){
            if(b[0] > 0 && a[0] > 0){
                if(a[0] - b[0] > 0){
                    d += b[0];
                    cout << "a" << endl; 
                    break;
                }
                else {
                    d += a[0];
                    cout << "b" << endl; 
                    break;
                }
            }
            break;
        }
        if(a[i] - b[i-1] >= 0){
            d += b[i-1];
            a[i] = a[i] - b[i-1];
            b[i-1] = 0;
        }
        else {
            d += a[i]; 
            b[i-1] = b[i-1]-a[i];
            a[i] = 0;
        }

        if(a[i-1] - b[i-1] >= 0) {
            d += b[i-1];
            a[i-1] = a[i-1] - b[i-1];
            b[i-1] = 0;
        }
        else {
            d += a[i-1]; 
            b[i-1] = abs(a[i-1] - b[i-1]);
            a[i-1] = 0;
        }
    }
    cout << d <<endl; 
    return 0;
}


Measured memory_bytes: 1792
// https://atcoder.jp/contests/dp/tasks/dp_a

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
// int gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// int lcm(long a, long b) { return a * b / gcd(a, b); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> h(n + 1, INF);
    REP(i, n) cin >> h[i];
    // 入力値の足場の高さHの差分の合計を最小化する
    // vector<int> dp(n + 1, INF);
    int dp[n + 1];
    REP(i, n + 1) dp[i] = INF;
    dp[0] = 0;
    REP(i, n - 1) {
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
    }
    cout << dp[n - 1] << endl;

    return 0;
}


Measured memory_bytes: 1152
#include <stdio.h>

using namespace std;

int main() {
  int N;
  char S[3];
  scanf("%s",S);
  N = 700;
  for (int i = 0; i < 3; i++) {
    if (S[i] == 'o') N += 100;
  }
  printf("%d\n",N);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define SZ(x) (int)(x).size()
#define endl '\n'
#define FOR(a, b, c) for (auto a = (b); (a) < (c); ++(a))
#define F0R(a, b) FOR (a, 0, (b))
#define CEIL(a, b) ((a) + (b)-1) / (b)
template <class T>
bool ckmin(T& a, const T& b) {
  return a > b ? a = b, true : false;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, true : false;
}
#ifndef DEBUG
#define DEBUG 0
#endif
#define dout \
  if (DEBUG) std::cerr
#define dvar(...) " [" << #__VA_ARGS__ ": " << mt(__VA_ARGS__) << "] "
template <typename T>
struct IsC {
  template <typename C>
  static char test(typename C::const_iterator*);
  template <typename C>
  static int test(...);
  static const bool value = sizeof(test<T>(0)) == sizeof(char);
};
template <>
struct IsC<string> {
  static const bool value = false;
};
template <typename C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(ostream&, const C&);
template <typename T1, typename T2>
ostream& operator<<(ostream&, const pair<T1, T2>&);
template <typename... T> using TS = tuple_size<tuple<T...>>;
template<size_t idx, typename... T>
typename enable_if<TS<T...>::value == idx + 1, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return o << ", " << get<idx>(t) << ')';
}
template<size_t idx, typename... T>
typename enable_if<0 < idx && idx + 1 < TS<T...>::value, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return operator<<<idx + 1>(o << ", " << get<idx>(t), t);
}
template<size_t idx = 0, typename... T>
typename enable_if<1 < TS<T...>::value && !idx, ostream&>::type
operator<<(ostream& o, const tuple<T...>& t) {
  return operator<<<idx + 1>(o << '(' << get<idx>(t), t);
}
template<typename T>
ostream& operator<<(ostream& o, const tuple<T>& t) {
  return o << get<0>(t);
}
template <typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p) {
  return o << mt(p.fi, p.se);
}
template <typename C>
typename enable_if<IsC<C>::value, ostream&>::type operator<<(
    ostream& o, const C& c) {
  o << '[';
  for (auto it = c.cbegin(); it != c.cend(); ++it)
    o << *it << (next(it) != c.cend() ? ", " : "");
  return o << ']';
}
template <typename T>
void tprint(vector<vector<T>>& v, size_t width = 0, ostream& o = cerr) {
  if (!DEBUG) return;
  for (const auto& vv : v) {
    for (const auto& i : vv) o << setw(width) << i;
    o << endl;
  }
}

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

  int n; cin >> n;
  ll ans = 0;
  ll hb = 0;
  F0R (_, n) {
    ll a; cin >> a;
    ll ex = max(hb - a, 0ll);
    ans += ex;
    ckmax(hb, ex + a);
  }
  cout << ans << endl;
  
  
  return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 5;

ll n, t, a[MAXN];
int main(){
    ios::sync_with_stdio(false);

    ll x = 1, y = 1000000000000000001, z;
    cin >> n;
    int f = 1;
    for(int i = 1; i <= n; i++) cin >> a[i], f &= a[i] > 0;
    if(!f){ cout << 0; return 0; }
    for(int i = 1; i <= n; i++){
        t = a[i];
        if(!f) continue;
        z = y / x + (y % x > 0);
        if(t >= z) f = 0;
        else x *= t;
    }
    cout << (f ? x : -1);
}


Measured memory_bytes: 4392
h,w = gets.split.map(&:to_i)
a = h.times.map{gets.split.map(&:to_i)}
x=0
y=0
dy=1
ops = []
while x<h
  if a[x][y].odd?
    if y+dy>=0&&y+dy<w
      a[x][y+dy]+=1
      ops << [x,y,x,y+dy]
    elsif x<h-1
      a[x+1][y]+=1
      ops << [x,y,x+1,y]
    end
  end
  y += dy
  if y < 0 || y >= w
    y -= dy
    x += 1
    dy *= -1
  end
end

p ops.size
ops.each do |x,y,x_,y_|
  puts "#{x+1} #{y+1} #{x_+1} #{y_+1}"
end


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

int n,w,z;
int a[2005]={0};

int main(){
  cin >> n >> z >> w;
  for(int i=0;i<n;++i)cin >> a[i];
  if(n==1)cout << max(w-a[0],a[0]-w);
  else cout << max(max(a[n-2]-a[n-1],a[n-1]-a[n-2]),max(w-a[n-1],a[n-1]-w));
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();

        int KA = A/K; int KB = B/K;

        if(KA<KB){
            System.out.println("OK");
        } else if(A%K==0){
            System.out.println("OK");
        } else if(B%K==0){
            System.out.println("OK");
        } else{
            System.out.println("NG");
        }

        sc.close();
    }
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  int n ; 
  cin >> n ; 
  intll a[1001000] ; 
  intll ans = 0 ;
  rep(i,n){
    intll p ; 
    cin >> p ; 
    a[p] ++ ;
    ans += p ;
  }
  
  int q ; 
  cin >> q ;
  
  rep(i,q){
    intll b , c ; 
    cin >> b >> c ;
    ans = ans - a[b]*(b - c);
    a[c] +=  a[b] ;
    cout << ans <<endl ;
    a[b] = 0 ;
  }


}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vst;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;


const ll mod=1e9+7;
const ll inf=1e16; 

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)


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

 ll a,b,c,x,y;
  cin >> a >> b >> c >> x >> y;
  
  ll res=inf;
  
  rep(ab,0,max(x,y)+1){
   res=min(res,ab*2*c+max(0ll,(x-ab))*a+max(0ll,(y-ab))*b);
  }
  cout << res << endl;
  
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
    int n;
    cin >> n;
    vector<int> l(n);
    rep(i, n) cin >> l[i];
    sort(all(l));

    int cnt = 0;
    rep(i, n) cnt += l[i];

    cout << ((cnt - l[n - 1] > l[n - 1]) ? "Yes" : "No") << '\n';
    return 0;
}


Measured memory_bytes: 3596
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

string s;
string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

void f1() {
    s += "Z";
    int cnt = 0;
    for(int i=0; i<s.size(); i++) {
        if(isalpha(s[i])) {
            while(cnt<0) cnt+=26;
            cnt %= 26;
            cnt += s[i]-'A';
            cnt %= 26;

            s[i] = alphabet[cnt];

            cnt = 0;
        }
        else if(s[i] == '+') cnt++;
        else if(s[i] == '-') cnt--;
        else if(s[i] == '?') cnt=0;
    }

    string ret = "";
    rep(i,s.size()-1) {
        if(isalpha(s[i]) || s[i]=='[' || s[i]==']' || s[i]=='?') ret += s[i];
    }
    s = ret;
}

void str_reverse(int s0, int t0) {
    string ret = "";
    for(int i=t0; i>=s0; i--) ret += s[i];

    // cout<<"hoge : "<<ret<<endl;
    // cout<<s.substr(0,s0)<<endl;
    // cout<<s.substr(t0+1,s.size()-t0)<<endl;
    s = s.substr(0,s0) + ret + s.substr(t0+1,s.size()-t0);
}
void f2() {
    stack<int> st;
    rep(i,s.size()) {
        if(s[i] == '[') {
            st.push(i);
        }
        else if(s[i] == ']') {
            int top = st.top();
            st.pop();
            // cout<<top<<","<<i<<endl;
            // cout<<s<<endl;
            str_reverse(top, i);
            // s[top] = '.';
            // s[i] = '.';
            // cout<<s<<endl;
            // s = s.erase(top,1);
            // s = s.erase(i-1,1);
            // cout<<s<<endl;
        }
    }
}

void f3() {
    string ret = "";

    rep(i,s.size()) {
        if(isalpha(s[i])) ret += s[i];
        else if(s[i] == '?') ret += "A";
    }

    s = ret;
}

void solve() {
    f1();
    rep(i,s.size()) {
        if(s[i] == '?') s[i] = 'A';
    }

    f2();
    f3();

    cout<<s<<endl;

}

int main() {
    while(cin>>s) {
        if(s==".") break;
        solve();
    }
    return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <queue>
using namespace std;
int main(){
  long long n,m;cin>>n>>m;
  priority_queue<long long> a;
  long long sm = 0;
  for(int i = 0; n > i; i++){
    long long tmp;cin>>tmp;
    a.push(tmp);
    sm += tmp;
  }
  for(int i = 0; m > i; i++){
    long long nw = a.top();
    a.pop();
    a.push(nw/2);
    sm = sm - nw + (nw/2);
  }
  cout << sm << endl;
}

Measured memory_bytes: 1400
local mmi = math.min
local n = io.read("*n")
local sum = {io.read("*n")}
for i = 2, n do
  sum[i] = sum[i - 1] + io.read("*n")
end
local dp = {}
dp[1] = {}
for i = 1, n do
  dp[1][i] = 0
end
for i = 2, n do
  dp[i] = {}
  local leftposlim = n - i + 1
  for j = 1, leftposlim do
    local v = dp[1][j] + dp[i - 1][j + 1]
    for k = 2, i - 1 do
      v = mmi(v, dp[k][j] + dp[i - k][j + k])
    end
    v = v + sum[j + i - 1]
    if 1 < j then v = v - sum[j - 1] end
    dp[i][j] = v
  end
end
print(dp[n][1])


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

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    string s;
    while(cin >> s) {
        vector<int> f(26,0);
        for(char c : s) {
            f[c-'a']++;
        }
        int ok = 1;
        for(int i = 0; i < 26 && ok; i++) {
            if(f[i] % 2 != 0) {
                ok = 0;
            }
        }
        cout << (ok? "Yes" : "No") << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
s = input()
a = ['A','T','G','C']
ans = []
c = 0

for i in s:
    if i in a:
        c += 1
    else:
        ans += [c]
        c = 0
ans += [c]
if ans == []:
    print(len(s))
else:
    print(max(ans))


Measured memory_bytes: 9048
#include <iostream>

using namespace std;
int main() {
	int x, y;
 	cin >> x >> y;
  	bool ok = false;
    for (int i = 0; i <= x; ++i)
    	if (i * 2 + (x - i) * 4 == y) {
        	cout << "Yes";
            exit(0);
        }
    cout << "No";
}

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

using namespace std;

vector<int> v;
bool dp[200000];
int main() {
    
    for (int i = 100; i <= 105; ++i)
        v.push_back(i);

    int x;
    cin >> x;
    
    dp[x] = 1;

    for (int i = x - 1; i >= 0; --i) 
        for (int z: v) 
            dp[i] |= dp[i + z];

    puts(dp[0] ? "1":"0");
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int n;
    cin >> n;
    vector a(n,0);
    vector b(n,0);
    for (int i=0; i<n; i++) cin >> a[i];
    for (int i=0; i<n; i++) cin >> b[i];
    sort(b.rbegin(), b.rend());
//    debug(a);
//    debug(b);

    bool ans = true;

    for (int i=0; i<10; i++) {
        int front = 0;
        int back = n-1;
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] == b[i]) {
                cnt++;
                if (b[front] != b[i]) {
                    swap(b[front], b[i]);
                    front++;
                } else if (b[back] != b[i]) {
                    swap(b[back], b[i]);
                    back--;
                }
            }
        }
    }

    for (int i=0; i<n; i++) {
        if (a[i] == b[i]) ans = false;
    }

    if (ans) {
        cout << "Yes" << endl;
        for (int i=0; i<n; i++) {
            cout << b[i] << (i==n-1? "\n" : " ");
        }
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 4404
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

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

    int a,b,c;cin>>a>>b>>c;
    if(a+b+c>=22) cout<<"bust"<<endl;
    else cout<<"win"<<endl;
    return 0;
}


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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

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

	if(a[0]==0){
		cout<<0<<endl;
		return 0;
	}

	ll ans=1;
	rep(i,n){
		if(a[i]>ll(1e18)/ans){
			cout<<-1<<endl;
			return 0;
		}
		ans *= a[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4036
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int, int>
#define pb(a) push_back(a)
#define all(v) v.begin(), v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

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

	vint A(3);
	for (int i = 0; i < 3; i++) {
		cin >> A[i];
	}

	sort(all(A));

	cout << A[0] + A[1] << endl;

	return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))
Kb = format(K, 'b')
f = lambda x: sum(a ^ x for a in A)
table = [f(2**i) - f(0) for i in range(42)]
candy = {i: x for i, x in enumerate(table) if x > 0 and 2 ** i <= K}
if candy:
    mask = [K]
    for i in range(len(Kb) - 1, -1, -1):
        if K & (1 << i):
            mask += [K ^ (1 << i) | ((1 << i) - 1)]
    res = 0
    for m in mask:
        tmp = 0
        for b in range(42):
            if m & (1 << b) and b in candy:
                tmp += candy[b]
        res = max(res, tmp)
    print(res + f(0))
else:
    print(f(0))

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

int N,K;
int arr[105];
int dp[100005];


int solve(int val)
{
    int &ret=dp[val];
    if(ret!=-1)return ret;
    ret=0;
    for(int i=0;i<N;i++){
        if(arr[i]<=val)
            ret=ret||!solve(val-arr[i]);
    }
    return ret;
}


int main()
{
    cin>>N>>K;
    for(int i=0;i<N;i++)
        cin>>arr[i];
    memset(dp,-1,sizeof(dp));
    int ans=solve(K);
    if(ans) cout<<"First";
    else cout<<"Second";
    return 0;
}


Measured memory_bytes: 5376
#include<bits/stdc++.h>  
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(int i = a; i <=b; i++)
#define rep2(i,a,b) for(int i = a; i>=b; i--)
#define PB push_back 
#define MP make_pair
#define db long double
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define cases int testcases;cin>>testcases; while(testcases--)
#define INF 2000000000
const double PI = acos(-1);
const int N = 100005;
#define eps 1e-6
#define MOD 1000000007
  int32_t main() 
  {
    IOS




        int n;
        cin >> n;

        int arr[n+1];
        int a = n + 1;

        int ans =0;

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

          a = min(a,arr[i]);
          if(a == arr[i]) ans++;
        }

        cout << ans;
    return 0;
      }
        

Measured memory_bytes: 1792
x,k,d=map(int,input().split())
x=abs(x)
ans=1
minb=1
if k%2==0:ans=0  #偶数

semin=x//d #最小に行くための個数
if semin%2==0:minb=0 #最小に行くための個数が偶数

if semin>k:print(abs(x-k*d))
else:
  if ans==minb:
    print(abs(x-d*semin))
  else:
    print(abs((x-(d*semin))-d))

Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const int mod = 1e9 + 7;

const int m = 2019;

int main()
{

    int x;
    cin >> x;
    int ans;
    ans = pow(x, 3);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3248
#include<bits/stdc++.h>
using namespace std;
typedef  long long int ll;
const ll mod = 1e9+7;
const ll mod1 = 998244353;
#define rep(i,a,b) for(ll i=a;i<b;i++)

//*********Debugger template starts***********************//
#define n_l '\n'
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; cout << to_string(__VA_ARGS__) << endl
template <typename T, size_t N> int SIZE(const T (&t)[N]){ return N; } template<typename T> int SIZE(const T &t){ return t.size(); } string to_string(const string s, int x1=0, int x2=1e9){ return '"' + ((x1 < s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c){ return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1=0, int x2=1e9){ string t = ""; for(int __iii__ = min(x1,SIZE(b)),  __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__){ t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if(l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if(e != l){ if(rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else{ t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if(l_v_l_v_l == 0) res += n_l; return res; } void dbgm(){;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgm(T...); }
#define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cout << endl
//*********Debugger template ends ***********************//

void swap(ll &a , ll &b){
    ll t = a;
    a = b;
    b = t;
}

ll min(ll a, ll b){
    if(a<b)return a;
    return b;
}

ll max(ll a, ll b){
    if(a>b)return a;
    return b;
}

 ll pow(ll a, ll b) {
    a %= mod;
    ll ans = 1;
    while (b > 0) {
        if (b & 1)
            ans = ans * a % mod;
        a = a * a % mod;
        b /= 2;
    }
    return ans;
}




int main(){
   
  ios_base :: sync_with_stdio(0);
  cin.tie(0);
  ll n;
  cin>>n;
  ll a[n];

  ll sum = 0 ;
  rep(i, 1 , n+1){
    if((i)%3 != 0 && (i)%5 != 0 ){
        sum += i;
    }
  }
  cout<<sum;
}


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

int main()
{
	int n;
	cin >> n;
	vector<int> hs(n);
	for (auto &&h : hs)
	{
		cin >> h;
	}

	if (n == 1)
	{
		cout << 0 << endl;
		return 0;
	}

	int ans = 0;

	for (int i = 0, tmp = 0; i < n - 1; i++)
	{
		if (hs[i] >= hs[i + 1])
		{
			tmp++;
		}
		else
		{
			ans = max(ans, tmp);
			tmp = 0;
		}
		if (i == n - 2)
		{
			ans = max(ans, tmp);
		}
	}

	cout << ans << endl;

	return 0;
}

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

struct Mo {
    vector<int> left, right, index;
    int window;
    int nl, nr, ptr;
    
    vector<int> a; // input
    vector<int> res; // output
    /* 問題ごとに書き換える */
    vector<int> count;
    int sum;
    
    
    Mo(int n, int q) {
        window = (int)sqrt(n); nl = 0; nr = 0; ptr = 0;
        left.resize(q);
        right.resize(q);
        index.resize(q); iota(index.begin(), index.end(), 0);

        a.resize(n);
        res.resize(q);
        /* 問題ごとに書き換える */
        count.assign(n, 0);
        sum = 0;
    }

    /* 問題ごとに書き換える */
    void add(int id) { if (count[a[id]]++ == 0) sum++; return; }
    void del(int id) { if (--count[a[id]] == 0) sum--; return; }
    
    /* culculation */
    void next() {
        int i = index[ptr++];
        while (left[i] < nl ) add(--nl);
        while (nr < right[i]) add(nr++);
        while (nl < left[i] ) del(nl++);
        while (right[i] < nr) del(--nr);
        res[i] = sum;
    }

    /* query sort ans culculation */
    void build() {
        sort(index.begin(), index.end(), [&](int a, int b) {
            if (left[a] / window != left[b] / window) return left[a] < left[b];
            if((left[a] / window) % 2) return right[a] > right[b];
            return right[a] < right[b];
        } );
        for (int i = 0; i < (int)index.size(); i++) next();
    }
};

int n, q, x, l, r;

int main() {
    scanf("%d %d", &n, &q);
    Mo mo(n, q);
    for (int i = 0; i < n; i++) { scanf("%d", &x); mo.a[i] = --x; }
    for (int i = 0; i < q; i++) { scanf("%d %d", &l, &r); mo.left[i] = --l; mo.right[i] = r; }

    mo.build();
    for (int i = 0; i < q; i++) printf("%d\n", mo.res[i]);
    return 0;
}

Measured memory_bytes: 15500
N = gets.to_i
a = gets.split(' ').map(&:to_i)

o = 0
four = 0
a.each do |ai|
  if ai.odd?
    o += 1
  elsif ai % 4 == 0
    four += 1
  end
end

if o <= four || 2 * four + 1 == N
  print 'Yes'
else
  print 'No'
end

Measured memory_bytes: 8452
#include<iostream>
#include <string.h>

using namespace std ;
int n ,m ;
int Map[11][10001];
int  Max ;


void ral(int r)
{
	for (int i=0;i<m;i++)
		Map[r][i] = Map[r][i] ^ 1; 
}

int cal ()
{
	int Sum = 0 ;
	for (int i=0;i<m;i++)
	{
		int count = 0 ;
		for (int j=0;j<n;j++)
			if (Map[j][i] == 0)
				count ++ ;
		Sum += max (count , n-count);
	}
	return Sum ;
}

void  dfs ( int r )
{
	if (r == n )
	{
		Max= max (Max , cal());
	}	
	else 
	{
		ral(r) ;
		dfs (r+1);
		ral(r);
		dfs (r+1);
	}
	
 } 
int main ()
{
	while (cin >> n >> m && m &&n)
	{
		int Count = 0;
		for (int i=0;i<n;i++)
			for (int j=0 ;j<m;j++)
			{
				cin >> Map[i][j];
				if (Map[i][j] == 0)
					Count ++ ;
			}
					
		Max = Count;
		dfs(0);
		cout <<Max<<endl ;		
	}
 } 


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

int main(){
  
  int a,b,c;
  cin >> a >> b >> c;
  
  if( a == b ){
    
    cout << c << endl;
    
  }
  
  else if( b == c ){
    
    cout << a << endl;
    
  }
  
  else{
    
    cout << b << endl;
    
  }
  
}

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

int main()
{
    int t;

    int ans;
    int n,m;
    scanf("%d",&t);
    while(t--){
        scanf("%d%d",&m,&n);
        if(n*n+m*m<=1){
            printf("C\n");
            continue;
        }
        int x=sqrt(m*m+n*n+0.5);
        ans=0;

        for(int i=-x;i<=x;i++){
            for(int j=-x;j<=x;j++){
                int p=i*m+j*n;
                int q=i*n-j*m;
                int z=i*i+j*j;
                if(z&&p%z==0&&q%z==0){
                    ans++;
                }
            }
        }
        if(ans==8){
            printf("P\n");
        }
        else{
            printf("C\n");
        }
    }
    return 0;
}

Measured memory_bytes: 1168
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

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

//vector出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){
  o<<"{";
  for(int i=0;i<(int)v.size();i++) o << (i>0?", ":"") << v[i];
  o<<"}";
  return o;
}

ll const mod =1e9+7;
int main() {
  int N; cin >> N;

  ll t=1,a=1,x,y;
  vector<vector<int>> TA(N,vector<int>(2));
  rep(i,N) {
    cin >> x >> y;
    ll tt = max({(a+y-1)/y, (t+x-1)/x}); 

    a = tt*y;
    t = tt*x;
    
  }
  cout << t+a << endl;
}

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

bool checkForWalls(string s, int start, int end) {
  for(int i=start; i<end; i++){
    if(s[i] == '#' && s[i+1] == '#') return true;
  }
  return false;
}

bool checkEmpty(string s, int start, int end) {
  for(int i=start; i<=end; i++){
    if(s[i-1] == '.' && s[i] == '.' && s[i+1] == '.') return true;
  }
  return false;
}

int main(){
	int n, a, b, c , d;
	cin >> n >> a >> b >> c >> d; 
  a--; b--; c--; d--;
	string s; 
	cin >> s; 

  if(checkForWalls(s, a, c) || checkForWalls(s, b, d)) {
    cout << "No" << endl;
    return 0;
  }
	
  if (c < d){
    cout << "Yes" << endl;
    return 0;
  }

  cout << (checkEmpty(s, b, d) ? "Yes" : "No") << endl;
  return 0;
}

/* 
  First we check if :
  - there are two consecutive walls between A .. C. If there is, then "No"
  - there are two consecutive walls between B .. D. If there is, then "No"
  
  We check if :
  - C < D, then the answer is always possible
  - else :
      Find if there are three consecutive empty space between B .. D. If there is, then "Yes"
      else it's a "No"

*/

Measured memory_bytes: 3460
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>
using Int = long long;
constexpr Int inf = 1e18;
int main(){
    int N,M; std::cin >> N >> M;
    std::string s; std::cin >> s;
    std::vector<std::vector<int>>edge(N + 1);
    for(int i = 0; i + 1 < edge.size(); ++i)
        edge[i + 1].emplace_back(i);
    for(int i = 0; i + 1 < edge.size(); ++i){
        int nxt = std::min(N,i + M);
        edge[i].emplace_back(nxt);
    }
    std::vector<Int>d(N + 1,inf);
    std::vector<Int>memo(N + 1,inf);
    std::priority_queue<std::tuple<Int, Int,Int>,std::vector<std::tuple<Int,Int,Int>>,std::greater<>>que;
    que.emplace(0,0);
    d[0] = 0;
    memo[0] = 0;
    while(not que.empty()){
        Int k,cv,org;
        std::tie(k,cv,org) = que.top(); que.pop();
        if(d[cv] < k ) continue;
        for(auto nxt : edge[cv]){
            bool is_virtual = nxt < cv;
            if(is_virtual){
                if(d[nxt] > d[cv]){
                    d[nxt] = d[cv];
                    memo[nxt] =  org;
                    que.emplace(d[nxt],nxt,org);
                } else if(d[nxt] == d[cv] && memo[nxt] > org && nxt != org)
                    memo[nxt] = org;
            } else if(s[cv] != '1') {
                if(d[nxt] > d[cv] + 1){
                    d[nxt] = d[cv] + 1;
                    memo[nxt] = cv;
                    que.emplace(d[nxt],nxt,cv);
                } else if(d[nxt] == d[cv] + 1 && memo[nxt] > cv){
                    memo[nxt] =  cv;
                }
            }
        }
    }
    std::vector<std::string> ans;
    int cpos = N;
    if(d[N] != inf){
        while(cpos != 0){
            ans.push_back(std::to_string(cpos - memo[cpos]));
            cpos = memo[cpos];
        }
        std::reverse(ans.begin(),ans.end());
        for(auto s : ans)
            std::cout << s << std::endl;
    } else {
        puts("-1");
    }
}



Measured memory_bytes: 10548
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mxn= 5e5+5;
// check for forloop
// intialize variable
// overflow
// go for easy solution
#define mod 1000000007
ll INF = 1000000000000000005LL;
#define endl '\n'
void rishabh(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int main(){
    rishabh();
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    if((a<=0&&0<=b)||(c<=0&&0<=d))
    cout<<max({a*c,a*d,b*c,b*d,0LL});
    else cout<<max({a*c,a*d,b*c,b*d});
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
string ss[9]={" ","SUN","MON","TUE","WED","THU","FRI","SAT"};
int main(){
	string s;
	cin>>s;
	for(int i=1;i<=7;i++)
		if(s==ss[i]){ 
			cout<<7-(i-1)<<endl; 
			return 0; 
		}
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
class Program
{
    public static void Main()
    {
        int K = int.Parse(Console.ReadLine());
        String[] input = Console.ReadLine().Split();
        int A = int.Parse(input[0]);
        int B = int.Parse(input[1]);
        bool flag = false;
        for (int i = A; i <= B; i++)
        {
            if (i % K == 0) flag = true;
        }
        if (flag) { Console.WriteLine("OK"); }
        else { Console.WriteLine("NG"); }
    }
}

Measured memory_bytes: 27536
#include<iostream>
using namespace std;
int main()
{
	long long int zong, ans=0, h, l, now, yu, c;
	cin>>zong>>l>>h;
	yu=zong%(h+l);
	now=zong/(h+l);
	ans=now*l;
	if(yu<=l)
	{
		ans+=yu;
	}
	else
	{
		ans+=l;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define NIL -1

int F[44];

int main()
{
  int n,i;

  scanf("%d",&n);

  for(i = 0 ; i <= n ; i++) //データを初期化
    {
      F[i] = NIL;
    }

  printf("%d\n",fib(n));
  
  return 0;
}

int fib(int n)
{
  if(n == 0 || n == 1) return F[n] = 1;
  else if(F[n] != NIL) return F[n];
  else return F[n] = fib(n-1) + fib(n-2);
}



Measured memory_bytes: 2052