akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    int N;
    cin >> N;
    bool fla = false;

    for(int i = 1;i <= 9;i++)
        for(int j = 1;j <= 9;j++){
            if(i*j == N){
                fla = true;
                break;
            }
        }

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

Measured memory_bytes: 3632
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <sstream>
#include <numeric>
#include <set>
#include <map>
//#include <bits/stdc++.h>

#define rep(i, j) for(int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
#define ll long long
#define bl bool
#define nn printf("\n");
#define mod 1000000007

using namespace std;

struct inout { int cri; string name; };
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N; cin >> N;
	vector<inout> dat(N + 2);
	rep(i, N) 
	{
		cin >> dat[i].name; 
		dat[i].cri = 0;
	}
	int M; cin >> M;
	int l = 0;
	rep(i, M)
	{
		string tar; cin >> tar;
		int k = 0;
		rep(j, N)
		{
			if (dat[j].name == tar)
			{
				if(l == 0)
				{
					cout << "Opened by " << dat[j].name << "\n";
					l = 1;
					break;
				}
				else if (l == 1)
				{
					cout << "Closed by " << dat[j].name << "\n";
					l = 0;
					break;
				}
			}
			k++;
			if (k > N - 1) { cout << "Unknown " << tar << "\n"; }
		}
	}

	return 0;
}

Measured memory_bytes: 3252
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl;
#define Vecpr vector<pair<lli,lli>>
#define mod 1000000007;
bool is_prime(lli x) {
  for(lli i = 2; i * i <= x; i++) {
    if(x % i == 0) return false;
  }
  return true;
}
int main() {
  lli A,B,C=1,D=0,E=0,F=0,G=0,H=0,N,M;
  string S;
  cin >> S >> A;
  B=S.size();
  if(B%A!=0)B=B/A+1;
  else B/=A;
  rep(i,0,B){
    NeOut(S[i*A]);
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;

#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define ALL(obj) (obj).begin(),(obj).end()

#define rt return
#define ENDL cout<<endl
#define s second
#define f first

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){ 
    int N;cin >> N;
    vector<int> V,C;
    for(int a = 0;a < N;a++){
        int b;cin >> b;
        V.push_back(b);
    }
    for(int a = 0;a < N;a++){
        int b;cin >> b;
        C.push_back(b);
    }
    int ans = 0;
    for(int a = 0;a < N;a++){
        if(V.at(a) - C.at(a) >= 0){
            ans += V.at(a)-C.at(a);
        }
    }
    cout<<ans<<endl;
}


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

int main()
{
  int A,B,C;
  cin >> A >> B >> C;
  int check = A;
  int flag = 0;
  do
  {
    if(check%B == C) 
    {
      flag = 1;
      break;
    }
    check = (check+A)%B;
  }while(check%B != A%B && flag == 0);
  
  if(flag == 1)
  {
    cout << "YES" << endl;
  }
  else
  {
    cout << "NO" << endl;
  }
}


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

using namespace std;

const int N = 1234567;

int a[N], cnt[N], pairs[N], lonely[N];

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    cnt[a[i] % m]++;
    if (lonely[a[i]]) {
      pairs[a[i] % m]++;
    }
    lonely[a[i]] ^= 1;
  }
  int ans = 0;
  for (int r = 0; r < m; r++) {
    int other = (m - r) % m;
    if (other < r) {
      continue;
    }
    if (other == r) {
      ans += cnt[r] / 2;
      continue;
    }
    int x = r, y = other;
    if (cnt[x] < cnt[y]) {
      swap(x, y);
    }
    int overhead = cnt[x] - cnt[y];
    if (2 * pairs[x] >= overhead) {
      ans += (cnt[x] + cnt[y]) / 2;
    } else {
      ans += pairs[x] + cnt[y];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i = 0; i < (n); i++)
 
int main() {
	int X,Y,Z;
  	cin >> X >> Y >> Z;
	cout << Z << " " << X << " " << Y << " " << endl;
}

Measured memory_bytes: 3596
n = int(input())
tempre, a = list(map(int, input().split()))
heights = list(map(int, input().split()))

min_abs = 10**6
ans = -1
for i, h in enumerate(heights):
    t = tempre - 0.006 * h
    if abs(t-a) < min_abs:
        ans = i+1
        min_abs = abs(t-a)
print(ans)



Measured memory_bytes: 9140
from math import ceil
n=int(input())
p=input().split()
ans=0
l=['0']*len(p)
for i in range(len(p)):
    if i+1==int(p[i]):
        l[i]='1'
s=''.join(l)

l=s.split('0')

for j in l:
    ans+=ceil(len(j)/2)
print(ans)


Measured memory_bytes: 18720
#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 = 1000000007;
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, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		assert(n < mod);
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
	mint p(int n, int k) {
		return fact[n] * ifact[n - k];
	}
}c(1000005);
using namespace std;
int main() {
	int N,M;
	cin >> N >> M;
	mint ans = 0;

	for (int i = 0; i <= N+1; ++i) {
		mint now = c(N, i);
		now *= c.p(M,N);
		now *= c.p(M-i,N-i);
		if (1 == (i &1)) {
			now = -now;
		}
		ans += now;
	}
	
	cout <<ans<<endl;
	return 0;
}

