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

#define int long long
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = INT_MAX / 2;
constexpr int MOD = 1e9 + 7;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vec>;

template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) {
    return stream << p.first << " " << p.second;
}
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}
template <typename T>
T sum_(vector<T> vec, T init = 0) {
    return std::accumulate(all(vec), T(init));
}

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

template <typename T>
void init(vector<vector<T>> m) {
    repall (v, m)
        init(v);
}

template <typename T>
void init(vector<T>& v) {
    rep (i, v.size())
        cin >> v[i];
}

template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) {
    assert(v.size() == w.size());
    rep (i, v.size())
        cin >> v[i] >> w[i];
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------

int tall(int level) { return pow(2, level + 2) - 3; }

int mai(int level, int layer) {
    if (level == 0) return 1;
    if (layer == 1) return 0;
    if (layer <= 1 + tall(level - 1)) return mai(level - 1, layer - 1);
    if (layer == 2 + tall(level - 1))
        return mai(level - 1, tall(level - 1)) + 1;
    if (layer <= 2 + 2 * tall(level - 1))
        return mai(level - 1, tall(level - 1)) + 1 +
               mai(level - 1, layer - 2 - tall(level - 1));
    return 1 + 2 * mai(level - 1, tall(level - 1));
}

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

    int n, x;
    cin >> n >> x;
    print(mai(n, x));

    return 0;
}

Measured memory_bytes: 384
#!/usr/bin/env python
# -*- coding:utf-8 -*-

import numpy as np

N_s, M_s, C_s = input().split()
N = int(N_s)
M = int(M_s)
C = int(C_s)

B = [int(i) for i in input().split()]
A = []
for rows in range(0,N):
    tmp = [int(i) for i in input().split()]
    A.append(tmp)

B_array = np.array(B)
A_array = np.array(A)

val = np.dot(A_array, B_array) + C
print(np.sum(val>0))

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

namespace AGC014
{
    public class A
    {
        private void Run()
        {
            var input = Console.ReadLine().Trim().Split();
            var A = long.Parse(input[0]);
            var B = long.Parse(input[1]);
            var C = long.Parse(input[2]);

            long result = 0;
            while (A % 2 == 0 && B % 2 == 0 && C % 2 == 0)
            {
                var a = B / 2 + C / 2;
                var b = C / 2 + A / 2;
                var c = A / 2 + B / 2;
                A = a;
                B = b;
                C = c;
                result++;

                if (result > 100000)
                {
                    result = -1;
                    break;
                }
            }
            Console.WriteLine(result);
        }

