akhauriyash/Code-Regression huggingface dataset:
# AOJ ITP1_6_C

def numinput():
    # たとえば1 2 3 4という出力に対して[1, 2, 3, 4]を生成する。
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a

def main():
    data = []
    for i in range(4):
        floor = []
        for j in range(3):
            list = []
            for k in range(10):
                list.append(0)
            floor.append(list)
        data.append(floor)
    # これでdata[0], data[1], data[2], data[3]が各フロアを意味する。
    # 階数が各々0, 1, 2だけど出力と入力が1ずつズレてる。
    n = int(input())
    for i in range(n):
        info = numinput()
        # info[0]が1, 2, 3, 4で棟の数(1引く)
        # info[1]が1, 2, 3で階の数(1引く)
        # info[2]が1, 2, ..., 10で部屋の数(1引く)
        # info[3]が整数で入るとか出るとか。
        data[info[0] - 1][info[1] - 1][info[2] - 1] += info[3]

    # 出力は注意を要する。0, 1, 2, 3棟の順に0階、・・。
    for i in range(4):
        for j in range(3):
            _str_ = ""
            for k in range(10):
                _str_ += " " + str(data[i][j][k])
            print(_str_)
        if i < 3: print("####################")

if __name__ == "__main__":
    main()


Measured memory_bytes: 5608
w, h, n = [int(i) for i in input().split()]
xl = 0
xr = w
yt = h
yb = 0
for ni in range(n):
  x, y, a =[int(i) for i in input().split()]
  if a == 1:
    xl = max(x,xl)
  elif a == 2:
    xr = min(x,xr)
  elif a == 3:
    yb = max(y,yb)
  elif a == 4:
    yt = min(y,yt)
if xl > xr or yb > yt:
  print(0)
else:
  print((xr-xl)*(yt-yb))

Measured memory_bytes: 3064
#include<queue>
#include<iostream>

using namespace std;

typedef	pair<int,int>	pii;

int main()
{
	for(int n,m;cin>>n>>m,n;){
		static bool adj[500][500];
		for(int i=0;i<n;i++)for(int j=0;j<n;j++)adj[i][j]=false;
		for(int i=0;i<m;i++){
			int a,b;	cin>>a>>b;
			adj[a-1][b-1]=adj[b-1][a-1]=true;
		}

		bool invited[500]={};
		queue<pii> qu;	qu.push(make_pair(0,0));
		while(!qu.empty()){
			pii a=qu.front();	qu.pop();
			int u=a.first,dep=a.second;
			if(invited[u])	continue;
			invited[u]=true;
			if(dep<2){
				for(int v=0;v<n;v++){
					if(!invited[v] && adj[u][v])
						qu.push(make_pair(v,dep+1));
				}
			}
		}

		int cnt=0;
		for(int i=1;i<n;i++)	if(invited[i])	cnt++;
		cout<<cnt<<endl;
	}

	return 0;
}

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

int main() {
  int n;
  string s;
  cin >> n >>s;
  int ans = 0;
  rep(i,n-2){
    if (s.substr(i,3) == "ABC") ++ans;
  }
  cout << ans << endl;
return 0;
}

Measured memory_bytes: 256
# ABC129 D
H, W = map(int, input().split(' '))

H += 2
W += 2
L = [[0 for _ in range(W)] for _ in range(H)]
R = [[0 for _ in range(W)] for _ in range(H)]
U = [[0 for _ in range(W)] for _ in range(H)]
D = [[0 for _ in range(W)] for _ in range(H)]

grid = []
grid.append(list(('#'*W).strip()))
for i in range(H-2):
    grid.append(list(('#'+input()+'#').strip()))
grid.append(list(('#'*W).strip()))

for i in range(1, H-1):
    for j in range(1, W-1):
        if grid[i][j] == '.':
            L[i][j] = L[i][j-1] + 1
        if grid[i][W - j-1]  == '.':
            R[i][W - j-1] = R[i][W - j-1 + 1] + 1

for j in range(1, W-1):
    for i in range(1, H-1):
        if grid[i][j] == '.':
            U[i][j] = U[i-1][j] + 1
        if grid[H - i-1][j]  == '.':
            D[H - i-1][j] = D[H - i-1 + 1][j] + 1

total = [[0 for _ in range(W)] for _ in range(H)]
for i in range(1, H-1):
    for j in range(1,W-1):
        total[i][j] = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3

ans = 0
for i in range(1,H-1):
    ans = max(ans, max(total[i]))
print (ans)

Measured memory_bytes: 347656
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>

#define rep_ui(k,n)      for(ui  i = (k); i < (n); ++i)
#define rep_si(k,n)      for(int i = (k); i < (n); ++i)
#define rep_ul(k,n)      for(ul  i = (k); i < (n); ++i)
#define rep_sl(k,n)      for(ll  i = (k); i < (n); ++i)
#define rep_ui_down(k,n) for(ui  i = (k); i > (n); --i)
#define rep_si_down(k,n) for(int i = (k); i > (n); --i)
#define rep_ul_down(k,n) for(ul  i = (k); i > (n); --i)
#define rep_sl_down(k,n) for(ll  i = (k); i > (n); --i)