Measured memory_bytes: 18612
#include <bits/stdc++.h>
using namespace std;
 
#define LL long long
typedef pair<int, int> pii;
 
template< typename T > inline void read(T &x)
{
    static char _c;
    static bool _f;
 
    x = 0;
    _f = 0;
    _c = getchar();
 
    while(_c < '0' || '9' < _c) {if(_c == '-') _f = true; _c = getchar();}
    while('0' <= _c && _c <= '9') {x = (x << 1) + (x << 3) + (_c & 15); _c = getchar();}
    if(_f) x = -x;
}
 
template < typename T > inline void Min(T &x, T y) {if(y < x) x = y;}
template < typename T > inline void Max(T &x, T y) {if(x < y) x = y;}
 
 
#define lowbit(x) ((x) & -(x))
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) ((l)+(((r)-(l))>>1))
#define fi first
#define se second
#define mk make_pair
#define pb push_back
 
const int INF = 0x3f3f3f3f;
const double pi = (double) acos(-1.0);
const double eps = (double) 1e-8;
const int e5 = (int) 1e5 + 5;
//const int MOD = (int) 1e9 + 7;
const int MOD = (int) 998244353;
//int MOD = 998244353;
 
inline int sig(double x) {return x < -eps ? -1 : eps < x;}
LL fp(LL a, LL n, LL mod = MOD)
{
    if(n < 0) a = fp(a, mod - 2, mod), n = -n;
    LL res = 1; for(; n; n >>= 1, a = a * a % mod) if(n & 1) res = res * a % mod; return res;
}
 
struct Mint
{
    int x;
    Mint() {x = 0;}
    Mint(int _x): x(_x) {if(x < 0 || x >= MOD) x = (x % MOD + MOD) % MOD;}
    Mint(LL _x): x(_x) {if(x < 0 || x >= MOD) x = (x % MOD + MOD) % MOD;}
    Mint operator - () const{
        return Mint(MOD - x);
    }
    Mint operator + (const Mint &rhs) const{
        return Mint(x + rhs.x >= MOD ? x + rhs.x - MOD : x + rhs.x);
    }
    Mint operator - (const Mint &rhs) const{
        return Mint(x - rhs.x < 0 ? x - rhs.x + MOD : x - rhs.x);
    }
    Mint operator * (const Mint &rhs) const{
        return Mint((LL)x * rhs.x % MOD);
    }
    Mint operator / (const Mint &rhs) const{
        return Mint(x * fp(rhs.x, -1) % MOD);
    }
    Mint& operator += (const Mint &rhs) {
        x += rhs.x; if(x >= MOD) x -= MOD; return *this;
    }
    Mint& operator *= (const Mint &rhs) {
        x = ((LL)x * rhs.x) % MOD; return *this;
    }
    bool operator == (const Mint &rhs) const{
        return x == rhs.x;
    }
    bool operator != (const Mint &rhs) const{
        return x != rhs.x;
    }
    friend ostream& operator << (ostream &out, const Mint &rhs){
        return out << rhs.x;
    }
    friend istream& operator >> (istream &in, Mint &rhs){
        return in >> rhs.x;
    }
};
 
 
const int maxn = (int) 2e5 + 20;
const int maxm = (int) 1e6 + 20;
 
 
void work()
{
    double x;
    cin >>x;
    printf("%.12f\n", 2 * pi * x);
}
 
int main(int argc, char **argv)
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
//    get_prime();
//    pre();
    int tc = 1;
//    read(tc);
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};


int main(){
  
  string s;
  cin >> s;
  if(stoi(s.substr(5,2)) > 4 || (stoi(s.substr(5,2)) == 4 && stoi(s.substr(8,2)) == 31))cout << "TBD" << endl;
  else cout << "Heisei" << endl;




  return 0;
}

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

int main() {
   int a, b, c, d, ans;
   cin >> a;

   b = a / 500;
   ans = b * 1000;
   c = a % 500;
   d = c / 5;
   ans += d * 5;

   cout << ans << endl;
}

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

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

typedef long long ll;
const ll MOD = 1e9 + 7;

int main() {
  int N, K;
  std::string S;
  std::cin >> N >> K >> S;

  int cnt = 0;
  rep(i, N - 1) {
    if(S[i] != S[i + 1]) ++cnt;
  }

  int ans;
  if(K >= (cnt + 1) / 2) {
    ans = N - 1;
  } else {
    ans = N - (cnt + 1) + 2 * K;
  }
  std::cout << ans << '\n';
}


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

int main(){	
    int n[101];
    int i;
    int num;
    cin >> num;

    for (i = 0; i < num; i++) cin >> n[i];
    cout << n[num - 1];

    for (i = 1; i < num; i++) cout << " " << n[num - i - 1];
    cout << endl;

	return 0;
}



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

