akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3

def main():
    [N, M, X, Y] = list(map(int, input().split()))
    x = list(map(int, input().split()))
    y = list(map(int, input().split()))

    x.append(X)
    y.append(Y)
    max_x = max(x)
    min_y = min(y)

    print('War' if min_y <= max_x else 'No War')


if __name__ == '__main__':
    main()



Measured memory_bytes: 3060
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))

# ===CODE===

eps = 10 ** (-9)


def main():
    n = ni()
    a = na()

    seta = set(a)
    cnta = collections.Counter(a)
    lista = list(seta)
    lista.sort()

    table = [True for _ in range(10 ** 6 + 1)]
    ans = 0

    for ai in lista:
        if table[ai]:
            if cnta[ai] == 1:
                ans += 1
            for i in range(ai, 10 ** 6 + 1, ai):
                table[i] = False

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 222812
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
struct Node{
  int no;
  int par;
  vector<Node*> child;
  void build(int i){
    no=i;par=i;
  }
};
signed main(){
  int n;cin>>n;
  vector<Node> node(n+1);
  rep1(i,n-1){
    int a;cin>>a;
    node[a].child.push_back(&node[i+1]);
  }
  rep1(i,n){
    cout<<node[i].child.size()<<"\n";
  }
  return 0;
}


Measured memory_bytes: 17068
import fractions
from collections import deque
import numbers as np
import math


def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    ids = [i for i in range(N)]
    C = list(zip(A, ids))
    sort = sorted(C, key=lambda x: x[0], reverse=True)
    rest = [sort[0][0] for _ in range(N)]
    rest[sort[0][1]] = sort[1][0]
    for i in range(N):
        print(rest[i])


if __name__ == "__main__":
    main()


Measured memory_bytes: 41016
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll n,m;
    cin>>n>>m;
    ll arra[n+5];
    for(int i=1; i<=n; i++)
        cin>>arra[i];
    int x=1;
    vector<ll>vec,ans;
    vec.push_back(1);
    int idx;
    for(int i=1; i<=m; i++)
    {

        ll y=x;
        x=arra[x];
        arra[y]=-1;
        if(arra[x]==-1)
        {
           for(int i=0;i<vec.size();i++) {
              if(vec[i]==x) {
                for(int j=i;j<vec.size();j++) {
                    ans.push_back(vec[j]);
                }

                break;

              }
           }
            break;
        }
        vec.push_back(x);
    }


    /// cout<<vec.size()<<endl;
    ll dx=vec.size()-1;
    m-=dx;
  ///  cout<<m<<endl;
    if(m<=0)
    {
        cout<<vec[dx]<<endl;
    }
    else
    {
        ll fx=ans.size();
        ll mx=m%fx;
        if(mx==0) {
            mx=fx;
        }

        cout<<ans[mx-1]<<endl;

    }



}


Measured memory_bytes: 9188
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())
a = LI()

b = [0 for i in range(N)]
cnt = 0
for i in reversed(range(N)):
    part_sum = 0
    step_cnt = N // (i+1)
    for step in range(2,step_cnt+1):
        # print("step",step)
        part_sum += b[step * (i+1)-1]
    # print(part_sum)
    b[i] = (part_sum + a[i]) % 2

# print(b)
poss = []
for i in range(N):
    if b[i] == 1:
        cnt += 1
        poss.append(i+1)

print(cnt)
for pos in poss:
    print(pos)


Measured memory_bytes: 14528
import copy
n = int(input())
x = list(map(int, input().split()))
x_sorted = sorted(copy.copy(x))
flr = x_sorted[int(n / 2) - 1]
cil = x_sorted[int(n / 2)]
for i in x:
  if i <= flr:
    print(cil)
  else:
    print(flr)

Measured memory_bytes: 26724
import java.util.*;
import java.awt.geom.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			int w = sc.nextInt();
			int d = sc.nextInt();
			if(n==0 && w==0 && d==0) break;
			
			Rectangle2D.Double r = new Rectangle2D.Double(0, 0, w, d);
			Rectangle2D.Double q;
			ArrayList<Rectangle2D.Double> list = new ArrayList<Rectangle2D.Double>();
			list.add(r);
			
			int p, s, x, y;
			for(int i=1;i<=n;i++){
				p = sc.nextInt()-1;
				s = sc.nextInt();
				
				r = list.get(p);
				list.remove(p);
				
				x = (int)r.getX();
				y = (int)r.getY();
				w = (int)r.getWidth();
				d = (int)r.getHeight();
				s %= 2*w+2*d;
				
				for(int j=0;j<2;j++){
					if(s<w){
						if(j==1) s = w-s;
						r = new Rectangle2D.Double(x, y, s, d);
						q = new Rectangle2D.Double(x+s, y, w-s, d);
						if(s<=w/2) list.add(r);
						list.add(q);
						if(s>w/2)list.add(r);
						break;
					}
					s -= w;
					if(s<d){
						if(j==1)s = d-s;
						r = new Rectangle2D.Double(x, y, w, s);
						q = new Rectangle2D.Double(x, y+s, w, d-s);
						if(s<=d/2) list.add(r);
						list.add(q);
						if(s>d/2)list.add(r);
						break;
					}
					s -= d;
				}
			}
			int[] ans = new int[n+1];
			for(int i=0;i<=n;i++) ans[i] = (int)(list.get(i).getWidth()*list.get(i).getHeight());
			Arrays.sort(ans);
			
			for(int i=0;i<n+1;i++){
				if(i!=0) System.out.print(" ");
				System.out.print(ans[i]);
			}
			System.out.println();
		}	
	}	
}