#define rep_uj(k,n)      for(ui  j = (k); j < (n); ++j)
#define rep_sj(k,n)      for(int j = (k); j < (n); ++j)
#define rep_uj_down(k,n) for(ui  j = (k); j > (n); --j)
#define rep_sj_down(k,n) for(int j = (k); j > (n); --j)

#define rep(k,n)         rep_ui(k,n)

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

template<class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vc)
{
  boost::for_each(vc, [&os, &vc](T value) {
    os << value;
    if (value != vc.back())
      os << ' ';
    });
  return os;
}

template<class T1, class T2>
inline
std::ostream&
operator<<(std::ostream& os, const std::pair<T1, T2>& p)
{
  return os << p.first << ' ' << p.second;
}

void solve(void)
{
  ui N{}; std::cin >> N;

  typedef std::vector<ull> Vector;
  Vector A(N + 1);
  Vector B(N);
  rep(0, A.size()) std::cin >> A[i];
  rep(0, B.size()) std::cin >> B[i];

  ull ans{ 0 };
  ui half = N / 2;
  rep(0, half)
  {
    ans += std::min(A[i], B[i]);
    if (A[i] >= B[i])
    {
      A[i] = A[i] - B[i];
      B[i] = 0;
    }
    else
    {
      B[i] = B[i] - A[i];
      A[i] = 0;
      ans += std::min(A[i + 1], B[i]);
      if (A[i + 1] >= B[i])
      {
        A[i + 1] = A[i + 1] - B[i];
        B[i] = 0;
      }
      else
      {
        B[i] = B[i] - A[i + 1];
        A[i + 1] = 0;
      }
    }

    ans += std::min(A[N - i], B[N - i - 1]);
    if (A[N - i] >= B[N - i - 1])
    {
      A[N - i] = A[N - i] - B[N - i - 1];
      B[N - i - 1] = 0;
    }
    else
    {
      B[N - i - 1] = B[N - i - 1] - A[N - i];
      A[N - i] = 0;
      ans += std::min(A[N - i - 1], B[N - i - 1]);
      if (A[N - i - 1] >= B[N - i - 1])
      {
        A[N - i - 1] = A[N - i - 1] - B[N - i - 1];
        B[N - i - 1] = 0;
      }
      else
      {
        B[N - i - 1] = B[N - i - 1] - A[N - i - 1];
        A[N - i - 1] = 0;
      }
    }
  }

  if (half * 2 == N - 1)
  {
    ans += std::min(A[half], B[half]);
    if (A[half] >= B[half])
    {
      A[half] = A[half] - B[half];
      B[half] = 0;
    }
    else
    {
      B[half] = B[half] - A[half];
      A[half] = 0;
      ans += std::min(A[half + 1], B[half]);
      if (A[half + 1] >= B[half])
      {
        A[half + 1] = A[half + 1] - B[half];
        B[half] = 0;
      }
      else
      {
        B[half] = B[half] - A[half + 1];
        A[half + 1] = 0;
      }
    }
  }

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

  return;
}

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

  solve();

  return 0;
}


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

using namespace std;

int main() {
  int h, w;
  cin >> h >> w;
  string* a = new string[h];
  for(int i=0; i<h; i++) {
    cin >> a[i];
  }
  cout << string(w+2, '#') << endl;
  for(int i=0; i<h; i++) {
    cout << "#" << a[i] << "#" << endl;
  }
  cout << string(w+2, '#') << endl;
}


Measured memory_bytes: 512
import sys
import numpy as np

n = int(input())
b = np.array(list(map(int, input().split())))

ans = []
for i in range(n, 0, -1):
    cp = np.arange(1, i + 1)
    diff = b - cp
    if np.where(diff == 0)[0].shape[0] == 0:
        print(-1)
        sys.exit()
    else:
        rem = (np.where(diff == 0)[0]).max()
        ans.append(b[rem])
        b = np.delete(b, rem, axis=0)

print(*ans[::-1], sep="\n")

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

int main() {
  long long a,b,c; cin >> a >> b >> c;
  if(a + b > c){
    cout << "No";
    return 0;
  }
  if(a*a + b*b + c*c - 2 * (a*b + a*c + b*c) > 0){
    cout << "Yes";
  }else{
    cout << "No";
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int H,W;
char s[51][51];
bool masu[51][51];
void dfs(){
    for(int i = 0; i < 51; i++){
        for(int j = 0; j < 51; j++){
            if(s[i][j] == '#') masu[i][j] = false;
            else masu[i][j] = true;
        }
    }

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(s[i][j] == '#' && !masu[i][j]){
                for(int k = 0; k < 4; k++){
                    int ny = i + dy[k];
                    int nx = j + dx[k];
                    if(0 <= ny && ny < H && 0 <= nx && nx < W){
                        if(s[ny][nx] == '.') continue;
                        else if(s[ny][nx] == '#'){
                            masu[ny][nx] = true;
                            masu[i][j] = true;
                        }
                    }
                }
            }
        }
    }
}

