akhauriyash/Code-Regression huggingface dataset:
N = int(input())
A = []
for i in range(N) :
    A.append(int(input()))

Amax = -1
Amax2 = -1
index = -1
index2 = -1

for i in range(N) :
    if Amax < A[i] :
        Amax = A[i]
        index = i

if A.count(Amax) > 1 :
    for i in range(N) :
        print(Amax)
    exit()

for i in range(N) :
    if i == index :
        continue
    if Amax2 < A[i] :
        Amax2 = A[i]
        index2 = i

for i in range(N) :
    if i == index :
        print(Amax2)
    else :
        print(Amax)


Measured memory_bytes: 12532
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		BigDecimal a = scan.nextBigDecimal();
		BigDecimal b = scan.nextBigDecimal();

		BigDecimal ans = a.multiply(b).setScale(0, RoundingMode.DOWN);
		System.out.println(ans);

		scan.close();

	}

}


Measured memory_bytes: 37444
import numpy as np

n,m = map(int,input().split())
h = list(map(int,input().split()))
ok = [0]*n

for i in range(m):
    a,b = map(int,input().split())
    a -=1
    b -=1
    if h[a] >= h[b]: ok[b] = 1
    if h[b] >= h[a]: ok[a] = 1
nplist = np.array(ok)
print(np.count_nonzero(nplist == 0))


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

int main() {
  int s;
  cin >> s;
  string str = to_string(s);

  for(int i = 0;i < 3;i++){
      if(str[i] == str[i+1]){
        cout << "Bad" << endl;
        return 0;
      } 
  }
  cout << "Good" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin>>s;
  vector<int> ans(s.size(),0);
  char last=s[0];
  int cnt=1;
  int index;
  for(int i=1;i<s.size();i++){
    if(s[i]=='R'){
      cnt++;
      last='R';
    }else if(s[i]!=last&&last=='R'){
      cnt--;
      ans[i-1]=cnt/2+1;
      ans[i]=cnt/2+1;
      if(cnt%2==1){
        ans[i]++;
        //printf("yooo\n");
      }
      index=i;
      last='L';
      cnt=0;
    }else if(s[i]==last&&last=='L'){
      if((i-index)%2){
        ans[index-1]++;
      }else{
        ans[index]++;
      }
    }
  }
  for(int i=0;i<s.size();i++){
    if(i>0){
      cout<<" "<<flush;
    }
    cout<<ans[i];
  }
  return 0;
}

Measured memory_bytes: 3856
n=int(input())
l=list(map(int,input().split()))
if(n<=2):
    print(1)
    quit()
h=0
ans=1
for i in range(n-1):
    if((l[i+1]-l[i])*h<0):
        ans+=1
        h=0
        continue
    if(l[i+1]-l[i]<0):
        h=-1
    elif(l[i+1]-l[i]>0):
        h=1
print(ans)

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