Measured memory_bytes: 38004
#include<iostream>
#include<map>
#include<stdio.h>
#include<algorithm>

#define vai freopen("in","r",stdin);
#define f first
#define s second
#define inf 0x3f3f3f3f

using namespace std;
const int maxn = 2e5 + 10;
const long long int mod = 1e9 + 7;
typedef long long ll;

ll n, m ,v[maxn], sum = 0;
 

ll corte ( ll l ){
	ll sum = 0;
	for(int i = 0 ;i < n;i++) sum+= abs( v[i] -l);
	return sum;
}

int main (){
	 
	cin >> n;
	
	for(ll i = 0 ; i < n ;i++) cin>> v[i], v[i]-=(i+1);
	sort( v, v + n);
	
	cout << min ( corte(v[n/2]) , corte(v[n+1/2]) ) << '\n';
 
 
 
	return 0;
}


Measured memory_bytes: 1792
#include<algorithm>/*{{{*/
#include<cctype>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<vector>
using namespace std;
typedef long long lld;
typedef long double lf;
typedef unsigned long long uld;
typedef pair<int,int> pii;
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define ROF(i,a,b) for(int i=(a);i>=(b);--i)
namespace RA{
    int r(int p){return 1ll*rand()*rand()%p;}
    int r(int L,int R){return r(R-L+1)+L;}
}
namespace IO{
    char nc(){ static char bf[100000],*p1=bf,*p2=bf; return p1==p2&&(p2=(p1=bf)+ fread(bf,1,100000,stdin),p1==p2)?EOF:*p1++; }
    int rd(){ int res=0; char c=getchar(); while(!isdigit(c))c=getchar(); while(isdigit(c))res=res*10+c-'0',c=getchar(); return res; }
}/*}}}*/
/******************heading******************/
const int N=3e5+5;

int n;
int a[N],b[N],c[N];

struct dis{
    int f[N];
    void di(int k){FOR(i,0,k)f[i]=i;}
    int get(int k){return f[k]==k?k:f[k]=get(f[k]);}
    void merge(int x,int y){f[get(x)]=get(y);}
}d;

void sub(int x){
    c[x]--;
    if(!c[x])d.merge(x,x-1);
}
int getsmall(int x){
    return d.get(x);
}

int main(){
    scanf("%d",&n);
    int nn=1<<n;
    d.di(nn+1);
    FOR(i,1,nn)scanf("%d",&a[i]);
    sort(a+1,a+nn+1);
    FOR(i,1,nn){
        int nex=i;
        while(nex<nn&&a[nex]==a[nex+1])a[nex]=a[i-1]+1,++nex;
        a[nex]=a[i-1]+1,i=nex;
    }
    reverse(a+1,a+nn+1);
    FOR(i,1,nn)c[a[i]]++;
    FOR(i,1,nn)if(!c[i])d.merge(i,i-1);
    b[1]=getsmall(nn),sub(b[1]);
    FOR(i,1,n){
        //printf("i=%d\n",i);
        //找到最大的1<<i个数，和b[1..1<<i]检查
        int lim=1<<(i-1);
        FOR(j,1,lim){
            int cur=getsmall(b[j]-1);
            if(!cur)return puts("No"),0;
            b[lim+j]=cur,sub(cur);
        }
        //FOR(j,1,1<<i)printf("%d%c",b[j]," \n"[j==(1<<i)]);
    }
    puts("Yes");
    return 0;
}
/*

1 2 2 2 2 2 2 3 3 3 3 3 3 3 3 4 4 4 4 5 5 6 6 6 6 7 7 7 7 7 8 9

9 8 
7 7 

9 8 7 7 
7 7 6 6 

9 8 7 7 7 7 6 6 
7 6 6 5 5 4 4 4

9 8 7 7 7 7 6 6 7 6 6 5 5 4 4 4
4 3 3 3 3 3 3 3 3 2 2 2 2 2 2 1
*/


Measured memory_bytes: 4608
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
set<int>s;
signed main()
{
	int n,m;
	cin>>n>>m;
	while (m--){
		int a;
		cin>>a;
		while(a--){
			int b;
			cin>>b;
			s.insert(b);
		}
	}
	cout<<n-sz(s);
	re 0;
}

Measured memory_bytes: 3628
import math

s = input().rstrip().split()

l = [int(s[0]), int(s[1]), int(s[2])]

l.sort()

a = l[0]
b = l[1]
c = l[2]
x = b - a
a = c - a
b = c - b



p=0
if x %2==0:
    p = (int)(x / 2 + b)
    
else:
    p = (int)((x - 1) / 2 + b + 2)
    
print(p)

Measured memory_bytes: 3064
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    string s;
    while(cin >> s){
        int num = stoi(s.substr(0, s.find(',')));
        double m = stof(s.substr(s.find(',')+1, s.rfind(',')-1-s.find(',')));
        double h = stof(s.substr(s.rfind(',')+1, s.size()+1-s.rfind(',')));
        double BMI = m / (h * h);
        if(BMI >= 25){
            cout << num << endl;
        }
    }
}

Measured memory_bytes: 1224
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <cmath>
#include <cstring>
#include <stack>
using namespace std;

