akhauriyash/Code-Regression huggingface dataset:
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
A=get_i
puts A.inject(0){|res,x| res.gcd(x)}

Measured memory_bytes: 21736
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define mod 1000000007
using namespace std;

int main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);cout.tie(NULL);
	int n;
	cin>>n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	vector<vector<ll> > dp(n,vector<ll> (n,1e15));
	for(int i=0;i<n;++i)
		dp[i][i]=0;
	for(int d=1;d<n;++d){
		for(int l=0;l+d<n;++l){
			int r=l+d;
			ll sum = 0;
			for(int k=l;k<=r;++k)
				sum+=a[k];
			for(int k=l;k<r;++k){
				dp[l][r] = min(dp[l][k]+dp[k+1][r]+sum,dp[l][r]);
			}
		}
	}
	cout<<dp[0][n-1];
	// cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ll       long long
#define PR       pair<ll, ll>
#define READ(f)  freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

const int N = 3e5 + 5;
const int MOD = 1e9 + 7;;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

double a[N];

int main() {
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    int n;
    double m, sum = 0;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    double cnt = 0, must = (1.0 / (4.0 * m)) * sum;
    for (int i = 0; i < n; i++) {
        if (a[i] >= must) {
            cnt++;
        }
    }
//    cout << sum << endl;
//    cout << cnt << " " << must << endl;
    puts(cnt >= m ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod= 1e9+7;
typedef long long ll;
#define fastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define what_is(x) cerr << #x << " is " << x << endl;
int main()
{
    int n;
    cin>>n;
    map<string,int>mp;


    vector<string>s(n);
    int ma=-1;
    for (int i=0; i<n; ++i)
    {
        cin>>s[i];
        mp[s[i]]++;
        ma=max(ma,mp[s[i]]);
    }
    set<string>ans;

    for (int i=0; i<s.size(); ++i)
    {
        if (mp[s[i]]==ma)
            ans.insert(s[i]);
    }
    for (auto a:ans)
        cout<<a<<"\n";



}


Measured memory_bytes: 36096
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main()
{
    char a[1000],b[1000],c[10000];
    int size=0,sp,i;
    scanf("%s",&a);
    scanf("%s",&b);
    scanf("%s",&c);
    a[0]=a[0]-32;
    b[0]=b[0]-32;
    c[0]=c[0]-32;
    printf("%c",a[0]);
    printf("%c",b[0]);
    printf("%c",c[0]);

}


Measured memory_bytes: 1636
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
#define yn(x) puts((x ? "Yes" : "No"))
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
vi a, b,c,d;
int Q;
int ans = -1;

void input() {
  cin>>N>>M>>Q;
  a.resize(Q+1);
  b.resize(Q+1);
  c.resize(Q+1);
  d.resize(Q+1);


  rep(i,0,Q-1){
    cin>>a[i]>>b[i]>>c[i]>>d[i];
    a[i]--;b[i]--;
  }
}


void dfs(vector<int> A){
  if (A.size() == N){
    // calc
    int ret = 0;
    rep(i,0,Q-1){
      if (A[b[i]] - A[a[i]] == c[i]){
        ret += d[i];
      }
    }
    chmax(ans,ret);
    return;
  }
  for(int i = A.back(); i <= M; ++i){
    vector<int> t (A.size());
    rep(j,0,A.size()-1){
      t[j] = A[j];
    }
    t.push_back(i);
    dfs(t);
  }
  // for(int i=A.back(); i <= M; ++i){
  //   vector<int> t (A.size());
  //   rep(j,0,A.size()-1){
  //     t[j] = A[j];
  //   }
  //   dfs(t);
  // }
}

void solve() {
  // vector<int> A = {1};
  // dfs(A);
  rep(i,1,M){
    vector<int> b(1);
    b[0] = i;
    dfs(b);
  }
  cout<<ans<<endl;
}
signed main() {
  cout << setprecision(12);
  input();
  solve();
  return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <string>
#include <iostream>
#include <limits.h>
#include <algorithm>

#define ll long long
#define in(params) cin >> (params);
#define p(params) cout << params << endl;
#define mod 1000000007LL

using namespace std;

int main()
{
    int N, Q;
    cin >> N >> Q;
    string s;
    cin >> s;

    int l;
    int r;
    int a[N + 1];

    a[0] = 0;
    for (int i = 0; i < N; i++)
    {
        if(s.substr(i, 2) == "AC") {
            a[i + 1] = a[i] + 1;
        } else {
            a[i + 1] = a[i];
        }
    }

    for (int i = 0; i < Q; i++)
    {
        cin >> l;
        cin >> r;

        p(a[r - 1] - a[l - 1]);

    }

    return 0;
}

Measured memory_bytes: 1408
import math
N,A,B=map(int,input().split())
H=[int(input()) for i in range(N)]
left=1
right=10**10
while left!=right:
  x=(left+right)//2
  S=0
  for i in range(N):
    if H[i]-B*x>=0:
      S+=math.ceil((H[i]-B*x)/(A-B))
  if S<=x:
      right=x
  else:
      left=x+1
print(left)
 
    
    

Measured memory_bytes: 51160
def solve(a, b, c, d):
    for t in range(300):
        if t % 2 == 0:
            c -= b
            if c <= 0:
                return "Yes"
        else:
            a -= d
            if a <= 0:
                return "No"

a, b, c, d = map(int, input().split())
print(solve(a, b, c, d))

Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (ll)(n); i++)

int main() {
  vector <bool> prime((ll)pow(10, 5), 1);
  prime.at(0) = 0;
  rep(i, (ll)pow(10, 5)) {
    if (prime.at(i)) {
      for (ll j = 2*(i+1)-1; j < (ll)pow(10, 5); j += i+1) prime.at(j) = 0;
    }
  }
  vector <ll> prime_2017((ll)pow(10, 5)+1, 0);
  for (ll i = 1; i <= (ll)pow(10, 5); i++) {
    if (i%2 && prime.at(i-1) && prime.at((i+1)/2-1)) prime_2017.at(i) = 1;
  }
  rep(i, (ll)pow(10, 5)) prime_2017.at(i+1) += prime_2017.at(i);
  ll q; cin >> q;
  rep(i, q) {
    ll l, r; cin >> l >> r;
    cout << prime_2017.at(r)-prime_2017.at(l-1) << endl;
  }
}

Measured memory_bytes: 3800
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long INF = 1e15;

#include <math.h>
#define PI 3.14159265358979323846264338327950L

bool isPrime(long long x) {
    if (x == 1) return true;
    for (long long i = 2; i*i <= x; i++) {
        if (x % i == 0) return false;
    }
    return true;
}

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

vector<long long> common_divisors(long long a, long long b) {
    long long n = gcd(a, b);
    vector<long long> ans;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            if (n / i == i) {
                ans.push_back(i);
            }
            else {
                ans.push_back(n / i);
                ans.push_back(i);
            }
        }
    }
    return ans;
}

