akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <math.h>
#include <vector>
#include <stack>
#include <cstdio>
#include <string>
#include <bitset>
#include <list>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <functional>
#include <queue>
#include <regex>
#include <cassert>
#include <map>
// #include "bits/stdc++.h"

using namespace std;
//debug

#define rep(i, N, M) for (ll i = N; i < M; ++i)
#define rrep(i, N, M) for (ll i = N; i < M; --i)
#define pb push_back


typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef priority_queue<ll> pqll;
typedef priority_queue<pll, vector<pll>> pqpll;
typedef priority_queue<ll, vll, greater<ll>> pqll_greater;
typedef priority_queue<pll, vector<pll>, greater<pll>> pqpll_greater;


#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define vec(a) vector<a>
#define _CRT_SECURE_NO_WARNINGS

template<class T, class S>
T atbit(T n, S i) {
	return (n >> i) % i;
}

template<class T>
T getbit(T i) {
	return 1LL << i;
}

//#define TRANSFORM(v,w,func) decltype(v) w ; transform((v).begin(),(v).end(),back_inserter(w),func);

using namespace std;


int main() {
	ll N, K;
	cin >> N >> K;
	vll x(N);
	rep(i, 0, N) {
		cin >> x[i];
	}
	ll np = count_if(x.begin(), x.end(), [](ll a) {return a >= 0; });
	ll np_ = count_if(x.begin(), x.end(), [](ll a) {return a > 0; });
	ll nm = count_if(x.begin(), x.end(), [](ll a) {return a <= 0; });
	ll nm_ = count_if(x.begin(), x.end(), [](ll a) {return a < 0; });

	auto get_cost = [&](ll idx,char flag) {//
		if (flag=='R') {
			return *(lower_bound(x.begin(), x.end(), 0) + (idx-1));
		}
		else {
			return - *(upper_bound(x.begin(), x.end(), 0) - idx);
		}
	};

	
	vll cost;// ( cost , i)

	rep(i, 0, N-K+1) {
		cost.push_back(
			abs(x[i]) + x[i + K - 1] - x[i]
		);
		cost.push_back(
			abs(x[i+K-1]) + x[i + K - 1] - x[i]
		);
	}

	cout << *min_element(cost.begin(),cost.end());
}
//ll N;
//cin >> N;
//vll a(N);
//rep(i,0, N) cin >> a[i];

Measured memory_bytes: 2168
/*
    Life Before Death, Strength Before Weakness, Journey Before Destination
    ------------------------------------------------------------------------
    You don't become great by trying to be great.
    You become great by wanting to do something,
    and then doing it so hard that you become great in the process.
    */
 
    //#pragma comment(linker, ack:200000000")
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #include <bits/stdc++.h>
    using namespace std;
    
    #define TRACE
    
    #ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
      cerr << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
      const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
    #else
    #define trace(...)
    #endif
    
    #define rep(i, n)    for(ll i = 0; i < (n); ++i)
    #define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
    #define repD(i, a, n)  for(ll i = a; i >= (n); --i)
    #define trav(a, x) for(auto& a : x)
    #define all(x) x.begin(), x.end()
    #define sz(x) (int)(x).size()
    #define fill(a)  memset(a, 0, sizeof (a))
    #define fst first
    #define snd second
    //#define mp make_pair
    #define pb push_back
    #define PI           3.141592653589793238462643383279502884197169399  /* pi */
    // #define te    
    typedef long double ld;
    typedef long long ll;
    typedef pair<ll, ll> pii;
    typedef vector<ll> vi;
    const int maxN = 100100;

    void solve() {
        ll n, cnt = 0;
        cin >> n;
        string a, b;
        cin >> a >> b;
        rep(i, n){
            ll f = 10;
            rep(j, n-i) if(a[j+i]!=b[j]) f = 5;
            if(f == 10){
                //cout << "fd " << i << endl;
                cout << (n + i) << endl; 
                return;
            }
        }
        cout << (2*n) << endl;
    }
 
    int main() {
      cin.sync_with_stdio(0); cin.tie(0);
      cin.exceptions(cin.failbit);
      // ll ti;   cin >> ti;  while(ti--)
      solve();
      return 0;
    } 

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