int main(){
    long long n, a, b;
    cin >> n >> a >> b;
    long long t = n / (a + b), x = n % (a + b);
    cout << (t*a + min(x, a)) << '\n';
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#define INF 999999999

using namespace std;

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

int n, m, a;
int h, p, q;

int main()
{
	while (cin >> n >> m >> a) {
		if (n == 0 && m == 0 && a == 0)return 0;

		int amida[1050];
		for (int i = 1; i <= n; i++) {
			amida[i] = i;
		}

		vector<PP>yokosen;
		for (int i = 0; i < m; i++) {
			cin >> h >> p >> q;
			yokosen.push_back(PP(h, P(p, q)));
		}
		sort(yokosen.begin(), yokosen.end());

		for (int i = 0; i < yokosen.size(); i++) {
			int k = yokosen[i].second.first;
			int j = yokosen[i].second.second;
			swap(amida[k], amida[j]);
		}

		cout << amida[a] << endl;
	}

	return 0;
}

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

using namespace std;
int main()
{
    int a, b, c;
    cin>>a>>b>>c;
    if((a+b)<=(a+c))
    {
        if((a+b)<=(b+c))
        {
            cout<<a+b;
        }
        else
        {
            cout<<b+c;
        }
    }
    else
    {
        if((a+c)<=(b+c))
        {
            cout<<a+c;
        }
        else
        {
            cout<<b+c;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int N;
  scanf("%d",&N);
  int v[N];
  double result = 0;
  for(int i = 0;i < N;i++)
    scanf("%d",&v[i]);
  for(int i = 0;i < N - 1;i++){
    for(int j = i + 1;j < N;j++){
      if(v[i] > v[j]){
	int t = v[j];
	v[j] = v[i];
	v[i] = t;
      }
    }
  }
  result = (v[0] + v[1]) / 2.0;
  for(int i = 2;i < N;i++)
    result = (result + v[i]) / 2.0;
  printf("%f",result);
  return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

/*--------switch header--------*/
#define ALGORITHM   1
#define CASSERT     0
#define CMATH       0
#define DEQUE       0
#define FUNCTIONAL  1
#define IOMANIP     1
#define IOSTREAM    1
#define LIST        0
#define MAP         0
#define QUEUE       0
#define SET         0
#define STRING      1
#define UTILITY     1
#define VECTOR      1
#define VEC_DEBUG   1

using namespace std;

#pragma region headers
#if VEC_DEBUG
#define _GLIBCXX_DEBUG
#endif
#if ALGORITHM
#include <algorithm>
#endif
#if CASSERT
#include <cassert>
#endif
#if CMATH
#include <cmath>
#endif
#if DEQUE
#include <deque>
#endif
#if FUNCTIONAL
#include <functional>
#endif
#if IOMANIP
#include <iomanip>
#endif
#if IOSTREAM
#include <iostream>
#endif
#if LIST
#include <list>
#endif
#if MAP
#include <map>
#endif
#if QUEUE
#include <queue>
#endif
#if SET
#include <set>
#endif
#if STRING
#include <string>
#endif
#if UTILITY
#include <utility>
#endif
#if VECTOR
#include <vector>
#endif
#pragma endregion


/*----------macros----------*/

//output================
#define endl '\n'
#define fcout cout << fixed << setprecision(15)

//typedef===============
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define ALL(x)          (x).begin(), (x).end()
#define rALL(x)         (x).rbegin(), (x).rend()
#define REP(i, n)       for(int i = 0; (i) < (n); (i)++)
#define rREP(i, n)      for(int i = n - 1; (i) >= 0 ; (i)--)
#define FOR(i, a, b)    for(int i = (a); (i) < (b) ; (i)++)
#define CtoI(c)         int((c)) - int('0')

//functions=============
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };



/*--------additional--------*/



/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    string s; cin >> s;
    if(s[2]==s[3] && s[4]==s[5])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

return 0;
}

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

int main(){
  int A,B,C,K,num=0;
  cin>>A>>B>>C>>K;
  if(A>=K){
    while(K!=0){
      K--;
      num++;
    }
  }
  else if(A+B>=K){
    while(A!=0){
      A--;
      num++;
    }
  }
  else {
    for(int i=0;i<K-A-B;i++){
      num--;
    }
    while(A!=0){
      A--;
      num++;
    }
  }
  cout<<num<<endl;
}
   
     

  


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

P p[500000];
int calc(P*a, int n) {
	if (n == 1)return INT_MAX;
	int x = a[n / 2].first;
	int d = min(calc(a, n / 2), calc(a + n / 2, n - n / 2));
	inplace_merge(a, a + n / 2, a + n, [](const P&a, const P&b) {return a.second < b.second; });
	rep(i, n) {
		if (abs(a[i].first - x)*abs(a[i].first - x) >= d)continue;
		for (int j = i + 1; j < n; j++) {
			int dx = a[j].first - a[i].first;
			int dy = a[j].second - a[i].second;
			if (dy*dy >= d)break;
			d = min(d, dx*dx + dy*dy);
		}
	}
	return d;
}
int main() {
	int n; scanf("%d", &n);
	rep(i, n)scanf("%d%d", &p[i].first, &p[i].second);
	sort(p, p + n);
	printf("%d\n", calc(p, n));
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (int i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()

const int MAX = 101;

int N;
int color[2*MAX];

string query(vi nums) {
    cout << "?";
    FORE(n, nums) cout << " " << (n+1);
    cout << endl;
    string ans;
    cin >> ans;
    return ans;
}

vi sequence(int n) {
    vi nums(N);
    REP (i, N) nums[i] = i+n;
    return nums;
}

void set_color(int n, string c, bool other) {
    if (other ^ c == "Blue") color[n] = 1;
    else color[n] = 2;
}

string solve() {
    string base = query(sequence(0));

    int left = 0, right = N;
    while (right - left > 1) {
        int mid = (left + right) / 2;
        if (query(sequence(mid)) == base) left = mid;
        else right = mid;
    }

    set_color(left, base, true);
    set_color(left+N, base, false);

    vi row1 = sequence(left+1);
    vi row2;
    REP (i, left) row2.PB(i);
    FOR (i, left+N+1, 2*N) row2.PB(i);
    row2.PB(0);

    REP (i, 2*N) {
        if (i == left || i == left + N) continue;
        else if (i < left || left + N < i) {
            row1[N-1] = i;
            set_color(i, query(row1), true);
        } else {
            row2[N-1] = i;
            set_color(i, query(row2), true);
        }
    }

    string ans = "! ";
    REP (i, 2*N) ans += (color[i] == 1 ? "R" : "B");
    return ans;
}

int main() {
    cin >> N;
    cout << solve() << endl;
}

Measured memory_bytes: 724
#include <bits/stdc++.h>
#define maxn 100005
using namespace std;

int main() {
    int a[4][4]={},n,x,b[4][4]={},i,j;
    for(int i=1;i<=3;i++){
        for(int j=1;j<=3;j++){
            cin>>a[i][j];
        }
    }
    cin>>n;
    while(n--){
        cin>>x;
        for(int i=1;i<=3;i++){
            for(int j=1;j<=3;j++){
                if(a[i][j]==x) b[i][j]=1;
            }
        }
    }
    int ok=0,s;
    for(i=1;i<=3;i++){
        s=1;
        for(int j=1;j<=3;j++){
            if(b[i][j]==0) s=0;
        }
        if(s==1)ok=1;
    }
    for(int j=1;j<=3;j++){
        s=1;
        for(int i=1;i<=3;i++){
            if(b[i][j]==0) s=0;
        }
        if(s==1) ok=1;
    }
    s=1;
    for(i=1;i<=3;i++){
        if(b[i][i]==0) s=0;
    }
    if(s==1) ok=1;
    s=1;
    for(i=1;i<=3;i++){
        if(b[i][3-i+1]==0) s=0;
    }
    if(s==1) ok=1;
    if(ok==1) cout<<"Yes";
    else      cout<<"No";
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <iomanip>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define ls ro<<1
#define fi first
#define se second
#define rs ro<<1|1
#define ll long long
#define pb push_back
#define vi vector<int>
#define lowbit(x) x&(-x)
#define pii pair<int,int>
#define lson ro<<1,l,mid
#define umap unordered_map
#define uset unordered_set
#define rson ro<<1|1,mid+1,r
#define mem(a,b) memset(a,b,sizeof(a))
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);

using namespace std;

const int INF = 0x3f3f3f3f;




int main() {
	IOS;
	double a,b;
	cin>>a>>b;
	cout<<ceil(a/b)<<endl;






	return 0;
}


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

int main(){
  int n, k;
  cin >> n >> k;
  int a[n];
  for ( int i = 0; i < n; i++){
    cin >> a[i];
  }
  double n_d = (double)n;
  double k_d = (double)k;
  int ans = (int)ceil((n_d - k_d)/(k_d-1)) + 1;
  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<vector<vector<char> >,int> P;
const long long int MOD = 1000000007;
const int INF = 1000000000;

string str;
ll n;
ll p = 1;
int s;
ll num[10];
ll ans = 0;
ll out;

int main(){
    cin >> str;
    s = str.size();
    rep(i,s){
        n = n*10+str[i]-'0';
        p *= 10;
    }
    rep(i,10) num[i] = i;
    do{
        ll x = 0;
        rep(i,s){
            x = x*10+num[i];
        }
        ll pre = min(abs(x-n),p-abs(x-n));
        if(pre > ans || (pre==ans && out > x)){
            ans = pre;
            out = x;
        }
        
    } while(next_permutation(num,num+10));
    ll pp = 1;
    ll zu = 0;
    while(pp <= out){
        pp *= 10;
        zu++;
    }
    rep(i,s-zu) cout << 0;
    cout << out << endl;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define mp make_pair
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
const ll INF=1LL<<40;
const ll LINF=1LL<<62;
const double eps=1e-9;
const ll MOD=1000000007LL;
template<typename T>void chmin(T &a,T b){a=min(a,b);};
template<typename T>void chmax(T &a,T b){a=max(a,b);};
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V>typename enable_if<is_class<T>::value==0>::type fill_v(T& t,const V& v){t=v;}
template<typename T,typename V>typename enable_if<is_class<T>::value!=0>::type fill_v(T& t,const V& v){for(auto &e:t)fill_v(e,v);};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
    int n,m,q;cin>>n>>m>>q;
    vector<ll> a(n),b(m);
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<m;i++)cin>>b[i];
    while(q--){
        ll x;cin>>x;
        auto itr=lower_bound(all(a),x);if(itr==a.end())--itr;
        ll p=*itr;
        ll q=-INF;
        if(itr!=a.begin()){
            --itr;
            q=*itr;
        }
        itr=lower_bound(all(b),x);if(itr==b.end())--itr;
        ll r=*itr;
        ll s=-INF;
        if(itr!=b.begin()){
            --itr;
            s=*itr;
        }
        ll ans=LINF;
        if(p<x){
            chmin(ans,x-min(p,s));
            if(r<x){
                chmin(ans,x-min(p,r));
            }else{
                chmin(ans,(r-x)*2LL+(x-p));
                chmin(ans,(r-x)+(x-p)*2LL);
            }
        }else if(r<x){
            chmin(ans,x-min(q,r));
            chmin(ans,(p-x)*2LL+(x-r));
            chmin(ans,(p-x)+(x-r)*2LL);
        }else{
            chmin(ans,x-min(q,s));
            chmin(ans,max(p,r)-x);
            chmin(ans,(p-x)*2LL+(x-s));
            chmin(ans,(p-x)+(x-s)*2LL);
            chmin(ans,(r-x)*2LL+(x-q));
            chmin(ans,(r-x)+(x-q)*2LL);
        }
        cout<<ans<<endl;
    }   
}

Measured memory_bytes: 2944
using System;

class Painting {
    static void Main(string[] args) {
        int h = int.Parse(System.Console.ReadLine());
        int w = int.Parse(System.Console.ReadLine());
        int n = int.Parse(System.Console.ReadLine());
        int rtn = 0;
        int wk = 0;
        
        while (wk < n) {
            if (h < w) {
                wk = wk + w;
                h--;
            } else {
                wk = wk + h;
                w--;
            }
            rtn++;
        }
        System.Console.WriteLine(rtn.ToString());
    }
}


Measured memory_bytes: 11220
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iterator>
#include <set>
#include <functional>

using namespace std;

#define DT long long
#define forn(i,n)for(i=0;i<n;i++)
#define forc(i,c,n)for(i=c;i<=n;i++)
#define all(x) (x).begin(), (x).end()

int main() {
	ifstream fin("Text.txt");
	int i, j , q;
	DT m, n, c=0, m1, m2, ans = 0,a,b;
	//scanf("%d%d", &n);
	cin >> n;
	vector<vector<DT> >vc(n, vector<DT>(2));
	forn(i, n) {
		cin >> vc[i][0] >> vc[i][1];
	}
	forn(i, n) {
		a = vc[n - i - 1][0];
		b = vc[n - i - 1][1];

		c = b - ((a + ans) % b);
		if (c != b)
			ans += c;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5760
n=int(input())
x=list(map(int,input().split()))
a=[]
a.append(0)
for i in range(n):
    a.append(x[i])
a.append(0)
sum=0
for i in range(n+1):
    sum+=abs(a[i]-a[i+1])
for i in range(1,n+1):
    s=abs(a[i-1]-a[i+1])
    s1=abs(a[i-1]-a[i])
    s2=abs(a[i]-a[i+1])
    print(sum+s-(s1+s2))


Measured memory_bytes: 14048
#include <iostream>


#include <vector>


using namespace std;


class H
{
public:
	H()
	{}

	vector<int> items;
};
int main()
{
	int n,k;
	cin >>n >>k;
	
	vector<H> hs;
	hs.resize(n);

	for (int i = 0; i < k; i++)
	{
		int k2;
		cin >> k2;
		for (int j = 0; j < k2; j++)
		{
			int k3;
			cin >> k3;
			hs[k3-1].items.push_back(j);
		}
	}
	int cnt = 0;
	for (auto& a : hs)
	{
		if (a.items.size() == 0)
		{
			cnt++;
		}
	}
	cout << cnt;

	return 0;
}

Measured memory_bytes: 3624
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
const ll maxN=1e5+5;
ll a[maxN] , n , q , A , B;
map<ll,ll> mp;

void solve(){
	cin>> n ;
	ll sum=0;
	for(ll i=0;i<n ;i++){
		cin>>a[i];
		sum+=a[i];
		mp[a[i]]++;
	}
	cin>> q ;
	for(ll i=0;i<q;i++){
		cin>> A >> B ;
		if(mp.count(A)==0){
			cout<<sum<<endl;
			continue;
		}
		ll ps=mp[A];
		sum-=(ps*A);
		sum+=(ps*B);
		mp.erase(A);
		if(mp.count(B))
		mp[B]+=ps;
		else mp[B]=ps;
		cout<<sum<<endl;
	}
}
int main(){
	mahakal(),fast;
	ll t=1;
	// cin>>t ;
	while(t--)solve();

	return 0;
}

Measured memory_bytes: 8352
n, m, x = map(int, input().split())
C = []
M = []

for _ in range(n):
    c, *mi = map(int, input().split())
    C.append(c)
    M.append(mi)

res = 10**10

for i in range(1 << n):
    tmp = 0
    cnt = [0] * m
    for j in range(n):
        if (i >> j) & 1 == 1:
            tmp += C[j]
            for k in range(m):
                cnt[k] += M[j][k]
    if min(cnt) >= x:
        res = min(res, tmp)

if res == 10**10:
    print(-1)
else:
    print(res)


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

using namespace std;

#define ll long long
#define vi  vector<int>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD 1e9 + 7
#define PAI  3.1415
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i,n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

ll gcd(ll a,ll b){
  if(a < b)swap(a , b);
  if(a % b == 0) return b;
  else gcd(b, a%b);
}

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a/gcd(a , b))*b;
}

struct UnionFind {
  vi par; //par[i] : iの親番号（例）par[3] = 2 : 3の親は2

  UnionFind(int N) : par(N) { //最初は全てが根として初期化
    rep(i,N) par[i] = i;
  }

  int root(int x){ //データxが属する木の根を再帰で得る : root(x) = {xの木の根}
    if(par[x] == x)return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y){ //xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if(rx == ry)return; //xとyの根が同じ
    par[rx] = ry; //xとyの根が同じでない時、xの根rxをyの根にryにつける。
  }

  bool same(int x, int y){//2つのデータx，yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main(){

  int n; cin >> n;
  vi dp(100010,inf);
  vi v;

  rep(i,7){
    int a = pow(6,i);
    if(a <= 100000)v.pb(a);
    else break;
  }
  rep(i,7){
    int a = pow(9,i);
    if(a <= 100000)v.pb(a);
    else break;
  }

  dp[1] = 1;
  rep(i,v.size()){
    dp[v[i]] = 1;
  }

  for(int i = 1;i < 100001;i++){
    rep(j,v.size()){
      if(i - v[j] < 0)continue;
      chmin(dp[i] , min (dp[i - v[j]] + 1 ,dp[i - 1] + 1));
    }
  }

  cout << dp[n] << endl;

  return 0;

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    ll n, ans = 0;
    cin >> n;
    vector<ll> a(n), pos(n+1);
    set<ll> st;
    rep(i, n){
        cin >> a[i];
        pos[a[i]] = i+1;
    }
    st.insert(pos[1]);
    ans += pos[1]*(n-pos[1]+1);
    REP(i, n-1){
        auto tmp = st.upper_bound(pos[i+1]);
        ll l, r;
        if(tmp == st.begin()){l = 0; r = *tmp;}
        else if(tmp == st.end()){tmp--; l = *tmp; r = n+1;}
        else{tmp--; l = *tmp; tmp++; r = *tmp;}
        l++; r--;
        int a = pos[i+1];
        ans += (a-l+1) * (r-a+1) * (i+1);
        st.insert(pos[i+1]);
    }
    cout << ans << endl;
}


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

int main() {
   int r, g;
   cin >> r >> g;

   cout << 2 * g - r << endl;
}

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

int main() {
	int		a;
	int		b;
	char	sign;
	int		result;

	cin >> a >> sign >> b;
	while (sign != '?')
	{
		if (sign == '+')
			result = a + b;
		else if (sign == '-')
			result = a - b;
		else if (sign == '*')
			result = a * b;
		else if (sign == '/')
			result = a / b;
		cout << result << endl;
		cin >> a >> sign >> b;
	}
}




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

using namespace std;

#define eb emplace_back
#define ii pair<int, int>
#define OK (cerr << "OK" << endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define all(x) x.begin(), x.end()
#define vvi vector<vector<int>>
#define vvii vector<vector<pair<int, int>>>
#define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v))
#define endl '\n'

constexpr int INF = 2e18;
constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 2e5 + 3;

// #define MULTIPLE_TEST_CASES
void solve() {
  int n;
  cin >> n;
  int d;
  cin >> d;

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    if (hypot(x, y) <= d)
      ++ans;
  }
  cout << ans << endl;
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int t = 1;
#ifdef MULTIPLE_TEST_CASES
  cin >> t;
#endif
  while (t--)
    solve();
}

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

using namespace std;

int main()
{
	int n;
	vector<int> v;
	cin >> n;
	for (int i = 1; i <= n;i++)
	{
		int a;
		cin >> a;
		v.push_back(a - i);
	}
	sort(v.begin(), v.end());
	long long ans = 0;
	for (int i = 0; i < n;i++)
		ans += abs(v[i] - v[n / 2]);
	cout << ans << endl;

	return 0;
}


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

int main(){
    int N,M;
    cin >> N >> M;
    int k[M],S[M][N];
    int p[M];

    for(int i=0; i<M; i++){
        cin >> k[i];
        for(int j=0; j<k[i]; j++){
            cin >> S[i][j];
        }
    }
    for(int i=0; i<M; i++){
        cin >> p[i];
    }
 
    int maxCases = 1<<N;
    int count=0;

    for(int numCase=0; numCase < maxCases; numCase++){

        int son[N];
        int pon[M];
        for(int i=0; i<N; i++) son[i]=0;
        for(int i=0; i<M; i++) pon[i]=0;        
        bool alllight=false; //false

        for(int i=0; i<N; i++){
            son[i]  = (numCase >> i) & 1;
        }

        for(int i=0; i<M; i++){
            for(int j=0; j<k[i]; j++){
                if(son[S[i][j]-1]){
                    pon[i]++;
                }
            }
        }

        for(int i=0; i<M; i++){
            if( pon[i]%2!=p[i] ){
                break;
            }
            if( i == M-1 ){
                alllight = true;
            }
        }
        
        if(alllight){
            count++;
        }

    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    p = list(map(float, input().split()))
    dp = [[0 for _ in range(n + 100)] for _ in range(n + 100)]

    # 初期化
    dp[0][0] = 1.0

    # KeyInsight
    # dp[i][j] := 最初の i 枚のコインを投げたときに、表が j 枚となる確率
    # ・状態：確率
    # ・すべての候補，条件に一致する候補をdpで管理
    # See:
    # https://qiita.com/drken/items/03c7db44ccd27820ea0d#i-%E5%95%8F%E9%A1%8C---coins
    for i in range(n):
        for j in range(i + 1):
            # 表
            dp[i + 1][j + 1] += dp[i][j] * p[i]
            # 裏
            dp[i + 1][j] += dp[i][j] * (1 - p[i])

    ans = 0

    # 表が多い場合のみ計算
    for j in range((n + 1) // 2, n + 1):
        ans += dp[n][j]

    print(ans)


if __name__ == '__main__':
    main()


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

int main() {
    int64_t A,B,H,M;
    cin >> A >> B >> H >> M;
    double the_1,the_2,the;

    the_1 = M_PI*(60*H+M)/360.0;
    the_2 = M_PI*M/30.0;
    the = the_1 - the_2;

    double ans = sqrt(A*A+B*B-2*A*B*cos(the));

    cout << fixed << setprecision(15) << ans << endl;
}


Measured memory_bytes: 4192
while True:
    x=int(input())
    if x==0:
        break

    y=1000-x;
    a=y%500
    b=a%100
    c=b%50
    d=c%10
    e=d%5
    z=y//500+a//100+b//50+c//10+d//5+e
    print(z)



Measured memory_bytes: 5584
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=100000000000000000;


int main() {
    int a,b;
    cin >> a >> b;
    if (b%a==0) cout << a+b << endl;
    else cout << b-a << endl; 
    
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <tuple>
#define ll long long
using namespace std;
/*階乗*/
ll factorial(ll n){
    if(n==0){
        return 1;
    }
    else{
        return n*factorial(n-1);
    }
}

/* ユークリッドの互除法 最大公約数*/
/*ll gcd(ll a, ll b) {
	ll r;
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}
*/


/*最小公倍数*/
/*
ll lcm(ll a,ll b){
	return a/gcd(a,b)*b;
}
*/

/*二点間の距離*/
double dist(pair<double,double> a,pair<double,double> b){
	return sqrt(pow((a.first - b.first) ,2) + pow((a.second - b.second),2));
}

//繰り返し自乗法
double ism(double aa,ll p){
    double ap=aa;
    double ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans*=ap;
        }
        p/=2;
        ap=ap*ap;
    }
    return ans;

}
//繰り返し自乗法(アマリトリバージョン)
ll ismm(ll aa,ll p,ll m){
    ll ap=aa;
    ll ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans=(ans*ap)%m;    
        }
        p/=2;              
        ap=(ap*ap)%m;
    }
    return ans;

}
/*
ll solve(ll i,ll m,vector<ll>t,ll n){
    if(m==0){
        return 1;
    }
    if(i>=n){
        return 0;
    }
    
    
    cout<<i+1<<" "<<m<<endl;
    cout<<i+1<<" "<<m-t[i]<<endl;
    ll res=solve(i+1,m,t,n)||solve(i+1,m-t[i],t,n);
    return res;
}
*/

//小数点12桁
struct all_init
{
    all_init()
    {
        cout << fixed << setprecision(12);
    }
} All_init;


int main()
{
    ll n;
    cin>>n;
    cout<<(n+2-1)/2<<endl;

    

}

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

x = 0 
y = 0
t = 0

for i in Input:
    dif_x = abs(x - i[1])
    dif_y = abs(y - i[2])
    dif_t = abs(t - i[0])

    if dif_x + dif_y <= dif_t and (dif_x + dif_y)%2 == dif_t%2:
        x = i[1]
        y = i[2]
        t = i[0]
    else:
        print("No")
        break

else:
    print("Yes")

Measured memory_bytes: 27380
package main

import "fmt"

func main() {
	var b string
	fmt.Scan(&b)

	switch b {
	case "A":
		fmt.Println("T")
	case "C":
		fmt.Println("G")
	case "G":
		fmt.Println("C")
	case "T":
		fmt.Println("A")
	}
}


Measured memory_bytes: 512
#include <stdio.h>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define min(a, b) ((a) < (b) ? (a) : (b))

#define scani(i) scanf("%d", &(i))
#define scanc(c) scanf("%c", &(c))
#define scand(d) scanf("%lf", &(d))

#define printi(i) printf("%d", i)
#define pr printf("\n")

#define NUM (100)

int main(int argc, char** argv){
    int n, b[99];
    scani(n);


    rep(i, n - 1){
        scani(b[i]);
    }

    int sum = 0;
    sum += b[0];
    sum += b[n-2];

    rep(i, n - 2){
        sum += min(b[i], b[i+1]);
    }
    printi(sum);
    pr;


    return 0;
}



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

using namespace std;

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

  int n;
  cin >> n;
  vector<int> A(n), B(n), C(n);
  for (auto &a : A) cin >> a;
  for (auto &b : B) cin >> b;
  for (auto &c : C) cin >> c;
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());
  
  
  long long a = n-1, b = n-1, c = n-1;
  vector<long long> sum(n,0);
  while (a >= 0 && b >= 0) {
    while (a >= 0 && A[a] >= B[b]) a--;
    if (a < 0) break;
    sum[b] = a+1;
    b--;
  }
  for (int i = 1; i < n; ++i) {
    sum[i] += sum[i-1];
  }

  b = n-1; 
  long long res = 0;
  while (b >= 0 && c >= 0) {
    while (b >= 0 && B[b] >= C[c]) b--;
    if (b < 0) break;
    res += sum[b]; 
    c--;
  }
  cout << res << endl;

  return 0;
}



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

vector<int>pes,color,ces,sz;
vector<ll>points;

void dfs(int u, int z){
	color[u]=z;
	points[color[u]]+=ces[u];
	sz[color[u]]++;

	int v = pes[u];
	if(color[v]==-1)dfs(v,z);
}


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;ll k;
	cin>>n>>k;
	pes=ces=sz=vector<int>(n+1);
	color.resize(n+1,-1);
	points.resize(n+1);

	
	for(int i=1;i<=n;i++){
		cin>>pes[i];
	}
	for(int i=1;i<=n;i++){
		cin>>ces[i];
	}
	int z = 0;
	for(int i=1;i<=n;i++){
		if(color[i]==-1){
			dfs(i,++z);
		}
	}
	ll ans=-5e18;
	for(int i =1;i<=n;i++){
		ll cnt=k/sz[color[i]];
		int len=k%sz[color[i]];
		ll tmp=0;
		ll foo1=-5e18,foo2=-5e18,foo3=-5e18;
		
		for(int u=pes[i],qtd=0;u!=i;u=pes[u],qtd++){
			tmp+=ces[u];
			foo1=max(tmp,foo1);
			if(qtd<len)foo2=max(tmp,foo2);
			if(qtd<k)foo3=max(tmp,foo3);
		}
		tmp+=ces[i];
		foo1=max(tmp,foo1);
		ans=max(foo3,ans);
		tmp=foo2+cnt*points[color[i]];
		if(cnt>0)tmp=max(tmp,foo1+(cnt-1)*points[color[i]]);
		ans=max(ans,max(foo2,tmp));
	}
	cout<<ans;
	
	return 0;
}

Measured memory_bytes: 3784
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back      
#define F first
#define S second
#define SS stringstream
#define sqr(x) ((x)*(x))
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define CC(x) cout << (x) << endl
#define pw(x) (1ll<<(x))
#define buli(x) __builtin_popcountll(x)
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define M 1000000007
#define N 211111

#define TASK "1"

using namespace std;

long long s, a[4];

int main(){
	#ifdef home
		freopen(TASK".in","r",stdin);	
		freopen(TASK".out","w",stdout);
	#endif		
	ios::sync_with_stdio(false);
	cin >> a[0] >> a[1] >> a[2] >> a[3];
	cin >> s;
	s *= 4;

	for (int i = 0; i < 3; i++) if (a[i] * 2 < a[i + 1]) a[i + 1] = a[i] * 2;

	long long cost = s / 8 * a[3];
	s %= 8;
	for (int i = 2; i >= 0; i--) if (s & pw(i)) cost += a[i];
	cout << cost << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int A[] = new int[N];
        int R;
        boolean Rflg = false;
        int count = 0;

        for (int i = 0; i < N; i++) {
            A[i] = Integer.parseInt(sc.next());
        }

        while (Rflg == false) {
            for (int i = 0; i < N; i++) {
                R = A[i] % 2;
                if (R != 0) {
                    Rflg = true;
                    break;
                }
                A[i] = A[i] / 2;
                count++;
            }
        }

        PrintWriter out = new PrintWriter(System.out);
        out.println(count / N);

        sc.close();
        out.flush();
    }
}