int main(){
  int n;
  cin >> n;
  vi a(n), b(n);
  rep(i, 0, n)
    cin >> a[i] >> b[i];
  
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  
  int ans;
  
  if(n%2 == 1){
    ll am, bm;
    am = a[(n-1)/2];
    bm = b[(n-1)/2];
    ans = bm - am +1;
  }
  else{
    ll am, bm;
    am = (a[n/2-1]+a[n/2]);
    bm = (b[n/2-1]+b[n/2]);
    ans = bm - am +1;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 4880
Q, H, S, D = map(int, input().split())
N = int(input())

A = min(Q*4, H*2, S)
if N % 2 == 0:
    print(min(A*N, D*N//2))
else:
    if N == 1:
        print(A)
    else:
        print(min(A*N, D*(N//2)+A))


Measured memory_bytes: 2940
from collections import deque

N = int(input())

nodes = [tuple(map(int, input().split(' '))) for _ in range(N)]

distances = [-1] * (N + 1)

queue = deque()
queue.append((1, 0))

while len(queue) > 0:
    node, distance = queue.popleft()
    if distances[node] != -1:
        continue
    distances[node] = distance

    neighbors = nodes[node - 1][2:]
    for neighbor in neighbors:
        queue.append((neighbor, distance + 1))

for node in range(1, N + 1):
    print(node, distances[node])



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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;

const double PI=3.14159265358979323846;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

void dump(const vector<int> &v)
{
	REP(i, SZ(v)-1){ cout << v[i] << " "; }
	cout << v[SZ(v)-1] << endl;
}

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

	VI A(n * m);
	VI b(m);

	REP(j, n){
		REP(i, m){
			cin >> A[j * m + i];
		}
	}

	REP(i, m){
		cin >> b[i];
	}

	VI C(n);

	REP(k, n){
		ll c = 0;
		REP(i, m){
			c += A[k * m + i] * b[i];
		}
		C[k] = c;
	}

	REP(k, n){
		cout << C[k] << endl;
	}

	return 0;
}




Measured memory_bytes: 3140
n, m = map(int,input().split())
list = [list(map(int,input().split())) for i in range(n)]

list.sort()
ans = 0
hon = 0
i = 0
for i in range(n):
    if hon+list[i][1] >= m:
        list[i][1] = m-hon
        ans += list[i][0]*list[i][1]
        break
    else:
        ans += list[i][0]*list[i][1]
        hon += list[i][1]
print(ans)

Measured memory_bytes: 27760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;

int main() {
  
  int k;
  cin >> k;
  vec1 t = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << t.at(k-1) << endl;
}

Measured memory_bytes: 256
S = int(input())

ab = S // 100
cd = S % 100
if (ab == 0 or ab > 12):
    if 1 <= cd <= 12:
        print('YYMM')
    else:
        print('NA')
elif (cd == 0 or cd > 12):
    if 1 <= ab <= 12:
        print('MMYY')
    else:
        print('NA')
else:
    print('AMBIGUOUS')

Measured memory_bytes: 3060
#include<stdio.h>
#include<vector>
#include<algorithm>
int gcd(int a, int b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

int main()
{
	int N;
	scanf("%d", &N);

	std::vector<int> A(N, 0);
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}

	std::vector<int> L(N+1, 0);
	std::vector<int> R(N+1, 0);

	for (int i = 0; i < N; i++) {
		L[i+1] = gcd(L[i], A[i]);
	}
	for (int i = N-1; i > 0; i--) {
		R[i] = gcd(R[i+1], A[i]);
	}

	int output = 0;
	int temp = 0;
	for (int i = 0; i < N; i++) {
		output = std::max(output, gcd(L[i], R[i + 1]));
	}
	printf("%d", output);

	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define FOR(i,b,e) for (common_type_t <decltype (b), decltype (e)> i = (b), i ## __end = (e); i < i ## __end; ++ i)
#define FORR(i,b,e) for (common_type_t <decltype (b), decltype (e)> i = (e), i ## __begin = (b); i -- > i ## __begin;)
#define rep(i,n) for (decay_t <decltype (n)> i = 0, i ## __len = (n); i < i ## __len; ++ i)
#define ALL(x) begin (x), end (x)
using namespace std;

auto main () -> int
{
  cin.tie (nullptr);
  ios::sync_with_stdio (false);

  int a, e, k, t;
  cin >> a >> t >> t >> t >> e >> k;
  cout << (e - a > k ? ":(" : "Yay!") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
int cnt(int x){
    int sum=0;
    while(x % 2 != 1){
        x = x / 2;
        sum++;
    }
    return sum;
}
int main() {
    int N;
    std::cin >> N;
    int count = 0;
    for(int i = 0; i < N; i++){
        int x;
        std::cin >> x;
        count += cnt(x);
    }
    std::cout << count << std::endl;
    return 0;
}

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) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<int> a(n), b(n), c(n-1);
  rep(i, n) cin >> a[i], a[i]--;
  rep(i, n) cin >> b[i];
  rep(i, n-1) cin >> c[i];
  int ans = 0;
  rep(i, n) {
    ans += b[a[i]];
    if (i < n - 1 && a[i] + 1 == a[i+1]) ans += c[a[i]];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import collections

h,w,m = map(int,input().split())
X = []
Y = []
for _ in range(m):
    x,y = map(int,input().split())
    X.append(x)
    Y.append(y)

most_common_x = collections.Counter(X).most_common()
most_common_x_index = most_common_x[0][0]
most_common_x_count = most_common_x[0][1]
most_common_y = collections.Counter(Y).most_common()
most_common_y_index = most_common_y[0][0]
most_common_y_count = most_common_y[0][1]

otherwisey = []
otherwisex = []
for i in range(m):
    if X[i] != most_common_x_index:
        otherwisey.append(Y[i])
    if Y[i] != most_common_y_index:
        otherwisex.append(X[i])

most_common_y = collections.Counter(otherwisey).most_common()
if len(most_common_y)!= 0:
    ansx = most_common_y[0][1] + most_common_x_count
else:
    ansx = most_common_x_count

most_common_x = collections.Counter(otherwisex).most_common()
if len(most_common_x)!= 0:
    ansy = most_common_x[0][1] + most_common_y_count
else:
    ansy = most_common_y_count

print(max(ansx,ansy))

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

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

  vector<int> ap, an, az;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    if (a >= 0) {
      ap.push_back(a);
    } else {
      an.push_back(a);
    }
  }

  sort(ap.begin(), ap.end());
  sort(an.rbegin(), an.rend());

  int m;
  vector<pair<int, int>> ans;
  if (ap.size() > 0 && an.size() > 0) {
    while (ap.size() > 1) {
      ans.push_back({an.back(), ap.back()});
      an.back() -= ap.back();
      ap.pop_back();
    }
    while (an.size() > 1) {
      ans.push_back({ap.back(), an.back()});
      ap.back() -= an.back();
      an.pop_back();
    }
    m = ap.back() - an.back();
    ans.push_back({ap.back(), an.back()});
  } else {
    if (ap.size() > 0) {
      reverse(ap.begin(), ap.end());
      while (ap.size() > 2) {
        int x = ap.back();
        ap.pop_back();
        int y = ap.back();
        ap.pop_back();
        ap.push_back(x - y);
        ans.push_back({x, y});
      }
      int x = ap.back();
      ap.pop_back();
      int y = ap.back();
      ap.pop_back();
      m = y - x;
      ans.push_back({y, x});
    }
    if (an.size() > 0) {
      reverse(an.begin(), an.end());
      while (an.size() > 2) {
        int x = an.back();
        an.pop_back();
        int y = an.back();
        an.pop_back();
        an.push_back(x - y);
        ans.push_back({x, y});
      }
      int x = an.back();
      an.pop_back();
      int y = an.back();
      an.pop_back();
      m = x - y;
      ans.push_back({x, y});
    }
  }

  cout << m << endl;
  for (int i = 0; i < ans.size(); ++i) {
    cout << ans[i].first << " " << ans[i].second << endl;
  }
}

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

const string cls[] = {
    "",
    "light fly",
    "fly",
    "bantam",
    "feather",
    "light",
    "light welter",
    "welter",
    "light middle",
    "middle",
    "light heavy",
    "heavy"
};

const int a[] = {
    -100,
    48,
    51,
    54,
    57,
    60,
    64,
    69,
    75,
    81,
    91,
    100000000
};

int main(){
    double w;
    while (cin >> w){
        int i = 0;
        while (w > a[i]) i++;
        cout << cls[i] << endl;
    }
}

Measured memory_bytes: 1240
#######################################
import numpy as np
import math
import copy
import re
import sys
#sys.exit(0)

inf = float("inf")
prime = 1

def check_print(check_flag, text, end="\n"):
  if check_flag:
    print(text, end=end)

def c2i(x):
    if str.isdecimal(x):
        return int(x)
    else:
        return x

def cout(*args):
  arglist = []
  for arg in args:
    if hasattr(arg, "__iter__"):
      arglist.extend(arg)
    else:
      arglist.append(arg)
      
  arglist = list(map(str, arglist))
  print(" ".join(arglist))

#or
#print(" ".join(list(map(str, lis))))
  
def count2(num):
  count=0
  while num%2==0:
    num/=2
    count+=1
  return count

def ketasum(num):
  nums = [int(s) for s in str(num)]
  return sum(nums)

#math
def gcd(a, b): #最大公約数
  while b:
    a, b = b, a % b
  return int(a)

def lcm(a, b): #最小公倍数
  return int(a * b // gcd (a, b))

def gcd3(lis): #最大公約数(3over)
  ans = lis[0]
  for li in lis:
    ans = gcd(ans,li)

def lcm3(lis): #最小公倍数(3over)
  ans = lis[0]
  for li in lis:
    ans = lcm(ans,li)

def divisor(n): #nの約数を全て求める
  i = 1
  table = []
  while i * i <= n:
    if n%i == 0:
      table.append(i)
      table.append(n//i)
    i += 1
  table = list(set(table))
  return table

def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

def is_prime(n):
  for i in range(2, n + 1):
    if i * i > n:
      break
    if n % i == 0:
      return False
  return n != 1

#processing stock
"""
a = sorted(a)
a = sorted(a, reverse=True)

"""

#regex
"""
pattern = ""
result = re.search(pattern, s)

result = re.fullmatch(pattern, s)

result = re.finditer(pattern, s)
for res in result:
    print res.group()   # 1回目: ca      2回目: ca   
    print res.start()   # 1回目: 0       2回目: 6      
    print res.end()     # 1回目: 2       2回目: 8      
    print res.span()    # 1回目: (0, 2)  2回目: (6, 8)
"""


#math
"""
#切り捨て
math.floor()
# 切り上げ
math.ceil()
"""

#input stock
"""
n = int(input())

#list
a = list(map(int, input().split()))
a,b = map(int, input().split())

d=[]
for i in range(n):
  d[i]=int(input())

#2dim-list
a = [list(map(int, input().split())) for i in range(n)]

s = input()
ss =  [int(si) for si in s]
"""

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

def anti_d(num):
  return num - (num//c + num//d - num//lcm(c,d))

ret = anti_d(b) - anti_d(a-1)
print(int(ret))

Measured memory_bytes: 14296
// ~maqsat~
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

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

#define F first
#define S second
#define in insert
#define pb push_back
#define eb emplace_back
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define count1 __builtin_popcountl
#define debug(x) cerr << (#x) << " = " << (x) << "\n";
#define TEZ ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define fre(f) if(fopen(f".in", "r")) freopen(f".in", "r", stdin),freopen(f".out", "w", stdout);

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ull = unsigned long long;
// using big = __int128_t; // -10^38...10^38
using db = double;
using ld = long double;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
typedef vector<ii> vii;
typedef vector<pll> vll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T, class U> inline void cmin(T &a, U b) { a = min(a, b); }
template <class T, class U> inline void cmax(T &a, U b) { a = max(a, b); }
template <class T, class U, class X, class Y> inline void psmn(T &a, U b, X &p, Y i) { if(b < a)a = b,p = i; }
template <class T, class U, class X, class Y> inline void psmx(T &a, U b, X &p, Y i) { if(b > a)a = b,p = i; }

const int oo = 0x3f3f3f3f;
const ll N = 1e5 + 345;
const ll MOD = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const db EPS = 1e-9;
const db PI = acos(-1); // 3.14159265358979323846

#define int ll

bool pr(ll x) {
    for (ll i = 2; i <= sqrt(x); i++) {
        if (x % i == 0) {
            return false;
        }
    }

    return true;
}

inline vl cd(ll a) {
	vl ans;
	ans.eb(1);
	for(int i = 2; i <= sqrt(a); i++) {
		if(a % i == 0) {
			ans.eb(i);
			if(i != a / i) ans.eb(a/i);
		}
	}
	ans.eb(a);
	return ans;
}

signed main() {
	fre(""); TEZ;

	ll a, b;
	cin >> a >> b;
	vector <ll> aa = cd(a), ab = cd(b);

    
	int j = 0;
	vl ans;
	map <ll, bool> m, u;
	for(int i = 0; i < sz(aa); i++) {
		m[aa[i]] = 1;
	}
	for(int i = 0; i < sz(ab); i++) {
	    if(m[ab[i]] && !u[ab[i]]) {
	        u[ab[i]] = 1;
	       ans.eb(ab[i]);
	    }
	}
    
	int n = sz(ans);
	ll mx = 1;
	for(int i = 0; i < n; i++) {
	    int res = 0;
	    ll g = ans[i];
		for(int j = 0; j < n; j++) {
		    if(pr(ans[j])) res++;
		}
		cmax(mx, res);
	}
	cout << mx;

	return 0;
}


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

int main(void) {
    int i, n, y=0;
    cin >> n;
    string s[n];
    for(i=0; i<n; i++) {
        cin >> s[i];
        if(s[i]=="Y")
            y=1;
    }
    if(y==1)
        cout << "Four" << endl;
    else
        cout << "Three" << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var cin = new Scanner2();
			int n = cin.Int();
			if (n == 0) {
				Console.WriteLine(0);
				return;
			}

			int[] d = cin.ArrayInt(n);
			int[] counts = new int[13];
			for (int i = 0; i < n; i++) {
				counts[d[i]]++;
			}

			int ans = 12;
			int left = 0;
			int right = 0;
			bool isLeft = true;
			for (int i = 0; i < 13; i++) {
				if (counts[i] >= 3) {
					ans = 0;
				}

				if (i == 0) {
					if (counts[i] > 0) {
						ans = 0;
					}
				} else {
					if (counts[i] == 1) {
						if (isLeft) {
							ans = Math.Min(ans, i - left);
							left = i;
							isLeft = false;
						} else {
							ans = Math.Min(ans, i - right);
							right = i;
							isLeft = true;
						}
					} else if (counts[i] > 1) {
						if (i == 12) {
							ans = 0;
						} else {
							ans = Math.Min(ans, i - left);
							ans = Math.Min(ans, i - right);
							left = i;
							right = i;
						}
					}
				}
			}

			ans = Math.Min(ans, Math.Abs(24 - (right + left)));
			Console.WriteLine(ans);
		}
	}

	public class Scanner2
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private readonly string filePath_;
		private string[] buf_;
		private int index_;
		Func<string> reader_;

		public Scanner2(string file = "")
		{
			if (string.IsNullOrWhiteSpace(file)) {
				reader_ = Console.ReadLine;
			} else {
				filePath_ = file;
				var fs = new StreamReader(file);
				reader_ = fs.ReadLine;
			}
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = reader_();
			while (st == "") {
				st = reader_();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}

		public void Save(string text)
		{
			if (string.IsNullOrWhiteSpace(filePath_)) {
				return;
			}

			File.WriteAllText(filePath_ + "_output.txt", text);
		}
	}
}

Measured memory_bytes: 11220
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

D = I()
c = [0] + LI()
s = [0] + [[0] + LI() for i in range(D)]
t = [0] + [I() for i in range(D)]
M = I()
dq = [LI() for i in range(M)]

last = [[0]*27 for i in range(D+1)]
manzokudo = 0

for i in range(1,D+1):
    for j in range(1,27):
        if j != t[i]:
            last[i][j] = last[i-1][j]
        else:
            last[i][t[i]] = i
    manzokudo += s[i][t[i]]
    r = 0
    for j in range(1,27):
        r += c[j]*(i-last[i][j])
    manzokudo -= r

for i in range(M):
    d,q = dq[i]
    t0 = t[d]
    manzokudo += s[d][q] - s[d][t0]
    for j in range(d,D+1):
        if j == d:
            last[d][t0] = last[d-1][t0]
            manzokudo -= c[t0] * (d - last[d][t0])
            last[d][q] = d
            manzokudo += c[q] * (d - last[d-1][q])
        else:
            if last[j][t0] == d:
                last[j][t0] = last[d-1][t0]
                manzokudo -= c[t0] * (d - last[d][t0])
            if last[j][q] == last[d-1][q]:
                last[j][q] = d
                manzokudo += c[q] * (d - last[d-1][q])
    t[d] = q
    print(manzokudo)

Measured memory_bytes: 83932
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 2e9;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int n, k;
	cin >> n >> k;
	cout << 1 + (n - k + k - 2) / (k - 1) << '\n';
 	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <iostream>

using namespace std;
typedef long long ll;

vector<int> memo;//x+x
int ns[1000];
int N,M;

int score(int x){
	if(x > M){
		return 0;
	}else{
		return x;
	}
}

int solve(){
	int ans = 0;
	for(const auto x : memo){
		ans = max(ans,score(x));
		if(x < M){
			auto it = upper_bound(memo.begin(),memo.end(),M-x);
			if(it!=memo.begin()){
				--it;
				ans = max(ans,score(x+ *it));
			}
		}
	}
	return ans;
}

int main(){
	while(true){
		memo.clear();
		cin >> N >> M;
		if(N == 0 && M==0)break;
		for(int i=0;i<N;++i){
			int t;
			scanf("%d",&t);
			ns[i] = t;
		}
		memo.push_back(0);
		for(int i=0;i<N;++i){
			memo.push_back(ns[i]);
			for(int j=i;j<N;++j){
				memo.push_back(ns[i]+ns[j]);
			}
		}
		sort(memo.begin(),memo.end());
		memo.erase(unique(memo.begin(),memo.end()),memo.end());
		cout << solve() << endl;
	}
	return 0;
}

Measured memory_bytes: 3212
#include<bits/stdc++.h>
#define $ for(i=0;i++<n;)
using namespace std;
int n,m,g[777][777],C[777],t[777][2],A,c,i,j;
vector<int>G[777];
bitset<777>P(1);
int f(int u,int c){
	int t=1,i=0;
	for(C[u]=c;i<G[u].size();i++)t&=C[G[u][i]]<0?f(G[u][i],c^1):C[G[u][i]]^c;
	return t;
}
main(){
	for(cin>>n>>m;cin>>i>>j;)g[i][j]=g[j][i]=1;
	$ for(j=i;j++<n;)if(!g[i][j])G[i].push_back(j),G[j].push_back(i);
	$ C[i]=-1;
	$ A+=C[i]<0&&!f(i,c+=2);
	A=A?-1:1e9;
	$ t[C[i]/2][C[i]%2]++;
	$ P=P<<t[i][0]|P<<t[i][1];
	$ A=min(A,P[i]?i*(i-1)/2+(n-i)*(n-i-1)/2:A);
	cout<<A;
}


Measured memory_bytes: 3200
/* ****revpro**** */
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl	   '\n'
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)    
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define mii	    map<ll,ll>
using namespace std;

#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define N  100005
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;  
#define ordered_set tree<double, null_type,less<double>, rb_tree_tag,tree_order_statistics_node_update> 
void solve()
{
	ll n,k;
	cin>>k>>n;
	ll a[n];
	rep(i,0,n) cin>>a[i];
	ll mx=0;
	rep(i,0,n)
	{
		if(i<n-1)
		{
			mx=max(mx,a[i+1]-a[i]);
		}
		else mx=max(mx,k-a[i]+a[0]);
	}
	cout<<k-mx;
}
signed main()
{
	
		/***********************************/
    unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
    mt19937_64 generator (seed);
    /***********************************/
 
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
		
	}
	TIME
	return 0;
}

Measured memory_bytes: 1792
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
typedef long long int ll;
#define rep(i,n) for(int i=0;i<n;++i)
#define ALL(x) x.begin(),x.end();
const int INF = 1LL << 30;
const ll LLINF = 1LL << 60;
using namespace std;
int main() {
	int a, b, c, x,ct=0;
	cin >> a >> b >> c >> x;
	rep(i, a+1)rep(j, b+1)rep(w, c+1) {
		if (i * 500 + j * 100 + w * 50 == x)++ct;
	}
	cout << ct << endl;
	return 0;
}

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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long

static const ll MAX = 1000000;
static const ll INFTY = 1e12;
static const ll MOD = 1000000007;

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;


const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int H, W, N;
int sx, sy, gx, gy; 
vector<vector<char>> field;
vector<vector<int>> dist;
//vector<pair<int, int>> gx, gy;
deque<pair<int, int>> que;

typedef vector<vector<int> > Matrix;

const ll INF = 1e18;

int main() {

    ll n;
    cin >> n;
    map<ll, ll> v1, v2;
    REP(i, n){
        if(i%2==0){
            ll v;
            cin >> v;
            v1[v]++;
        }
        else {
            ll v;
            cin >> v;
            v2[v]++;
        }
    }

    vector<pair<ll, ll>> v1_, v2_;

    for(auto itr = v2.begin(); itr != v2.end(); ++itr) {
        v2_.push_back({itr->second, itr->first});
    }
    for(auto itr = v1.begin(); itr != v1.end(); ++itr) {
        v1_.push_back({itr->second, itr->first});
    }
    sort(v1_.begin(), v1_.end(), greater<pair<ll, ll>>());
    sort(v2_.begin(), v2_.end(), greater<pair<ll, ll>>());

    ll ans;
    if(v1_[0].second == v2_[0].second){
        if(v1_.size()==1 && v2_.size()==1){
            ans = n/2;
        }else{

            ll ans1 = (n/2 - v1_[0].first) + (n/2 - v2_[1].first);
            ll ans2 = (n/2 - v2_[0].first) + (n/2 - v1_[1].first);

            ans = min(ans1,ans2);
            // ans = 0;
        }
    }else{
        ans = (n/2 - v1_[0].first) + (n/2 - v2_[0].first);
    }

    

    cout << ans << endl;

}

/*
みんな、くるくるぱーにな〜れ
　∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/



Measured memory_bytes: 8824
#include<cstdio>
using namespace std;

int n,x,y,z,m;
int i,j;

int main()
{
    scanf("%d",&n);
    x = n / 4;
    y = 0;
    z = n;
    if(n % 4 == 0 || n % 7 == 0)
        printf("Yes");
    else
    {
        for(i = 0; i <= x; i++)
        {
            if(y != 0)
                break;
            n = z;
            n = n - 4 * i;
            m = n;
            for(j = 0; j <= m / 7; j++)
            {
                n = n - 7;
                if(n == 0)
                {
                    printf("Yes");
                    y++;
                    break;
                }
            }
        }
        if(y == 0)
            printf("No");
    }
    return 0;
}


Measured memory_bytes: 128
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 06/14/20 20:53:44
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int h,w,k; cin>>h>>w>>k;
  int a,b,c,d; cin>>a>>b>>c>>d; a--; b--; c--; d--;
  vector<string> grid(h);
  for (int i = 0; i < h; i++) {
    cin>>grid[i];
  }
  vector<vector<int>> dist(h, vector<int>(w, 1e9));
  dist[a][b] = 0;
  struct Pos {
    int x,y;
  };
  queue<Pos> qs;
  qs.push({a,b});
  constexpr int dir[4][2] = {
      {-1,0},
      {1,0},
      {0,-1},
      {0,1}
  };
  while (not qs.empty()) {
    auto [x,y] = qs.front(); qs.pop();
    if (x == c and y == d) {
      break;
    }
    auto cd = dist[x][y];
    for (auto [dx,dy] : dir) {
      for (int i = 1; i <= k; i++) {
        int nx = x+dx*i;
        int ny = y+dy*i;
        if (nx < 0 or nx >= h or ny < 0 or ny >= w)
          continue;
        if (grid[nx][ny] == '@')
          break;
        if (dist[nx][ny] < cd+1)
          break;
        if (dist[nx][ny] == cd+1)
          continue;
        dist[nx][ny] = cd+1;
        qs.push({nx,ny});
      }
    }
  }
  cout << (dist[c][d]==1e9 ? -1 : dist[c][d]) << endl;

  return 0;
}


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

int main(){
    int n, tmp;
    cin >> n;
    int a[n] = {0};
    for(int i = 0; i < n-1; i++){
        cin >> tmp;
        a[tmp-1]++;
    }
    for(int i = 0; i < n; i++){
        cout << a[i] << endl;
    }
}

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

bool solve(vector<int> r, int n) {
    for (int i = 0; i < n; i++) {
        if (r[i] < 1) return false;
    }
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int INF = 1000000007;
    int N, W, H;

    cin >> N >> W >> H;
    vector<int> ruisekiW(W + 10, 0);
    vector<int> ruisekiH(H + 10, 0);
    for (int i = 0; i < N; i++) {
        int x, y, w;
        cin >> x >> y >> w;
        int x_w = x - w < 0 ? 0 : x - w;
        int xtw = x + w > W ? W : x + w;
        ruisekiW[x_w] += 1;
        ruisekiW[xtw] -= 1;

        int y_w = y - w < 0 ? 0 : y - w;
        int ytw = y + w > H ? H : y + w;
        ruisekiH[y_w] += 1;
        ruisekiH[ytw] -= 1;
    }
    for (int i = 0; i < ruisekiW.size(); i++) {
        ruisekiW[i + 1] = ruisekiW[i] + ruisekiW[i + 1];
    }
    for (int i = 0; i < ruisekiH.size(); i++) {
        ruisekiH[i + 1] = ruisekiH[i] + ruisekiH[i + 1];
    }
    if (solve(ruisekiW, W) || solve(ruisekiH, H)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 4480
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD (1'000'000'007)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;

int color[100005];
bool is_bipartite_graph(vector<vector<int>> &graph, int c, int p){
    color[p]=c;
    for(int cc : graph[p]){
        if(color[cc]==c) return false;
        if(color[cc]==0) if(!is_bipartite_graph(graph, -c, cc)) return false;
    }
    return true;
}

int main(void)
{
    int n,m;
    cin >> n >> m;
    vector<vector<int>> graph(n, vector<int>());
    REP(i, m){
        int a,b;
        cin >> a >> b;
        a--;b--;
        graph[a].pb(b);
        graph[b].pb(a);
    }

    ll ans=0;
    if(is_bipartite_graph(graph, 1,0)){
        ll w=0;
        REP(i, n){
            if(color[i]==1) w++;
        }
        ans = w * (n-w) - m; 
    }else{
        ans = (ll)n*(n-1)/2 - m;
    }

    pr(ans);
}

Measured memory_bytes: 6528
class NormalInput {
  input: string[];
  pointer: number;
  constructor(raw: string) {
    this.input = raw.split(/ |\n/);
    this.pointer = 0;
  }
  int = (): number => {
    const ret = parseInt(this.input[this.pointer], 10);
    this.pointer++;
    return ret;
  };
  str = (): string => {
    const ret = this.input[this.pointer];
    this.pointer++;
    return ret;
  };
  strs = (length: number): string[] => {
    let ret: string[] = [];
    for (let i = 0; i < length; i++) {
      ret.push(this.str());
    }
    return ret;
  };
  ints = (length: number): number[] => {
    let ret: number[] = [];
    for (let i = 0; i < length; i++) {
      ret.push(this.int());
    }
    return ret;
  };
}
function rep(n: number) {
  let a = [];
  for (let i = 0; i < n; i++) a.push(i);
  return a;
}
function Main({ int, str, strs, ints }: NormalInput) {
  const [N, _X, _Y] = ints(3);
  const [X, Y] = [_X - 1, _Y - 1];
  const count = rep(N).map(() => 0);
  const dist = (i, j) => {
    if (i <= X) {
      if (j <= X) {
        return j - i;
      } else if (j <= Y) {
        return Math.min(j - i, X - i + Y - j + 1);
      } else {
        return j - i - (Y - X - 1);
      }
    } else if (i <= Y) {
      if (j <= Y) {
        return Math.min(j - i, Y - j + i - X + 1);
      } else {
        return Math.min(j - i, j - Y + 1 + i - X);
      }
    } else {
      return j - i;
    }
  };
  for (let i = 0; i < N; i++)
    for (let j = i + 1; j < N; j++) {
      count[dist(i, j)] = count[dist(i, j)] + 1;
    }
  for (let i = 1; i < N; i++) console.log(count[i]);
}

//DO NOT EDIT
Main(new NormalInput(require("fs").readFileSync("/dev/stdin", "utf8")));


Measured memory_bytes: 9792
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int a = sc.nextInt();
		int b = sc.nextInt();
		Pair p = extgcd(a, b, new Pair(0, 0));
		System.out.println(p.x + " " + p.y);
	}
	static Pair extgcd(long a, long b, Pair p) {
		if (b == 0) {
			p.x = 1;
			p.y = 0;
			return p;
		}
		p.swap();
		extgcd(b, a % b, p);
		p.swap();
		p.y -= a / b * p.x;
		return p;
	}
}

class Pair {
	public long x;
	public long y;
	public Pair(long x, long y) {
		this.x = x;
		this.y = y;
	}
	void swap() {
		long tmp = x;
		x = y;
		y = tmp;
	}
}


class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}
	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}
	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || Integer.MAX_VALUE < nl) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 24452
//kruskal tree
#include <cstdio>
#include <algorithm>
using namespace std;
#define M 9999
int parent[M],a[M],b[M];
pair<int,int>node[M];
int root(int a){return parent[a]==a?a:parent[a]=root(parent[a]);}
int differ(int a,int b){
	int x=root(a),y=root(b);
	if(x==y)return 0;
	return 1;
}
int unite(int a,int b){
	int x=root(a),y=root(b);
	if(x==y)return 0;
	parent[x]=y;
	return 1;
}
int main(){
	int i,j,n,m,r,R;
	for(;scanf("%d%d",&n,&m),n;printf("%d\n",R)){
		for(i=0;i<m;i++)scanf("%d%d%d",a+i,b+i,&node[i].first),node[i].second=i,a[i]--,b[i]--;
		sort(node,node+m);
		for(R=-1,i=0;i<m;i++){
			for(r=j=0;j<n;j++)parent[j]=j;
			unite(a[node[i].second],b[node[i].second]);
			for(j=i+1;j<m;j++)if(unite(a[node[j].second],b[node[j].second]))r=node[j].first-node[i].first;
			for(j=1;j<n&&!differ(0,j);j++);
			if(j==n&&(R==-1||R>r))R=r;
		}
	}
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define mo 1000000007
#define pi 3.1415926535898
#define eps 1e-9 
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
long long n,k,i,j,top,a[100005],f[100005],ans;
long long ksm(long long u,long long v){
	long long o=1;
	while(v){
		if(v&1)
			o=o*u%mo;
		u=u*u%mo;
		v>>=1;
	}
	return o;
}
int main(){
	//freopen("camp.in","r",stdin);
	//freopen("camp.out","w",stdout);
	//sort(o+1,o+n+1);
	n=read();k=read();
	for(i=1;i*i<=n;i++)
		if(n%i==0){
			top++;
			a[top]=i;
			if(i*i!=n){
				top++;
				a[top]=n/i;
			}
		}
	sort(a+1,a+top+1);
	for(i=1;i<=top;i++){
		f[i]=ksm(k,a[i]+1>>1);
		for(j=1;j<i;j++)
			if(a[i]%a[j]==0)
				f[i]=(f[i]-f[j]+mo)%mo;
		if(a[i]&1)
			ans=(ans+f[i]*a[i])%mo;
		else
			ans=(ans+f[i]*a[i]/2)%mo;
	}
	pus(ans,2);
	return 0;
}

Measured memory_bytes: 256
import heapq
N,K=map(int, input().split())
V=list(map(int, input().split()))

ans=-10**9
for l in range(min(N,K)+1):
    for r in range(max(1,min(N,K)+1-l)):
        for d in range(max(1,min(N,K-l-r)+1)):
            h=V[:l]
            heapq.heapify(h)
            for i in range(r): heapq.heappush(h, V[-1-i])
            for i in range(min(d,len(h))): heapq.heappop(h)
            ans=max(ans,sum(h))
print(ans)

Measured memory_bytes: 81880
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
int n, w[201000];
map<int, int>Map;
bool Pos(int K) {
	int i;
	Map.clear();
	for (i = 2; i <= n; i++) {
		if (w[i] > w[i - 1]) {
			continue;
		}
		while (!Map.empty()) {
			auto it = Map.end();
			it--;
			if (it->first <= w[i])break;
			Map.erase(it);
		}
		Map[w[i]]++;
		int pv = w[i];
		while(Map[pv] == K) {
			if (pv == 1)return false;
			Map[pv] -= K;
			pv--;
			Map[pv]++;
		}
	}
	return true;
}
int main() {
	int i, chk = 0;
	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		scanf("%d", &w[i]);
		if (i>1 && w[i] <= w[i - 1])chk = 1;
	}
	if (!chk) {
		puts("1");
		return 0;
	}
	int b = 2, e = n, mid, r = 0;
	while (b <= e) {
		mid = (b + e) >> 1;
		if (Pos(mid)) {
			r = mid;
			e = mid - 1;
		}
		else b = mid + 1;
	}
	printf("%d\n", r);
}

Measured memory_bytes: 1024
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <cmath>
#include <set>
#include <map>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include <vector>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<int> G[100005];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
std::vector<P> tree[100010];
struct edge{int to,cost;};

ll i,j;
ll a,b,c;
ll ima=0,ans=0;
ll d[100005];
ll n,m;
 
int main(){
	cin>>n;
	d[0]=0;
	for(i=1;i<=n;i++){
		cin>>d[i];
		ans += abs(d[i]-ima);
		ima=d[i];
	}
	d[n+1]=0;
	ans += abs(d[n]-d[n+i]);
	for(i=1;i<=n;i++){
		if((d[i]-d[i-1]>0 && d[i+1]-d[i]<0) || (d[i]-d[i-1]<0 && d[i+1]-d[i]>0)){
			cout<<ans-abs(d[i]-d[i-1])-abs(d[i+1]-d[i])+abs(d[i-1]-d[i+1])<<endl;
		}else{
			cout<<ans<<endl;
		}
	}


	
		
	return 0;
}

Measured memory_bytes: 6656
#include<stdio.h>

int main (void) {
   int a, b, c, i, count = 0;

   scanf("%d %d %d", &a, &b, &c);

   for (i = a; i<=b; i++){
      if(c%i == 0) count++;
   }
   printf("%d\n", count);
   return 0;
}


Measured memory_bytes: 2752
#include <iostream>
#include <string>

int main(){
 std::string S,T;
 std::cin>>S>>T;

 for(int i=0;i<S.size();i++){
  if(T[i]!=S[i]){
   std::cout<<"No"<<std::endl;
   return 0;
  }
 }
 
 std::cout<<"Yes"<<std::endl;
 return 0;
}

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

#define abs(a) (((a) < 0) ? (-(a)) : (a))
int main(void) {
    int64_t N,M;
    int64_t mindistance;
    int64_t index;
    int64_t tmp;

    cin >> N >> M;

    vector<pair<int64_t,int64_t>> ab(N);
    vector<pair<int64_t,int64_t>> cd(M);
    for(int i=0;i<N;i++) {
        cin >> ab[i].first >> ab[i].second;
    }

    for(int i=0;i<M;i++) {
        cin >> cd[i].first >> cd[i].second;
    }

    for(auto a:ab) {
        mindistance = 1000000000;
        index = -1;
        for(int i=0;i<M;i++) {
            tmp = abs(a.first - cd[i].first) + abs(a.second - cd[i].second);
            if(mindistance > tmp) {
                mindistance = tmp;
                index = i;
            }
        }
        cout << index + 1 << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll n; 
	cin>>n;
	ll k;
	cin>>k;
	vector<ll>marks(n);
	for(ll i=0;i<n;i++)
		cin>>marks[i];
	unsigned ll n1=1,prev;
	for(ll i=0;i<k;i++)
		n1=((n1%18446744073709551615)*(marks[i]%18446744073709551615))%18446744073709551615;
	
	for(ll i=k;i<n;i++){
		prev=n1;
		n1=n1/marks[i-k];
		n1=((n1%18446744073709551615)*(marks[i]%18446744073709551615))%18446744073709551615;
		if(marks[i-k]<marks[i]||n1>prev)cout<<" Yes";
		else
			cout<<" No";
		cout<<'\n';
	}
	return 0;
}



Measured memory_bytes: 4764
/**
 *   created: 28 April 2019  23:46:46
**/
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int , int> pii;
typedef vector< pair<int , int> > vii;
typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long , long long> pll;
typedef vector< pair<long long , long long> > vll;

#define PB push_back
#define PPB pop_back
#define all(c) (c).begin,(c).end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
// #define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007


#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif


void optimizeIO()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

//=========================================================================================================

int main()
{
	// optimizeIO();
	int tc=1;
	// cin>>tc;
	for(int tt=0;tt<tc;tt++){
		int n,m;
		cin>>n>>m;
		vll v(n);
		rep(i,0,n){
			ll a,b;
			cin>>a>>b;
			v[i] = {a,b};
		}
		sort(v.begin(), v.end());
		ll cnt=0,rup=0;
		rep(i,0,n){
			if(v[i].second+cnt>=m){
				rup += v[i].first*(m-cnt);
				cout<<rup;
				return 0;
			}
			rup += v[i].first*v[i].second;
			cnt += v[i].second;
		}
	}
	return 0;
}




Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,t,a,i,j,x;
	cin>>n>>t>>a;
  	a*=1000;
  	t*=1000;
  	vector<pair<int,int>> h(n);
  	for(i=0;i<n;i++){
      cin>>x;
      h[i].first=abs(t-6*x-a);
      h[i].second=i+1;
    }
  	sort(h.begin(),h.end());
  	cout<<h[0].second<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cmath>
#include <cstdlib>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
#define ALL(x) x.begin(), x.end()
#define INF (1001000000)
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i:c)
#define EXIST(cs,v) (find(ALL(cs),(v))!=cs.end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define UNIQ(c) (c).erase(unique((c).begin(),(c).end()), (c).end());
#define P(p) cout<<(p)<<endl;

bool is_odd_string(string s) {
    if (s.length() == 1) return true;

    // 長さが偶数
    if (s.length() % 2 == 0) {
        string a = s.substr(0, s.length()/2);
        string b = s.substr(s.length()/2, s.length());
        if (a == b) return true;
        else return false;
    }
    // 長さが奇数
    else {
        return false;
    }
}

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

    string s;
    cin >> s;

    FOR(i, 1, s.length()) {
        string new_s = s.substr(0, s.length()-i);
        if (is_odd_string(new_s)) {
            P(s.length() - i);
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 256