bool check(){
    for(int i = 0; i < 50; i++){
        for(int j = 0; j < 50; j++){
            if(!masu[i][j]) return false;
        }
    }
    return true;
}

int main(){
    cin >> H >> W;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> s[i][j];
        }
    }
    dfs();
    bool ans = check();
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

ll dp[2020];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  ll s;
  cin >> s;

  dp[0] = 1;
  rep(i, s) {
    FOR(j, i + 3, s + 1) {
      dp[j] = (dp[j] + dp[i]) % mod;
    }
  }
  cout << dp[s] << '\n';

  
  return 0;
}

Measured memory_bytes: 3600
/* 
chirag11032000
Chirag Thakur
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;

template < typename T > using OrderedSet = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

const db PI = acos(-1);
const ll LINF = LLONG_MAX;
const int INF = INT_MAX, MOD = 1e9 + 7, N = 1e5 + 10;

int n;
vector < int > b;

void testCase();

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	testCase();
	cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
	return 0;
}

void testCase() {
	cin >> n;
	b.resize(n + 1);
	for (int i = 1; i <= n; ++i) {
		cin >> b[i];
	}
	vector < int > seq;
	for (int turn = n; turn >= 1; --turn) {
		int ind = -1;
		for (int pos = turn; pos >= 1; --pos) {
			if (b[pos] == pos) {
				ind = pos;
				break;
			}
		}
		if (ind == -1) {
			cout << "-1\n";
			return;
		} else {
			seq.eb(b[ind]);
			b.erase(b.begin() + ind);
		}
	}
	reverse(all(seq));
	for (auto &el: seq) {
		cout << el << "\n";
	}
}

Measured memory_bytes: 256
Scanf.scanf "%d" (fun q ->
    for i = 1 to q do
        Scanf.scanf " %d %d" (fun a b ->
            if a * b = 1 then Printf.printf "0\n" else
                let f = int_of_float (sqrt (float (a * b))) in
                let f = if f * f = a * b then f - 1 else f in
                let ax = if a <= f then f - 1 else f in
                let bx = if b <= f then f - 1 else f in
                let ans = if (a * b - 1) / f = f then ax + bx - 1 else ax + bx in
                Printf.printf "%d\n" ans
        )
    done
)

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


// GCD, LCM
// https://youtu.be/8lm8o8L9Bmw?t=2285
// https://youtu.be/XI8exXVxZ-Q?t=3595
// https://youtu.be/F2p_e6iKxnk?t=843
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


void solve(long long K){
    ll ans =0;
    for(int i=1;i<=K;i++){
        for(int j=1;j<=K;j++){
            ll abgcd = gcd(i,j);
            for(int k=1;k<=K;k++){
                ans += gcd(abgcd,k);
            }
        }
    }
    cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long K;
    scanf("%lld",&K);
    solve(K);
    return 0;
}


Measured memory_bytes: 3688
#include<stdio.h>

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)

using namespace std;


int main(){
	int n,ans;
	int m[]={500,100,50,10,5,1};
	for(;;){
		scanf("%d",&n);
		if(n==0)break;
		ans=0;
		n=1000-n;
		rep(i,6)while(m[i]<=n){
			ans++;
			n-=m[i];
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1028
import sys
read = sys.stdin.buffer.read
input = sys.stdin.readline
input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')

#2320
#import numpy as np

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())



def main():
	n,m=MI()
	e=[]
	for _ in range(m):
		a,b=MI()
		a-=1
		b-=1
		e.append([a,b])
	#print(e)

	UF=UnionFind(n)
	ans=[]
	tmp=n*(n-1)//2

	for li in reversed(e):
		ans.append(tmp)
		a=li[0]
		b=li[1]
		if UF.same(a,b):
			continue
		aa=UF.parents[UF.find(a)]
		bb=UF.parents[UF.find(b)]
		#print(a,b,aa,bb)
		tmp-=aa*bb
		UF.union(a,b)
	print("\n".join(str(i) for i in ans[::-1]))




if __name__ == "__main__":
	main()

Measured memory_bytes: 117212
#include<bits/stdc++.h>
using namespace std;
const int mod=10000;
string A,B,S;
int M;

int memo[501][10][3][2][500];

int calc(int keta=0,int mae=0,int hoko=0,int jiyuu=0,int amari=0){
    if(keta==S.size()){
        return amari==0;
    }
    if(~memo[keta][mae][hoko][jiyuu][amari])
        return memo[keta][mae][hoko][jiyuu][amari];

    int ret=0;
    for(int i=0;i<10;i++){
        if(jiyuu==0&&S[keta]<i+'0')break;
        if((hoko||mae)&&mae==i)continue;
        int njiyuu=jiyuu|(i+'0'!=S[keta]);
        int namari=(amari*10+i)%M;
        if(hoko==0){
            if(mae)ret=(ret+calc(keta+1,i,mae<i?2:1,njiyuu,namari))%mod;
            else ret=(ret+calc(keta+1,i,0,njiyuu,namari))%mod;
        }
        else if(hoko==1&&mae<i){
            ret=(ret+calc(keta+1,i,2,njiyuu,namari))%mod;
        }
        else if(hoko==2&&mae>i){
            ret=(ret+calc(keta+1,i,1,njiyuu,namari))%mod;
        }
    }
    return memo[keta][mae][hoko][jiyuu][amari]=ret;
}

int main(){
    cin>>A>>B>>M;
    A[A.size()-1]--;
    for(int i=A.size()-1;i>0;i--){
        if(A[i]>='0')break;
        A[i]='9';
        A[i-1]--;
    }

    S=B;memset(memo,-1,sizeof(memo));
    int vb=calc();

    S=A;memset(memo,-1,sizeof(memo));
    int va=calc();

    cout<<(vb-va+mod)%mod<<endl;

    return 0;
}

Measured memory_bytes: 59992
import java.util.*;

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

    for (int i = 0; i < n; i++) {
      m[i] = sc.nextInt();
      x -= m[i];
      if (m[i] < minM) {
        minM = m[i];
      }
    }

    answer += (x / minM);

    System.out.println(answer);
  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  loop(i,0,n)
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>

int main(){
    int k;
    int a,b;
    cin>>k;
    cin>>a>>b;
    int ans=0;
    for(int i=a;i<b+1;i++){
        if(i%k==0)ans=1;
    }
    if(ans==1){
        cout<<"OK"<<endl;
    }
    else{
        cout<<"NG"<<endl;
    }
}

Measured memory_bytes: 3636
// In the name of Allah 
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define ld long double
#define mp make_pair

const ll MAX = 5e2 + 10, inf = 1e9+1, mod = 95542721;

ll N, n, h, w;


int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> N;
	for (n = 1; n <= 3500; n++)
	{
		for (w = 1 ; w <= 3500; w++)
		{
			ll k = (4*n*w - N*(w+n));
			if (k <= 0) continue;
			if (N*n*w % k == 0)
				return cout << w << ' ' << n << ' ' << N*n*w / k << endl, 0;

		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PI 2.0*acos(0.0)
#define ll              long long int
#define gcd(a,b)        __gcd(a,b)
#define lcm(a,b)        ((a)*(b))/gcd(a,b)
#define MOD             1000000007
#define mx              123456789
using namespace std;
int main()
{
    int n, m, i, j, k, l;
    cin>>n;
    int a[n+2], cnt[n+2]={0};
    for(i=1; i<n; i++)
    {
       cin>>a[i];
    }
    for(i=1; i<n; i++)
    {
        cnt[a[i]]++;
    }
    for(i=1; i<=n; i++)
    {
        cout<<cnt[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 5184
#include<stdio.h>
int main(void)
{	
	int N[4000];
	long long int P[4000],A[4000],M[4000];

	int a,b,c,d;
	for(b=0;;b=0)
	{
		scanf("%d",&c);
		if(c==0)
			break;
		for(a=0;a<c;a++)
		{
			scanf("%d %lld %lld",&N[a],&P[a],&A[a]);
			M[a]=P[a]*A[a];
			for(d=0;d<a;d++)
				if(N[a]==N[d])
				{
					M[a]+=M[d];
					M[d]=0;
				}
		}
		for(a=0;a<c;a++)
			if(M[a]>=1000000 )
			{
				printf("%d\n",N[a]);
				b++;
			}
		if(b==0)
			printf("NA\n");
	}
	return 0;
}

Measured memory_bytes: 656
package main

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

func main() {
	var n, c int
	fmt.Scan(&n, &c)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	ds := make([][]int, c)
	for i := range ds {
		ds[i] = make([]int, c)
		for j := range ds[i] {
			sc.Scan()
			ds[i][j], _ = strconv.Atoi(sc.Text())
		}
	}
	cs := make([][]int, n)
	for i := range cs {
		cs[i] = make([]int, n)
		for j := range cs[i] {
			sc.Scan()
			cs[i][j], _ = strconv.Atoi(sc.Text())
			cs[i][j]--
		}
	}
	d1 := make([]int, c)
	d2 := make([]int, c)
	d3 := make([]int, c)
	for cl := 0; cl < c; cl++ {
		var s1, s2, s3 int
		for i := 0; i < n; i++ {
			for j := 0; j < n; j++ {
				switch (i + j) % 3 {
				case 0:
					s1 += ds[cs[i][j]][cl]
				case 1:
					s2 += ds[cs[i][j]][cl]
				case 2:
					s3 += ds[cs[i][j]][cl]
				}
			}
		}
		d1[cl] = s1
		d2[cl] = s2
		d3[cl] = s3
	}

	mi := int(1e10)
	for c1 := 0; c1 < c; c1++ {
		for c2 := 0; c2 < c; c2++ {
			if c2 == c1 {
				continue
			}
			for c3 := 0; c3 < c; c3++ {
				if c3 == c1 || c3 == c2 {
					continue
				}
				mi = min(mi, d1[c1]+d2[c2]+d3[c3])
			}
		}
	}

	fmt.Println(mi)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 4504
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
	int a;
	cin>>a;
	switch(a){
		case 0:cout<<1<<endl;break;
		case 1:cout<<2<<endl;break;
		case 2:cout<<1<<endl;break;
		default:cout<<0<<endl;
	}
}

Measured memory_bytes: 1164
#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let (n, k) = get!(usize, usize);
    let cc: Vec<char> = get!(String).chars().collect();
    let mut v = Vec::new();
    let mut pre_zero;
    let mut pre_one;
    if cc[0] == '0' {
        pre_zero = true;
        pre_one = false;
    } else {
        pre_zero = false;
        pre_one = true;
    }
    let mut zero = 0;
    let mut one = 0;
    let mut zero_count = 0;
    for i in 0..cc.len() {
        if cc[i] == '0' {
            zero += 1;
            if !pre_zero {
                v.push((1, one));
                one = 0;
            }
            pre_zero = true;
            pre_one = false;
        } else if cc[i] == '1' {
            one += 1;
            if !pre_one {
                v.push((0, zero));
                zero = 0;
                zero_count += 1;
            }
            pre_zero = false;
            pre_one = true;
        }
    }
    if zero != 0 {
        v.push((0, zero));
        zero_count += 1;
    } else {
        v.push((1, one));
    }
    //eprintln!("cc: {:?}", cc);
    //eprintln!("v: {:?}", v);
    //eprintln!("zero_count: {}", zero_count);
    if zero_count <= k {
        println!("{}", n);
        return;
    }
    let mut max = 0;
    for i in 0..v.len() {
        let mut tmax = 0;
        let mut right;
        if v[i].0 == 0 {
            right = 2 * k + i;
        } else {
            right = 2 * k + 1 + i;
        }
        if v.len() < right {
            right = v.len();
        }
        for j in i..right {
            tmax += v[j].1;
        }
        //eprintln!("right: {}", right);
        //eprintln!("tmax: {}", tmax);
        if max < tmax {
            max = tmax;
        }
    }
    println!("{}", max);
}


Measured memory_bytes: 4352
#from collections import deque
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(M)]
path=[set() for i in range(N+1)]
for a,b in AB:
    path[a].add(b)
    path[b].add(a)
path=[list(i) for i in path]

stack=[[1,[1]]]
itta=set([1])

notBridge=set()
while stack:
    ten,totyuu=stack[-1]
    #print(stack)
    if not path[ten]:
        stack.pop()
        continue
    miti=path[ten].pop()
    if not miti in itta:
        stack.append([miti,totyuu+[miti]])
        itta.add(miti)
    elif len(totyuu)>1 and totyuu[-2]==miti:
        pass
    else:
        flag=0
        Z=totyuu+[miti]
        #totyuu+=[miti]
        for i in range(len(Z)-1):
            if miti==Z[i]:
                flag=1
            if flag:
                notBridge.add(Z[i]*100+Z[i+1] if Z[i]<Z[i+1] else Z[i]+Z[i+1]*100)
print(M-len(notBridge))


Measured memory_bytes: 38384
import sys
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
sys.setrecursionlimit(int(1e+6))
MOD = int(1e+9) + 7
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3

def main():
    S = i2s()
    N = int(S)
    if len(S) == 1:
        n = N
    elif len(S) == 2:
        n = 9
    elif len(S) == 3:
        n = N - 90
    elif len(S) == 4:
        n = 909
    elif len(S) == 5:
        n = N - 9090
    else:
        n = 90909
    print(n)

main()


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

int x, n;
bool p[128];

int main() {
    cin >> x >> n;
    for(int i = 1; i <= n; i++) {
        int a;
        cin >> a;
        p[a] = 1;
    }

    int bestDif = 2e9, ans = -1;
    for(int i = 0; i <= 101; i++)
        if(p[i] == 0 && abs(i-x) < bestDif) {
            bestDif = abs(x-i);
            ans = i;
        }
    cout << ans;
}


Measured memory_bytes: 3636
from collections import deque,defaultdict,Counter
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from bisect import bisect_left,bisect_right
from math import sqrt,gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode
import sys
sys.setrecursionlimit(10 ** 6)

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse=False):
    data.sort(key=lambda x:x[col],reverse=revese)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def mydictvaluesort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[1] )

def mydictkeysort(dictionary):
    return sorted( dictionary.items(), key=lambda x:x[0] )

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

a,b,c = MI()

s = 4*a*b
u = (c-a-b)**2

if c-a-b<=1:
    print("No")
    exit()

if s<u:
    print("Yes")
else:
    print("No")

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

#define SZ(x) (int)((x).size())
#define xx first
#define yy second
#define pii pair<int, int>

// 7 * ((10 ^ ans) - 1) / 9

void solve() {
    int k;
    cin >> k;
    if (k % 2 && k % 5) { 
        int ans = 1, num = 7;
        while (num % k) {
            num = (10 * num + 7) % k;
            ans++;
        }
        cout << ans << '\n';
    }
    else
        cout << "-1" << '\n';
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // int _; cin >> _; while (_--)
    solve();
    return 0;
}


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

const int MAX = 210000;
int Q;
long long type[MAX], a[MAX], b[MAX];

int main() {
    cin >> Q;

    long long sum = 0;
    priority_queue<long long> zen;
    priority_queue<long long, vector<long long>, greater<long long> > kou;
    long long zensum = 0;
    long long kousum = 0;
    
    for (int i = 0; i < Q; ++i) {
        cin >> type[i];
        if (type[i] == 1) {
            cin >> a[i] >> b[i];
            sum += b[i];

            if (zen.size() > kou.size()) {
                // kou に
                int t = zen.top();
                if (a[i] >= t) {
                    kou.push(a[i]); kousum += a[i];
                }
                else {
                    zen.pop(); zensum -= t;
                    zen.push(a[i]); zensum += a[i];
                    kou.push(t); kousum += t;
                }
            }
            else {
                // zen に
                if (zen.empty()) zen.push(a[i]), zensum += a[i];
                else {
                    int t = kou.top();
                    if (a[i] <= t) {
                        zen.push(a[i]); zensum += a[i];
                    }
                    else {
                        kou.pop(); kousum -= t;
                        kou.push(a[i]); kousum += a[i];
                        zen.push(t); zensum += t;
                    }
                }
            }
        }
        else {
            long long x = zen.top();
            long long res = (x * (int)zen.size() - zensum) + (kousum - x * (int)kou.size()) + sum;
            cout << x << " " << res << endl;
        }
    }
}

Measured memory_bytes: 9692
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;
template<class T>
T gcd(T x, T y) {
	return y ? gcd(y, x % y) : x;
}

template<class T>
vector<T> enum_div(T n) {
	vector<T> ret;
	for (T i = 1; i * i < n; ++i) {

		if (n % i == 0) {
			ret.push_back(i);

			if (i != 1 && i * i != n) {
				ret.push_back(n / i);
			}
		}
	}
	return ret;
}

template<class T>
map<T, int> prime_factorization(T n) {
	map<T, int> ret;

	for (long long i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}

	if (n != 1)ret[n] = 1;
	return ret;
}

template<class T>
long long C(T n, T r) {
	static map<pair<T, T>, long long> _map;
	if (n < r) return 0;

	if (n == r || r == 0) {
		_map[make_pair(n, r)] = 1ll;
	}
	else if (_map[make_pair(n, r)] == 0) {
		_map[make_pair(n, r)] = (C(n - 1, r) + C(n - 1, r - 1));
	}

	_map[make_pair(n, r)] %= MOD;
	return _map[make_pair(n, r)];
}

int main() {
	vector<int> A(3);
	cin >> A[0] >> A[1] >> A[2];
	sort(A.rbegin(), A.rend());
	
	cout << min(abs(A[0] - A[1]) + abs(A[2] - A[1]), abs(A[0] - A[2]) + abs(A[1] -  A[2])) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
using namespace std;
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; }
const long long INF = 1LL << 60;
using Graph=vector<vector<int>>;

int gcd(lint x, lint y){
  return y==0 ? x:gcd(y,x % y);
}

int digsum(int n) {
  int res = 0;
  while(n > 0) {
    res += n%10;
    n /= 10;
  }
  return res;
}

int dignum(int n) {
  int res = 0;
  while(n > 0) {
    res++;
    n /= 10;
  }
  return res;
}

int stringcount(string s, char c) {
  return count(s.cbegin(), s.cend(), c);
}

int lcm(lint x, lint y){
  return x/ gcd(x, y) * y;
}

int combi(int n, int r){
  int num = 1;
  for(int i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}

int main(){
  int n,k,re;
  re=0;
  cin>>n>>k;
  vector<int> l;
  rep(i,n){
    int j;
    cin>>j;
    l.pb(j);

  }
  sort(all(l));
  rep(i,k){
    re+=l[i];
  }
  cout<<re<<endl;
}

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


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

    if(a<=x && x<= a+b) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

    return 0;
}

Measured memory_bytes: 256
/*---------------------------------

 @Author:   Dicer
 @DateTime: 2019-05-28 20:18:59

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
inline ll qpow(ll a,ll b,ll mod){ll res=1;while(b){if(b&1)res = (res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int MAXN = 2e5 + 7;

int a[233], dp[55][55][105];
int dfs(int l, int r, int k){
	if(dp[l][r][k] != -980615)	return dp[l][r][k];
	if(k <= 0)	return 0;
	if(l > r)	return 0;
	int res = 0;
	res = max(res, dfs(l+1, r, k-1) + a[l]);
	res = max(res, dfs(l, r-1, k-1) + a[r]);
	res = max(res, dfs(l+1, r, k-2));
	res = max(res, dfs(l, r-1, k-2));
	return dp[l][r][k] = res;
}
int main(int argc, char const *argv[])
{
	int n, k;
	cin >> n >> k;
	for(int i = 1; i <= n; ++i){
		for(int j = 1; j <= n; ++j){
			for(int q = 1; q <= k; ++q){
				dp[i][j][q] = -980615;
			}
		}
	}
	for(int i = 1; i <= n; ++i)	cin >> a[i];
	cout << dfs(1, n, k) << endl;
	return 0;
}

Measured memory_bytes: 1408
N, M = map(int, input().split())
ab = [map(int, input().split()) for _ in range(M)]
a, b = [list(i) for i in zip(*ab)]

path = [0]*N

for i in range(M):
    path[a[i]-1] += 1
    path[b[i]-1] += 1

for v in path:
    print(v)

Measured memory_bytes: 38384
//ProblemD

#ifdef _MYPC
#include "mypc.h"
#endif // _MYPC

#include <iostream>
#include <string>
#include <vector>
#include <bitset>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <memory>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

//ProblemD

using ll = long long;

class Solve {
private:
	void solve() {
		int n;
		ll c;
		cin >> n >> c;
		vector<ll> x(n + 2, 0), v(n + 2, 0);
		for (int i = 1; i <= n; i++) cin >> x[i] >> v[i];
		x[n + 1] = c;

		vector<ll> r(n + 2, 0), l(n + 2, 0);
		
		for (int i = 1; i <= n; i++) {
			r[i] = r[i - 1] + v[i] - (x[i] - x[i - 1]);
		}
		for (int i = n; i >= 1; i--) {
			l[i] = l[i + 1] + v[i] - (x[i + 1] - x[i]);
		}

		ll rst = 0;
		stack<int> st;
		for (int i = n; i >= 1; i--) {
			if (st.empty() || l[st.top()] < l[i]) {
				st.push(i);
			}
		}

		for (int i = 0; i <= n; i++) {
			if (!st.empty() && st.top() <= i) {
				st.pop();
			}

			ll ml = !st.empty() ? l[st.top()] - x[i] : 0ll;
			if (ml < 0) ml = 0;
			rst = max(rst, r[i] + ml);
		}

		for (int i = 1; i <= n; i++) {
			if (st.empty() || r[st.top()] < r[i]) {
				st.push(i);
			}
		}
		for (int i = n+1; i >= 1; i--) {
			if (!st.empty() && st.top() >= i) {
				st.pop();
			}

			ll mr = !st.empty() ? r[st.top()] - (c - x[i]) : 0ll;
			if (mr < 0) mr = 0;
			rst = max(rst, l[i] + mr);
		}
		cout << rst << endl;
	}

public:
	Solve() { solve(); }
};

int main(int argc, char* argv[]) {
	unique_ptr<Solve> solve = make_unique<Solve>();
	return 0;
}


Measured memory_bytes: 3840
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 666666
int h,w;
char s[666][666];
int main()
{
	scanf("%d%d",&h,&w);
	for(int i=1;i<=h;++i)
		scanf("%s",s[i]+1),s[i][1]='#';
	for(int i=1;i<=h;++i)
		if(i&1)
		{
			for(int j=1;j<w;++j) putchar('#');
			puts(".");
		}
		else puts(s[i]+1);
	for(int i=1;i<=h;++i)
		s[i][1]='.',s[i][w]='#';
	for(int i=1;i<=h;++i)
		if(i&1) puts(s[i]+1);
		else
		{
			putchar('.');
			for(int j=1;j<w;++j) putchar('#');
			puts("");
		}
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;


int main(void){
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll ans=1;
    map<char,ll>alpha;
    for(ll i=0;i<n;i++){
        alpha[s[i]]++;
    }
    for(char x='a';x<='z';x++){
        ans=(ans*(alpha[x]+1))%N;
    }
    cout<<(ans-1+N)%N<<endl;
}

Measured memory_bytes: 512
#include <iostream>
 #include <vector>
using namespace std;
 
int main(void){
    int N,K;
    cin >> N >> K;
    int p=0;
    for(int i=0;i<N;i++){
        int x;cin >> x;
        if(x==1){
            p = i;
            break;
        }
    }
    
    int num = 0;
    
    while(N-K>p){
        num++;
        N-=K-1;
    }
    while(N-K>0){
        num++;
        N-=K-1;
    }
    num++;
    cout << num;
    return 0;
}

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

public class Main {

    private static Scanner in = new Scanner(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int n = in.nextInt();
        int[] p = new int[n];
        for (int i=0; i < n; i++)
            p[i] = in.nextInt();

        int ans = 0;
        for (int i=0; i < n-2; i++) {
            int[] sub = new int[]{p[i], p[i + 1], p[i + 2]};
            Arrays.sort(sub);
            if (sub[1] == p[i + 1])
                ans++;
        }

        out.println(ans);
    }

}


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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deb(x)	cout << #x << " " << x << endl;

typedef long long int ll;
typedef map<pair<int, int>, ll> mpi;

long shUtils(int cnt, int curr, int a[], int n, mpi &dp) {
    
    if (cnt >= n/2) {
        return 0;
    }

    if (curr >= n) {
        return LONG_MIN;
    }

    if (n/2-cnt > (n-curr+1)/2)
    	return LONG_MIN;

    pair<int, int> p = {cnt, n/2-curr};

    if (dp.find(p) != dp.end()) {
    	// deb(dp[p]);
        return dp[p];
    }

    ll tmp = shUtils(cnt + 1, curr + 2, a, n, dp);
    ll choice1;

    if (tmp == LONG_MIN)
        choice1 = tmp;
    else
        choice1 = a[curr] + tmp;

    ll choice2 = shUtils(cnt, curr + 1, a, n, dp);

    ll ans = max(choice1, choice2);
    dp[p] = ans;

    return ans;
}

ll selectHalf(int a[], int n) {

    mpi dp;

    ll ans = shUtils(0, 0, a, n, dp); // cnt and index passed
    return ans;
}

int main() {

	IOS

	int n;
	cin >> n;

	int a[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];

	cout << selectHalf(a, n) << endl;

	return 0;
}

Measured memory_bytes: 32540
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    m = [0] * n
    m[0] = 0
    for i in range(1, n):
        m[i] = min(m[j] + abs(h[j] - h[i]) for j in range(max(0, i-k),i))
    print(m[-1])

main()


Measured memory_bytes: 13980
def solve(h, w):
    odd_line = '#.' * (w // 2)
    even_line = '.#' * (w // 2)
    if w%2:
        odd_line = odd_line + '#'
        even_line = even_line + '.'
    two_lines = odd_line + '\n' + even_line + '\n'
    print(two_lines * (h // 2), end='')
    if h%2:
        print(odd_line)
    print()

if __name__ == '__main__':
    while True:
        h, w = [int(i) for i in input().split()]
        if h == w == 0: break
        solve(h, w)

Measured memory_bytes: 6792
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  FOR(i, 1, n + 1) {
    int x = (int)((double)i * 1.08);
    if(n == x) {
      cout << i << '\n';
      return 0;
    }
  }
  puts(":(");
  return 0;
}


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>
#include <limits>
#define ll long long
using namespace std;
struct all_init
{
    all_init()
    {
        cout << fixed << setprecision(12);
    }
} All_init;

int main()
{
    ll n,k,ans=0;
    cin>>n>>k;
    vector<ll>h(n);
    for(ll i=0;i<n;i++){
        cin>>h[i];
    }
    sort(h.begin(),h.end(),greater<ll>());
    for(ll i=0;i<n;i++){
        if(k>0){
            k--;
        }
        else{
            ans+=h[i];
        }
    }
    cout<<ans<<endl;
    

}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main(){
	int n,a[1000];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
    }
	for(int j=n-1;j>=1;j--){
	cout<<a[j]<<" ";
	
	}
cout<<a[0]<<endl;
return 0;
}


Measured memory_bytes: 3072
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    string s; 
	int K;
	cin >> s >> K;
    set<string> subs;
    // O(N^2=1e7)
    for (int l = 0; l < static_cast<int>(s.length()); ++l)
    {
        for (int r = l + 1; r <= min(l + K, static_cast<int>(s.length())); ++r)
        {
            subs.insert(s.substr(l, r - l));
        }
    }
    auto itr = subs.begin();
    for (int i = 1; i < K; ++i)
    {
        ++itr;
    }
    cout << *itr << endl;
}

Measured memory_bytes: 1664
#include <stdio.h>

int main(void){
  char a, b;
  scanf("%c %c", &a, &b);
  if(a == 'H'){
    printf("%c\n", b);
  }else{
    if(b == 'H') printf("D\n");
    else printf("H\n");
  }
  return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
from sys import stdin
# import numpy as np
# import sys
# sys.setrecursionlimit(10**4)

def _li(): return list(map(int, stdin.readline().split()))
def _li_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def _lf(): return list(map(float, stdin.readline().split()))
def _ls(): return stdin.readline().split()
def _i(): return int(stdin.readline())
def _f(): return float(stdin.readline())
def _s(): return stdin.readline()[:-1]


a, b = _li()
if a < b:
    ans = str(a) * b
else:
    ans = str(b) * a
print(ans)


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

int main(void){
    int n,k,ng = 0 ,ok = 1e9;
    cin >> n >> k;
    int a[n];
    rep(i,n) cin >> a[i];
    while(ok-ng>1){
        int mid = (ok+ng)/2,cnt=0;
        rep(i,n) cnt += (a[i]-1)/mid;  
        if(cnt<=k) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}

Measured memory_bytes: 4416
#include<bits/stdc++.h>
#define For(i,j,k)	for(ll i=j;i<=k;++i)
#define Dow(i,j,k)	for(ll i=k;i>=j;--i)
#define maxm 10011
#define maxn 511
#define pb push_back
#define ll unsigned long long
using namespace std;
inline ll read()
{
	ll t=0,f=1;char c=getchar();
	while(c<'0'||c>'9')	{c=getchar();}
	while(c<='9'&&c>='0')	t=t*10+c-48,c=getchar();
	return t*f;
}
char s[10];
int main()
{
	scanf("%s",s+1);
	int len=strlen(s+1);
	For(i,1,len-1)	if(s[i]=='A'&&s[i+1]=='C')	{puts("Yes");return 0;}
	puts("No");
}

Measured memory_bytes: 256