akhauriyash/Code-Regression huggingface dataset:
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

N = int(readline())
k = -1
for i in range(1,1000):
    if i*(i-1)//2 == N:
        k = i
        print('Yes')
        break
if k == -1:
    print('No')
    exit()

print(k)
ans = [[] for i in range(k)]

import itertools

for i,(a,b) in enumerate(itertools.combinations(range(k),2),1):
    ans[a].append(i)
    ans[b].append(i)

for aaa in ans:
    print(len(aaa),' '.join(map(str,aaa)))


Measured memory_bytes: 9204
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(){
    string S; cin >> S;
    int K; cin >> K;
    int L = S.length();
    
    for(int i=0;i<L-1;i++){
        if(S[i] == 'a') continue;
        int diff = abs(S[i] - 'z') + 1;
        if(diff <= K){
            S[i] = 'a';
            K -= diff;
        }
    }
    K %= 26;
    (S[L-1] += K-'a') %= 26;
    S[L-1] += 'a';

    cout << S << endl;
    return 0;

}

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

int main(){
	int N;
	cin >> N;
	vector <int> vec(N);
	for (int i = 0; i < N; i++)
		cin >> vec.at(i);
	sort (vec.begin(), vec.end());
	cout << vec.at(N-1) - vec.at(0) << endl;
	return 0;
}


Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
    tmp = input[0].split(" ");
    tmp1 = input[1].split(" ")
    var N = Number(tmp[0])
    var d = []
    for(var i=0; i<N; i++)
    {
        d.push(Number(tmp1[i]))
    }
    d.sort((a,b) => a-b)
    var min = d[d.length/2-1]
    var max = d[d.length/2]
    console.log(max-min)

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main()
{
  ll n,m;
  cin >> n >> m;
  vector<int> v;
  rep(m) v.push_back(0);
  for (ll i = 0; i < n; i++)
  {
    ll k;
    cin >> k;
    for (ll j = 0; j < k; j++)
    {
      ll tmp;
      cin >> tmp;
      v[tmp-1]++;
    }
  }
  ll cnt = 0;
  for (ll i = 0; i < m; i++)
  {
    if(v[i]==n) cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
W = list(map(int, input().split()))
C = list(map(int, input().split()))
#print(N)
#print(W)
#print(C)

from numpy import *
Z = list(array(W)-array(C))
#print(Z)
x = 0
idx = 0
while idx < len(Z):
    if Z[idx] >= 0:
        x += Z[idx]
        idx += 1
    else:
        idx += 1
print(x)

Measured memory_bytes: 13988
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <time.h>
#define INF 100000000000000000LL

using namespace std;
typedef long long int ll;

int main()
{
	int N, C;
	ll d[30][30];
	int c[501][501];
	scanf("%d %d", &N, &C);
	for(int i=0; i<C; i++){
		for(int j=0; j<C; j++){
			scanf("%lld", &d[i][j]);
		}
	}
	for(int i=1; i<=N; i++){
		for(int j=1; j<=N; j++){
			scanf("%d", &c[i][j]);
			c[i][j]--;
		}
	}
	ll dsum[3][30]={};
	for(int i=0; i<C; i++){
		for(int j=1; j<=N; j++){
			for(int k=1; k<=N; k++){
				dsum[(j+k)%3][i]+=d[c[j][k]][i];
			}
		}
	}
	ll ans=INF;
	for(int i=0; i<C; i++){
		for(int j=0; j<C; j++){
			for(int k=0; k<C; k++){
				if(i==j || j==k || i==k) continue;
				if(ans>dsum[0][i]+dsum[1][j]+dsum[2][k]) ans=dsum[0][i]+dsum[1][j]+dsum[2][k];
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 1280
#include<iostream>
#include<vector>
#include<algorithm>
#define DIM 100005
#define f first
#define s second
using namespace std;
int n, m, i, r1, r2, nr;
int ff[DIM], r[DIM], viz[DIM], val[DIM];
long long sum[DIM];
vector< pair<int, int> > v[DIM];
struct str{
    int x, y, c;
};
str w[DIM];
int cmp(str a, str b){
    return a.c < b.c;
}
int rad(int x){
    while(r[x] > 0){
        x = r[x];
    }
    return x;
}
void dfs(int nod, int maxim){
    for(int i = 0; i < v[nod].size(); i++){
        int ind = v[nod][i].s;
        if(viz[ind] == 0 && w[ind].c <= maxim){
            viz[ind] = 1;
            nr++;
            dfs(v[nod][i].f, maxim);
        }
    }
}
int main(){
    cin>> n >> m;
    for(i = 1; i <= n; i++){
        cin>> val[i];
    }
    for(i = 1; i <= m; i++){
        cin>> w[i].x >> w[i].y >> w[i].c;
    }
    sort(w + 1, w + m + 1, cmp);
    for(i = 1; i <= n; i++){
        r[i] = -1;
        sum[i] = val[i];
    }
    for(i = 1; i <= m; i++){
        r1 = rad(w[i].x);
        r2 = rad(w[i].y);
        if(r1 != r2){
            if(r[r1] < r[r2]){
                r[r1] += r[r2];
                r[r2] = r1;
                sum[r1] += sum[r2];
            }
            else{
                r[r2] += r[r1];
                r[r1] = r2;
                sum[r2] += sum[r1];
            }
        }
        r1 = rad(w[i].x);
        if(sum[r1] >= w[i].c){
            ff[i] = 1;
        }
    }
    for(i = 1; i <= m; i++){
        v[ w[i].x ].push_back( make_pair(w[i].y, i) );
        v[ w[i].y ].push_back( make_pair(w[i].x, i) );
    }
    for(i = m; i >= 1; i--){
        if(viz[i] == 0 && ff[i] == 1){
            dfs(w[i].x, w[i].c);
        }
    }
    cout<< m - nr;
    return 0;
}


Measured memory_bytes: 13824
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int H,W,K;
    cin >> H >> W >> K;
    vector<vector<int>>c(H,vector<int>(W));
    vector<vector<int>>d(H,vector<int>(W));
    char hold;
    int black = 0;
    for (int i = 0; i<H; i++){
        for (int j = 0; j<W; j++){
            cin >> hold;
            if(hold == '.'){
                c.at(i).at(j) = 0;
            }else{
                c.at(i).at(j) = 1;
                black++;
            }
            
        }
    }
    int ans = 0;
    int count,count1;
    for (int bits = 0; bits < (1 << H); bits++) {
        count = 0;
        d = c;
        for (int i = 0; i < H; i++) {
            int mask = 1 << i;
            if (bits & mask) {  // i番目のbitが立っている
                for (int j = 0; j < W; j++) {
                    if (d.at(i).at(j) == 1){
                        count ++;
                        d.at(i).at(j) = 0;
                    }
                }
            }
        }
        for (int bits1 = 0; bits1 < (1 << W); bits1++) {
            count1 = 0;
            for (int j = 0; j < W; j++) {
                int mask1 = 1 << j;
                if (bits1 & mask1) {  // j番目のbitが立っている
                    for (int k = 0; k < H; k++) {
                        count1 += d.at(k).at(j);
                    }
                }
            }

            if(black - count - count1 == K){
                ans++;
            }
            
        }
        
    }
    cout << ans << endl;
}


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

int main() {
  string str;
  cin >> str;
  int S = str.size();
  vector<int> rs;
  vector<int> ls;
  vector<int> rt;
  vector<int> lt;
  
  for (int i = 0; i < S-1; i++) {
    if (str.at(i) == 'R' && str.at(i+1) == 'L') {
      rs.push_back(i);
      ls.push_back(i+1);
    }
    if (str.at(i) == 'L' && str.at(i+1) == 'R') {
      lt.push_back(i);
      rt.push_back(i+1);
    }
  }
  int M = rs.size();
  
  int ans[S];
  for (int i = 0; i < S; i++) {
    ans[i] = 0;
  }
  if ((rs[0]+1) % 2 == 0) {
    ans[rs[0]] += (rs[0]+1)/2;
    ans[ls[0]] += (rs[0]+1)/2;
  } else {
    ans[rs[0]] += (rs[0]+1)/2 + 1;
    ans[ls[0]] += (rs[0]+1)/2;
  }
  
  if ((S-ls[M-1]) % 2 == 0) {
    ans[rs[M-1]] += (S-ls[M-1])/2;
    ans[ls[M-1]] += (S-ls[M-1])/2;
  } else  {
    ans[rs[M-1]] += (S-ls[M-1])/2;
    ans[ls[M-1]] += (S-ls[M-1])/2+1;
  } 
  
  for (int i = 0; i < M-1; i++) {
    if ((lt[i]-ls[i]+1) % 2 == 0) {
      ans[rs[i]] += (lt[i]-ls[i]+1) / 2;
      ans[ls[i]] += (lt[i]-ls[i]+1) / 2;
    } else {
      ans[rs[i]] += (lt[i]-ls[i]+1) / 2;
      ans[ls[i]] += (lt[i]-ls[i]+1) / 2+1;
    }
    if ((rs[i+1]-rt[i]+1) % 2 == 0) {
      ans[rs[i+1]] += (rs[i+1]-rt[i]+1) / 2;
      ans[ls[i+1]] += (rs[i+1]-rt[i]+1) / 2;
    } else {
      ans[rs[i+1]] += (rs[i+1]-rt[i]+1) / 2+1;
      ans[ls[i+1]] += (rs[i+1]-rt[i]+1) / 2;
    }
  }
  for (int i = 0; i < S; i++) {
    cout << ans[i] << ' ';
  }
  cout << endl;
}

Measured memory_bytes: 2004
#include <bits/stdc++.h>
#define ll long long
#define pi pair<int, int>
#define vi vector<int>
#define pll pair<ll, ll>
#define pb push_back
#define mod 1000000007
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, m, v, p;
	cin>>n>>m>>v>>p;
	vector<ll> a(n + 1), sum(n + 1);
	sum[0] = 0;
	for(int i = 1; i <= n; i++){
		cin>>a[i];
	}
	sort(a.begin(), a.end());
	for(int i = 1; i <= n; i++){
		sum[i] = a[i] + sum[i - 1];
	}
	ll j = 1, ans = 0;
	for(ll i = 1; i <= n; i++){
		while(j <= n && a[j] <= a[i] + m){
			j++;
		}
		if(n + 1 - j >= p){
			continue;
		}
		ll total = v * m - i * m - (n + 1 - j) * m;
		if(total <= (j - 1 - i) * (a[i] + m) - (sum[j - 1] - sum[i])){
			ans++;
			continue;
		}
		ll low = i, high = j - 1;
		while(low < high){
			ll mid = (low + high) / 2;
			ll temp = (mid - i) * (a[i] + m) - (sum[mid] - sum[i]);
			temp = total - temp;
			if(temp % m == 0){
				if((temp / m) >= (j - 1 - mid)){
					high = mid;
				}
				else{
					low = mid + 1;
				}
			}
			else{
				if((temp / m) >= (j - 1 - mid)){
					high = mid;
				}
				else if((temp / m) == (j - 1 - mid) - 1 && a[mid + 1] + (temp % m) > a[i] + m){
					high = mid;
				}
				else{
					low = mid + 1;
				}
			}
			// temp += (j - 1 - mid) * (a[i] + m + 1) - (sum[j - 1] - sum[mid]);
			// if(temp > total){
			// 	low = mid + 1;
			// }
			// else{
			// 	high = mid;
			// }
		}
		ll temp = (low - i) * (a[i] + m) - (sum[low] - sum[i]);
		temp += (j - 1 - low) * m;
		temp = total - temp;
		if(n + 1 - (low + 1) < p - 1){
			// cout<<i<<endl;
			ans++;
		}
		else if(n + 1 - (low + 1) == p - 1 && a[i + 1] + temp <= a[i] + m){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1792
N = int(input())
A = list(map(int,input().split()))
i = 0
count = 1
while i < N-1:
    while i < N-1 and A[i] == A[i+1]:
        i += 1
    # Up
    if A[i] < A[i+1]:
        while i < N-1 and A[i] <= A[i+1]:
            i += 1
        if i < N-1:
            count += 1
            i += 1
    # Down
    elif A[i] > A[i+1]:
        while i < N-1 and A[i] >= A[i+1]:
            i += 1
        if i < N-1:
            count += 1
            i += 1
print(count)

Measured memory_bytes: 14224
using System;
using System.Linq;

namespace ABC104A
{
    class ABC104A
    {
        static void Main(string[] args)
        {
            var dg = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            var n = dg[0];
            var k = dg[1];

            Console.WriteLine(n % k == 0 ? "0" : "1");
        }
    }
}


Measured memory_bytes: 13268
import collections

N = int(input())
A = list(map(int,(input().split())))
d = collections.Counter(A)

num = [0]*(N+1)
for i in range(N+1):
    num[i] = d[i]

s = 0
for i in range(N+1):
    s += num[i]*(num[i]-1)//2
    
for i in range(1,N+1):
    print(s-(d[A[i-1]])+1)

Measured memory_bytes: 89804
#include<iostream>
using namespace std;
int main() {
    int n, x;
    
    while (true) {
        cin >> n >> x;
        if (n == 0 && x == 0) break;

        int a[100] = {};        
        for (int i = 0; i < n; i++) {
            a[i] = 1 + i;
        }
        
        int match = 0;
        /*
        for (int i = 0; i < n - 2; i++) {
            for (int j = i + 1; j < n - 1; j++) {
                for (int k = j + 1; k < n; k++) {
                    if (i == j || i == k || j == k) continue;
                    if (a[i] + a[j] + a[k] == x) match++;
                }
            }
        }*/
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                for (int k = 0; k < n; k++) {
                    if (i > j || i > k || j > k) continue;
                    if (i == j || i == k || j == k) continue;
                    if (a[i] + a[j] + a[k] == x) match++;
                }
            }
        }
        cout << match << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3012
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,a,b,ans;
  cin>>n>>a>>b;
  if (a>b) ans=0;
  else if (n==1) {
    if (a==b) ans=1;
    else ans=0;
  }
  else ans=(b-a)*(n-2)+1;
  cout<<ans;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	v := make([]float64, n)
	for i := range v {
		fmt.Scan(&v[i])
	}
	sort.Float64s(v)
	ans := (v[0] + v[1]) / 2
	for i := 2; i < len(v); i++ {
		ans = (ans + v[i]) / 2
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main() {
  int input1,input2,input3;
  vector<int> vect1(4,0);
  cin >> input1 >> input2;
  vect1[input1] = 1;
  vect1[input2] = 1;
  for(int i=1;i<vect1.size();i++){
    if(vect1[i]==0){
      cout << i;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
#define pb push_back
#define ins insert
#define pll pair<ll,ll>
#define fi first
#define se second
#define mpr make_pair
#define vtr vector
#define itor iterator 
#define N ll(1e9+7)
#define endl '\n'
#define inf ll(1e9)
using namespace std;
//ll power(ll a,ll b,ll mod)
//{
//	if(b==0)return 1;
//	ll ans=1;
//	while(b>0)
//	{
//		if(b&1)ans=(ans*a)%mod;
//		a=(a*a)%mod;
//		b>>=1;
//	}
//	return ans;
//}
int main()
{
	ios;
	ll t=1;
	while(t--){
		ll n,k,c;
	cin>>n;
	ll ans=2,i,div1,div2;
	for(i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			div1=i;
			div2=n/i;
			if(div1==div2)
			{
				ans++;
			}
			else
			{
				ll tp=n;
				while(tp%div1==0)
				{
					tp/=div1;
				}
				if(tp%div1==1)
				{
					ans++;
				}
//				tp=n;
//				while(tp%div2==0)
//				{
//					tp/=div2;
//				}
//				if(tp%div2==1)ans++;
			}
		}
	}
	for(i=2;i*i<=(n-1);i++)
	{
		if((n-1)%i==0)
		{
			div1=i;
			div2=(n-1)/i;
			if(div1==div2)
			{
				ans++;
			}
			else
			{
				ans+=2;
			}
		}
	}
	if(n-1==1)ans--;
	cout<<ans;
	}
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://agc017.contest.atcoder.jp/tasks/agc017_b>
問題文============================================================
 N 個のマスが一列に並んでいます． 一番左のマスには整数 A が，
 一番右のマスには整数 B が書かれており，他のマスには何も書かれていません．
 
 青橋君は，何も書かれていないマスに整数を書き込み，次の条件を満たすようにしたいです：
 
     どの隣接する 2 マスについても，書かれている整数の差は C 以上 D 以下である．
 
 青橋君は，この条件を満たす限り，いくらでも大きい整数や小さい整数を書き込むことができます．
 青橋君が条件を満たすように整数を書き込むことができるかを判定してください．
=================================================================

解説=============================================================
 
 A o o o ... o o o B
 
 各iマス目に関して、iマス目の値を Xi とした時
 全ての[1...N-1]のマスに関して
 -D <= Xi+1 - Xi <= -C (1) , C <= Xi+1 - Xi <= D  (2)
 が成り立つ。
 
 この時, N-1個の条件のうち m 個が (1) の条件を,
                     N-1-m個が (2) の条件を満たす時
 
 各々の条件を全て合わせると（総和を取る)
 
 C(N-1-m) - D*m <= Σ(Xi+1 - Xi) <= D(N-1-m) - C*m
 
 Σ(Xi+1 - Xi) => X_N - X_1 = B - A
 
 よって、この条件を満たす m が一つでも存在すれば A から B にすることができる
================================================================
*/
ll N,A,B,C,D;
inline bool f(ll m){
    return (C*(N-1-m) - D*m <= B - A) && (B - A <= D*(N-1-m) - C*m);
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    cin >> N >> A >> B >> C >> D;
    for(int i = 0; i < N;i++){
        if(f(i)){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
package main

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

const n = 26

func main() {
	io := NewIo(os.Stdin, os.Stdout)
	defer io.Flush()
	d := io.NextInt()
	c := io.NextInts(n)
	s := make([][]int, d)
	for i := 0; i < d; i++ {
		s[i] = io.NextInts(n)
	}
	t := io.NextInts(d)
	m := io.NextInt()
	k, v := make([]int, m), make([]int, m)
	for i := 0; i < m; i++ {
		k[i], v[i] = io.NextInt(), io.NextInt()
	}
	ans := solve(c, s, t, k, v)
	for i := range ans {
		io.Println(ans[i])
	}
}

func solve(c []int, s [][]int, t, k, v []int) []int {
	m := len(k)
	scores := make([]int, m)
	for i := 0; i < m; i++ {
		t[k[i]-1] = v[i]
		scores[i] = calcScore(c, s, t)
	}
	return scores
}

func calcScore(c []int, s [][]int, t []int) int {
	d := len(s)
	lasts := make([]int, n)
	score := 0
	for i := 0; i < d; i++ {
		lasts[t[i]-1] = i + 1
		up := s[i][t[i]-1]
		down := calcDown(c, lasts, i+1)
		score += up - down
	}
	return score
}

func calcDown(c []int, lasts []int, day int) int {
	down := 0
	for i := 0; i < n; i++ {
		down += c[i] * (day - lasts[i])
	}
	return down
}

// Io is I/O object
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

// NewIo returns a new Io instance
func NewIo(r io.Reader, w io.Writer) *Io {
	return &Io{
		reader: bufio.NewReader(r),
		writer: bufio.NewWriter(w),
	}
}

// Flush flushes writer
func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

// NextLine scans a line from stdin
func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

// Next return a word from stdin
func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

// NextInt returns an integer from stdin
func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

// NextInts returns n integers from stdin
func (io *Io) NextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = io.NextInt()
	}
	return ret
}

// Println is a wrapper of fmt.Fprintln
func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


Measured memory_bytes: 6136
#pragma region
// Author: Wenxing Mei
//   Date: 2018-08-25 20:17
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/trie_policy.hpp>
// using namespace __gnu_pbds;
#define rep(i, l, r) for (int i = (l); i < (r); ++i)
#define per(i, r, l) for (int i = (r); i >= (l); --i)
#define repv(ele, vec) for (auto &ele : vec)
#define zero(mem) memset(mem, 0, sizeof(mem))
#define sd(_) scanf("%d", &_)
#define sdd(_, __) scanf("%d%d", &_, &__)
#define sddd(_, __, ___) scanf("%d%d%d", &_, &__, &___)
#define sdddd(_, __, ___, ____) scanf("%d%d%d%d", &_, &__, &___, &____)
#define sf(_) scanf("%lf", &_)
#define sff(_, __) scanf("%lf%lf", &_, &__)
#define sfff(_, __, ___) scanf("%lf%lf%lf", &_, &__, &___)
#define sffff(_, __, ___, ____) scanf("%lf%lf%lf%lf", &_, &__, &___, &____)
#define sl(_) scanf("%lld", &_)
#define sll(_, __) scanf("%lld%lld", &_, &__)
#define slll(_, __, ___) scanf("%lld%lld%lld", &_, &__, &___)
#define sllll(_, __, ___, ____) scanf("%lld%lld%lld%lld", &_, &__, &___, &____)
#define sc(_) scanf("%c", &_)
#define ss(_) scanf("%s", _)
#define sz(x) (int)(x).size()
#define mid(a, b) (((a) + (b)) >> 1)
#define lfg(x) x << 1
#define rht(x) x << 1 | 1
#define inf 0x3f3f3f3f
#define all(container) container.begin(), container.end()
//#define MOD 19260817
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
#define get0 get<0>
#define get1 get<1>
#define get2 get<2>
#define get3 get<3>
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#pragma endregion

// Read the question correctly
// What are the exact constraints?
// Look out for SPECIAL CASES (n=1? n=1000000000?) and overflow (ull vs int?)
int a[100010];
int main() {
  int n, k;
  sdd(n, k);
  rep(i, 0, n) { sd(a[i]); }

  int x0 = lower_bound(a, a + n, 0) - a;
  if (x0 == 0) {
    printf("%d\n", a[k - 1]);
    return 0;
  } else if (x0 == n) {
    printf("%d\n", -a[x0 - k]);
    return 0;
  }
  int rhs_left = n - x0;

  int res = 0x7fffffff;
  rep(lhs_cnt, 0, x0 + 1) {
    // cout << ">> " << lhs_cnt << " " << x0 << endl;

    int rhs_need = k - lhs_cnt;
    // cout << rhs_need << " " << rhs_left << endl;
    if (rhs_need > rhs_left) { continue; }

    int tmp;
    if (lhs_cnt == 0) {
      tmp = a[x0 + k - 1];
    } else if (rhs_need == 0) {
      if (a[x0] == 0) {
        tmp = -a[x0 - k + 1];
      } else
        tmp = -a[x0 - k];

    } else {
      int l = -a[x0 - lhs_cnt];
      int r = a[x0 + rhs_need - 1];

      tmp = l + r + min(l, r);
    }
    res = min(res, tmp);
  }
  printf("%d\n", res);

  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=1e9+7 ;

long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a%b, y, x);
    y -= a/b * x;
    return d;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    n *= 2;
    ll ans = n - 1;
    REP(i,2,50000000) {
        if(n%i)continue;
        if(i>=n)break;
        ll x = i, y = n/i;
        rep(_,2){
            ll a=0,b=0;
            ll g = extGCD(x,y,a,b);
            if(g!=1)continue;
            while(a<0){
                a+=y;b-=x;
            }
            while(a>y){
                a-=y;b+=x;
            }
            assert(a*x + b* y == 1);
            if(1.0 * a * x > 1e18)continue;
            ans = min(ans, a*x);

            a=-a;b=-b;
            a+=y;b-=x;
            assert(a*x + b* y == -1);
            if(1.0 * a * x > 1e18)continue;
            ans = min(ans, a * x);
            swap(x,y);
        }
    }
    cout << ans << endl;
    return 0;
}

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


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

	long long l[n+1]={2,1};
	for (int i = 2; i <= n; i++){
		l[i]=l[i-2]+l[i-1];
	}
	
	cout<<l[n]<<endl;

}


Measured memory_bytes: 256
n = gets.chomp.to_i
a = gets.chomp.split(" ").map{|e|e.to_i}

def doit(a)
	for i in a do
		if i%2 == 0 then
			if i%3 != 0 && i%5 != 0 then return "DENIED" end
		end		
	end
	return "APPROVED"
end

print(doit(a))

Measured memory_bytes: 1788
const zeroPadding = (num, length) => {
  return ('0000000000' + num).slice(-length);
};

const Main = (input) => {
  // 入力値の整形
  input = input.split('\n');
  input.shift();
  const cities = input
    .map((line, index) => {
      // 空行は処理をスキップ
      if (line.length === 0) return null;
      const lineArray = line.split(' ');
      const ken = lineArray[0];
      const year = lineArray[1];
      return {
        index: index,
        ken: ken,
        year: year,
      };
    })
    .filter((data) => {
      // null値の除外
      return data;
    });

  const kenArray = [];
  cities
    .concat()
    .sort((a, b) => {
      return a.year - b.year;
    })
    .forEach((city) => {
      if (!kenArray[city.ken]) kenArray[city.ken] = [];
      kenArray[city.ken].push(city);
      cities[city.index].cityId =
        zeroPadding(city.ken, 6) + zeroPadding(kenArray[city.ken].length, 6);
    });

  cities.forEach((city) => {
    console.log(city.cityId);
  });
};

//* この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

int n;
vector<vector<int> > A;
vector<vector<int> > T;
int timer = 0;

void dfs(int cur){
    timer += 1;
    T[cur][0] = timer;

    for(int dst = 0; dst < n; ++dst){
        if(A[cur][dst] == 1 && T[dst][0] == -1){
            dfs(dst);
        }
    }
    timer += 1;
    T[cur][1] = timer;
}

int main(){
    cin >> n;
    A = vector<vector<int> >(n, vector<int>(n, 0));
    T = vector<vector<int> >(n, vector<int>(2, -1));
    for(int i=0; i<n; ++i){
        int k;
        cin >> k;
        k -= 1;
        int u;
        cin >> u;
        for(int j=0; j<u; ++j){
            int v;
            cin >> v;
            v -= 1;
            A[k][v] = 1;
        }
    }
    for(int i=0; i<n; ++i){
        if(T[i][0] == -1){
          dfs(i);
        }
    }
    for(int i=0; i<n; ++i){
        cout << i+1 << " " << T[i][0] << " " << T[i][1] << endl;
    }
}

Measured memory_bytes: 3144
#include <stdio.h>
int main(){
  int a,b,d,r;
  double f;
  scanf("%d %d",&a,&b);
  d=a/b;
  r=a%b;
  f=(double)a/(double)b;
  printf("%d %d %f\n",d,r,f);
  return 0;
}

Measured memory_bytes: 632
#include <cstdio>
#include <iostream>
#define ll long long
using namespace std;
const int N=1e6+10;
ll sum[N][2],num[N];
char str[N];
int n;
int main ()
{
	scanf("%d%s",&n,str+1);
	for(int i=1;i<=n;i++)
		sum[i][0]=sum[i-1][0]+(str[i]=='M'),sum[i][1]=sum[i-1][1]+(str[i]=='C'),num[i]=num[i-1]+(str[i]=='C')*sum[i][0];
	int q,m; scanf("%d",&q);
	while(q--)
	{
		scanf("%d",&m);
		ll ans=0;
		for(int i=1;i<=n;i++)
		if(str[i]=='D')
		{
			int r=min(n,i+m-1);
			ans+=num[r]-num[i]-sum[i][0]*(sum[r][1]-sum[i][1]);
		}
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 24704
n=gets.chomp
a = n.split("").map { |e| e.to_i  }
n=n.to_i

def s(a)
  var=0
  a.length.times do |i|
    var += a[i]
  end

  return var
end


b=0
b=s(a)


if n%b !=0
  puts "No"
else
  puts "Yes"
end

Measured memory_bytes: 1788
n = int(input())
h = list(map(int, input().split()))


ans = "Yes"
for i in range(1, n):
	if h[i-1] > h[i]:
		if h[i-1] <= h[i]+1:
			h[i] = h[i]+1
		else:
			ans = "No"
			break
	
		
print(ans)

Measured memory_bytes: 14396
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<char>> A(h * 2, vector<char>(w * 2));
    for(int i = 0; i < 2 * h; i += 2) {
        rep(j, w) {
            cin >> A[i][j];
            A[i + 1][j] = A[i][j];
        }

    } 
    rep(i, 2 * h) {
        rep(j, w) cout << A[i][j];
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (long long i = 0; i < n; i++)
#define RREP(i, n) for (long long i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (long long i = start; i < end; i++)
#define RFOR(i, start, end) for (long long i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
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;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}

// 配列を圧縮する。first に値、second に個数
template <class T> map<T, long long> run_length(vector<T> &v) {
    map<T, long long> ans;
    for (auto &&i : v) {
        if (ans.count(i))
            ans[i]++;
        else
            ans[i] = 1;
    }
    return ans;
}

template <class T> T nCr(T n, T r) {
    if (r > n)
        return 0;
    if (r * 2 > n)
        r = n - r;
    if (r == 0)
        return 1;
    T ans = n;
    for (T i = 2; i <= r; i++) {
        ans *= (T)(n - i + 1);
        ans /= (T)i;
    }
    return ans;
}

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

    int N;
    cin >> N;
    vector<ll> v(N);
    for (auto &&i : v) {
        cin >> i;
    }
    vector<ll> vv(N);
    partial_sum(ALL(v), vv.begin());

    vv.emplace_back(0);
    auto run = run_length(vv);
    ll ans   = 0;
    for (auto &&i : run) {
        ll x = i.second;
        if (1 < x) {
            ans += nCr<ll>(x, 2);
        }
    }
    print(ans);

    return 0;
}

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

using namespace std;

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

#define INF 2<<29
#define F first
#define S second

int main(){
  int n,a,b;
  scanf("%d %d %d",&n,&a,&b);
  printf("%d\n",min(n*a,b));
  
  return (0);
}


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

int bubbleSort(int A[], int N) {
  int sw = 0;
  bool flag = 1;
  for (int i = 0; flag; i++) {
    flag = 0;
    for (int j = N -1; j >= i + 1; j--) {
      if (A[j] < A[j - 1]) {
        swap(A[j], A[j -1]);
        flag = 1;
        sw++;
      }
    }
  }
  return sw;
}

int main() {
  int A[100], N, sw;
  cin >> N;
  for ( int i = 0; i < N; i++) cin >> A[i];

  sw = bubbleSort(A, N);

  for (int i = 0; i < N; i++) {
    if (i) cout << " ";
    cout << A[i];
  }
  cout << endl;
  cout << sw << endl;
  
  return 0;
}


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

int main() {
  int n;cin>>n;
  vector<int> a(n), b(n);
  for(int i=0;i<n;++i) {
    cin>>a[i];
  }
  
  int ans = 0;
  for(int i=0;i<n;++i){
    if(a[a[i]-1]==i+1) ++ans;
  }
  cout<<ans/2<<endl;
  return 0;
}

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

using namespace std;

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

	vector<long long> vals(n + 1);

	for (int i = 0; i < n; i++) {
		cin >> vals[i + 1];
	}

	vector<int> adj[n + 1];

	for (int i = 0; i < m; i++) {
		int p, q;
		cin >> p >> q;
		adj[p].push_back(q);
		adj[q].push_back(p);
	}

	int ans = 0;

	for (int i = 1; i <= n; i++) {
		if (!adj[i].size()) {
			ans++;
			continue;	
		}
		bool ok = 1;
		for (int j = 0; j < adj[i].size(); j++) {
			if (vals[adj[i][j]] >= vals[i]) {
				ok = 0;
				break;
			}
		}
		if (ok) ans++;
	}

	cout << ans;
}


Measured memory_bytes: 9040
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>
#include <cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;

inline bool check(ll x, ll y, ll xMax, ll yMax) { return x >= 0 && y >= 0 && xMax > x && yMax > y; }
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string tostring(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }
template<class T> inline T mypow(T x, ll n) { T res = 1; while (n > 0) { if (n & 1)res = res * x;	x = x * x;	n >>= 1; }return res; }
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

#define For(i,a,b)	for(ll (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define rFor(i,a,b)	for(ll (i) = (a-1);i >= (b);(i)--)
#define rrep(i,n)	rFor(i,n,0)
#define each(i,n)	for(auto &i : n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))
#define tostr(a)	tostring(a)
#define dump(val) 	cerr << #val " = " << val << endl;
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

const ll dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, -1, 0, 1, -1, 1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = 1e17 + 9;

#define int ll
#define double ld

signed main() {
	int a, b;
	cin >> a >> b;
	if (a <= 0 && 0 <= b) {
		cout << "Zero" << endl;
		return 0;
	}
	if (b < 0) {
		int t = (b - a) + 1;
		if (t % 2) {
			cout << "Negative" << endl;
			return 0;
		}
	}
	cout << "Positive" << endl;

	return 0;
}



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

#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    if(n==3||n==5||n==7){
        cout <<"YES"<<endl;
    }
    else{
        cout <<"NO"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
typedef long long ll;
inline ll gcd(ll a, ll b) {
  return b != 0 ? gcd(b, a % b) : a;
}
inline ll read(){
  ll ans=0,c=getchar();
  while(c<'0'||c>'9'){c=getchar();}
  while(c>='0'&&c<='9'){ans=ans*10+(c-'0'); c=getchar();}
  return ans;
}
int main(){
    int n;
    ll ans=1,x;
    scanf("%d",&n);
    while(n--){
      x=read();
      ans=ans/gcd(ans,x)*x;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 128
import Control.Applicative

f :: [Int] -> [Int]
f [x] = []
f (x:y:zs) = (y - x) : f (y:zs)

g :: Int -> [Int] -> Int
g _ [] = 0
g n (x:xs) = if x <= n then (n - x) + g n xs
                     else g n xs

main = do
  t <- (\[x,y] -> y) . map read . words <$> getLine :: IO Int
  times <- map read . words <$> getLine :: IO [Int]
  putStrLn $ show $ (length times) * t - (g t . f) times

Measured memory_bytes: 152956
#include<bits/stdc++.h>
#define REP(i,n) for(long long i=0;i<n;++i)
#define FOR(i,a,b) for(long long i=a;i<b;++i)
using namespace std;
const int MAX=1e5;
const int INF=INT_MAX;

struct Edge{
    int t,w;
    Edge(int t,int w): t(t),w(w) {}
};

vector< Edge > G[MAX];
int n,d[MAX];

bool vis[MAX];
int cnt;

void bfs(int s){
    fill(d,d+MAX,INF);
    queue< int > q;
    q.push(s);
    d[s]=0;
    int u;
    while(!q.empty()){
        u=q.front();q.pop();
        REP(i,G[u].size()){
            Edge e=G[u][i];
            if(d[e.t]==INF){
                d[e.t]=d[u]+e.w;
                q.push(e.t);
            }
        }
    }
}

void solve(){
    bfs(0);
    int maxv=0;
    int tgt=0;
    REP(i,n){
        if(d[i]==INF) continue;
        if(maxv<d[i]){
            maxv=d[i];
            tgt=i;
        }
    }

    bfs(tgt);
    maxv=0;
    REP(i,n){
        if(d[i]==INF) continue;
        maxv=max(maxv,d[i]);
    }

    printf("%d\n",maxv);
}

int main(){
    int s,t,w;
    scanf("%d",&n);

    REP(i,n-1){
        scanf("%d%d%d",&s,&t,&w);

        G[s].push_back(Edge(t,w));
        G[t].push_back(Edge(s,w));
    }
    solve();
    return 0;
}




Measured memory_bytes: 10036
import java.util.*;
import java.lang.*;

public class Main {
  
    public int dp(int[] a,int[] b,int[] c,int[] dp1 ,int[] dp2,int[] dp3,int n,int index,int type) {
    	if(index==n-1) {
    		dp1[n-1]=a[n-1];
    		dp2[n-1]=b[n-1];
    		dp3[n-1]=c[n-1];
    	}
    	else {
    		if(dp1[index]==-1)
    		dp1[index]=this.dp(a, b, c, dp1,dp2,dp3,n,index+1,0)+a[index];
    	if(dp2[index]==-1)
    		dp2[index]=this.dp(a, b, c, dp1,dp2,dp3,n,index+1,1)+b[index];
    	if(dp3[index]==-1)
    	dp3[index]=this.dp(a, b, c, dp1,dp2,dp3,n,index+1,2)+c[index];
    	}
    	if(type==0) {
    		return Math.max(dp2[index], dp3[index]);
    	}
    	if(type==1) {
    		return Math.max(dp1[index],dp3[index]);
    	}
    	else {
    		return Math.max(dp2[index], dp1[index]);
    	}
    	
    }
	public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[] a=new int[n];
        int[] b=new int[n];
        int[] c=new int[n];
        for(int i=0;i<n;i++) {
        	a[i]=sc.nextInt();
        	b[i]=sc.nextInt();
        	c[i]=sc.nextInt();
        }
        int[] dp1=new int[n];        int[] dp3=new int[n];
        int[] dp2=new int[n];

        for(int i=0;i<n;i++) {
        	dp1[i]=-1;
        	dp2[i]=-1;
        	dp3[i]=-1;
        }
        Main mm=new Main();
        mm.dp(a, b, c, dp1, dp2, dp3, n, 0,0);
        int temp=Math.max(dp1[0], dp2[0]);
        temp=Math.max(temp, dp3[0]);
        System.out.println(temp);
    }
}



Measured memory_bytes: 110616
#include<stdio.h>

void fib();

void risu();

void kannon();

int main(){

// 	fib();
// 	risu();
	kannon();

	return 0;
}

void kannon(){

	int i,j;

	int n[100];

	int count=0;

	for(i=0;i<100;i++){
		scanf("%d",&n[i]);
		if(n[i]==0)	break;
		count++;
	}

	for(j=0;j<count;j++){

		int f[n[j]+1];

		f[0]=1;
		f[1]=1;
		f[2]=2;

		for(i=3;i<=n[j];i++){
			f[i]=f[i-3]+f[i-2]+f[i-1];
		}
		
		int d=f[n[j]]/10;
		int y=d/365+1;
	

		printf("%d\n",y);

	}

}

void risu(){
	int i,j,n;
	scanf("%d",&n);

	int rs[n];	// risu high
	int rr[n];	// risu rank

	int max=0;

	int flag=0;	// 自分より大きいのがあるかないか、あれば１
/*
	typedef struct{
		int h;	// 高さ
		int r;	// 順位
	}rs[n];
*/
	for(i=0;i<n;i++){
		scanf("%d",&rs[i]);
		rr[i]=1;
	}

	for(i=1;i<n;i++){
		for(j=i-1;j>=0;j--){
			if(rs[i]>rs[j]){
				
			}

		
		}

// 		if(rr[i]>max)	max=rr[i];

	}

	printf("%d\n",max);




}


void fib(){
	int i,n;
	scanf("%d",&n);
	
	int f[n];

	f[0]=0;
	f[1]=1;

	for(i=2;i<=n;i++){
		f[i]=f[i-1]+f[i-2];
	}

	printf("%d\n",f[n]);
}

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define F first
#define S second
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
const int MOD = 1e9 + 7; 
const int N = 1e5+10; 
int main(void) 
{
	
	#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
	#endif


	int h, a; 
	scanf("%d %d", &h, &a); 
	int ans = 0; 
	ans += h/a; 
	if (h%a) ans++; 
	printf("%d\n", ans); 
	
	return false;   


}


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

namespace CSharpSample01
{

    
    class Program
    {

        
        static long Solve(int N, int K, int[] x)
        {
            long min = 10000000009;
            long time = 0;

            int left = 0;
            int right = K - 1;

           
            while(right < N)
            {
                time = 0;

                if(x[right] <= 0)
                {
                    time += Math.Abs(x[left]);
                }
                else if(x[left] >= 0)
                {
                    time += Math.Abs(x[right]);
                }
                else
                {
                    if(Math.Abs(x[left]) < Math.Abs(x[right]))
                    {
                        time += Math.Abs(x[left]) + Math.Abs(x[right] - x[left]);
                    }
                    else
                    {
                        time += Math.Abs(x[right]) + Math.Abs(x[left] - x[right]);
                    }
                }

                if (time < min) min = time;


                left++;
                right++;
            }

            return min;
        }



        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int N = int.Parse(input[0]);
            int K = int.Parse(input[1]);
            int[] x = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

            Console.WriteLine(Solve(N, K, x));

        }
    }
}

Measured memory_bytes: 21472
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <deque>
#include <numeric>
#include <sstream>
#include <iomanip>
#define ALL(X) X.begin(), X.end()
using lint = long long;
template <typename T>
void print_container(std::vector<T> vec)
{
    for (auto iter = vec.begin(); iter != vec.end(); ++iter)
    {
        std::cout << *iter << " ";
    }
    std::cout << std::endl;
}

int main()
{
    lint n;
    scanf("%lld", &n);
    std::vector<lint> a(n);

    for (int i = 0; i < n; ++i)
    {
        scanf("%lld", &a[i]);
    }

    lint ans = 0;

    lint rem = 0;

    for (int i = 0; i < n; ++i)
    {
        if (a[i] == 0)
        {
            rem = 0;
            continue;
        }
        ans += ((a[i] + rem) / 2);
        rem = (a[i] + rem) % 2;
    }

    std::cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 1024
use std::io;


/// https://beta.atcoder.jp/contests/abc084/tasks/abc084_c
/// Special Trains
fn main() {
    let n = read_one::<usize>();
    let mut csf = Vec::new();
    for _ in 1..n {
        let i = read::<usize>();
        csf.push((i[0], i[1], i[2]));
    }

    for i in 0..n {
        let mut t = 0;
        for j in i..n - 1 {
            if t < csf[j].1 { t = csf[j].1; }
            else if t % csf[j].2 != 0 {
                t += csf[j].2 - t % csf[j].2;
            }
            t += csf[j].0;
        }
        println!("{}", t);
    }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
int main()
{
	long long x,y,ans,sum=0;
	cin>>x>>y;
	ans=((long long)(y/x));
	while(ans>=1)
	{
		ans/=2;
		sum++;
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define M (200010)
#define ll long long
int n,a[M],b[M];

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]),b[i]=a[i];
	sort(b+1,b+1+n);
	for (int i=1;i<=n;i++) 
		if (a[i]!=b[n]) printf("%d\n",b[n]);
		else printf("%d\n",b[n-1]);	
}


Measured memory_bytes: 3200
#include <iostream>
#include <vector>

using namespace std;

const int MAXN = 2005;
vector<int> g[MAXN];

int dfs(int v, int p, int d) {
    int res = (d < 0);
    for(size_t i = 0; i < g[v].size(); i++)
        if(g[v][i] != p)
            res += dfs(g[v][i], v, d - 1);
    return res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n - 1; i++) {
        int v, u;
        cin >> v >> u;
        v--;
        u--;
        g[v].push_back(u);
        g[u].push_back(v);
    }
    int ans = MAXN;
    for(int i = 0; i < n; i++)
        ans = min(ans, dfs(i, -1, k / 2));
    for(int i = 0; i < n; i++)
        for(size_t j = 0; j < g[i].size(); j++)
            ans = min(ans, dfs(g[i][j], i, (k - 1) / 2) +
                      dfs(i, g[i][j], (k - 1) / 2));
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

int main()
{
    int n;
    while(cin >> n && n)
    {
        int ans = 0, t;
        n /= 4;
        REP(n){cin >> t; ans += t;}
        cout << ans << endl;

    }

    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


long solve(int n,vector<long> &a,vector<long> &b){
    long ret=0;
    while(1){
        bool f=false;
        for (int i = 0; i < n; i++) {
            if(a[i]!=b[i]) break;
            if(i==n-1) return ret;
        }
        for (int i = 0; i < n; i++) {
            long t = b[i%n] + b[(i+2)%n];
            if(b[(i+1)%n] > t){
                long k = (b[(i+1)%n] - a[(i+1)%n])/t;
                ret += k;
                b[(i+1)%n] -= t*k;
                if(k) f=true;
            }
        }
        if(!f) return -1;
    }
}


int main(){
    int n;cin >> n;
    vector<long> a(n),b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
        if(b[i]<a[i]){
            puts("-1");
            return 0;
        }
    }
    cout << solve(n,a,b) << endl;
    return 0;
}


Measured memory_bytes: 3328
#! /usr/bin/env python
# coding: UTF-8

def gcd(m, n):
    if n == 0:
        return m
    else:
        return gcd(n, m%n)

def main():
    n = int(input())

    print(int(n*2/gcd(n,2)))

if __name__ == '__main__':
    main()

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

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

int main(){
    int h,w;
    int n;
    cin >> h >> w;
    cin >> n;

    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int table[101][101] = {0};
    int cnt = 0;
    rep(i,h){
        if(i % 2 == 0){
            rep(j,w){
                if(a[cnt]>0){
                    a[cnt]--;
                    table[i][j] = cnt+1;
                    if(a[cnt]==0)cnt++;
                }
            }
        }else{
            for(int j=w-1;j >= 0;j--){
                if(a[cnt]>0){
                    a[cnt]--;
                    table[i][j] = cnt+1;
                    if(a[cnt] == 0)cnt++;
                }
            }
        }
    }
    
    rep(i,h){
        rep(j,w){
            cout << table[i][j] <<" ";
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 384