bool is_sorted(vector<int> a) {
    int n = a.size();
    for (int i = 0; i < n - 1; i++) {
        if (a[i + 1] < a[i]) return false;
    }
    return true;
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n - 1; i++) {
        if (a[i] < a[i + 1]) {
            a[i + 1]--;
        }
    }
    if (is_sorted(a)) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 4056
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <ctime>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <assert.h>
#include <iomanip>
#include <bitset>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define inf 1000000007
#define mod 1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";

#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 200005

template <class T,class U>inline void Max(T &a,U b){if(a<b)a=b;}
template <class T,class U>inline void Min(T &a,U b){if(a>b)a=b;}

//FILE* outFile;

inline void add(int &a,int b){a+=b;while(a>=mod)a-=mod;}
inline int gcd(int a, int b){if(b == 0)return a; return gcd(b, a%b);}
int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=ans*(ll)a%mod;
        a=(ll)a*a%mod;b>>=1;
    }
    return ans;
}

char s[N];
int dp[N], now;
bool can(int x, int t){
    now++;
    dp[x] = now;
    rep(i, x, t)if(dp[i] == now){
        if(s[i+1] == '.')dp[i+1] = now;
        if(i+2 <= t && s[i+2] == '.')dp[i+2] = now;
    }
    return dp[t] == now;
}
int main(){
    int j,k,i,T,ca=0, n, m, K;
    int a,b,c,d;
    scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
    a--, b--, c--, d--;
    scanf("%s", s);
    if(c < d){
        if(can(a, c) && can(b, d)){
            puts("Yes");
            return 0;
        }
    }
    else{
        rep(i, b-1, d)if(s[i] == '.' && i+2 < n){
            if(s[i+1] == '.' && s[i+2] == '.'){
                puts("Yes");
                return 0;
            }
        }
    }
    puts("No");
}



Measured memory_bytes: 1152
import copy

# https://atcoder.jp/contests/abc050/tasks/abc050_b

N = int(input())
T_list = list(map(int, input().split()))
M = int(input())

P_list = []
X_list = []
for m in range(M):
    p, x = map(int, input().split())
    P_list.append(p)
    X_list.append(x)

for p in range(M):
    T_d_list = copy.copy(T_list)
    T_d_list[P_list[p] - 1] = X_list[p]

    print(sum(T_d_list))


Measured memory_bytes: 3444
#include<string>
#include<stdio.h>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
using namespace std;
char in[30];
int ijk[600];
int v[600];
vector<pair<int,int> >g[600];
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<a;i++){
			v[i]=0;ijk[i]=999999999;g[i].clear();
		}
		int sz=0;
		map<string,int>m;
		scanf("%s",in);
		string s=in;
		m[s]=sz++;
		scanf("%s",in);
		string p=in;
		m[p]=sz++;
		scanf("%s",in);
		string t=in;
		m[t]=sz++;
		for(int i=0;i<b;i++){
			scanf("%s",in);
			string l=in;
			int L,R;
			if(m.count(l)){
				L=m[l];
			}else{
				L=sz;
				m[l]=sz++;
			}
			scanf("%s",in);
			string r=in;
			if(m.count(r)){
				R=m[r];
			}else{
				R=sz;
				m[r]=sz++;
			}
			int d,t;scanf("%d%d",&d,&t);
			g[L].push_back(make_pair(R,d/40+t));
			g[R].push_back(make_pair(L,d/40+t));
		}
		ijk[1]=0;
		priority_queue<pair<int,int> > Q;
		Q.push(make_pair(0,1));
		while(Q.size()){
			int cost=-Q.top().first;
			int at=Q.top().second;
			Q.pop();
			if(v[at])continue;
			v[at]=1;
			for(int i=0;i<g[at].size();i++){
				if(!v[g[at][i].first]&&ijk[g[at][i].first]>cost+g[at][i].second){
					ijk[g[at][i].first]=cost+g[at][i].second;
					Q.push(make_pair(-ijk[g[at][i].first],g[at][i].first));
				}
			}
		}
		printf("%d\n",ijk[0]+ijk[2]);
	}
}

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