        public static void Main()
        {
            var old = Console.Out;
            using (var writer = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false })
            {
                Console.SetOut(writer);
                new A().Run();
                Console.Out.Flush();
                Console.SetOut(old);
            }
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    cin >> N >> M;
    vvec<int> S(M);
    for(int i=0;i<M;i++){
        int k;
        cin >> k;
        for(int j=0;j<k;j++){
            int a;
            cin >> a;
            a--;
            S[i].push_back(a);
        }
    }
    int ans = 0;
    vec<int> P(M);
    for(int i=0;i<M;i++) cin >> P[i];
    for(int T=0;T<(1<<N);T++){
        bool ok = true;
        for(int i=0;i<M;i++){
            int c = 0;
            for(auto& x:S[i]){
                c += T>>x&1;
            }
            ok &= c%2==P[i];
        }
        ans += ok;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef complex<double> P;
typedef long long ll;
const ll MOD=100000007;
const ll INF=1000000000000LL;
ll dp[10][100001];

// kindªsizeÂ±­ñÌðßÌ
ll dfs(int kind,int size){
    int limit=5;
    if(kind==8||kind==0)limit=3;
    if(size==1)
        return 1;
    if(dp[kind][size]!=INF)
        return dp[kind][size];
    ll sum=1;
    for(int i = 1; i <= min(limit,size-1); i++){
        sum+=(dfs(kind,size-i));
        sum%=MOD;
    }
    return dp[kind][size]=sum;
}

void solve(){
    string str;
    for(int i = 0; i < 10; i++)
        fill(dp[i],dp[i]+100001,INF);
    while(cin>>str&&str!="#"){
        char prv=str[0];
        ll mul=1;
        int size=0;
        for(int i = 0; i < str.size(); i++){
            if(str[i]!=prv){
                mul*=dfs(prv-'0',size);
                mul%=MOD;
                size=1;
                prv=str[i];
            }
            else if(i==str.size()-1){
                mul*=dfs(prv-'0',size+1);
                mul%=MOD;
            }
            else
                size++;
        }
        cout<<mul%MOD<<endl;
    }
}

int main(){

    solve();

    return 0;
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N; 
  vector<int> X(N);
  int sum=0;
  for(int i; i < N; i++){
    cin >> X[i];
    sum+=X[i];
  }
  //sum/Nに最も近い座標
  int P = sum/N + (sum%N)*2/N;
  int stamina=0;
  for(int i; i < N; i++){
    stamina+=(X[i]-P)*(X[i]-P);
  }
  cout << stamina /*<< endl << P*/;
  return 0;
}

Measured memory_bytes: 256
# coding: utf-8
from collections import deque


def solve(*args: str) -> str:
    h, w = map(int, args[0].split())
    S = [[c for c in s] for s in args[1:]]

    total = sum(s.count('.') for s in S)

    Q = deque()
    Q.append((0, 0, 1))

    depth = 0
    while Q:
        x, y, n = Q.popleft()
        if S[y][x] == '.':
            S[y][x] = str(n)
            if (x, y) == (w-1, h-1):
                depth = n
                break

            if 0 < x:
                Q.append((x-1, y, n+1))
            if x+1 < w:
                Q.append((x+1, y, n+1))
            if 0 < y:
                Q.append((x, y-1, n+1))
            if y+1 < h:
                Q.append((x, y+1, n+1))

    return str(total-depth if depth else -1)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 3436
#include<bits/stdc++.h>
#define int long long
using namespace std;
void solve(){
    map<char, char>mp;
    mp['A'] = 'T';
    mp['T'] = 'A';
    mp['C'] = 'G';
    mp['G'] = 'C';
    char c;
    cin >> c;
    cout << mp[c] << endl;
}
main(){
    ios_base::sync_with_stdio(0);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int x,y,a,b,c;
ll p[100001],q[100001],r[100001];
int main(){
    cin>>x>>y>>a>>b>>c;
    rep(i,a) cin>>p[i];
    rep(i,b) cin>>q[i];
    rep(i,c) cin>>r[i];
    sort(p,p+a);reverse(p,p+a);
    sort(q,q+b);reverse(q,q+b);
    sort(r,r+a);reverse(r,r+a);
    vector<ll> v;
    rep(i,x) v.pb(p[i]);
    rep(i,y) v.pb(q[i]);
    rep(i,c) v.pb(r[i]);
    sort(v.begin(),v.end(),greater<ll>());
    ll ans=0;
    rep(i,x+y){
        ans+=v[i];
    }
    cout<<ans<<endl;
    return 0;
}

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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair
using ll  = long long;
using vi  = vector<int>;
using vvi = vector<vi>;
using vs  = vector<string>;
using pii = pair<int,int>;
constexpr ll inf = 1ll<<61;
constexpr ll mod = 1e9+7;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>void add(T &a, const T &b){a += b; a %= mod;}

signed main(){
  int n, q; cin >> n >> q;
  string s; cin >> s;
  vi imos(n+1);
  rep(i,n-1){
    if(s.substr(i,2) == "AC")
      imos[i+1]++;
  }
  rep(i,n){
    imos[i+1] += imos[i];
  }
  dump(imos);
  rep(i,q){
    int l, r; cin >> l >> r; r--; l--;
    int tmp = imos[r]-imos[l];
    cout << tmp << endl;
  }
}


Measured memory_bytes: 1792
#include <stdio.h>

int main (void)
{
    int a[3][3],key=0;
    int i,j;
    for(i=0;i<3;i++)
    {
        scanf("%d %d %d",&a[i][0],&a[i][1],&a[i][2]);
    }
    for(i=1;i<3;i++)
    {
        for(j=1;j<3;j++)
        {
            if(a[i][j]-a[i][j-1]==a[i-1][j]-a[i-1][j-1])
            {
                key++;
            }
        }
    }
    for(i=1;i<3;i++)
    {
        for(j=1;j<3;j++)
        {
            if(a[i][j]-a[i-1][j]==a[i][j-1]-a[i-1][j-1])
            {
                key++;
            }
        }
    }
    if(key==8)
    {
        puts("Yes");
    }else{
        puts("No");
    }
    return 0;
}


Measured memory_bytes: 1632
#include<iostream>
using namespace std;
int pos[1000001];
#include<cmath>
bool done[1000001];
int main()
{
    int n;
    cin>>n;
    int arr[n];
    int ans=n;

    for(int i=0; i<n; i++) {
        cin>>arr[i];
        pos[arr[i]]++;
        
    }
    for(int i=1; i<=1e6; i++) {
        if(pos[i]>1){ans-=pos[i];
        done[i]=true;}
    }
    if(pos[1]==1)
        cout<<1<<endl;
    else if(pos[1]>1)
        cout<<0<<endl;
    else {
        for(int i=0; i<n; i++) {
            if(!done[arr[i]]) {
                int y=arr[i];
                int l=(int)ceil(sqrt(y));
                for(int j=2; j<=l; j++) {
                    if(y%j==0 && j!=y ) {
                        if(pos[j]>0 || pos[y/j]>0) {
                            ans--;
                            break;
                        }
                    }
                }
            }
        }
        cout<<ans<<endl;


    }
    return 0;
}

Measured memory_bytes: 9224
Q = int(input())
lr = [list(map(int, input().split())) for _ in range(Q)]
N = 10**5
c = [0] * (N+1)
tf = [False] * (N+1)

for i in range(2, N+1):
    if not tf[i]:
        for j in range(i*2, N+1, i):
            tf[j] = True
for i in range(3, N, 2):
    if not tf[i] and not tf[(i+1)//2]:
        c[i] += 1

for i in range(3, N, 1):
    c[i] += c[i-1]
for l, r in lr:
    print(c[r] - c[l-1])


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

int main() {
	vector<long long> E(3);
	for (int i = 0; i < 3; i++) {
		cin >> E.at(i);
	}
	sort(E.begin(), E.end());
	if (E.at(0) % 2 == 0 || E.at(1) % 2 == 0 || E.at(2) % 2 == 0) {
		cout << 0 << endl;
	} else {
		cout << E.at(0) * E.at(1) << endl;
	}
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int inf=1<<29;
const ll Maxn=1e6;
const double pi=3.1415926536;
const ll MOD=1e6+7;


int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if((fabs(a-b)<=d && fabs(b-c)<=d)||(fabs(a-c)<=d)) printf("Yes\n");
	else printf("No\n");
}

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

vector<vector<int> > rot = {
	{0,1,2,3,4,5}, {0,2,4,1,3,5}, {0,4,3,2,1,5}, {0,3,1,4,2,5},
	{1,5,2,3,0,4}, {1,2,0,5,3,4}, {1,0,3,2,5,4}, {1,3,5,0,2,4},
	{2,5,4,1,0,3}, {2,4,0,5,1,3}, {2,0,1,4,5,3}, {2,1,5,0,4,3},
	{3,4,5,0,1,2}, {3,5,1,4,0,2}, {3,1,0,5,4,2}, {3,0,4,1,5,2},
	{4,0,2,3,5,1}, {4,2,5,0,3,1}, {4,5,3,2,0,1}, {4,3,0,5,2,1},
	{5,4,2,3,1,0}, {5,2,1,4,3,0}, {5,1,3,2,4,0}, {5,3,4,1,2,0}
};

vector<vector<vector<int> > > cond = {
	{},
	{{3,0,2}},
	{{1,1,4}},
	{{1,0,4},{2,2,3}},
	{{0,3,5}},
	{{0,2,5},{3,4,2}},
	{{0,1,5},{4,5,1}},
	{{0,0,5},{2,6,3},{4,4,1}}
};

struct State { int id, r; };
State pz[8];

string dice[8];
bool used[8];
bool adj[8][8];

char toggleCase(char c) {
	if (islower(c)) return toupper(c);
	return tolower(c);
}

string solve(int x) {
	if (x == 8) return "YES";
	for (int i=1; i<8; ++i) {
		if (used[i]) continue;
		bool adjacent = true;
		for (int j=0; j<(int)cond[x].size(); ++j) {
			if ( ! adj[i][pz[cond[x][j][1]].id]) {
				adjacent = false; break;
			}
		}
		if ( ! adjacent) continue;
		for (int j=0; j<24; ++j) {
			pz[x].id = i;
			pz[x].r = j;
			bool ok = true;
			for (int k=0; k<(int)cond[x].size(); ++k) {
				int bloc1 = x;
				int face1 = rot[pz[bloc1].r][cond[x][k][0]];
				int bloc2 = cond[x][k][1];
				int face2 = rot[pz[bloc2].r][cond[x][k][2]];
				if (toggleCase(dice[pz[bloc1].id][face1]) != dice[pz[bloc2].id][face2]) {
					ok = false; break;
				}
			}
			if (ok) {
				used[i] = true;
				if (solve(x+1) == "YES") return "YES";
				used[i] = false;
			}
		}
	}
	return "NO";
}

int main() {
	while (cin >> dice[0], dice[0] != "0") {
		for (int i=1; i<8; ++i) {
			cin >> dice[i];
		}
		for (int i=0; i<8; ++i) {
			for (int j=i+1; j<8; ++j) {
				bool ok = false;
				for (int k=0; k<6 && !ok; ++k) {
					for (int l=0; l<6 && !ok; ++l) {
						if (toggleCase(dice[i][k]) == dice[j][l]) ok = true;
					}
				}
				adj[i][j] = adj[j][i] = ok;
			}
		}
		memset(used, false, sizeof used);
		used[0] = true;
		pz[0].id = 0;
		string res = "NO";
		for (int i=0; i<24; ++i) {
			pz[0].r = i;
			if (solve(1) == "YES") {
				res = "YES"; break;
			}
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long

void lol(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif	
}

using namespace std;
int main(){
	FAST(); 
	lol();
	// int t; cin >> t; while(t--){
	// }
	int n; cin >> n;
	vector<int> ans(n,0);
	for(int i=0; i<n-1; i++){
		int p; cin >> p;
		ans[--p]++;
	}
	for (auto x: ans) cout << x << "\n";
	return 0;
}

Measured memory_bytes: 3988
#!/usr/bin/env python3
import math

n, x = list(map(int, input().split()))
x_list = list(map(int, input().split())) + [x]

x_list.sort()

x_diff = [x_list[i+1]-x_list[i] for i in range(len(x_list)-1)]

# print(x_diff)
A = x_diff

value = A[0]
for i in range(1, len(A)):
    value = math.gcd(value, A[i])
print(value)


Measured memory_bytes: 20264
#include<iostream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>


using namespace std;

#define rep(i,N) for(int i=0;i<N;i++) //0から
#define REP(i,N) for(int j=i;j<N;j++) //iから

typedef long long ll;




ll binary_search(vector<ll> a, ll n, ll key){
    ll right = n, left = -1;
    ll md = (right + left) / 2;

    while(right - left > 1){
        if(a[md] <= key){
            right = md;
        }else{
            left = md;
        }
        md = (right + left) / 2;
    }
    if(left == -1) return -1; //無い場合
    return right;
}

vector<ll> prime;
void Prime(ll n){ //線形篩,素数列挙
    vector<ll> p(n,0);
    p[0]=1;
    p[1]=1;
    for(ll i=2;i<n;i++){
        if(p[i]==0){
            prime.push_back(i);
            p[i]=i;
        }
        ll k=prime.size();
        for(ll j=0;j<k && i*prime[j]<n && prime[j]<=p[i];j++){
            p[i*prime[j]]=prime[j];
        }
    }
}

#define MOD ((ll)1e+9 + 7)




//cout<<fixed<<setprecision(10);
int main(){
    int n;
    cin>>n;
    int a,b;
    a=n/100;
    b=n%100;
    if(a<=12 && a>0){
        if(b<=12 && b>0){
            cout<<"AMBIGUOUS"<<endl;
        }
        else{
            cout<<"MMYY"<<endl;
        }
    }
    else{
        if(b<=12 && b>0){
            cout<<"YYMM"<<endl;
        }
        else{
            cout<<"NA"<<endl;
        }
    }

    return 0;
}



Measured memory_bytes: 3592
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<tuple>
#include<map>
#define DB double
#define LL long long
#define PP std::pair<DB,DB>
#define MPP std::make_pair
#define TT std::tuple<int,int,int>
std::vector<DB> v;
int  N, A, B;
std::map<DB,int> memo;
LL C[51][51];
LL ans;
int main() {
	std::cin >> N >> A >> B;
	for (int i = 0; i <= 50; i++) {
		for (int j = 0; j <= i; j++) {
			if (j == 0 || j == i)C[i][j] = (LL)1;
			else C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
		}
	}
	for (int i = 0; i < N; i++) {
		DB tmp;
		std::cin >> tmp;
		v.push_back(tmp);
		auto it = memo.find(tmp);
		if (it == memo.end()) {
			memo.insert(MPP(tmp, 1));
		}
		else {
			it->second++;
		}
	}
	std::sort(v.rbegin(), v.rend());
	DB MN, sum;
	int fi;
	MN = sum = fi = 0;
	for (int i = 0; i < A; i++) {
		sum += v[i];
		if (MN != v[i]) {
			MN = v[i];
			fi = 1;
		}
		else {
			fi++;
		}
	}
	DB ave = sum / (DB)A;
	while (1) {
		if (A > B) {
			break;
		}
		auto it = memo.find(MN);
		int n = it->second;
		int r = fi;
		ans += C[n][r];
		A++;
		fi++;
		if (MN != v[0]) {
			break;
		}
	}
	std::cout <<std::setprecision(20)<< std::fixed << ave << std::endl;
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
template<C T>void pr(T a){cout<<a;ln;}
template<C T,C T2>void pr(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n;
  R n;
  ll a[n];
  rep(i,n) R a[i];
  ll ans=0;
  rep(i,n) {
    ans+=a[i]/2;
    a[i]%=2;
    if(i!=n-1&&a[i]&&a[i+1]) {
      a[i+1]--;
      ans+=1;
    }
  }
  pr(ans);
}

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


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

int cmp(const void *a,const void *b){
  return *(int *)a-*(int *)b;
}

void run(void){
  int n,m;
  scanf("%d%d",&n,&m);
  int *a=(int *)malloc(sizeof(int)*(n+1));
  int i;
  for(i=1;i<=n;i++) scanf("%d",a+i);
  a[0]=0;
  for(i=1;i<=n;i++){
    a[i]+=a[i-1];
    a[i]%=m;
  }
  qsort(a,n+1,sizeof(int),cmp);
  int64 ans=0;
  i=0;
  while(i<=n){
    int j=i+1;
    while(j<=n && a[j]==a[i]) j++;
    int d=j-i;
    ans+=(int64)d*(d-1)/2;
    i=j;
  }
  printf("%lld\n",ans);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 892
n,m = map(int,input().split())
H = [int(i) for i in input().split()]

a = [0] * m
b = [0] * m
ans = [1]* n



for i in range(m):
    a[i], b[i] = map(int, input().split())


for j in range(m):
    if H[a[j]-1] < H[b[j]-1]:
        ans[a[j]-1] = 0
    elif H[a[j]-1] > H[b[j]-1]:
        ans[b[j]-1] = 0
    elif H[a[j]-1] == H[b[j]-1]:
        ans[a[j]-1] = 0
        ans[b[j]-1] = 0


print(ans.count(1))


Measured memory_bytes: 21728
#include<bits/stdc++.h>
// #define int long long
using namespace std;

int dp[100005][8][8][8];
pair<int,int> parent[100005][8][8][8];

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 n,a,b,c;
  cin>>n>>a>>b>>c;
  a=min(a,4);
  b=min(b,4);
  c=min(c,4);  

  dp[0][a][b][c]=1;
  string s[n+1];
  for(int i=1;i<=n;i++)
  {
    cin>>s[i];
  }
  for(int i=1;i<=n;i++)
  {
    for(int j=0;j<7;j++)
    {
      for(int k=0;k<7;k++)
      {
        for(int l=0;l<7;l++)
        {
          if(s[i]=="AC")
          {
            if(l>0&&j<7)
            {
              dp[i][j][k][l]|=dp[i-1][j+1][k][l-1];
              if(dp[i-1][j+1][k][l-1]>0)
              {
                parent[i][j][k][l]={3,1};
              }
            }
            if(j>0&&l<7)
            {
              dp[i][j][k][l]|=dp[i-1][j-1][k][l+1];                        
              if(dp[i-1][j-1][k][l+1]>0)
              {
                parent[i][j][k][l]={1,3};
              }
            }
          }
          else if(s[i]=="AB")
          {
            if(k>0&&j<7)
            {
            dp[i][j][k][l]|=dp[i-1][j+1][k-1][l];
              if(dp[i-1][j+1][k-1][l]>0)
              {
                parent[i][j][k][l]={2,1};
              }
            }
            if(j>0&&k<7)
            {
            dp[i][j][k][l]|=dp[i-1][j-1][k+1][l];                        
              if(dp[i-1][j-1][k+1][l]>0)
              {
                parent[i][j][k][l]={1,2};
              }
            }
          }
          if(s[i]=="BC")
          {
            if(l>0&&k<7)
            {
            dp[i][j][k][l]|=dp[i-1][j][k+1][l-1];
              if(dp[i-1][j][k+1][l-1]>0)
              {
                parent[i][j][k][l]={3,2};
              }
            }
            if(k>0&&l<7)
            {
            dp[i][j][k][l]|=dp[i-1][j][k-1][l+1];                        
              if(dp[i-1][j][k-1][l+1]>0)
              {
                parent[i][j][k][l]={2,3};
              }
            }
          }          
        }
      }
    }
  }
  a=-1;
  b=-1;
  c=-1;
  for(int i=0;i<8&&a==-1;i++)
    for(int j=0;j<8&&a==-1;j++)
      for(int k=0;k<8&&a==-1;k++)
      {
        if(dp[n][i][j][k]>0)
        {
          a=i;
          b=j;
          c=k;
          break;
        }
      }
  if(a==-1)
  {
    cout<<"No";
  }
  else
  {
    int x[4];
    x[1]=a;
    x[2]=b;
    x[3]=c;
    cout<<"Yes\n";
    vector<char>ans;
    int ini=n;
    while (ini>0)
    {
      int z=parent[ini][a][b][c].first;
      if(z==1)
        ans.push_back('A');
      else if(z==2)
        ans.push_back('B');
      else
        ans.push_back('C');
      x[parent[ini][a][b][c].first]--;
      x[parent[ini][a][b][c].second]++; 
      a=x[1];
      b=x[2];
      c=x[3];
      ini--;
    }
    reverse(ans.begin(),ans.end());
    for(auto i:ans)
      cout<<i<<'\n';
  }
  
}

Measured memory_bytes: 606932
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            int n = Integer.parseInt(br.readLine());
            int ans = 0;
            for (int i = 1; i <= n; i = i + 2) {
                int count = 0;
                for (int j = 1; j <= i; j++) {
                    if (i % j == 0) {
                        count++;
                    }
                }
                if (count == 8) {
                    ans++;
                }
            }
            System.out.println(ans);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}


Measured memory_bytes: 22612
#include<iostream>
#include<math.h>
#include <algorithm>
#include<float.h>
#include <limits>
#include <vector> 
#include <numeric>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define ll long long

using namespace::std;

int jo(ll int x, ll int y){
	ll int jhogeo = 1;
	rep(jinto,0,y) jhogeo=jhogeo*x;
	return jhogeo;
}


int main(){
int A,B;
  cin>>A>>B;
  if(A+B>23) cout<<A+B-24;
  else cout<<A+B;
      
}
// int *p = new int[N];

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//


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

int main() {
	int n,m,l;
	int i,j,k;
	long sum = 0;
	cin >> n >> m >> l;
	int A[n][m];
	int B[m][l];
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			cin >> A[i][j];
		}
	}
	for (i = 0; i < m; i++) {
		for (j = 0; j < l; j++) {
			cin >> B[i][j];
		}
	}
	for (i = 0; i < n; i++) {
		for (j = 0; j < l; j++) {
			for (k = 0; k < m; k++) {
				sum += A[i][k] * B[k][j];
			}
			cout << sum;
			if (j != l-1) cout << " ";
			sum = 0;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1236
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int X = sc.nextInt();
		int[] m = new int[N];
		for(int i=0; i<N; i++) {
			m[i] = sc.nextInt();
			X -= m[i];
		}
		Arrays.sort(m);
		System.out.println(N+(X/m[0]));
	}

}


Measured memory_bytes: 35788
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int X, Y; cin >> X >> Y;

    for(int i=0; i<=X; i++){
        if(i*2+(X-i)*4 == Y){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long y = sc.nextLong();
		String str = String.format("%32s", Long.toBinaryString(x & y)).replace(' ', '0');
		System.out.println(str.substring(str.length() - 32, str.length()));
		str = String.format("%32s", Long.toBinaryString(x | y)).replace(' ', '0');
		System.out.println(str.substring(str.length() - 32, str.length()));
		str = String.format("%32s", Long.toBinaryString(x ^ y)).replace(' ', '0');
		System.out.println(str.substring(str.length() - 32, str.length()));
	}
}



Measured memory_bytes: 26516
// review
#include <iostream>

using namespace std;

typedef long long ll;

const ll MOD = 998244353;
const int MAXN = 2 * 1e5 + 10;

ll n, m, k;

ll factorial[MAXN] = {0};

ll fact(ll n) {
  if (n == 0) {
    return 1;
  }
  if (factorial[n]) {
    return factorial[n];
  }
  factorial[n] = n * fact(n - 1) % MOD;
  return factorial[n];
}

ll mod_pow(ll n, ll x) {
  ll res = 1;
  while (x > 0) {
    if (x & 1) {
      res = (res * n) % MOD;
    }
    n = (n * n) % MOD;
    x >>= 1;
  }
  return res;
}

ll inv_mod(ll n) {
  return mod_pow(n, MOD - 2);
}

ll nCr(ll n, ll r) {
  return fact(n) * inv_mod(fact(r) * fact(n-r) % MOD) % MOD;
}

void solve() {
  // We can calculate the case when K pairs have same color by using combination as following.
  // There are N-1 pairs, (A1, A2), (A2, A3), ... (AN-1, AN) and we can select K pairs out of it: (N-1) C K
  // After making K pairs, we can think about them as one element which results in N-K elements to color.
  // We have M colors to choose from and above elements has to be colored differently.
  // First element can pick from M colors, then next one can select M - 1 (No the one from first element), then third one has M - 1 options...
  // As a result, we can color all of them in M * (M -1) * (M - 1) * ... * (M - 1) = M * (M-1)^(N-1-K) ways
  // Thus to color K pairs, we have (N-1) C K * M * (M-1)^(N-1-K) ways to do so.
  // What we want is total ways less than or equal to K pairs, so we can just sum them up.

  factorial[0] = 1;
  ll ans = 0;
  for (ll i=0;i<=k;i++) {
    ll tmp = (nCr(n-1, i) * m % MOD) * mod_pow(m-1,n-1-i) % MOD;
    ans = (ans + tmp) % MOD;
  }
  cout << ans << endl;
}

int main() {
  cin >> n >> m >> k;
  solve();
}


Measured memory_bytes: 8260
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
const ll mod = 1e9+7;
ll dp[2003][2003];
int s[2003],t[2003];
int n,m;
ll go(int i,int j){
    if(i==n or j==m)return 1;
    ll ret = dp[i][j];
    if(ret!=-1)return ret;
    ret = 0;
    ret=(ret+go(i+1,j))%mod;
    ret=(ret+go(i,j+1))%mod;
    if(s[i]!=t[j])ret = (ret-go(i+1,j+1))%mod;
    if(ret<0)ret+=mod;
    return dp[i][j] = ret;
}
void solve(){
    cin>>n>>m;
    for(int i=0;i<n;i++)cin>>s[i];
    for(int i=0;i<m;i++)cin>>t[i];
    memset(dp,-1,sizeof dp);
    cout<<go(0,0)<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 31872
N=int(input())
H=list(map(int, input().split()))

max_index = H.index(max(H))
ans = 0
num_before = 0
for i in range(max_index,N):
  if H[i] > num_before:
    ans += H[i] - num_before
  num_before = H[i]
num_before = max(H)
for i in range(-max_index,1):
  if H[-i] > num_before:
    ans += H[-i] - num_before
  num_before = H[-i]
print(ans)

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

typedef long long ll;
ll x;

int main(){
	scanf("%lld", &x);
	ll One = x / 500;
	x %= 500;
	ll Two = x / 5;
	x %= 5;
	ll Out = One*1000+Two*5;
	printf("%lld",Out);
}

Measured memory_bytes: 256
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let (n, a, b): (usize, i64, i64) = parse!(it, 3);
    let c = a - b;
    let h: Vec<i64> = parse!(it, n);
    let f = |x: i64| {
        let mut s = x;
        for i in 0..n {
            let ri = h[i] - x * b;
            if ri <= 0 {
                continue;
            }
            let ki = ri / c + if ri % c == 0 { 0 } else { 1 };
            s -= ki;
        }
        s >= 0
    };
    let mut ok = h.iter().max().unwrap() / b + 1;
    let mut ng = 0;
    while ok - ng > 1 {
        let m = (ok + ng) / 2;
        if f(m) {
            ok = m
        } else {
            ng = m
        }
    }
    println!("{}", ok);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        4 5 3
8
7
4
2
        ";
        solve(s);
    }
}


Measured memory_bytes: 8444
#include <iostream>
#include <climits>
#define MAX_N 200
using namespace std;
int min(int a, int b){
  return a < b ? a : b;
}
int max(int a, int b){
  return a > b ? a : b;
}
int main(void){
  int n;
  int mi = INT_MAX;
  int ma = INT_MIN;
  int a;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a;
    mi = min(mi, a);
    ma = max(ma, a);
  }
  cout << ma - mi << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

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

    sort(all(l));
    ll s = 0;
    rep(i,n)s += l[i];
    ll res = s - l[n-1];

    if(l[n-1] < res){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  rep(i,k) cin >> l[i] >> r[i];
  vector<mint> dp(n+1);
  vector<mint> dpsum(n+1);
  dp[1] = 1;
  dpsum[1] = 1;
  for (int i = 2; i <= n; ++i) {
    rep(j,k) {
      // [l[i], r[i]]
      int li = i-r[j];
      int ri = i-l[j];
      if (ri < 0) continue;
      li = max(li,1);
      dp[i] += dpsum[ri]-dpsum[li-1]; //dp[li]~dp[ri];
    }
    dpsum[i] = dpsum[i-1]+dp[i];
  }
  cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 6436
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long MOD = 998244353;
const long long INF = 1LL << 60;
const int inf = pow(10, 9) + 7;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, int B) {return (A + (B - 1)) / B;}
long long divCeil(int A, long long B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, long long B) {return (A + (B - 1)) / B;}

int main()
{
  string s;
  cin >> s;
  int n = s.size();

  string ans = "Yes";
  int N = 0, W = 0, S = 0, E = 0;
  for (int i = 0; i < n; i++)
  {
    if (s.at(i) == 'N') N++;
    else if (s.at(i) == 'W') W++;
    else if (s.at(i) == 'S') S++;
    else if (s.at(i) == 'E') E++;
  }
  
  if (N * S == 0 && N + S > 0) ans = "No";
  else if (W * E == 0 && W + E > 0) ans = "No";
  
  cout << ans << endl;
}

Measured memory_bytes: 256
s=input()
t=input()
ar1=[0]*26
ar2=[0]*26
for i in s:
    ar1[ord(i)-97]+=1
for i in t:
    ar2[ord(i)-97]+=1
ar1.sort()
ar2.sort()
if ar1==ar2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 74096
import sys

N, R = map(int, input().split())
if 2*R > N:
    R = N - R
P = [0] + list(map(int, input().split()))

L = []
used = [False]*(N+1)
pre = 0
for i in range(1, N+1):
    cnt = 0
    while not used[i]:
        used[i] = True
        cnt += 1
        i = P[i]
    if cnt:
        L.append(cnt)
table = [0]*(N+1)
for l in L:
    table[l] += 1
L = []
for i in range(N//2, 0, -1):
    x = table[i]
    if not x:
        continue
    if x == 1:
        L.append(i)
    else:
        p = 1 
        while p+p <= x:
            L.append(p*i)
            p = p+p
        if x - p + 1:
            L.append(i*(x - p + 1))
L = [l for l in L if l <= R]
L.sort()
H = 1
for l in L:
    H = H|(H<<l)
if H & 1<<R:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 40224
data = input().split()
A = int(data[0])
B = int(data[1])
k = int(data[2])
ans = []
i = 1
ma = max(A,B)

while i <= ma:
  if (A % i == 0) & (B % i == 0):
    ans.append(i)
  i += 1
ind = len(ans)

print(ans[ind - k ])



Measured memory_bytes: 3060
#!/usr/bin/env python3

import math

def gcd(a, b):
    if a < b:
        a, b = b, a
    q, r = a, b
    while r:
        q, r = r, q % r

    return q


def lcm(a, b):
    return a * b // gcd(a, b)

MAX_N = 102
INF = 10 ** 12
SRC = 0
DST = MAX_N - 1
g = [[0] * MAX_N for _ in range(MAX_N)]
level = []
visited = []
n = 0


def bfs(s):
    global level

    level = [-1] * MAX_N
    level[s] = 0
    que = [s]
    while 0 < len(que):
        v = que.pop(0)
        for w in range(MAX_N):
            if 0 < g[v][w] and level[w] < 0:
                level[w] = level[v] + 1
                que.append(w)


def dfs(v, t, f):
    global g, visited

    if v == t:
        return f
    for w in range(visited[v], MAX_N):
        visited[v] = w
        if 0 < g[v][w] and level[v] < level[w]:
            d = dfs(w, t, min(f, g[v][w]))
            if 0 < d:
                g[v][w] -= d
                g[w][v] += d
                return d

    return 0


def max_flow():
    global visited

    flow = 0
    while True:
        bfs(SRC)
        if level[DST] < 0:
            return flow
        visited = [0] * MAX_N
        f = dfs(SRC, DST, INF)
        while 0 < f:
            flow += f
            f = dfs(SRC, DST, INF)


def solve(n, a):
    global g

    sum_positive = sum([v for v in a if 0 < v])

    for i in range(1, n + 1):
        if 0 < a[i]:
            g[SRC][i] = a[i]
        elif a[i] < 0:
            g[i][DST] = -a[i]
            for j in range(i * 2, n + 1, i):
                if 0 < a[j]:
                    g[j][i] = INF

    return sum_positive - max_flow()


def main():
    global n

    n = int(input())
    a = list(map(int, input().split()))
    a = [0] + a

    print(solve(n, a))


if __name__ == '__main__':
    main()



Measured memory_bytes: 3192
#include <iostream>
#include <algorithm>
#include <vector>

int main() {
	int n;
	std::cin >> n;

	long long a, b, c, d;
	std::cin >> a >> b >> c >> d;

	if (a > b) std::swap(a, b);
	b -= a;

	for (int i = 0; i <= n - 1; i++) {
		long long top = -i * c;
		long long bottom = -i * d;

		long long high = top + (n - 1 - i) * d;
		long long low = bottom + (n - 1 - i) * c;

		if (low <= b && b <= high) {
			puts("YES");
			return 0;
		}
	}
	puts("NO");
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
   int W,H,x,y,r;
   cin>>W>>H>>x>>y>>r;
   if(x-r<0||y-r<0||x+r>W||y+r>H)
   cout<<"No"<<endl;
   else
   cout<<"Yes"<<endl;
   }


Measured memory_bytes: 3100
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;

int main() {
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#else
    //    freopen("lupa.in","r",stdin);
        //    freopen("pupa.out","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(20);
    cout << fixed;
    int x;
    cin >> x;
    for (int i = 2; i <= 100000; ++i) {
        if (x * i % 360 == 0) {
            cout << i;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int A, B;
  cin >> A >> B;
  if(A < 10 && B < 10) cout << A*B << endl;
  else cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
// ABC 081

// inputに入力データ全体が入る
function Main(input) {
  input = input.split("\n");
  const N = parseInt(input[0],10);
  const arr = input[1].split(" ");
  var count = 0;

  while(true) {
    var flag = 0;
    for(var i=0;i<N;i++) {
      var A = parseInt(arr[i],10);
      //偶数
      if(A%2 == 0) {
        arr[i] = A / 2;
        // 奇数
      } else {
        flag = 1;
      }
    }
    if(flag==0){count++;}
    else {break;}
  }
  console.log(count);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
from sys import stdin as s
n,m=map(int,s.readline().split())
l=[0]*n
wa=[0]*n
cor,pen=0,0
for i in range(m):
  x,y=s.readline().split()
  x=int(x)-1
  if y=="AC":
    l[x]=1
  elif not l[x]:
    wa[x]+=1
for i in range(n):
  if l[i]:
    cor+=1
    pen+=wa[i]
print(cor,pen)

Measured memory_bytes: 42288
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 1e5+5;
int n, t, p[N]; char s[N];
int main()
{
    scanf("%s", s+1), n = strlen(s+1);
    if(s[1] == '0'||s[n] == '1') return puts("-1"), 0;
    for(int i = 1; i < n; ++i) if((s[i] == '1') != (s[n-i] == '1')) return puts("-1"), 0;
    p[1] = t = 1; for(int i = 2, j = 1; i < n; ++i) if(s[i] == '1')
    {
        p[i] = ++t, printf("%d %d\n", p[j], p[i]);
        for(int k = 1; k <= i-j-1; ++k) printf("%d %d\n", ++t, p[i]);
        j = i;
    }
    printf("%d %d\n", p[n-1], n);
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fo(i,s,e) for( i=s;i<e;i++)
#define rfo(i,s,e) for(i=s;i>e;i--)
#define LLI long long int
#define LI long int 
const LI MOD=1e9+7;
#define pb push_back
#define pob pop_back()
#define sp " "
#define ff first
#define ss second
//            When something is important enough, you do it even if the odds are not in your favor.

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    // code goes here
    int t=1;//cin>>t;
    while(t--){
      LI n,i;cin>>n;
      double ans=0;
      fo(i,0,n){
        double x;cin>>x;
        ans+=1/x;
      }
      cout<<fixed<<setprecision(10)<<1/ans;
    }
    return 0;
}

Measured memory_bytes: 3776
package main


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

func StrStdin() string {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	return strings.TrimSpace(scanner.Text())
}

// 1つの符号付き整数値(64bit)入力
// Exapmle:
// ------------------
// 1000000007
// ------------------
func Int64Stdin() int64 {
	stringInput := StrStdin()
	num, _ := strconv.ParseInt(strings.TrimSpace(stringInput), 10, 64)
	return num
}

// 1つの符号無し整数値(64bit)入力
// Exapmle:
// ------------------
// 1000000007
// ------------------
func Uint64Stdin() uint64 {
	stringInput := StrStdin()
	num, _ := strconv.ParseUint(strings.TrimSpace(stringInput), 10, 64)
	return num
}

// 1つの符号付き浮動小数点(64bit)入力
// Exapmle:
// ------------------
// 33.4
// ------------------
func Float64Stdin() float64 {
	stringInput := StrStdin()
	num, _ := strconv.ParseFloat(strings.TrimSpace(stringInput), 64)
	return num
}

// 空白や空文字だけの値を除去したSplit
func SplitWithoutEmpty(stringTargeted string, delim string) []string {
	stringSplited := strings.Split(stringTargeted, delim)
	strs := []string{}

	for _, str := range stringSplited {
		if str != "" {
			strs = append(strs, str)
		}
	}
	return strs
}

// 空白区切りで複数の文字列を入力
// Example:
// --------------------
// hoge fuga hage
// --------------------
func SliceStrStdin(delim string) []string {
	stringInput := StrStdin()
	return SplitWithoutEmpty(stringInput, delim)
}

// 空白区切りで複数の符号付き整数値(64bit)を入力
// Example:
// --------------------
// 45 -100 23
// --------------------
func SliceInt64Stdin() []int64 {
	stringSplited := SliceStrStdin(" ")

	int64Slice := []int64{}

	for ni := range stringSplited {
		num, _ := strconv.ParseInt(stringSplited[ni], 10, 64)
		int64Slice = append(int64Slice, num)
	}

	return int64Slice
}

// 空白区切りで複数の符号無し整数値(64bit)を入力
// Example:
// --------------------
// 43 7 21
// --------------------
func SliceUint64Stdin() []uint64 {
	stringSplited := SliceStrStdin(" ")

	uint64Slice := []uint64{}

	for ni := range stringSplited {
		num, _ := strconv.ParseUint(stringSplited[ni], 10, 64)
		uint64Slice = append(uint64Slice, num)
	}

	return uint64Slice
}

// 空白区切りで複数の符号付き浮動小数点(64bit)を入力
// Example:
// --------------------
// 45.0 -62.1 11.7
// --------------------
func SliceFloat64Stdin() []float64 {
	stringSplited := SliceStrStdin(" ")

	float64Slice := []float64{}

	for ni := range stringSplited {
		num, _ := strconv.ParseFloat(stringSplited[ni], 64)
		float64Slice = append(float64Slice, num)
	}

	return float64Slice
}

func Solve() {
	ABK := SliceInt64Stdin()
	A, B, K := ABK[0], ABK[1], ABK[2]

	var (
		qa int64
		qb int64
	)

	if A - K >= 0 {
		qa, qb = A - K, B
	} else if (A + B) - K >= 0 {
		qa, qb = 0, (A + B) - K
	} else {
		qa, qb = 0, 0
	}

	fmt.Printf("%d %d", qa, qb)
}

func main() {
	Solve()
}

Measured memory_bytes: 640