int main(){
    int N;cin>>N;
    int A[N];
    for(int i=0;i<N;i++){
        cin>>A[i];
        if(A[i]%2==1){
            cout<<"first"<<endl;
            return 0;
        }else if(i==N-1){
            cout<<"second"<<endl;
        }
    }
}

Measured memory_bytes: 640
W, H, N = map(int, input().split())
r = [[1] * H for _ in range(W)]

for i in range(N):
    x, y, a = list(map(int, input().split()))
    if a == 1:
        for i in range(x):
            for j in range(H):
                r[i][j] = 0
    if a == 2:
        for i in range(x,W):
            for j in range(H):
                r[i][j] = 0
    if a == 3:
        for i in range(W):
            for j in range(y):
                r[i][j] = 0
    if a == 4:
        for i in range(W):
            for j in range(y,H):
                r[i][j] = 0
print(sum(sum(R) for R in r))


Measured memory_bytes: 74028
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vec = vector<ll>;
using vecp = vector<P>;
using mat = vector<vec>;
using matp = vector<vecp>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define all(v) v.begin(), v.end()

int main(){
  string S;
  ll K;
  cin >> S >> K;
  rep(i,(ll)S.size()){
    if(S.at(i)=='1'){
      if(K==i+1){
        cout << 1 << endl;
        return 0;
      }
    }else{
      cout << S.at(i) << endl;
      return 0;
    }
  }
}
          
      

Measured memory_bytes: 3596
ls = list(map(int,input().split()))
n = ls[0]
a = ls[1]
b = ls[2]
r = 0

for i in range(1, n+1):
  s = sum(list(map(int, list(str(i)))))
  if s >= a and s <= b:
    r += i
  