Measured memory_bytes: 25300
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;
typedef long long int ll;
typedef pair<long,long> p;
int main(void){
  ll N;
  cin >> N;
  vector<p> v;
  double fin = sqrt(N);
  for(int n=2;(double)n<=fin;n++){
    ll count = 0;
    while(N%n == 0){
      count++;
      N = N/n;
    }
    if(count != 0){
      v.push_back(make_pair(n,count));
    }
  }
  if(N != 1){
    v.push_back(make_pair(N,1));
  }
  ll ans = 0;
  for(int i=0;i<v.size();i++){
    int num = v[i].second;
    int m;
    for(m=1;;m++){
      if(m*(m+1)/2 > num)
	break;
    }
    ans = ans + m - 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3724
#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 drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

    // 整数スキャン（複数）
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&y);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s;
    cin >> s;
    */


int main() {
    int n;
    scanf("%d",&n);
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }

    int ans = 0;

    rep(i,n-1){
        if(a[i]==a[i+1]){
            ans++;
            i++;
        }
    }

    cout << ans << endl;
   
    return 0;
}
 
 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

int main(){
    int a,b;
    cin>>a>>b;
    cout<<max({a+b,a-b,a*b})<<endl;

    return 0;
}

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

#define se second
#define fi first
#define mk(a,b) make_pair(a,b)

