akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

void chmin(int& a, int b){
    a = min(a, b);
}

int main(){
    int N, A[200000];
    cin >> N;
    for(int i=0; i<N; i++) cin >> A[i];

    static int dp[200001][5];
    for(int i=0; i<=N; i++) for(int j=0; j<=4; j++) dp[i][j] = 1e9;
    dp[0][0] = 0;

    for(int i=0; i<N; i++){
        int prv = dp[i][0];
        for(int j=0; j<=4; j++){
            chmin(prv, dp[i][j]);
            int diff;
            if(j==0 || j==4){
                diff = A[i];
            }else if(j==1 || j==3){
                diff = (A[i] == 0 ? 2 : A[i]%2);
            }else{
                diff = (A[i]+1)%2;
            }
            chmin(dp[i+1][j], prv + diff);
        }
    }

    int ans = 1e9;
    for(int j=0; j<=4; j++) chmin(ans, dp[N][j]);
    cout << ans << endl;
    return 0;
}

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

 using namespace std;
 
 int main(){ 
        int N;
        scanf("%d",&N);
        if(N == 1){
       printf("Hello World"); 
      }else{
  int A , B;
scanf("%d%d",&A,&B);
       printf("%d",A+B); 
     }
  }

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

using namespace std;


int main(){
	#ifndef ONLINE_JUDGE  
    freopen("i.txt", "r", stdin); 
    freopen("o.txt", "w", stdout); 
    #endif
    string s="ACL";
    int n;
    cin>>n;
    string ans="";
    for(int i=0;i<n;i++){
    	ans+=s;
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 3548
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<cstring>
#include<complex>
#include<cmath>
#include<algorithm>
#include<list>
#include<functional>
#define mp make_pair
#define X first
#define Y second
#define INF 1987654321
#define PI 3.14159265358979323846264
#define MOD 1000000007LL
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset(a,0,sizeof(a));
#define MEM_1(a) memset(a,-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef complex<double> base;
ll POW(ll a, ll b) { if (b == 0)return 1; if (b == 1)return a; if (b & 1)return (a*POW(a, b - 1)) % MOD; ll t = POW(a, b / 2); return (t*t) % MOD; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[] = { 0,-1,1,0 }, dy[] = { 1,0,0,-1 };//동북남서
int ddx[] = { 0,0,1,1,1,-1,-1,-1 }, ddy[] = { 1,-1,1,0,-1,1,0,-1 };

char s[100005];
int main()
{
	int ans = 0;
	scanf("%s", s);
	for (int i = 1; s[i]; i++)
		if (s[i] != s[i - 1])ans++;
	printf("%d", ans);
}

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

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define llrp(i,n) for(long long i=0;i<n;i++)
#define llrep(i,m,n) for(long long i=m;i<=n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if
#define vcin(a); rp(i,a.size()){cin>>a[i];}
#define vcout(a); rp(i,a.size()){cout<<a[i]<<endl;}
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef string S;
typedef pair<int,int> P;

bool isOK(int index, int key,vi a) {
    if (a[index] >= key) return true;
    else return false;
}

int binary_search(int key,vi a) {
    int left = -1;
    int right = (int)a.size();
    while (right - left > 1) {
        int mid = left + (right - left) / 2;
        
        if (isOK(mid, key,a)) right = mid;
        else left = mid;
    }
    return right;
}

int modpow(int a,int b,int p){
    if(b==0){
        return 1;
    }elif(b%2==0){
        return modpow((a*a)%p,b/2,p);
    }else{
        return (a*modpow(a,b-1,p))%p;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    if(n<=m){
        if(m>0&&n<0){
            cout << min(abs(m+n)+1,m-n) << endl;
        }else{
            cout << m-n << endl;
        }
    }elif(n>0&&m<0){
        if(-n<m){
            cout << n+m+1 << endl;
        }else{
            cout << -n-m+1 << endl;
        }
    }elif(n<0&&m<0){
        cout << n-m+2 << endl;
    }elif(n>0&&m>0){
        cout << n-m+2 << endl;
    }else{
        if(n==0){
            cout << -m+1 << endl;
        }elif(m==0){
            cout << n+1 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
n, p = map(int, input().split())
s = list(map(int, list(input())))

if p in [2, 5]:
    ans = 0
    for i, x in enumerate(s):
        if x % p == 0:
            ans += i + 1
    print(ans)
    exit()

x = [0] * p
x[0] = 1
temp = 0
d = 1
for i in range(n-1, -1, -1):
    temp = (temp + s[i] * d) % p
    x[temp] += 1
    d = (d * 10) % p

ans = 0

for z in x:
    ans += z * (z-1) // 2

print(ans)


Measured memory_bytes: 6560
#include<cstdio>
using namespace std;
int main(){
    char upper_alpha[26], lower_alpha[26], alpha_count[26] = {}, upper_alphabet, lower_alphabet, sen;
    int i, j;

    i = 0;
    upper_alphabet = 'A';
    lower_alphabet = 'a';
    while(i < 26){
        upper_alpha[i] = upper_alphabet;
        lower_alpha[i] = lower_alphabet;
        i++;
        upper_alphabet++;
        lower_alphabet++;
    }

    i = 0;
    while ( scanf("%c", &sen) != EOF ){
        j = 0;
        while(j < 26){
            if (sen == upper_alpha[j] || sen == lower_alpha[j]) alpha_count[j]++;
            j++; 
        }
        i++;
    }

    i = 0;
    while(i < 26){
        printf("%c : %d\n", lower_alpha[i], alpha_count[i]);
        i++;
    }
    return 0;
}


Measured memory_bytes: 2616
import sys
sys.setrecursionlimit(10 ** 6)

N = int(input())

edges = [[] for _ in range(N)]

for i in range(N - 1):
    a, b = map(int,input().split())
    edges[a - 1].append([b - 1, i])

colors = [-1] * (N - 1)

def func(a, p_color=-1):
    color = 1
    for b, i in edges[a]:
        if color == p_color:
            color += 1
        colors[i] = color
        func(b, color)
        color += 1

func(0, -1)

print(max(colors))
for c in colors:
    print(c)

Measured memory_bytes: 81880
package main

import (
	"fmt"
	"math"
)

func main() {
	var N, sum, w, s int
	fmt.Scan(&N)
	a := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&w)
		sum += w
		a[i] = w
	}
	m := math.MaxInt64
	for i := 0; i < N-1; i++ {
		s += a[i]
		m = min(m, abs(sum-2*s))
	}
	fmt.Println(m)
}
func abs(a int) int {
	return int(math.Abs(float64(a)))
}
func min(a, b int) int {
	if b < a {
		return b
	}
	return a
}

Measured memory_bytes: 6144
# frozen_string_literal: true

s = gets.chomp
n = s.chomp.size
even = odd = 0

0.step(n - 1, 2) do |i|
  if s[i] == '1'
    even += 1
  else
    odd += 1
  end
end

1.step(n - 1, 2) do |i|
  if s[i] == '0'
    even += 1
  else
    odd += 1
  end
end

puts even < odd ? even : odd

Measured memory_bytes: 1916
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <map>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()

using namespace std;

typedef long long ll;

int N, X[100005];
ll ans, A, B;

int main() {
  scanf("%d %lld %lld", &N, &A, &B);
  rep(i, 0, N) scanf("%d", &X[i]);
   
  rep(i, 1, N) ans += min<ll>((X[i]-X[i-1])*A, B);
  
  printf("%lld", ans);
  return 0;

}

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

int main() {

  int N , M ;
  cin >> N >> M ;
  vector<ll> A(N) ;
  rep(i,N) cin >> A.at(i) ;
  ll ans = 0 ;
  priority_queue<int> pq  ;
  rep(i,N) pq.push(A.at(i)) ;
  rep(i,M) {
    ll B = pq.top() / 2 ;
    pq.pop()  ;
    pq.push(B);
  }
  rep(i,N){
    ans += pq.top() ;
    pq.pop();
  }
  cout << ans <<endl ;
}

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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

int N, K, L;
int p[100010], q[100010];
int r[100010], s[100010];
const int MAX_N = 200010;

struct UnionFind {
    int par[MAX_N]; // 親
    int depth[MAX_N]; // 木の深さ


    // n要素で初期化
    void init(int n) {
        rep(i, 0, n) {
            par[i] = i;
            depth[i] = 0;
        }
    }

    // 木の根を求める
    int find(int x) {
        if(par[x] == x) return x;
        else return par[x] = find(par[x]);
    }

    // xとyの属する集合を併合
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if(x == y) return;

        if(depth[x] < depth[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if(depth[x] == depth[y]) depth[x]++;
        }
    }

    // xとyが同じ集合に属するか否か
    bool same(int x, int y) {
        return find(x) == find(y);
    }
};


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    UnionFind uf1, uf2;
    cin >> N >> K >> L;
    uf1.init(N);
    uf2.init(N);

    rep(i, 0, K) {
        cin >> p[i] >> q[i];
        uf1.unite(--p[i], --q[i]);
    }

    rep(i, 0, L) {
        cin >> r[i] >> s[i];
        uf2.unite(--r[i], --s[i]);
    }

    map<pair<int, int> ,int> mp;
    rep(i, 0, N) {
        mp[pair<int, int>(uf1.find(i), uf2.find(i))]++;
    }
    rep(i, 0, N) {
        cout << mp[pair<int, int>(uf1.find(i), uf2.find(i))] << " ";
    }
    cout << endl;

}


Measured memory_bytes: 16768
#include <iostream>

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    
    int index;
    for(int n=0; n<N; n++) {
        int A;
        cin >> A;
        if(A==1) {
            index=n;
        }
    }
    
    int ans=0;
    if(index+1<=K || N-index<=K || (index%(K-1)+(N-index-1)%(K-1))%(K-1)==0) {
        ans = (N-K)/(K-1) + 1;
        if((N-K)%(K-1)!=0) {
            ans++;
        }
    } else {
        ans += index/(K-1);
        ans += (N-index-1)/(K-1);
        if(index%(K-1)!=0) {
            ans++;
        }
        if((N-index-1)%(K-1)!=0) {
            ans++;
        }
    }
    
    cout << ans << endl;

    return 0;
    
}

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

int main() {
  int X;
  cin >> X;
  int Y = X/100;
  int Z = X%100;
  if(Y*5 >= Z){
    cout << 1 << endl;
    return 0;
  }
  cout << 0 << endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

long long power(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

vector<vector<int> >adj;

pair<int,int> dis[100005][11];

vector<pair<int,pair<int,int> > >fi[12];
int n;

void bfs()
{
    queue<int>qq;
    for(int i=10;i>=1;i--)
    {
        for(auto j:fi[i])
        {
            if(dis[j.first][i].first<j.second.first)
                dis[j.first][i]=j.second;
        }
        for(int j=1;j<=n;j++)
        {
            if(dis[j][i].first)
            {
               qq.push(j);
            }
        }
        while (!qq.empty())
        {
            int z=qq.front();
            qq.pop();
            for(auto j:adj[z])
            {
                if(dis[j][i-1].first<dis[z][i].first)
                    dis[j][i-1]=dis[z][i];
            }
        }        
    }
}

signed main()
{

ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int m;
    cin>>n>>m;
    int x,y;
    adj.resize(n+1);
    for(int i=0;i<m;i++)
    {
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    int q;
    cin>>q;

    int cnt=0;
    
    while (q--)
    {
        ++cnt;
        int v,d,c;
        cin>>v>>d>>c;        
        dis[v][d]={cnt,c};
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=10;j++)
        {
            if(dis[i][j].first)
            {
                fi[j].push_back({i,dis[i][j]});
            }
        }
    }    
    bfs();
    for(int i=1;i<=n;i++)
    {
        int mx=0;
        int ind=0;
        for(int j=0;j<=10;j++)
        {
            if(dis[i][j].first>mx)
            {
                mx=dis[i][j].first;
                ind=dis[i][j].second;
            }
        }
        cout<<ind<<'\n';
    }

} 
    
 

Measured memory_bytes: 30688
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
using namespace std;
using ll = long long;
int main()
{
	ll a, b = 0, c = 0, d = 0;
	ll l;
	ll memo[100][100] = {};
	char C[100][100] = {};
	ll r, sy, sx, gy, gx;
	queue<int> x, y;
	cin >> c;
	cin >> r;
	//cin >> sy;
	//cin >> sx;
	sy = 1;
	sx = 1;
	//cin >> gy;
	//cin >> gx;
	for (int i = 0; i < c; i++)
	{
		for (int j = 0; j < r; j++)
		{
			cin >> C[i][j];
			if (C[i][j] == '.')
			{
				d++;
			}
		}
	}
	for (int i = 0; i < c; i++)
	{
		for (int j = 0; j < r; j++)
		{
			memo[i][j] = 1000000;
		}
	}
	x.push(sx - 1);
	y.push(sy - 1);
	memo[sy - 1][sx - 1] = 0;
	while (!x.empty())
	{
		a = x.front();
		x.pop();
		b = y.front();
		y.pop();
		//if (C[b][a]=='.')
		{
			if (C[b + 1][a] == '.'&&memo[b + 1][a] > memo[b][a] + 1)
			{
				x.push(a);
				y.push(b + 1);
				memo[b + 1][a] = memo[b][a] + 1;
			}
			if (C[b - 1][a] == '.'&&memo[b - 1][a] > memo[b][a] + 1)
			{
				x.push(a);
				y.push(b - 1);
				memo[b - 1][a] = memo[b][a] + 1;
			}
			if (C[b][a + 1] == '.'&&memo[b][a + 1] > memo[b][a] + 1)
			{
				x.push(a + 1);
				y.push(b);
				memo[b][a + 1] = memo[b][a] + 1;
			}
			if (C[b][a - 1] == '.'&&memo[b][a - 1] > memo[b][a] + 1)
			{
				x.push(a - 1);
				y.push(b);
				memo[b][a - 1] = memo[b][a] + 1;
			}


		}





	}
	/*for (int i = 0; i < c; i++)
	{
		for (int j = 0; j < r; j++)
		{
			cout << setw(8) << memo[i][j];
		}
		cout << endl;

	}*/
	if (memo[c-1][r-1] == 1000000)
	{
		cout << -1 << endl;

	}
	else
	{
		cout << d-memo[c - 1][r - 1]-1 << endl;

	}


	//cout << c + d << endl;

	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
    using namespace std;
    int main()
    {
    int n,k;
    cin>>n>>k;
     int z=n/k;
    long long ans=1ll*(z)*(z)*(z);
      int cnt=0;
      if(k&1){cout<<ans;return 0;}
    for(int i=1;i<=n;i++)if((i%k)==k/2)cnt++;
      ans+=1ll*cnt*cnt*cnt;
      cout<<ans;
    }


Measured memory_bytes: 256
#include <cstdio>

const int N = 100000;

int n, m, p[N], d[N];

int find(int u)
{
    if (p[u] == u) {
        return u;
    }
    int r = find(p[u]);
    d[u] += d[p[u]];
    p[u] = r;
    return r;
}

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; ++ i) {
        p[i] = i, d[i] = 0;
    }
    while (m --) {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        a --;
        b --;
        int pa = find(a);
        int pb = find(b);
        if (pa == pb) {
            if (d[b] - d[a] != c) {
                puts("No");
                return 0;
            }
        } else {
            p[pb] = pa;
            d[pb] = c - d[b] + d[a];
        }
    }
    puts("Yes");
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <queue>
#include <iomanip>


using namespace std;
 

int main() {

      int N;
      long sum;
      cin >> N;
      sum = 0;
      for(int i = 1 ; i <= N ; i++){
            
            if((i % 3 != 0) & (i % 5 != 0)){
                  
                  sum += i;
            }
      } 
      cout << sum;
      return 0;
}

Measured memory_bytes: 3592
#include <iostream>

using namespace std;

#define ll long long int

const int mx = 1e5+1 , inf = 1e9;

ll n,e,t;
ll x[mx];
ll dp[mx];
ll mn=inf;

ll ptr=-1;

int main()
{
    cin >> n >> e >> t;
    e*=2;
    t*=2;
    for(int i=0;i<n;i++)
    {
        cin >> x[i];
        x[i]*=2;
    }

    for(int i=0;i<n;i++)
    {
        while(x[ptr+1]<x[i]-t/2)
        {
            ptr++;
            if(ptr>0)
                mn=min(mn, dp[ptr-1]-2*x[ptr]);
            else
                mn=min(mn, 0-2*x[ptr]);
        }
        if(mn==inf)
        {
            dp[i]=t;
            continue;
        }
        dp[i]=mn+2*x[i];

        if(ptr>=0)
            dp[i]=min(dp[i],dp[ptr]+t);
    }

    cout << (dp[n-1] + e)/2;

    return 0;
}




Measured memory_bytes: 1792
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>

int main() {
  size_t N;
  scanf("%zu", &N);

  std::vector<std::pair<int, int>> a(2*N);
  for (size_t i=0; i<N; ++i) {
    scanf("%d", &a[i].first);
    a[i].second = -1;
  }

  for (size_t i=0; i<N; ++i) {
    scanf("%d", &a[N+i].first);
    a[N+i].second = 1;
  }

  std::sort(a.begin(), a.end());

  constexpr intmax_t mod=1e9+7;
  intmax_t res=1, cur=0;
  for (size_t i=0; i<2*N; ++i) {
    if (cur != 0 && ((cur < 0) != (a[i].second < 0))) {
      res = res*std::abs(cur) % mod;
    }
    cur += a[i].second;
  }
  printf("%jd\n", res);
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://atcoder.jp/contests/abc155/tasks/abc155_b>
 問題文============================================================
 B - Papers, Please
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N; cin >> N;
    for(int i = 0; i < N;i++){
        ll A; cin >> A;
        if(A%2 == 1) continue;
        if(A%3 == 0 || A%5 == 0) continue;
        return "DENIED";
    }
    return "APPROVED";
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<string>() << endl;
    return 0;
}


Measured memory_bytes: 256
use proconio::marker::Chars;
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        s: Chars
    };

    let mut v = vec![0; 2019];
    v[0] = 1;

    let mut ans = 0;
    let mut r = 0;
    for c in s {
        let c = c.to_digit(10).unwrap();
        r *= 10;
        r += c;
        r %= 2019;
        if v[r as usize] > 0 {
            ans += v[r as usize];
        }

        v[r as usize] += 1;

        let mut v2 = vec![0; 2019];
        for i in 0..2019 {
            if v[i] > 0 {
                v2[i * 10 % 2019] = v[i];
            }
        }
        v = v2;
    }

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


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

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

int main()
{
    int N;
    cin >> N;
    vector<long long> T(N), A(N);
    REP(i, N) cin >> T[i] >> A[i];

    long long ans_T = T[0], ans_A = A[0];
    FOR(i, 1, N){
        long long n = max((ans_T+T[i]-1)/T[i], (ans_A+A[i]-1)/A[i]);
        ans_T = n*T[i];
        ans_A = n*A[i];
    }
    cout << ans_T+ans_A << endl;

    return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

struct Tree{
  int num;
  vector<Tree> chd;
  Tree():num(0){
  }

  bool operator<(const Tree& rhs)const{
	return num < rhs.num;
  }
};

void solve(Tree& t){
  if(SZ(t.chd) == 0){
	t.num = (t.num+1) / 2;
	return;
  }
  for(auto& chd: t.chd)
	solve(chd);
  
  SORT(t.chd);
  for(int i=0;i<=SZ(t.chd)/2;++i)
	t.num += t.chd[i].num;
}

string str;
Tree parse(int a, int b){
  Tree ret;
  if(isdigit(str[a])){
	ret.num = atoi(str.substr(a, b-a).c_str());
	return ret;
  }
  
  int cnt = 0, st;
  for(int i=a;i<b;++i){
	if(str[i] == '['){
	  if(cnt++ == 0) st = i;
	}	
	else if(str[i] == ']')
	  if(--cnt == 0){
		ret.chd.PB(parse(st+1, i));
	  }	
  }
  return ret;
}

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

  int N; cin>>N;
  while(N--){
	cin >> str;
	Tree t = parse(0,SZ(str));
	solve(t);
	cout << t.num << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <unordered_map>
#include <set>

#define ll long long
#define ull unsigned long long
#define eps 10e-10
#define MOD 1000000007

using namespace std;

class Sento
{
private:
	ll n;
	ll t;
	vector<ll> ts;
public:
	Sento(){
		cin >> n >> t;
		ts.resize(n);
		for (int i = 0; i < n; ++i)
		{
			cin >> ts[i];
		}
	}
	void exec(){
		ll sum = t;
		ll end = t;
		for (int i = 0; i < n; ++i)
		{
			if(end > ts[i]){
				sum -= end - ts[i];
			}
			end = ts[i] + t;
			sum += t;
		}
		cout << sum << endl;
	}
};

int main(){
	Sento s = Sento();
	s.exec();
}


Measured memory_bytes: 1792
n,k = map(int,input().split())
li = []
for _ in range(n):
    i = int(input())
    li.append(i)
li.sort()
INF = float('inf')
diff = INF
for i,l in enumerate(li):
    if i + k - 1 > len(li)-1:
        break
    if li[i+k-1] - li[i] < diff:
        diff = li[i+k-1] - li[i]
print(diff)

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

using fint64 = int_fast64_t;
template<fint64 MOD>
struct ModInt{
    fint64 x;
    ModInt():x(0){}
    ModInt(fint64 x):
        x(x>=0?x%MOD:(MOD-(-x)%MOD)%MOD)
        {}
    // 負号
    ModInt operator -() const{
        return ModInt(-x);
    }
    // 加算
    ModInt &operator +=(const ModInt &rhs){
        x+=rhs.x;
        if(x>=MOD) x-=MOD;
        return (*this);
    }
    ModInt operator +(const ModInt &rhs) const{
        return ModInt(*this)+=rhs;
    }
    // 減算
    ModInt &operator -=(const ModInt &rhs){
        x+=MOD-rhs.x;
        if(x>=MOD) x-=MOD;
        return (*this);
    }
    ModInt operator -(const ModInt &rhs) const{
        return ModInt(*this)-=rhs;
    }
    // 乗算
    ModInt &operator *=(const ModInt &rhs){
        x*=rhs.x;
        if(x>=MOD) x%=MOD;
        return (*this);
    }
    ModInt operator *(const ModInt &rhs) const{
        return ModInt(*this)*=rhs;
    }
    // 除算
    ModInt &operator /=(const ModInt &rhs){
        (*this)*=rhs.inverse();
        return (*this);
    }
    ModInt operator /(const ModInt &rhs) const{
        return ModInt(*this)/=rhs;
    }
    // 等号
    bool operator ==(const ModInt &rhs){
        return x==rhs.x;
    }
    bool operator !=(const ModInt &rhs){
        return x!=rhs.x;
    }
    // 累乗
    ModInt pow(fint64 n) const{
        fint64 tmp=x;
        fint64 ret=1;
        while(n>0){
            if(n&1) ret=ret*tmp%MOD;
            tmp=tmp*tmp%MOD;
            n>>=1ll;
        }
        return ModInt(ret);
    }
    // 逆元
    ModInt inverse() const{
        fint64 a=x,b=MOD,s=1,t=0;
        while(b>0){
            fint64 u=a/b;
            a-=u*b;
            s-=u*t;
            swap(a,b);
            swap(s,t);
        }
        return ModInt(s);
    }
    // 入出力
    friend istream &operator >>(istream &lhs,ModInt<MOD> &rhs){
        fint64 x; lhs>>x;
        rhs=ModInt<MOD>(x);
        return lhs;
    }
    friend ostream &operator <<(ostream &lhs,const ModInt<MOD> &rhs){
        return lhs<<rhs.x;
    }
};

int main() {
	const int MOD = 1e9 + 7;
	using mint = ModInt<MOD>;
	int n; cin >> n;
	string s; cin >> s;
	const int N = 2 * n;
	for(int i = 0; i < N; ++i) {
		if(not (i & 1)) s[i] = (s[i] == 'W' ? 'B' : 'W');
	}
	mint l = 0, ans = 1;
	for(int i = 0; i < N; ++i) {
		if(s[i] == 'W') l += 1;
		if(s[i] == 'B') {
			ans *= l;
			l -= 1;
		}
	}
	if(l != 0) ans = 0;
	for(int i = 2; i <= n; ++i) {
		ans *= i;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 640
import sys
input = sys.stdin.readline
from collections import deque

def main():
	n = int(input().strip())
	v = [[] for _ in range(n)]
	for i in range(n):
		v[i] = list(map(int, input().strip().split()))
	l = [-1] * (n+1)
	q = deque()
	q.append((1, 0))
	while len(q) != 0:
		id, d = q.popleft()
		# print("id", id)
		if l[id] != -1:
			# print("b")
			continue
		l[id] = d
		# l[id] = min(d, l[id])
		# print(id, d)
		for i in range(v[id-1][1]):
			q.append((v[id-1][2+i], d+1))
			# if id == 8:
				# print("##", id, v[id-1][2+i])
				# print(repr(q))
	for i in range(1, n+1):
		print(i, l[i])

if __name__ == '__main__':
	main()



Measured memory_bytes: 6040
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
using namespace std;

int main(void){
    int n;
    double a,b,c,d;
    cin>>n>>a>>b>>c>>d;
    
    int x1=ceil(n/a),x2=ceil(n/c);
    if(x1*b<x2*d)cout<<x1*b<<endl;
    else cout<<x2*d<<endl;
    
    
    
    
    
    return 0;
}



Measured memory_bytes: 3252
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <ctype.h>
#include <deque>
#include <queue>
#include <cstring>
#include <set>
#include <list>
#include <map>
#include <random>
#include <unordered_map>
#include <stdio.h>

using namespace std;

typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<bool> vb;
typedef std::vector<string> vs;
typedef std::vector<double> vd;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<int> > vvi;
typedef vector<vvi> vvvi;
typedef vector<vll> vvll;
typedef std::vector<std::pair<int, int> > vpi;
typedef vector<vpi> vvpi;
typedef std::pair<int, int> pi;
typedef std::pair<ll, ll> pll;
typedef std::vector<pll> vpll;

const long long mod = 1000000007;

#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define forn(i, a, b) for(int i = a; i < b; i++)

#define pb push_back
#define mp make_pair
vi a;
vpi o;
ll ans = 0;
const int INF = 1000000000;
class stree {
public:
    vpi t;
    int s;
    void build (vpi & a, int v, int tl, int tr) {
        if(v==1) {
            t.resize(a.size() * 4);
            s = a.size();
        }
        if (tl == tr)
            t[v] = a[tl];
        else {
            int tm = (tl + tr) / 2;
            build (a, v*2, tl, tm);
            build (a, v*2+1, tm+1, tr);
            t[v] = min(t[v*2], t[v*2+1]);
        }
    }
    
    pi get (int v, int tl, int tr, int l, int r) {
        if(l>r) return mp(INF,0);
        if (tl == tr)
            return t[v];
        if(l==tl && r==tr)
            return t[v];
        int tm = (tl + tr) / 2;
        return min(get (v*2, tl, tm, l, min(r,tm)), get (v*2+1, tm+1, tr, max(tm+1,l), r));
    }
};

stree lol;
int n;
void go(int l, int r) {
    pi x = lol.get(1, 0, n-1, l, r);
     int m=x.second;
    ans += (ll)x.first*(ll)(m-l+1) * (ll)(r-m+1);
    if(m>l) go(l,m-1);
    if(m<r) go(m+1,r);
}

int main()
{
//#ifndef ONLINE_JUDGE
//    freopen("input.txt", "rt", stdin);
//    freopen("output.txt", "wt", stdout);
//#endif
    
    scanf("%d", &n);
    a.resize(n);
    forn(i,0,n) {
        scanf("%d", &a[i]);
        o.pb(mp(a[i], i));
    }
    lol.build(o,1,0,n-1);
    go(0,n-1);
    
    cout<<ans;
}



Measured memory_bytes: 58992
import sys,collections,math,random;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
lis = []
for i in range(N):
    a,b = Is()
    lis.append([b,a])
lis = sorted(lis)
t = 0
for e in lis:
    t += e[1]
    if e[0] < t:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 37984
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	var N, M int
	fmt.Sscanf(scanner.Text(), "%d %d", &N, &M)

	ps := make([]int, M)
	ys := make([]int, M)
	for i := 0; i < M; i++ {
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d %d", &ps[i], &ys[i])
	}

	var p2years = make(map[int][]int)
	for i := 0; i < M; i++ {
		p2years[ps[i]] = append(p2years[ps[i]], ys[i])
	}

	var orders = make(map[int]map[int]int)
	for p, years := range p2years {
		sort.Sort(sort.IntSlice(years))

		indexes := make(map[int]int)
		for i, year := range years {
			indexes[year] = i
		}
		orders[p] = indexes
	}

	for i := 0; i < M; i++ {
		fmt.Printf("%06d", ps[i])
		index := orders[ps[i]][ys[i]]
		fmt.Printf("%06d\n", index+1)
	}
}

func indexOf(slice []int, value int) int {
	for i := 0; i < len(slice); i++ {
		if slice[i] == value {
			return i
		}
	}
	return -1
}


Measured memory_bytes: 37120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define rep(i,n) for (int i=0; i<(n); i++)
#define reps(i,s,n) for (int i=(s); i<(n); i++)
#define rep1(i,n) for (int i=1; i<=(n); i++)
#define repr(i,s,n) for (int i=(s)-1; i>=(n); i--)
#define print(a) cout << (a) << endl
#define all(v) v.begin(), v.end()
#define rsort(v) sort(v.rbegin(), v.rend())


int main() {
  int N; ll K;
  cin >> N >> K;
  vector<ll> A(N);
  rep(i,N) {
    cin >> A[i];
  }
  ll b=0,u=1e9;
  while (u-b>1) {
    ll mid = (u+b)/2;
    ll cnt = 0;
    rep(i,N) {
      cnt += (A[i]-1)/mid;
    }
    if (cnt<=K) {
      u = mid;
    } else {
      b = mid;
    }
  }
  print(u);
  return 0;
}

Measured memory_bytes: 4696
n = int(input())
a = list(map(int, input().split()))


a_odd = a[::2]
a_even = a[1::2]

if n % 2 == 0:
    ans = a_even[::-1]
    ans.extend(a_odd)
else:
    ans = a_odd[::-1]
    ans.extend(a_even)

print(*ans)

Measured memory_bytes: 96796
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,pprint,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
now = a[0]-1
for i in range(1,n):
    if now < a[i]:
        now = a[i]-1
    elif now == a[i]:
        continue
    else:
        print('No')
        break
else:
    print('Yes')    


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

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


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	clock_t start = clock();
#endif

	int n,m; cin >> n >> m;
	int a[n];
	f(i,0,n) cin>>a[i];
	int freq[n],num[n];
	fill(freq,freq+n,0); fill(num,num+n,0);
	f(i,0,n) num[--a[i]]++;	
	f(i,0,n) f(j,0,num[i]) if (i-j>=0)
			freq[i-j]++;	
	int cnt = 0;
	f(i,0,n) if (!freq[i])
		cnt++;
	stringstream ss;
	f(_,0,m) {
		int i, x; cin>>i>>x; --i; --x;
		num[a[i]]--;
		if (a[i]-num[a[i]] >= 0 && freq[a[i]-num[a[i]]]==1)
			cnt++;
		if (a[i]-num[a[i]]>=0) freq[a[i]-num[a[i]]]--;
		a[i] = x;
		if (a[i]-num[a[i]] >= 0 && !freq[a[i]-num[a[i]]])
			cnt--;
		if (a[i]-num[a[i]]>=0) freq[a[i]-num[a[i]]]++;
		num[a[i]]++;
		ss << cnt << endl;
	}
	cout << ss.str();

#ifdef LOCAL
	cout << setprecision(12) << (long double)(clock()-start) / CLOCKS_PER_SEC << endl;
#endif
	
	return 0;
}



Measured memory_bytes: 6532
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <limits.h>
#include <float.h>
#include <numeric>
#include <queue>

using namespace std;

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


int main(){
    int N;
    string a, b, c;
    cin >> N;
    cin >> a;
    cin >> b;
    cin >> c;
    int res = 0;
    for(int i = 0; i < N; i++){
        if(a[i] != b[i] && b[i] != c[i] && c[i] != a[i]){
            res += 2;
        }
        else if(a[i] == b[i] && b[i] != c[i]){
            res += 1;
        }
        else if(a[i] == c[i] && c[i] != b[i]){
            res += 1;
        }
        else if(b[i] == c[i] && a[i] != b[i]) {
            res += 1;
        }
    }
    cout << res << endl;

    return 0;
}


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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

ll combi(ll n, ll r);

int main() {
	ll n, p, a;
	ll even = 0;
	ll odd = 0;
	ll ans = 0;
	ll x = 0;
	ll y = 0;
	vector<ll> v1, v2;

	cin >> n >> p;

	REP(i, n) {
		cin >> a;
		
		if (a % 2 == 0) {
			even++;
			v1.push_back(a);
		}
		else {
			odd++;
		}
	}

	if (p == 0) {
		for (int i = 0; i <= even; i++) {
			x += combi(even, i);
		}

		for (int i = 0; i <= odd; i += 2) {
			y += combi(odd, i);
		}

		ans = x * y;
	}
	else {
		for (int i = 0; i <= even; i++) {
			x += combi(even, i);
		}

		for (int i = 1; i <= odd; i += 2) {
			y += combi(odd, i);
		}

		ans = x * y;
	}
	
	cout << ans << endl;
}

ll combi(ll n, ll r)
{
	ll i;
	ll p = 1;

	if (r > n / 2) {
		r = n - r;
	}

	if (n == 0 || r == 0) {
		return 1;
	}

	for (i = 1; i <= r; i++) {
		p = p*(n - i + 1) / i;
	}

	return p;
}

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

int main()
{
    int A, B;
    string S;

    cin >> A >> B;
    cin >> S;

    for (int i = 0; i < S.size(); i++)
    {
        if (i != A && (S[i] - '0' < 0 || 9 < S[i] - '0'))
        {
            cout << "No" << endl;
            return 0;
        }
        else if (i == A && S[A] != '-')
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <ccomplex>
#include <unordered_map>
#include <cstring>
#include <iostream>
#include <numeric>


using namespace std;
#define MAX 100000

int main(){
    int N, i;

    cin >> N >> i;

    int ans;
    ans = N - i + 1;

    cout << ans << endl;

    return 0;

}


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

// Begin Template IO/Utility
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
void dbg_out(){
	cerr<<endl;
}
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T){
	cerr<<' '<< H;
	dbg_out(T...);
}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &V){
	os<<'[';
	for(int i=0;i<(int)V.size();i++)
		os<<V[i]<<",]"[i==(int)V.size()-1];
	return os;
}
template<typename T> istream& operator>>(istream &is, vector<T> &V){
	for(T &x:V)
		is>>x;
	return is;
}
template<typename T, typename U> ostream& operator<<(ostream &os, const pair<T,U> &p){
	os<<'{'<<p.first<<','<<p.second<<'}';
	return os;
}
template<typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){
	is>>p.first>>p.second;
	return is;
}
template<typename T> void minself(T &a, T b){
	a=min(a,b);
}
template<typename T> void maxself(T &a, T b){
	a=max(a,b);
}
// End Template IO/Utility

int main(){
	int K, ans=0;
	cin>>K;
	for(int i=1;i<=K;i++)
		for(int j=1;j<=K;j++)
			for(int z=1;z<=K;z++)
				ans+=__gcd(__gcd(i,j),z);
	cout<<ans;
}


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

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

	for (int j = 0; j < N - 1; j++) {
		if (a[j] == a[j + 1]) {
			j++;
			x++;
		}
	}
	cout << x << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define N 200000
#define SENTINEL 1000000001
long long merge(int[],int,int,int);
long long mergeSort(int[],int,int);
int main(void)
{
  int i;//counter
  int n;//the number of integers
  int arr[N];
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&arr[i]);
  printf("%ld\n",mergeSort(arr,0,n));//mergeSort function returns the total number of inversions
  return 0;
}
long long merge(int arr[],int left,int mid,int right)
{
  long long ret=0;//the number of inversions
  int i,j,k;//counter
  int n1=mid-left;//the number of elements in array l
  int n2=right-mid;//the number of elements in array r
  int *l=(int*)malloc(sizeof(int)*(n1+1));
  int *r=(int*)malloc(sizeof(int)*(n2+1));
  for(i=0;i<n1;i++) l[i]=arr[left+i];
  for(i=0;i<n2;i++) r[i]=arr[mid+i];
  l[n1]=SENTINEL;
  r[n2]=SENTINEL;
  i=0;
  j=0;
  for(k=left;k<right;k++)
    {
      if(l[i]<=r[j])
	{
	  arr[k]=l[i];
	  i++;
	}
      else
	{
	  arr[k]=r[j];
	  j++;
	  ret+=n1-i;//add the number of inversions
	}
    }
  free(l);
  free(r);
  return ret;
}
long long mergeSort(int arr[],int left,int right)
{
  int mid;//separate point of array
  long long ret=0;//the number of inversions
  if(left+1<right)
    {
      mid=(left+right)/2;
      ret+=mergeSort(arr,left,mid);
      ret+=mergeSort(arr,mid,right);
      ret+=merge(arr,left,mid,right);
    }
  return ret;
}
void printArray(int arr[],int n)
{
  int i;//counter
  for(i=0;i<n;i++)
    {
      if(i>0) printf(" ");
      printf("%d",arr[i]);
    }
  printf("\n");
}



Measured memory_bytes: 3032
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define MAX 1e6
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

int main() 
{ 
	string s;
	cin>>s;
	if(s == "ARC") cout<<"ABC"<<endl;
	else cout<<"ARC"<<endl;
	return 0;	
}  


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e5+1;
const int mod=1e9+7;
vector<int>g[N];
#define pb push_back
ll n;
ll dp[N+1][2];

ll add(ll a,ll b)	{return (a + b)%mod; }
ll mul(ll a,ll b) 	{return (1LL*a*b)%mod; }

ll dfs(int u,int par,int color){
	if(dp[u][color]!=-1) return dp[u][color];
	ll mn=1;
	for(auto v:g[u]){
		if(v==par) continue;
		ll temp=dfs(v,u,1);									
		if(color) temp=add(temp,dfs(v,u,0));				
 		mn=mul(mn,temp);
	}
	return dp[u][color]=mn;
}

int main(){
	cin>>n;
	memset(dp,-1,sizeof(dp));
	for(int i=0;i<n-1;i++){
		int u,v;
		cin>>u>>v;
		g[u].pb(v);
		g[v].pb(u);
	}
	cout<<add(dfs(1,-1,1),dfs(1,-1,0))<<endl;
	return 0;
}

Measured memory_bytes: 15616
program exchange
  implicit none
  integer :: a, b, k, i
  read(*,*) a, b, k
  do i = 1, k
    a = (a-mod(a,2))/2
    b = b+a
    call swap(a,b)
  end do
  if (mod(k,2) == 1) call swap(a,b)
  write(*,'(i0,x,i0)') a, b
contains
  subroutine swap(a,b)
    integer, intent(inout) :: a, b
    a = xor(a,b)
    b = xor(a,b)
    a = xor(a,b)
  end
end program exchange

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
ll dp[105][105];
void solve(){
  ll h,w;
  cin>>h>>w;
  vector<string> v(h);
  for(ll i=0;i<h;i++)
    for(ll j=0;j<w;j++)
      dp[i][j]=h*w;
  for(ll i=0;i<h;i++)
    cin>>v[i];
  if(v[0][0]=='#')
    dp[0][0]=1;
  else
    dp[0][0]=0;
  for(ll i=0;i<h;i++)
    for(ll j=0;j<w;j++){
        if(i>0)
          dp[i][j]=min(dp[i][j],dp[i-1][j]+(v[i][j]=='#'&&v[i-1][j]=='.'));
        if(j>0)
          dp[i][j]=min(dp[i][j],dp[i][j-1]+(v[i][j]=='#'&&v[i][j-1]=='.'));
      }
  cout<<dp[h-1][w-1];
}
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll q=1;
  for(ll i=1;i<=q;i++)
    solve();
}

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

#define F first
#define S second
#define ll long long
#define ld long double
#define pb push_back
#define int long long

using namespace std ; 

const int MAXN = 501 * 1001 , MOD = 1e9 + 7 ; 


int dp[50][50] ; 

int32_t main() 
{
	ios::sync_with_stdio(0); 
	cin.tie(0); cout.tie(0);
	int a , b ; 
	cin >> a >> b ; 
	cout << (abs(a-b)<=1?"Brown":"Alice")  << endl ; 
	return 0 ;  
	//for(int i = 0 ; i < 20 ; i ++ , cout << '\n') for(int j = 0 ; j < 20 ; j ++ ) 
	for(int s = 0 ; s <= 40 ; s ++ ) for(int i = 0 ; i <= s ; i ++ ) 
	{	
		int j = s - i ; 
		for(int k = 1 ; 2 * k <= i ; k ++ ) 
			if(!dp[i-2*k][j+k])
				dp[i][j] = 1 ; //, cout << k << endl  ; 
		for(int k = 1 ; 2 * k <= j ; k ++ ) 
			if(!dp[i+k][j-2*k])
				dp[i][j] = 1 ; //  cout << '*' << k << endl ; 
		if(!dp[i][j]) cout << i << ' ' << j << endl ; 
		//	cout << i << ' ' << ' '<< j << ' ' << dp[i][j] << endl ; 
	//	if(i>j){
	//		dp[i][j] = min(dp[i][j],dp[j][i]) ; 
	//	dp[j][i] = min(dp[i][j],dp[j][i]) ; 
	//	}
		//cout << dp[i][j] << ' ' ; 
	}
	for(int i = 0 ; i < 20 ; i ++ , cout << '\n' ) for(int j = 0 ; j < 20 ; j ++ ) cout << dp[i][j] << ' ' ;  
}


Measured memory_bytes: 256
n = gets.chomp.to_i
citys = gets.chomp.split.map(&:to_i)
braves = gets.chomp.split.map(&:to_i)
monster = 0
braves.each_with_index do |brave, i|
  if citys[i] > brave
    monster += brave
  else
    monster += citys[i]
    add_monster = [brave -citys[i], citys[i+1]].min
    monster += add_monster
    citys[i+1] -= add_monster
  end
end

print("#{monster}\n")

Measured memory_bytes: 21532
import java.util.Scanner;
class Main{
public static void main(String[]args){

Scanner sc=new Scanner(System.in);
int X=sc.nextInt();

  int[] num={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
};
  int ans=num[X-1];
  System.out.println(ans);
}
}

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

int main() {
  string s;
  cin >> s;
  
  if(s.at(0) == s.at(1) || s.at(1)== s.at(2)|| s.at(2)==s.at(3)){
    cout << "Bad" << endl;
  }
  else {
    cout << "Good" << endl;
  }
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>
#include <ctype.h>
using namespace std;
string n;
int p,ans;
int main(){
	while(cin>>n){
        ans=0;
		int f=n.size();
        for(p=0;p<f;p++){
		if(p==0&&*n.begin()=='0'){goto se;}else
		if(*n.begin()=='1'){ans++;}else
		if(*n.begin()=='2'){ans+=2;}else
		if(*n.begin()=='3'){ans+=3;}else
		if(*n.begin()=='4'){ans+=4;}else
		if(*n.begin()=='5'){ans+=5;}else
		if(*n.begin()=='6'){ans+=6;}else
		if(*n.begin()=='7'){ans+=7;}else
		if(*n.begin()=='8'){ans+=8;}else
		if(*n.begin()=='9'){ans+=9;}
		n.erase(n.begin());}
	cout<<ans<<endl;
	}
	se:
	return 0;}


Measured memory_bytes: 1204
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<cmath>
#include<map> 
#include<string>
#include<queue>
#include<stack> 
#include<bitset>
#include<list>
#include<set>
#include<utility>
#define IO ios::sync_with_stdio(false)
//#define int long long
using namespace std;
char c[10][10];
int h,w,k;
int main()
{
	IO;
	cin>>h>>w>>k;
	int ans=0;
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			cin>>c[i][j];
		}
	}
	for(int i=0;i<(1<<h);i++)
	{
		for(int j=0;j<(1<<w);j++)
		{
			int num=0;
			for(int ii=0;ii<h;ii++)
			{
				for(int jj=0;jj<w;jj++)
				{
					if(!(i&(1<<ii))&&!(j&(1<<jj))&&c[ii][jj]=='#')num++;
				}
			}
			if(num==k)ans++;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 3660