ull fact(int n){
    ull ans=1;
    if (n==0)return 1;
    for (int i=1;i<=n;i++){
        ans=(ans*i)%1000000007;
    }return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ull n,m;cin>>n>>m;
    if (n==m||n==m+1||m==n+1){
        if (n==m){
            cout<<((fact(n)%1000000007)*((fact(m)%1000000007))*2)%1000000007;
        }else cout<<((fact(n)%1000000007)*((fact(m)%1000000007)))%1000000007;
    }else cout<<0;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int N,Q;
ll a[100000];

ll solve(ll S){
  ll sum=0,ans=0,k=0;
  for(int i=0;i<N;i++){
    sum+=a[i];
    while(sum>S){
      sum-=a[k];
      k++;
    }
    ans+=(i-k+1);
  }
  return ans;
}

int main(){

  scanf("%d %d",&N,&Q);
  for(int i=0;i<N;i++)scanf("%lld",&a[i]);
  for(int i=0;i<Q;i++){
    ll x;
    scanf("%lld",&x);
    printf("%lld\n",solve(x));    
  }

  return 0;
}

Measured memory_bytes: 3984
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>

typedef long long ll;

using namespace std;

typedef struct data
{
    ll id, score;
    string name;
} data_t;

int main()
{
    ll n;
    string ss;
    ll va; 

    cin >> n;
    vector<data_t> t(n);

    for (ll i=0; i<n; ++i)
    {
        cin >> ss >> va;
        t[i].id = i;
        t[i].name = ss;
        t[i].score = va;
    }

    for (ll i=0; i<n; i++) 
    {
        for (ll j=i; j<n; j++)
        {
            if (t[i].name > t[j].name)
            {
                swap(t[i].name, t[j].name);
                swap(t[i].id, t[j].id);
                swap(t[i].score, t[j].score);
            }
        }
    }
    for (ll i=0; i<n; i++) 
    {
        for (ll j=i; j<n; j++)
        {
            if (t[i].name == t[j].name)
            {
                if (t[i].score < t[j].score)
                {
                    swap(t[i].id, t[j].id);
                    swap(t[i].score, t[j].score);
                }
            }
        }
    }

    for (ll i=0; i<n; ++i)
    {
        cout << t[i].id+1 << endl;
        //cout << t[i].name << t[i].score << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define H ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
using namespace std;
const ll  mod = 998244353;

    int frq[200001];

int main()
{
    H
    int n;
    cin >> n;
    int a[n], b[n], c[n];
    ll sum[n];
    for (int i = 0; i < n; i++) cin >> c[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(b, b + n);
    sort(c, c + n);
    for (int i = 0; i < n; i++){
        auto x = lower_bound(c, c + n, b[i]);
        sum[i] = x - c;
        if (i) sum[i] += sum[i - 1];
        //cout << x - c << '\n';
    }
    ll ans = 0;
    int idx;
    for (int i = 0; i < n; i++){
        idx = lower_bound(b, b + n, a[i]) - b - 1;
        if (idx >= 0) {
            ans += sum[idx];
            //cout << idx << ' ' << sum[idx] << '\n';
        }
    }
    cout << ans;
    return 0 ;
}


Measured memory_bytes: 2176
N, Y = gets.split.map(&:to_i)
tmp = 0
key = 0
(0..N).each do |i|
	(0..(N-i)).each do |j|
		tmp = 10000*i + 5000*j + 1000*(N-i-j)
		if tmp == Y
			key = 1
			puts "#{i} #{j} #{N-i-j}"
			break
		end
	end
	if key == 1
		break
	end
end

if key == 0
	puts "-1 -1 -1"
end

Measured memory_bytes: 14396
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli > plli;
typedef vector<lli> vlli;
typedef vector<plli > vplli;

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define lcm(a, b) ((a * b) / gcd(a, b))
#define sqr(x) (x)*(x)
#define all(a) a.begin(),a.end()
#define UN(v) sort(all(v)), v.resize(unique(all(v))-v.begin())

#define endl '\n'

const long long INF = 100000000000000000;
const long long MOD = 1000000007;
const long long MAXN = 100005;
const double PI = acos(-1);

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

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

void solve() {
    int a[3][3], n;
    int check[3][3];
    memset(check, 0, sizeof(check));
    for (auto & i : a) {
        for (int & j : i) {
            cin >> j;
        }
    }
    cin >> n;
    for (int i = 0; i < n; i++) {
        int b;
        cin >> b;
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if (a[j][k] == b) {
                    check[j][k] = 1;
                }
            }
        }
    }

    for (int i = 0; i < 3; i++) {
        if (check[i][0] and check[i][1] and check[i][2]) {
            cout << "Yes" << endl;
            return;
        }
        if (check[0][i] and check[1][i] and check[2][i]) {
            cout << "Yes" << endl;
            return;
        }
    }
    if (check[0][0] and check[1][1] and check[2][2]) {
        cout << "Yes" << endl;
        return;
    }
    if (check[0][2] and check[1][1] and check[2][0]) {
        cout << "Yes" << endl;
        return;
    }
    cout << "No" << endl;
}

int main()
{
    IOS;
    int t = 1;
    //cin >> t;
    for (int i = 1; i <= t; i++) {
        //cout << "Case " << i << ": ";
        solve();
    }
    return 0;
}


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

int main(){
    char ch;
    int cnt[26]={};
    
    while(cin >> ch){
        ch =tolower(ch);
        if (isalpha(ch)){
            cnt[ch-'a']++;
        }
    }
    for(int i=0;i<26;i++){
        printf("%c : %d\n",i+'a',cnt[i]);
    }
    return 0;
}


Measured memory_bytes: 3056
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main(){
#ifdef CIN
	ifstream cin("input.txt");
	ofstream cout("output.txt");
#endif

	int a, b;

	cin >> a >> b;

	if (a > b) cout << "a > b" << endl;
	else if (a == b) cout << "a == b" << endl;
	else cout << "a < b" << endl;


	return 0;
}

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

int main()
{
	int n;
	cin>>n;
	int x=0;

	while(n)
	{
		if(n%10==7)
		{
			x=1;
			break;
		}
		n=n/10;
	}

	if(x==0)
		cout<<"No";
	else cout<<"Yes";
	return 0;
}

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

typedef long long ll;

using namespace std;

#define MAX 1000000

int a,d,n;

bool is_prime[MAX+1];
bool is_prime_small[MAX+1];


int main(){
    while(1){
        int ans=0;
        scanf("%d %d %d",&a,&d,&n);
        if(a==0 && d==0 && n==0)break;
        for (int i = 0; i*i <= MAX; i++) is_prime_small[i] = true;
        for (int i = 0; i <= MAX; i++) is_prime[i] = true;

        for(int i= 2; i*i <= MAX ;i++){
            if(is_prime_small[i]){
                for (int j = 2*i; j*j <= MAX ; j+= i) is_prime_small[j] = false;
                for(int j = max(2,(a+i-1)/i)*i;j <= MAX;j+= i)is_prime[j-a] = false;
            }
        }
        int p=0;
        //is_prime[i-a] = true ⇒　iが素数
        for (int i = a; i <= MAX; i+=d){
            if(i==1)continue;
            if(is_prime[i-a]){
                p++;
            }
            if(p==n){
                ans=i;
                break;
            }
        }
        printf("%d\n",ans);


    }
}


Measured memory_bytes: 4140
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_2_C&lang=jp
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n[3];
  for(int i=0;i<3;i++)cin>>n[i];
  sort(n,n+3);
  for(int i=0;i<3;i++){
    if(i!=2)cout<<n[i]<<" ";
    else cout<<n[i];
  }
  cout<<endl;
  return 0;
}



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

//LIFE IS NOT A PROBLEM TO BE SOLVED

using namespace std;

#define rep(i,a,b) for(int i = int(a); i < int(b) ; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

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


int main(){
	
	string s; cin >> s;
	s[3] = '8';
	cout << s << '\n';
	
	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int par1[200000];
int par2[200000];
int ran1[200000];
int ran2[200000];

void init(int n){
  rep(i,0,n){
    par1[i]=i;
    ran1[i]=0;
    par2[i]=i;
    ran2[i]=0;
  }
}

int find1(int x){
  if(par1[x]==x) return x;
  return par1[x]=find1(par1[x]);
}

int find2(int x){
  if(par2[x]==x) return x;
  return par2[x]=find2(par2[x]);
}

void unite1(int x,int y){
  x=find1(x);
  y=find1(y);
  if(x==y) return;
  if(ran1[x]<ran1[y]) par1[x]=y;
  else{
    par1[y]=x;
    if(ran1[x]==ran1[y]) ran1[x]++;
  }
}

void unite2(int x,int y){
  x=find2(x);
  y=find2(y);
  if(x==y) return;
  if(ran2[x]<ran2[y]) par2[x]=y;
  else{
    par2[y]=x;
    if(ran2[x]==ran2[y]) ran2[x]++;
  }
}

bool same1(int x,int y){
  return find1(x)==find1(y);
}

bool same2(int x,int y){
  return find2(x)==find2(y);
}

int main(){
  int n,k,l;
  cin>>n>>k>>l;
  init(n);
  rep(i,0,k){
    int a,b;
    cin>>a>>b;
    unite1(a-1,b-1);
  }
  rep(i,0,l){
    int a,b;
    cin>>a>>b;
    unite2(a-1,b-1);
  }
  
  map<P,vector<int>> m;
  int ans[n];
  rep(i,0,n){
    m[P(find1(i),find2(i))].push_back(i);
  }
  for(auto p:m){
    rep(i,0,p.second.size()){
      ans[p.second[i]]=p.second.size();
    }
  }
  rep(i,0,n){
    cout<<ans[i]<<endl;
  }
}

Measured memory_bytes: 24448
S = input()
T = input()

s_dict = {}
for i in S:
    if not i in s_dict.keys():
        s_dict[i] = 1
    else:
        s_dict[i] += 1

t_dict = {}
for i in T:
    if not i in t_dict.keys():
        t_dict[i] = 1
    else:
        t_dict[i] += 1

if sorted(s_dict.values()) == sorted(t_dict.values()):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
char c[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ",s[10010];
int main()
{
    int i,n;
    scanf("%d",&n);
    scanf("%s",s);
    for(i=0;i<strlen(s);i++)
    {
    	printf("%c",c[(s[i]-'A'+n)%26]);
    }
    return 0;
}

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

using namespace std;

const int N=2e5+5;

int n,k,a[N];

double ans,pre[N];

int main()
{
    cin >> n >> k;
    for (int i=0;i<n;i++)
    {
        cin >> a[i];
        pre[i+1]=(a[i]*(a[i]+1))/2;
        pre[i+1]/=a[i];
    }
    for (int i=1;i<=n;i++)
    {
        pre[i]+=pre[i-1];
    }
    for (int i=k;i<=n;i++)
    {
        ans=max(ans,pre[i]-pre[i-k]);
    }
    cout << fixed << setprecision(6) << ans << endl;
    return 0;
}



Measured memory_bytes: 2560
#include<iostream>
using namespace std;
int main(){
  string s;
  cin>>s;
  string ss;
  cin>>ss;
  for(int i=0;i<s.length();i++){
    if(s[i]!=ss[i]){
      cout<<"No";
      return 0;
    }
  }
  cout<<"Yes";
  return 0;
}

Measured memory_bytes: 3596
from collections import deque
s = input()
q = int(input())

s = deque(s)
cnt = 0

for i in range(q):
    Q = list(input().split())
    if int(Q[0]) == 1:
        cnt += 1
    else:
        if int(Q[1]) == 1:
            if cnt % 2 == 0:
                s.appendleft(Q[2])
            else:
                s.append(Q[2])
        else:
            if cnt % 2 == 0:
                s.append(Q[2])
            else:
                s.appendleft(Q[2])

ans = ''

for _ in range(len(s)):
    if cnt % 2 == 0:
        ans += s.popleft()
    else:
        ans += s.pop()

print(ans)
 

Measured memory_bytes: 6276
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <climits>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << -1; return;}
#define yes {cout << "Yes"; return;}
#define mkp make_pair
#define mkt make_tuple
#define cerr if(0) cerr

void solve() {
    int n; cin >> n;
    vector <int> a(n);
    loop(i, n)
        cin >> a[i];
    sort(all(a));
    int ans = 0;
    loop(i, n) {
        loop(j, i) {
            int r = upper_bound(all(a), a[i] + a[j] - 1) - a.begin(), l = lower_bound(all(a), abs(a[i] - a[j]) + 1) - a.begin();
            ans += r - l - (l <= i && r > i) - (l <= j && r > j);
        }
    }
    cout << ans / 3;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 3672
a = input().split()
N, L = [int(i) for i in a]
l = []
for i in range(1,N+1):
  dif = abs(L+i-1)
  l.append(dif)
m = l.index(min(l)) + 1
sol = N*L + (N-1)*N/2 - (L+m-1)
print(int(sol))

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

int main(void){
  int n,a,b,c,d,x,y;
  
  cin >> n >> a >> b >> c >> d;
  x = (n+a-1)/a * b;
  y = (n+c-1)/c * d;
  cout << (x<y?x:y) << endl;
  return 0;
}



Measured memory_bytes: 3112
#include<bits/stdc++.h>
#define fo(i,a,b)for(int i=a,_e=b;i<=_e;++i)
#define ll long long
using namespace std;
const int N=1e5+5;
int n,a,b,is[N],c[4];
struct nod{int a,i;}v[N*2];
ll tot,tot2,ansa,ansb;
bool cmp(nod a,nod b){return a.a<b.a;}
int main(){
	ios::sync_with_stdio(false);
	cin>>n;
	fo(i,1,n)cin>>a>>b,v[i*2]=(nod){a,i},v[i*2-1]=(nod){b,-i},ansa+=a,ansb+=b;
	sort(v+1,v+n*2+1,cmp);
	fo(i,1,n){
		tot+=v[i].a;
		is[abs(v[i].i)]|=v[i].i>0?2:1;
	}
	fo(i,1,n)c[is[i]]++;
	if(c[1]+c[2]==n){
		tot2=tot-v[n-1].a;
		tot-=v[n].a;
		is[abs(v[n].i)]=0;
		fo(i,n+1,n*2)
			if(is[abs(v[i].i)]){
				tot+=v[i].a;
				break;
			}
		is[abs(v[n].i)]=1;
		is[abs(v[n-1].i)]=0;
		fo(i,n+1,n*2)
			if(is[abs(v[i].i)]){
				tot2+=v[i].a;
				break;
			}
		tot=min(tot,tot2);
	}
	cout<<min(tot,min(ansa,ansb));
}

Measured memory_bytes: 2176
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const ll INF=1e+18;
const int MOD=1e+9+7;

//REPマクロ
#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 REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

using Graph =vector<vector<ll>>;
int main(){
    ll N,K;
    cin>>N>>K;
    vector<ll> G(N);
    vector<vector<ll>> cost(N,vector<ll>(N,0));
    vector<ll> P(N),C(N);
    REP(i,N){
        cin>>P[i];
        P[i]--;
        G[i]=P[i];
    }
    REP(i,N) cin>>C[i];
    REP(i,N){
        cost[i][P[i]]=C[i];
    }


    ll ans=-INF;
    REP(i,N){
        vector<ll> dist; // 全頂点を「未訪問」に初期化
        vector<ll> junban;
        int v=i;
        int nv;
        ll dis=0;
        dist.push_back(0);
        do{
            nv=G[v];
            dis+=cost[v][nv];
            dist.push_back(dis);
            v=nv;
        }while(v!=i);
        ll num=dist.size()-1;
        ll loop=dist[num];
        if(loop<0||K<=num){
            REP2(j,1,min(K+1,num+1)){
                ans=max(ans,dist[j]);
            }
        }else{
            ll tmp=(K/num)*loop;
            ll amari=K-(K/num)*num;
            REP(j,amari+1){
                ans=max(ans,tmp+dist[j]);
            }
            tmp-=loop;
            REP2(j,1,num+1){
                ans=max(ans,tmp+dist[j]);
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 199360
#include<stdio.h>

int main(void) {
  int a, b;
  int i = 0;
  scanf("%d %d", &a, &b);
  for ( i; ; i++ ) {
    if ( i >= ((double)(b-1) / (a-1)) ) { break; }
  }
  printf("%d\n", i);
  return 0;
}

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

int main(){
  string S;
  cin >> S;
  
  if(S.at(5) == '0' && S.at(6) < '5'){
    cout << "Heisei" << endl;
  }else{
    cout << "TBD" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define mm map<ii>
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/


int main()
{
	fast

	ll n;
	cin>>n;

	vl v(5);
	ll mini = inf;
	forn(i,0,5)
	{
		cin>>v[i];
		mini = min(mini,v[i]);
	}


	cout<<((ll)4 + (ll)ceil(((double)(n))/mini));


	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))

#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)

#define All(x) (x).begin(),(x).end()

#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))

#define Unique(v) v.resize(unique(All(v)) - v.begin())

#define peq(p0, p1)(p0.first == p1.first && p0.second == p1.second)

#define End '\n'
#define Out(x) cout<<(x)<<End
#define OutP(p, sep, end) cout<<p.first<<sep<<p.second<<end

template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lb std::lower_bound
#define ub std::upper_bound

#define lbi(v, x) lb(All(v), (x))-v.begin()
#define ubi(v, x) ub(All(v), (x))-v.begin()

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);
	//std::cout.precision(18);

    int a, b;

	cin >> a >> b;

	if (a == 1) a += 13;
	if (b == 1) b += 13;

	if (a < b) Out("Bob");
	else if (b < a) Out("Alice");
	else Out("Draw");
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end() 
#define asn ans
using namespace std;
template <typename T> istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;

int main() {
	int n; CI n;
	vector<int> a(n); CI a;
	int ans = 0;
	REP(i, n) {
		once:
		if (a[i] % 2 == 0) {
			ans++;
			a[i] /= 2;
			goto once;
		}
	}
	CO ans EN;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n = int(input())
MAX = 55555
is_prime = [1 for _ in range(MAX+1)]
is_prime[0] = 0
is_prime[1] = 0

for i in range(2, MAX+1):
    if is_prime[i]==0:
        continue
    else:
        for j in range(2*i,MAX+1,i):
            is_prime[j] = 0
primes = [i for i in range(MAX+1) if is_prime[i]==1]

res = []
for i in primes:
    if len(res)==n:
        break
    if i%5==1:
        res.append(i)

print(*res)


Measured memory_bytes: 3736
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
	int xx, yy, n;
	int x[120], y[120], a[120];
	while(~scanf("%d %d %d", &xx, &yy, &n))
	{
		int i;
		int ans = 0;
		int x1 = 0, x2 = xx, y1 = 0, y2 = yy;
		for(i = 0; i < n; i++)
		{
			scanf("%d %d %d", &x[i], &y[i], &a[i]);
			if(a[i] == 1)
			x1 = max(x1, x[i]);
			if(a[i] == 2)
			x2 = min(x2, x[i]);
			if(a[i] == 3)
			y1 = max(y1, y[i]);
			if(a[i] == 4)
			y2 = min(y2, y[i]);
		}
		ans = (x2 - x1) * (y2 - y1);
		if((x1 >= x2) || (y1 >= y2)) ans = 0;
		printf("%d\n", ans);
	}

}

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

int main(){
  int a,b;
  cin>>a>>b;

  if( a < b ) cout<<"a < b"<<endl;
  if( a > b ) cout<<"a > b"<<endl;
  if( a == b ) cout<<"a == b"<<endl;

  return 0;
}



Measured memory_bytes: 3104
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<list>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,x) unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;

/*
struct point
{
long long dist; long long name;
bool operator<(const point& rhs) const {
return dist > rhs.dist;
}
};
*/

ll const MAX = 200005;
vll G[MAX];
ll color[MAX] = {};
ll isolate = 0;
ll conn = 0;
ll sigl = 0;

void dfs(ll start) {
	if (SIZE(G[start]) == 0) {
		isolate++;
		return;
	}
	bool flag = 0;
	color[start] = 0;
	stack<ll> st;
	st.push(start);
	while (!st.empty()) {
		ll cur = st.top();
		st.pop();
		for (auto nex : G[cur]) {
			if (color[nex] == -1) {
				color[nex] = !color[cur];
				st.push(nex);
			}
			else if (color[nex] == color[cur]) {
				flag = 1;
			}
		}
	}
	conn++;
	if (flag) {
		sigl++;
	}
}

int main() {
	ll n, m; cin >> n >> m;
	REP(i, 0, MAX - 1) {
		color[i] = -1;
	}
	REP(i, 1, m) {
		ll a, b;
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	REP(i, 1, n) {
		if (color[i] == -1) {
			dfs(i);
		}
	}
	ll ans = 0;
	ans = n * n - (n-isolate) * (n-isolate);
	ans += sigl * conn * 2 - sigl * sigl;
	ll semi = conn - sigl;
	ans += semi * semi * 2;
	cout << ans << endl;
}

Measured memory_bytes: 13056
require 'set'

class Piece
	def initialize
		@blocks = []
		@children = Set.new
		@weight = 0
	end

	def add_block(y, x)
		@blocks << [y, x]
	end

	def add_child(piece)
		@children << piece
	end

	def check(root = false)
		@children.each(&:check)
		if @children.empty?
			@total_weight = 4
			@total_cg = @blocks.map(&:last).inject(:+) / 4.0 + 0.5 
		else
			@children.each do |c|
				touched = c.blocks.select{|y, x| @blocks.include?([y-1, x])}.map(&:last)
				xl, xr = touched.min, touched.max + 1
				raise if c.total_cg <= xl || xr <= c.total_cg
			end

			@total_weight = 4 + @children.map(&:total_weight).inject(:+)
			my_cg = @blocks.map(&:last).inject(:+) / 4.0 + 0.5 
			@total_cg = (my_cg * 4 + @children.map{|c| c.total_weight * c.total_cg}.inject(:+)) / @total_weight
		end

		if root
			touched = @blocks.select{|y, x| y == 0}.map(&:last)
			xl, xr = touched.min, touched.max + 1
			raise if @total_cg <= xl || xr <= @total_cg
		end
	end

	attr_reader :blocks, :total_weight, :total_cg
end


loop do
	w, h = gets.split.map &:to_i
	break if w == 0
	a = []
	h.times do
		a.unshift gets.chomp.split("")
	end

	hash = {}
	root = nil
	(0..h-1).each do |y|
		(0..w-1).each do |x|
			next if a[y][x] == ?.
			next if hash[[y, x]]
			piece = Piece.new
			hash[[y, x]] = piece
			root = piece if y == 0

			stack = [[y,x]]
			until stack.empty?
				i, j = stack.pop
				piece.add_block(i, j)

				v = [i+1, j]
				if i < h-1 && a[i][j] == a[i+1][j] && !hash[v]
					hash[v] = piece	
					stack << v
				end

				v = [i, j+1]
				if j < w-1 && a[i][j] == a[i][j+1] && !hash[v]
					hash[v] = piece	
					stack << v
				end

				v = [i, j-1]
				if j > 0 && a[i][j] == a[i][j-1] && !hash[v]
					hash[v] = piece	
					stack << v
				end
			end
		end
	end

	(0..h-2).each do |y|
		(0..w-1).each do |x|
			p_piece = hash[[y, x]]
			next if !p_piece
			if (c_piece = hash[[y+1, x]]) && (c_piece != p_piece)
				p_piece.add_child(c_piece)
			end
		end
	end

	begin
		root.check(true)
		puts 'STABLE'
	rescue
		puts 'UNSTABLE'
	end
end

Measured memory_bytes: 9348
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <map>
#define ull unsigned long long
#define ll long long
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,d,x,a;
    cin >> n >> d >> x;
    vector<int> a_1;
    for(int i=0;i<n;i++){
        cin >> a;
        a_1.push_back(a);
    }
    int ans=0;
    for(int i=0;i<n;i++){
        if(d%a_1[i]!=0){
            ans+=d/a_1[i]+1;
        }
        else ans+=d/a_1[i];
    }
    cout << ans+x << endl;
    return 0;
}

Measured memory_bytes: 256
/*input
20 20
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
....................
*/
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
int n,m;
vector<string> mat;
vector<vector<int>> dp;

int fun(int x,int y)
{
	if(x<0 || x>=n || y<0 || y>=m) return 0;
	if(dp[x][y]!=-1) return dp[x][y];
	if(mat[x][y]=='#') return dp[x][y]=0;
	if(x==0 && y==0) return dp[x][y]=1;
	int ans = (fun(x-1,y) + fun(x,y-1))%mod;
	return dp[x][y]=ans;
}

int main()
{
	cin>>n>>m;
	mat.resize(n);
	dp.assign(n,vector<int> (m,-1));
	for(int i=0;i<n;i++)
	{
		string s;cin>>s;
		mat[i]=s;
	}
	cout<<fun(n-1,m-1)<<"\n";
	return 0;
}


Measured memory_bytes: 8704
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    int n, k;
    cin >> n >> k;

    if (k == 1) {
        cout << 0 << endl;
    } else {
        cout << n - k << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import sys

n = int(input())
hs = list(map(int, input().split()))
goal = [0 for _ in range(n)]

count = 0
while True:
    # print(hs)
    if hs == goal:
        print(count)
        sys.exit()

    count += 1
    is_done = False
    for i in range(n):
        if hs[i] == 0:
            if is_done:
                break
        else:
            hs[i] = hs[i] - 1
            is_done = True

Measured memory_bytes: 40432
from fractions import gcd
n =int(input())
a =list(map(int ,input().split()))

b =[a[0]]
for i in range(1,n-1):
    b.append(gcd(b[-1],a[i]))

c =[a[-1]]
for i in range(n-2,0,-1):
    c.append(gcd(c[-1], a[i]))

MAX =0
for i in range(n):
    if i == 0:
        MAX =max(MAX, c[-1])
    elif i ==n-1:
        MAX =max(MAX, b[-1])
    else:
        MAX =max(MAX, gcd(b[i-1], c[n-i-2]))
print(MAX)

Measured memory_bytes: 16576
#include <bits/stdc++.h>
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;

#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for (int i=(a); i<(b); ++i)
#define FORD(i,a,b) for (int i=(a)-1; i>=(b); --i)

#define pb push_back
#define mp make_pair
#define st first
#define nd second

const int MOD = 1000000007;

int A[222222];
int main() {
  // ios_base::sync_with_stdio(0);

  int N;
  scanf("%d", &N);
  REP(i,N) {
    scanf("%d", &A[i]);
  }

  LL result = 0;
  REP(i,N) {
    bool ok = A[i] == 0;
    if (i > 0) ok = ok || (A[i] <= A[i-1]+1);
    if (!ok) {
      printf("-1\n");
      return 0;
    }

    if (i > 0 && A[i] != A[i-1]+1) result += A[i-1];
  }
  result += A[N-1];
  printf("%lld\n", result);
}


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

int main(){
  int a,b,c,d,e,f;
  cin >> a >> b >> c >> d >> e >> f;
  
  int answ = 0;
  int anss = 0;
  double ansr = -1.0;
  
  for (int i = 0; i * a * 100 <= f;i++){
    for( int j = 0;(i * a + j + b) <=f;j++){
      if (i + j){
        int water = 100 * ( i * a + j * b);
        int maxsugar = min(f - water, e * ( i * a + j * b));
        for ( int k = 0; c * k <= maxsugar;k++){
          int l = (maxsugar - c * k) / d;          
          int sugar = c * k + d * l;
          double rate = 100.0 * sugar / (water + sugar);
          if( water > 0  && water <= f && sugar <= e * ( i * a + j * b) && ansr < rate){
            answ = water;
            anss = sugar;
            ansr = rate;
          } //4kif
        }//4k
      }//4jif
    }//4j
   }//4i
  cout << answ + anss << ' ' << anss << endl;
}//main

Measured memory_bytes: 256
N, M = map(int, input().split())
Ai = []
for i in range(N):
    Ai.append(list(map(int, input().split())))

patterns = [
    [1, 1, 1],
    [1, 1, -1],
    [1, -1, 1],
    [1, -1, -1],
    [-1, 1, 1],
    [-1, 1, -1],
    [-1, -1, 1],
    [-1, -1, -1],
]
max_value = 0
for p in patterns:
    Ai.sort(key=lambda x: x[0] * p[0] + x[1] * p[1] + x[2] * p[2], reverse=True)
    t0 = 0
    t1 = 0
    t2 = 0
    for i in range(M):
        t0 += Ai[i][0]
        t1 += Ai[i][1]
        t2 += Ai[i][2]
    t = abs(t0) + abs(t1) + abs(t2)
    if t > max_value:
        max_value = t
print(max_value)



Measured memory_bytes: 3316
#include<stdio.h>
#include<math.h>

 
int main(){
  int n,i,A[250];
 
  scanf("%d",&n);
  
  for(i=1;i<=n;i++){
    
    scanf("%d",&A[i]);
    
  }


  
  for(i=1;i<=n;i++){

    
    printf("node %d: key = %d, ",i,A[i]);
    
    if(i/2>= 1)printf("parent key = %d, ",A[i/2]);
    
    if(2*i <= n)printf("left key = %d, ",A[2*i]);
    
    if(2*i+1 <= n)printf("right key = %d, ",A[2*i+1]);

    
    printf("\n");
  }
  
 
  return 0;
}



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

#define N 100
#define INFTY (1<<21)
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], p[N];

void dijkstra(int s){
  int mincost = 0;
  for(int i = 0 ; i < n ; i++){
    color[i] = WHITE;
    d[i] = INFTY;
    p[i] = -1;
  }
  d[s] = 0;
  p[s] = -1;

  while(true){
    mincost = INFTY;
    int u = -1;
    for(int i = 0 ; i < n; i++){
      if(color[i] != BLACK && d[i] < mincost){
        mincost = d[i];
        u = i;
      }
    }
    if(mincost == INFTY){
      break;
    }
    color[u] = BLACK;

    for(int v = 0 ; v < n ; v++ ){
      if(color[v] != BLACK && M[u][v] != INFTY){
        if(d[u] + M[u][v] < d[v]){
          d[v] = d[u] + M[u][v];
          p[v] = u;
          color[v] = GRAY;
        }
      }
    }
  }
}

int main(){
  cin >> n;
  for(int i = 0 ; i < n ; i++){
    for(int j = 0 ; j < n ; j++){
      M[i][j] = INFTY;
    }
    int u, k;
    cin >> u >> k;
    for(int j = 0 ; j < k ; j++){
      int v , c;
      cin >> v >> c;
      M[u][v] = c;
    }
  }
  dijkstra(0);
  /*for(int i = 0; i < n ; i++){
    for(int j = 0 ; j < n ; j++){
      cout << M[i][j] << " " ;
    }
    cout << "\n";
  }*/
  for(int i = 0 ; i < n ; i++){
    cout << i << " " << d[i] << "\n";
  }
  return 0;
}



Measured memory_bytes: 3104
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - 居合を終え、青い絵を覆う / UOIAUAI
            var c = Console.ReadLine();
            var vowel = new string[] { "a", "e", "i", "o", "u" };

            if (vowel.Contains(c))
            {
                Console.WriteLine("vowel");
            }
            else
            {
                Console.WriteLine("consonant");
            }            
        }
    }
}


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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v) do { x = max(x, v); } while (0)
#define chmin(x, v) do { x = min(x, v); } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

ll N, K;
bool dp[200000];
vector<ll> a;

signed main() {
  cin >> N >> K;
  a.resize(N);
  rep(i, N)
    cin >> a[i];
  dp[0] = false;
  rep(k, 200000) {
    bool win = false;
    rep(i, N) {
      if (k-a[i] >= 0 && dp[k-a[i]] == false)
        win = true;
    }
    dp[k] = win;
  }
  cout << (dp[K]?"First":"Second") << endl;
  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>

#include<stdlib.h>

#include<string.h>

 

int main(void){




char num_str[1002];

int num;

long sum = 0;

int i;

char tmp;

 

while (1){

fgets(num_str,sizeof(num_str),stdin);

if (num_str[0] =='0') break;

for (i = 0; i < strlen(num_str)-1; i++){

tmp = num_str[i];

num = atoi(&tmp);

sum = sum + num;

}




printf("%ld\n",sum);

sum = 0;

memset(num_str,1002, 0);

}




return 0;

}

Measured memory_bytes: 532
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
class Solver{
public:
    static const int MAXN=2e5+10;
    int N;
    ll A[MAXN];
    ll rangeSum(int l,int r){
        return A[r]-A[l-1];
    }
    void solve(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        cin>>N;
        for(int u=1;u<=N;u++){
            ll x;
            cin>>x;
            A[u]=A[u-1]+x;
        }
        int l=1,r=3;
        ll ans=1e18;
        for(int i=2;i<=N-2;i++){
            while(l+2<=i&&abs(rangeSum(1,l)-rangeSum(l+1,i))>=abs(rangeSum(1,l+1)-rangeSum(l+2,i)))l++;
            while(r+2<=N&&abs(rangeSum(i+1,r)-rangeSum(r+1,N))>=abs(rangeSum(i+1,r+1)-rangeSum(r+2,N)))r++;
            set<ll>tmp;
            tmp.insert(rangeSum(1,l));
            tmp.insert(rangeSum(l+1,i));
            tmp.insert(rangeSum(i+1,r));
            tmp.insert(rangeSum(r+1,N));
            ans=min(ans,*tmp.rbegin()-*tmp.begin());
        }
        cout<<ans;
    }
};
int main()
{
    // freopen("in.txt","r",stdin);
    (new Solver())->solve();
}

Measured memory_bytes: 1792
#include <cstdio>
int main ()
{
	int A,B,C,D,i,j;
	while(scanf("%d%d%d%d",&A,&B,&C,&D)!=EOF)
	{
	i=A*B;
	j=C*D;
	if(i>j)
	{
		printf("%d\n",i);
	}
	else
	{
		printf("%d\n",j);
	}
	}
	return 0;
	}

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

using namespace std;
#define rep(i,n) for (int i =0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;

int main(){
    int N;
    cin >> N;
    ll ans1=1;
    ll ans2=1;
    ll ans3=1;
    rep (i,N){
        ans1*=10;
        ans2*=9;
        ans3*=8;
        
        if(ans3>(1000000000+7)){
            ans3%=(1000000000+7);
             ans2%=(1000000000+7);
              ans1%=(1000000000+7);
            



        }

    }  

    ll ans=  ans1+ans3-2*ans2;
    ans %=(1000000000+7);
    ans =(ans+1000000000+7)%(1000000000+7);

    cout <<ans;
    return 0;
}

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

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
//-------------------------↓↓↓↓↓↓------------------------

long func(int tar,int flags){
    long res;
    if(flags == 0 || flags == 4){
        res = tar;
    }
    else if(flags == 1 || flags == 3){
        if(tar == 0)res = 2;
        else if(tar % 2 == 1)res = 1;
        else res = 0;
    }
    else{
        if(tar == 0)res = 1;
        else if(tar % 2 == 1)res = 0;
        else res = 1;
    }

    return res;
}

int main(void){
    int n; cin >> n;
    int a[n + 10];
    rep(i, n)cin >> a[i];
    
    long dp[n + 10][10];
    rep(i, n + 5){
        rep(j, 9){
            if(i == 0)dp[i][j] = 0;
            else dp[i][j] = 1e18;
        }
    }
    rrep(i, 1, n + 1){
        rep(j, 5){
            long cost = 1e18;
            rep(k, j + 1){
                cost = min(cost, dp[i - 1][k]);
            }
            dp[i][j] = cost + func(a[i - 1], j);
        }
    }

    long ans = 1e18;
    rep(i, 5){
        ans = min(ans, dp[n][i]);
    }

    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 16640
// Problem : A - Frog 1
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;

#define ff first
#define fs second
#define lb lower_bound
#define ub upper_bound

#define int long long
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector< vi >
#define vpii vector< pii >
#define vb vector<bool>
#define si set<int>
#define mii map<int, int>
#define mci map<char, int>
#define md 1000000007
#define pb push_back
#define eb emplace_back
#define fio ios_base::sync_with_stdio (false); cin.tie (NULL);  cout.tie (NULL);
#define qw1(x) cerr<<#x<<": "<<x<<" "<<endl
#define qw2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define qw3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define qw4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl


#define f(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define rl(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define all(x) x.begin(),x.end()
#define endl '\n'
void printv(vector<int>  v){ for(int i=0;i<v.size();i++) cout<<v[i]<<' '; cout<<endl;   }
int bem(int m , int n, int mod) { int res=1; while(n){
	     			        if(n%2!=0) { res*=m; res%=mod; }
	    			        m*=m;   m%=mod;   n/=2;
			                          }
				return res;	}
int be(int a, int b) { int res=1; 	while(b){
				if(b%2!=0) res*=a;
				a*=a; b/=2;
				}
			return res;	}
void sieve(int n, vb &prime){
    prime[0]=false;     prime[1]=false;
    for(int i=2;i*i<=n;i++){
         if(prime[i]==true){
              for(int j=i*i;j<=n;j+=i)    prime[j]=false;
             	  }
    	 }
	}
vi v, dp;
int fun(int n)
{
	if(dp[n]!=-1) return dp[n];
	else if(n==0) return dp[n]=0;
	else if(n==1) return dp[n]=abs(v[1]-v[0]);
	else
	return dp[n]=min(fun(n-1)+abs(v[n]-v[n-1]),fun(n-2)+abs(v[n]-v[n-2]) );
}
void solve()
  {
int n; cin>>n;
v.resize(n); f(i, 0, n-1) cin>>v[i];
dp.resize(n, -1);
cout<<fun(n-1);

  }

int32_t main ()
{
//fio
int t=1; 
//cin>>t; 
while(t--){
	solve();
}
 
}








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

int main() {
  int y,m,d;
  char a,b;
  cin>>y>>a>>m>>b>>d;
  if(m<=4){
    cout<<"Heisei"<<endl;
  }
  else{
    cout<<"TBD"<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <math.h>
#include <map>
#include <queue>
#include <set>
#include <stack>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define debug(x) cout<<x<<endl
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
typedef long long ll;
using namespace std;
const int MAXN=1e5+50;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
//::iterator it;
int main()
{
    std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int a,b,n;
    cin>>a>>b;
    if(a<=b){
      cout<<"unsafe"<<endl;
    }else cout<<"safe"<<endl;
    return 0;
}
/*

*/

 
 

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

using namespace std;

#define int 		long long
#define endl		"\n"
#define mod			1000000007
#define IOS			ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

int32_t main() {

	IOS;

	int n;
	cin >> n;
	vector<int> v(n);

	unordered_map<int, int> m;
	int sum = 0;

	for (int i  = 0; i < n; i++) {
		cin >> v[i];
		sum += v[i];
		m[v[i]]++;
	}

	int q;
	cin >> q;
	while (q--) {
		int b, c, present;
		cin >> b >> c;
		present = m[b];
		m[b] = 0;
		m[c] += present;

		sum += present * (c - b);
		cout << sum << endl;
	}

	return 0;
}

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

int main(){
  int A,B,a,b,c,d;
  cin >> A >> B;
  int sum = 0;
  
 
  rep(i, B-A+1){
    int N = A + i;
    a = N / 10000;
    b = N % 10000 / 1000;
    c = N % 100 / 10;
    d = N % 10;
    
    if(a == d && b == c)
      sum++;
    
  }

  
  cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		while (true) {
			int N = sc.nextInt();
			if (N == 0) break;
			int[] I = new int[N];
			for (int i = 0; i < N; ++i) {
				I[i] = sc.nextInt();
			}
			double best = Double.MAX_VALUE;
			int bs = 0;
			int ba = 0;
			int bc = 0;
			for (int s = 0; s < 16; ++s) {
				for (int a = 0; a < 16; ++a) {
					for (int c = 0; c < 16; ++c) {
						int[] hist = new int[256];
						int r = s;
						for (int i = 0; i < N; ++i) {
							r = (a * r + c) & 0xFF;
							hist[(I[i] + r) & 0xFF]++;
						}
						double e = 0;
						for (int i = 0; i < 256; ++i) {
							double v = 1.0 * hist[i] / N;
							if (v != 0) e -= v * Math.log(v);
						}
						if (e < best - 1e-10) {
							best = e;
							bs = s;
							ba = a;
							bc = c;
						}
					}
				}
			}
			System.out.println(bs + " " + ba + " " + bc);
		}
	}

}

Measured memory_bytes: 87972
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

int main(){
    string s;
    int len,temp[4];
    cin>>s;
    len = s.length();
    memset(temp,0,sizeof(temp));
    for(int i = 0;i < len;i++){
        if(s[i] == 'S') temp[0]=-1;
        else if(s[i] == 'N') temp[1]=1;
        if(s[i] == 'E') temp[2]=-1;
        else if(s[i] == 'W') temp[3]=1;
    }
    if((temp[0]+temp[1]) || (temp[2]+temp[3])) puts("No");
    else puts("Yes");
    return 0;
}


Measured memory_bytes: 256