typedef long long ll;
typedef pair<ll, ll> pll;

int N;
ll H[100010], P[100010];
vector<pll> V;
ll dp[5010][5010];
ll INF = 1000000000000000000;

int main()
{
    cin >> N;
    for(int i = 0; i < N; i++)cin >> H[i] >> P[i];

    for(int i = 0; i < N; i++)V.push_back(mk(P[i] + H[i], i));

    sort(V.begin(), V.end());

    for(int i = 0; i < 5010; i++)for(int j = 0; j < 5010; j++)dp[i][j] = INF;
    dp[0][0] = 0;
    for(int i = 0; i < N; i++)for(int j = 0; j < N; j++)
    {
        pll now = V[i];
        ll p = P[now.se], h = H[now.se];

        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
        if(dp[i][j] <= h)dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + p);
    }

    int ans = 0;
    for(int i = 0; i < 5010; i++)if(dp[N][i] != INF)ans = i;

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 197120
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  ll n;
  cin >> n;
  ll ans = 0;
  for(ll i = 0; i < n; i++){
    ans += i;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d %d", $x, $n);
if($x === 0) {
    $a = [];
} else {
    $aa = fgets(STDIN);
    $a = explode(' ', $aa);

    foreach ($a as &$value) {
        $value = (int) $value;
    }
    unset($value);
    sort($a);
}


$ptr = array_search($x, $a);
if($ptr === false) {
    echo $x;
    exit(0);
}

$fwdptr = $ptr;
$revptr = $ptr;

for($i = 0;true;$i++) {
    $possible_fwd = $a[$ptr] +$i; //11
    $possible_rev = $a[$ptr] -$i; //9

    if($a[$revptr] === $possible_rev) {
        $revptr--;
    } else {
        echo $possible_rev;
        exit(0);
    }
    if($a[$fwdptr] === $possible_fwd) {
        $fwdptr++;
    } else {
        echo $possible_fwd;
        exit(0);
    }
}


Measured memory_bytes: 16132
import math
n, p = [int(i) for i in input().split()]
a = [int(i) % 2 for i in input().split()]
def nCr(n, r):
    f = math.factorial
    return f(n) // f(r) // f(n-r)
print(sum([nCr(a.count(1), i) for i in range(p, a.count(1) + 1, 2)]) * (2**a.count(0)))

Measured memory_bytes: 3060