print(r)

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    int l,r;
    cin >> l >> r;
    int ans = 3000;
    if (l/2019 != r/2019) ans = 0; else {
        l = l % 2019;
        r = r % 2019;
        if (r <= l) r += 2019;
        for (int i = l; i <= r-1; i++)
        {
            for (int j = i+1; j <= r; j++)
            {
                int p = (i*j) % 2019;
                if (p < ans) ans = p;
                if (ans == 0) break;
            }
            
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;
const ll inf = 1e18+5;
ll n, can[55][55];
const ll mod = 1e9+7;
ll add (ll a, ll b){
	return (a%mod + b%mod + mod)%mod;
}
ll mult(ll a, ll b){
	return (a%mod * b%mod +mod)%mod;
}
struct M{
	ll t[55][55];
	M(){
		for (ll i = 0; i < n; i++){
			for (ll j = 0; j< n; j++){
				t[i][j] = 0;
			}
		}
	}
	M operator* (const M& b) const {
		M c = M();
		for (ll i = 0; i < n; i++){
			for (ll j = 0; j < n; j++){
				for (ll k = 0; k <n; k++){
					c.t[i][k] = add(c.t[i][k], mult(t[i][j], b.t[j][k]));
				}
			}
		}
		return c;
	}
};
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	ll k;
	cin >> n >> k;
	for (ll i= 0; i < n; i++){
		for (ll j = 0; j < n; j++){
			cin >> can[i][j];
		}
	}
	M answer = M();
	for (ll i = 0; i< n; i++){
		answer.t[i][i] = 1; //setting base case for f(1)
	}
	M m = M();
	for  (ll i = 0; i< n; i++){
		for (ll j = 0;j< n; j++){
			m.t[i][j] = can[i][j];
		}
	}
	while (k){
		if (k% 2 == 1){
			answer = answer *m;
		}
		m = m*m;
		k/=2;
	}
	//exponentiate the can matrix ^k to get f(k)
	ll total = 0;
	for (ll i = 0; i < n; i++){
		for (ll j= 0; j < n; j++){
			total = add(total, answer.t[i][j]);
		}
	}	
	cout << total;return 0;
	
	//~ dp[i] stores the number of paths that i can get to node i
	vector<ll> dp(n, 1);
	//~ for (ll i = 0; i < n; i++)dp[i] = 1;
	for (ll step = 0; step < k; step++){
		vector<ll> new_dp(n);
		for (ll i= 0; i< n; i++){
			for (ll j = 0; j < n; j++){
				if (can[i][j]){
					new_dp[j] += dp[i];
					//so new dp stores for cur k, 
					//dp is k-1, so if there is an edge, we can update
				}
				
			}
		}
		dp = new_dp;
	}
	ll ans  = 0;
	for (ll i= 0; i < n; i++){
		ans += dp[i];
	}
	cout << ans;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
long long n,a,b,c,res;

int main(){
	cin>>n>>a>>b;
	res = res + n/(a + b) * a;
	c = n % (a + b);
	if(c > a){
		cout<<res + a<<endl;
	}
	else{
		cout<<res + c<<endl;
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<string>
#include<map>
#include<set>
using namespace std;
#define ll long long
#define ull unsigned long long
#define INF 1e9
#define eps 1e-6
#define PI acos(-1.0)
#define M 10010
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 10;

int a,b;

int main() {
  //freopen("in.txt", "r", stdin);
  //freopen("out.txt","w",stdout);
  cin>>a>>b;
  cout<<a*b-a-b+1<<endl;
  return 0;
}

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

#define null               ""
#define all(dat)           dat.begin(), dat.end()
#define over(msg)          cout << msg << endl, exit(0);
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fr, to)    for (int i = fr; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

struct edge {
    int u, v, val;
    edge() {}
    edge(int u, int v, int val) {
        this->u = u;
        this->v = v;
        this->val = val;
    }
};

int n, m, s, pr[100005], sz[100005];
num w[100005];
edge dat[100005];

bool cmp(edge a, edge b) {
    return a.val < b.val;
}

int find_pr(int a) {
    return pr[a] == a ? a : pr[a] = find_pr(pr[a]);
}

void unite(int u, int v) {
    int pu = find_pr(u), pv = find_pr(v);
    if (pu == pv)  return;
    pr[pv] = pu;
    w[pu] += w[pv];
    sz[pu] += sz[pv];
    sz[pv] = 0;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    cont (i, n) {
        cin >> w[i];
        pr[i] = i;
    }
    cont (i, m) {
        int u, v, val;
        cin >> u >> v >> val;
        dat[i] = edge(u, v, val);
    }
    sort(dat + 1, dat + m + 1, cmp);
    cont (i, m) {
        int u = dat[i].u, v = dat[i].v, val = dat[i].val;
        unite(u, v);
        int p = find_pr(u);
        ++sz[p];
        if (w[p] >= val) {
            s += sz[p];
            sz[p] = 0;
        }
    }
    cout << m - s << endl;
}


Measured memory_bytes: 2944
S = input()
T = input()
 
Nmax = len(T)
for i in range(len(S)-len(T)+1):
    diff = 0
    for j in range(len(T)):
        if(S[i+j] != T[j]):
            diff += 1
 
    Nmax = min(diff, Nmax)
 
print(Nmax)

Measured memory_bytes: 8936
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
//constexpr ll MOD = 1000000007;
constexpr ll MOD = 998244353;
ll INF = 4001001001001001001;
long double EPS = 1e-9;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<tuple<ll,ll,ll>>>;

// MOD確認

int main(){
   string T;
   cin >> T;
   ll N = T.size();
   T = "#" + T;
   T = T + "#"; 
   FOR(i,1,N+1){
      if(T[i] == '?'){
         if(T[i-1] == 'P') T[i] = 'D';
         else if(T[i+1] == 'D') T[i] = 'P';
         else T[i] = 'D';
      }
   }
   cout << T.substr(1,N) << endl;
} 


Measured memory_bytes: 3936
#include <stdio.h>

int main(void) {
    
    int i;
    int num;
  
    scanf("%d", &num);
  
    int su[num];
    int judge =0;
  
    for(i=0; i<num; i++){
        scanf("%d", &su[i]);
        
        if(su[i]%2==0){
            if(su[i]%3!=0 && su[i]%5!=0)
                judge=1;
        }
    }
    
    if(judge==0)
        printf("APPROVED");
    else
        printf("DENIED");
    
	return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <math.h> 
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <string>
#include <numeric>
#include <bitset>
#include <queue>
#include <map>

using namespace std;


int main() {
	//input
	string S, T;
	cin >> S >> T;

	bool ok = true;
	map<char, char> ma, ima;

	for (int i = 0; i < S.size(); ++i) {
		char s = S[i], t = T[i];
		//cout << i << " :" << ma.count(s) << endl;
		//cout << i << " :" << ima.count(t) << endl;
		if (ma.count(s)) { //m.count()の戻り値が0に等しければキーが存在しない、1に等しければキーが存在する(https://cpprefjp.github.io/reference/map/map/count.html)
			if (ma[s] != t) {
				ok = false;
			}
		}
		if (ima.count(t)) {
			if (ima[t] != s) {
				ok = false;
			}
		}
		ma[s] = t; ima[t] = s;
	}

	if (ok) puts("Yes");
	else puts("No");

	return 0;
}

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

string s;

int main(void){
    
    cin >> s;
    
    int ans = 0;
    for(int i = 0; i < s.size(); ++i){
        if(s[i] == '+') ++ans;
        else --ans;
    }
    
    cout << ans << endl;
    
    return 0;
}


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

int main() {
 int n,m;
  cin >> n >> m;
  vector<int> a(n);
  
  rep (i,n) {
  cin >>a.at(i);
  }
  
  int total = 0;
  rep(i,n) {
   total += a.at(i);
  }
  std::sort(a.begin(),a.end(), std::greater<int>());
  
  bool choice = true;
  
  rep (i, m) {
   if (a.at(i) * 4 * m < total ) {
   choice = false;
   break;
  }
  }
  if (choice) {
    cout << "Yes";
  }
    else {
    cout << "No";
    }
}


Measured memory_bytes: 3604
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long int LL;
typedef long long int ll;
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include<stack>

int main()
{
#ifdef LOCAL
    freopen("data.h", "r", stdin);
    //freopen("1.h","w",stdout);
#endif
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(c>=a&&c<=b) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 256
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
typedef long long ll;
string O,E;
int main(){
	cin>>O;
	cin>>E;

	int S=O.size()+E.size();

	for(int i=0;i<S;i++){
		if(i%2==0){
			cout<<O[i/2];
		}else{
			cout<<E[i/2];
		}
	}
	cout<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int n;
    cin >> n;

    int x = n;
    while(x != 1){
        if(x % 2){
            break;
        }
        x /= 2;
    }
    if(x == 1){
        cout << "No" << endl;
        return 0;
    }

    int cnt = 0;
    x = n;
    while(x != 1){
        x /= 2;
        cnt++;
    }

    cout << "Yes" << endl;
    cout << "1 2" << endl;
    cout << "2 3" << endl;
    cout << 3 << " " << n + 1 << endl;
    cout << n + 1 << " " << n + 2 << endl;
    cout << n + 2 << " " << n + 3 << endl;
    for(int i = 4; i + 1 <= n; i += 2){
        cout << i << " " << i + 1 << endl;
        cout << i + 1 << " " << n + 1 << endl;
        cout << n + 1 << " " << n + i << endl;
        cout << n + i << " " << n + i + 1 << endl;
    }
    if(n % 2 == 0){
        cout << n + (1 << cnt) << " " << n << endl;
        cout << (n ^ 1 ^ (1 << cnt)) << " " << n * 2 << endl;
    }

    return 0;
}


Measured memory_bytes: 2816
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner src = new Scanner(System.in);
         int i = 1;
        while(true) {
            int num = src.nextInt();
            
            if(num == 0){
                break;
            }else {
                System.out.println("Case "+i + ": "+  num );
                i += 1;
            }
        }
    }
}


Measured memory_bytes: 41648
import java.util.Scanner;

public class Main{
	
	public static void main(String[] args) {
		int N, time = 0;
		int[] C = new int[500];
		int[] S = new int[500];
		int[] F = new int[500];
		
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		for(int i = 0; i < N - 1; i++) {
			C[i] = sc.nextInt();
			S[i] = sc.nextInt();
			F[i] = sc.nextInt();
		}
		int[] ans = new int[N];
		
		for(int i = 0; i < N - 1; i++) {
			time = 0;
			for(int j = i; j < N - 1; j++) {
				time += calcTime(time, C[j], S[j], F[j]);
			}
			ans[i] = time;
		}
		for(int i: ans) {
			System.out.println(i);
		}
		
	}
	private static int calcTime(int ft, int C, int S, int F) {
		int tt;
		
		if(ft < S) {
			tt = S;
		}else if(ft % F == 0) {
			tt = ft;
		}else {
			tt = ft + F - ft % F;
		}
		return tt + C - ft;
	}
}

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

char str[31];
bool ascii[26]={false};

int main(){
    scanf("%s", str);
    bool flag = true;
    for(int i=0; i<(int)strlen(str); i++){
        if(ascii[str[i]-'a']){
            printf("no\n");
            flag = false;
            break;
        }
        ascii[str[i]-'a'] = true;
    }
    if(flag)printf("yes");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using T = tuple<string,int,int>;

int main(){
  ll x; cin >> x;
  ll total = 100;
  ll cnt = 0;
  while(x > total){
    cnt++;
    total += total*0.01;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3636
# -*- coding: utf-8 -*-
import sys


S_list=list(input().strip())
sub_S = S_list[2:-1]

if S_list[0] != "A"  or  sub_S.count("C") != 1:
    print("WA")
    sys.exit()

check_S = S_list[:]
del check_S[ 2 + sub_S.index("C") ]
del check_S[0]

for word in check_S:
    if "a" <= word <= "z":
        continue
    else:
        print("WA")
        sys.exit()

print("AC")


Measured memory_bytes: 2940
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          Aman Raj  - @amanraj1608
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

#include<bits/stdc++.h>
//Short Keywords
#define ll          long long
#define pb          push_back
#define mp          make_pair
#define end         '\n'
#define mii         map<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (ll int)x.size()
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }


int main() {
    fast_io;
    int n;
    cin >> n;
    int v[n]={0},c[n]={0},sum=0;
    rep(i,0,n) cin >> v[i];
    rep(i,0,n) cin >> c[i];
    rep(i,0,n) {
        if(v[i]-c[i]>=0)
            sum+=v[i]-c[i];
    }
    cout << sum << "\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <complex>
#include <vector>
#include <algorithm>
using namespace std;

const double EPS = 1e-7;
typedef complex<double> P; /* _ */
struct L {                 /* üª */
	P p, q;
	L(P p, P q) : p(p), q(q) {}
};

// OÏ
double cross(P a, P b) { return imag(conj(a)*b); }

// ¼üaÆ¼übÌð_ðvZ·éDæÉð·»èªK{D
P crossPointLL(L a, L b){
	double A = cross(a.q-a.p, b.q-b.p);
	double B = cross(a.q-a.p, a.q-b.p);
	return b.p + B/A * (b.q-b.p);
}

// _pÆ_qÌ¼ñªüðÔ·
L pointBisector(P p, P q) {
	P cen = (p+q)*0.5;
	return L(cen, cen+(q-p)*P(0,1));
}

int main(){
	int n;
	cin>>n;
	double x1, y1, x2, y2, x3, y3;
	while(cin>>x1>>y1>>x2>>y2>>x3>>y3){
		// Cuè@
		P p1 = P(x1, y1);
		P p2 = P(x2, y2);
		P p3 = P(x3, y3);
		L l1 = pointBisector(p1, p2);
		L l2 = pointBisector(p2, p3);
		P cen = crossPointLL(l1, l2);
		double r = abs(p1-cen);

		// ö®ðp¢½è@
		double a1 = 2*(x2-x1);
		double b1 = 2*(y2-y1);
		double c1 = x1*x1-x2*x2+y1*y1-y2*y2;
		double a2 = 2*(x3-x1);
		double b2 = 2*(y3-y1);
		double c2 = x1*x1-x3*x3+y1*y1-y3*y3;
		double cx = (b1*c2-b2*c1)/(a1*b2-a2*b1);
		double cy = (c1*a2-c2*a1)/(a1*b2-a2*b1);
		P cen2 = P(cx, cy);
		double r2 = abs(p1-cen2);

		printf("%.3f %.3f %.3f", cen2.real(), cen2.imag(), r2);
		cout<<endl;

		// ÜÆß
		//int x1000 = cen2.real() >= 0 ? 1000*cen2.real()+0.5 : 1000*cen2.real()-0.5;
		//int y1000 = cen2.imag() >= 0 ? 1000*cen2.real()+0.5 : 1000*cen2.real()-0.5;
		//int r1000 = r2          >= 0 ? 1000*r2         +0.5 : 1000*r2         -0.5;
		//printf("%.3f %.3f %.3f", 1.0*x1000/1000, 1.0*y1000/1000, 1.0*r1000/1000);
		//cout<<endl;

	}
	return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define MAX_V 10006
#define INF 0x3fffffff
using namespace std;
struct edge{
    int to,cost,dis;
    };
typedef pair<int,int> P;
int V;
vector<edge> G[MAX_V];
int d[MAX_V];

void dij(int s){
    priority_queue<P,vector<P>,greater<P> > que;
    fill(d,d+V,INF);
    d[s]=0;
    que.push(P(0,s));
    while(!que.empty()){
        P p=que.top();que.pop();
        int v=p.second;
        if(d[v]<p.first)continue;
        for(int i=0;i<G[v].size();i++){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(P(d[e.to],e.to));
            }
        }
    }
    int ans=0;

    for(int i=1;i<V;i++){
        int mimcost=INF;
        for(int j=0;j<G[i].size();j++){
            if(d[G[i][j].to]+G[i][j].cost==d[i]&&G[i][j].dis<mimcost){

                mimcost=G[i][j].dis;
                //cout<<mimcost<<endl;
            }
        }
        //cout<<mimcost<<endl;
        ans+=mimcost;
    }
    cout<<ans<<endl;

}

int main(){
   // freopen("1.txt","r",stdin);
    int M;
    while(cin>>V>>M){
        if(V==0&&M==0)break;
        for(int i=0;i<V;i++)G[i].clear();
        while(M--){
            int a,b,t,c;
            cin>>a>>b>>t>>c;
            a--;b--;
            edge tmp;
            tmp.to=b;
            tmp.cost=t;
            tmp.dis=c;
            G[a].push_back(tmp);
            tmp.to=a;
            G[b].push_back(tmp);
        }
        dij(0);
    }
    return 0;
}

Measured memory_bytes: 5020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    string s,t;
    cin>>s>>t;
    int num=0;
    for(int i=0;i<=2;i++){
        if(s[i]!=t[i]){
            ++num;
        }
    }
    num=3-num;
    cout<<num;
    return 0;
}

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

#define int long long
#define double long double

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()

#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

const int INF = 1e16;
const int MOD = 1e9+7;

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

int c = 0;

void show(vi A)
{
    REP(i, A.size()-1) cout << A[i] << " ";
    cout << A[A.size()-1] << endl;
}

void selectionSort(vi& A, int N)
{
    REP(i, N)
    {
        int minj = i;
        for(int j = i; j < N; j++)
        {
            if(A[j] < A[minj]) minj = j;
        }
        if(i != minj)
        {
            c++;
            swap(A[i], A[minj]);
        }
    }
}

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int N; cin >> N;
    vi A(N); REP(i, N) cin >> A[i];
    selectionSort(A, N);
    show(A);
    cout << c << endl;
}


Measured memory_bytes: 3184
N = int(input())
A = list(map(int, input().split())) 

"""
A[i] + A[j] = j - i
A[i] + i = j - A[j]

a = A[i] + i
b = j - A[j]
"""

ans = 0
dic = {}

for i in range(N-1, -1, -1):
    wa = A[i] + i
    if wa in dic:
        ans += dic[wa]
    sa = i - A[i]
    if sa in dic:
        dic[sa] += 1
    else:
        dic[sa] = 1
print(ans)

Measured memory_bytes: 40236
using System;

namespace ABC080
{
    class B
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int n = N;
            int sum = 0;
            while (0 < n)
            {
                sum += n % 10;
                n = n / 10;
            }

            if (N % sum == 0) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); }

        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include<list>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<set>
#include<map>
using namespace std;
int main()
{
    multiset<int > s;
    int q;
    cin>>q;
    int b,tp1;
    while(q--){
        cin>>tp1;
        if(tp1==1){
                cin>>b;
                cout<<s.count(b)<<"\n";
        }
        else if(tp1==0){
            cin>>b;
            s.insert(b);
            cout<<s.size()<<"\n";
        }
        else if(tp1==2){
            cin>>b;
            s.erase(b);
        }
        else{
            int r,l;
            cin>>l>>r;
            set<int>::iterator it=s.lower_bound(l);
            while(*it<=r&&it!=s.end()){
                cout<<*it<<"\n";
                it++;
            }
        }
    }

}





Measured memory_bytes: 12260
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int h = scan.nextInt();
		int a = scan.nextInt();

		int result;
		if (h % a == 0)
			result = h / a;
		else
			result = h / a + 1;
		System.out.println(result);
	}

}


Measured memory_bytes: 22868
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

ll gcd(ll i,ll j){
  if(i<j){
    swap(i, j);
  }
  if(j==0)return i;
  ll r=i%j;
  while(r!=0){
    i=j;
    j=r;
    r=i%j;
  }
  return j;
}


int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n){
    cin >> a[i];
  }
  vector<ll> g1(n+1);
  g1[1]=a[0];
  repo(i, n-1){
    g1[i+1]=gcd(g1[i], a[i]);
  }
  vector<ll> g2(n+1);
  g2[n-1]=a[n-1];
  for(int i=n-2; i>=0; i--){
    g2[i]=gcd(g2[i+1], a[i]);
  }
  ll ans=0;
  repo(i, n){
    ans=max(ans, gcd(g1[i-1], g2[i]));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5616
#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,A[100];
    cin>>n;
    rep(i,n) cin>>A[i];
    double ans=0;
    sort(A,A+n);
    rep(i,n){
        if(i==0) ans+=A[i];
        else ans=(ans+A[i])/2;
    }
    cout<<setprecision(10)<<ans;
}

Measured memory_bytes: 256
/*in the name of Allah the most beneficent the most merciful.*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define MAX 1e18
#define MIN -1e18
#define MOD 1000000007
//#define mod2 20071027
//#define MOD 998244353
#define base 139
// #define MOD 1000074259
#define base2 31
#define memz(a) memset(a, 0, sizeof(a))
#define memn(a) memset(a, -1, sizeof(a))
#define in1(a) scanf("%lld", &a)
#define in2(a, b) scanf("%lld%lld", &a, &b)
#define TC(c) printf("Case #%lld: ", ++c)
#define out(x) cout << #x << " -> " << x << endl;
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FILE   freopen("input.txt", "r", stdin);  freopen("out.txt", "w", stdout);
using namespace std;
const ll B = 20, N = 300010, M = 2000000;
ll res, cnt[110], a[110], n, f,in[110];
string s;
int solve()
{
    in1(n);
    for (int i = 0; i < n; i++)
    {
        in1(a[i]);
    }
    sort(a, a + n);
    cnt[0] = 1;
    in[0]=a[0];
    for (int i = 1; i < n; i++)
    {
        if (a[i] != a[i - 1])
        {
           ++f;
           in[f]=a[i];
        }
        cnt[f]++;
    }
    for (int i = 0; i <= f; i++)
    {
        for (int j = i + 1; j <= f; j++)
        {
            for (int k = j + 1; k <= f; k++)
            {
                if (in[i] + in[j] > in[k] && in[j] + in[k] > in[i] && in[k] + in[i] > in[j])
                {
                    if (cnt[i] && cnt[j] && cnt[k])
                    {
                        res += (cnt[i] * cnt[j] * cnt[k]);
                    }
                }
            }
        }
    }
    printf("%lld\n", res);
    return 0;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    return solve();
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int M,D;
  int count = 0;
  cin >> M >> D;
  for (int i = 1; i <= M; i++) {
    for (int j = 1; j <= D; j++) {
      if (j%10 >= 2 && j/10 >= 2 && (j%10)*(j/10) == i){
        count++;
      }
    }
  }
  cout << count << endl;
}
  

Measured memory_bytes: 3596
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define debug(v) cout << #v<< ": " << v <<endl;
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL<<60;
ll M = 1000000007;

int main(){
    ll n; cin >> n;
    vll a(n);
    rep(i, 0, n){
        cin >> a[i];
    }    
    vll ac(n+1);
    ac[0] = 0;
    ll s = 0;
    rep(i, 1, n+1){
        s += a[i-1];
        ac[i] = s;
    }
    ll mn = INF;
    ll lc = 1, rc = 3;
    rep(i, 2, n-1){
        while(abs(ac[i] - ac[lc] - (ac[lc])) > abs(ac[i] - ac[lc+1] - ac[lc+1])){
            lc++;
        }
        while(abs(ac[n] - ac[rc] - (ac[rc] - ac[i])) > abs(ac[n] - ac[rc+1] - (ac[rc+1] - ac[i]))){
            rc++;
        }
        ll x = max(max(ac[lc], ac[i]-ac[lc]), max(ac[rc]-ac[i], ac[n]-ac[rc]));
        ll y = min(min(ac[lc], ac[i]-ac[lc]), min(ac[rc]-ac[i], ac[n]-ac[rc]));
        chmin(mn, x-y);
    }
    prtl(mn);
}



Measured memory_bytes: 6432
#include <bits/stdc++.h>
#define int long long
#define lint long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
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> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> 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); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

int N, Q;
vector<int> G[200010];
int dp[200010];

void dfs(int v, int pv, int s) {
    dp[v] += s;
    for (int u : G[v]) {
        if (u != pv) {
            dfs(u, v, dp[v]);
        }
    }
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    cin >> N >> Q;
    REP(i, N - 1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    REP(i, Q) {
        int p, x;
        cin >> p >> x;
        p--;
        dp[p] += x;
    }
    dfs(0, -1, 0);
    for (int i = 0; i < N; i++) {
        cout << dp[i] << " \n"[i+1==N];
    }

    return 0;
}

Measured memory_bytes: 24320
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

// エイリアス
using ll = long long;
using P = pair<int, int>;

int main() {
  // 入力
  int H, W;
  cin >> H >> W;
  vector<string> mp(H);
  for (int i = 0; i < H; i++) cin >> mp[i];

  int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
  int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (mp[i][j] == '#') {
        cout << '#';
        continue;
      }
      int cnt = 0;
      for (int k = 0; k < 8; k++) {
        int x = j + dx[k];
        int y = i + dy[k];
        if (x < 0 || W <= x || y < 0 || H <= y) continue;
        if (mp[y][x] == '#') cnt++;
      }
      cout << cnt;
    }
    cout << endl;
  }

  return 0;
}


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

typedef long long ll;

int main() {
    string S, T = "AKIHABARA";
    cin >> S;
    int i = 0;
    rep(j, 9) {
        if (S[i] == T[j]) {
            i++;
            continue;
        }
        if (T[j] == 'A') {
            continue;
        }
        cout << "NO\n";
        return 0;
    }
    if (i == S.size()) cout << "YES\n";
    else cout << "NO\n";
}

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

int main(){
    string s; cin >> s;
    string res = "";
    for(int i = 0; i < s.size(); i+=2){
        res+=s[i];
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>

int main(void){
	int rad=90,n,m;
	double x=0,y=0;
	char str[100],*line;

	for( ; ; ){
		fgets(str,sizeof(str),stdin);
		line = strtok(str,",");
		sscanf(line,"%d",&n);
		line = strtok(NULL,",");
		sscanf(line,"%d",&m);
		if(n==0 && m==0)
			break;
		x += n*cos(rad*M_PI/180);
		y += n*sin(rad*M_PI/180);
		rad -= m;
	}
	printf("%d\n%d\n",(int)x,(int)y);
	return 0;
}

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

typedef long long ll;
#define int ll
#define db(x) cout<<#x<<" = "<<x<<"\n";
#define FIN ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ALL(a) a.begin(),a.end()
#define mset(a,b) memset(a,b,sizeof(a));

void solve()
{
    int n;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++)
    cin>>arr[i];
    if(n<3)
    {
        cout<< 0;
        return ;
    }
    
    sort(arr,arr+n);
    int ans=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            for(int k=j+1;k<n;k++)
            {
                if(arr[i]+arr[j]>arr[k]&&arr[i]!=arr[j]&&arr[i]!=arr[k]&&arr[j]!=arr[k])
                ans++;
            }
        }
    }
    cout<<ans<<endl;
}
main() 
{
	FIN;
	solve();
	
	
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<string.h>

int main(void){

    char S[101];
    int i,j,ans=0;

    scanf("%s",S);
    i = 0;
    j = strlen(S)-1;

    while(j-i > 0){
        if(S[i] != S[j]) ans++;
        i++;
        j--;
    }

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

Measured memory_bytes: 128
c = [[int(cn) for cn in input().split()] for _ in range(3)]
max_val = max(c[0])
ans = 'No'
for a1 in range(max_val + 1):
  b = [c[0][i] - a1 for i in range(3)]
  correct = True
  for i in range(2):
    ai_cand = []
    for j in range(3):
      cand = c[i + 1][j] - b[j]
      correct = cand >= 0
      if correct:
        ai_cand.append(cand)
      else:
        break
    if correct:
      correct = ai_cand[0] == ai_cand[1] and ai_cand[1] == ai_cand[2]
      if not correct:
        break
    else:
      break
  if correct:
    ans = 'Yes'
    break
print(ans)


Measured memory_bytes: 62212
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = n;
  for (int i=0; i<n; i++) {
    if (i==0) continue;
    if (s[i]==s[i-1]) ans--;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512