int main()
{
  string s;
  cin >> s;
  int sum = 0;
  for(int i = 0;i < 4;i++){
    if(s[i] == '+') sum++;
    else if(s[i] == '-') sum--;
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
queue<char> c;
bool C=false,F=false;
char c1;
int main()
{
    while(cin>>c1){
        if(c1=='C'||c1=='F'){c.push(c1);}
    }
    int len0=c.size();
    while(len0>0){
        if(c.front()=='F'){
            if(C==true){F=true;break;}
        }
        if(c.front()=='C'){C=true;}
        c.pop();
        len0--;
    }
    if(C&&F){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import sys
import numpy as np
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines


def main():

    H, W, D = map(int, readline().split())
    A = [list(map(int, readline().split())) for _ in range(H)]
    Q = int(readline())
    LR = map(int, read().split())

    a = [(0, (0, 0))]
    for i in range(H):
        a.extend([(element, [i, w]) for w, element in enumerate(A[i])])

    a.sort()
    tmp, number = zip(*a)
    number = np.array(number)
    x = np.resize(number[:, 0], (H * W // D + 1, D))
    y = np.resize(number[:, 1], (H * W // D + 1, D))

    magic = np.abs(x[1:] - x[:-1]) + np.abs(y[1:] - y[:-1])
    np.cumsum(magic, axis=0, out=magic)

    for L, R in zip(LR, LR):
        if L != R:
            q1 = R // D - 1
            q2 = L // D - 1
            r = R % D
            if q2 == -1:
                print(magic[q1][r])
            else:
                print(magic[q1][r] - magic[q2][r])
        else:
            print(0)


if __name__ == '__main__':
    main()

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

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var input = Console.ReadLine().ToCharArray();
            if(input[0] == 'A')
            {
                Console.WriteLine('T');
            }
            else if(input[0] == 'T')
            {
                Console.WriteLine('A');
            }
            else if(input[0] == 'C')
            {
                Console.WriteLine('G');
            }
            else if(input[0] == 'G')
            {
                Console.WriteLine('C');
            }
        }
    }
}

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

using namespace std;

int main(){
    string s;
    cin >> s;
    if(s[0] != s[1] &&s[1] != s[2] && s[2] != s[3]){
        cout << "Good" << endl;
    }else{
        cout << "Bad" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;int n,m,d,x,q,a,c[100010];int main(){while(cin>>d&&d){cin>>n>>m;c[0]=a=0;for(q=1;q<n;q++)cin>>c[q];sort(c,c+n);while(m--){cin>>q;x=lower_bound(c,c+n,q)-c;if(x==n)a+=min(d-q,q-c[n-1]);else a+=min(c[x]-q,q-c[x-1]);}cout<<a<<endl;}return 0;}

Measured memory_bytes: 3432
#template
def inputlist(): return [int(j) for j in input().split()]
#template

mod = 10**9 + 7
N = int(input())
A = inputlist()

s = sum(A)
ans = 0
for i in range(N):
    s -= A[i]
    ans += A[i]*s
    ans %= mod
print(ans)

Measured memory_bytes: 105224
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tuple<ll,ll,ll> tll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
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; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
ll dp[1000005][2][2];
int main(){
  ll n;
  cin>>n;
  memset(dp,-0,sizeof(dp));
  dp[0][0][0]=1;
  rep(i,n)rep(j,2)rep(z,2)rep(u,10){
    ll ni=i+1,nj=j,nz=z;
    if(nj==0&&u==9)nj=1;
    if(nz==0&&u==0)nz=1;
    dp[ni][nj][nz]+=dp[i][j][z];
    dp[ni][nj][nz]%=MOD;
  }
  COUT(dp[n][1][1]);
}

Measured memory_bytes: 34880
import java.util.Scanner;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner in = new Scanner(System.in);
        int a = 0, b = 0,c = 0;
        String as = in.nextLine();
        String bs = in.nextLine();
        String cs = in.nextLine();

        char now = 'a';
        while(true){
            switch (now) {
            case 'a':
                if(a == as.length()){
                    System.out.println("A");
                    return;
                }
                now= as.charAt(a++);
                break;
            case 'b':
                if(b == bs.length()){
                    System.out.println("B");
                    return;
                }
                now= bs.charAt(b++);
                break;
            case 'c':
                if(c == cs.length()){
                    System.out.println("C");
                    return;
                }
                now= cs.charAt(c++);
                break;
            }
        }
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n;
    cin >> n;
    vll l(n);
    vll x(2e3 + 10); // x[i] : 長さ i の棒の本数
    REP(i, n){
        cin >> l[i];
        x[l[i]]++;
    }
    vll cnt(2e3 + 10); // cnt[i] : 長さ i より小さい棒の総数
    REP(i, 2e3 + 9){
        cnt[i + 1] = cnt[i] + x[i];
    }

    // 長さ i, j の棒(i < j)を全探索, i = j は場合分け
    // 3辺目の長さを k とすると, k が満たすべき条件は j <= k < i + j

    ll res = 0;
    for (int i = 1; i <= 1e3; i++) {
        res += (x[i] * (x[i] - 1) / 2) * (cnt[2 * i] - cnt[i + 1]); // i = j < k
        res += (x[i] * (x[i] - 1) * (x[i] - 2) / 6); // i = j = k
        for (int j = i + 1; j <= 1e3; j++) {
            res += x[i] * x[j] * (cnt[i + j] - cnt[j + 1]); // i < j < k
            res += x[i] * x[j] * (x[j] - 1) / 2; // i < j = k
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;

int main() {
  ll q, h, s, d, n;
  cin >> q >> h >> s >> d >> n;
  cout << (n / 2) * min(min(min(8 * q, 4 * h), 2 * s), d) +
              (n % 2) * min(min(4 * q, 2 * h), s)
       << endl;
}


Measured memory_bytes: 256
def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)

a=(int)(input())
flag=0

a=a*9

cnt=a
qq=a

for i in range(2,a+1):
   # print(i)
    if i*i>a:
        break
    if qq%i==0:
       # print(i)
        cnt=cnt/i*(i-1)
        while qq%i==0:
           # print(qq)
            qq=qq/i

if qq>1:
    cnt=cnt/qq*(qq-1)

#print(cnt)
qwq=(int)(cnt)
t=1

if a%2!=0 and a%5!=0:
    for i in range(1,a+1):
       # t=t*10
        if qwq%i!=0:
            continue
        #print(i)
        if ((10**i-1)*7) % a == 0:
            flag=1
            print(i)
            break
if flag==0:
    print(-1)


Measured memory_bytes: 10732
package main

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

func s(A int) (B int) {
	for A > 0 {
		B += A % 10
		A /= 10
	}
	return
}

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	min := 1 + s(N-1)
	for i := 1; i < N; i++ {
		K := s(i) + s(N-i)
		if min > K {
			min = K
		}
	}
	fmt.Println(min)
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
   long long int n,i,sum = 0;
   cin>>n;
   map<long long int,int>mp;
   mp[n] = 1;
   while(1)
   {

       if(n%2==0)
       {
           n /= 2;
       }
       else
        n = 3*n + 1;
           sum++;
       if(mp[n]==1)
        break;

           mp[n] = 1;
   }
   sum++;
   cout<<sum<<endl;
   return 0;
}


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

int main() {
    ll x, k, d, n;
    cin >> x >> k >> d;
    if (x < 0) {x *= -1;}

    n = x / d;
    if (k >= n) {
        k -= n;
        x %= d;
    }
    else {
        x -= d * k;
        k = 0;
    }
    if (k % 2 == 1) {x = d - x;}

    cout << x << endl;
}


Measured memory_bytes: 3584
S=input()
mylist=["Sunny", "Cloudy", "Rainy"]
number=0

for i in range(3):
    if S==mylist[i]:
        number=i
    else:
        pass
#print(number)
if number==2:
    print(mylist[0])
else:
    print(mylist[number+1])

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

int main(void){
  char s[1000];
  scanf("%s",s);
  int len=strlen(s);
  
  if(s[len-1]=='s')
    printf("%ses\n",s);
  else
    printf("%ss\n",s);
  
  return 0;
}
  

Measured memory_bytes: 2156
N, x = map(int, input().split())
a=list(map(int, input().split()))
count = 0
for i in range(N):
    if a[i]>x:
        count+=a[i]-x
        a[i]=x
count1=count
a1=a.copy()
for i in range(0, N, 2):
    ai=a1[i]
    if i==0:
        a1[i]=min(ai, x-a1[i+1])
    elif i==N-1:
        a1[i]=min(ai, x-a1[i-1])
    else:
        a1[i]=min(x-a1[i-1], x-a1[i+1], ai)
    count1+=ai-a1[i]

count2=count
a2=a.copy()
for i in range(1, N, 2):
    ai=a2[i]
    if i==0:
        a[i]=min(ai, x-a2[i+1])
    elif i==N-1:
        a2[i]=min(x-a2[i-1], ai)
    else:
        a2[i]=min(x-a2[i-1], x-a2[i+1], ai)
    count2+=ai-a2[i]

count3=count
prev=a[0]
for i in range(1, N):
    ai=a[i]
    if x-prev>=0 and x-prev<ai:
        a[i]=x-prev
    count3+=ai-a[i]
    prev=a[i]
print(min(count1, count2, count3))


Measured memory_bytes: 14068
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
long long modpow(int n, int r) {
    long long ret = 1; long long tmp = (long long) n;
    while (r != 0) {
        if (r % 2) ret *= tmp;
        tmp *= tmp; tmp %= mod; ret %= mod;
        r /= 2;
    }
    return ret;
}

int main() {
    int n; cin >> n;
    string s; cin >> s;
    int l = s.size();
    vector<long long> dp(2*n+1, 0), dp2;
    dp[0] = 1;
    for (int i = 0; i < n; i++) {
        dp2.assign(2*n+1, 0);
        for (int j = 0; j <= 2*n; j++) {
            if (j == 0) dp2[j] = (dp[j] + dp[j+1]) % mod;
            else dp2[j] = (dp[j-1]*2 + dp[j+1]) % mod;
        }
        swap(dp, dp2);
    }
    long long inv = modpow(2, mod-2);
    long long mul = modpow(inv, l);
    cout << dp[l] * mul % mod << endl;
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstdlib>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

using namespace std;

typedef long long int ll;

const ll INF=(ll)1e18;

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

  string S;
  cin >> S;
  transform(S.begin()+K-1, S.begin()+K, S.begin()+K-1, ::tolower);
  cout << S << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.stream.Collectors;

class Store {
    long cost, count;

    public Store(long cost, long count) {
        this.cost = cost;
        this.count = count;
    }

    long toSum() {
        return this.cost * this.count;
    }
}

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

        List<Store> list = new ArrayList<>();

        for (int i = 0; i < n; i++) {
            list.add(new Store(sc.nextLong(), sc.nextLong()));
        }

        long costSum = 0;
        ArrayDeque<Store> sorted = list.stream().sorted((x, y) -> (int)(x.cost - y.cost)).collect(Collectors.toCollection(ArrayDeque::new));

        boolean isCompleted = false;
        while (!isCompleted) {
            Store next = sorted.pop();
//            System.out.println("cost: " + next.cost + " count: " + next.count + " m: " + m + " costSum: " + costSum);
            if (m <= next.count) {
                costSum += next.cost * m;
                isCompleted = true;
            } else {
                m -= next.count;
                costSum += next.toSum();
            }
        }

        System.out.println(costSum);

    }
}


Measured memory_bytes: 95064
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <stdlib.h>

using namespace std;

void solve()
{
    int N;
    cin >> N;

    int K;
    cin >> K;

    vector<int> p(N);

    for (int i = 0; i < N; ++i)
    {
        cin >> p[i];
    }

    vector<int> dp(N, 2147483640);

    dp[0] = 0;
    dp[1] = abs(p[0] - p[1]);

    for (int i = 0; i < N - 1; ++i)
    {
        for (int j = i + 1; j < i + 1 + K && j < N; ++j)
        {
            dp[j] = min(dp[j], dp[i] + abs(p[i] - p[j]));
        }
    }

    cout << dp[N - 1] << "\n";
}

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

    solve();
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
const ll INF = (1ll << 60);

int main() {
 string s;
 cin >> s;
 if (s == "SUN") cout << 7 << endl;
 if (s == "MON") cout << 6 << endl;
 if (s == "TUE") cout << 5 << endl;
 if (s == "WED") cout << 4 << endl;
 if (s == "THU") cout << 3 << endl;
 if (s == "FRI") cout << 2 << endl;
 if (s == "SAT") cout << 1 << endl;
}


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

using namespace std;

typedef long long ll;

ll ans,n,l,r;
ll m;
ll k;

ll grundy(ll a,ll b){
	for(int ii=0;ii<3;ii++){
		if(a != ii && b != ii){
			return ii;
		}
	}
	return 3;
}

int main(){
	cin >> k;
	for(int i=0;i<k;i++){
		cin >> n >> m;
		m++;
		l = (m + 1) / 2;
		r = m - 1;
		ll before_even = 2;
		ll before_last = 2;
		ll even,odd;
		while(1){
			//cout << l << " " << r << endl;
			even = grundy(before_last, before_even);
			odd = grundy(before_even, even);
			if(l <= n && n <= r){
				
				//cout << even << " " << odd << endl;
				if((r - n) % 2 == 0){
					ans = ans ^ even;
					//cout << even << endl;
					break;
				}else{
					ans = ans ^ odd;
					//cout << odd << endl;
					break;
				}
			}else{
				if(r % 2 == 0){
					before_even = even;
				}else{
					before_even = odd;
				}
				if((l - r) % 2 == 0){
					before_last = even;
				}else{
					before_last = odd;
				}
				r = l - 1;
				l = (r + 2) / 2;
			}
		}
	}
	if(ans == 0){
		cout << "tubuann" << endl;
	}else{
		cout << "mo3tthi" << endl;
	}
}


Measured memory_bytes: 3120
from operator import mul
from functools import reduce

def cmb(n,r):
    if r > n: return 0
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

n,k = map(int, input().split())
mod = 10 ** 9 + 7
for i in range(1,k+1):
  print((cmb(n-k+1,i) % mod * cmb(k-1, i-1) % mod) % mod)


Measured memory_bytes: 3944
#include<bits/stdc++.h>
using namespace std;
#define int         long long int
#define vi           vector<int>
#define pii          pair<int,int>
#define vpp          vector<pii>
#define mii          map<int,int>
#define pb           push_back
#define endl        '\n'
#define rep(i,a,bb)  for(int i=a;i<bb;i++)
#define ff           first
#define ss           second
#define fast         ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test         int T;cin>>T;while(T--)
#define __sort(v)    sort(v.begin(),v.end())
#define __rsort(v)   sort(v.rbegin(),v.rend())
#define setbits(x)   __builtin_popcount(x)
#define zrobits(x)   __builtin_ctzint(x)
//const int inf = 5 * (1e+18);
const int mod = 7 + 1e+9;

int32_t main()
{
  fast;

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


  int a, b, c, k;
  cin >> a >> b >> c >> k;

  int ans = 0;
  ans = min(a, k);
  k = max(0ll, k - a);
  k = max(0ll, k - b);
  ans += min(c, k) * (-1);


  cout << ans;






}




Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

	cout << c - min(c, a - b) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 1000

int main(void){
  int i,num;
  int a1[N]={0},a2[N]={0},a3[N]={0},a4[N]={0},
      b1[N]={0},b2[N]={0},b3[N]={0},b4[N]={0};
  int hit,blow;

  for(i=0;((scanf("%d%d%d%d%d%d%d%d",
            &a1[i],&a2[i],&a3[i],&a4[i],
            &b1[i],&b2[i],&b3[i],&b4[i]
            ))==8);i++){}
  num=i;
  for(i=0;i<num;i++){
    hit=0;
    blow=0;
    if(a1[i]==b1[i])  hit++;
    if(a2[i]==b2[i])  hit++;
    if(a3[i]==b3[i])  hit++;
    if(a4[i]==b4[i])  hit++;
    if(a1[i]==b2[i] ||
        a1[i]==b3[i] ||
        a1[i]==b4[i])  blow++;
    if(a2[i]==b1[i] ||
        a2[i]==b3[i] ||
        a2[i]==b4[i])  blow++;
    if(a3[i]==b1[i] ||
        a3[i]==b2[i] ||
        a3[i]==b4[i])  blow++;
    if(a4[i]==b1[i] ||
        a4[i]==b2[i] ||
        a4[i]==b3[i])  blow++;
    printf("%d %d\n",hit,blow);
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
  int t,n,i,j,k,l;
  string s,s1;
  cin>>s;
  cin>>s1;
  n=s.size();int m=s1.size();
  int min1=1e6;
  for(i=0;i<=(n-m);i++)
  { l=0;
    for(j=0;j<m;j++)
    {
      if(s[i+j]!=s1[j]) l++;
    }
    min1=min(min1,l);
  }
  cout<<min1;
}

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

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template <typename T> using pq = priority_queue<T>;
template <typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template <typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for (auto &i : mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template <class T> ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template <class T> istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template <class T> ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll n, k;
    cin >> n >> k;
    vl a(n);
    cin >> a;
    ll s = 0, e = *max_element(all(a)) + 1;
    double mi = ll_inf;
    while (e - s > 1) {
        ll mid = (s + e) / 2;

        ll cnt = 0;
        double prevmi = 0;
        rep(i, n) {
            ll div = ll(ceil(double(a[i]) / mid));
            cnt += div - 1;
            prevmi = max(prevmi, double(a[i]) / div);
        }
        if (cnt > k) {
            s = mid;
        } else {
            e = mid;
            mi = min(mi, prevmi);
        }
    }
    if (e == 1) {
        mi = 1;
    }
    cout << ll(ceil(mi)) << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}


Measured memory_bytes: 4884
def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    #table = list(set(table))
    table = list(table)
    table.sort()
    return table

N = int(input())

#for N in range(1000000000000):
n = []
n = divisor(N)
#print(n)

cnt = 999999999999999
for i in range(0,len(n)//2,1):
    t = int(n[i])-1 + int(n[len(n)-i-1])-1
    if cnt > t:
        cnt = t
print(cnt)



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

vector<int> C(10000);

void CountingSort(vector<int>& A, vector<int>& B)
{
    int k = 0;
    for (auto a : A) {
        ++C[a];
        k = max(k, a);
    }
    for (int i = 1; i <= k; ++i) {
        C[i] += C[i - 1];
    }
    for (int i = A.size() - 1; i >= 0; --i) {
        B[C[A[i]] - 1] = A[i];
        --C[A[i]];
    }
}

int main()
{
    int n;
    cin >> n;
    vector<int> A;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        A.push_back(a);
    }
    vector<int> B(A.size());
    CountingSort(A, B);
    for (int i = 0; i < B.size(); ++i) {
        if (i) {
            cout << " ";
        }
        cout << B[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 18508
'''
def factorial(n):
    if n == 1:
        return n
    return n*factorial(n-1)
'''
def dist(i, j):
    dx = x[i] - x[j]
    dy = y[i] - y[j]
    return (dx**2 + dy**2)**0.5

n = int(input())
x = [None]*n
y = [None]*n

for i in range(n):
    x[i], y[i] =map(int, input().split())

sum = 0
for idi in range(n):
    for idj in range(idi+1, n):
        sum += dist(idi, idj)

ans = sum*2/n

print(ans)


Measured memory_bytes: 38384
#include<set>
#include<iostream>
#include<map>
#include<vector>
#include<queue>
#include <utility>
#include<algorithm>

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int  visit[100005];
long long  dist[100005];
vector<int>vec[100005];
map<pair<int,int>,int>mp;
void bfs(int x)
{

   int s=x;
   visit[s]=1;
   queue<int>q;
   q.push(s);
   while(!q.empty()){
    int y=q.front();
    q.pop();
    for(int i=0;i<vec[y].size();i++)
    {
        if(visit[vec[y][i]]==0)
        {
            visit[vec[y][i]]=1;
            q.push(vec[y][i]);
            dist[vec[y][i]]=dist[y]+mp[{y,vec[y][i]}];
        }




    }




   }





}






int main()
{

int a,b,c,d,e,i;
cin >> a ;
set<int>s;
for(i=0;i<=a;i++)
{
    visit[i]=0;
    dist[i]=0;
}

if(a==1)
{
    cout << 0 << endl;
}
else{

   a--;
while(a--)
{
    cin >> c >> d >> e;
    s.insert(c);
    s.insert(d);
    vec[c].push_back(d);
    vec[d].push_back(c);
    mp[{c,d}]=e;
    mp[{d,c}]=e;


}
bfs(c);
for(auto it=s.begin();it!=s.end();it++)
{
    if(dist[*it]%2==0)
    {
        cout << 0 << endl;
    }
    else{
        cout << 1 << endl;
    }




}



}






}


Measured memory_bytes: 27428
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4") // wonderful

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

#define forn(i, a, n) for (int i = (a); i < (int)n; i++)
#define trav(x, arr) for (auto &x : arr)
#define sz(x) (int)x.size()
#define Matrix(m, h, w) std::vector<vector<int>> m(h, vector<int> (w)); 
using ll = long long;

#define vi vector<int>
#define vl vector<long>
#define vll vector<ll>

// benq
const int MOD = 1000000007; // 998244353
const ll INF = 1e18;
const int MX = 100001;


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


   char s; cin >> s;

   if (isupper(s))
   		cout << "A";
   else cout << "a";

    return 0;
}

Measured memory_bytes: 3528
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1LL << 60;


int main(void){
    int a[3][3];
    REP(i,3) REP(j,3) cin >> a[i][j];
    int n;
    cin >> n;
    int b[n];
    REP(i,n) cin >> b[i];
    bool x[3][3];
    REP(i,3)REP(j,3)x[i][j]=false;
    REP(i,n){
        REP(j,3){
            REP(k,3){
                if(a[j][k]==b[i])
                    x[j][k]=true;
            }
        }
    }
    string ans="No";
    REP(i,3)
        if(x[i][0] && x[i][1] && x[i][2]){
            ans="Yes";
        }
            
    REP(i,3)
        if(x[0][i] && x[1][i] && x[2][i]){
            ans="Yes";
        }
    
    if(x[0][0] && x[1][1] && x[2][2])
        ans="Yes";

    if(x[0][2] && x[1][1] && x[2][0])
        ans="Yes";
    cout << ans;
    return 0;
}

Measured memory_bytes: 3452
def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    P = list(map(int, input().split()))
    X = list(map(int, input().split()))

    child = [[] for _ in range(N+1)]
    par = [-1] * (N+1)
    for i, p in enumerate(P):
        child[p].append(i+2)
        par[i+2] = p
    child_num = [len(child[i]) for i in range(N+1)]
    st = []
    for i in range(1, N+1):
        if child_num[i] == 0:
            st.append(i)
    dp = [None] * (N+1)
    ok = 1
    while st:
        v = st.pop()
        x = X[v-1]
        if v != 1:
            p = par[v]
            child_num[p] -= 1
            if child_num[p] == 0:
                st.append(p)
        if not child[v]:
            dp[v] = (x, 0)
            continue
        dp2 = [[False] * (x+1) for _ in range(len(child[v])+1)]
        dp2[0][0] = True
        S = 0
        for i, u in enumerate(child[v]):
            a, b = dp[u]
            S += a+b
            for j in range(x+1):
                if dp2[i][j]:
                    if j + a <= x:
                        dp2[i+1][j+a] = True
                    if j+b <= x:
                        dp2[i+1][j+b] = True
        finish = 1
        for j in range(x, -1, -1):
            if dp2[-1][j]:
                dp[v] = (x, S-j)
                finish = 0
                break
        if finish:
            ok = 0
            break

    if ok:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')


if __name__ == '__main__':
    main()


Measured memory_bytes: 43376
// https://atcoder.jp/contests/abc124/tasks/abc124_b

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int main()
{
  int N, h, maxH, r = 1;
  cin >> N;

  cin >> maxH;
  REP(i, N - 1)
  {
    cin >> h;
    if (maxH <= h)
      r++;
    maxH = max(maxH, h);
  }

  cout << r << '\n';

  return 0;
}


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

using namespace std;
struct CinInit
{
    CinInit()
    {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} CinInit;

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

    for (int i = 0; i < n; i++)
    {
        if (s[i] != s[k - 1])
            s[i] = '*';
    }

    cout << s << "\n";

    return 0;
}


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

int main() {
    ll n;
    cin>>n;
    vector<ll> v(n);
    for(ll i=0;i<n;i++) {
        cin>>v[i];
    }
    ll mx=0,sum=0;
    for(ll i=0;i<n;i++) {
        mx=max(v[i],mx);
        if(v[i]<mx) {
            sum+=mx-v[i];
        }
    }
    cout<<sum<<endl;


    return 0;
}

Measured memory_bytes: 4832
import sys
input = sys.stdin.readline
S = list(input())[: -1]
K = int(input())
a = ord("a")
N = len(S)
for i in range(N):
  x = ord(S[i])
  if K >= (a - x) % 26:
    K -= (a - x) % 26
    S[i] = "a"
S[-1] = chr((ord(S[i]) - a + K % 26) % 26 + a)
print("".join(S))

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

using namespace std;

int main()
{
	for(int n,m;cin>>n>>m,n|m;){
		vector<int> p(n);
		for(int i=0;i<n;i++)
			cin>>p[i];
		vector<int> a;
		a.push_back(0);
		a.insert(a.end(),p.begin(),p.end());
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				a.push_back(p[i]+p[j]);
		sort(a.begin(),a.end());
		a.erase(unique(a.begin(),a.end()),a.end());
		
		int res=0;
		for(int i=0;i<a.size();i++){
			int j=upper_bound(a.begin(),a.end(),m-a[i])-a.begin();
			if(j)
				res=max(res,a[i]+a[j-1]);
		}
		cout<<res<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline T read(){
	T f=0,x=0;char c=getchar();
	while(!isdigit(c)) f=c=='-',c=getchar();
	while(isdigit(c)) x=x*10+c-48,c=getchar();
	return f?-x:x;
}
namespace run{
	const int N=109;
	int mod;
	inline int add(int x,int y){return x+y>=mod?x-mod+y:x+y;}

	int cur,pre,f[2][N][N],n,m,K,C[N][N],pw[N][N*N];
	int main(){
		n=read<int>(),m=read<int>(),K=read<int>(),mod=read<int>();
		pw[0][0]=C[0][0]=1;
		for(int i=1;i<=max(n,m);i++){
			C[i][0]=1;
			for(int j=1;j<=i;j++) C[i][j]=add(C[i-1][j-1],C[i-1][j]);
		}for(int i=1;i<=K;i++){
			pw[i][0]=1;
			for(int j=1;j<=max(n,m);j++) pw[i][j]=1LL*pw[i][j-1]*i%mod;
		}

		f[0][0][0]=1;
		for(int t=1;t<=K;t++){
			pre=cur,cur^=1;
			for(int i=0;i<=n;i++) for(int j=0;j<=m;j++) f[cur][i][j]=0;
			for(int i=0;i<=n;i++)
				for(int j=0;j<=m;j++){
					int tmp=1LL*pw[t][m-j]*pw[K-t+1][j]%mod,omega=f[pre][i][j];
					for(int k=0;omega && k+i<=n;k++,omega=1LL*omega*tmp%mod)
						f[cur][i+k][j]=(1LL*omega*C[n-i][k]+f[cur][i+k][j])%mod;
				}
			
			pre=cur,cur^=1;
			for(int i=0;i<=n;i++) for(int j=0;j<=m;j++) f[cur][i][j]=0;
			for(int i=0;i<=n;i++)
				for(int j=0;j<=m;j++){
					int tmp=1LL*pw[t][n-i]*pw[K-t+1][i]%mod,omega=f[pre][i][j];
					for(int k=0;omega && k+j<=m;k++,omega=1LL*omega*tmp%mod)
						f[cur][i][j+k]=(1LL*omega*C[m-j][k]+f[cur][i][j+k])%mod;
				}
			
			pre=cur,cur^=1;
			for(int i=0;i<=n;i++) for(int j=0;j<=m;j++) f[cur][i][j]=0;
			for(int i=0;i<=n;i++)
				for(int j=0;j<=m;j++){
					int tmp=1LL*pw[t][m-j]*pw[K-t][j]%mod,omega=f[pre][i][j];
					for(int k=0;omega && k+i<=n;k++,omega=1LL*omega*tmp%mod)
						if(k&1) f[cur][i+k][j]=(1LL*(mod-omega)*C[n-i][k]+f[cur][i+k][j])%mod;
						else f[cur][i+k][j]=(1LL*omega*C[n-i][k]+f[cur][i+k][j])%mod;
				}
			
			pre=cur,cur^=1;
			for(int i=0;i<=n;i++) for(int j=0;j<=m;j++) f[cur][i][j]=0;
			for(int i=0;i<=n;i++)
				for(int j=0;j<=m;j++){
					int tmp=1LL*pw[t][n-i]*pw[K-t][i]%mod,omega=f[pre][i][j];
					for(int k=0;omega && k+j<=m;k++,omega=1LL*omega*tmp%mod)
						if(k&1) f[cur][i][j+k]=(1LL*(mod-omega)*C[m-j][k]+f[cur][i][j+k])%mod;
						else f[cur][i][j+k]=(1LL*omega*C[m-j][k]+f[cur][i][j+k])%mod;
				}
		}
		printf("%d\n",f[cur][n][m]);
		return 0;
	}
}
int main(){
#ifdef my
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	return run::main();
}

Measured memory_bytes: 4196